Add application menu and about dialog
This commit is contained in:
parent
d0e1383861
commit
6fb4d39fc8
43
glade/about.glade
Normal file
43
glade/about.glade
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!-- Generated with glade 3.22.1 -->
|
||||||
|
<interface>
|
||||||
|
<requires lib="gtk+" version="3.20"/>
|
||||||
|
<object class="GtkAboutDialog" id="about-dialog">
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="type_hint">dialog</property>
|
||||||
|
<property name="program_name">GDS-Render Tool </property>
|
||||||
|
<property name="comments" translatable="yes">Tool for rendering GDS(II) layout files into LaTeX/TikZ code or directly into a PDF file</property>
|
||||||
|
<property name="website">https://git.shimatta.de/mhu/gds-render</property>
|
||||||
|
<property name="website_label" translatable="yes">Git Repository</property>
|
||||||
|
<property name="authors">Mario Hüttel <mario.huettel@gmx.net></property>
|
||||||
|
<property name="logo_icon_name">applications-graphics</property>
|
||||||
|
<property name="license_type">gpl-2-0-only</property>
|
||||||
|
<child>
|
||||||
|
<placeholder/>
|
||||||
|
</child>
|
||||||
|
<child internal-child="vbox">
|
||||||
|
<object class="GtkBox">
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="orientation">vertical</property>
|
||||||
|
<property name="spacing">2</property>
|
||||||
|
<child internal-child="action_area">
|
||||||
|
<object class="GtkButtonBox">
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="layout_style">end</property>
|
||||||
|
<child>
|
||||||
|
<placeholder/>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">False</property>
|
||||||
|
<property name="position">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<placeholder/>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</interface>
|
@ -4,7 +4,6 @@
|
|||||||
<requires lib="gtk+" version="3.20"/>
|
<requires lib="gtk+" version="3.20"/>
|
||||||
<object class="GtkWindow" id="main-window">
|
<object class="GtkWindow" id="main-window">
|
||||||
<property name="height_request">250</property>
|
<property name="height_request">250</property>
|
||||||
<property name="visible">True</property>
|
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<child type="titlebar">
|
<child type="titlebar">
|
||||||
<object class="GtkHeaderBar">
|
<object class="GtkHeaderBar">
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
<gresources>
|
<gresources>
|
||||||
<gresource prefix="/">
|
<gresource prefix="/">
|
||||||
<file compressed="true">main.glade</file>
|
<file compressed="true">main.glade</file>
|
||||||
|
<file compressed="true">about.glade</file>
|
||||||
<file>layer-widget.glade</file>
|
<file>layer-widget.glade</file>
|
||||||
<file>dialog.glade</file>
|
<file>dialog.glade</file>
|
||||||
</gresource>
|
</gresource>
|
||||||
|
58
main.c
58
main.c
@ -21,22 +21,78 @@
|
|||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
#include "main-window.h"
|
#include "main-window.h"
|
||||||
|
|
||||||
|
struct application_data {
|
||||||
|
GtkApplication *app;
|
||||||
|
GtkWindow *main_window;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static void app_quit(GSimpleAction *action, GVariant *parameter, gpointer user_data)
|
||||||
|
{
|
||||||
|
struct application_data *appdata = (struct application_data *)user_data;
|
||||||
|
gtk_widget_destroy(GTK_WIDGET(appdata->main_window));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void app_about(GSimpleAction *action, GVariant *parameter, gpointer user_data)
|
||||||
|
{
|
||||||
|
GtkBuilder *builder;
|
||||||
|
GtkDialog *dialog;
|
||||||
|
struct application_data *appdata = (struct application_data *)user_data;
|
||||||
|
|
||||||
|
builder = gtk_builder_new_from_resource("/about.glade");
|
||||||
|
dialog = GTK_DIALOG(gtk_builder_get_object(builder, "about-dialog"));
|
||||||
|
gtk_window_set_transient_for(GTK_WINDOW(dialog), appdata->main_window);
|
||||||
|
gtk_dialog_run(dialog);
|
||||||
|
|
||||||
|
gtk_widget_destroy(dialog);
|
||||||
|
g_object_unref(builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
const GActionEntry app_actions[] = {
|
||||||
|
{ "quit", app_quit },
|
||||||
|
{ "about", app_about }
|
||||||
|
};
|
||||||
|
|
||||||
static void gapp_activate(GApplication *app, gpointer user_data)
|
static void gapp_activate(GApplication *app, gpointer user_data)
|
||||||
{
|
{
|
||||||
GtkWindow *main_window;
|
GtkWindow *main_window;
|
||||||
|
struct application_data *appdata = (struct application_data *)user_data;
|
||||||
|
|
||||||
main_window = create_main_window();
|
main_window = create_main_window();
|
||||||
|
appdata->main_window = main_window;
|
||||||
gtk_application_add_window(GTK_APPLICATION(app), main_window);
|
gtk_application_add_window(GTK_APPLICATION(app), main_window);
|
||||||
|
gtk_widget_show(GTK_WIDGET(main_window));
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
GtkApplication *gapp;
|
GtkApplication *gapp;
|
||||||
int app_status;
|
int app_status;
|
||||||
|
struct application_data appdata;
|
||||||
|
GMenu *menu;
|
||||||
|
GMenu *m_quit;
|
||||||
|
GMenu *m_about;
|
||||||
|
|
||||||
gapp = gtk_application_new("de.shimatta.gds-render", G_APPLICATION_FLAGS_NONE);
|
gapp = gtk_application_new("de.shimatta.gds-render", G_APPLICATION_FLAGS_NONE);
|
||||||
g_signal_connect (gapp, "activate", G_CALLBACK(gapp_activate), NULL);
|
g_application_register(G_APPLICATION(gapp), NULL, NULL);
|
||||||
|
//g_action_map_add_action_entries(G_ACTION_MAP(gapp), app_actions, G_N_ELEMENTS(app_actions), &appdata);
|
||||||
|
g_signal_connect (gapp, "activate", G_CALLBACK(gapp_activate), &appdata);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
menu = g_menu_new();
|
||||||
|
m_quit = g_menu_new();
|
||||||
|
m_about = g_menu_new();
|
||||||
|
g_menu_append(m_quit, "Quit", "app.quit");
|
||||||
|
g_menu_append(m_about, "About", "app.about");
|
||||||
|
g_menu_append_section(menu, NULL, G_MENU_MODEL(m_about));
|
||||||
|
g_menu_append_section(menu, NULL, G_MENU_MODEL(m_quit));
|
||||||
|
g_action_map_add_action_entries(G_ACTION_MAP(gapp), app_actions, G_N_ELEMENTS(app_actions), &appdata);
|
||||||
|
gtk_application_set_app_menu(GTK_APPLICATION(gapp), G_MENU_MODEL(menu));
|
||||||
|
|
||||||
|
g_object_unref(m_quit);
|
||||||
|
g_object_unref(m_about);
|
||||||
|
g_object_unref(menu);
|
||||||
|
|
||||||
|
|
||||||
app_status = g_application_run (G_APPLICATION(gapp), argc, argv);
|
app_status = g_application_run (G_APPLICATION(gapp), argc, argv);
|
||||||
|
Loading…
Reference in New Issue
Block a user