persist the menu and tool bar visibility as user settings

This commit is contained in:
Vincent Sanders 2019-09-21 01:07:32 +01:00 committed by Daniel Silverstone
parent e14416d43f
commit 9d3112a643
6 changed files with 92 additions and 21 deletions

View File

@ -251,7 +251,10 @@ static nserror set_defaults(struct nsoption_s *defaults)
/* set default items in toolbar */
nsoption_set_charp(toolbar_items,
strdup("back/history/forward/reloadstop/url_bar/websearch/openmenu"));
strdup("back/history/forward/reloadstop/url_bar/websearch/openmenu"));
/* set default for menu and tool bar visibility */
nsoption_set_charp(bar_show, strdup("tool"));
return NSERROR_OK;
}

View File

@ -75,4 +75,4 @@ NSOPTION_INTEGER(position_tab, 0)
NSOPTION_STRING(toolbar_items, NULL)
/* The menu and tool bars that are shown */
NSOPTION_STRING(toolbar_show, NULL)
NSOPTION_STRING(bar_show, NULL)

View File

@ -589,6 +589,55 @@ static gboolean nsgtk_on_find_activate_menu(GtkMenuItem *widget, gpointer data)
return TRUE;
}
static nserror get_bar_show(bool *menu, bool *tool)
{
const char *cur_bar_show;
*menu = false;
*tool = false;
cur_bar_show = nsoption_charp(bar_show);
if (cur_bar_show != NULL) {
if (strcmp(cur_bar_show, "menu/tool") == 0) {
*menu = true;
*tool = true;
} else if (strcmp(cur_bar_show, "menu") == 0) {
*menu = true;
} else if (strcmp(cur_bar_show, "tool") == 0) {
*tool = true;
}
}
return NSERROR_OK;
}
static nserror set_bar_show(const char *bar, bool show)
{
bool menu;
bool tool;
const char *new_bar_show;
get_bar_show(&menu, &tool);
if (strcmp(bar, "menu") == 0) {
menu = show;
} else if (strcmp(bar, "tool") == 0) {
tool = show;
}
if ((menu == true) && (tool == true)) {
new_bar_show = "menu/tool";
} else if (menu == true) {
new_bar_show = "menu";
} else if (tool == true) {
new_bar_show = "tool";
} else {
new_bar_show = "none";
}
nsoption_set_charp(bar_show, strdup(new_bar_show));
return NSERROR_OK;
}
static gboolean
nsgtk_on_menubar_activate_menu(GtkMenuItem *widget, gpointer data)
@ -617,7 +666,7 @@ nsgtk_on_menubar_activate_menu(GtkMenuItem *widget, gpointer data)
}
gtk_widget_show(GTK_WIDGET(gs->menu_bar->bar_menu));
set_bar_show("menu", true);
} else {
if (gtk_check_menu_item_get_active(bmcmi) == TRUE) {
gtk_check_menu_item_set_active(bmcmi, FALSE);
@ -632,6 +681,7 @@ nsgtk_on_menubar_activate_menu(GtkMenuItem *widget, gpointer data)
}
gtk_widget_hide(GTK_WIDGET(gs->menu_bar->bar_menu));
set_bar_show("menu", false);
}
return TRUE;
}
@ -664,6 +714,7 @@ nsgtk_on_toolbar_activate_menu(GtkMenuItem *widget, gpointer data)
}
nsgtk_window_toolbar_show(gs, true);
set_bar_show("tool", true);
} else {
if (gtk_check_menu_item_get_active(bmcmi) == TRUE) {
gtk_check_menu_item_set_active(bmcmi, FALSE);
@ -678,6 +729,7 @@ nsgtk_on_toolbar_activate_menu(GtkMenuItem *widget, gpointer data)
}
nsgtk_window_toolbar_show(gs, false);
set_bar_show("tool", false);
}
return TRUE;
}
@ -792,6 +844,7 @@ create_scaffolding_burger_menu(struct nsgtk_scaffolding *gs,
return nmenu;
}
/**
* Create and connect handlers to popup menu.
*
@ -800,7 +853,8 @@ create_scaffolding_burger_menu(struct nsgtk_scaffolding *gs,
* \return menu structure on success or NULL on error.
*/
static struct nsgtk_popup_menu *
create_scaffolding_popup_menu(struct nsgtk_scaffolding *gs, GtkAccelGroup *group)
create_scaffolding_popup_menu(struct nsgtk_scaffolding *gs,
GtkAccelGroup *group)
{
struct nsgtk_popup_menu *nmenu;
@ -1013,6 +1067,7 @@ static void nsgtk_menu_set_sensitivity(struct nsgtk_scaffolding *g)
}
}
/* set menu items to have icons */
static void nsgtk_menu_set_icons(struct nsgtk_scaffolding *g)
{
@ -1041,6 +1096,7 @@ static void nsgtk_menu_set_icons(struct nsgtk_scaffolding *g)
}
}
/**
* create and initialise menus
*
@ -1103,10 +1159,6 @@ static nserror nsgtk_menus_create(struct nsgtk_scaffolding *gs)
}
/* exported function documented in gtk/scaffolding.h */
void nsgtk_scaffolding_set_title(struct gui_window *gw, const char *title)
{
@ -1189,12 +1241,6 @@ GtkNotebook* nsgtk_scaffolding_notebook(struct nsgtk_scaffolding *g)
return g->notebook;
}
/* exported interface documented in gtk/scaffolding.h */
GtkWidget *nsgtk_scaffolding_urlbar(struct nsgtk_scaffolding *g)
{
return NULL;//g->url_bar;
}
/* exported interface documented in gtk/scaffolding.h */
GtkMenuBar *nsgtk_scaffolding_menu_bar(struct nsgtk_scaffolding *gs)
@ -1373,6 +1419,8 @@ struct nsgtk_scaffolding *nsgtk_new_scaffolding(struct gui_window *toplevel)
{
nserror res;
struct nsgtk_scaffolding *gs;
bool menu;
bool tool;
gs = calloc(1, sizeof(*gs));
if (gs == NULL) {
@ -1457,6 +1505,14 @@ struct nsgtk_scaffolding *nsgtk_new_scaffolding(struct gui_window *toplevel)
gs->prev = NULL;
scaf_list = gs;
/* set menu and tool bar visibility */
get_bar_show(&menu, &tool);
if (menu) {
gtk_widget_show(GTK_WIDGET(gs->menu_bar->bar_menu));
} else {
gtk_widget_hide(GTK_WIDGET(gs->menu_bar->bar_menu));
}
/* finally, show the window. */
gtk_widget_show(GTK_WIDGET(gs->window));

View File

@ -79,12 +79,6 @@ GtkWindow *nsgtk_scaffolding_window(struct nsgtk_scaffolding *g);
*/
GtkNotebook *nsgtk_scaffolding_notebook(struct nsgtk_scaffolding *g);
/**
* Get the gtk url bar from a scaffold.
*/
GtkWidget *nsgtk_scaffolding_urlbar(struct nsgtk_scaffolding *g);
struct gtk_search *nsgtk_scaffolding_search(struct nsgtk_scaffolding *g);
GtkMenuBar *nsgtk_scaffolding_menu_bar(struct nsgtk_scaffolding *g);

View File

@ -3608,7 +3608,6 @@ nserror nsgtk_toolbar_show(struct nsgtk_toolbar *tb, bool show)
gtk_widget_show(GTK_WIDGET(tb->widget));
} else {
gtk_widget_hide(GTK_WIDGET(tb->widget));
}
return NSERROR_OK;
}

View File

@ -707,6 +707,22 @@ static struct browser_window *bw_from_gw(void *data)
}
static bool get_tool_bar_show(void)
{
const char *cur_bar_show;
cur_bar_show = nsoption_charp(bar_show);
if (cur_bar_show != NULL) {
if (strcmp(cur_bar_show, "menu/tool") == 0) {
return true;
} else if (strcmp(cur_bar_show, "tool") == 0) {
return true;
}
}
return false;
}
/**
* Create and open a gtk container (window or tab) for a browsing context.
*
@ -887,6 +903,9 @@ gui_window_create(struct browser_window *bw,
/* initialy should not be visible */
nsgtk_search_toggle_visibility(g->search);
/* set toolbar visibility from user option */
nsgtk_toolbar_show(g->toolbar, get_tool_bar_show());
/* safe to drop the reference to the tab_builder as the container is
* referenced by the notebook now.
*/