Revision: 2134 http://geany.svn.sourceforge.net/geany/?rev=2134&view=rev Author: ntrel Date: 2007-12-28 09:35:58 -0800 (Fri, 28 Dec 2007)
Log Message: ----------- Disable popup menu items when there is no selection.
Modified Paths: -------------- trunk/ChangeLog trunk/plugins/filebrowser.c
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-12-28 17:02:07 UTC (rev 2133) +++ trunk/ChangeLog 2007-12-28 17:35:58 UTC (rev 2134) @@ -6,6 +6,8 @@ item callbacks. Rename "Open with..." popup item "Open externally" ("..." is usually used when the user can input more information). + * plugins/filebrowser.c: + Disable popup menu items when there is no selection.
2007-12-25 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
Modified: trunk/plugins/filebrowser.c =================================================================== --- trunk/plugins/filebrowser.c 2007-12-28 17:02:07 UTC (rev 2133) +++ trunk/plugins/filebrowser.c 2007-12-28 17:35:58 UTC (rev 2134) @@ -77,7 +77,14 @@ static gchar *open_cmd; // in locale-encoding static gchar *config_file;
+static struct +{ + GtkWidget *open; + GtkWidget *open_external; + GtkWidget *find_in_files; +} popup_items;
+ // Returns: whether name should be hidden. static gboolean check_hidden(const gchar *base_name) { @@ -495,6 +502,7 @@ gtk_container_add(GTK_CONTAINER(menu), item); g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_open_clicked), NULL); + popup_items.open = item;
image = gtk_image_new_from_stock(GTK_STOCK_OPEN, GTK_ICON_SIZE_MENU); gtk_widget_show(image); @@ -504,6 +512,7 @@ gtk_container_add(GTK_CONTAINER(menu), item); g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_external_open), NULL); + popup_items.open_external = item;
image = gtk_image_new_from_stock(GTK_STOCK_FIND, GTK_ICON_SIZE_MENU); gtk_widget_show(image); @@ -512,6 +521,7 @@ gtk_widget_show(item); gtk_container_add(GTK_CONTAINER(menu), item); g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_find_in_files), NULL); + popup_items.find_in_files = item;
item = gtk_separator_menu_item_new(); gtk_widget_show(item); @@ -543,7 +553,25 @@ { if (event->button == 1 && event->type == GDK_2BUTTON_PRESS) on_open_clicked(NULL, NULL); - else + return FALSE; +} + + +static void update_popup_menu(GtkWidget *popup_menu) +{ + GtkTreeSelection *treesel = gtk_tree_view_get_selection(GTK_TREE_VIEW(file_view)); + gboolean have_sel = (gtk_tree_selection_count_selected_rows(treesel) > 0); + gboolean multi_sel = (gtk_tree_selection_count_selected_rows(treesel) > 1); + + gtk_widget_set_sensitive(popup_items.open, have_sel); + gtk_widget_set_sensitive(popup_items.open_external, have_sel); + gtk_widget_set_sensitive(popup_items.find_in_files, have_sel && ! multi_sel); +} + + +// delay updating popup menu until the selection has been set +static gboolean on_button_release(GtkWidget *widget, GdkEventButton *event, gpointer user_data) +{ if (event->button == 3) { static GtkWidget *popup_menu = NULL; @@ -551,9 +579,10 @@ if (popup_menu == NULL) popup_menu = create_popup_menu();
+ update_popup_menu(popup_menu); + gtk_menu_popup(GTK_MENU(popup_menu), NULL, NULL, NULL, NULL, event->button, event->time); - return FALSE; } return FALSE; } @@ -631,6 +660,8 @@ g_signal_connect(G_OBJECT(file_view), "realize", G_CALLBACK(on_current_path), NULL); g_signal_connect(G_OBJECT(file_view), "button-press-event", G_CALLBACK(on_button_press), NULL); + g_signal_connect(G_OBJECT(file_view), "button-release-event", + G_CALLBACK(on_button_release), NULL); g_signal_connect(G_OBJECT(file_view), "key-press-event", G_CALLBACK(on_key_press), NULL); }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.