Commit ac8dd5dd authored by Paolo Bacchilega's avatar Paolo Bacchilega

file manager: converted accelerators to customizable shortcuts

parent f4a23f68
......@@ -543,6 +543,70 @@ gth_browser_activate_delete (GSimpleAction *action,
}
static void
remove_from_source (GthBrowser *browser,
gboolean permanently)
{
GthFileSource *source;
GthFileData *location;
GList *items;
GList *file_data_list;
if (permanently) {
/* Use the VFS file source to delete the files from the
* disk. */
source = gth_main_get_file_source_for_uri ("file:///");
location = NULL;
}
else {
/* Removes the files from the current location,
* for example: when viewing a catalog removes
* the files from the catalog; when viewing a
* folder removes the files from the folder. */
source = _g_object_ref (gth_browser_get_location_source (browser));
location = gth_browser_get_location_data (browser);
}
if (source == NULL)
return;
items = gth_file_selection_get_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));
if (items == NULL)
return;
file_data_list = gth_file_list_get_files (GTH_FILE_LIST (gth_browser_get_file_list (browser)), items);
gth_file_source_remove (source,
location,
file_data_list,
permanently,
GTK_WINDOW (browser));
_g_object_list_unref (file_data_list);
_gtk_tree_path_list_free (items);
_g_object_unref (source);
}
void
gth_browser_activate_remove_from_source (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
remove_from_source (GTH_BROWSER (user_data), FALSE);
}
void
gth_browser_activate_remove_from_source_permanently (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
remove_from_source (GTH_BROWSER (user_data), TRUE);
}
void
gth_browser_activate_rename (GSimpleAction *action,
GVariant *parameter,
......@@ -993,3 +1057,27 @@ gth_browser_activate_folder_context_move_to (GSimpleAction *action,
{
copy_folder_to_folder (GTH_BROWSER (user_data), TRUE);
}
void
gth_browser_activate_open_with_gimp (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
GthBrowser *browser = user_data;
GList *items;
GList *file_data_list;
GList *file_list;
items = gth_file_selection_get_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));
if (items == NULL)
return;
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 %U", "Gimp", file_list);
_g_object_list_unref (file_list);
_g_object_list_unref (file_data_list);
_gtk_tree_path_list_free (items);
}
......@@ -31,6 +31,8 @@ DEF_ACTION_CALLBACK (gth_browser_activate_edit_paste)
DEF_ACTION_CALLBACK (gth_browser_activate_duplicate)
DEF_ACTION_CALLBACK (gth_browser_activate_trash)
DEF_ACTION_CALLBACK (gth_browser_activate_delete)
DEF_ACTION_CALLBACK (gth_browser_activate_remove_from_source)
DEF_ACTION_CALLBACK (gth_browser_activate_remove_from_source_permanently)
DEF_ACTION_CALLBACK (gth_browser_activate_rename)
DEF_ACTION_CALLBACK (gth_browser_activate_file_list_rename)
DEF_ACTION_CALLBACK (gth_browser_activate_copy_to_folder)
......@@ -47,6 +49,7 @@ DEF_ACTION_CALLBACK (gth_browser_activate_folder_context_delete)
DEF_ACTION_CALLBACK (gth_browser_activate_folder_context_copy_to)
DEF_ACTION_CALLBACK (gth_browser_activate_folder_context_move_to)
DEF_ACTION_CALLBACK (gth_browser_activate_open_with_gimp)
DEF_ACTION_CALLBACK (gth_browser_activate_open_with_application)
#endif /* ACTIONS_H */
......@@ -46,6 +46,8 @@ static const GActionEntry actions[] = {
{ "edit-paste", gth_browser_activate_edit_paste },
{ "trash", gth_browser_activate_trash },
{ "delete", gth_browser_activate_delete },
{ "remove-from-source", gth_browser_activate_remove_from_source },
{ "remove-from-source-permanently", gth_browser_activate_remove_from_source_permanently },
{ "rename", gth_browser_activate_rename },
{ "file-list-rename", gth_browser_activate_file_list_rename },
{ "duplicate", gth_browser_activate_duplicate },
......@@ -62,6 +64,7 @@ static const GActionEntry actions[] = {
{ "folder-context-move-to", gth_browser_activate_folder_context_move_to },
{ "folder-context-trash", gth_browser_activate_folder_context_trash },
{ "folder-context-delete", gth_browser_activate_folder_context_delete },
{ "open-with-gimp", gth_browser_activate_open_with_gimp },
{ "open-with-application", gth_browser_activate_open_with_application, "i" }
};
......@@ -117,11 +120,17 @@ static const GthMenuEntry vfs_entries[] = {
static const GthAccelerator accelerators[] = {
{ "win.rename", "F2" },
{ "win.edit-cut", "<Control>x" },
{ "win.edit-copy", "<Control>c" },
{ "win.edit-paste", "<Control>v" },
{ "win.duplicate", "<Control>d" },
};
static const GthShortcut shortcuts[] = {
{ "rename", N_("Rename File"), GTH_SHORTCUT_CONTEXT_BROWSER_VIEWER, GTH_SHORTCUT_CATEGORY_FILE_EDIT, "F2" },
{ "duplicate", N_("Duplicate File"), GTH_SHORTCUT_CONTEXT_VIEWER, GTH_SHORTCUT_CATEGORY_FILE_EDIT, "D" },
{ "remove-from-source", N_("Delete File"), GTH_SHORTCUT_CONTEXT_BROWSER_VIEWER, GTH_SHORTCUT_CATEGORY_FILE_EDIT, "Delete" },
{ "remove-from-source-permanently", N_("Delete File Permanently"), GTH_SHORTCUT_CONTEXT_BROWSER_VIEWER, GTH_SHORTCUT_CATEGORY_FILE_EDIT, "<shift>Delete" },
{ "open-with-gimp", N_("Open With Gimp"), GTH_SHORTCUT_CONTEXT_BROWSER_VIEWER, GTH_SHORTCUT_CATEGORY_FILE_EDIT, "G" },
};
......@@ -709,6 +718,9 @@ fm__gth_browser_construct_cb (GthBrowser *browser)
gth_window_add_accelerators (GTH_WINDOW (browser),
accelerators,
G_N_ELEMENTS (accelerators));
gth_window_add_shortcuts (GTH_WINDOW (browser),
shortcuts,
G_N_ELEMENTS (shortcuts));
gth_browser_add_header_bar_button (browser,
GTH_BROWSER_HEADER_SECTION_BROWSER_LOCATIONS,
......@@ -1170,80 +1182,3 @@ 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;
guint modifiers;
GList *items;
GList *file_data_list;
GList *file_list;
modifiers = gtk_accelerator_get_default_mod_mask ();
switch (event->keyval) {
case GDK_KEY_g:
if ((event->state & modifiers) == 0) {
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 %U", "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;
case GDK_KEY_Delete:
if (((event->state & modifiers) == 0)
|| ((event->state & modifiers) == GDK_SHIFT_MASK)
|| ((event->state & modifiers) == GDK_CONTROL_MASK))
{
GthFileSource *source;
GthFileData *location;
if ((event->state & modifiers) == 0) {
/* Removes the files from the current location,
* for example: when viewing a catalog removes
* the files from the catalog; when viewing a
* folder removes the files from the folder. */
source = _g_object_ref (gth_browser_get_location_source (browser));
location = gth_browser_get_location_data (browser);
}
else {
/* When a key modifier is active, use the VFS
* file source to delete the files from the
* disk. */
source = gth_main_get_file_source_for_uri ("file:///");
location = NULL;
}
if (source == NULL)
return result;
items = gth_file_selection_get_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));
if (items == NULL)
return result;
file_data_list = gth_file_list_get_files (GTH_FILE_LIST (gth_browser_get_file_list (browser)), items);
gth_file_source_remove (source,
location,
file_data_list,
(event->state & modifiers) == GDK_SHIFT_MASK,
GTK_WINDOW (browser));
result = GINT_TO_POINTER (1);
_g_object_list_unref (file_data_list);
_gtk_tree_path_list_free (items);
_g_object_unref (source);
}
break;
}
return result;
}
......@@ -40,7 +40,5 @@ void fm__gth_browser_folder_tree_drag_data_received_cb (GthBrowser *brow
void fm__gth_browser_folder_tree_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 */
......@@ -44,7 +44,6 @@ gthumb_extension_activate (void)
gth_hook_add_callback ("gth-browser-update-sensitivity", 10, G_CALLBACK (fm__gth_browser_update_sensitivity_cb), NULL);
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-file-list-key-press", 10, G_CALLBACK (fm__gth_browser_file_list_key_press_cb), NULL);
}
......
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