[gthumb] handle popup-menu signals for widgets with a contextual menu



commit 40677d08aac25f0db4591729a9f820b8052ceae4
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sun Jul 18 13:45:43 2010 +0200

    handle popup-menu signals for widgets with a contextual menu

 extensions/file_viewer/gth-file-viewer-page.c      |   13 ++++
 extensions/gstreamer_tools/gth-media-viewer-page.c |   13 ++++
 extensions/image_viewer/gth-image-viewer-page.c    |   13 ++++
 gthumb/gth-browser.c                               |   76 +++++++++++++++----
 gthumb/gth-file-properties.c                       |   33 +++++++--
 gthumb/gth-folder-tree.c                           |   43 +++++++++++-
 6 files changed, 167 insertions(+), 24 deletions(-)
---
diff --git a/extensions/file_viewer/gth-file-viewer-page.c b/extensions/file_viewer/gth-file-viewer-page.c
index 91befd3..cc7f7ce 100644
--- a/extensions/file_viewer/gth-file-viewer-page.c
+++ b/extensions/file_viewer/gth-file-viewer-page.c
@@ -76,6 +76,15 @@ viewer_button_press_cb (GtkWidget         *widget,
 }
 
 
+static gboolean
+viewer_popup_menu_cb (GtkWidget         *widget,
+		      GthFileViewerPage *self)
+{
+	gth_browser_file_menu_popup (self->priv->browser, NULL);
+	return TRUE;
+}
+
+
 static void
 thumb_loader_ready_cb (GthThumbLoader    *il,
 		       GError            *error,
@@ -134,6 +143,10 @@ gth_file_viewer_page_real_activate (GthViewerPage *base,
 			  "button_press_event",
 			  G_CALLBACK (viewer_button_press_cb),
 			  self);
+	g_signal_connect (G_OBJECT (self->priv->viewer),
+			  "popup-menu",
+			  G_CALLBACK (viewer_popup_menu_cb),
+			  self);
 	g_signal_connect (G_OBJECT (self->priv->label),
 			  "key_press_event",
 			  G_CALLBACK (viewer_key_press_cb),
diff --git a/extensions/gstreamer_tools/gth-media-viewer-page.c b/extensions/gstreamer_tools/gth-media-viewer-page.c
index 7e6f3cd..ccbc6d5 100644
--- a/extensions/gstreamer_tools/gth-media-viewer-page.c
+++ b/extensions/gstreamer_tools/gth-media-viewer-page.c
@@ -231,6 +231,15 @@ video_area_button_press_cb (GtkWidget          *widget,
 
 
 static gboolean
+video_area_popup_menu_cb (GtkWidget          *widget,
+			  GthMediaViewerPage *self)
+{
+	gth_browser_file_menu_popup (self->priv->browser, NULL);
+	return TRUE;
+}
+
+
+static gboolean
 video_area_scroll_event_cb (GtkWidget 	       *widget,
 			    GdkEventScroll     *event,
 			    GthMediaViewerPage *self)
@@ -581,6 +590,10 @@ gth_media_viewer_page_real_activate (GthViewerPage *base,
 			  G_CALLBACK (video_area_button_press_cb),
 			  self);
 	g_signal_connect (G_OBJECT (self->priv->area),
+			  "popup-menu",
+			  G_CALLBACK (video_area_popup_menu_cb),
+			  self);
+	g_signal_connect (G_OBJECT (self->priv->area),
 			  "scroll_event",
 			  G_CALLBACK (video_area_scroll_event_cb),
 			  self);
diff --git a/extensions/image_viewer/gth-image-viewer-page.c b/extensions/image_viewer/gth-image-viewer-page.c
index 1040011..ea1fb5d 100644
--- a/extensions/image_viewer/gth-image-viewer-page.c
+++ b/extensions/image_viewer/gth-image-viewer-page.c
@@ -239,6 +239,15 @@ viewer_button_press_event_cb (GtkWidget          *widget,
 
 
 static gboolean
+viewer_popup_menu_cb (GtkWidget          *widget,
+		      GthImageViewerPage *self)
+{
+	gth_browser_file_menu_popup (self->priv->browser, NULL);
+	return TRUE;
+}
+
+
+static gboolean
 viewer_scroll_event_cb (GtkWidget 	   *widget,
 		        GdkEventScroll      *event,
 		        GthImageViewerPage  *self)
@@ -430,6 +439,10 @@ gth_image_viewer_page_real_activate (GthViewerPage *base,
 			  "zoom_changed",
 			  G_CALLBACK (viewer_zoom_changed_cb),
 			  self);
+	g_signal_connect (G_OBJECT (self->priv->viewer),
+			  "popup-menu",
+			  G_CALLBACK (viewer_popup_menu_cb),
+			  self);
 	g_signal_connect_after (G_OBJECT (self->priv->viewer),
 				"button_press_event",
 				G_CALLBACK (viewer_button_press_event_cb),
diff --git a/gthumb/gth-browser.c b/gthumb/gth-browser.c
index 099e069..6d3951c 100644
--- a/gthumb/gth-browser.c
+++ b/gthumb/gth-browser.c
@@ -3037,6 +3037,34 @@ pref_general_filter_changed (GConfClient *client,
 }
 
 
+static void
+gth_file_list_popup_menu (GthBrowser     *browser,
+			  GdkEventButton *event)
+{
+	int button, event_time;
+
+	gth_hook_invoke ("gth-browser-file-list-popup-before", browser);
+	gtk_ui_manager_ensure_update (browser->priv->ui);
+
+	if (event != NULL) {
+		button = event->button;
+		event_time = event->time;
+	}
+	else {
+		button = 0;
+		event_time = gtk_get_current_event_time ();
+	}
+
+	gtk_menu_popup (GTK_MENU (browser->priv->file_list_popup),
+			NULL,
+			NULL,
+			NULL,
+			NULL,
+			button,
+			event_time);
+}
+
+
 static gboolean
 gth_file_list_button_press_cb  (GtkWidget      *widget,
 				GdkEventButton *event,
@@ -3054,17 +3082,8 @@ gth_file_list_button_press_cb  (GtkWidget      *widget,
 			gth_file_selection_unselect_all (GTH_FILE_SELECTION (file_view));
 			gth_file_selection_select (GTH_FILE_SELECTION (file_view), pos);
 		}
+		gth_file_list_popup_menu (browser, event);
 
-		gth_hook_invoke ("gth-browser-file-list-popup-before", browser);
-		gtk_ui_manager_ensure_update (browser->priv->ui);
-
-		gtk_menu_popup (GTK_MENU (browser->priv->file_list_popup),
-				NULL,
-				NULL,
-				NULL,
-				NULL,
-				event->button,
-				event->time);
 		return TRUE;
 	}
 	else if ((event->type == GDK_BUTTON_PRESS) && (event->button == 2)) {
@@ -3089,6 +3108,15 @@ gth_file_list_button_press_cb  (GtkWidget      *widget,
 
 
 static gboolean
+gth_file_list_popup_menu_cb (GtkWidget *widget,
+			     gpointer   user_data)
+{
+	gth_file_list_popup_menu (GTH_BROWSER (user_data), NULL);
+	return TRUE;
+}
+
+
+static gboolean
 update_selection_cb (gpointer user_data)
 {
 	GthBrowser *browser = user_data;
@@ -4022,19 +4050,23 @@ _gth_browser_construct (GthBrowser *browser)
 	gtk_box_pack_start (GTK_BOX (vbox), browser->priv->file_list, TRUE, TRUE, 0);
 
 	g_signal_connect (G_OBJECT (browser->priv->file_list),
-			  "button_press_event",
+			  "button-press-event",
 			  G_CALLBACK (gth_file_list_button_press_cb),
 			  browser);
+	g_signal_connect (G_OBJECT (browser->priv->file_list),
+			  "popup-menu",
+			  G_CALLBACK (gth_file_list_popup_menu_cb),
+			  browser);
 	g_signal_connect (G_OBJECT (gth_file_list_get_view (GTH_FILE_LIST (browser->priv->file_list))),
-			  "selection_changed",
+			  "selection-changed",
 			  G_CALLBACK (gth_file_view_selection_changed_cb),
 			  browser);
 	g_signal_connect (G_OBJECT (gth_file_list_get_view (GTH_FILE_LIST (browser->priv->file_list))),
-			  "item_activated",
+			  "item-activated",
 			  G_CALLBACK (gth_file_view_item_activated_cb),
 			  browser);
 	g_signal_connect (G_OBJECT (browser->priv->file_list),
-			  "key_press_event",
+			  "key-press-event",
 			  G_CALLBACK (gth_file_list_key_press_cb),
 			  browser);
 
@@ -5553,6 +5585,18 @@ void
 gth_browser_file_menu_popup (GthBrowser     *browser,
 			     GdkEventButton *event)
 {
+	int button;
+	int event_time;
+
+	if (event != NULL) {
+		button = event->button;
+		event_time = event->time;
+	}
+	else {
+		button = 0;
+		event_time = gtk_get_current_event_time ();
+	}
+
 	gth_hook_invoke ("gth-browser-file-popup-before", browser);
 	gtk_ui_manager_ensure_update (browser->priv->ui);
 	gtk_menu_popup (GTK_MENU (browser->priv->file_popup),
@@ -5560,6 +5604,6 @@ gth_browser_file_menu_popup (GthBrowser     *browser,
 			NULL,
 			NULL,
 			NULL,
-			3,
-			event->time);
+			button,
+			event_time);
 }
diff --git a/gthumb/gth-file-properties.c b/gthumb/gth-file-properties.c
index f6fefef..626c09c 100644
--- a/gthumb/gth-file-properties.c
+++ b/gthumb/gth-file-properties.c
@@ -244,12 +244,11 @@ copy_menu_item_activate_cb (GtkMenuItem *menuitem,
 	if (! gtk_tree_selection_get_selected (GTK_TREE_SELECTION (gtk_tree_view_get_selection (GTK_TREE_VIEW (self->priv->tree_view))), &model, &iter))
 		return;
 
-	gtk_tree_model_get (model, &iter,
-			    VALUE_COLUMN, &value,
-			    -1);
-	gtk_clipboard_set_text (gtk_clipboard_get_for_display (gtk_widget_get_display (GTK_WIDGET (menuitem)), GDK_SELECTION_CLIPBOARD),
-			        value,
-			        -1);
+	gtk_tree_model_get (model, &iter, VALUE_COLUMN, &value, -1);
+	if (value != NULL)
+		gtk_clipboard_set_text (gtk_clipboard_get_for_display (gtk_widget_get_display (GTK_WIDGET (menuitem)), GDK_SELECTION_CLIPBOARD),
+					value,
+					-1);
 
 	g_free (value);
 }
@@ -292,6 +291,24 @@ tree_view_button_press_event_cb (GtkWidget      *widget,
 }
 
 
+static gboolean
+tree_view_popup_menu_cb (GtkWidget *widget,
+			 gpointer   user_data)
+{
+	GthFileProperties *self = user_data;
+
+	gtk_menu_popup (GTK_MENU (self->priv->popup_menu),
+			NULL,
+			NULL,
+			NULL,
+			NULL,
+			0,
+			gtk_get_current_event_time ());
+
+	return TRUE;
+}
+
+
 static void
 gth_file_properties_init (GthFileProperties *self)
 {
@@ -349,6 +366,10 @@ gth_file_properties_init (GthFileProperties *self)
 			  "button-press-event",
 			  G_CALLBACK (tree_view_button_press_event_cb),
 			  self);
+	g_signal_connect (self->priv->tree_view,
+			  "popup-menu",
+			  G_CALLBACK (tree_view_popup_menu_cb),
+			  self);
 
 	/**/
 
diff --git a/gthumb/gth-folder-tree.c b/gthumb/gth-folder-tree.c
index ecdbe5e..be6ff88 100644
--- a/gthumb/gth-folder-tree.c
+++ b/gthumb/gth-folder-tree.c
@@ -345,12 +345,47 @@ row_expanded_cb (GtkTreeView  *tree_view,
 }
 
 
+static gboolean
+popup_menu_cb (GtkWidget *widget,
+	       gpointer   user_data)
+{
+	GthFolderTree *folder_tree = user_data;
+	GtkTreeStore  *tree_store = folder_tree->priv->tree_store;
+	GthFileData   *file_data = NULL;
+	GtkTreeIter    iter;
+
+	if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_tree)), NULL, &iter)) {
+		EntryType entry_type;
+
+		gtk_tree_model_get (GTK_TREE_MODEL (tree_store),
+				    &iter,
+				    COLUMN_TYPE, &entry_type,
+				    COLUMN_FILE_DATA, &file_data,
+				    -1);
+		if (entry_type != ENTRY_TYPE_FILE) {
+			_g_object_unref (file_data);
+			return FALSE;
+		}
+	}
+
+	g_signal_emit (folder_tree,
+		       gth_folder_tree_signals[FOLDER_POPUP],
+		       0,
+		       file_data,
+		       gtk_get_current_event_time ());
+
+	_g_object_unref (file_data);
+
+	return TRUE;
+}
+
+
 static int
 button_press_cb (GtkWidget      *widget,
 		 GdkEventButton *event,
-		 gpointer        data)
+		 gpointer        user_data)
 {
-	GthFolderTree     *folder_tree = data;
+	GthFolderTree     *folder_tree = user_data;
 	GtkTreeStore      *tree_store = folder_tree->priv->tree_store;
 	GtkTreePath       *path;
 	GtkTreeIter        iter;
@@ -973,6 +1008,10 @@ gth_folder_tree_construct (GthFolderTree *folder_tree)
 	/**/
 
 	g_signal_connect (folder_tree,
+			  "popup-menu",
+			  G_CALLBACK (popup_menu_cb),
+			  folder_tree);
+	g_signal_connect (folder_tree,
 			  "button-press-event",
 			  G_CALLBACK (button_press_cb),
 			  folder_tree);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]