changeset 659:542bb47fef04

Merge vflist_pop_menu() and vficon_pop_menu() into vf_pop_menu().
author zas_
date Tue, 13 May 2008 20:13:44 +0000
parents dc09f544d292
children 19f39b9953eb
files src/view_file.c src/view_file.h src/view_file_icon.c src/view_file_icon.h src/view_file_list.c src/view_file_list.h
diffstat 6 files changed, 133 insertions(+), 164 deletions(-) [+]
line wrap: on
line diff
--- a/src/view_file.c	Tue May 13 19:56:52 2008 +0000
+++ b/src/view_file.c	Tue May 13 20:13:44 2008 +0000
@@ -17,6 +17,7 @@
 #include "info.h"
 #include "layout.h"
 #include "menu.h"
+#include "ui_menu.h"
 #include "utilops.h"
 #include "view_file_list.h"
 #include "view_file_icon.h"
@@ -485,7 +486,127 @@
 	}
 }
 
+GtkWidget *vf_pop_menu(ViewFile *vf)
+{
+	GtkWidget *menu;
+	GtkWidget *item;
+	GtkWidget *submenu;
+	gint active = 0;
 
+	switch(vf->type)
+	{
+	case FILEVIEW_LIST:
+		vflist_color_set(vf, VFLIST_INFO(vf, click_fd), TRUE);
+		active = (VFLIST_INFO(vf, click_fd) != NULL);
+		break;
+	case FILEVIEW_ICON:
+		active = (VFICON_INFO(vf, click_id) != NULL);
+		break;
+	}
+
+	menu = popup_menu_short_lived();
+
+	g_signal_connect(G_OBJECT(menu), "destroy",
+			 G_CALLBACK(vf_popup_destroy_cb), vf);
+
+	if (vf->clicked_mark > 0)
+		{
+		gint mark = vf->clicked_mark;
+		gchar *str_set_mark = g_strdup_printf(_("_Set mark %d"), mark);
+		gchar *str_res_mark = g_strdup_printf(_("_Reset mark %d"), mark);
+		gchar *str_toggle_mark = g_strdup_printf(_("_Toggle mark %d"), mark);
+		gchar *str_sel_mark = g_strdup_printf(_("_Select mark %d"), mark);
+		gchar *str_sel_mark_or = g_strdup_printf(_("_Add mark %d"), mark);
+		gchar *str_sel_mark_and = g_strdup_printf(_("_Intersection with mark %d"), mark);
+		gchar *str_sel_mark_minus = g_strdup_printf(_("_Unselect mark %d"), mark);
+
+		g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
+
+		vf->active_mark = mark;
+		vf->clicked_mark = 0;
+
+		menu_item_add_sensitive(menu, str_set_mark, active,
+					G_CALLBACK(vf_pop_menu_set_mark_sel_cb), vf);
+
+		menu_item_add_sensitive(menu, str_res_mark, active,
+					G_CALLBACK(vf_pop_menu_res_mark_sel_cb), vf);
+
+		menu_item_add_sensitive(menu, str_toggle_mark, active,
+					G_CALLBACK(vf_pop_menu_toggle_mark_sel_cb), vf);
+
+		menu_item_add_divider(menu);
+
+		menu_item_add_sensitive(menu, str_sel_mark, active,
+					G_CALLBACK(vf_pop_menu_sel_mark_cb), vf);
+		menu_item_add_sensitive(menu, str_sel_mark_or, active,
+					G_CALLBACK(vf_pop_menu_sel_mark_or_cb), vf);
+		menu_item_add_sensitive(menu, str_sel_mark_and, active,
+					G_CALLBACK(vf_pop_menu_sel_mark_and_cb), vf);
+		menu_item_add_sensitive(menu, str_sel_mark_minus, active,
+					G_CALLBACK(vf_pop_menu_sel_mark_minus_cb), vf);
+
+		menu_item_add_divider(menu);
+
+		g_free(str_set_mark);
+		g_free(str_res_mark);
+		g_free(str_toggle_mark);
+		g_free(str_sel_mark);
+		g_free(str_sel_mark_and);
+		g_free(str_sel_mark_or);
+		g_free(str_sel_mark_minus);
+		}
+
+	submenu_add_edit(menu, &item, G_CALLBACK(vf_pop_menu_edit_cb), vf);
+	gtk_widget_set_sensitive(item, active);
+
+	menu_item_add_stock_sensitive(menu, _("_Properties"), GTK_STOCK_PROPERTIES, active,
+				      G_CALLBACK(vf_pop_menu_info_cb), vf);
+	menu_item_add_stock_sensitive(menu, _("View in _new window"), GTK_STOCK_NEW, active,
+				      G_CALLBACK(vf_pop_menu_view_cb), vf);
+
+	menu_item_add_divider(menu);
+	menu_item_add_stock_sensitive(menu, _("_Copy..."), GTK_STOCK_COPY, active,
+				      G_CALLBACK(vf_pop_menu_copy_cb), vf);
+	menu_item_add_sensitive(menu, _("_Move..."), active,
+				G_CALLBACK(vf_pop_menu_move_cb), vf);
+	menu_item_add_sensitive(menu, _("_Rename..."), active,
+				G_CALLBACK(vf_pop_menu_rename_cb), vf);
+	menu_item_add_stock_sensitive(menu, _("_Delete..."), GTK_STOCK_DELETE, active,
+				      G_CALLBACK(vf_pop_menu_delete_cb), vf);
+	if (options->show_copy_path)
+		menu_item_add_sensitive(menu, _("_Copy path"), active,
+					G_CALLBACK(vf_pop_menu_copy_path_cb), vf);
+
+	menu_item_add_divider(menu);
+
+	submenu = submenu_add_sort(NULL, G_CALLBACK(vf_pop_menu_sort_cb), vf,
+				   FALSE, FALSE, TRUE, vf->sort_method);
+	menu_item_add_divider(submenu);
+	menu_item_add_check(submenu, _("Ascending"), vf->sort_ascend,
+			    G_CALLBACK(vf_pop_menu_sort_ascend_cb), vf);
+
+	item = menu_item_add(menu, _("_Sort"), NULL, NULL);
+	gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
+
+	menu_item_add_check(menu, _("View as _icons"), (vf->type == FILEVIEW_ICON),
+			    G_CALLBACK(vf_pop_menu_toggle_view_type_cb), vf);
+
+	switch(vf->type)
+	{
+	case FILEVIEW_LIST:
+		menu_item_add_check(menu, _("Show _thumbnails"), VFLIST_INFO(vf, thumbs_enabled),
+				    G_CALLBACK(vflist_pop_menu_thumbs_cb), vf);
+		break;
+	case FILEVIEW_ICON:
+		menu_item_add_check(menu, _("Show filename _text"), VFICON_INFO(vf, show_text),
+				    G_CALLBACK(vficon_pop_menu_show_names_cb), vf);
+		break;
+	}
+	
+	menu_item_add_stock(menu, _("Re_fresh"), GTK_STOCK_REFRESH, G_CALLBACK(vf_pop_menu_refresh_cb), vf);
+
+	return menu;
+}
 
 gint vf_refresh(ViewFile *vf)
 {
--- a/src/view_file.h	Tue May 13 19:56:52 2008 +0000
+++ b/src/view_file.h	Tue May 13 20:13:44 2008 +0000
@@ -57,6 +57,7 @@
 void vf_pop_menu_toggle_view_type_cb(GtkWidget *widget, gpointer data);
 void vf_pop_menu_refresh_cb(GtkWidget *widget, gpointer data);
 void vf_popup_destroy_cb(GtkWidget *widget, gpointer data);
+GtkWidget *vf_pop_menu(ViewFile *vf);
 
 FileData *vf_index_get_data(ViewFile *vf, gint row);
 gint vf_index_by_path(ViewFile *vf, const gchar *path);
--- a/src/view_file_icon.c	Tue May 13 19:56:52 2008 +0000
+++ b/src/view_file_icon.c	Tue May 13 20:13:44 2008 +0000
@@ -201,7 +201,7 @@
 	file_util_rename(NULL, vf_pop_menu_file_list(vf), vf->listview);
 }
 
-static void vficon_pop_menu_show_names_cb(GtkWidget *widget, gpointer data)
+void vficon_pop_menu_show_names_cb(GtkWidget *widget, gpointer data)
 {
 	ViewFile *vf = data;
 
@@ -223,61 +223,6 @@
 	vf->popup = NULL;
 }
 
-static GtkWidget *vficon_pop_menu(ViewFile *vf)
-{
-	GtkWidget *menu;
-	GtkWidget *item;
-	GtkWidget *submenu;
-	gint active;
-
-	active = (VFICON_INFO(vf, click_id) != NULL);
-
-	menu = popup_menu_short_lived();
-
-	g_signal_connect(G_OBJECT(menu), "destroy",
-			 G_CALLBACK(vf_popup_destroy_cb), vf);
-
-	submenu_add_edit(menu, &item, G_CALLBACK(vf_pop_menu_edit_cb), vf);
-	gtk_widget_set_sensitive(item, active);
-
-	menu_item_add_stock_sensitive(menu, _("_Properties"), GTK_STOCK_PROPERTIES, active,
-				      G_CALLBACK(vf_pop_menu_info_cb), vf);
-
-	menu_item_add_stock_sensitive(menu, _("View in _new window"), GTK_STOCK_NEW, active,
-				      G_CALLBACK(vficon_pop_menu_view_cb), vf);
-	menu_item_add_divider(menu);
-
-	menu_item_add_stock_sensitive(menu, _("_Copy..."), GTK_STOCK_COPY, active,
-				      G_CALLBACK(vf_pop_menu_copy_cb), vf);
-	menu_item_add_sensitive(menu, _("_Move..."), active,
-				G_CALLBACK(vf_pop_menu_move_cb), vf);
-	menu_item_add_sensitive(menu, _("_Rename..."), active,
-				G_CALLBACK(vf_pop_menu_rename_cb), vf);
-	menu_item_add_stock_sensitive(menu, _("_Delete..."), GTK_STOCK_DELETE, active,
-				      G_CALLBACK(vf_pop_menu_delete_cb), vf);
-	if (options->show_copy_path)
-		menu_item_add_sensitive(menu, _("_Copy path"), active,
-					G_CALLBACK(vf_pop_menu_copy_path_cb), vf);
-	menu_item_add_divider(menu);
-
-	submenu = submenu_add_sort(NULL, G_CALLBACK(vf_pop_menu_sort_cb), vf,
-				   FALSE, FALSE, TRUE, vf->sort_method);
-	menu_item_add_divider(submenu);
-	menu_item_add_check(submenu, _("Ascending"), vf->sort_ascend,
-			    G_CALLBACK(vf_pop_menu_sort_ascend_cb), vf);
-
-	item = menu_item_add(menu, _("_Sort"), NULL, NULL);
-	gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
-
-	menu_item_add_check(menu, _("View as _icons"), TRUE,
-			    G_CALLBACK(vf_pop_menu_toggle_view_type_cb), vf);
-	menu_item_add_check(menu, _("Show filename _text"), VFICON_INFO(vf, show_text),
-			    G_CALLBACK(vficon_pop_menu_show_names_cb), vf);
-	menu_item_add_stock(menu, _("Re_fresh"), GTK_STOCK_REFRESH, G_CALLBACK(vf_pop_menu_refresh_cb), vf);
-
-	return menu;
-}
-
 /*
  *-------------------------------------------------------------------
  * signals
@@ -1292,7 +1237,7 @@
 			vficon_selection_add(vf, VFICON_INFO(vf, click_id), SELECTION_PRELIGHT, NULL);
 			tip_unschedule(vf);
 
-			vf->popup = vficon_pop_menu(vf);
+			vf->popup = vf_pop_menu(vf);
 			gtk_menu_popup(GTK_MENU(vf->popup), NULL, NULL, vfi_menu_position_cb, vf, 0, GDK_CURRENT_TIME);
 			break;
 		default:
@@ -1396,7 +1341,7 @@
 #endif
 			break;
 		case MOUSE_BUTTON_RIGHT:
-			vf->popup = vficon_pop_menu(vf);
+			vf->popup = vf_pop_menu(vf);
 			gtk_menu_popup(GTK_MENU(vf->popup), NULL, NULL, NULL, NULL, bevent->button, bevent->time);
 			break;
 		default:
--- a/src/view_file_icon.h	Tue May 13 19:56:52 2008 +0000
+++ b/src/view_file_icon.h	Tue May 13 20:13:44 2008 +0000
@@ -32,6 +32,7 @@
 void vficon_pop_menu_rename_cb(GtkWidget *widget, gpointer data);
 void vficon_pop_menu_refresh_cb(GtkWidget *widget, gpointer data);
 void vficon_popup_destroy_cb(GtkWidget *widget, gpointer data);
+void vficon_pop_menu_show_names_cb(GtkWidget *widget, gpointer data);
 
 FileData *vficon_index_get_data(ViewFile *vf, gint row);
 gint vficon_index_by_path(ViewFile *vf, const gchar *path);
--- a/src/view_file_list.c	Tue May 13 19:56:52 2008 +0000
+++ b/src/view_file_list.c	Tue May 13 20:13:44 2008 +0000
@@ -142,7 +142,7 @@
 }
 
 
-static void vflist_color_set(ViewFile *vf, FileData *fd, gint color_set)
+void vflist_color_set(ViewFile *vf, FileData *fd, gint color_set)
 {
 	GtkTreeModel *store;
 	GtkTreeIter iter;
@@ -336,7 +336,7 @@
 	file_util_rename(NULL, list, vf->listview);
 }
 
-static void vflist_pop_menu_thumbs_cb(GtkWidget *widget, gpointer data)
+void vflist_pop_menu_thumbs_cb(GtkWidget *widget, gpointer data)
 {
 	ViewFile *vf = data;
 
@@ -368,108 +368,6 @@
 }
 
 
-static GtkWidget *vflist_pop_menu(ViewFile *vf)
-{
-	GtkWidget *menu;
-	GtkWidget *item;
-	GtkWidget *submenu;
-	gint active;
-
-	vflist_color_set(vf, VFLIST_INFO(vf, click_fd), TRUE);
-	active = (VFLIST_INFO(vf, click_fd) != NULL);
-
-	menu = popup_menu_short_lived();
-	g_signal_connect(G_OBJECT(menu), "destroy",
-			 G_CALLBACK(vf_popup_destroy_cb), vf);
-
-	if (vf->clicked_mark > 0)
-		{
-		gint mark = vf->clicked_mark;
-		gchar *str_set_mark = g_strdup_printf(_("_Set mark %d"), mark);
-		gchar *str_res_mark = g_strdup_printf(_("_Reset mark %d"), mark);
-		gchar *str_toggle_mark = g_strdup_printf(_("_Toggle mark %d"), mark);
-		gchar *str_sel_mark = g_strdup_printf(_("_Select mark %d"), mark);
-		gchar *str_sel_mark_or = g_strdup_printf(_("_Add mark %d"), mark);
-		gchar *str_sel_mark_and = g_strdup_printf(_("_Intersection with mark %d"), mark);
-		gchar *str_sel_mark_minus = g_strdup_printf(_("_Unselect mark %d"), mark);
-
-		g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
-
-		vf->active_mark = mark;
-		vf->clicked_mark = 0;
-
-		menu_item_add_sensitive(menu, str_set_mark, active,
-					G_CALLBACK(vf_pop_menu_set_mark_sel_cb), vf);
-
-		menu_item_add_sensitive(menu, str_res_mark, active,
-					G_CALLBACK(vf_pop_menu_res_mark_sel_cb), vf);
-
-		menu_item_add_sensitive(menu, str_toggle_mark, active,
-					G_CALLBACK(vf_pop_menu_toggle_mark_sel_cb), vf);
-
-		menu_item_add_divider(menu);
-
-		menu_item_add_sensitive(menu, str_sel_mark, active,
-					G_CALLBACK(vf_pop_menu_sel_mark_cb), vf);
-		menu_item_add_sensitive(menu, str_sel_mark_or, active,
-					G_CALLBACK(vf_pop_menu_sel_mark_or_cb), vf);
-		menu_item_add_sensitive(menu, str_sel_mark_and, active,
-					G_CALLBACK(vf_pop_menu_sel_mark_and_cb), vf);
-		menu_item_add_sensitive(menu, str_sel_mark_minus, active,
-					G_CALLBACK(vf_pop_menu_sel_mark_minus_cb), vf);
-
-		menu_item_add_divider(menu);
-
-		g_free(str_set_mark);
-		g_free(str_res_mark);
-		g_free(str_toggle_mark);
-		g_free(str_sel_mark);
-		g_free(str_sel_mark_and);
-		g_free(str_sel_mark_or);
-		g_free(str_sel_mark_minus);
-		}
-
-	submenu_add_edit(menu, &item, G_CALLBACK(vf_pop_menu_edit_cb), vf);
-	gtk_widget_set_sensitive(item, active);
-
-	menu_item_add_stock_sensitive(menu, _("_Properties"), GTK_STOCK_PROPERTIES, active,
-				      G_CALLBACK(vf_pop_menu_info_cb), vf);
-	menu_item_add_stock_sensitive(menu, _("View in _new window"), GTK_STOCK_NEW, active,
-				      G_CALLBACK(vf_pop_menu_view_cb), vf);
-
-	menu_item_add_divider(menu);
-	menu_item_add_stock_sensitive(menu, _("_Copy..."), GTK_STOCK_COPY, active,
-				      G_CALLBACK(vf_pop_menu_copy_cb), vf);
-	menu_item_add_sensitive(menu, _("_Move..."), active,
-				G_CALLBACK(vf_pop_menu_move_cb), vf);
-	menu_item_add_sensitive(menu, _("_Rename..."), active,
-				G_CALLBACK(vf_pop_menu_rename_cb), vf);
-	menu_item_add_stock_sensitive(menu, _("_Delete..."), GTK_STOCK_DELETE, active,
-				      G_CALLBACK(vf_pop_menu_delete_cb), vf);
-	if (options->show_copy_path)
-		menu_item_add_sensitive(menu, _("_Copy path"), active,
-					G_CALLBACK(vf_pop_menu_copy_path_cb), vf);
-
-	menu_item_add_divider(menu);
-
-	submenu = submenu_add_sort(NULL, G_CALLBACK(vf_pop_menu_sort_cb), vf,
-				   FALSE, FALSE, TRUE, vf->sort_method);
-	menu_item_add_divider(submenu);
-	menu_item_add_check(submenu, _("Ascending"), vf->sort_ascend,
-			    G_CALLBACK(vf_pop_menu_sort_ascend_cb), vf);
-
-	item = menu_item_add(menu, _("_Sort"), NULL, NULL);
-	gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
-
-	menu_item_add_check(menu, _("View as _icons"), FALSE,
-			    G_CALLBACK(vf_pop_menu_toggle_view_type_cb), vf);
-	menu_item_add_check(menu, _("Show _thumbnails"), VFLIST_INFO(vf, thumbs_enabled),
-			    G_CALLBACK(vflist_pop_menu_thumbs_cb), vf);
-	menu_item_add_stock(menu, _("Re_fresh"), GTK_STOCK_REFRESH, G_CALLBACK(vf_pop_menu_refresh_cb), vf);
-
-	return menu;
-}
-
 /*
  *-----------------------------------------------------------------------------
  * callbacks
@@ -562,7 +460,7 @@
 		VFLIST_INFO(vf, click_fd) = NULL;
 		}
 
-	vf->popup = vflist_pop_menu(vf);
+	vf->popup = vf_pop_menu(vf);
 	gtk_menu_popup(GTK_MENU(vf->popup), NULL, NULL, vflist_menu_position_cb, vf, 0, GDK_CURRENT_TIME);
 
 	return TRUE;
@@ -605,7 +503,7 @@
 
 	if (bevent->button == MOUSE_BUTTON_RIGHT)
 		{
-		vf->popup = vflist_pop_menu(vf);
+		vf->popup = vf_pop_menu(vf);
 		gtk_menu_popup(GTK_MENU(vf->popup), NULL, NULL, NULL, NULL,
 				bevent->button, bevent->time);
 		return TRUE;
--- a/src/view_file_list.h	Tue May 13 19:56:52 2008 +0000
+++ b/src/view_file_list.h	Tue May 13 20:13:44 2008 +0000
@@ -37,6 +37,7 @@
 void vflist_pop_menu_rename_cb(GtkWidget *widget, gpointer data);
 void vflist_pop_menu_refresh_cb(GtkWidget *widget, gpointer data);
 void vflist_popup_destroy_cb(GtkWidget *widget, gpointer data);
+void vflist_pop_menu_thumbs_cb(GtkWidget *widget, gpointer data);
 
 FileData *vflist_index_get_data(ViewFile *vf, gint row);
 gint vflist_index_by_path(ViewFile *vf, const gchar *path);
@@ -63,5 +64,7 @@
 gint vflist_maint_removed(ViewFile *vf, FileData *fd, GList *ignore_list);
 gint vflist_maint_moved(ViewFile *vf, FileData *fd, GList *ignore_list);
 
+void vflist_color_set(ViewFile *vf, FileData *fd, gint color_set);
+
 
 #endif