summaryrefslogtreecommitdiff
path: root/gtk/gtkfilechooserdefault.c
diff options
context:
space:
mode:
authorFederico Mena Quintero <federico@gnome.org>2011-09-05 13:19:17 -0500
committerFederico Mena Quintero <federico@gnome.org>2011-09-05 13:22:01 -0500
commit668287b9401e6b508e6164cd5b2bab2613857d6a (patch)
tree47bb4fd05e3686b974ba3877ec1c4ed68f7e1393 /gtk/gtkfilechooserdefault.c
parent6eb777a8afb9d0a8b868cc6e71da85bcc4c7fa9c (diff)
downloadgtk+-668287b9401e6b508e6164cd5b2bab2613857d6a.tar.gz
Factor out functions to create contextual menu items for the file list
Signed-off-by: Federico Mena Quintero <federico@gnome.org>
Diffstat (limited to 'gtk/gtkfilechooserdefault.c')
-rw-r--r--gtk/gtkfilechooserdefault.c69
1 files changed, 41 insertions, 28 deletions
diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c
index 7eaaef2830..8ff8196958 100644
--- a/gtk/gtkfilechooserdefault.c
+++ b/gtk/gtkfilechooserdefault.c
@@ -4100,6 +4100,39 @@ check_copy_file_location_sensitivity (GtkFileChooserDefault *impl)
gtk_widget_set_sensitive (impl->browse_files_popup_menu_copy_file_location_item, active);
}
+static GtkWidget *
+file_list_add_image_menu_item (GtkFileChooserDefault *impl,
+ const char *stock_name,
+ const char *mnemonic_label,
+ GCallback callback)
+{
+ GtkWidget *item;
+
+ item = gtk_image_menu_item_new_with_mnemonic (mnemonic_label);
+ gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
+ gtk_image_new_from_stock (stock_name, GTK_ICON_SIZE_MENU));
+ g_signal_connect (item, "activate", callback, impl);
+ gtk_widget_show (item);
+ gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item);
+
+ return item;
+}
+
+static GtkWidget *
+file_list_add_check_menu_item (GtkFileChooserDefault *impl,
+ const char *mnemonic_label,
+ GCallback callback)
+{
+ GtkWidget *item;
+
+ item = gtk_check_menu_item_new_with_mnemonic (mnemonic_label);
+ g_signal_connect (item, "toggled", callback, impl);
+ gtk_widget_show (item);
+ gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item);
+
+ return item;
+}
+
/* Constructs the popup menu for the file list if needed */
static void
file_list_build_popup_menu (GtkFileChooserDefault *impl)
@@ -4114,41 +4147,21 @@ file_list_build_popup_menu (GtkFileChooserDefault *impl)
impl->browse_files_tree_view,
popup_menu_detach_cb);
- item = gtk_image_menu_item_new_with_mnemonic (_("_Copy file's location"));
- impl->browse_files_popup_menu_copy_file_location_item = item;
- gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
- gtk_image_new_from_stock (GTK_STOCK_COPY, GTK_ICON_SIZE_MENU));
- g_signal_connect (item, "activate",
- G_CALLBACK (copy_file_location_cb), impl);
- gtk_widget_show (item);
- gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item);
+ impl->browse_files_popup_menu_copy_file_location_item = file_list_add_image_menu_item (impl, GTK_STOCK_COPY, _("_Copy file's location"),
+ G_CALLBACK (copy_file_location_cb));
- item = gtk_image_menu_item_new_with_mnemonic (_("_Add to Bookmarks"));
- impl->browse_files_popup_menu_add_shortcut_item = item;
- gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
- gtk_image_new_from_stock (GTK_STOCK_ADD, GTK_ICON_SIZE_MENU));
- g_signal_connect (item, "activate",
- G_CALLBACK (add_to_shortcuts_cb), impl);
- gtk_widget_show (item);
- gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item);
+ impl->browse_files_popup_menu_add_shortcut_item = file_list_add_image_menu_item (impl, GTK_STOCK_ADD, _("_Add to Bookmarks"),
+ G_CALLBACK (add_to_shortcuts_cb));
item = gtk_separator_menu_item_new ();
gtk_widget_show (item);
gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item);
- item = gtk_check_menu_item_new_with_mnemonic (_("Show _Hidden Files"));
- impl->browse_files_popup_menu_hidden_files_item = item;
- g_signal_connect (item, "toggled",
- G_CALLBACK (show_hidden_toggled_cb), impl);
- gtk_widget_show (item);
- gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item);
+ impl->browse_files_popup_menu_hidden_files_item = file_list_add_check_menu_item (impl, _("Show _Hidden Files"),
+ G_CALLBACK (show_hidden_toggled_cb));
- item = gtk_check_menu_item_new_with_mnemonic (_("Show _Size Column"));
- impl->browse_files_popup_menu_size_column_item = item;
- g_signal_connect (item, "toggled",
- G_CALLBACK (show_size_column_toggled_cb), impl);
- gtk_widget_show (item);
- gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item);
+ impl->browse_files_popup_menu_size_column_item = file_list_add_check_menu_item (impl, _("Show _Size Column"),
+ G_CALLBACK (show_size_column_toggled_cb));
bookmarks_check_add_sensitivity (impl);
check_copy_file_location_sensitivity (impl);