Commit efb72fd1 authored by Paolo Bacchilega's avatar Paolo Bacchilega
Browse files

made the keyword shortcuts extensible

parent ab32be07
......@@ -24,6 +24,7 @@
#include <config.h>
#include <glib/gi18n.h>
#include <glib-object.h>
#include <gdk/gdkkeysyms.h>
#include <gthumb.h>
#include "actions.h"
......@@ -608,3 +609,33 @@ fm__gth_browser_unrealize_cb (GthBrowser *browser)
G_CALLBACK (clipboard_owner_change_cb),
browser);
}
gpointer
fm__gth_browser_file_list_key_press_cb (GthBrowser *browser,
GdkEventKey *event)
{
gpointer result = NULL;
GList *items;
GList *file_data_list;
GList *file_list;
if ((event->state & GDK_CONTROL_MASK) || (event->state & GDK_MOD1_MASK))
return NULL;
switch (gdk_keyval_to_lower (event->keyval)) {
case GDK_g:
items = gth_file_selection_get_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));
file_data_list = gth_file_list_get_files (GTH_FILE_LIST (gth_browser_get_file_list (browser)), items);
file_list = gth_file_data_list_to_file_list (file_data_list);
_g_launch_command (GTK_WIDGET (browser), "gimp", "Gimp", file_list);
_g_object_list_unref (file_list);
_g_object_list_unref (file_data_list);
_gtk_tree_path_list_free (items);
result = GINT_TO_POINTER (1);
break;
}
return result;
}
......@@ -25,17 +25,19 @@
#include <gthumb.h>
void fm__gth_browser_construct_cb (GthBrowser *browser);
void fm__gth_browser_update_sensitivity_cb (GthBrowser *browser);
void fm__gth_browser_set_current_page_cb (GthBrowser *browser);
void fm__gth_browser_load_location_after_cb (GthBrowser *browser,
GFile *location,
GError *error);
void fm__gth_browser_folder_tree_popup_before_cb (GthBrowser *browser,
GthFileSource *file_source,
GFile *folder);
void fm__gth_browser_selection_changed_cb (GthBrowser *browser);
void fm__gth_browser_realize_cb (GthBrowser *browser);
void fm__gth_browser_unrealize_cb (GthBrowser *browser);
void fm__gth_browser_construct_cb (GthBrowser *browser);
void fm__gth_browser_update_sensitivity_cb (GthBrowser *browser);
void fm__gth_browser_set_current_page_cb (GthBrowser *browser);
void fm__gth_browser_load_location_after_cb (GthBrowser *browser,
GFile *location,
GError *error);
void fm__gth_browser_folder_tree_popup_before_cb (GthBrowser *browser,
GthFileSource *file_source,
GFile *folder);
void fm__gth_browser_selection_changed_cb (GthBrowser *browser);
void fm__gth_browser_realize_cb (GthBrowser *browser);
void fm__gth_browser_unrealize_cb (GthBrowser *browser);
gpointer fm__gth_browser_file_list_key_press_cb (GthBrowser *browser,
GdkEventKey *event);
#endif /* CALLBACKS_H */
......@@ -38,6 +38,7 @@ gthumb_extension_activate (void)
gth_hook_add_callback ("gth-browser-realize", 10, G_CALLBACK (fm__gth_browser_realize_cb), NULL);
gth_hook_add_callback ("gth-browser-unrealize", 10, G_CALLBACK (fm__gth_browser_unrealize_cb), NULL);
gth_hook_add_callback ("gth-browser-selection-changed", 10, G_CALLBACK (fm__gth_browser_selection_changed_cb), NULL);
gth_hook_add_callback ("gth-browser-file-list-key-press", 10, G_CALLBACK (fm__gth_browser_file_list_key_press_cb), NULL);
}
......
......@@ -262,7 +262,7 @@ viewer_key_press_cb (GtkWidget *widget,
return TRUE;
}
return FALSE;
return gth_hook_invoke_get ("gth-browser-file-list-key-press", self->priv->browser, event) != NULL;
}
......
......@@ -22,6 +22,7 @@
#include <config.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include "dlg-personalize-filters.h"
#include "gconf-utils.h"
#include "glib-utils.h"
......@@ -2633,6 +2634,58 @@ gth_file_view_item_activated_cb (GtkIconView *iconview,
}
static gboolean
gth_file_list_key_press_cb (GtkWidget *widget,
GdkEventKey *event,
gpointer user_data)
{
GthBrowser *browser = user_data;
gboolean result = FALSE;
if (! (event->state & GDK_CONTROL_MASK) && ! (event->state & GDK_MOD1_MASK)) {
switch (gdk_keyval_to_lower (event->keyval)) {
case GDK_f:
gth_browser_fullscreen (browser);
result = TRUE;
break;
/* FIXME: add these to the image viewer
case GDK_b:
case GDK_BackSpace:
gth_browser_show_prev_image (browser, FALSE, FALSE);
result = TRUE;
break;
case GDK_n:
gth_browser_show_next_image (browser, FALSE, FALSE);
result = TRUE;
break;
*/
/* FIXME: add these to the rotate extension
case GDK_bracketright:
gth_window_activate_action_tools_jpeg_rotate_right (NULL, window);
result = TRUE;
break;
case GDK_bracketleft:
gth_window_activate_action_tools_jpeg_rotate_left (NULL, window);
result = TRUE;
break;
*/
default:
break;
}
}
if (! result)
result = gth_hook_invoke_get ("gth-browser-file-list-key-press", browser, event) != NULL;
return result;
}
static void
add_browser_toolbar_menu_buttons (GthBrowser *browser)
{
......@@ -3136,6 +3189,10 @@ _gth_browser_construct (GthBrowser *browser)
"item_activated",
G_CALLBACK (gth_file_view_item_activated_cb),
browser);
g_signal_connect (G_OBJECT (browser->priv->file_list),
"key_press_event",
G_CALLBACK (gth_file_list_key_press_cb),
browser);
browser->priv->file_list_popup = gtk_ui_manager_get_widget (browser->priv->ui, "/FileListPopup");
......
......@@ -126,6 +126,14 @@ gth_main_register_default_hooks (void)
**/
gth_hook_register ("gth-browser-selection-changed", 1);
/**
* Called after a key press in the file list
*
* @browser (GthBrowser*): the relative window.
* @event (GdkEventKey *); the key event.
*/
gth_hook_register ("gth-browser-file-list-key-press", 2);
/**
* Called in _gdk_pixbuf_save_async
*
......
......@@ -1049,3 +1049,31 @@ _gtk_paned_set_position2 (GtkPaned *paned,
if (pos > 0)
gtk_paned_set_position (paned, size - pos);
}
void
_g_launch_command (GtkWidget *parent,
const char *command,
const char *name,
GList *files)
{
GError *error = NULL;
GAppInfo *app_info;
GdkAppLaunchContext *launch_context;
app_info = g_app_info_create_from_commandline (command, name, G_APP_INFO_CREATE_SUPPORTS_URIS, &error);
if (app_info == NULL) {
_gtk_error_dialog_from_gerror_show(GTK_WINDOW (parent), _("Could not launch the application"), &error);
return;
}
launch_context = gdk_app_launch_context_new ();
gdk_app_launch_context_set_screen (launch_context, gtk_widget_get_screen (parent));
if (! g_app_info_launch (app_info, files, G_APP_LAUNCH_CONTEXT (launch_context), &error)) {
_gtk_error_dialog_from_gerror_show(GTK_WINDOW (parent), _("Could not launch the application"), &error);
return;
}
g_object_unref (app_info);
}
......@@ -117,6 +117,10 @@ void _gtk_tree_path_list_free (GList *list);
int _gtk_paned_get_position2 (GtkPaned *paned);
void _gtk_paned_set_position2 (GtkPaned *paned,
int pos);
void _g_launch_command (GtkWidget *parent,
const char *command,
const char *name,
GList *files);
G_END_DECLS
......
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