Skip to content

Commit

Permalink
Don't use the notebook page widget for tab popup
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
b4n committed May 26, 2014
1 parent 54724ee commit 6e58ef3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 25 deletions.
15 changes: 4 additions & 11 deletions src/callbacks.c
Expand Up @@ -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;
Expand Down
19 changes: 5 additions & 14 deletions src/notebook.c
Expand Up @@ -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();
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 6e58ef3

Please sign in to comment.