diff --git a/ChangeLog b/ChangeLog index 75fb42c2..dc02eb01 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,12 @@ Adjust minimum required GTK version. * src/Makefile.am, wscript: Add main.h to the list of installed header files. + * geany.glade, src/document.c, src/documentprivate.h, src/interface.c, + src/notebook.c, src/ui_utils.c: + Remove GeanyDocumentPrivate::tabmenu_label. + Disable the default tab bar menu for the main notebook widget and + use a custom menu instead which lists all open files as usual plus + 'Close Other Documents' and 'Close All' menu items. 2009-02-27 Enrico Tröger diff --git a/geany.glade b/geany.glade index 3bb23ffd..90883701 100644 --- a/geany.glade +++ b/geany.glade @@ -1766,7 +1766,7 @@ True GTK_POS_TOP True - True + False diff --git a/src/document.c b/src/document.c index 853cf5c6..4ae5803d 100644 --- a/src/document.c +++ b/src/document.c @@ -296,7 +296,6 @@ void document_update_tab_label(GeanyDocument *doc) parent = gtk_widget_get_parent(parent); gtk_label_set_text(GTK_LABEL(doc->priv->tab_label), base_name); - gtk_label_set_text(GTK_LABEL(doc->priv->tabmenu_label), base_name); ui_widget_set_tooltip_text(parent, DOC_FILENAME(doc)); diff --git a/src/documentprivate.h b/src/documentprivate.h index d0a5af2b..3ba02bed 100644 --- a/src/documentprivate.h +++ b/src/documentprivate.h @@ -61,8 +61,6 @@ typedef struct GeanyDocumentPrivate { /* GtkLabel shown in the notebook header. */ GtkWidget *tab_label; - /* GtkLabel shown in the notebook right-click menu. */ - GtkWidget *tabmenu_label; /* GtkTreeView object for this %document within the Symbols treeview of the sidebar. */ GtkWidget *tag_tree; /* GtkTreeStore object for this %document within the Symbols treeview of the sidebar. */ diff --git a/src/interface.c b/src/interface.c index c80f7f7f..69720ae1 100644 --- a/src/interface.c +++ b/src/interface.c @@ -1082,7 +1082,6 @@ create_window1 (void) gtk_widget_show (notebook1); gtk_paned_pack2 (GTK_PANED (hpaned1), notebook1, TRUE, TRUE); gtk_notebook_set_scrollable (GTK_NOTEBOOK (notebook1), TRUE); - gtk_notebook_popup_enable (GTK_NOTEBOOK (notebook1)); scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL); gtk_widget_show (scrolledwindow1); diff --git a/src/notebook.c b/src/notebook.c index 6f4fb73c..b64a9140 100644 --- a/src/notebook.c +++ b/src/notebook.c @@ -179,6 +179,73 @@ static gboolean is_position_on_tab_bar(GtkNotebook *notebook, GdkEventButton *ev } +static void tab_bar_menu_activate_cb(GtkMenuItem *menuitem, gpointer data) +{ + GeanyDocument *doc = data; + + if (! DOC_VALID(doc)) + return; + + gtk_notebook_set_current_page(GTK_NOTEBOOK(main_widgets.notebook), + document_get_notebook_page(doc)); +} + + +static GtkMenu *get_tab_bar_popup_menu(void) +{ + static GtkWidget *menu = NULL; + GtkWidget *menu_item, *menu_item_label; + const GdkColor *color; + GeanyDocument *doc; + guint i, len; + gchar *base_name; + + if (menu == NULL) + menu = gtk_menu_new(); + + /* clear the old menu items */ + gtk_container_foreach(GTK_CONTAINER(menu), (GtkCallback) gtk_widget_destroy, NULL); + + len = gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook)); + for (i = 0; i < len; i++) + { + doc = document_get_from_page(i); + if (! DOC_VALID(doc)) + continue; + + base_name = g_path_get_basename(doc->file_name); + menu_item = gtk_image_menu_item_new_with_label(base_name); + gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_item), + gtk_image_new_from_icon_name(GTK_STOCK_FILE, GTK_ICON_SIZE_MENU)); + gtk_widget_show(menu_item); + gtk_container_add(GTK_CONTAINER(menu), menu_item); + g_signal_connect(menu_item, "activate", G_CALLBACK(tab_bar_menu_activate_cb), doc); + + color = document_get_status_color(doc); + menu_item_label = gtk_bin_get_child(GTK_BIN(menu_item)); + gtk_widget_modify_fg(menu_item_label, GTK_STATE_NORMAL, color); + gtk_widget_modify_fg(menu_item_label, GTK_STATE_ACTIVE, color); + + g_free(base_name); + } + menu_item = gtk_separator_menu_item_new(); + gtk_widget_show(menu_item); + gtk_container_add(GTK_CONTAINER(menu), menu_item); + + 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), NULL); + + menu_item = ui_image_menu_item_new(GTK_STOCK_CLOSE, _("C_lose All")); + gtk_widget_show(menu_item); + gtk_container_add(GTK_CONTAINER(menu), menu_item); + g_signal_connect(menu_item, "activate", G_CALLBACK(on_close_all1_activate), NULL); + + return GTK_MENU(menu); +} + + static gboolean notebook_tab_bar_click_cb(GtkWidget *widget, GdkEventButton *event, gpointer user_data) { @@ -195,6 +262,11 @@ static gboolean notebook_tab_bar_click_cb(GtkWidget *widget, GdkEventButton *eve return TRUE; } } + else if (event->button == 3) + { + gtk_menu_popup(get_tab_bar_popup_menu(), NULL, NULL, + NULL, NULL, event->button, event->time); + } return FALSE; } @@ -452,17 +524,14 @@ gint notebook_new_tab(GeanyDocument *this) gtk_widget_show_all(ebox); - this->priv->tabmenu_label = gtk_label_new(NULL); - gtk_misc_set_alignment(GTK_MISC(this->priv->tabmenu_label), 0.0, 0); - document_update_tab_label(this); if (file_prefs.tab_order_ltr) tabnum = gtk_notebook_append_page_menu(GTK_NOTEBOOK(main_widgets.notebook), page, - ebox, this->priv->tabmenu_label); + ebox, NULL); else tabnum = gtk_notebook_insert_page_menu(GTK_NOTEBOOK(main_widgets.notebook), page, - ebox, this->priv->tabmenu_label, 0); + ebox, NULL, 0); tab_count_changed(); diff --git a/src/ui_utils.c b/src/ui_utils.c index dc775cfa..05146de3 100644 --- a/src/ui_utils.c +++ b/src/ui_utils.c @@ -1333,8 +1333,6 @@ void ui_update_tab_status(GeanyDocument *doc) /* NULL color will reset to default */ gtk_widget_modify_fg(doc->priv->tab_label, GTK_STATE_NORMAL, color); gtk_widget_modify_fg(doc->priv->tab_label, GTK_STATE_ACTIVE, color); - gtk_widget_modify_fg(doc->priv->tabmenu_label, GTK_STATE_NORMAL, color); - gtk_widget_modify_fg(doc->priv->tabmenu_label, GTK_STATE_ACTIVE, color); treeviews_openfiles_update(doc); }