diff --git a/frontends/gtk/scaffolding.c b/frontends/gtk/scaffolding.c index 8712dcd10..6ace03263 100644 --- a/frontends/gtk/scaffolding.c +++ b/frontends/gtk/scaffolding.c @@ -1191,16 +1191,6 @@ static nserror nsgtk_search_connect_signals(struct nsgtk_scaffolding *gs) } -/* exported interface documented in gtk/scaffolding.h */ -struct nsgtk_scaffolding *nsgtk_current_scaffolding(void) -{ - if (scaf_current == NULL) { - scaf_current = scaf_list; - } - return scaf_current; -} - - /* exported function documented in gtk/scaffolding.h */ void nsgtk_scaffolding_set_title(struct gui_window *gw, const char *title) { @@ -1297,9 +1287,12 @@ struct gtk_search *nsgtk_scaffolding_search(struct nsgtk_scaffolding *g) } /* exported interface documented in gtk/scaffolding.h */ -GtkMenuBar *nsgtk_scaffolding_menu_bar(struct nsgtk_scaffolding *g) +GtkMenuBar *nsgtk_scaffolding_menu_bar(struct nsgtk_scaffolding *gs) { - return g->menu_bar->bar_menu; + if (gs == NULL) { + return NULL; + } + return gs->menu_bar->bar_menu; } /* exported interface documented in gtk/scaffolding.h */ @@ -1354,6 +1347,8 @@ void nsgtk_scaffolding_set_top_level(struct gui_window *gw) sc = nsgtk_get_scaffold(gw); assert(sc != NULL); + scaf_current = sc; + sc->top_level = gw; /* Synchronise the history (will also update the URL bar) */ @@ -1463,6 +1458,28 @@ nsgtk_scaffolding_context_menu(struct nsgtk_scaffolding *g, nsgtk_menu_popup_at_pointer(gtkmenu, NULL); } +/* exported interface documented in gtk/scaffolding.h */ +struct nsgtk_scaffolding *nsgtk_current_scaffolding(void) +{ + if (scaf_current == NULL) { + scaf_current = scaf_list; + } + return scaf_current; +} + +/* exported interface documented in gtk/scaffolding.h */ +struct nsgtk_scaffolding *nsgtk_scaffolding_from_notebook(GtkNotebook *notebook) +{ + struct nsgtk_scaffolding *gs; + gs = scaf_list; + while (gs != NULL) { + if (gs->notebook == notebook) { + break; + } + gs = gs->next; + } + return gs; +} /* exported interface documented in gtk/scaffolding.h */ struct nsgtk_scaffolding *nsgtk_new_scaffolding(struct gui_window *toplevel) diff --git a/frontends/gtk/scaffolding.h b/frontends/gtk/scaffolding.h index 42ae6b6be..28fa6ec25 100644 --- a/frontends/gtk/scaffolding.h +++ b/frontends/gtk/scaffolding.h @@ -153,5 +153,12 @@ void nsgtk_scaffolding_context_menu(struct nsgtk_scaffolding *g, gdouble x, gdou */ void nsgtk_scaffolding_set_title(struct gui_window *gw, const char *title); +/** + * find which scaffolding contains a gtk notebook + * + * \param notebook The notebook to search for. + * \return The scaffolding containing the notebook or NULL if not found + */ +struct nsgtk_scaffolding *nsgtk_scaffolding_from_notebook(GtkNotebook *notebook); #endif /* NETSURF_GTK_SCAFFOLDING_H */ diff --git a/frontends/gtk/tabs.c b/frontends/gtk/tabs.c index 18dec6174..b9e6dadb1 100644 --- a/frontends/gtk/tabs.c +++ b/frontends/gtk/tabs.c @@ -173,37 +173,50 @@ nsgtk_tab_switch_page_after(GtkNotebook *notebook, { GtkWidget *srcpage; GtkWidget *addpage; - struct gui_window *gw; - nserror error; + GtkMenuBar *menubar; + struct gui_window *gw = NULL; + nserror res = NSERROR_INVALID; addpage = g_object_get_data(G_OBJECT(notebook), "addtab"); - if (selpage == addpage) { - if ((srcpagenum != -1) && - (srcpagenum != (gint)selpagenum)) { - /* ensure the add tab is not actually selected */ - NSLOG(netsurf, INFO, "src %d sel %d", srcpagenum, - selpagenum); - srcpage = gtk_notebook_get_nth_page(notebook, srcpagenum); - gw = g_object_get_data(G_OBJECT(srcpage), "gui_window"); - if ((gw != NULL) && (nsgtk_get_scaffold(gw) != NULL)) { - error = nsgtk_window_item_activate(gw, NEWTAB_BUTTON); - if (error != NSERROR_OK) { - NSLOG(netsurf, INFO, - "Failed to open new tab."); - } - } - } - } else { + /* check if trying to select the "add page" tab */ + if (selpage != addpage) { NSLOG(netsurf, INFO, "sel %d", selpagenum); - /* tab with page in it */ + menubar = nsgtk_scaffolding_menu_bar(nsgtk_scaffolding_from_notebook(notebook)); gw = g_object_get_data(G_OBJECT(selpage), "gui_window"); if (gw != NULL) { + /* tab with web page in it */ nsgtk_scaffolding_set_top_level(gw); + gtk_widget_show(GTK_WIDGET(addpage)); + gtk_widget_set_sensitive(GTK_WIDGET(menubar), true); + } else { + /* tab with non browser content (e.g. tb customize) */ + gtk_widget_hide(GTK_WIDGET(addpage)); + gtk_widget_set_sensitive(GTK_WIDGET(menubar), false); } + return; + } + + NSLOG(netsurf, INFO, "src %d sel %d", srcpagenum, selpagenum); + + /* ensure the add tab is not already selected */ + if ((srcpagenum == -1) || (srcpagenum == (gint)selpagenum)) { + return; + } + + srcpage = gtk_notebook_get_nth_page(notebook, srcpagenum); + + gw = g_object_get_data(G_OBJECT(srcpage), "gui_window"); + + if (gw != NULL) { + res = nsgtk_window_item_activate(gw, NEWTAB_BUTTON); + } + if (res != NSERROR_OK) { + NSLOG(netsurf, INFO, "Failed to open new tab."); } } + /** * The tab reordered gtk signal handler *