[gthumb] shortcut preferences: added a category filter
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb] shortcut preferences: added a category filter
- Date: Sun, 24 Nov 2019 12:34:24 +0000 (UTC)
commit 8ea7fc65dba5d5e39a81917f470117270f902736
Author: Paolo Bacchilega <paobac src gnome org>
Date: Sun Nov 17 11:58:04 2019 +0100
shortcut preferences: added a category filter
data/ui/shortcuts-preferences.ui | 86 ++++++++++-----------
gthumb/dlg-preferences-extensions.c | 6 +-
gthumb/dlg-preferences-shortcuts.c | 145 ++++++++++++++++++++++++++++++++++--
gthumb/gth-main.c | 7 ++
gthumb/gth-main.h | 1 +
5 files changed, 187 insertions(+), 58 deletions(-)
---
diff --git a/data/ui/shortcuts-preferences.ui b/data/ui/shortcuts-preferences.ui
index dca2d5c8..93b7e19d 100644
--- a/data/ui/shortcuts-preferences.ui
+++ b/data/ui/shortcuts-preferences.ui
@@ -4,53 +4,54 @@
<requires lib="gtk+" version="3.16"/>
<object class="GtkListStore" id="category_liststore">
<columns>
- <!-- column-name category -->
- <column type="gint"/>
+ <!-- column-name id -->
+ <column type="gchararray"/>
<!-- column-name name -->
<column type="gchararray"/>
</columns>
- <data>
- <row>
- <col id="0">1</col>
- <col id="1" translatable="yes">User Interface</col>
- </row>
- <row>
- <col id="0">5</col>
- <col id="1" translatable="yes">File Navigation</col>
- </row>
- <row>
- <col id="0">2</col>
- <col id="1" translatable="yes">File Edit</col>
- </row>
- <row>
- <col id="0">5</col>
- <col id="1" translatable="yes">Image View</col>
- </row>
- <row>
- <col id="0">3</col>
- <col id="1" translatable="yes">Image Edit</col>
- </row>
- <row>
- <col id="0">6</col>
- <col id="1" translatable="yes">Slideshow</col>
- </row>
- </data>
</object>
- <object class="GtkSizeGroup" id="column1_size_group"/>
- <object class="GtkSizeGroup" id="column2_size_group"/>
- <object class="GtkSizeGroup" id="column3_size_group"/>
<object class="GtkBox" id="preferences_page">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
- <object class="GtkLabel">
+ <object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="label" translatable="yes">Keyboard Shortcuts:</property>
- <property name="mnemonic_widget">shortcuts_list</property>
- <property name="xalign">0</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Shortcuts:</property>
+ <property name="mnemonic_widget">shortcuts_list</property>
+ <property name="xalign">0</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkComboBox" id="category_combobox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="model">category_liststore</property>
+ <child>
+ <object class="GtkCellRendererText"/>
+ <attributes>
+ <attribute name="text">1</attribute>
+ </attributes>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="expand">False</property>
@@ -108,16 +109,7 @@
</packing>
</child>
</object>
- <object class="GtkListStore" id="shortcuts_liststore">
- <columns>
- <!-- column-name action_name -->
- <column type="gchararray"/>
- <!-- column-name description -->
- <column type="gchararray"/>
- <!-- column-name shortcut -->
- <column type="gchararray"/>
- <!-- column-name category -->
- <column type="gboolean"/>
- </columns>
- </object>
+ <object class="GtkSizeGroup" id="column1_size_group"/>
+ <object class="GtkSizeGroup" id="column2_size_group"/>
+ <object class="GtkSizeGroup" id="column3_size_group"/>
</interface>
diff --git a/gthumb/dlg-preferences-extensions.c b/gthumb/dlg-preferences-extensions.c
index 4a34ebcf..e7de573f 100644
--- a/gthumb/dlg-preferences-extensions.c
+++ b/gthumb/dlg-preferences-extensions.c
@@ -58,9 +58,9 @@ typedef struct {
static ExtensionCategory extension_category[] = {
- { EXTENSION_CATEGORY_ALL, N_("All"), "folder" },
- { EXTENSION_CATEGORY_ENABLED, N_("Enabled"), "folder" },
- { EXTENSION_CATEGORY_DISABLED, N_("Disabled"), "folder" },
+ { EXTENSION_CATEGORY_ALL, NC_("Extensions", "All"), "folder" },
+ { EXTENSION_CATEGORY_ENABLED, NC_("Extensions", "Enabled"), "folder" },
+ { EXTENSION_CATEGORY_DISABLED, NC_("Extensions", "Disabled"), "folder" },
{ EXTENSION_CATEGORY_SEPARATOR, NULL, NULL },
{ "Browser", N_("Browser"), "folder" },
{ "Viewer", N_("Viewers"), "folder" },
diff --git a/gthumb/dlg-preferences-shortcuts.c b/gthumb/dlg-preferences-shortcuts.c
index 07c6f407..dca3336b 100644
--- a/gthumb/dlg-preferences-shortcuts.c
+++ b/gthumb/dlg-preferences-shortcuts.c
@@ -33,6 +33,8 @@
#define GET_WIDGET(name) _gtk_builder_get_widget (data->builder, (name))
#define BROWSER_DATA_KEY "shortcuts-preference-data"
+#define GTH_SHORTCUT_CATEGORY_ALL "all"
+#define GTH_SHORTCUT_CATEGORY_MODIFIED "modified"
enum {
@@ -47,12 +49,14 @@ typedef struct {
GtkBuilder *builder;
GtkWidget *preferences_dialog;
GPtrArray *rows;
+ char *show_category;
} BrowserData;
static void
browser_data_free (BrowserData *data)
{
+ g_free (data->show_category);
g_ptr_array_unref (data->rows);
g_object_unref (data->builder);
g_free (data);
@@ -64,6 +68,7 @@ typedef struct {
GthShortcut *shortcut;
GtkWidget *accel_label;
GtkWidget *revert_button;
+ gboolean modified;
} RowData;
@@ -96,13 +101,11 @@ row_data_free (RowData *row_data)
static void
row_data_update_accel_label (RowData *row_data)
{
- gboolean modified;
-
if (row_data == NULL)
return;
- modified = g_strcmp0 (row_data->shortcut->default_accelerator, row_data->shortcut->accelerator) != 0;
- if (modified) {
+ row_data->modified = g_strcmp0 (row_data->shortcut->default_accelerator,
row_data->shortcut->accelerator) != 0;
+ if (row_data->modified) {
char *esc_text;
char *markup_text;
@@ -116,8 +119,8 @@ row_data_update_accel_label (RowData *row_data)
else
gtk_label_set_text (GTK_LABEL (row_data->accel_label), row_data->shortcut->label);
- gtk_widget_set_sensitive (row_data->revert_button, modified);
- gtk_widget_set_child_visible (row_data->revert_button, modified);
+ gtk_widget_set_sensitive (row_data->revert_button, row_data->modified);
+ gtk_widget_set_child_visible (row_data->revert_button, row_data->modified);
}
@@ -137,6 +140,14 @@ find_row_by_shortcut (BrowserData *browser_data,
}
+static void
+update_filter_if_required (BrowserData *data)
+{
+ if (g_strcmp0 (data->show_category, GTH_SHORTCUT_CATEGORY_MODIFIED) == 0)
+ gtk_list_box_invalidate_filter (GTK_LIST_BOX (_gtk_builder_get_widget (data->builder,
"shortcuts_list")));
+}
+
+
static gboolean
row_data_update_shortcut (RowData *row_data,
guint keycode,
@@ -168,6 +179,7 @@ row_data_update_shortcut (RowData *row_data,
gth_shortcut_set_key (row_data->shortcut, keycode, modifiers);
row_data_update_accel_label (row_data);
+ update_filter_if_required (row_data->browser_data);
gth_main_shortcuts_changed (gth_window_get_shortcuts (GTH_WINDOW
(row_data->browser_data->browser)));
}
@@ -258,7 +270,7 @@ _new_shortcut_row (GthShortcut *shortcut,
gtk_container_set_border_width (GTK_CONTAINER (box), 5);
gtk_container_add (GTK_CONTAINER (row), box);
- label = gtk_label_new (shortcut->description);
+ label = gtk_label_new (_(shortcut->description));
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
gtk_widget_set_margin_end (label, 12);
gtk_size_group_add_widget (GTK_SIZE_GROUP (gtk_builder_get_object (data->builder,
"column1_size_group")), label);
@@ -318,7 +330,7 @@ _new_shortcut_category_row (const char *category_id,
gtk_container_add (GTK_CONTAINER (row), box);
category = gth_main_get_shortcut_category (category_id);
- text = (category != NULL) ? category->display_name : _("Other");
+ text = (category != NULL) ? _(category->display_name) : _("Other");
esc_text = g_markup_escape_text (text, -1);
markup_text = g_strdup_printf ("<b>%s</b>", esc_text);
@@ -375,6 +387,68 @@ restore_all_button_clicked_cb (GtkButton *button,
}
+static int
+cmp_category (gconstpointer a,
+ gconstpointer b)
+{
+ GthShortcutCategory *cat_a = * (GthShortcutCategory **) a;
+ GthShortcutCategory *cat_b = * (GthShortcutCategory **) b;
+
+ if (cat_a->sort_order == cat_b->sort_order)
+ return 0;
+ else if (cat_a->sort_order > cat_b->sort_order)
+ return 1;
+ else
+ return -1;
+}
+
+
+static void
+category_combo_box_changed_cb (GtkComboBox *combo_box,
+ gpointer user_data)
+{
+ BrowserData *data = user_data;
+ GtkTreeIter iter;
+
+ if (gtk_combo_box_get_active_iter (combo_box, &iter)) {
+ char *category_id;
+
+ gtk_tree_model_get (GTK_TREE_MODEL (gtk_builder_get_object (data->builder,
"category_liststore")),
+ &iter,
+ 0, &category_id,
+ -1);
+
+ g_free (data->show_category);
+ data->show_category = g_strdup (category_id);
+
+ gtk_list_box_invalidate_filter (GTK_LIST_BOX (_gtk_builder_get_widget (data->builder,
"shortcuts_list")));
+
+ g_free (category_id);
+ }
+}
+
+
+static gboolean
+shortcut_filter_func (GtkListBoxRow *row,
+ gpointer user_data)
+{
+ BrowserData *data = user_data;
+ RowData *row_data;
+
+ if (g_strcmp0 (data->show_category, GTH_SHORTCUT_CATEGORY_ALL) == 0)
+ return TRUE;
+
+ row_data = g_object_get_data (G_OBJECT (row), "shortcut-row-data");
+ if ((row_data == NULL) || (row_data->shortcut == NULL))
+ return FALSE;
+
+ if (g_strcmp0 (data->show_category, GTH_SHORTCUT_CATEGORY_MODIFIED) == 0)
+ return row_data->modified;
+
+ return g_strcmp0 (data->show_category, row_data->shortcut->category) == 0;
+}
+
+
void
shortcuts__dlg_preferences_construct_cb (GtkWidget *dialog,
GthBrowser *browser,
@@ -394,9 +468,12 @@ shortcuts__dlg_preferences_construct_cb (GtkWidget *dialog,
data->builder = _gtk_builder_new_from_file ("shortcuts-preferences.ui", NULL);
data->preferences_dialog = dialog;
data->rows = g_ptr_array_new ();
+ data->show_category = g_strdup (GTH_SHORTCUT_CATEGORY_ALL);
g_object_set_data_full (G_OBJECT (dialog), BROWSER_DATA_KEY, data, (GDestroyNotify)
browser_data_free);
+ /* shortcut list */
+
shortcuts_list = _gtk_builder_get_widget (data->builder, "shortcuts_list");
shortcuts_v = gth_window_get_shortcuts_by_category (GTH_WINDOW (browser));
last_category = NULL;
@@ -424,6 +501,10 @@ shortcuts__dlg_preferences_construct_cb (GtkWidget *dialog,
_new_shortcut_row (shortcut, data),
-1);
}
+ gtk_list_box_set_filter_func (GTK_LIST_BOX (shortcuts_list),
+ shortcut_filter_func,
+ data,
+ NULL);
g_signal_connect (shortcuts_list,
"row-activated",
@@ -434,6 +515,54 @@ shortcuts__dlg_preferences_construct_cb (GtkWidget *dialog,
G_CALLBACK (restore_all_button_clicked_cb),
data);
+ /* shortcut categories */
+
+ {
+ GPtrArray *category_v;
+ GtkListStore *list_store;
+ GtkTreeIter iter;
+ int i;
+
+ category_v = g_ptr_array_copy (gth_main_get_shortcut_categories (), NULL, NULL);
+ g_ptr_array_set_free_func (category_v, NULL);
+ g_ptr_array_sort (category_v, cmp_category);
+
+ list_store = (GtkListStore *) gtk_builder_get_object (data->builder, "category_liststore");
+
+ gtk_list_store_append (list_store, &iter);
+ gtk_list_store_set (list_store, &iter,
+ 0, GTH_SHORTCUT_CATEGORY_ALL,
+ 1, C_("Shortcuts", "All"),
+ -1);
+
+ gtk_list_store_append (list_store, &iter);
+ gtk_list_store_set (list_store, &iter,
+ 0, GTH_SHORTCUT_CATEGORY_MODIFIED,
+ 1, C_("Shortcuts", "Modified"),
+ -1);
+
+ for (i = 0; i < category_v->len; i++) {
+ GthShortcutCategory *category = g_ptr_array_index (category_v, i);
+
+ if (g_strcmp0 (category->id, GTH_SHORTCUT_CATEGORY_HIDDEN) == 0)
+ continue;
+
+ gtk_list_store_append (list_store, &iter);
+ gtk_list_store_set (list_store, &iter,
+ 0, category->id,
+ 1, _(category->display_name),
+ -1);
+ }
+
+ gtk_combo_box_set_active (GTK_COMBO_BOX (_gtk_builder_get_widget (data->builder,
"category_combobox")), 0);
+ g_signal_connect (_gtk_builder_get_widget (data->builder, "category_combobox"),
+ "changed",
+ G_CALLBACK (category_combo_box_changed_cb),
+ data);
+
+ g_ptr_array_unref (category_v);
+ }
+
/* add the page to the preferences dialog */
label = gtk_label_new (_("Shortcuts"));
diff --git a/gthumb/gth-main.c b/gthumb/gth-main.c
index ecf104cb..736bd12f 100644
--- a/gthumb/gth-main.c
+++ b/gthumb/gth-main.c
@@ -649,6 +649,13 @@ gth_main_get_shortcut_category (const char *id)
}
+GPtrArray *
+gth_main_get_shortcut_categories (void)
+{
+ return Main->priv->shortcut_category_v;
+}
+
+
void
gth_main_register_shortcut_category (GthShortcutCategory *shortcut_category,
int n_categories)
diff --git a/gthumb/gth-main.h b/gthumb/gth-main.h
index 5475502c..dacdb49a 100644
--- a/gthumb/gth-main.h
+++ b/gthumb/gth-main.h
@@ -89,6 +89,7 @@ GList * gth_main_get_all_metadata_info (void);
void gth_main_register_shortcut_category (GthShortcutCategory *shortcut_category,
int n_categories);
GthShortcutCategory * gth_main_get_shortcut_category (const char *id);
+GPtrArray * gth_main_get_shortcut_categories (void);
void gth_main_register_sort_type (GthFileDataSort *sort_type);
GthFileDataSort * gth_main_get_sort_type (const char *name);
GList * gth_main_get_all_sort_types (void);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]