summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJan-Michael Brummer <jan.brummer@tabos.org>2019-05-03 22:21:05 +0200
committerJan-Michael Brummer <jan.brummer@tabos.org>2019-05-13 22:01:29 +0200
commite962f8ec4273ab62d30be0045d40a48fd2e4b918 (patch)
tree43e532647ecb0e93d0a3547c68d99c30f43baf17 /src
parentcae625ba5e53b7f731eae899979cec64f4040b09 (diff)
downloadepiphany-e962f8ec4273ab62d30be0045d40a48fd2e4b918.tar.gz
Mark addresses currently open in browser
Fixes: https://gitlab.gnome.org/GNOME/epiphany/issues/153
Diffstat (limited to 'src')
-rw-r--r--src/ephy-location-controller.c17
-rw-r--r--src/ephy-suggestion-model.c77
2 files changed, 91 insertions, 3 deletions
diff --git a/src/ephy-location-controller.c b/src/ephy-location-controller.c
index c63a959ab..25284a803 100644
--- a/src/ephy-location-controller.c
+++ b/src/ephy-location-controller.c
@@ -146,6 +146,23 @@ entry_activate_cb (GtkEntry *entry,
if (content == NULL || content[0] == '\0')
return;
+ if (g_str_has_prefix (content, "ephy-tab://")) {
+ GtkWidget *notebook = ephy_window_get_notebook (controller->window);
+ GtkWidget *tab;
+ EphyWebView *webview;
+ gint current = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
+ guint64 page = g_ascii_strtoull (content + strlen ("ephy-tab://"), NULL, 0);
+
+ tab = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), current);
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), page);
+ webview = ephy_embed_get_web_view (EPHY_EMBED (tab));
+
+ if (ephy_web_view_is_overview (webview))
+ g_signal_emit_by_name (GTK_NOTEBOOK (notebook), "tab-close-request", tab);
+
+ return;
+ }
+
address = g_strdup (content);
effective_address = ephy_embed_utils_normalize_or_autosearch_address (g_strstrip (address));
g_free (address);
diff --git a/src/ephy-suggestion-model.c b/src/ephy-suggestion-model.c
index 799ba0fd5..3a59b505d 100644
--- a/src/ephy-suggestion-model.c
+++ b/src/ephy-suggestion-model.c
@@ -22,6 +22,7 @@
#include "ephy-embed-shell.h"
#include "ephy-search-engine-manager.h"
#include "ephy-suggestion.h"
+#include "ephy-window.h"
#include <dazzle.h>
#include <glib/gi18n.h>
@@ -192,7 +193,11 @@ should_add_bookmark_to_model (EphySuggestionModel *self,
const char *title,
const char *location)
{
- return strstr (title, search_string) || strstr (location, search_string);
+ g_autofree gchar *search_casefold = g_utf8_casefold (search_string, -1);
+ g_autofree gchar *title_casefold = g_utf8_casefold (title, -1);
+ g_autofree gchar *location_casefold = g_utf8_casefold (location, -1);
+
+ return strstr (title_casefold, search_casefold) || strstr (location_casefold, search_casefold);
}
static void
@@ -347,6 +352,67 @@ add_search_engines (EphySuggestionModel *self,
return added;
}
+static guint
+add_tabs (EphySuggestionModel *self,
+ const char *query)
+{
+ GApplication *application;
+ EphyEmbedShell *shell;
+ EphyWindow *window ;
+ GtkWidget *notebook;
+ gint n_pages;
+ gint current;
+ guint added = 0;
+
+ shell = ephy_embed_shell_get_default ();
+ application = G_APPLICATION (shell);
+ window = EPHY_WINDOW (gtk_application_get_active_window (GTK_APPLICATION (application)));
+
+ notebook = ephy_window_get_notebook (window);
+ n_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook));
+ current = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
+
+ for (int i = 0; i < n_pages; i++) {
+ EphyEmbed *embed;
+ EphyWebView *webview;
+ EphySuggestion *suggestion;
+ g_autofree gchar *escaped_title = NULL;
+ g_autofree gchar *markup = NULL;
+ const gchar *display_address;
+ g_autofree gchar *address = NULL;
+ const gchar *title;
+ g_autofree gchar *title_casefold = NULL;
+ g_autofree gchar *display_address_casefold = NULL;
+ g_autofree gchar *query_casefold = NULL;
+
+ if (i == current)
+ continue;
+
+ embed = EPHY_EMBED (gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), i));
+ webview = ephy_embed_get_web_view (embed);
+ display_address = ephy_web_view_get_display_address (webview);
+ address = g_strdup_printf ("ephy-tab://%d", i);
+ title = webkit_web_view_get_title (WEBKIT_WEB_VIEW (webview));
+
+ display_address_casefold = g_utf8_casefold (display_address, -1);
+ query_casefold = g_utf8_casefold (query, -1);
+ if (title)
+ title_casefold = g_utf8_casefold (title, -1);
+
+ if ((title_casefold && strstr (title_casefold, query_casefold)) || strstr (display_address_casefold, query_casefold)) {
+ escaped_title = g_markup_escape_text (title, -1);
+ markup = dzl_fuzzy_highlight (escaped_title, query, FALSE);
+ suggestion = ephy_suggestion_new_with_custom_subtitle (markup, title, _("Switch to Tab"), address);
+ load_favicon (self, suggestion, display_address);
+
+ g_sequence_append (self->items, suggestion);
+ added++;
+ }
+ }
+
+ return added;
+}
+
static void
query_completed_cb (EphyHistoryService *service,
gboolean success,
@@ -375,7 +441,8 @@ query_completed_cb (EphyHistoryService *service,
self->items = g_sequence_new (g_object_unref);
if (strlen (query) > 0) {
- added = add_bookmarks (self, query);
+ added = add_tabs (self, query);
+ added += add_bookmarks (self, query);
added += add_history (self, urls, query);
added += add_search_engines (self, query);
}
@@ -438,6 +505,7 @@ ephy_suggestion_model_get_suggestion_with_uri (EphySuggestionModel *self,
const char *uri)
{
GSequenceIter *iter;
+ g_autofree gchar *uri_casefold = g_utf8_casefold (uri, -1);
g_assert (EPHY_IS_SUGGESTION_MODEL (self));
g_assert (uri != NULL && *uri != '\0');
@@ -445,9 +513,12 @@ ephy_suggestion_model_get_suggestion_with_uri (EphySuggestionModel *self,
for (iter = g_sequence_get_begin_iter (self->items);
!g_sequence_iter_is_end (iter); iter = g_sequence_iter_next (iter)) {
EphySuggestion *suggestion;
+ g_autofree gchar *suggestion_casefold = NULL;
suggestion = g_sequence_get (iter);
- if (strcmp (ephy_suggestion_get_uri (suggestion), uri) == 0)
+ suggestion_casefold = g_utf8_casefold (ephy_suggestion_get_uri (suggestion), -1);
+
+ if (strcmp (suggestion_casefold, uri_casefold) == 0)
return suggestion;
}