Commit 8ea7fc65 authored by Paolo Bacchilega's avatar Paolo Bacchilega
Browse files

shortcut preferences: added a category filter

parent dc4926ba
...@@ -4,53 +4,54 @@ ...@@ -4,53 +4,54 @@
<requires lib="gtk+" version="3.16"/> <requires lib="gtk+" version="3.16"/>
<object class="GtkListStore" id="category_liststore"> <object class="GtkListStore" id="category_liststore">
<columns> <columns>
<!-- column-name category --> <!-- column-name id -->
<column type="gint"/> <column type="gchararray"/>
<!-- column-name name --> <!-- column-name name -->
<column type="gchararray"/> <column type="gchararray"/>
</columns> </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>
<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"> <object class="GtkBox" id="preferences_page">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<property name="spacing">6</property> <property name="spacing">6</property>
<child> <child>
<object class="GtkLabel"> <object class="GtkBox">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="label" translatable="yes">Keyboard Shortcuts:</property> <property name="spacing">6</property>
<property name="mnemonic_widget">shortcuts_list</property> <child>
<property name="xalign">0</property> <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> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
...@@ -108,16 +109,7 @@ ...@@ -108,16 +109,7 @@
</packing> </packing>
</child> </child>
</object> </object>
<object class="GtkListStore" id="shortcuts_liststore"> <object class="GtkSizeGroup" id="column1_size_group"/>
<columns> <object class="GtkSizeGroup" id="column2_size_group"/>
<!-- column-name action_name --> <object class="GtkSizeGroup" id="column3_size_group"/>
<column type="gchararray"/>
<!-- column-name description -->
<column type="gchararray"/>
<!-- column-name shortcut -->
<column type="gchararray"/>
<!-- column-name category -->
<column type="gboolean"/>
</columns>
</object>
</interface> </interface>
...@@ -58,9 +58,9 @@ typedef struct { ...@@ -58,9 +58,9 @@ typedef struct {
static ExtensionCategory extension_category[] = { static ExtensionCategory extension_category[] = {
{ EXTENSION_CATEGORY_ALL, N_("All"), "folder" }, { EXTENSION_CATEGORY_ALL, NC_("Extensions", "All"), "folder" },
{ EXTENSION_CATEGORY_ENABLED, N_("Enabled"), "folder" }, { EXTENSION_CATEGORY_ENABLED, NC_("Extensions", "Enabled"), "folder" },
{ EXTENSION_CATEGORY_DISABLED, N_("Disabled"), "folder" }, { EXTENSION_CATEGORY_DISABLED, NC_("Extensions", "Disabled"), "folder" },
{ EXTENSION_CATEGORY_SEPARATOR, NULL, NULL }, { EXTENSION_CATEGORY_SEPARATOR, NULL, NULL },
{ "Browser", N_("Browser"), "folder" }, { "Browser", N_("Browser"), "folder" },
{ "Viewer", N_("Viewers"), "folder" }, { "Viewer", N_("Viewers"), "folder" },
......
...@@ -33,6 +33,8 @@ ...@@ -33,6 +33,8 @@
#define GET_WIDGET(name) _gtk_builder_get_widget (data->builder, (name)) #define GET_WIDGET(name) _gtk_builder_get_widget (data->builder, (name))
#define BROWSER_DATA_KEY "shortcuts-preference-data" #define BROWSER_DATA_KEY "shortcuts-preference-data"
#define GTH_SHORTCUT_CATEGORY_ALL "all"
#define GTH_SHORTCUT_CATEGORY_MODIFIED "modified"
enum { enum {
...@@ -47,12 +49,14 @@ typedef struct { ...@@ -47,12 +49,14 @@ typedef struct {
GtkBuilder *builder; GtkBuilder *builder;
GtkWidget *preferences_dialog; GtkWidget *preferences_dialog;
GPtrArray *rows; GPtrArray *rows;
char *show_category;
} BrowserData; } BrowserData;
static void static void
browser_data_free (BrowserData *data) browser_data_free (BrowserData *data)
{ {
g_free (data->show_category);
g_ptr_array_unref (data->rows); g_ptr_array_unref (data->rows);
g_object_unref (data->builder); g_object_unref (data->builder);
g_free (data); g_free (data);
...@@ -64,6 +68,7 @@ typedef struct { ...@@ -64,6 +68,7 @@ typedef struct {
GthShortcut *shortcut; GthShortcut *shortcut;
GtkWidget *accel_label; GtkWidget *accel_label;
GtkWidget *revert_button; GtkWidget *revert_button;
gboolean modified;
} RowData; } RowData;
...@@ -96,13 +101,11 @@ row_data_free (RowData *row_data) ...@@ -96,13 +101,11 @@ row_data_free (RowData *row_data)
static void static void
row_data_update_accel_label (RowData *row_data) row_data_update_accel_label (RowData *row_data)
{ {
gboolean modified;
if (row_data == NULL) if (row_data == NULL)
return; return;
modified = g_strcmp0 (row_data->shortcut->default_accelerator, row_data->shortcut->accelerator) != 0; row_data->modified = g_strcmp0 (row_data->shortcut->default_accelerator, row_data->shortcut->accelerator) != 0;
if (modified) { if (row_data->modified) {
char *esc_text; char *esc_text;
char *markup_text; char *markup_text;
...@@ -116,8 +119,8 @@ row_data_update_accel_label (RowData *row_data) ...@@ -116,8 +119,8 @@ row_data_update_accel_label (RowData *row_data)
else else
gtk_label_set_text (GTK_LABEL (row_data->accel_label), row_data->shortcut->label); 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_sensitive (row_data->revert_button, row_data->modified);
gtk_widget_set_child_visible (row_data->revert_button, modified); gtk_widget_set_child_visible (row_data->revert_button, row_data->modified);
} }
...@@ -137,6 +140,14 @@ find_row_by_shortcut (BrowserData *browser_data, ...@@ -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 static gboolean
row_data_update_shortcut (RowData *row_data, row_data_update_shortcut (RowData *row_data,
guint keycode, guint keycode,
...@@ -168,6 +179,7 @@ row_data_update_shortcut (RowData *row_data, ...@@ -168,6 +179,7 @@ row_data_update_shortcut (RowData *row_data,
gth_shortcut_set_key (row_data->shortcut, keycode, modifiers); gth_shortcut_set_key (row_data->shortcut, keycode, modifiers);
row_data_update_accel_label (row_data); 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))); gth_main_shortcuts_changed (gth_window_get_shortcuts (GTH_WINDOW (row_data->browser_data->browser)));
} }
...@@ -258,7 +270,7 @@ _new_shortcut_row (GthShortcut *shortcut, ...@@ -258,7 +270,7 @@ _new_shortcut_row (GthShortcut *shortcut,
gtk_container_set_border_width (GTK_CONTAINER (box), 5); gtk_container_set_border_width (GTK_CONTAINER (box), 5);
gtk_container_add (GTK_CONTAINER (row), box); 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_label_set_xalign (GTK_LABEL (label), 0.0);
gtk_widget_set_margin_end (label, 12); 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); 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, ...@@ -318,7 +330,7 @@ _new_shortcut_category_row (const char *category_id,
gtk_container_add (GTK_CONTAINER (row), box); gtk_container_add (GTK_CONTAINER (row), box);
category = gth_main_get_shortcut_category (category_id); 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); esc_text = g_markup_escape_text (text, -1);
markup_text = g_strdup_printf ("<b>%s</b>", esc_text); markup_text = g_strdup_printf ("<b>%s</b>", esc_text);
...@@ -375,6 +387,68 @@ restore_all_button_clicked_cb (GtkButton *button, ...@@ -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 void
shortcuts__dlg_preferences_construct_cb (GtkWidget *dialog, shortcuts__dlg_preferences_construct_cb (GtkWidget *dialog,
GthBrowser *browser, GthBrowser *browser,
...@@ -394,9 +468,12 @@ shortcuts__dlg_preferences_construct_cb (GtkWidget *dialog, ...@@ -394,9 +468,12 @@ shortcuts__dlg_preferences_construct_cb (GtkWidget *dialog,
data->builder = _gtk_builder_new_from_file ("shortcuts-preferences.ui", NULL); data->builder = _gtk_builder_new_from_file ("shortcuts-preferences.ui", NULL);
data->preferences_dialog = dialog; data->preferences_dialog = dialog;
data->rows = g_ptr_array_new (); 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); 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_list = _gtk_builder_get_widget (data->builder, "shortcuts_list");
shortcuts_v = gth_window_get_shortcuts_by_category (GTH_WINDOW (browser)); shortcuts_v = gth_window_get_shortcuts_by_category (GTH_WINDOW (browser));
last_category = NULL; last_category = NULL;
...@@ -424,6 +501,10 @@ shortcuts__dlg_preferences_construct_cb (GtkWidget *dialog, ...@@ -424,6 +501,10 @@ shortcuts__dlg_preferences_construct_cb (GtkWidget *dialog,
_new_shortcut_row (shortcut, data), _new_shortcut_row (shortcut, data),
-1); -1);
} }
gtk_list_box_set_filter_func (GTK_LIST_BOX (shortcuts_list),
shortcut_filter_func,
data,
NULL);
g_signal_connect (shortcuts_list, g_signal_connect (shortcuts_list,
"row-activated", "row-activated",
...@@ -434,6 +515,54 @@ shortcuts__dlg_preferences_construct_cb (GtkWidget *dialog, ...@@ -434,6 +515,54 @@ shortcuts__dlg_preferences_construct_cb (GtkWidget *dialog,
G_CALLBACK (restore_all_button_clicked_cb), G_CALLBACK (restore_all_button_clicked_cb),
data); 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 */ /* add the page to the preferences dialog */
label = gtk_label_new (_("Shortcuts")); label = gtk_label_new (_("Shortcuts"));
......
...@@ -649,6 +649,13 @@ gth_main_get_shortcut_category (const char *id) ...@@ -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 void
gth_main_register_shortcut_category (GthShortcutCategory *shortcut_category, gth_main_register_shortcut_category (GthShortcutCategory *shortcut_category,
int n_categories) int n_categories)
......
...@@ -89,6 +89,7 @@ GList * gth_main_get_all_metadata_info (void); ...@@ -89,6 +89,7 @@ GList * gth_main_get_all_metadata_info (void);
void gth_main_register_shortcut_category (GthShortcutCategory *shortcut_category, void gth_main_register_shortcut_category (GthShortcutCategory *shortcut_category,
int n_categories); int n_categories);
GthShortcutCategory * gth_main_get_shortcut_category (const char *id); 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); void gth_main_register_sort_type (GthFileDataSort *sort_type);
GthFileDataSort * gth_main_get_sort_type (const char *name); GthFileDataSort * gth_main_get_sort_type (const char *name);
GList * gth_main_get_all_sort_types (void); GList * gth_main_get_all_sort_types (void);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment