Commit 70ec2d72 authored by Paolo Bacchilega's avatar Paolo Bacchilega
Browse files

shortcuts: allow extensions to register shortcut categories

parent d1f7327b
......@@ -339,15 +339,16 @@ _new_shortcut_row (GthShortcut *shortcut,
static GtkWidget *
_new_shortcut_category_row (GthShortcutCategory category,
int n_category)
_new_shortcut_category_row (const char *category_id,
int n_category)
{
GtkWidget *row;
GtkWidget *box;
const char *text;
char *esc_text;
char *markup_text;
GtkWidget *label;
GtkWidget *row;
GtkWidget *box;
GthShortcutCategory *category;
const char *text;
char *esc_text;
char *markup_text;
GtkWidget *label;
row = gtk_list_box_row_new ();
gtk_list_box_row_set_activatable (GTK_LIST_BOX_ROW (row), FALSE);
......@@ -358,28 +359,8 @@ _new_shortcut_category_row (GthShortcutCategory category,
gtk_widget_set_margin_top (box, 15);
gtk_container_add (GTK_CONTAINER (row), box);
text = _("Others");
switch (category) {
case GTH_SHORTCUT_CATEGORY_UI:
text = _("Show/Hide");
break;
case GTH_SHORTCUT_CATEGORY_FILE_NAVIGATION:
text = _("File Navigation");
break;
case GTH_SHORTCUT_CATEGORY_FILE_EDIT:
text = _("File Edit");
break;
case GTH_SHORTCUT_CATEGORY_IMAGE_VIEW:
text = _("Viewer");
break;
case GTH_SHORTCUT_CATEGORY_IMAGE_EDIT:
text = _("Image Edit");
break;
case GTH_SHORTCUT_CATEGORY_SLIDESHOW:
text = _("Slideshow");
break;
}
category = gth_main_get_shortcut_category (category_id);
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);
......@@ -403,22 +384,6 @@ _new_shortcut_category_row (GthShortcutCategory category,
}
static int
sort_shortcuts_by_category (gconstpointer a,
gconstpointer b)
{
const GthShortcut *sa = * (GthShortcut **) a;
const GthShortcut *sb = * (GthShortcut **) b;
if (sa->category < sb->category)
return -1;
if (sa->category > sb->category)
return 1;
return g_strcmp0 (sa->description, sb->description);
}
static void
restore_all_button_clicked_cb (GtkButton *button,
gpointer user_data)
......@@ -459,8 +424,8 @@ shortcuts__dlg_preferences_construct_cb (GtkWidget *dialog,
{
BrowserData *data;
GtkWidget *shortcuts_list;
GPtrArray *accel_v;
int last_category;
GPtrArray *shortcuts_v;
const char *last_category;
int n_category;
int i;
GtkWidget *label;
......@@ -475,17 +440,16 @@ shortcuts__dlg_preferences_construct_cb (GtkWidget *dialog,
g_object_set_data_full (G_OBJECT (dialog), BROWSER_DATA_KEY, data, (GDestroyNotify) browser_data_free);
shortcuts_list = _gtk_builder_get_widget (data->builder, "shortcuts_list");
accel_v = gth_window_get_shortcuts (GTH_WINDOW (browser));
g_ptr_array_sort (accel_v, sort_shortcuts_by_category);
last_category = -1;
shortcuts_v = gth_window_get_shortcuts_by_category (GTH_WINDOW (browser));
last_category = NULL;
n_category = 0;
for (i = 0; i < accel_v->len; i++) {
GthShortcut *shortcut = g_ptr_array_index (accel_v, i);
for (i = 0; i < shortcuts_v->len; i++) {
GthShortcut *shortcut = g_ptr_array_index (shortcuts_v, i);
if (shortcut->category == GTH_SHORTCUT_CATEGORY_HIDDEN)
if (g_strcmp0 (shortcut->category, GTH_SHORTCUT_CATEGORY_HIDDEN) == 0)
continue;
if (shortcut->category != last_category) {
if (g_strcmp0 (shortcut->category,last_category) != 0) {
last_category = shortcut->category;
n_category++;
gtk_list_box_insert (GTK_LIST_BOX (shortcuts_list),
......
......@@ -33,6 +33,17 @@
#include "pixbuf-io.h"
GthShortcutCategory shortcut_categories[] = {
{ GTH_SHORTCUT_CATEGORY_HIDDEN, NULL },
{ GTH_SHORTCUT_CATEGORY_UI, N_("Show/Hide") },
{ GTH_SHORTCUT_CATEGORY_FILE_NAVIGATION, N_("File Navigation") },
{ GTH_SHORTCUT_CATEGORY_FILE_EDIT, N_("File Edit") },
{ GTH_SHORTCUT_CATEGORY_IMAGE_VIEW, N_("Viewer") },
{ GTH_SHORTCUT_CATEGORY_IMAGE_EDIT, N_("Image Edit") },
{ GTH_SHORTCUT_CATEGORY_SLIDESHOW, N_("Slideshow") },
};
static void
gth_main_register_default_file_loader (void)
{
......@@ -69,6 +80,7 @@ gth_main_register_default_types (void)
gth_main_register_type ("file-properties", GTH_TYPE_FILE_COMMENT);
gth_main_register_type ("file-properties", GTH_TYPE_FILE_DETAILS);
gth_main_register_default_file_loader ();
gth_main_register_shortcut_category (shortcut_categories);
gth_hook_add_callback ("dlg-preferences-construct", 1, G_CALLBACK (general__dlg_preferences_construct_cb), NULL);
gth_hook_add_callback ("dlg-preferences-apply", 1, G_CALLBACK (general__dlg_preferences_apply), NULL);
gth_hook_add_callback ("dlg-preferences-construct", 2, G_CALLBACK (browser__dlg_preferences_construct_cb), NULL);
......
......@@ -106,6 +106,8 @@ struct _GthMainPrivate {
GPtrArray *metadata_info;
GHashTable *metadata_info_hash;
gboolean metadata_info_sorted;
GPtrArray *shortcut_category_v;
GHashTable *shortcut_category_h;
GHashTable *sort_types;
GHashTable *image_loaders;
GHashTable *types;
......@@ -139,6 +141,9 @@ gth_main_finalize (GObject *object)
g_list_foreach (gth_main->priv->metadata_provider, (GFunc) g_object_unref, NULL);
g_list_free (gth_main->priv->metadata_provider);
g_ptr_array_unref (gth_main->priv->shortcut_category_v);
g_hash_table_unref (gth_main->priv->shortcut_category_h);
if (gth_main->priv->sort_types != NULL)
g_hash_table_unref (gth_main->priv->sort_types);
if (gth_main->priv->image_loaders != NULL)
......@@ -183,6 +188,8 @@ gth_main_init (GthMain *main)
main->priv->metadata_info = g_ptr_array_new ();
main->priv->metadata_info_hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
main->priv->metadata_info_sorted = FALSE;
main->priv->shortcut_category_v = g_ptr_array_new ();
main->priv->shortcut_category_h = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
main->priv->sort_types = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
main->priv->image_loaders = g_hash_table_new_full (g_str_hash,
(GEqualFunc) g_content_type_equals,
......@@ -635,6 +642,30 @@ gth_main_get_all_metadata_info (void)
}
GthShortcutCategory *
gth_main_get_shortcut_category (const char *id)
{
return g_hash_table_lookup (Main->priv->shortcut_category_h, id);
}
void
gth_main_register_shortcut_category (GthShortcutCategory *shortcut_category)
{
int i;
g_mutex_lock (&register_mutex);
for (i = 0; shortcut_category[i].id != NULL; i++) {
if (gth_main_get_shortcut_category (shortcut_category[i].id) == NULL) {
g_ptr_array_add (Main->priv->shortcut_category_v, &shortcut_category[i]);
g_hash_table_insert (Main->priv->shortcut_category_h, shortcut_category[i].id, &shortcut_category[i]);
}
}
g_mutex_unlock (&register_mutex);
}
void
gth_main_register_sort_type (GthFileDataSort *sort_type)
{
......
......@@ -35,6 +35,7 @@
#include "gth-image-saver.h"
#include "gth-metadata-provider.h"
#include "gth-monitor.h"
#include "gth-shortcut.h"
#include "gth-tags-file.h"
#include "gth-test.h"
#include "pixbuf-io.h"
......@@ -85,6 +86,8 @@ GthMetadataProvider * gth_main_get_metadata_writer (const char
GthMetadataCategory * gth_main_get_metadata_category (const char *id);
GthMetadataInfo * gth_main_get_metadata_info (const char *id);
GList * gth_main_get_all_metadata_info (void);
void gth_main_register_shortcut_category (GthShortcutCategory *shortcut_category);
GthShortcutCategory * gth_main_get_shortcut_category (const char *id);
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);
......
......@@ -36,7 +36,7 @@ gth_shortcut_new (void)
shortcut->action_name = NULL;
shortcut->description = NULL;
shortcut->context = 0;
shortcut->category = 0;
shortcut->category = NULL;
shortcut->default_accelerator = NULL;
shortcut->accelerator = NULL;
shortcut->label = NULL;
......
......@@ -27,14 +27,27 @@
G_BEGIN_DECLS
#define GTH_SHORTCUT_CONTEXT_INTERNAL -1
#define GTH_SHORTCUT_CATEGORY_HIDDEN -1
#define GTH_SHORTCUT_CATEGORY_HIDDEN "hidden"
#define GTH_SHORTCUT_CATEGORY_UI "ui"
#define GTH_SHORTCUT_CATEGORY_FILE_NAVIGATION "file-navigation"
#define GTH_SHORTCUT_CATEGORY_FILE_EDIT "file-edit"
#define GTH_SHORTCUT_CATEGORY_IMAGE_VIEW "image-view"
#define GTH_SHORTCUT_CATEGORY_IMAGE_EDIT "image-edit"
#define GTH_SHORTCUT_CATEGORY_SLIDESHOW "slideshow"
typedef struct {
char *id;
char *display_name;
} GthShortcutCategory;
typedef struct {
char *action_name;
char *description;
int context;
int category;
char *category;
char *default_accelerator;
char *accelerator;
char *label;
......
......@@ -22,6 +22,7 @@
#include <config.h>
#include <gtk/gtk.h>
#include "glib-utils.h"
#include "gth-main.h"
#include "gth-window.h"
#include "gth-window-title.h"
#include "gtk-utils.h"
......@@ -822,6 +823,27 @@ gth_window_get_shortcuts (GthWindow *window)
}
static int
sort_shortcuts_by_category (gconstpointer a,
gconstpointer b)
{
const GthShortcut *sa = * (GthShortcut **) a;
const GthShortcut *sb = * (GthShortcut **) b;
return g_strcmp0 (sa->category, sb->category);
}
GPtrArray *
gth_window_get_shortcuts_by_category (GthWindow *window)
{
g_return_val_if_fail (GTH_IS_WINDOW (window), NULL);
g_ptr_array_sort (window->priv->shortcuts_v, sort_shortcuts_by_category);
return window->priv->shortcuts_v;
}
gboolean
gth_window_activate_shortcut (GthWindow *window,
int context,
......
......@@ -125,6 +125,8 @@ void gth_window_add_shortcuts (GthWindow *window,
const GthShortcut *shortcuts,
int n_shortcuts);
GPtrArray * gth_window_get_shortcuts (GthWindow *window);
GPtrArray * gth_window_get_shortcuts_by_category
(GthWindow *window);
gboolean gth_window_activate_shortcut (GthWindow *window,
int context,
guint keycode,
......
......@@ -143,16 +143,6 @@ typedef enum /*< skip >*/ {
} GthShortcutContext;
typedef enum {
GTH_SHORTCUT_CATEGORY_UI,
GTH_SHORTCUT_CATEGORY_FILE_NAVIGATION,
GTH_SHORTCUT_CATEGORY_FILE_EDIT,
GTH_SHORTCUT_CATEGORY_IMAGE_VIEW,
GTH_SHORTCUT_CATEGORY_IMAGE_EDIT,
GTH_SHORTCUT_CATEGORY_SLIDESHOW
} GthShortcutCategory;
typedef void (*DataFunc) (gpointer user_data);
typedef void (*ReadyFunc) (GError *error,
gpointer user_data);
......
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