Add Open Link in New Tab and Open URL in New Tab.

Enhance the context menu to allow opening of links in a
new tab as well as any selected text that looks like an URL.
This commit is contained in:
Christian Dywan 2008-03-13 01:21:59 +01:00
parent 4a1e0ab67b
commit 02d7848c5d
2 changed files with 61 additions and 33 deletions

View file

@ -15,7 +15,7 @@
#include "conf.h"
#include "midori-websettings.h"
#include "../katze/katze.h"
#include <katze/katze.h>
#include <gtk/gtk.h>
#include <webkit/webkit.h>
@ -34,39 +34,31 @@ MidoriWebSettings* webSettings;
/* NOTE: Those uncommented were replaced with remotely related icons
in order to reduce the amount of warnings :D */
#define STOCK_BOOKMARK GTK_STOCK_FILE // "stock_bookmark" // "bookmark-web"
#define STOCK_FORM_FILL "insert-text" // "form-fill" // MISSING
#define STOCK_LOCATION "location-entry"
#define STOCK_NEWSFEED "gtk-index" // "newsfeed" // MISSING
#define STOCK_PLUGINS "plugin" // MISSING
#define STOCK_BOOKMARK GTK_STOCK_FILE // "stock_bookmark" "bookmark-web"
#define STOCK_FORM_FILL GTK_STOCK_JUSTIFY_FILL // "insert-text" "form-fill"
#define STOCK_LOCATION GTK_STOCK_BOLD // "location-entry"
#define STOCK_NEWSFEED "gtk-index" // "newsfeed"
#define STOCK_PLUGINS GTK_STOCK_CONVERT // "plugin"
#define STOCK_POPUPS_BLOCKED "popup-hidden"
#define STOCK_SOURCE_VIEW "stock_view-html-source" // MISSING
#define STOCK_TAB_CLOSE "tab-close" // MISSING
#define STOCK_WINDOW_CLOSE "window-close" // MISSING
#define STOCK_SOURCE_VIEW "stock_view-html-source" // "view-source"
#define STOCK_TAB_CLOSE GTK_STOCK_CLOSE // "tab-close"
#define STOCK_WINDOW_CLOSE GTK_STOCK_CLOSE // "window-close"
// We can safely use standard icons
// Assuming that we have reliable fallback icons
// We assume that these legacy icon names are usually present
#define STOCK_BOOKMARK_NEW "bookmark-new"
#define STOCK_BOOKMARK_NEW_ "stock_add-bookmark"
#define STOCK_BOOKMARK_NEW "stock_add-bookmark"
#define STOCK_HOMEPAGE GTK_STOCK_HOME
#define STOCK_IMAGE "image-x-generic"
#define STOCK_IMAGE_ "gnome-mime-image"
#define STOCK_IMAGE "gnome-mime-image"
#define STOCK_LOCK_OPEN "stock_lock-open"
#define STOCK_LOCK_SECURE "stock_lock"
#define STOCK_LOCK_BROKEN "stock_lock-broken"
#define STOCK_NETWORK_OFFLINE "connect_no"
#define STOCK_NETWORK_OFFLINE_ "network-offline"
#define STOCK_NETWORK_OFFLINE "network-offline"
#define STOCK_SCRIPT "stock_script"
#define STOCK_SEND "mail-send"
#define STOCK_SEND_ "stock_mail-send"
#define STOCK_TAB_NEW "tab-new"
#define STOCK_TAB_NEW_ "stock_new-tab"
#define STOCK_SEND "stock_mail-send"
#define STOCK_TAB_NEW "stock_new-tab"
#define STOCK_THEME "gnome-settings-theme"
#define STOCK_USER_TRASH "user-trash"
#define STOCK_USER_TRASH_ "gnome-stock-trash"
#define STOCK_WINDOW_NEW "window-new"
#define STOCK_WINDOW_NEW_ "stock_new-window"
#define STOCK_USER_TRASH "gnome-stock-trash"
#define STOCK_WINDOW_NEW "stock_new-window"
// For backwards compatibility

View file

@ -11,11 +11,16 @@
#include "midori-webview.h"
#include "global.h"
#include "sokoke.h"
#include <webkit/webkitwebframe.h>
#include <string.h>
// This is unstable API, so we need to declare it
gchar*
webkit_web_view_get_selected_text (WebKitWebView* web_view);
G_DEFINE_TYPE (MidoriWebView, midori_web_view, WEBKIT_TYPE_WEB_VIEW)
struct _MidoriWebViewPrivate
@ -448,12 +453,14 @@ gtk_widget_scroll_event (MidoriWebView* web_view,
return FALSE;
}
/*static void
midori_web_view_menu_new_tab_activate (GtkWidget* widget,
static void
midori_web_view_menu_new_tab_activate_cb (GtkWidget* widget,
MidoriWebView* web_view)
{
// FIXME: Open a new tab and load the uri
}*/
const gchar* uri = g_object_get_data (G_OBJECT (widget), "uri");
g_print ("selected: %s\n", uri);
g_signal_emit (web_view, signals[NEW_TAB], 0, uri);
}
static void
webkit_web_view_populate_popup_cb (GtkWidget* web_view,
@ -462,12 +469,41 @@ webkit_web_view_populate_popup_cb (GtkWidget* web_view,
const gchar* uri = midori_web_view_get_link_uri (MIDORI_WEB_VIEW (web_view));
if (uri)
{
// new tab
GtkWidget* menuitem = gtk_image_menu_item_new_with_mnemonic (
"Open Link in New _Tab");
GdkScreen* screen = gtk_widget_get_screen (web_view);
GtkIconTheme* icon_theme = gtk_icon_theme_get_for_screen (screen);
if (gtk_icon_theme_has_icon (icon_theme, STOCK_TAB_NEW))
{
GtkWidget* icon = gtk_image_new_from_stock (STOCK_TAB_NEW,
GTK_ICON_SIZE_MENU);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), icon);
}
gtk_menu_shell_insert (GTK_MENU_SHELL (menu), menuitem, 1);
g_object_set_data (G_OBJECT (menuitem), "uri", (gchar*)uri);
g_signal_connect (menuitem, "activate",
G_CALLBACK (midori_web_view_menu_new_tab_activate_cb), web_view);
gtk_widget_show (menuitem);
}
if (webkit_web_view_has_selection (WEBKIT_WEB_VIEW (web_view)))
if (!uri && webkit_web_view_has_selection (WEBKIT_WEB_VIEW (web_view)))
{
// selected uri in tab
gchar* text = webkit_web_view_get_selected_text (
WEBKIT_WEB_VIEW (web_view));
if (text && strchr (text, '.') && !strchr (text, ' '))
{
GtkWidget* menuitem = gtk_image_menu_item_new_with_mnemonic (
"Open URL in New _Tab");
GtkWidget* icon = gtk_image_new_from_stock (GTK_STOCK_JUMP_TO,
GTK_ICON_SIZE_MENU);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), icon);
gtk_menu_shell_insert (GTK_MENU_SHELL (menu), menuitem, -1);
g_object_set_data (G_OBJECT (menuitem), "uri", text);
g_signal_connect (menuitem, "activate",
G_CALLBACK (midori_web_view_menu_new_tab_activate_cb), web_view);
gtk_widget_show (menuitem);
}
// FIXME: We are leaking 'text' which is not const be should be.
}
}