mirror of
https://github.com/netsurf-browser/netsurf
synced 2025-01-18 08:39:50 +03:00
stop gtk about dialog forcing navigation of existing browsing contexts
This commit is contained in:
parent
984299e5b4
commit
06a1d75d52
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2008 Mike Lester <element3260@gmail.com>
|
||||
* Copyright 2014 Vincent Sanders <vince@netsurf-browser.org>
|
||||
*
|
||||
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
||||
*
|
||||
@ -16,62 +16,56 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file gtk/dialogs/about.c
|
||||
*
|
||||
* Implementation of gtk about dialog.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "utils/utils.h"
|
||||
#include "utils/messages.h"
|
||||
#include "utils/nsoption.h"
|
||||
#include "desktop/browser.h"
|
||||
|
||||
#include "gtk/compat.h"
|
||||
#include "gtk/gui.h"
|
||||
#include "gtk/dialogs/about.h"
|
||||
|
||||
|
||||
/**
|
||||
* About dialog information button click.
|
||||
*
|
||||
* \param button The button widget that was clicked
|
||||
* \param data The text of the url to open
|
||||
*/
|
||||
static void
|
||||
nsgtk_about_dialog_credits(GtkWidget *button, gpointer data)
|
||||
nsgtk_about_dialog_info(GtkWidget *button, gpointer data)
|
||||
{
|
||||
struct browser_window *bw = data;
|
||||
nsurl *url;
|
||||
nserror ret;
|
||||
const char *url_text = data;
|
||||
enum browser_window_create_flags flags = BW_CREATE_HISTORY;
|
||||
|
||||
if (nsurl_create("about:credits", &url) != NSERROR_OK) {
|
||||
warn_user("NoMemory", 0);
|
||||
} else {
|
||||
browser_window_navigate(bw,
|
||||
url,
|
||||
NULL,
|
||||
BW_NAVIGATE_HISTORY,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
if (nsoption_bool(show_single_tab) == true) {
|
||||
flags |= BW_CREATE_TAB;
|
||||
}
|
||||
|
||||
ret = nsurl_create(url_text, &url);
|
||||
if (ret == NSERROR_OK) {
|
||||
ret = browser_window_create(flags, url, NULL, NULL, NULL);
|
||||
nsurl_unref(url);
|
||||
}
|
||||
|
||||
gtk_widget_destroy(gtk_widget_get_toplevel(button));
|
||||
}
|
||||
|
||||
static void
|
||||
nsgtk_about_dialog_licence(GtkWidget *button, gpointer data)
|
||||
{
|
||||
struct browser_window *bw = data;
|
||||
nsurl *url;
|
||||
|
||||
if (nsurl_create("about:licence", &url) != NSERROR_OK) {
|
||||
warn_user("NoMemory", 0);
|
||||
} else {
|
||||
browser_window_navigate(bw,
|
||||
url,
|
||||
NULL,
|
||||
BW_NAVIGATE_HISTORY,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
nsurl_unref(url);
|
||||
if (ret != NSERROR_OK) {
|
||||
warn_user(messages_get_errorcode(ret), 0);
|
||||
}
|
||||
|
||||
/* close about dialog */
|
||||
gtk_widget_destroy(gtk_widget_get_toplevel(button));
|
||||
}
|
||||
|
||||
void nsgtk_about_dialog_init(GtkWindow *parent,
|
||||
struct browser_window *bw,
|
||||
const char *version)
|
||||
void nsgtk_about_dialog_init(GtkWindow *parent, const char *version)
|
||||
{
|
||||
GtkWidget *dialog, *vbox, *button, *image, *label;
|
||||
gchar *name_string;
|
||||
@ -89,7 +83,7 @@ void nsgtk_about_dialog_init(GtkWindow *parent,
|
||||
vbox = nsgtk_vbox_new(FALSE, 8);
|
||||
|
||||
gtk_box_pack_start(GTK_BOX(nsgtk_dialog_get_content_area(GTK_DIALOG(dialog))), vbox, TRUE, TRUE, 0);
|
||||
|
||||
|
||||
if (pixbufs != NULL) {
|
||||
GtkIconSet *icon_set = gtk_icon_set_new_from_pixbuf(GDK_PIXBUF(g_list_nth_data(pixbufs, 0)));
|
||||
|
||||
@ -103,7 +97,7 @@ void nsgtk_about_dialog_init(GtkWindow *parent,
|
||||
|
||||
gtk_box_pack_start(GTK_BOX (vbox), image, FALSE, FALSE, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
label = gtk_label_new (NULL);
|
||||
gtk_label_set_markup (GTK_LABEL (label), name_string);
|
||||
@ -112,7 +106,7 @@ void nsgtk_about_dialog_init(GtkWindow *parent,
|
||||
gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_CENTER);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
|
||||
|
||||
label = gtk_label_new("NetSurf is a small fast web browser");
|
||||
label = gtk_label_new("NetSurf is a small fast web browser");
|
||||
gtk_label_set_selectable(GTK_LABEL (label), TRUE);
|
||||
gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_CENTER);
|
||||
gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
|
||||
@ -135,14 +129,14 @@ void nsgtk_about_dialog_init(GtkWindow *parent,
|
||||
gtk_box_pack_end(GTK_BOX(nsgtk_dialog_get_action_area(GTK_DIALOG(dialog))),
|
||||
button, FALSE, TRUE, 0);
|
||||
gtk_button_box_set_child_secondary (GTK_BUTTON_BOX(nsgtk_dialog_get_action_area(GTK_DIALOG(dialog))), button, TRUE);
|
||||
g_signal_connect(button, "clicked", G_CALLBACK(nsgtk_about_dialog_credits), (gpointer)bw);
|
||||
g_signal_connect(button, "clicked", G_CALLBACK(nsgtk_about_dialog_info), (gpointer)"about:credits");
|
||||
|
||||
/* Add the Licence button */
|
||||
button = gtk_button_new_from_stock ("Licence");
|
||||
gtk_box_pack_end(GTK_BOX (GTK_DIALOG(nsgtk_dialog_get_action_area(GTK_DIALOG(dialog)))),
|
||||
gtk_box_pack_end(GTK_BOX (nsgtk_dialog_get_action_area(GTK_DIALOG(dialog))),
|
||||
button, FALSE, TRUE, 0);
|
||||
gtk_button_box_set_child_secondary (GTK_BUTTON_BOX(nsgtk_dialog_get_action_area(GTK_DIALOG(dialog))), button, TRUE);
|
||||
g_signal_connect(button, "clicked", G_CALLBACK(nsgtk_about_dialog_licence), (gpointer)bw);
|
||||
g_signal_connect(button, "clicked", G_CALLBACK(nsgtk_about_dialog_info), (gpointer)"about:licence");
|
||||
|
||||
|
||||
/* Ensure that the dialog box is destroyed when the user responds. */
|
||||
|
@ -19,8 +19,6 @@
|
||||
#ifndef NETSURF_GTK_ABOUT_H
|
||||
#define NETSURF_GTK_ABOUT_H
|
||||
|
||||
#include "desktop/browser.h"
|
||||
|
||||
void nsgtk_about_dialog_init(GtkWindow *parent, struct browser_window *bw, const char *version);
|
||||
void nsgtk_about_dialog_init(GtkWindow *parent, const char *version);
|
||||
|
||||
#endif
|
||||
|
@ -76,7 +76,7 @@ MENUPROTO(source_zoom_out);
|
||||
MENUPROTO(source_zoom_normal);
|
||||
MENUPROTO(source_about);
|
||||
|
||||
struct menu_events source_menu_events[] = {
|
||||
static struct menu_events source_menu_events[] = {
|
||||
MENUEVENT(source_save_as),
|
||||
MENUEVENT(source_print),
|
||||
MENUEVENT(source_close),
|
||||
@ -309,8 +309,8 @@ nsgtk_source_tab_init(GtkWindow *parent, struct browser_window *bw)
|
||||
ret = netsurf_path_to_nsurl(filename, &url);
|
||||
g_free(filename);
|
||||
if (ret == NSERROR_OK) {
|
||||
ret = browser_window_create(BW_CREATE_TAB | BW_CREATE_CLONE,
|
||||
url, NULL, bw, NULL);
|
||||
ret = browser_window_create(BW_CREATE_TAB,
|
||||
url, NULL, NULL, NULL);
|
||||
nsurl_unref(url);
|
||||
}
|
||||
|
||||
@ -530,7 +530,7 @@ gboolean nsgtk_on_source_about_activate(GtkMenuItem *widget, gpointer g)
|
||||
{
|
||||
struct nsgtk_source_window *nsg = (struct nsgtk_source_window *) g;
|
||||
|
||||
nsgtk_about_dialog_init(nsg->sourcewindow, nsg->bw, netsurf_version);
|
||||
nsgtk_about_dialog_init(nsg->sourcewindow, netsurf_version);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -136,8 +136,8 @@ struct gtk_scaffolding {
|
||||
struct gtk_scaffolding *next, *prev;
|
||||
};
|
||||
|
||||
/** current window for model dialogue use */
|
||||
static struct gtk_scaffolding *current_model;
|
||||
/** current scaffold for model dialogue use */
|
||||
static struct gtk_scaffolding *scaf_current;
|
||||
|
||||
/** global list for interface changes */
|
||||
nsgtk_scaffolding *scaf_list = NULL;
|
||||
@ -497,7 +497,7 @@ static void nsgtk_openfile_open(const char *filename)
|
||||
nsurl *url;
|
||||
nserror error;
|
||||
|
||||
bw = nsgtk_get_browser_window(current_model->top_level);
|
||||
bw = nsgtk_get_browser_window(scaf_current->top_level);
|
||||
|
||||
urltxt = malloc(strlen(filename) + FILE_SCHEME_PREFIX_LEN + 1);
|
||||
|
||||
@ -596,9 +596,9 @@ MULTIHANDLER(newtab)
|
||||
|
||||
MULTIHANDLER(openfile)
|
||||
{
|
||||
current_model = g;
|
||||
scaf_current = g;
|
||||
GtkWidget *dlgOpen = gtk_file_chooser_dialog_new("Open File",
|
||||
current_model->window, GTK_FILE_CHOOSER_ACTION_OPEN,
|
||||
scaf_current->window, GTK_FILE_CHOOSER_ACTION_OPEN,
|
||||
GTK_STOCK_CANCEL, -6, GTK_STOCK_OPEN, -5, NULL);
|
||||
|
||||
gint response = gtk_dialog_run(GTK_DIALOG(dlgOpen));
|
||||
@ -1631,9 +1631,7 @@ MULTIHANDLER(info)
|
||||
|
||||
MULTIHANDLER(about)
|
||||
{
|
||||
nsgtk_about_dialog_init(g->window,
|
||||
nsgtk_get_browser_window(g->top_level),
|
||||
netsurf_version);
|
||||
nsgtk_about_dialog_init(g->window, netsurf_version);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -1837,6 +1835,16 @@ nsgtk_new_scaffolding_link_popup(struct gtk_scaffolding *g, GtkAccelGroup *group
|
||||
return nmenu;
|
||||
}
|
||||
|
||||
/* exported interface documented in gtk/scaffolding.h */
|
||||
nsgtk_scaffolding *nsgtk_current_scaffolding(void)
|
||||
{
|
||||
if (scaf_current == NULL) {
|
||||
scaf_current = scaf_list;
|
||||
}
|
||||
return scaf_current;
|
||||
}
|
||||
|
||||
/* exported interface documented in gtk/scaffolding.h */
|
||||
nsgtk_scaffolding *nsgtk_new_scaffolding(struct gui_window *toplevel)
|
||||
{
|
||||
struct gtk_scaffolding *g;
|
||||
|
@ -115,8 +115,18 @@ struct nsgtk_button_connect {
|
||||
|
||||
extern nsgtk_scaffolding *scaf_list;
|
||||
|
||||
/**
|
||||
* create a new scaffolding for a window.
|
||||
*/
|
||||
nsgtk_scaffolding *nsgtk_new_scaffolding(struct gui_window *toplevel);
|
||||
|
||||
/**
|
||||
* Obtain the most recently used scaffolding element.
|
||||
*
|
||||
* This allows tabs to be opened in the most recently used window
|
||||
*/
|
||||
nsgtk_scaffolding *nsgtk_current_scaffolding(void);
|
||||
|
||||
bool nsgtk_scaffolding_is_busy(nsgtk_scaffolding *g);
|
||||
|
||||
GtkWindow *nsgtk_scaffolding_window(nsgtk_scaffolding *g);
|
||||
|
24
gtk/window.c
24
gtk/window.c
@ -696,13 +696,26 @@ static void window_destroy(GtkWidget *widget, gpointer data)
|
||||
g_object_unref(gw->input_method);
|
||||
}
|
||||
|
||||
/* Core interface documented in desktop/gui.h to create a gui_window */
|
||||
|
||||
/**
|
||||
* Create and open a gtk container (window or tab) for a browsing context.
|
||||
*
|
||||
* \param bw The browsing context to create gui_window for.
|
||||
* \param existing An existing gui_window, may be NULL
|
||||
* \param flags flags to control the container creation
|
||||
* \return gui window, or NULL on error
|
||||
*
|
||||
* If GW_CREATE_CLONE flag is set existing is non-NULL.
|
||||
*
|
||||
* Front end's gui_window must include a reference to the
|
||||
* browser window passed in the bw param.
|
||||
*/
|
||||
static struct gui_window *
|
||||
gui_window_create(struct browser_window *bw,
|
||||
struct gui_window *existing,
|
||||
gui_window_create_flags flags)
|
||||
{
|
||||
struct gui_window *g; /**< what we're creating to return */
|
||||
struct gui_window *g; /* what is being creating to return */
|
||||
GError* error = NULL;
|
||||
bool tempback;
|
||||
GtkBuilder* xml;
|
||||
@ -732,8 +745,11 @@ gui_window_create(struct browser_window *bw,
|
||||
|
||||
/* attach scaffold */
|
||||
if (flags & GW_CREATE_TAB) {
|
||||
assert(existing != NULL);
|
||||
g->scaffold = existing->scaffold;
|
||||
if (existing != NULL) {
|
||||
g->scaffold = existing->scaffold;
|
||||
} else {
|
||||
g->scaffold = nsgtk_current_scaffolding();
|
||||
}
|
||||
} else {
|
||||
/* Now construct and attach a scaffold */
|
||||
g->scaffold = nsgtk_new_scaffolding(g);
|
||||
|
Loading…
Reference in New Issue
Block a user