[gnome-builder/wip/libide] libide: add IdeSourceView:search-context gproperty



commit c02261c74849665ea11b38fed03777dcc0e7c831
Author: Christian Hergert <christian hergert me>
Date:   Thu Mar 12 15:04:32 2015 -0700

    libide: add IdeSourceView:search-context gproperty
    
    This will allow us to share the default search context for a source view.
    Much better than the multiple search contexts we have today in the
    default vim mode (which we will remove soon in favor of this).

 libide/ide-source-view.c |   48 ++++++++++++++++++++++++++++++++++++++++++++++
 libide/ide-source-view.h |    1 +
 2 files changed, 49 insertions(+), 0 deletions(-)
---
diff --git a/libide/ide-source-view.c b/libide/ide-source-view.c
index 033965f..0e9cf20 100644
--- a/libide/ide-source-view.c
+++ b/libide/ide-source-view.c
@@ -97,6 +97,7 @@ typedef struct
   GQueue                      *selections;
   GQueue                      *snippets;
   GtkSourceCompletionProvider *snippets_provider;
+  GtkSourceSearchContext      *search_context;
 
   gulong                       buffer_changed_handler;
   gulong                       buffer_delete_range_after_handler;
@@ -149,6 +150,7 @@ enum {
   PROP_INSERT_MATCHING_BRACE,
   PROP_OVERWRITE_BRACES,
   PROP_SCROLL_OFFSET,
+  PROP_SEARCH_CONTEXT,
   PROP_SHOW_GRID_LINES,
   PROP_SHOW_LINE_CHANGES,
   PROP_SNIPPET_COMPLETION,
@@ -1046,6 +1048,7 @@ ide_source_view_connect_buffer (IdeSourceView *self,
                                 IdeBuffer     *buffer)
 {
   IdeSourceViewPrivate *priv = ide_source_view_get_instance_private (self);
+  GtkSourceSearchSettings *search_settings;
   GtkTextIter iter;
 
   g_assert (IDE_IS_SOURCE_VIEW (self));
@@ -1121,6 +1124,18 @@ ide_source_view_connect_buffer (IdeSourceView *self,
                                self,
                                0);
 
+  search_settings = g_object_new (GTK_SOURCE_TYPE_SEARCH_SETTINGS,
+                                  "wrap-around", TRUE,
+                                  "regex-enabled", FALSE,
+                                  "case-sensitive", TRUE,
+                                  NULL);
+  priv->search_context = g_object_new (GTK_SOURCE_TYPE_SEARCH_CONTEXT,
+                                       "buffer", buffer,
+                                       "highlight", TRUE,
+                                       "settings", search_settings,
+                                       NULL);
+  g_clear_object (&search_settings);
+
   gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (buffer), &iter);
   gtk_text_buffer_create_mark (GTK_TEXT_BUFFER (buffer), "scroll-mark", &iter, TRUE);
 
@@ -1151,6 +1166,8 @@ ide_source_view_disconnect_buffer (IdeSourceView *self,
   ide_clear_signal_handler (buffer, &priv->buffer_notify_highlight_diagnostics_handler);
   ide_clear_signal_handler (buffer, &priv->buffer_notify_language_handler);
 
+  g_clear_object (&priv->search_context);
+
   ide_source_view_set_indenter (self, NULL);
 }
 
@@ -3433,6 +3450,10 @@ ide_source_view_get_property (GObject    *object,
       g_value_set_uint (value, ide_source_view_get_scroll_offset (self));
       break;
 
+    case PROP_SEARCH_CONTEXT:
+      g_value_set_object (value, ide_source_view_get_search_context (self));
+      break;
+
     case PROP_SHOW_GRID_LINES:
       g_value_set_boolean (value, ide_source_view_get_show_grid_lines (self));
       break;
@@ -3619,6 +3640,15 @@ ide_source_view_class_init (IdeSourceViewClass *klass)
   g_object_class_install_property (object_class, PROP_SCROLL_OFFSET,
                                    gParamSpecs [PROP_SCROLL_OFFSET]);
 
+  gParamSpecs [PROP_SEARCH_CONTEXT] =
+    g_param_spec_object ("search-context",
+                         _("Search Context"),
+                         _("The search context for the view."),
+                         GTK_SOURCE_TYPE_SEARCH_CONTEXT,
+                         (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+  g_object_class_install_property (object_class, PROP_SEARCH_CONTEXT,
+                                   gParamSpecs [PROP_SEARCH_CONTEXT]);
+
   gParamSpecs [PROP_SHOW_GRID_LINES] =
     g_param_spec_boolean ("show-grid-lines",
                           _("Show Grid Lines"),
@@ -4766,3 +4796,21 @@ ide_source_view_set_enable_word_completion (IdeSourceView *self,
       g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_ENABLE_WORD_COMPLETION]);
     }
 }
+
+/**
+ * ide_source_view_get_search_context:
+ * @self: An #IdeSourceView.
+ *
+ * Returns the #GtkSourceSearchContext for the source view if there is one.
+ *
+ * Returns: (transfer none) (nullable): A #GtkSourceSearchContext or %NULL.
+ */
+GtkSourceSearchContext *
+ide_source_view_get_search_context (IdeSourceView *self)
+{
+  IdeSourceViewPrivate *priv = ide_source_view_get_instance_private (self);
+
+  g_return_val_if_fail (IDE_IS_SOURCE_VIEW (self), NULL);
+
+  return priv->search_context;
+}
diff --git a/libide/ide-source-view.h b/libide/ide-source-view.h
index 04f511c..cfd860f 100644
--- a/libide/ide-source-view.h
+++ b/libide/ide-source-view.h
@@ -268,6 +268,7 @@ const PangoFontDescription *ide_source_view_get_font_desc             (IdeSource
 gboolean                    ide_source_view_get_insert_matching_brace (IdeSourceView              *self);
 gboolean                    ide_source_view_get_overwrite_braces      (IdeSourceView              *self);
 guint                       ide_source_view_get_scroll_offset         (IdeSourceView              *self);
+GtkSourceSearchContext     *ide_source_view_get_search_context        (IdeSourceView              *self);
 gboolean                    ide_source_view_get_show_grid_lines       (IdeSourceView              *self);
 gboolean                    ide_source_view_get_show_line_changes     (IdeSourceView              *self);
 gboolean                    ide_source_view_get_snippet_completion    (IdeSourceView              *self);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]