mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-24 04:56:50 +03:00
complete toolbar button click handler implementation
This commit is contained in:
parent
08d7c55cc5
commit
e36338b617
@ -90,10 +90,6 @@ static gboolean nsgtk_on_##q##_activate_menu(GtkMenuItem *widget, gpointer data)
|
|||||||
static gboolean nsgtk_on_##q##_activate(struct nsgtk_scaffolding *g)
|
static gboolean nsgtk_on_##q##_activate(struct nsgtk_scaffolding *g)
|
||||||
|
|
||||||
|
|
||||||
/** Macro to define a handler for button events. */
|
|
||||||
#define BUTTONHANDLER(q)\
|
|
||||||
static gboolean nsgtk_on_##q##_activate(GtkButton *widget, gpointer data)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* handle menu activate signals by calling toolbar item activation
|
* handle menu activate signals by calling toolbar item activation
|
||||||
*/
|
*/
|
||||||
@ -574,41 +570,6 @@ nsgtk_window_tabs_remove(GtkNotebook *notebook,
|
|||||||
nsgtk_scaffolding_set_sensitivity(gs);
|
nsgtk_scaffolding_set_sensitivity(gs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle opening a file path.
|
|
||||||
*
|
|
||||||
* \param filename The filename to open.
|
|
||||||
*/
|
|
||||||
static void nsgtk_openfile_open(const char *filename)
|
|
||||||
{
|
|
||||||
struct browser_window *bw;
|
|
||||||
char *urltxt;
|
|
||||||
nsurl *url;
|
|
||||||
nserror error;
|
|
||||||
|
|
||||||
bw = nsgtk_get_browser_window(scaf_current->top_level);
|
|
||||||
|
|
||||||
urltxt = malloc(strlen(filename) + FILE_SCHEME_PREFIX_LEN + 1);
|
|
||||||
|
|
||||||
if (urltxt != NULL) {
|
|
||||||
sprintf(urltxt, FILE_SCHEME_PREFIX"%s", filename);
|
|
||||||
|
|
||||||
error = nsurl_create(urltxt, &url);
|
|
||||||
if (error != NSERROR_OK) {
|
|
||||||
nsgtk_warning(messages_get_errorcode(error), 0);
|
|
||||||
} else {
|
|
||||||
browser_window_navigate(bw,
|
|
||||||
url,
|
|
||||||
NULL,
|
|
||||||
BW_NAVIGATE_HISTORY,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL);
|
|
||||||
nsurl_unref(url);
|
|
||||||
}
|
|
||||||
free(urltxt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* signal handlers for menu entries */
|
/* signal handlers for menu entries */
|
||||||
|
|
||||||
@ -967,113 +928,46 @@ MENUHANDLER(reload, RELOAD_BUTTON);
|
|||||||
*/
|
*/
|
||||||
MENUHANDLER(back, BACK_BUTTON);
|
MENUHANDLER(back, BACK_BUTTON);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* menu signal handler for activation on forward item
|
||||||
|
*/
|
||||||
|
MENUHANDLER(forward, FORWARD_BUTTON);
|
||||||
|
|
||||||
MULTIHANDLER(forward)
|
/**
|
||||||
{
|
* menu signal handler for activation on home item
|
||||||
struct browser_window *bw =
|
*/
|
||||||
nsgtk_get_browser_window(g->top_level);
|
MENUHANDLER(home, HOME_BUTTON);
|
||||||
|
|
||||||
if ((bw == NULL) || (!browser_window_history_forward_available(bw)))
|
/**
|
||||||
return TRUE;
|
* menu signal handler for activation on localhistory item
|
||||||
|
*/
|
||||||
|
MENUHANDLER(localhistory, LOCALHISTORY_BUTTON);
|
||||||
|
|
||||||
/* clear potential search effects */
|
/**
|
||||||
browser_window_search_clear(bw);
|
* menu signal handler for activation on globalhistory item
|
||||||
|
*/
|
||||||
|
MENUHANDLER(globalhistory, GLOBALHISTORY_BUTTON);
|
||||||
|
|
||||||
browser_window_history_forward(bw, false);
|
/**
|
||||||
scaffolding_update_context(g);
|
* menu signal handler for activation on addbookmarks item
|
||||||
|
*/
|
||||||
|
MENUHANDLER(addbookmarks, ADDBOOKMARKS_BUTTON);
|
||||||
|
|
||||||
return TRUE;
|
/**
|
||||||
}
|
* menu signal handler for activation on showbookmarks item
|
||||||
|
*/
|
||||||
|
MENUHANDLER(showbookmarks, SHOWBOOKMARKS_BUTTON);
|
||||||
|
|
||||||
MULTIHANDLER(home)
|
/**
|
||||||
{
|
* menu signal handler for activation on showcookies item
|
||||||
static const char *addr = NETSURF_HOMEPAGE;
|
*/
|
||||||
struct browser_window *bw = nsgtk_get_browser_window(g->top_level);
|
MENUHANDLER(showcookies, SHOWCOOKIES_BUTTON);
|
||||||
nsurl *url;
|
|
||||||
nserror error;
|
|
||||||
|
|
||||||
if (nsoption_charp(homepage_url) != NULL) {
|
/**
|
||||||
addr = nsoption_charp(homepage_url);
|
* menu signal handler for activation on showcookies item
|
||||||
}
|
*/
|
||||||
|
MENUHANDLER(openlocation, OPENLOCATION_BUTTON);
|
||||||
|
|
||||||
error = nsurl_create(addr, &url);
|
|
||||||
if (error != NSERROR_OK) {
|
|
||||||
nsgtk_warning(messages_get_errorcode(error), 0);
|
|
||||||
} else {
|
|
||||||
browser_window_navigate(bw,
|
|
||||||
url,
|
|
||||||
NULL,
|
|
||||||
BW_NAVIGATE_HISTORY,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL);
|
|
||||||
nsurl_unref(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
MULTIHANDLER(localhistory)
|
|
||||||
{
|
|
||||||
struct browser_window *bw = nsgtk_get_browser_window(g->top_level);
|
|
||||||
nserror res;
|
|
||||||
|
|
||||||
res = nsgtk_local_history_present(g->window, bw);
|
|
||||||
if (res != NSERROR_OK) {
|
|
||||||
NSLOG(netsurf, INFO,
|
|
||||||
"Unable to initialise local history window.");
|
|
||||||
}
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
MULTIHANDLER(globalhistory)
|
|
||||||
{
|
|
||||||
nserror res;
|
|
||||||
res = nsgtk_global_history_present();
|
|
||||||
if (res != NSERROR_OK) {
|
|
||||||
NSLOG(netsurf, INFO,
|
|
||||||
"Unable to initialise global history window.");
|
|
||||||
}
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
MULTIHANDLER(addbookmarks)
|
|
||||||
{
|
|
||||||
struct browser_window *bw = nsgtk_get_browser_window(g->top_level);
|
|
||||||
|
|
||||||
if (bw == NULL || !browser_window_has_content(bw))
|
|
||||||
return TRUE;
|
|
||||||
hotlist_add_url(browser_window_access_url(bw));
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
MULTIHANDLER(showbookmarks)
|
|
||||||
{
|
|
||||||
nserror res;
|
|
||||||
res = nsgtk_hotlist_present();
|
|
||||||
if (res != NSERROR_OK) {
|
|
||||||
NSLOG(netsurf, INFO, "Unable to initialise bookmark window.");
|
|
||||||
}
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
MULTIHANDLER(showcookies)
|
|
||||||
{
|
|
||||||
nserror res;
|
|
||||||
res = nsgtk_cookies_present();
|
|
||||||
if (res != NSERROR_OK) {
|
|
||||||
NSLOG(netsurf, INFO, "Unable to initialise cookies window.");
|
|
||||||
}
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
MULTIHANDLER(openlocation)
|
|
||||||
{
|
|
||||||
#if 0
|
|
||||||
gtk_widget_grab_focus(GTK_WIDGET(g->url_bar));
|
|
||||||
#endif
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
MULTIHANDLER(nexttab)
|
MULTIHANDLER(nexttab)
|
||||||
{
|
{
|
||||||
@ -1101,86 +995,29 @@ nsgtk_on_closetab_activate_menu(GtkMenuItem *widget, gpointer data)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
MULTIHANDLER(contents)
|
/**
|
||||||
{
|
* menu signal handler for activation on showcookies item
|
||||||
struct browser_window *bw = nsgtk_get_browser_window(g->top_level);
|
*/
|
||||||
nsurl *url;
|
MENUHANDLER(contents, CONTENTS_BUTTON);
|
||||||
nserror error;
|
|
||||||
|
|
||||||
error = nsurl_create("http://www.netsurf-browser.org/documentation/", &url);
|
/**
|
||||||
if (error != NSERROR_OK) {
|
* menu signal handler for activation on showcookies item
|
||||||
nsgtk_warning(messages_get_errorcode(error), 0);
|
*/
|
||||||
} else {
|
MENUHANDLER(guide, GUIDE_BUTTON);
|
||||||
browser_window_navigate(bw,
|
|
||||||
url,
|
|
||||||
NULL,
|
|
||||||
BW_NAVIGATE_HISTORY,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL);
|
|
||||||
nsurl_unref(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
/**
|
||||||
}
|
* menu signal handler for activation on showcookies item
|
||||||
|
*/
|
||||||
|
MENUHANDLER(info, INFO_BUTTON);
|
||||||
|
|
||||||
MULTIHANDLER(guide)
|
/**
|
||||||
{
|
* menu signal handler for activation on showcookies item
|
||||||
struct browser_window *bw = nsgtk_get_browser_window(g->top_level);
|
*/
|
||||||
nsurl *url;
|
MENUHANDLER(about, ABOUT_BUTTON);
|
||||||
|
|
||||||
if (nsurl_create("http://www.netsurf-browser.org/documentation/guide", &url) != NSERROR_OK) {
|
|
||||||
nsgtk_warning("NoMemory", 0);
|
|
||||||
} else {
|
|
||||||
browser_window_navigate(bw,
|
|
||||||
url,
|
|
||||||
NULL,
|
|
||||||
BW_NAVIGATE_HISTORY,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL);
|
|
||||||
nsurl_unref(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
MULTIHANDLER(info)
|
|
||||||
{
|
|
||||||
struct browser_window *bw = nsgtk_get_browser_window(g->top_level);
|
|
||||||
nsurl *url;
|
|
||||||
|
|
||||||
if (nsurl_create("http://www.netsurf-browser.org/documentation/info", &url) != NSERROR_OK) {
|
|
||||||
nsgtk_warning("NoMemory", 0);
|
|
||||||
} else {
|
|
||||||
browser_window_navigate(bw,
|
|
||||||
url,
|
|
||||||
NULL,
|
|
||||||
BW_NAVIGATE_HISTORY,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL);
|
|
||||||
nsurl_unref(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
MULTIHANDLER(about)
|
|
||||||
{
|
|
||||||
nsgtk_about_dialog_init(g->window);
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
BUTTONHANDLER(history)
|
|
||||||
{
|
|
||||||
struct nsgtk_scaffolding *g = (struct nsgtk_scaffolding *)data;
|
|
||||||
return nsgtk_on_localhistory_activate(g);
|
|
||||||
}
|
|
||||||
|
|
||||||
#undef MULTIHANDLER
|
#undef MULTIHANDLER
|
||||||
#undef CHECKHANDLER
|
#undef MENUHANDLER
|
||||||
#undef BUTTONHANDLER
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* attach gtk signal handlers for menus
|
* attach gtk signal handlers for menus
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
#include "desktop/save_complete.h"
|
#include "desktop/save_complete.h"
|
||||||
#include "desktop/save_text.h"
|
#include "desktop/save_text.h"
|
||||||
#include "desktop/print.h"
|
#include "desktop/print.h"
|
||||||
|
#include "desktop/hotlist.h"
|
||||||
#include "netsurf/content.h"
|
#include "netsurf/content.h"
|
||||||
#include "netsurf/browser_window.h"
|
#include "netsurf/browser_window.h"
|
||||||
#include "netsurf/keypress.h"
|
#include "netsurf/keypress.h"
|
||||||
@ -55,10 +56,16 @@
|
|||||||
#include "gtk/resources.h"
|
#include "gtk/resources.h"
|
||||||
#include "gtk/schedule.h"
|
#include "gtk/schedule.h"
|
||||||
#include "gtk/local_history.h"
|
#include "gtk/local_history.h"
|
||||||
|
#include "gtk/global_history.h"
|
||||||
|
#include "gtk/viewsource.h"
|
||||||
|
#include "gtk/download.h"
|
||||||
|
#include "gtk/viewdata.h"
|
||||||
#include "gtk/tabs.h"
|
#include "gtk/tabs.h"
|
||||||
#include "gtk/print.h"
|
#include "gtk/print.h"
|
||||||
#include "gtk/layout_pango.h"
|
#include "gtk/layout_pango.h"
|
||||||
#include "gtk/preferences.h"
|
#include "gtk/preferences.h"
|
||||||
|
#include "gtk/hotlist.h"
|
||||||
|
#include "gtk/cookies.h"
|
||||||
#include "gtk/toolbar.h"
|
#include "gtk/toolbar.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1696,6 +1703,111 @@ set_item_sensitivity(struct nsgtk_toolbar_item *item, bool sensitivity)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cause the toolbar browsing context to navigate to a new url.
|
||||||
|
*
|
||||||
|
* \param tb the toolbar context.
|
||||||
|
* \param urltxt The url string.
|
||||||
|
* \return NSERROR_OK on success else appropriate error code.
|
||||||
|
*/
|
||||||
|
static nserror
|
||||||
|
toolbar_navigate_to_url(struct nsgtk_toolbar *tb, const char *urltxt)
|
||||||
|
{
|
||||||
|
struct browser_window *bw;
|
||||||
|
nsurl *url;
|
||||||
|
nserror res;
|
||||||
|
|
||||||
|
res = nsurl_create(urltxt, &url);
|
||||||
|
if (res != NSERROR_OK) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
bw = tb->get_bw(tb->get_bw_ctx);
|
||||||
|
|
||||||
|
res = browser_window_navigate(bw,
|
||||||
|
url,
|
||||||
|
NULL,
|
||||||
|
BW_NAVIGATE_HISTORY,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL);
|
||||||
|
nsurl_unref(url);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* run a gtk file chooser as a save dialog to obtain a path
|
||||||
|
*/
|
||||||
|
static nserror
|
||||||
|
nsgtk_saveas_dialog(struct browser_window *bw,
|
||||||
|
const char *title,
|
||||||
|
GtkWindow *parent,
|
||||||
|
bool folder,
|
||||||
|
gchar **path_out)
|
||||||
|
{
|
||||||
|
nserror res;
|
||||||
|
GtkWidget *fc; /* file chooser widget */
|
||||||
|
GtkFileChooserAction action;
|
||||||
|
char *path; /* proposed path */
|
||||||
|
|
||||||
|
if (!browser_window_has_content(bw)) {
|
||||||
|
/* cannot save a page with no content */
|
||||||
|
return NSERROR_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (folder) {
|
||||||
|
action = GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER;
|
||||||
|
} else {
|
||||||
|
action = GTK_FILE_CHOOSER_ACTION_SAVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
fc = gtk_file_chooser_dialog_new(title,
|
||||||
|
parent,
|
||||||
|
action,
|
||||||
|
NSGTK_STOCK_CANCEL,
|
||||||
|
GTK_RESPONSE_CANCEL,
|
||||||
|
NSGTK_STOCK_SAVE,
|
||||||
|
GTK_RESPONSE_ACCEPT,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
/* set a default file name */
|
||||||
|
res = nsurl_nice(browser_window_access_url(bw), &path, false);
|
||||||
|
if (res != NSERROR_OK) {
|
||||||
|
path = strdup(messages_get("SaveText"));
|
||||||
|
if (path == NULL) {
|
||||||
|
gtk_widget_destroy(fc);
|
||||||
|
return NSERROR_NOMEM;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((!folder) || (access(path, F_OK) != 0)) {
|
||||||
|
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(fc), path);
|
||||||
|
}
|
||||||
|
free(path);
|
||||||
|
|
||||||
|
/* confirm overwriting */
|
||||||
|
gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(fc), TRUE);
|
||||||
|
|
||||||
|
/* run the dialog to let user select path */
|
||||||
|
if (gtk_dialog_run(GTK_DIALOG(fc)) != GTK_RESPONSE_ACCEPT) {
|
||||||
|
gtk_widget_destroy(fc);
|
||||||
|
return NSERROR_NOT_FOUND;
|
||||||
|
}
|
||||||
|
|
||||||
|
*path_out = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fc));
|
||||||
|
|
||||||
|
gtk_widget_destroy(fc);
|
||||||
|
|
||||||
|
return NSERROR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Toolbar button clicked handlers
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* callback for all toolbar items widget size allocation
|
* callback for all toolbar items widget size allocation
|
||||||
*
|
*
|
||||||
@ -1779,35 +1891,6 @@ back_button_clicked_cb(GtkWidget *widget, gpointer data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* handler for local history 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
|
|
||||||
localhistory_button_clicked_cb(GtkWidget *widget, gpointer data)
|
|
||||||
{
|
|
||||||
nserror res;
|
|
||||||
struct nsgtk_toolbar *tb = (struct nsgtk_toolbar *)data;
|
|
||||||
struct browser_window *bw;
|
|
||||||
GtkWidget *toplevel;
|
|
||||||
|
|
||||||
toplevel = gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW);
|
|
||||||
if (toplevel != NULL) {
|
|
||||||
bw = tb->get_bw(tb->get_bw_ctx);
|
|
||||||
|
|
||||||
res = nsgtk_local_history_present(GTK_WINDOW(toplevel), bw);
|
|
||||||
if (res != NSERROR_OK) {
|
|
||||||
NSLOG(netsurf, INFO,
|
|
||||||
"Unable to present local history window.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* handler for forward tool bar item clicked signal
|
* handler for forward tool bar item clicked signal
|
||||||
*
|
*
|
||||||
@ -1891,11 +1974,9 @@ reload_button_clicked_cb(GtkWidget *widget, gpointer data)
|
|||||||
static gboolean
|
static gboolean
|
||||||
home_button_clicked_cb(GtkWidget *widget, gpointer data)
|
home_button_clicked_cb(GtkWidget *widget, gpointer data)
|
||||||
{
|
{
|
||||||
nserror res;
|
|
||||||
struct nsgtk_toolbar *tb = (struct nsgtk_toolbar *)data;
|
struct nsgtk_toolbar *tb = (struct nsgtk_toolbar *)data;
|
||||||
|
nserror res;
|
||||||
const char *addr;
|
const char *addr;
|
||||||
struct browser_window *bw;
|
|
||||||
nsurl *url;
|
|
||||||
|
|
||||||
if (nsoption_charp(homepage_url) != NULL) {
|
if (nsoption_charp(homepage_url) != NULL) {
|
||||||
addr = nsoption_charp(homepage_url);
|
addr = nsoption_charp(homepage_url);
|
||||||
@ -1903,19 +1984,7 @@ home_button_clicked_cb(GtkWidget *widget, gpointer data)
|
|||||||
addr = NETSURF_HOMEPAGE;
|
addr = NETSURF_HOMEPAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
res = nsurl_create(addr, &url);
|
res = toolbar_navigate_to_url(tb, addr);
|
||||||
if (res == NSERROR_OK) {
|
|
||||||
bw = tb->get_bw(tb->get_bw_ctx);
|
|
||||||
|
|
||||||
res = browser_window_navigate(bw,
|
|
||||||
url,
|
|
||||||
NULL,
|
|
||||||
BW_NAVIGATE_HISTORY,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL);
|
|
||||||
nsurl_unref(url);
|
|
||||||
}
|
|
||||||
if (res != NSERROR_OK) {
|
if (res != NSERROR_OK) {
|
||||||
nsgtk_warning(messages_get_errorcode(res), 0);
|
nsgtk_warning(messages_get_errorcode(res), 0);
|
||||||
}
|
}
|
||||||
@ -2226,69 +2295,6 @@ closewindow_button_clicked_cb(GtkWidget *widget, gpointer data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static nserror
|
|
||||||
nsgtk_saveas_dialog(struct browser_window *bw,
|
|
||||||
const char *title,
|
|
||||||
GtkWindow *parent,
|
|
||||||
bool folder,
|
|
||||||
gchar **path_out)
|
|
||||||
{
|
|
||||||
nserror res;
|
|
||||||
GtkWidget *fc; /* file chooser widget */
|
|
||||||
GtkFileChooserAction action;
|
|
||||||
char *path; /* proposed path */
|
|
||||||
|
|
||||||
if (!browser_window_has_content(bw)) {
|
|
||||||
/* cannot save a page with no content */
|
|
||||||
return NSERROR_INVALID;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (folder) {
|
|
||||||
action = GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER;
|
|
||||||
} else {
|
|
||||||
action = GTK_FILE_CHOOSER_ACTION_SAVE;
|
|
||||||
}
|
|
||||||
|
|
||||||
fc = gtk_file_chooser_dialog_new(title,
|
|
||||||
parent,
|
|
||||||
action,
|
|
||||||
NSGTK_STOCK_CANCEL,
|
|
||||||
GTK_RESPONSE_CANCEL,
|
|
||||||
NSGTK_STOCK_SAVE,
|
|
||||||
GTK_RESPONSE_ACCEPT,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
/* set a default file name */
|
|
||||||
res = nsurl_nice(browser_window_access_url(bw), &path, false);
|
|
||||||
if (res != NSERROR_OK) {
|
|
||||||
path = strdup(messages_get("SaveText"));
|
|
||||||
if (path == NULL) {
|
|
||||||
gtk_widget_destroy(fc);
|
|
||||||
return NSERROR_NOMEM;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((!folder) || (access(path, F_OK) != 0)) {
|
|
||||||
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(fc), path);
|
|
||||||
}
|
|
||||||
free(path);
|
|
||||||
|
|
||||||
/* confirm overwriting */
|
|
||||||
gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(fc), TRUE);
|
|
||||||
|
|
||||||
/* run the dialog to let user select path */
|
|
||||||
if (gtk_dialog_run(GTK_DIALOG(fc)) != GTK_RESPONSE_ACCEPT) {
|
|
||||||
gtk_widget_destroy(fc);
|
|
||||||
return NSERROR_NOT_FOUND;
|
|
||||||
}
|
|
||||||
|
|
||||||
*path_out = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fc));
|
|
||||||
|
|
||||||
gtk_widget_destroy(fc);
|
|
||||||
|
|
||||||
return NSERROR_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* handler for full save export tool bar item clicked signal
|
* handler for full save export tool bar item clicked signal
|
||||||
*
|
*
|
||||||
@ -3013,6 +3019,220 @@ debugdomtree_button_clicked_cb(GtkWidget *widget, gpointer data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* handler for local history 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
|
||||||
|
localhistory_button_clicked_cb(GtkWidget *widget, gpointer data)
|
||||||
|
{
|
||||||
|
nserror res;
|
||||||
|
struct nsgtk_toolbar *tb = (struct nsgtk_toolbar *)data;
|
||||||
|
struct browser_window *bw;
|
||||||
|
GtkWidget *toplevel;
|
||||||
|
|
||||||
|
toplevel = gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW);
|
||||||
|
if (toplevel != NULL) {
|
||||||
|
bw = tb->get_bw(tb->get_bw_ctx);
|
||||||
|
|
||||||
|
res = nsgtk_local_history_present(GTK_WINDOW(toplevel), bw);
|
||||||
|
if (res != NSERROR_OK) {
|
||||||
|
NSLOG(netsurf, INFO,
|
||||||
|
"Unable to present local history window.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* handler for global history 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
|
||||||
|
globalhistory_button_clicked_cb(GtkWidget *widget, gpointer data)
|
||||||
|
{
|
||||||
|
nserror res;
|
||||||
|
res = nsgtk_global_history_present();
|
||||||
|
if (res != NSERROR_OK) {
|
||||||
|
NSLOG(netsurf, INFO,
|
||||||
|
"Unable to initialise global history window.");
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* handler for add bookmark 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
|
||||||
|
addbookmarks_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);
|
||||||
|
if (browser_window_has_content(bw)) {
|
||||||
|
hotlist_add_url(browser_window_access_url(bw));
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* handler for show bookmark 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
|
||||||
|
showbookmarks_button_clicked_cb(GtkWidget *widget, gpointer data)
|
||||||
|
{
|
||||||
|
nserror res;
|
||||||
|
res = nsgtk_hotlist_present();
|
||||||
|
if (res != NSERROR_OK) {
|
||||||
|
NSLOG(netsurf, INFO, "Unable to initialise bookmark window.");
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* handler for show cookies 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
|
||||||
|
showcookies_button_clicked_cb(GtkWidget *widget, gpointer data)
|
||||||
|
{
|
||||||
|
nserror res;
|
||||||
|
res = nsgtk_cookies_present();
|
||||||
|
if (res != NSERROR_OK) {
|
||||||
|
NSLOG(netsurf, INFO, "Unable to initialise cookies window.");
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* handler for open location 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
|
||||||
|
openlocation_button_clicked_cb(GtkWidget *widget, gpointer data)
|
||||||
|
{
|
||||||
|
struct nsgtk_toolbar *tb = (struct nsgtk_toolbar *)data;
|
||||||
|
GtkToolItem *urltitem;
|
||||||
|
|
||||||
|
urltitem = tb->buttons[URL_BAR_ITEM]->button;
|
||||||
|
if (urltitem != NULL) {
|
||||||
|
GtkEntry *entry;
|
||||||
|
entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(urltitem)));
|
||||||
|
gtk_widget_grab_focus(GTK_WIDGET(entry));
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* handler for contents 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
|
||||||
|
contents_button_clicked_cb(GtkWidget *widget, gpointer data)
|
||||||
|
{
|
||||||
|
struct nsgtk_toolbar *tb = (struct nsgtk_toolbar *)data;
|
||||||
|
nserror res;
|
||||||
|
|
||||||
|
res = toolbar_navigate_to_url(tb, "http://www.netsurf-browser.org/documentation/");
|
||||||
|
if (res != NSERROR_OK) {
|
||||||
|
nsgtk_warning(messages_get_errorcode(res), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* handler for contents 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
|
||||||
|
guide_button_clicked_cb(GtkWidget *widget, gpointer data)
|
||||||
|
{
|
||||||
|
struct nsgtk_toolbar *tb = (struct nsgtk_toolbar *)data;
|
||||||
|
nserror res;
|
||||||
|
|
||||||
|
res = toolbar_navigate_to_url(tb, "http://www.netsurf-browser.org/documentation/guide");
|
||||||
|
if (res != NSERROR_OK) {
|
||||||
|
nsgtk_warning(messages_get_errorcode(res), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* handler for contents 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
|
||||||
|
info_button_clicked_cb(GtkWidget *widget, gpointer data)
|
||||||
|
{
|
||||||
|
struct nsgtk_toolbar *tb = (struct nsgtk_toolbar *)data;
|
||||||
|
nserror res;
|
||||||
|
|
||||||
|
res = toolbar_navigate_to_url(tb, "http://www.netsurf-browser.org/documentation/info");
|
||||||
|
if (res != NSERROR_OK) {
|
||||||
|
nsgtk_warning(messages_get_errorcode(res), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* handler for contents 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
|
||||||
|
about_button_clicked_cb(GtkWidget *widget, gpointer data)
|
||||||
|
{
|
||||||
|
GtkWindow *parent; /* gtk window widget is in */
|
||||||
|
|
||||||
|
parent = GTK_WINDOW(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW));
|
||||||
|
|
||||||
|
nsgtk_about_dialog_init(parent);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create a toolbar item
|
* create a toolbar item
|
||||||
*
|
*
|
||||||
|
@ -128,17 +128,17 @@ TOOLBAR_ITEM(TOGGLEDEBUGGING_BUTTON, toggledebugging, true, toggledebugging_butt
|
|||||||
TOOLBAR_ITEM(SAVEBOXTREE_BUTTON, debugboxtree, true, debugboxtree_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(SAVEDOMTREE_BUTTON, debugdomtree, true, debugdomtree_button_clicked_cb)
|
||||||
TOOLBAR_ITEM(LOCALHISTORY_BUTTON, localhistory, true, localhistory_button_clicked_cb)
|
TOOLBAR_ITEM(LOCALHISTORY_BUTTON, localhistory, true, localhistory_button_clicked_cb)
|
||||||
TOOLBAR_ITEM(GLOBALHISTORY_BUTTON, globalhistory, true, NULL)
|
TOOLBAR_ITEM(GLOBALHISTORY_BUTTON, globalhistory, true, globalhistory_button_clicked_cb)
|
||||||
TOOLBAR_ITEM(ADDBOOKMARKS_BUTTON, addbookmarks, true, NULL)
|
TOOLBAR_ITEM(ADDBOOKMARKS_BUTTON, addbookmarks, true, addbookmarks_button_clicked_cb)
|
||||||
TOOLBAR_ITEM(SHOWBOOKMARKS_BUTTON, showbookmarks, true, NULL)
|
TOOLBAR_ITEM(SHOWBOOKMARKS_BUTTON, showbookmarks, true, showbookmarks_button_clicked_cb)
|
||||||
TOOLBAR_ITEM(SHOWCOOKIES_BUTTON, showcookies, true, NULL)
|
TOOLBAR_ITEM(SHOWCOOKIES_BUTTON, showcookies, true, showcookies_button_clicked_cb)
|
||||||
TOOLBAR_ITEM(OPENLOCATION_BUTTON, openlocation, true, NULL)
|
TOOLBAR_ITEM(OPENLOCATION_BUTTON, openlocation, true, openlocation_button_clicked_cb)
|
||||||
TOOLBAR_ITEM(NEXTTAB_BUTTON, nexttab, false, NULL)
|
TOOLBAR_ITEM(NEXTTAB_BUTTON, nexttab, false, NULL)
|
||||||
TOOLBAR_ITEM(PREVTAB_BUTTON, prevtab, false, NULL)
|
TOOLBAR_ITEM(PREVTAB_BUTTON, prevtab, false, NULL)
|
||||||
TOOLBAR_ITEM(CONTENTS_BUTTON, contents, true, NULL)
|
TOOLBAR_ITEM(CONTENTS_BUTTON, contents, true, contents_button_clicked_cb)
|
||||||
TOOLBAR_ITEM(GUIDE_BUTTON, guide, true, NULL)
|
TOOLBAR_ITEM(GUIDE_BUTTON, guide, true, guide_button_clicked_cb)
|
||||||
TOOLBAR_ITEM(INFO_BUTTON, info, true, NULL)
|
TOOLBAR_ITEM(INFO_BUTTON, info, true, info_button_clicked_cb)
|
||||||
TOOLBAR_ITEM(ABOUT_BUTTON, about, true, NULL)
|
TOOLBAR_ITEM(ABOUT_BUTTON, about, true, about_button_clicked_cb)
|
||||||
|
|
||||||
#ifdef TOOLBAR_ITEM_SET
|
#ifdef TOOLBAR_ITEM_SET
|
||||||
#undef TOOLBAR_ITEM
|
#undef TOOLBAR_ITEM
|
||||||
|
Loading…
Reference in New Issue
Block a user