Skip to content

Commit

Permalink
Add GtkShortcutsWindow
Browse files Browse the repository at this point in the history
Fixes #45.
  • Loading branch information
Hjdskes committed Aug 25, 2018
1 parent 27bce61 commit 5fd8da6
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 1 deletion.
1 change: 1 addition & 0 deletions data/gcolor3.gresource.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/nl/hjdskes/gcolor3/">
<file alias="shortcuts.ui" preprocess="xml-stripblanks">shortcuts.ui</file>
<!-- Using this alias, GtkApplication will automatically pick it up for us. -->
<file alias="gtk/menus.ui" preprocess="xml-stripblanks">menus.ui</file>
<file alias="color-row.ui" preprocess="xml-stripblanks">color-row.ui</file>
Expand Down
4 changes: 4 additions & 0 deletions data/menus.ui
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
<interface>
<menu id="app-menu">
<section>
<item>
<attribute name="action">app.shortcuts</attribute>
<attribute name="label" translatable="yes">_Keyboard Shortcuts</attribute>
</item>
<item>
<attribute name="action">app.about</attribute>
<attribute name="label" translatable="yes">_About</attribute>
Expand Down
60 changes: 60 additions & 0 deletions data/shortcuts.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="3.16"/>
<object class="GtkShortcutsWindow" id="shortcuts-gcolor3">
<property name="modal">1</property>
<child>
<object class="GtkShortcutsSection">
<property name="visible">1</property>
<property name="section-name">shortcuts</property>
<property name="max-height">12</property>
<child>
<object class="GtkShortcutsGroup">
<property name="visible">1</property>
<property name="title" translatable="yes">General</property>
<child>
<object class="GtkShortcutsShortcut">
<property name="visible">1</property>
<property name="accelerator">F9</property>
<property name="title" translatable="yes">Change page</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkShortcutsGroup">
<property name="visible">1</property>
<property name="title" translatable="yes">Palette shortcuts</property>
<child>
<object class="GtkShortcutsShortcut">
<property name="visible">1</property>
<property name="accelerator">&lt;ctrl&gt;s</property>
<property name="title" translatable="yes">Save currently selected color</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkShortcutsGroup">
<property name="visible">1</property>
<property name="title" translatable="yes">Saved color management</property>
<child>
<object class="GtkShortcutsShortcut">
<property name="visible">1</property>
<property name="accelerator">&lt;ctrl&gt;c</property>
<property name="title" translatable="yes">Copy highlighted color's hex value</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="visible">1</property>
<property name="accelerator">Delete</property>
<property name="title" translatable="yes">Delete highlighted color</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</interface>
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ project('gcolor3', 'c', version: '2.2',
]
)

dep_gtk = dependency('gtk+-3.0', version: '>= 3.12.0', required: true)
dep_gtk = dependency('gtk+-3.0', version: '>= 3.20.0', required: true)
cc = meson.get_compiler('c')
dep_lm = cc.find_library('m', required: true)

Expand Down
1 change: 1 addition & 0 deletions po/POTFILES
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ data/nl.hjdskes.gcolor3.desktop.in
data/nl.hjdskes.gcolor3.appdata.xml.in
data/color-row.ui
data/menus.ui
data/shortcuts.ui
data/window.ui
src/main.c
src/gcolor3-application.c
Expand Down
29 changes: 29 additions & 0 deletions src/gcolor3-application.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,34 @@ struct _Gcolor3ApplicationPrivate {

G_DEFINE_TYPE_WITH_PRIVATE (Gcolor3Application, gcolor3_application, GTK_TYPE_APPLICATION);

static void
gcolor3_application_action_shortcuts (UNUSED GSimpleAction *action,
UNUSED GVariant *parameter,
gpointer user_data)
{
static GtkWindow *overlay = NULL;
GtkBuilder *builder;
GtkWindow *window;

if (!overlay) {
builder = gtk_builder_new_from_resource ("/nl/hjdskes/gcolor3/shortcuts.ui");
overlay = GTK_WINDOW (gtk_builder_get_object (builder, "shortcuts-gcolor3"));
g_object_unref (builder);
g_object_set (overlay, "view-name", NULL, NULL);

g_signal_connect (overlay, "delete-event",
G_CALLBACK (gtk_widget_hide_on_delete), NULL);

window = gtk_application_get_active_window (GTK_APPLICATION (user_data));

gtk_window_set_modal (overlay, TRUE);
gtk_window_set_transient_for (overlay, window);
gtk_window_set_destroy_with_parent (overlay, TRUE);
}

gtk_window_present (overlay);
}

static void
gcolor3_application_action_about (UNUSED GSimpleAction *action,
UNUSED GVariant *parameter,
Expand Down Expand Up @@ -79,6 +107,7 @@ gcolor3_application_action_quit (UNUSED GSimpleAction *action,
}

static GActionEntry app_entries[] = {
{ "shortcuts", gcolor3_application_action_shortcuts, NULL, NULL, NULL },
{ "about", gcolor3_application_action_about, NULL, NULL, NULL },
{ "quit", gcolor3_application_action_quit, NULL, NULL, NULL },
};
Expand Down

0 comments on commit 5fd8da6

Please sign in to comment.