another five handlers and fix menu sensitivity on throbber state change

This commit is contained in:
Vincent Sanders 2019-08-29 23:14:31 +01:00 committed by Daniel Silverstone
parent 45bd456cd8
commit 08d7c55cc5
7 changed files with 227 additions and 188 deletions

View File

@ -249,7 +249,7 @@ static nserror set_defaults(struct nsoption_s *defaults)
nsoption_set_int(button_type, 2);
break;
}
return NSERROR_OK;
}
@ -261,7 +261,7 @@ static nserror set_defaults(struct nsoption_s *defaults)
*
* \param argc The number of arguments on the command line
* \param argv A string vector of command line arguments.
* \respath A string vector of the path elements of resources
* \respath A string vector of the path elements of resources
*/
static nserror nsgtk_init(int argc, char** argv, char **respath)
{
@ -1204,7 +1204,7 @@ int main(int argc, char** argv)
NSLOG(netsurf, INFO, "Unable to load translated messages");
/** \todo decide if message load faliure should be fatal */
}
/* Locate the correct user cache directory path */
ret = get_cache_home(&cache_home);
if (ret == NSERROR_NOT_FOUND) {

View File

@ -927,160 +927,46 @@ nsgtk_on_toolbar_activate_menu(GtkMenuItem *widget, gpointer data)
return TRUE;
}
MULTIHANDLER(downloads)
{
nsgtk_download_show(g->window);
/**
* menu signal handler for activation on downloads item
*/
MENUHANDLER(downloads, DOWNLOADS_BUTTON);
return TRUE;
}
/**
* menu signal handler for activation on save window size item
*/
MENUHANDLER(savewindowsize, SAVEWINDOWSIZE_BUTTON);
MULTIHANDLER(savewindowsize)
{
int x,y,w,h;
char *choices = NULL;
/**
* menu signal handler for activation on toggle debug render item
*/
MENUHANDLER(toggledebugging, TOGGLEDEBUGGING_BUTTON);
gtk_window_get_position(g->window, &x, &y);
gtk_window_get_size(g->window, &w, &h);
/**
* menu signal handler for activation on debug box tree item
*/
MENUHANDLER(debugboxtree, SAVEBOXTREE_BUTTON);
nsoption_set_int(window_width, w);
nsoption_set_int(window_height, h);
nsoption_set_int(window_x, x);
nsoption_set_int(window_y, y);
/**
* menu signal handler for activation on debug dom tree item
*/
MENUHANDLER(debugdomtree, SAVEDOMTREE_BUTTON);
netsurf_mkpath(&choices, NULL, 2, nsgtk_config_home, "Choices");
if (choices != NULL) {
nsoption_write(choices, NULL, NULL);
free(choices);
}
/**
* menu signal handler for activation on stop item
*/
MENUHANDLER(stop, STOP_BUTTON);
return TRUE;
}
/**
* menu signal handler for activation on reload item
*/
MENUHANDLER(reload, RELOAD_BUTTON);
MULTIHANDLER(toggledebugging)
{
struct browser_window *bw;
/**
* menu signal handler for activation on back item
*/
MENUHANDLER(back, BACK_BUTTON);
bw = nsgtk_get_browser_window(g->top_level);
browser_window_debug(bw, CONTENT_DEBUG_REDRAW);
nsgtk_reflow_all_windows();
return TRUE;
}
MULTIHANDLER(debugboxtree)
{
gchar *fname;
gint handle;
FILE *f;
struct browser_window *bw;
handle = g_file_open_tmp("nsgtkboxtreeXXXXXX", &fname, NULL);
if ((handle == -1) || (fname == NULL)) {
return TRUE;
}
close(handle); /* in case it was binary mode */
/* save data to temporary file */
f = fopen(fname, "w");
if (f == NULL) {
nsgtk_warning("Error saving box tree dump.",
"Unable to open file for writing.");
unlink(fname);
return TRUE;
}
bw = nsgtk_get_browser_window(g->top_level);
browser_window_debug_dump(bw, f, CONTENT_DEBUG_RENDER);
fclose(f);
nsgtk_viewfile("Box Tree Debug", "boxtree", fname);
g_free(fname);
return TRUE;
}
MULTIHANDLER(debugdomtree)
{
gchar *fname;
gint handle;
FILE *f;
struct browser_window *bw;
handle = g_file_open_tmp("nsgtkdomtreeXXXXXX", &fname, NULL);
if ((handle == -1) || (fname == NULL)) {
return TRUE;
}
close(handle); /* in case it was binary mode */
/* save data to temporary file */
f = fopen(fname, "w");
if (f == NULL) {
nsgtk_warning("Error saving box tree dump.",
"Unable to open file for writing.");
unlink(fname);
return TRUE;
}
bw = nsgtk_get_browser_window(g->top_level);
browser_window_debug_dump(bw, f, CONTENT_DEBUG_DOM);
fclose(f);
nsgtk_viewfile("DOM Tree Debug", "domtree", fname);
g_free(fname);
return TRUE;
}
MULTIHANDLER(stop)
{
struct browser_window *bw =
nsgtk_get_browser_window(g->top_level);
browser_window_stop(bw);
return TRUE;
}
MULTIHANDLER(reload)
{
struct browser_window *bw =
nsgtk_get_browser_window(g->top_level);
if (bw == NULL)
return TRUE;
/* clear potential search effects */
browser_window_search_clear(bw);
browser_window_reload(bw, true);
return TRUE;
}
MULTIHANDLER(back)
{
struct browser_window *bw =
nsgtk_get_browser_window(g->top_level);
if ((bw == NULL) || (!browser_window_history_back_available(bw)))
return TRUE;
/* clear potential search effects */
browser_window_search_clear(bw);
browser_window_history_back(bw, false);
scaffolding_update_context(g);
return TRUE;
}
MULTIHANDLER(forward)
{
@ -1675,39 +1561,21 @@ void nsgtk_window_set_title(struct gui_window *gw, const char *title)
}
#if 0
static nserror gui_window_start_throbber(struct gui_window* gw)
/* exported interface documented in scaffolding.h */
nserror nsgtk_scaffolding_throbber(struct gui_window* gw, bool active)
{
struct nsgtk_scaffolding *g = nsgtk_get_scaffold(_g);
g->buttons[STOP_BUTTON]->sensitivity = true;
g->buttons[RELOAD_BUTTON]->sensitivity = false;
nsgtk_scaffolding_set_sensitivity(g);
scaffolding_update_context(g);
}
static nserror gui_window_stop_throbber(struct gui_window* gw)
{
nserror res;
GdkPixbuf *pixbuf;
struct nsgtk_scaffolding *g = nsgtk_get_scaffold(_g);
if (g == NULL) {
return;
struct nsgtk_scaffolding *gs = nsgtk_get_scaffold(gw);
if (active) {
gs->menus[STOP_BUTTON].sensitivity = true;
gs->menus[RELOAD_BUTTON].sensitivity = false;
} else {
gs->menus[STOP_BUTTON].sensitivity = false;
gs->menus[RELOAD_BUTTON].sensitivity = true;
}
scaffolding_update_context(gs);
if (g->buttons[STOP_BUTTON] != NULL)
g->buttons[STOP_BUTTON]->sensitivity = false;
if (g->buttons[RELOAD_BUTTON] != NULL)
g->buttons[RELOAD_BUTTON]->sensitivity = true;
nsgtk_scaffolding_set_sensitivity(g);
return NSERROR_OK;
}
#endif
static void

View File

@ -63,6 +63,11 @@ struct nsgtk_scaffolding *nsgtk_new_scaffolding(struct gui_window *gw);
*/
nserror nsgtk_scaffolding_destroy_all(void);
/**
* Update scaffolding window when throbber state changes
*/
nserror nsgtk_scaffolding_throbber(struct gui_window* gw, bool active);
/**
* Obtain the most recently used scaffolding element.
*

View File

@ -180,7 +180,7 @@ nsgtk_tab_switch_page_after(GtkNotebook *notebook,
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);
error = nsgtk_window_item_activate(gw, NEWTAB_BUTTON);
if (error != NSERROR_OK) {
NSLOG(netsurf, INFO,
"Failed to open new tab.");

View File

@ -2820,7 +2820,7 @@ fullscreen_button_clicked_cb(GtkWidget *widget, gpointer data)
/**
* handler for full screen tool bar item clicked signal
* handler for view source tool bar item clicked signal
*
* \param widget The widget the signal is being delivered to.
* \param data The toolbar context passed when the signal was connected
@ -2847,6 +2847,172 @@ viewsource_button_clicked_cb(GtkWidget *widget, gpointer data)
}
/**
* handler for show downloads tool bar item clicked signal
*
* \param widget The widget the signal is being delivered to.
* \param data The toolbar context passed when the signal was connected
* \return TRUE
*/
static gboolean
downloads_button_clicked_cb(GtkWidget *widget, gpointer data)
{
GtkWindow *gtkwindow; /* gtk window widget is in */
gtkwindow = GTK_WINDOW(gtk_widget_get_ancestor(widget,GTK_TYPE_WINDOW));
nsgtk_download_show(gtkwindow);
return TRUE;
}
/**
* handler for show downloads tool bar item clicked signal
*
* \param widget The widget the signal is being delivered to.
* \param data The toolbar context passed when the signal was connected
* \return TRUE
*/
static gboolean
savewindowsize_button_clicked_cb(GtkWidget *widget, gpointer data)
{
GtkWindow *gtkwindow; /* gtk window widget is in */
int x,y,w,h;
char *choices = NULL;
gtkwindow = GTK_WINDOW(gtk_widget_get_ancestor(widget,GTK_TYPE_WINDOW));
gtk_window_get_position(gtkwindow, &x, &y);
gtk_window_get_size(gtkwindow, &w, &h);
nsoption_set_int(window_width, w);
nsoption_set_int(window_height, h);
nsoption_set_int(window_x, x);
nsoption_set_int(window_y, y);
netsurf_mkpath(&choices, NULL, 2, nsgtk_config_home, "Choices");
if (choices != NULL) {
nsoption_write(choices, NULL, NULL);
free(choices);
}
return TRUE;
}
/**
* handler for show downloads tool bar item clicked signal
*
* \param widget The widget the signal is being delivered to.
* \param data The toolbar context passed when the signal was connected
* \return TRUE
*/
static gboolean
toggledebugging_button_clicked_cb(GtkWidget *widget, gpointer data)
{
struct nsgtk_toolbar *tb = (struct nsgtk_toolbar *)data;
struct browser_window *bw;
bw = tb->get_bw(tb->get_bw_ctx);
browser_window_debug(bw, CONTENT_DEBUG_REDRAW);
nsgtk_reflow_all_windows();
return TRUE;
}
/**
* handler for debug box tree tool bar item clicked signal
*
* \param widget The widget the signal is being delivered to.
* \param data The toolbar context passed when the signal was connected
* \return TRUE
*/
static gboolean
debugboxtree_button_clicked_cb(GtkWidget *widget, gpointer data)
{
struct nsgtk_toolbar *tb = (struct nsgtk_toolbar *)data;
struct browser_window *bw;
gchar *fname;
gint handle;
FILE *f;
handle = g_file_open_tmp("nsgtkboxtreeXXXXXX", &fname, NULL);
if ((handle == -1) || (fname == NULL)) {
return TRUE;
}
close(handle); /* in case it was binary mode */
/* save data to temporary file */
f = fopen(fname, "w");
if (f == NULL) {
nsgtk_warning("Error saving box tree dump.",
"Unable to open file for writing.");
unlink(fname);
return TRUE;
}
bw = tb->get_bw(tb->get_bw_ctx);
browser_window_debug_dump(bw, f, CONTENT_DEBUG_RENDER);
fclose(f);
nsgtk_viewfile("Box Tree Debug", "boxtree", fname);
g_free(fname);
return TRUE;
}
/**
* handler for debug dom tree tool bar item clicked signal
*
* \param widget The widget the signal is being delivered to.
* \param data The toolbar context passed when the signal was connected
* \return TRUE
*/
static gboolean
debugdomtree_button_clicked_cb(GtkWidget *widget, gpointer data)
{
struct nsgtk_toolbar *tb = (struct nsgtk_toolbar *)data;
struct browser_window *bw;
gchar *fname;
gint handle;
FILE *f;
handle = g_file_open_tmp("nsgtkdomtreeXXXXXX", &fname, NULL);
if ((handle == -1) || (fname == NULL)) {
return TRUE;
}
close(handle); /* in case it was binary mode */
/* save data to temporary file */
f = fopen(fname, "w");
if (f == NULL) {
nsgtk_warning("Error saving box tree dump.",
"Unable to open file for writing.");
unlink(fname);
return TRUE;
}
bw = tb->get_bw(tb->get_bw_ctx);
browser_window_debug_dump(bw, f, CONTENT_DEBUG_DOM);
fclose(f);
nsgtk_viewfile("DOM Tree Debug", "domtree", fname);
g_free(fname);
return TRUE;
}
/**
* create a toolbar item
*

View File

@ -63,7 +63,7 @@ typedef enum {
GLOBALHISTORY_BUTTON,
ADDBOOKMARKS_BUTTON,
SHOWBOOKMARKS_BUTTON,
SHOWCOOKIES_BUTTON,
SHOWCOOKIES_BUTTON,
OPENLOCATION_BUTTON,
NEXTTAB_BUTTON,
PREVTAB_BUTTON,
@ -122,11 +122,11 @@ TOOLBAR_ITEM(ZOOMMINUS_BUTTON, zoomminus, true, zoomminus_button_clicked_cb)
TOOLBAR_ITEM(ZOOMNORMAL_BUTTON, zoomnormal, true, zoomnormal_button_clicked_cb)
TOOLBAR_ITEM(FULLSCREEN_BUTTON, fullscreen, true, fullscreen_button_clicked_cb)
TOOLBAR_ITEM(VIEWSOURCE_BUTTON, viewsource, true, viewsource_button_clicked_cb)
TOOLBAR_ITEM(DOWNLOADS_BUTTON, downloads, true, NULL)
TOOLBAR_ITEM(SAVEWINDOWSIZE_BUTTON, savewindowsize, true, NULL)
TOOLBAR_ITEM(TOGGLEDEBUGGING_BUTTON, toggledebugging, true, NULL)
TOOLBAR_ITEM(SAVEBOXTREE_BUTTON, debugboxtree, true, NULL)
TOOLBAR_ITEM(SAVEDOMTREE_BUTTON, debugdomtree, true, NULL)
TOOLBAR_ITEM(DOWNLOADS_BUTTON, downloads, true, downloads_button_clicked_cb)
TOOLBAR_ITEM(SAVEWINDOWSIZE_BUTTON, savewindowsize, true, savewindowsize_button_clicked_cb)
TOOLBAR_ITEM(TOGGLEDEBUGGING_BUTTON, toggledebugging, true, toggledebugging_button_clicked_cb)
TOOLBAR_ITEM(SAVEBOXTREE_BUTTON, debugboxtree, true, debugboxtree_button_clicked_cb)
TOOLBAR_ITEM(SAVEDOMTREE_BUTTON, debugdomtree, true, debugdomtree_button_clicked_cb)
TOOLBAR_ITEM(LOCALHISTORY_BUTTON, localhistory, true, localhistory_button_clicked_cb)
TOOLBAR_ITEM(GLOBALHISTORY_BUTTON, globalhistory, true, NULL)
TOOLBAR_ITEM(ADDBOOKMARKS_BUTTON, addbookmarks, true, NULL)

View File

@ -1360,12 +1360,12 @@ gui_window_event(struct gui_window *gw, enum gui_window_event event)
case GW_EVENT_START_THROBBER:
nsgtk_toolbar_throbber(gw->toolbar, true);
/** \todo menu sensitivity for back/reload */
nsgtk_scaffolding_throbber(gw, true);
break;
case GW_EVENT_STOP_THROBBER:
nsgtk_toolbar_throbber(gw->toolbar, false);
/** \todo menu sensitivity for back/reload */
nsgtk_scaffolding_throbber(gw, false);
break;
default: