[Xfce4-commits] <midori:master> Retain selection in urlbar when switching tabs
Christian Dywan
noreply at xfce.org
Wed Sep 26 01:36:01 CEST 2012
Updating branch refs/heads/master
to 935b5c381d3afa2ce41676f7f83f6392f39c75e4 (commit)
from c99d48c65e6271846590c925419487b173bcff18 (commit)
commit 935b5c381d3afa2ce41676f7f83f6392f39c75e4
Author: Christian Dywan <christian at twotoasts.de>
Date: Wed Sep 26 01:30:54 2012 +0200
Retain selection in urlbar when switching tabs
midori/midori-locationaction.c | 47 ++++++++++++++++++++++++++++------------
1 files changed, 33 insertions(+), 14 deletions(-)
diff --git a/midori/midori-locationaction.c b/midori/midori-locationaction.c
index c6aeca8..49f3295 100644
--- a/midori/midori-locationaction.c
+++ b/midori/midori-locationaction.c
@@ -33,7 +33,6 @@ struct _MidoriLocationAction
GtkAction parent_instance;
gchar* text;
- gchar* uri;
KatzeArray* search_engines;
gdouble progress;
gchar* secondary_icon;
@@ -369,6 +368,32 @@ midori_location_action_popup_position (MidoriLocationAction* action,
gtk_window_move (GTK_WINDOW (popup), wx, wy);
}
+static void
+midori_location_action_entry_set_text (GtkWidget* entry,
+ const gchar* text)
+{
+ /* Retain selection/ primary clipboard when replacing text ie. switching tabs */
+ gchar* selection = NULL;
+ GtkClipboard* clipboard;
+
+ if (gtk_widget_get_realized (entry))
+ {
+ clipboard = gtk_widget_get_clipboard (entry, GDK_SELECTION_PRIMARY);
+ int start, end;
+ if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry)
+ && gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
+ selection = gtk_editable_get_chars (GTK_EDITABLE (entry), start, end);
+ }
+
+ gtk_entry_set_text (GTK_ENTRY (entry), text);
+
+ if (selection != NULL)
+ {
+ gtk_clipboard_set_text (clipboard, selection, strlen (selection));
+ g_free (selection);
+ }
+}
+
static int
midori_location_action_add_search_engines (MidoriLocationAction* action,
GtkListStore* store,
@@ -443,7 +468,7 @@ midori_location_action_complete (MidoriLocationAction* action,
else
{
midori_location_action_popdown_completion (action);
- gtk_entry_set_text (GTK_ENTRY (action->entry), uri);
+ midori_location_action_entry_set_text (action->entry, uri);
g_signal_emit (action, signals[SUBMIT_URI], 0, uri, new_tab);
}
}
@@ -712,7 +737,7 @@ midori_location_action_entry_for_proxy (GtkWidget* proxy)
static void
midori_location_action_init (MidoriLocationAction* location_action)
{
- location_action->text = location_action->uri = NULL;
+ location_action->text = NULL;
location_action->search_engines = NULL;
location_action->progress = 0.0;
location_action->secondary_icon = NULL;
@@ -731,7 +756,6 @@ midori_location_action_finalize (GObject* object)
MidoriLocationAction* location_action = MIDORI_LOCATION_ACTION (object);
katze_assign (location_action->text, NULL);
- katze_assign (location_action->uri, NULL);
katze_assign (location_action->search_engines, NULL);
katze_assign (location_action->key, NULL);
@@ -965,7 +989,7 @@ midori_location_action_key_press_event_cb (GtkEntry* entry,
else
{
midori_location_action_popdown_completion (location_action);
- gtk_entry_set_text (entry, uri);
+ midori_location_action_entry_set_text (GTK_WIDGET (entry), uri);
}
g_free (uri);
@@ -1722,16 +1746,16 @@ midori_location_action_disconnect_proxy (GtkAction* action,
* midori_location_action_get_uri:
* @location_action: a #MidoriLocationAction
*
- * Retrieves the current URI. See also midori_location_action_get_text().
- *
* Return value: the current URI
+ *
+ * Deprecated: 0.4.8: Use @midori_location_action_get_text.
**/
const gchar*
midori_location_action_get_uri (MidoriLocationAction* location_action)
{
g_return_val_if_fail (MIDORI_IS_LOCATION_ACTION (location_action), NULL);
- return location_action->uri;
+ return location_action->text;
}
/**
@@ -1774,7 +1798,6 @@ midori_location_action_set_text (MidoriLocationAction* location_action,
midori_location_action_popdown_completion (location_action);
katze_assign (location_action->text, g_strdup (text));
- katze_assign (location_action->uri, g_strdup (text));
if (!(proxies = gtk_action_get_proxies (GTK_ACTION (location_action))))
return;
@@ -1783,7 +1806,7 @@ midori_location_action_set_text (MidoriLocationAction* location_action,
if (GTK_IS_TOOL_ITEM (proxies->data))
{
GtkWidget* entry = midori_location_action_entry_for_proxy (proxies->data);
- gtk_entry_set_text (GTK_ENTRY (entry), text);
+ midori_location_action_entry_set_text (entry, text);
}
}
@@ -1806,10 +1829,6 @@ void
midori_location_action_add_uri (MidoriLocationAction* location_action,
const gchar* uri)
{
- g_return_if_fail (MIDORI_IS_LOCATION_ACTION (location_action));
- g_return_if_fail (uri != NULL);
-
- katze_assign (location_action->uri, g_strdup (uri));
}
/**
More information about the Xfce4-commits
mailing list