[gnome-builder] editor: fix the search system
- From: Sébastien Lafargue <slafargue src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] editor: fix the search system
- Date: Fri, 29 Sep 2017 21:09:01 +0000 (UTC)
commit a9c5ca1e133b89471ff8f82fb0fea06f90248e2c
Author: Sebastien Lafargue <slafargue gnome org>
Date: Fri Sep 29 19:16:12 2017 +0200
editor: fix the search system
src/libide/editor/ide-editor-private.h | 4 ++
src/libide/editor/ide-editor-search-bar.c | 38 ++++++++++++++++++++
src/libide/editor/ide-editor-view.c | 5 +++
src/libide/sourceview/ide-source-view.c | 16 ++++++++
src/libide/sourceview/ide-source-view.h | 2 +
.../gbp-quick-highlight-view-addin.c | 2 +
6 files changed, 67 insertions(+), 0 deletions(-)
---
diff --git a/src/libide/editor/ide-editor-private.h b/src/libide/editor/ide-editor-private.h
index 5ae5429..844376a 100644
--- a/src/libide/editor/ide-editor-private.h
+++ b/src/libide/editor/ide-editor-private.h
@@ -110,6 +110,10 @@ struct _IdeEditorSearchBar
GtkGrid *search_options;
GtkCheckButton *use_regex;
GtkCheckButton *whole_word;
+
+ GSettings *quick_highlight_settings;
+
+ guint quick_highlight_enabled : 1;
};
void _ide_editor_view_init_actions (IdeEditorView *self);
diff --git a/src/libide/editor/ide-editor-search-bar.c b/src/libide/editor/ide-editor-search-bar.c
index 6a0d056..bea0724 100644
--- a/src/libide/editor/ide-editor-search-bar.c
+++ b/src/libide/editor/ide-editor-search-bar.c
@@ -165,9 +165,34 @@ on_notify_search_text (IdeEditorSearchBar *self,
GParamSpec *pspec,
GtkSourceSearchSettings *search_settings)
{
+ GtkWidget *widget;
+ IdeEditorView *editor_view;
+ IdeSourceView *view;
+ GtkSourceSearchContext *view_search_context;
+ GtkSourceSearchSettings *view_search_settings;
+ const gchar *search_text;
+
g_assert (IDE_IS_EDITOR_SEARCH_BAR (self));
g_assert (GTK_SOURCE_IS_SEARCH_SETTINGS (search_settings));
+ /* We set the view context search text for keymodes searching */
+ if (self->context == NULL)
+ {
+ if (NULL != (widget = gtk_widget_get_ancestor (GTK_WIDGET (self), IDE_TYPE_EDITOR_VIEW)))
+ {
+ editor_view = IDE_EDITOR_VIEW (widget);
+ view = ide_editor_view_get_view (editor_view);
+
+ search_text = gtk_source_search_settings_get_search_text (search_settings);
+
+ if (NULL != (view_search_context = ide_source_view_get_search_context (view)))
+ {
+ view_search_settings = gtk_source_search_context_get_settings (view_search_context);
+ gtk_source_search_settings_set_search_text (view_search_settings, search_text);
+ }
+ }
+ }
+
update_replace_actions_sensitivity (self);
}
@@ -387,6 +412,10 @@ ide_editor_search_bar_bind_context (IdeEditorSearchBar *self,
g_assert (GTK_SOURCE_IS_SEARCH_CONTEXT (context));
g_assert (DZL_IS_SIGNAL_GROUP (context_signals));
+ self->quick_highlight_enabled = g_settings_get_boolean (self->quick_highlight_settings, "enabled");
+ if (self->quick_highlight_enabled)
+ g_settings_set_boolean (self->quick_highlight_settings, "enabled", FALSE);
+
buffer = gtk_source_search_context_get_buffer (context);
dzl_signal_group_set_target (self->buffer_signals, buffer);
}
@@ -398,6 +427,9 @@ ide_editor_search_bar_unbind_context (IdeEditorSearchBar *self,
g_assert (IDE_IS_EDITOR_SEARCH_BAR (self));
g_assert (DZL_IS_SIGNAL_GROUP (context_signals));
+ if (self->quick_highlight_enabled)
+ g_settings_set_boolean (self->quick_highlight_settings, "enabled", TRUE);
+
if (self->buffer_signals != NULL)
dzl_signal_group_set_target (self->buffer_signals, NULL);
}
@@ -503,6 +535,7 @@ ide_editor_search_bar_destroy (GtkWidget *widget)
g_clear_object (&self->search_entry_tag);
g_clear_object (&self->settings);
g_clear_object (&self->settings_signals);
+ g_clear_object (&self->quick_highlight_settings);
GTK_WIDGET_CLASS (ide_editor_search_bar_parent_class)->destroy (widget);
}
@@ -683,6 +716,10 @@ ide_editor_search_bar_init (IdeEditorSearchBar *self)
G_CALLBACK (search_entry_next_match),
self);
+ self->quick_highlight_settings =
+ g_settings_new_with_path ("org.gnome.builder.extension-type",
+
"/org/gnome/builder/extension-types/quick-highlight-plugin/GbpQuickHighlightViewAddin/");
+
_ide_editor_search_bar_init_actions (self);
_ide_editor_search_bar_init_shortcuts (self);
}
@@ -714,6 +751,7 @@ ide_editor_search_bar_set_context (IdeEditorSearchBar *self,
g_return_if_fail (IDE_IS_EDITOR_SEARCH_BAR (self));
g_return_if_fail (!context || GTK_SOURCE_IS_SEARCH_CONTEXT (context));
+
if (g_set_object (&self->context, context))
{
dzl_signal_group_set_target (self->context_signals, context);
diff --git a/src/libide/editor/ide-editor-view.c b/src/libide/editor/ide-editor-view.c
index dbfe7cf..57ed0a6 100644
--- a/src/libide/editor/ide-editor-view.c
+++ b/src/libide/editor/ide-editor-view.c
@@ -534,6 +534,7 @@ search_revealer_notify_reveal_child (IdeEditorView *self,
GtkRevealer *revealer)
{
GtkSourceCompletion *completion;
+ GtkSourceSearchContext *view_search_context;
g_return_if_fail (IDE_IS_EDITOR_VIEW (self));
g_return_if_fail (pspec != NULL);
@@ -579,6 +580,10 @@ search_revealer_notify_reveal_child (IdeEditorView *self,
gtk_source_search_context_set_highlight (self->search_context, TRUE);
ide_editor_search_bar_set_context (self->search_bar, self->search_context);
+ /* We need to hide the search highlight on the view context */
+ if (NULL != (view_search_context = ide_source_view_get_search_context (self->source_view)))
+ gtk_source_search_context_set_highlight (view_search_context, FALSE);
+
/*
* Block the completion while the search bar is set. It only
* slows things down like search/replace functionality. We'll
diff --git a/src/libide/sourceview/ide-source-view.c b/src/libide/sourceview/ide-source-view.c
index 083ba64..0579c41 100644
--- a/src/libide/sourceview/ide-source-view.c
+++ b/src/libide/sourceview/ide-source-view.c
@@ -3913,6 +3913,7 @@ ide_source_view_real_move_search (IdeSourceView *self,
{
if (priv->saved_search_text == NULL)
return;
+
gtk_source_search_settings_set_search_text (settings, priv->saved_search_text);
}
@@ -8864,6 +8865,21 @@ ide_source_view_clear_search (IdeSourceView *self)
gtk_source_search_settings_set_search_text (search_settings, "");
}
+void
+ide_source_view_save_search (IdeSourceView *self,
+ const gchar *search_text)
+{
+ IdeSourceViewPrivate *priv = ide_source_view_get_instance_private (self);
+
+ g_return_if_fail (IDE_IS_SOURCE_VIEW (self));
+
+ if (0 != g_strcmp0 (priv->saved_search_text, search_text))
+ {
+ g_free (priv->saved_search_text);
+ priv->saved_search_text = (search_text != NULL) ? g_strdup (search_text) : NULL;
+ }
+}
+
gint
ide_source_view_get_count (IdeSourceView *self)
{
diff --git a/src/libide/sourceview/ide-source-view.h b/src/libide/sourceview/ide-source-view.h
index 717931e..009d309 100644
--- a/src/libide/sourceview/ide-source-view.h
+++ b/src/libide/sourceview/ide-source-view.h
@@ -383,6 +383,8 @@ void ide_source_view_push_snippet (IdeSource
IdeSourceSnippet *snippet,
const GtkTextIter *location);
void ide_source_view_rollback_search (IdeSourceView *self);
+void ide_source_view_save_search (IdeSourceView *self,
+ const gchar
*search_text);
void ide_source_view_set_count (IdeSourceView *self,
gint count);
void ide_source_view_set_enable_word_completion(IdeSourceView *self,
diff --git a/src/plugins/quick-highlight/gbp-quick-highlight-view-addin.c
b/src/plugins/quick-highlight/gbp-quick-highlight-view-addin.c
index bf987b5..3f062c4 100644
--- a/src/plugins/quick-highlight/gbp-quick-highlight-view-addin.c
+++ b/src/plugins/quick-highlight/gbp-quick-highlight-view-addin.c
@@ -211,7 +211,9 @@ gbp_quick_highlight_view_addin_enabled_changed (GbpQuickHighlightViewAddin *self
{
g_signal_handler_block (buffer, self->notify_style_scheme_handler);
g_signal_handler_block (buffer, self->mark_set_handler);
+
gtk_source_search_settings_set_search_text (self->search_settings, NULL);
+
gtk_source_search_context_set_highlight (self->search_context, FALSE);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]