Skip to content

Instantly share code, notes, and snippets.

@tualatrix
Created January 31, 2012 08:16
Show Gist options
  • Save tualatrix/1709438 to your computer and use it in GitHub Desktop.
Save tualatrix/1709438 to your computer and use it in GitHub Desktop.
Add Google Search support for GNOME Terminal
diff --git a/src/terminal-util.c b/src/terminal-util.c
index e36cba9..8e1c64f 100644
--- a/src/terminal-util.c
+++ b/src/terminal-util.c
@@ -125,7 +125,7 @@ terminal_util_show_error_dialog (GtkWindow *transient_parent,
g_free (message);
}
-static gboolean
+gboolean
open_url (GtkWindow *parent,
const char *uri,
guint32 user_time,
diff --git a/src/terminal-util.h b/src/terminal-util.h
index a8648af..44a15a5 100644
--- a/src/terminal-util.h
+++ b/src/terminal-util.h
@@ -46,6 +46,11 @@ void terminal_util_set_atk_name_description (GtkWidget *widget,
const char *name,
const char *desc);
+gboolean open_url (GtkWindow *parent,
+ const char *uri,
+ guint32 user_time,
+ GError **error);
+
void terminal_util_open_url (GtkWidget *parent,
const char *orig_url,
TerminalURLFlavour flavor,
diff --git a/src/terminal-window.c b/src/terminal-window.c
index 65e7189..165d616 100644
--- a/src/terminal-window.c
+++ b/src/terminal-window.c
@@ -1233,6 +1233,20 @@ popup_copy_url_callback (GtkAction *action,
}
static void
+search_on_google_callback (GtkAction *action,
+ TerminalWindow *window)
+{
+ gchar *url;
+ GtkClipboard *clipboard;
+
+ clipboard = gtk_widget_get_clipboard (GTK_WIDGET (window), GDK_SELECTION_PRIMARY);
+ url = g_strdup_printf ("http://www.google.com/search?ie=UTF-8&q=%s", gtk_clipboard_wait_for_text(clipboard));
+ open_url (GTK_WINDOW (window), url, gtk_get_current_event_time (), NULL);
+
+ g_free(url);
+}
+
+static void
popup_leave_fullscreen_callback (GtkAction *action,
TerminalWindow *window)
{
@@ -1345,6 +1359,8 @@ popup_clipboard_targets_received_cb (GtkClipboard *clipboard,
gtk_action_set_visible (action, show_link);
action = gtk_action_group_get_action (priv->action_group, "PopupCopyLinkAddress");
gtk_action_set_visible (action, show_link);
+ action = gtk_action_group_get_action (priv->action_group, "PopupSearchOnGoogle");
+ gtk_action_set_visible (action, vte_terminal_get_has_selection (VTE_TERMINAL (screen)));
action = gtk_action_group_get_action (priv->action_group, "PopupCloseWindow");
gtk_action_set_visible (action, n_pages <= 1);
@@ -1944,6 +1960,9 @@ terminal_window_init (TerminalWindow *window)
{ "PopupCopyLinkAddress", NULL, N_("_Copy Link Address"), NULL,
NULL,
G_CALLBACK (popup_copy_url_callback) },
+ { "PopupSearchOnGoogle", NULL, N_("_Search On Google"), NULL,
+ NULL,
+ G_CALLBACK (search_on_google_callback) },
{ "PopupTerminalProfiles", NULL, N_("P_rofiles") },
{ "PopupCopy", GTK_STOCK_COPY, NULL, "",
NULL,
diff --git a/src/terminal.xml b/src/terminal.xml
index 91329d3..21a08ac 100644
--- a/src/terminal.xml
+++ b/src/terminal.xml
@@ -85,6 +85,7 @@
<menuitem action="PopupCopyCallAddress" />
<menuitem action="PopupOpenLink" />
<menuitem action="PopupCopyLinkAddress" />
+ <menuitem action="PopupSearchOnGoogle" />
<separator />
<menuitem action="PopupNewTerminal" />
<menuitem action="PopupNewTab" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment