From 46e1116aaa38793ff3a36fb5ff05e3be448df49f Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Thu, 5 Sep 2019 23:37:44 +0100 Subject: change toolbar customization to tab approach --- frontends/gtk/res/toolbar.gtk3.ui | 85 +++++++++++++++++++++++- frontends/gtk/scaffolding.c | 24 +------ frontends/gtk/toolbar.c | 133 ++++++++++++++++++++++++++------------ frontends/gtk/toolbar_items.h | 2 + 4 files changed, 182 insertions(+), 62 deletions(-) (limited to 'frontends/gtk') diff --git a/frontends/gtk/res/toolbar.gtk3.ui b/frontends/gtk/res/toolbar.gtk3.ui index 1f1148703..b9eee2ccd 100644 --- a/frontends/gtk/res/toolbar.gtk3.ui +++ b/frontends/gtk/res/toolbar.gtk3.ui @@ -1,5 +1,5 @@ - + @@ -14,6 +14,9 @@ False gtkToolBarTitle dialog + + + False @@ -134,4 +137,84 @@ + + True + False + vertical + + + True + False + + + False + True + 0 + + + + + True + False + + + False + True + 1 + + + + + True + False + end + + + Reset + True + True + True + + + True + True + 0 + + + + + gtk-discard + True + True + True + True + + + True + True + 1 + + + + + gtk-apply + True + True + True + True + + + True + True + 2 + + + + + False + True + 2 + + + diff --git a/frontends/gtk/scaffolding.c b/frontends/gtk/scaffolding.c index 1022e76df..a2c3a7dee 100644 --- a/frontends/gtk/scaffolding.c +++ b/frontends/gtk/scaffolding.c @@ -586,15 +586,6 @@ nsgtk_on_link_copy_activate_menu(GtkMenuItem *widget, gpointer data) } -static gboolean -nsgtk_on_customize_activate_menu(GtkMenuItem *widget, gpointer data) -{ - struct nsgtk_scaffolding *g = (struct nsgtk_scaffolding *)data; - nsgtk_toolbar_customization_init(g); - return TRUE; -} - - static gboolean nsgtk_on_find_activate_menu(GtkMenuItem *widget, gpointer data) { struct nsgtk_scaffolding *g = (struct nsgtk_scaffolding *)data; @@ -773,10 +764,6 @@ static void nsgtk_menu_connect_signals(struct nsgtk_scaffolding *g) "toggled", G_CALLBACK(nsgtk_on_toolbar_activate_menu), g); - g_signal_connect(g->menu_bar->view_submenu->toolbars_submenu->customize_menuitem, - "activate", - G_CALLBACK(nsgtk_on_customize_activate_menu), - g); } @@ -807,10 +794,6 @@ create_scaffolding_burger_menu(struct nsgtk_scaffolding *gs, "toggled", G_CALLBACK(nsgtk_on_toolbar_activate_menu), gs); - g_signal_connect(nmenu->view_submenu->toolbars_submenu->customize_menuitem, - "activate", - G_CALLBACK(nsgtk_on_customize_activate_menu), - gs); return nmenu; } @@ -845,10 +828,6 @@ create_scaffolding_popup_menu(struct nsgtk_scaffolding *gs, GtkAccelGroup *group "toggled", G_CALLBACK(nsgtk_on_toolbar_activate_menu), gs); - g_signal_connect(nmenu->toolbars_submenu->customize_menuitem, - "activate", - G_CALLBACK(nsgtk_on_customize_activate_menu), - gs); /* set initial popup menu visibility */ popup_menu_hide(nmenu, false, false); @@ -974,6 +953,9 @@ static nserror nsgtk_menu_initialise(struct nsgtk_scaffolding *g) ITEM_MB(NEXTTAB, nexttab, view_submenu->tabs); ITEM_MB(PREVTAB, prevtab, view_submenu->tabs); ITEM_MB(CLOSETAB, closetab, view_submenu->tabs); + /* view - toolbars submenu */ + ITEM_MB(CUSTOMIZE, customize, view_submenu->toolbars); + g->menus[CUSTOMIZE_BUTTON].popup = g->popup_menu->toolbars_submenu->customize_menuitem; /* navigation menu */ ITEM_MBp(BACK, back, nav); diff --git a/frontends/gtk/toolbar.c b/frontends/gtk/toolbar.c index 5a7d252ad..dadddc27d 100644 --- a/frontends/gtk/toolbar.c +++ b/frontends/gtk/toolbar.c @@ -137,11 +137,21 @@ struct nsgtk_toolbar { void *get_ctx; }; +/** + * toolbar cusomisation context + */ +struct nsgtk_toolbar_customization { + /** + * first entry is a toolbar widget so a customisation widget + * can be cast to toolbar and back. + */ + struct nsgtk_toolbar toolbar; -static GtkTargetEntry entry = {(char *)"nsgtk_button_data", - GTK_TARGET_SAME_APP, 0}; - -static bool edit_mode = false; + /** + * toolbar gtk builder + */ + GtkBuilder *builder; +}; /** * toolbar customization window context @@ -158,6 +168,8 @@ struct nsgtk_toolbar_custom_store { bool fromstore; }; +static bool edit_mode = false; + /* the number of buttons that fit in the width of the store window */ #define NSGTK_STORE_WIDTH 6 @@ -233,11 +245,6 @@ nsgtk_toolbar_##name##_data_minus(GtkWidget *widget, \ #undef TOOLBAR_ITEM -/* exported interface documented in gtk/scaffolding.h */ -static GtkToolbar *nsgtk_scaffolding_toolbar(struct nsgtk_scaffolding *g) -{ - return NULL;//g->tool_bar; -} /** * get default image for buttons / menu items from gtk stock items. @@ -494,37 +501,6 @@ void nsgtk_theme_implement(struct nsgtk_scaffolding *g) } -/** - * callback function to iterate toolbar's widgets - */ -static void nsgtk_toolbar_clear_toolbar(GtkWidget *widget, gpointer data) -{ - struct nsgtk_scaffolding *g = (struct nsgtk_scaffolding *)data; - gtk_container_remove(GTK_CONTAINER(nsgtk_scaffolding_toolbar(g)), - widget); -} - -/** - * connect temporary handler for toolbar edit events - * - * \param g The scaffolding - * \param bi The button index - */ -static void nsgtk_toolbar_temp_connect(struct nsgtk_scaffolding *g, - nsgtk_toolbar_button bi) -{ - struct nsgtk_toolbar_item *bc; - - if (bi != URL_BAR_ITEM) { - bc = nsgtk_scaffolding_button(g, bi); - if ((bc->button != NULL) && (bc->dataminus != NULL)) { - g_signal_connect(bc->button, - "drag-data-get", - G_CALLBACK(bc->dataminus), - g); - } - } -} /** * get scaffolding button index of button at location @@ -817,6 +793,48 @@ make_toolbar_item(nsgtk_toolbar_button i, struct nsgtk_theme *theme) return w; } +#if 0 + +static GtkTargetEntry entry = {(char *)"nsgtk_button_data", + GTK_TARGET_SAME_APP, 0}; + +/* exported interface documented in gtk/scaffolding.h */ +static GtkToolbar *nsgtk_scaffolding_toolbar(struct nsgtk_scaffolding *g) +{ + return NULL;//g->tool_bar; +} + +/** + * callback function to iterate toolbar's widgets + */ +static void nsgtk_toolbar_clear_toolbar(GtkWidget *widget, gpointer data) +{ + struct nsgtk_scaffolding *g = (struct nsgtk_scaffolding *)data; + gtk_container_remove(GTK_CONTAINER(nsgtk_scaffolding_toolbar(g)), + widget); +} + +/** + * connect temporary handler for toolbar edit events + * + * \param g The scaffolding + * \param bi The button index + */ +static void nsgtk_toolbar_temp_connect(struct nsgtk_scaffolding *g, + nsgtk_toolbar_button bi) +{ + struct nsgtk_toolbar_item *bc; + + if (bi != URL_BAR_ITEM) { + bc = nsgtk_scaffolding_button(g, bi); + if ((bc->button != NULL) && (bc->dataminus != NULL)) { + g_signal_connect(bc->button, + "drag-data-get", + G_CALLBACK(bc->dataminus), + g); + } + } +} /* exported interface documented in gtk/scaffolding.h */ static void nsgtk_scaffolding_reset_offset(struct nsgtk_scaffolding *g) @@ -1498,7 +1516,42 @@ void nsgtk_toolbar_customization_init(struct nsgtk_scaffolding *g) /* open toolbar window */ nsgtk_toolbar_window_open(g); } +#endif +/** + * create a toolbar customization tab + * + * this is completely different approach to previous implementation. it + * is not modal and the toolbar configuration is performed completely + * within the tab. once the user is happy they can apply the change or + * cancel as they see fit while continuing to use the browser as usual. + */ +static gboolean cutomize_button_clicked_cb(GtkWidget *widget, gpointer data) +{ + struct nsgtk_toolbar *tb = (struct nsgtk_toolbar *)data; + struct nsgtk_toolbar_customization *tbc; + nserror res; + /* create nsgtk_toolbar_customization which has nsgtk_toolbar + * at the front so we can reuse functions that take + * nsgtk_toolbar + */ + tbc = calloc(1, sizeof(struct nsgtk_toolbar_customization)); + /* create builder*/ + res = nsgtk_builder_new_from_resname("toolbar", &tbc->builder); + if (res != NSERROR_OK) { + NSLOG(netsurf, INFO, "Toolbar UI builder init failed"); + return TRUE; + } + + /* get toolbar widget from builder */ + /* populate toolbar widget in edit mode */ + /* attach handlers to widgets */ + /* use layout box for widgets to drag to/from */ + /* save and update on apply button then discard */ + /* discard button causes destruction */ + /* close and cleanup on destroy signal */ + return TRUE; +} /** * \return toolbar item id when a widget is an element of the scaffolding diff --git a/frontends/gtk/toolbar_items.h b/frontends/gtk/toolbar_items.h index 0ed2f2af1..661cbef1d 100644 --- a/frontends/gtk/toolbar_items.h +++ b/frontends/gtk/toolbar_items.h @@ -72,6 +72,7 @@ typedef enum { INFO_BUTTON, ABOUT_BUTTON, OPENMENU_BUTTON, + CUSTOMIZE_BUTTON, PLACEHOLDER_BUTTON /* size indicator; array maximum indices */ } nsgtk_toolbar_button; /* PLACEHOLDER_BUTTON - 1 */ @@ -144,6 +145,7 @@ TOOLBAR_ITEM(GUIDE_BUTTON, guide, true, y, p) TOOLBAR_ITEM(INFO_BUTTON, info, true, y, p) TOOLBAR_ITEM(ABOUT_BUTTON, about, true, y, p) TOOLBAR_ITEM(OPENMENU_BUTTON, openmenu, true, y, n) +TOOLBAR_ITEM(CUSTOMIZE_BUTTON, cutomize, true, y, p) #ifdef TOOLBAR_ITEM_SET #undef TOOLBAR_ITEM -- cgit v1.2.3