[gthumb/ext: 31/79] Added a 'open with' submenu in the file context menu
- From: Paolo Bacchilega <paobac src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gthumb/ext: 31/79] Added a 'open with' submenu in the file context menu
- Date: Sun, 2 Aug 2009 20:26:30 +0000 (UTC)
commit db25573c45e5be8089dd03dd5e64ba27ac09ffca
Author: Paolo Bacchilega <paobac src gnome org>
Date: Wed Jul 1 19:04:43 2009 +0200
Added a 'open with' submenu in the file context menu
extensions/file_manager/actions.c | 2 +-
gthumb/gth-browser-actions-callbacks.c | 17 ++++-
gthumb/gth-browser-actions-callbacks.h | 2 +-
gthumb/gth-browser-actions-entries.h | 9 +-
gthumb/gth-browser-ui.h | 14 ++--
gthumb/gth-browser.c | 133 +++++++++++++++++++++++++++++++-
6 files changed, 161 insertions(+), 16 deletions(-)
---
diff --git a/extensions/file_manager/actions.c b/extensions/file_manager/actions.c
index 46f187e..b62a350 100644
--- a/extensions/file_manager/actions.c
+++ b/extensions/file_manager/actions.c
@@ -414,7 +414,7 @@ gth_browser_activate_action_edit_delete (GtkAction *action,
GthBrowser *browser)
{
GList *items;
- GList *file_list = NULL;
+ GList *file_list;
int file_count;
char *prompt;
GtkWidget *d;
diff --git a/gthumb/gth-browser-actions-callbacks.c b/gthumb/gth-browser-actions-callbacks.c
index 8778750..186a2ef 100644
--- a/gthumb/gth-browser-actions-callbacks.c
+++ b/gthumb/gth-browser-actions-callbacks.c
@@ -31,6 +31,7 @@
#include "gconf-utils.h"
#include "glib-utils.h"
#include "gth-browser.h"
+#include "gth-file-list.h"
#include "gth-file-selection.h"
#include "gth-folder-tree.h"
#include "gth-main.h"
@@ -69,10 +70,20 @@ gth_browser_activate_action_bookmarks_edit (GtkAction *action,
void
-gth_browser_activate_action_file_open_with (GtkAction *action,
- GthBrowser *browser)
+gth_browser_activate_action_file_open (GtkAction *action,
+ GthBrowser *browser)
{
- /* FIXME */
+ GList *items;
+ GList *file_list;
+
+ items = gth_file_selection_get_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));
+ file_list = gth_file_list_get_files (GTH_FILE_LIST (gth_browser_get_file_list (browser)), items);
+
+ if (file_list != NULL)
+ gth_browser_load_file (browser, (GthFileData *) file_list->data, TRUE);
+
+ _g_object_list_unref (file_list);
+ _gtk_tree_path_list_free (items);
}
diff --git a/gthumb/gth-browser-actions-callbacks.h b/gthumb/gth-browser-actions-callbacks.h
index f0aef4c..515c34c 100644
--- a/gthumb/gth-browser-actions-callbacks.h
+++ b/gthumb/gth-browser-actions-callbacks.h
@@ -34,7 +34,7 @@ DEFINE_ACTION(gth_browser_activate_action_edit_metadata)
DEFINE_ACTION(gth_browser_activate_action_edit_preferences)
DEFINE_ACTION(gth_browser_activate_action_edit_extensions)
DEFINE_ACTION(gth_browser_activate_action_edit_select_all)
-DEFINE_ACTION(gth_browser_activate_action_file_open_with)
+DEFINE_ACTION(gth_browser_activate_action_file_open)
DEFINE_ACTION(gth_browser_activate_action_file_new_window)
DEFINE_ACTION(gth_browser_activate_action_file_revert)
DEFINE_ACTION(gth_browser_activate_action_file_save)
diff --git a/gthumb/gth-browser-actions-entries.h b/gthumb/gth-browser-actions-entries.h
index d92da20..eabd204 100644
--- a/gthumb/gth-browser-actions-entries.h
+++ b/gthumb/gth-browser-actions-entries.h
@@ -34,16 +34,17 @@ static GtkActionEntry gth_browser_action_entries[] = {
{ "GoMenu", NULL, N_("_Go") },
{ "BookmarksMenu", NULL, N_("_Bookmarks") },
{ "HelpMenu", NULL, N_("_Help") },
+ { "OpenWithMenu", NULL, N_("Open _With") },
{ "File_NewWindow", "window-new",
N_("New _Window"), "<control>N",
N_("Open another window"),
G_CALLBACK (gth_browser_activate_action_file_new_window) },
- { "File_OpenWith", GTK_STOCK_OPEN,
- N_("_Open With..."), "",
- N_("Open selected images with an application"),
- G_CALLBACK (gth_browser_activate_action_file_open_with) },
+ { "File_Open", GTK_STOCK_OPEN,
+ NULL, NULL,
+ NULL,
+ G_CALLBACK (gth_browser_activate_action_file_open) },
{ "File_Save", GTK_STOCK_SAVE,
NULL, "<control>S",
diff --git a/gthumb/gth-browser-ui.h b/gthumb/gth-browser-ui.h
index e8fb5a3..33e8f4c 100644
--- a/gthumb/gth-browser-ui.h
+++ b/gthumb/gth-browser-ui.h
@@ -69,6 +69,10 @@ static const char *fixed_ui_info =
" <separator/>"
" <placeholder name='File_Actions'/>"
" <separator/>"
+" <menuitem action='View_ShowHiddenFiles'/>"
+" <menuitem action='View_Sort_By'/>"
+" <menuitem action='View_Filters'/>"
+" <separator/>"
" <placeholder name='Folder_Actions'/>"
" </menu>"
" <menu name='Go' action='GoMenu'>"
@@ -146,7 +150,9 @@ static const char *fixed_ui_info =
" </popup>"
" <popup name='FileListPopup'>"
-" <menuitem action='File_OpenWith'/>"
+" <menuitem name='Open' action='File_Open'/>"
+" <menu name='OpenWith' action='OpenWithMenu'>"
+" </menu>"
" <separator/>"
" <placeholder name='File_Actions'/>"
" <separator/>"
@@ -185,10 +191,6 @@ static const char *browser_ui_info =
" <menuitem action='View_Filterbar'/>"
" </placeholder>"
" <placeholder name='Folder_Actions'>"
-" <menuitem action='View_ShowHiddenFiles'/>"
-" <menuitem action='View_Sort_By'/>"
-" <menuitem action='View_Filters'/>"
-" <separator/>"
" <menuitem action='View_Thumbnails'/>"
" </placeholder>"
" </menu>"
@@ -214,7 +216,7 @@ static const char *viewer_ui_info =
" </placeholder>"
" </menu>"
" <menu name='View' action='ViewMenu'>"
-" <placeholder name='File_Actions'>"
+" <placeholder name='Folder_Actions'>"
" <menuitem action='View_BrowserMode'/>"
" </placeholder>"
" </menu>"
diff --git a/gthumb/gth-browser.c b/gthumb/gth-browser.c
index afd7de6..225142b 100644
--- a/gthumb/gth-browser.c
+++ b/gthumb/gth-browser.c
@@ -435,6 +435,16 @@ gth_browser_update_title (GthBrowser *browser)
else
g_string_append (title, _("gthumb"));
+ if (browser->priv->current_file != NULL) {
+ GthFileStore *file_store;
+ int pos;
+
+ file_store = gth_browser_get_file_store (browser);
+ pos = gth_file_store_find_visible (file_store, browser->priv->current_file->file);
+ if (pos >= 0)
+ g_string_append_printf (title, " (%d/%d)", pos + 1, gth_file_store_n_visibles (file_store));
+ }
+
gtk_window_set_title (GTK_WINDOW (browser), title->str);
g_string_free (title, TRUE);
@@ -469,6 +479,7 @@ gth_browser_update_sensitivity (GthBrowser *browser)
n_files = gth_file_store_n_visibles (gth_browser_get_file_store (browser));
n_selected = gth_file_selection_get_n_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));
+ _gth_browser_set_action_sensitive (browser, "File_Open", n_selected == 1);
_gth_browser_set_action_sensitive (browser, "File_Save", viewer_can_save && modified);
_gth_browser_set_action_sensitive (browser, "File_SaveAs", viewer_can_save);
_gth_browser_set_action_sensitive (browser, "File_Revert", viewer_can_save && modified);
@@ -2245,6 +2256,125 @@ gth_file_list_button_press_cb (GtkWidget *widget,
static void
+activate_open_with_application_item (GtkMenuItem *menuitem,
+ gpointer data)
+{
+ GthBrowser *browser = data;
+ GList *items;
+ GList *file_list;
+ GList *uris;
+ GList *scan;
+ GAppInfo *appinfo;
+ GError *error = NULL;
+
+ items = gth_file_selection_get_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));
+ file_list = gth_file_list_get_files (GTH_FILE_LIST (gth_browser_get_file_list (browser)), items);
+
+ uris = NULL;
+ for (scan = file_list; scan; scan = scan->next) {
+ GthFileData *file_data = scan->data;
+ uris = g_list_prepend (uris, g_file_get_uri (file_data->file));
+ }
+
+ appinfo = g_object_get_data (G_OBJECT (menuitem), "appinfo");
+ g_return_if_fail (G_IS_APP_INFO (appinfo));
+
+ if (! g_app_info_launch_uris (appinfo, uris, NULL, &error))
+ _gtk_error_dialog_from_gerror_show (GTK_WINDOW (browser),
+ _("Could not perform the operation"),
+ &error);
+
+ g_list_free (uris);
+ _g_object_list_unref (file_list);
+ _gtk_tree_path_list_free (items);
+}
+
+
+static void
+_gth_browser_update_open_menu (GthBrowser *browser)
+{
+ GtkWidget *openwith_item;
+ GtkWidget *menu;
+ GList *items;
+ GList *file_list;
+ GList *scan;
+ GList *appinfo_list;
+ GHashTable *used_apps;
+
+ openwith_item = gtk_ui_manager_get_widget (browser->priv->ui, "/FileListPopup/OpenWith");
+ menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (openwith_item));
+ _gtk_container_remove_children (GTK_CONTAINER (menu), NULL, NULL);
+
+ items = gth_file_selection_get_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));
+ file_list = gth_file_list_get_files (GTH_FILE_LIST (gth_browser_get_file_list (browser)), items);
+
+ appinfo_list = NULL;
+ for (scan = file_list; scan; scan = scan->next) {
+ GthFileData *file_data = scan->data;
+ const char *mime_type;
+
+ mime_type = gth_file_data_get_mime_type (file_data);
+ if ((mime_type == NULL) || g_content_type_is_unknown (mime_type))
+ continue;
+
+ appinfo_list = g_list_concat (appinfo_list, g_app_info_get_all_for_type (mime_type));
+ }
+
+ used_apps = g_hash_table_new (g_str_hash, g_str_equal);
+ for (scan = appinfo_list; scan; scan = scan->next) {
+ GAppInfo *appinfo = scan->data;
+ char *label;
+ GtkWidget *menu_item;
+ GIcon *icon;
+ GdkPixbuf *pixbuf;
+
+ if (strcmp (g_app_info_get_executable (appinfo), "gthumb") == 0)
+ continue;
+ if (g_hash_table_lookup (used_apps, g_app_info_get_id (appinfo)) != NULL)
+ continue;
+ g_hash_table_insert (used_apps, (gpointer) g_app_info_get_id (appinfo), GINT_TO_POINTER (1));
+
+ label = g_strdup_printf (_("Open with \"%s\""), g_app_info_get_name (appinfo));
+ menu_item = gtk_image_menu_item_new_with_label (label);
+
+ icon = g_app_info_get_icon (appinfo);
+ pixbuf = gth_icon_cache_get_pixbuf (browser->priv->menu_icon_cache, icon);
+ gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), gtk_image_new_from_pixbuf (pixbuf));
+
+ gtk_widget_show (menu_item);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
+
+ g_object_set_data (G_OBJECT (menu_item), "appinfo", appinfo);
+ g_signal_connect (menu_item,
+ "activate",
+ G_CALLBACK (activate_open_with_application_item),
+ browser);
+
+ g_object_unref (pixbuf);
+ g_free (label);
+ }
+
+ /*
+ if (appinfo_list == NULL) {
+ GtkWidget *menu_item;
+
+ menu_item = gtk_image_menu_item_new_with_label (_("No application available"));
+ gtk_widget_set_sensitive (menu_item, FALSE);
+ gtk_widget_show (menu_item);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
+ }*/
+
+ gtk_widget_set_sensitive (openwith_item, appinfo_list != NULL);
+ gtk_widget_show (openwith_item);
+
+ g_hash_table_destroy (used_apps);
+ g_list_free (appinfo_list);
+ _g_object_list_unref (file_list);
+ _gtk_tree_path_list_free (items);
+}
+
+
+static void
gth_file_view_selection_changed_cb (GtkIconView *iconview,
gpointer user_data)
{
@@ -2253,6 +2383,7 @@ gth_file_view_selection_changed_cb (GtkIconView *iconview,
gth_browser_update_sensitivity (browser);
_gth_browser_update_statusbar_list_info (browser);
+ _gth_browser_update_open_menu (browser);
if (gth_window_get_current_page (GTH_WINDOW (browser)) != GTH_BROWSER_PAGE_BROWSER)
return;
@@ -3120,10 +3251,10 @@ gth_browser_set_sort_order (GthBrowser *browser,
browser->priv->sort_type = sort_type;
browser->priv->sort_inverse = inverse;
-
gth_file_list_set_sort_func (GTH_FILE_LIST (browser->priv->file_list),
browser->priv->sort_type->cmp_func,
browser->priv->sort_inverse);
+ gth_browser_update_title (browser);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]