[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r18921 - gnunet-gtk/src/fs
From: |
gnunet |
Subject: |
[GNUnet-SVN] r18921 - gnunet-gtk/src/fs |
Date: |
Mon, 2 Jan 2012 07:00:57 +0100 |
Author: grothoff
Date: 2012-01-02 07:00:57 +0100 (Mon, 02 Jan 2012)
New Revision: 18921
Modified:
gnunet-gtk/src/fs/gnunet-fs-gtk-event_handler.c
Log:
-LRN: Add a proper popup handler (which also works for ctrl+F10 and Menu
keys, not just rightclicks)
Modified: gnunet-gtk/src/fs/gnunet-fs-gtk-event_handler.c
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk-event_handler.c 2012-01-02 06:00:16 UTC
(rev 18920)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk-event_handler.c 2012-01-02 06:00:57 UTC
(rev 18921)
@@ -113,6 +113,122 @@
static struct PublishTab *publish_tab;
+static gboolean
+search_list_popup (GtkTreeView *tv, struct SearchTab *tab, GdkEventButton
*event_button)
+{
+ GtkMenu *menu;
+ GtkWidget *child;
+ GtkTreeSelection *sel;
+ GtkTreePath *path;
+ GtkTreeModel *tm;
+ GtkTreeIter iter;
+ struct SearchResult *sr;
+ struct GNUNET_FS_Uri *uri;
+ gboolean got_selection;
+ gint init_button;
+ guint32 event_time;
+
+ current_context_search_tab = tab;
+ if (current_context_row_reference != NULL)
+ {
+ gtk_tree_row_reference_free (current_context_row_reference);
+ current_context_row_reference = NULL;
+ }
+ path = NULL;
+ if (event_button != NULL)
+ {
+ got_selection =
+ gtk_tree_view_get_path_at_pos (tv, event_button->x, event_button->y,
+ &path, NULL, NULL, NULL);
+ if (got_selection)
+ {
+ tm = gtk_tree_view_get_model (tv);
+ got_selection = gtk_tree_model_get_iter (tm, &iter, path);
+ current_context_row_reference = gtk_tree_row_reference_new (tm, path);
+ gtk_tree_path_free (path);
+ }
+ init_button = event_button->button;
+ event_time = event_button->time;
+ }
+ else
+ {
+ sel = gtk_tree_view_get_selection (tv);
+ got_selection = gtk_tree_selection_get_selected (sel, &tm, &iter);
+ path = gtk_tree_model_get_path (tm, &iter);
+ current_context_row_reference = gtk_tree_row_reference_new (tm, path);
+ gtk_tree_path_free (path);
+ init_button = 0;
+ event_time = gtk_get_current_event_time ();
+ }
+ if (!got_selection)
+ {
+ /* nothing selected or model empty? */
+ current_context_search_tab = NULL;
+ return FALSE;
+ }
+ gtk_tree_model_get (tm, &iter, 1, &uri, 9, &sr, -1);
+
+ /*
+ * FIXME: have additional options, depending on status:
+ * - view full meta data (in new window)
+ * - copy URI to clipboard
+ * - start recursive download
+ * - abort active download (!)
+ * => need to know download status before creating menu!
+ */
+ menu = GTK_MENU (gtk_menu_new ());
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Creating a menu for SR=%p, DE=%p\n", sr, sr->download);
+ if (sr->download == NULL)
+ {
+ if (NULL != uri)
+ {
+ /* only display download menus if there is a URI */
+ child = gtk_menu_item_new_with_label (_("_Download"));
+ g_signal_connect (child, "activate",
+ G_CALLBACK (start_download_ctx_menu), NULL);
+ gtk_label_set_use_underline (GTK_LABEL
+ (gtk_bin_get_child (GTK_BIN (child))),
+ TRUE);
+ gtk_widget_show (child);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), child);
+
+ child = gtk_menu_item_new_with_label (_("Download _recursively"));
+ g_signal_connect (child, "activate",
+ G_CALLBACK (start_download_recursively_ctx_menu),
NULL);
+ gtk_label_set_use_underline (GTK_LABEL
+ (gtk_bin_get_child (GTK_BIN (child))),
+ TRUE);
+ gtk_widget_show (child);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), child);
+ }
+ }
+ else
+ {
+ child = gtk_menu_item_new_with_label (_("_Abort download"));
+ g_signal_connect (child, "activate",
+ G_CALLBACK (abort_download_ctx_menu), sr->download);
+ gtk_label_set_use_underline (GTK_LABEL
+ (gtk_bin_get_child (GTK_BIN (child))),
+ TRUE);
+ gtk_widget_show (child);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), child);
+ }
+
+ child = gtk_menu_item_new_with_label (_("_Copy URI to Clipboard"));
+ g_signal_connect (child, "activate",
+ G_CALLBACK (copy_uri_to_clipboard_ctx_menu), NULL);
+ gtk_label_set_use_underline (GTK_LABEL
+ (gtk_bin_get_child (GTK_BIN (child))), TRUE);
+ gtk_widget_show (child);
+
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), child);
+ gtk_menu_popup (menu, NULL, NULL, NULL, NULL, init_button, event_time);
+ /* FIXME: attach some kind of handler to destroy the menu */
+ return TRUE;
+}
+
+
static void
closure_notify_free (gpointer data, GClosure *closure)
{
@@ -901,7 +1017,18 @@
GNUNET_free (uris);
}
+gboolean
+search_list_on_popup (GtkWidget *widget, gpointer user_data)
+{
+ GtkTreeView *tv;
+ struct SearchTab *tab = user_data;
+ tv = GTK_TREE_VIEW (widget);
+ return search_list_popup (tv, tab, NULL);
+}
+
+
+
/**
* We got a right-click on the search result list. Display the context
* menu.
@@ -912,13 +1039,6 @@
GdkEventButton *event_button;
struct SearchTab *tab = user_data;
GtkTreeView *tv;
- GtkMenu *menu;
- GtkWidget *child;
- GtkTreePath *path;
- GtkTreeModel *tm;
- GtkTreeIter iter;
- struct SearchResult *sr;
- struct GNUNET_FS_Uri *uri;
tv = GTK_TREE_VIEW (widget);
if (event->type == GDK_BUTTON_PRESS)
@@ -926,97 +1046,12 @@
event_button = (GdkEventButton *) event;
if (event_button->button == 3)
{
- current_context_search_tab = tab;
- if (current_context_row_reference != NULL)
- {
- gtk_tree_row_reference_free (current_context_row_reference);
- current_context_row_reference = NULL;
- }
- path = NULL;
- if (FALSE ==
- gtk_tree_view_get_path_at_pos (tv, event_button->x, event_button->y,
- &path, NULL, NULL, NULL))
- {
- /* nothing selected */
- current_context_search_tab = NULL;
- return FALSE;
- }
- tm = gtk_tree_view_get_model (tv);
- if (TRUE != gtk_tree_model_get_iter (tm, &iter, path))
- {
- /* model empty? */
- current_context_search_tab = NULL;
- return FALSE;
- }
- gtk_tree_model_get (tm, &iter, 1, &uri, 9, &sr, -1);
- current_context_row_reference = gtk_tree_row_reference_new (tm, path);
- gtk_tree_path_free (path);
-
- /*
- * FIXME: have additional options, depending on status:
- * - view full meta data (in new window)
- * - copy URI to clipboard
- * - start recursive download
- * - abort active download (!)
- * => need to know download status before creating menu!
- */
- menu = GTK_MENU (gtk_menu_new ());
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Creating a menu for SR=%p, DE=%p\n", sr, sr->download);
- if (sr->download == NULL)
- {
- if (NULL != uri)
- {
- /* only display download menus if there is a URI */
- child = gtk_menu_item_new_with_label (_("_Download"));
- g_signal_connect (child, "activate",
- G_CALLBACK (start_download_ctx_menu), NULL);
- gtk_label_set_use_underline (GTK_LABEL
- (gtk_bin_get_child (GTK_BIN (child))),
- TRUE);
- gtk_widget_show (child);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), child);
-
- child = gtk_menu_item_new_with_label (_("Download _recursively"));
- g_signal_connect (child, "activate",
- G_CALLBACK (start_download_recursively_ctx_menu),
NULL);
- gtk_label_set_use_underline (GTK_LABEL
- (gtk_bin_get_child (GTK_BIN (child))),
- TRUE);
- gtk_widget_show (child);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), child);
- }
- }
- else
- {
- child = gtk_menu_item_new_with_label (_("_Abort download"));
- g_signal_connect (child, "activate",
- G_CALLBACK (abort_download_ctx_menu), sr->download);
- gtk_label_set_use_underline (GTK_LABEL
- (gtk_bin_get_child (GTK_BIN (child))),
- TRUE);
- gtk_widget_show (child);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), child);
- }
-
- child = gtk_menu_item_new_with_label (_("_Copy URI to Clipboard"));
- g_signal_connect (child, "activate",
- G_CALLBACK (copy_uri_to_clipboard_ctx_menu), NULL);
- gtk_label_set_use_underline (GTK_LABEL
- (gtk_bin_get_child (GTK_BIN (child))),
TRUE);
- gtk_widget_show (child);
-
-
-
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), child);
- gtk_menu_popup (menu, NULL, NULL, NULL, NULL, event_button->button,
- event_button->time);
+ return search_list_popup (tv, tab, event_button);
}
}
return FALSE;
}
-
/**
* Selected row has changed, update preview and metadata
* areas.
@@ -1362,6 +1397,8 @@
G_CALLBACK (update_meta_data_views), tab);
g_signal_connect (G_OBJECT (tv), "button_press_event",
G_CALLBACK (search_list_on_menu), tab);
+ g_signal_connect (G_OBJECT (tv), "popup-menu",
+ G_CALLBACK (search_list_on_popup), tab);
/* make visible */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r18921 - gnunet-gtk/src/fs,
gnunet <=