make handling of non browser window containing tabs reasonable

This commit is contained in:
Vincent Sanders 2019-09-07 13:42:33 +01:00 committed by Daniel Silverstone
parent 747f135de5
commit 608cc3cbbf
3 changed files with 69 additions and 32 deletions

View File

@ -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)

View File

@ -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 */

View File

@ -173,36 +173,49 @@ 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