summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--frontends/gtk/toolbar.c192
-rw-r--r--frontends/gtk/toolbar.h9
-rw-r--r--frontends/gtk/window.c13
-rw-r--r--frontends/gtk/window.h5
4 files changed, 131 insertions, 88 deletions
diff --git a/frontends/gtk/toolbar.c b/frontends/gtk/toolbar.c
index c3a95b9ea..9c51b5bd6 100644
--- a/frontends/gtk/toolbar.c
+++ b/frontends/gtk/toolbar.c
@@ -1095,72 +1095,10 @@ static void nsgtk_toolbar_cast(struct nsgtk_scaffolding *g)
-/**
- * save toolbar settings to file
- */
-static nserror nsgtk_toolbar_customisation_save(struct nsgtk_scaffolding *g)
-{
- char *choices = NULL;
- char *order;
- int order_len = PLACEHOLDER_BUTTON * 12; /* length of order buffer */
- int tbidx;
- char *cur;
- int plen;
- order = malloc(order_len);
-
- if (order == NULL) {
- return NSERROR_NOMEM;
- }
- cur = order;
-
- for (tbidx = BACK_BUTTON; tbidx < PLACEHOLDER_BUTTON; tbidx++) {
- plen = snprintf(cur,
- order_len,
- "%d;%d|",
- tbidx,
- nsgtk_scaffolding_button(g, tbidx)->location);
- if (plen == order_len) {
- /* ran out of space, bail early */
- NSLOG(netsurf, INFO,
- "toolbar ordering exceeded available space");
- break;
- }
- cur += plen;
- order_len -= plen;
- }
-
- nsoption_set_charp(toolbar_order, order);
-
- /* ensure choices are saved */
- netsurf_mkpath(&choices, NULL, 2, nsgtk_config_home, "Choices");
- if (choices != NULL) {
- nsoption_write(choices, NULL, NULL);
- free(choices);
- }
-
- return NSERROR_OK;
-}
/**
- * when 'save settings' button is clicked
- */
-static gboolean nsgtk_toolbar_persist(GtkWidget *widget, gpointer data)
-{
- struct nsgtk_scaffolding *g = (struct nsgtk_scaffolding *)data;
-
- edit_mode = false;
- /* save state to file, update toolbars for all windows */
- nsgtk_toolbar_customisation_save(g);
- nsgtk_toolbar_cast(g);
- nsgtk_toolbar_set_physical(g);
- nsgtk_toolbar_close(g);
- gtk_widget_destroy(window->window);
- return TRUE;
-}
-
-/**
* when 'reload defaults' button is clicked
*/
static gboolean nsgtk_toolbar_reset(GtkWidget *widget, gpointer data)
@@ -1401,6 +1339,77 @@ void nsgtk_toolbar_customisation_init(struct nsgtk_scaffolding *g)
}
#endif
+
+/**
+ * save toolbar settings to file
+ */
+static nserror
+nsgtk_toolbar_customisation_save(struct nsgtk_toolbar_customisation *tbc)
+{
+ char *choices = NULL;
+ char *order;
+ int order_len;
+ int tbidx;
+ char *cur;
+ int plen;
+
+ order_len = PLACEHOLDER_BUTTON * 12; /* length of order buffer */
+ order = malloc(order_len);
+
+ if (order == NULL) {
+ return NSERROR_NOMEM;
+ }
+ cur = order;
+
+ for (tbidx = BACK_BUTTON; tbidx < PLACEHOLDER_BUTTON; tbidx++) {
+ plen = snprintf(cur,
+ order_len,
+ "%d;%d|",
+ tbidx,
+ tbc->toolbar.buttons[tbidx]->location);
+ if (plen == order_len) {
+ /* ran out of space, bail early */
+ NSLOG(netsurf, INFO,
+ "toolbar ordering exceeded available space");
+ break;
+ }
+ cur += plen;
+ order_len -= plen;
+ }
+
+ nsoption_set_charp(toolbar_order, order);
+
+ /* ensure choices are saved */
+ netsurf_mkpath(&choices, NULL, 2, nsgtk_config_home, "Choices");
+ if (choices != NULL) {
+ nsoption_write(choices, NULL, NULL);
+ free(choices);
+ }
+
+ return NSERROR_OK;
+}
+
+
+/**
+ * customisation apply handler for clicked signal
+ *
+ * when 'save settings' button is clicked
+ */
+static gboolean
+customisation_apply_clicked_cb(GtkWidget *widget, gpointer data)
+{
+ struct nsgtk_toolbar_customisation *tbc;
+ tbc = (struct nsgtk_toolbar_customisation *)data;
+
+ /* save state to file, update toolbars for all windows */
+ nsgtk_toolbar_customisation_save(tbc);
+ nsgtk_window_toolbar_update();
+ gtk_widget_destroy(tbc->container);
+
+ return TRUE;
+}
+
+
/**
* find the toolbar item with a given location.
*
@@ -1654,7 +1663,7 @@ static void
customisation_toolbar_drag_leave_cb(GtkWidget *widget,
GdkDragContext *gdc,
guint time,
- gpointer data)
+ gpointer data)
{
gtk_toolbar_set_drop_highlight_item(GTK_TOOLBAR(widget), NULL, 0);
}
@@ -2257,7 +2266,7 @@ static gboolean cutomize_button_clicked_cb(GtkWidget *widget, gpointer data)
}
/* ensure icon sizes and text labels on toolbar are set */
- res = nsgtk_toolbar_update(&tbc->toolbar);
+ res = nsgtk_toolbar_restyle(&tbc->toolbar);
if (res != NSERROR_OK) {
goto cutomize_button_clicked_cb_error;
}
@@ -2309,12 +2318,12 @@ static gboolean cutomize_button_clicked_cb(GtkWidget *widget, gpointer data)
G_CALLBACK(gtk_widget_destroy),
tbc->container);
-#if 0
g_signal_connect(GTK_WIDGET(gtk_builder_get_object(builder, "apply")),
"clicked",
- G_CALLBACK(nsgtk_toolbar_persist),
- g);
+ G_CALLBACK(customisation_apply_clicked_cb),
+ tbc);
+#if 0
g_signal_connect(GTK_WIDGET(gtk_builder_get_object(builder, "reset")),
"clicked",
G_CALLBACK(nsgtk_toolbar_reset),
@@ -4021,30 +4030,12 @@ nsgtk_toolbar_create(GtkBuilder *builder,
}
}
- res = apply_user_button_customisation(tb);
- if (res != NSERROR_OK) {
- free(tb);
- return res;
- }
-
- res = populate_gtk_toolbar_widget(tb);
- if (res != NSERROR_OK) {
- free(tb);
- return res;
- }
-
res = nsgtk_toolbar_update(tb);
if (res != NSERROR_OK) {
free(tb);
return res;
}
- res = toolbar_connect_signals(tb);
- if (res != NSERROR_OK) {
- free(tb);
- return res;
- }
-
*tb_out = tb;
return NSERROR_OK;
}
@@ -4059,7 +4050,7 @@ nserror nsgtk_toolbar_destroy(struct nsgtk_toolbar *tb)
}
/* exported interface documented in toolbar.h */
-nserror nsgtk_toolbar_update(struct nsgtk_toolbar *tb)
+nserror nsgtk_toolbar_restyle(struct nsgtk_toolbar *tb)
{
/*
* reset toolbar size allocation so icon size change affects
@@ -4245,3 +4236,32 @@ nserror nsgtk_toolbar_show(struct nsgtk_toolbar *tb, bool show)
}
return NSERROR_OK;
}
+
+
+/* exported interface documented in toolbar.h */
+nserror nsgtk_toolbar_update(struct nsgtk_toolbar *tb)
+{
+ nserror res;
+
+ /* setup item locations based on user config */
+ res = apply_user_button_customisation(tb);
+ if (res != NSERROR_OK) {
+ return res;
+ }
+
+ /* populate toolbar widget */
+ res = populate_gtk_toolbar_widget(tb);
+ if (res != NSERROR_OK) {
+ return res;
+ }
+
+ /* ensure icon sizes and text labels on toolbar are set */
+ res = nsgtk_toolbar_restyle(tb);
+ if (res != NSERROR_OK) {
+ return res;
+ }
+
+ res = toolbar_connect_signals(tb);
+
+ return res;
+}
diff --git a/frontends/gtk/toolbar.h b/frontends/gtk/toolbar.h
index 75fb3abfa..b699898b9 100644
--- a/frontends/gtk/toolbar.h
+++ b/frontends/gtk/toolbar.h
@@ -43,6 +43,13 @@ nserror nsgtk_toolbar_create(GtkBuilder *builder, struct browser_window *(*get_b
*/
nserror nsgtk_toolbar_destroy(struct nsgtk_toolbar *toolbar);
+/**
+ * Update the toolbar items being shown based on current settings
+ *
+ * \param toolbar A toolbar returned from a creation
+ * \return NSERROR_OK on success
+ */
+nserror nsgtk_toolbar_update(struct nsgtk_toolbar *tb);
/**
* Update toolbar style and size based on current settings
@@ -50,7 +57,7 @@ nserror nsgtk_toolbar_destroy(struct nsgtk_toolbar *toolbar);
* \param toolbar A toolbar returned from a creation
* \return NSERROR_OK on success
*/
-nserror nsgtk_toolbar_update(struct nsgtk_toolbar *tb);
+nserror nsgtk_toolbar_restyle(struct nsgtk_toolbar *tb);
/**
diff --git a/frontends/gtk/window.c b/frontends/gtk/window.c
index 76e9863ee..9368d7003 100644
--- a/frontends/gtk/window.c
+++ b/frontends/gtk/window.c
@@ -1506,7 +1506,7 @@ nserror nsgtk_window_update_all(void)
struct gui_window *gw;
for (gw = window_list; gw != NULL; gw = gw->next) {
nsgtk_tab_options_changed(nsgtk_scaffolding_notebook(gw->scaffold));
- nsgtk_toolbar_update(gw->toolbar);
+ nsgtk_toolbar_restyle(gw->toolbar);
/** \todo update search bar */
browser_window_schedule_reformat(gw->bw);
}
@@ -1525,3 +1525,14 @@ nserror nsgtk_window_toolbar_show(struct nsgtk_scaffolding *gs, bool show)
}
return NSERROR_OK;
}
+
+/* exported interface documented in window.h */
+nserror nsgtk_window_toolbar_update(void)
+{
+ struct gui_window *gw;
+ for (gw = window_list; gw != NULL; gw = gw->next) {
+ nsgtk_toolbar_update(gw->toolbar);
+
+ }
+ return NSERROR_OK;
+}
diff --git a/frontends/gtk/window.h b/frontends/gtk/window.h
index 1b3c8aa24..9d8d16e8b 100644
--- a/frontends/gtk/window.h
+++ b/frontends/gtk/window.h
@@ -55,6 +55,11 @@ struct nsgtk_scaffolding *nsgtk_get_scaffold(struct gui_window *gw);
nserror nsgtk_window_update_all(void);
/**
+ * every window will have its toolbar updated to reflect user settings
+ */
+nserror nsgtk_window_toolbar_update(void);
+
+/**
* Windows associated with a scaffold will have their toolbar show state set
*/
nserror nsgtk_window_toolbar_show(struct nsgtk_scaffolding *gs, bool show);