[gnome-builder/wip/chergert/editorsearch] editor: add active property to IdeEditorSearch



commit 2797723a8beb2a601d9ac99e4e8f39f8f2844a0e
Author: Christian Hergert <chergert redhat com>
Date:   Wed Oct 11 03:06:21 2017 -0700

    editor: add active property to IdeEditorSearch
    
    This allows plugins to track when a search might be active. We
    can use this from the quick-highlight plugin to avoid performing
    extra work when it will just get in the way.

 src/libide/editor/ide-editor-search.c |   43 +++++++++++++++++++++++++++++++++
 src/libide/editor/ide-editor-search.h |    1 +
 2 files changed, 44 insertions(+), 0 deletions(-)
---
diff --git a/src/libide/editor/ide-editor-search.c b/src/libide/editor/ide-editor-search.c
index 27f2dd3..9afd6c2 100644
--- a/src/libide/editor/ide-editor-search.c
+++ b/src/libide/editor/ide-editor-search.c
@@ -68,6 +68,7 @@ struct _IdeEditorSearch
 
 enum {
   PROP_0,
+  PROP_ACTIVE,
   PROP_AT_WORD_BOUNDARIES,
   PROP_CASE_SENSITIVE,
   PROP_EXTEND_SELECTION,
@@ -187,6 +188,10 @@ ide_editor_search_get_property (GObject    *object,
 
   switch (prop_id)
     {
+    case PROP_ACTIVE:
+      g_value_set_boolean (value, ide_editor_search_get_active (self));
+      break;
+
     case PROP_CASE_SENSITIVE:
       g_value_set_boolean (value, ide_editor_search_get_case_sensitive (self));
       break;
@@ -305,6 +310,19 @@ ide_editor_search_class_init (IdeEditorSearchClass *klass)
   object_class->set_property = ide_editor_search_set_property;
 
   /**
+   * IdeEditorSearch:active:
+   *
+   * The "active" property is %TRUE when their is an active search
+   * in progress.
+   *
+   * Since: 3.28
+   */
+  properties [PROP_ACTIVE] =
+    g_param_spec_boolean ("active", NULL, NULL,
+                          FALSE,
+                          (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
+  /**
    * IdeEditorSearch:view:
    *
    * The "view" property is the underlying #GtkSourceView that
@@ -604,6 +622,8 @@ ide_editor_search_acquire_context (IdeEditorSearch *self)
 
       /* Update text tag stylign */
       ide_editor_search_notify_style_scheme (self, NULL, buffer);
+
+      g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_ACTIVE]);
     }
 
   return self->context;
@@ -621,6 +641,7 @@ ide_editor_search_release_context (IdeEditorSearch *self)
                                             G_CALLBACK (ide_editor_search_notify_occurrences_count),
                                             self);
       g_clear_object (&self->context);
+      g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_ACTIVE]);
     }
 }
 
@@ -1615,6 +1636,28 @@ ide_editor_search_set_repeat (IdeEditorSearch *self,
     }
 }
 
+/**
+ * ide_editor_search_get_active:
+ * @self: a #IdeEditorSearch
+ *
+ * Gets the "active" property.
+ *
+ * The #IdeEditorSearch is considered active if there is a search
+ * context loaded and the search text is not empty.
+ *
+ * Returns: %TRUE if a search is active
+ */
+gboolean
+ide_editor_search_get_active (IdeEditorSearch *self)
+{
+  g_return_val_if_fail (IDE_IS_EDITOR_SEARCH (self), FALSE);
+
+  if (self->context != NULL)
+    return !dzl_str_empty0 (ide_editor_search_get_search_text (self));
+
+  return FALSE;
+}
+
 static void
 ide_editor_search_actions_move_next (IdeEditorSearch *self,
                                      GVariant        *param)
diff --git a/src/libide/editor/ide-editor-search.h b/src/libide/editor/ide-editor-search.h
index 2840994..706b19c 100644
--- a/src/libide/editor/ide-editor-search.h
+++ b/src/libide/editor/ide-editor-search.h
@@ -57,6 +57,7 @@ G_DECLARE_FINAL_TYPE (IdeEditorSearch, ide_editor_search, IDE, EDITOR_SEARCH, GO
 GType                  ide_editor_search_direction_get_type           (void);
 GType                  ide_editor_search_select_get_type              (void);
 IdeEditorSearch       *ide_editor_search_new                          (GtkSourceView             *view);
+gboolean               ide_editor_search_get_active                   (IdeEditorSearch           *self);
 void                   ide_editor_search_set_case_sensitive           (IdeEditorSearch           *self,
                                                                        gboolean                   
case_sensitive);
 gboolean               ide_editor_search_get_case_sensitive           (IdeEditorSearch           *self);


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