[geany/geany] 6e58ef: Don't use the notebook page widget for tab popup

Colomban Wendling git-noreply at xxxxx
Mon May 26 14:21:16 UTC 2014


Branch:      refs/heads/master
Author:      Colomban Wendling <ban at herbesfolles.org>
Committer:   Colomban Wendling <ban at herbesfolles.org>
Date:        Mon, 26 May 2014 14:21:16 UTC
Commit:      6e58ef3755e1d69c4edf3300ac17ae34413b8545
             https://github.com/geany/geany/commit/6e58ef3755e1d69c4edf3300ac17ae34413b8545

Log Message:
-----------
Don't use the notebook page widget for tab popup

Directly use the GeanyDocument rather than pass the notebook page
widget and get the document from that.  This makes the code more future
proof and less weird.


Modified Paths:
--------------
    src/callbacks.c
    src/notebook.c

Modified: src/callbacks.c
15 lines changed, 4 insertions(+), 11 deletions(-)
===================================================================
@@ -1914,25 +1914,18 @@ G_MODULE_EXPORT void on_search1_activate(GtkMenuItem *menuitem, gpointer user_da
 
 
 /* simple implementation (vs. close all which doesn't close documents if cancelled),
- * if user_data is set, it is a GtkNotebook child widget */
+ * if user_data is set, it is the GeanyDocument to keep */
 G_MODULE_EXPORT void on_close_other_documents1_activate(GtkMenuItem *menuitem, gpointer user_data)
 {
 	guint i;
-	GeanyDocument *doc, *cur_doc;
+	GeanyDocument *cur_doc = user_data;
 
-	if (user_data != NULL)
-	{
-		gint page_num = gtk_notebook_page_num(
-			GTK_NOTEBOOK(main_widgets.notebook), GTK_WIDGET(user_data));
-		cur_doc = document_get_from_page(page_num);
-	}
-	else
+	if (cur_doc == NULL)
 		cur_doc = document_get_current();
 
-
 	for (i = 0; i < documents_array->len; i++)
 	{
-		doc = documents[i];
+		GeanyDocument *doc = documents[i];
 
 		if (doc == cur_doc || ! doc->is_valid)
 			continue;


Modified: src/notebook.c
19 lines changed, 5 insertions(+), 14 deletions(-)
===================================================================
@@ -445,12 +445,10 @@ static void on_open_in_new_window_activate(GtkMenuItem *menuitem, gpointer user_
 }
 
 
-static void show_tab_bar_popup_menu(GdkEventButton *event, GtkWidget *page)
+static void show_tab_bar_popup_menu(GdkEventButton *event, GeanyDocument *doc)
 {
 	GtkWidget *menu_item;
 	static GtkWidget *menu = NULL;
-	GeanyDocument *doc = NULL;
-	gint page_num;
 
 	if (menu == NULL)
 		menu = gtk_menu_new();
@@ -465,12 +463,6 @@ static void show_tab_bar_popup_menu(GdkEventButton *event, GtkWidget *page)
 	gtk_widget_show(menu_item);
 	gtk_container_add(GTK_CONTAINER(menu), menu_item);
 
-	if (page != NULL)
-	{
-		page_num = gtk_notebook_page_num(GTK_NOTEBOOK(main_widgets.notebook), page);
-		doc = document_get_from_page(page_num);
-	}
-
 	menu_item = ui_image_menu_item_new(GTK_STOCK_OPEN, "Open in New _Window");
 	gtk_widget_show(menu_item);
 	gtk_container_add(GTK_CONTAINER(menu), menu_item);
@@ -488,13 +480,13 @@ static void show_tab_bar_popup_menu(GdkEventButton *event, GtkWidget *page)
 	gtk_widget_show(menu_item);
 	gtk_container_add(GTK_CONTAINER(menu), menu_item);
 	g_signal_connect(menu_item, "activate", G_CALLBACK(notebook_tab_close_clicked_cb), doc);
-	gtk_widget_set_sensitive(GTK_WIDGET(menu_item), (page != NULL));
+	gtk_widget_set_sensitive(GTK_WIDGET(menu_item), (doc != NULL));
 
 	menu_item = ui_image_menu_item_new(GTK_STOCK_CLOSE, _("Close Ot_her Documents"));
 	gtk_widget_show(menu_item);
 	gtk_container_add(GTK_CONTAINER(menu), menu_item);
-	g_signal_connect(menu_item, "activate", G_CALLBACK(on_close_other_documents1_activate), page);
-	gtk_widget_set_sensitive(GTK_WIDGET(menu_item), (page != NULL));
+	g_signal_connect(menu_item, "activate", G_CALLBACK(on_close_other_documents1_activate), doc);
+	gtk_widget_set_sensitive(GTK_WIDGET(menu_item), (doc != NULL));
 
 	menu_item = ui_image_menu_item_new(GTK_STOCK_CLOSE, _("C_lose All"));
 	gtk_widget_show(menu_item);
@@ -635,8 +627,7 @@ static gboolean notebook_tab_click(GtkWidget *widget, GdkEventButton *event, gpo
 	/* right-click is first handled here if it happened on a notebook tab */
 	if (event->button == 3)
 	{
-		/* show_tab_bar_popup_menu() needs the tab widget (GtkBox, parent of scintilla) */
-		show_tab_bar_popup_menu(event, gtk_widget_get_parent(GTK_WIDGET(doc->editor->sci)));
+		show_tab_bar_popup_menu(event, doc);
 		return TRUE;
 	}
 



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Commits mailing list