[gtksourceview/wip/chergert/gsv-gtk4: 225/259] completion: implement GtkSourceCompletion:remember-info-visibility




commit 808460a0cbff73e421167558b9fb6c0793d4c659
Author: Christian Hergert <chergert redhat com>
Date:   Tue Sep 8 14:09:40 2020 -0700

    completion: implement GtkSourceCompletion:remember-info-visibility
    
    This exited in the previous completion implementation, and is fairly easy
    to support in the new implementation too.

 gtksourceview/gtksourcecompletion.c             | 33 +++++++++++++++++++++++++
 gtksourceview/gtksourcecompletionlist-private.h | 32 +++++++++++++-----------
 gtksourceview/gtksourcecompletionlist.c         | 27 ++++++++++++++++++++
 tests/test-completion.c                         |  4 +++
 4 files changed, 81 insertions(+), 15 deletions(-)
---
diff --git a/gtksourceview/gtksourcecompletion.c b/gtksourceview/gtksourcecompletion.c
index 629bc9ca..8b5eaf7e 100644
--- a/gtksourceview/gtksourcecompletion.c
+++ b/gtksourceview/gtksourcecompletion.c
@@ -119,6 +119,9 @@ struct _GtkSourceCompletion
        /* If the first item is automatically selected */
        guint select_on_show : 1;
 
+       /* If we remember to re-show the info window */
+       guint remember_info_visibility : 1;
+
        /* If icon column is visible */
        guint show_icons : 1;
 
@@ -131,6 +134,7 @@ enum {
        PROP_0,
        PROP_BUFFER,
        PROP_PAGE_SIZE,
+       PROP_REMEMBER_INFO_VISIBILITY,
        PROP_SELECT_ON_SHOW,
        PROP_SHOW_ICONS,
        PROP_VIEW,
@@ -869,6 +873,10 @@ gtk_source_completion_get_property (GObject    *object,
 
        switch (prop_id)
        {
+       case PROP_REMEMBER_INFO_VISIBILITY:
+               g_value_set_boolean (value, self->remember_info_visibility);
+               break;
+
        case PROP_SELECT_ON_SHOW:
                g_value_set_boolean (value, _gtk_source_completion_get_select_on_show (self));
                break;
@@ -896,6 +904,16 @@ gtk_source_completion_set_property (GObject      *object,
 
        switch (prop_id)
        {
+       case PROP_REMEMBER_INFO_VISIBILITY:
+               self->remember_info_visibility = g_value_get_boolean (value);
+               if (self->display != NULL)
+               {
+                       _gtk_source_completion_list_set_remember_info_visibility (self->display,
+                                                                                 
self->remember_info_visibility);
+               }
+               g_object_notify_by_pspec (object, pspec);
+               break;
+
        case PROP_SELECT_ON_SHOW:
                gtk_source_completion_set_select_on_show (self, g_value_get_boolean (value));
                break;
@@ -957,6 +975,19 @@ gtk_source_completion_class_init (GtkSourceCompletionClass *klass)
                                   1, 32, DEFAULT_PAGE_SIZE,
                                   G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
 
+       /**
+        * GtkSourceCompletion:remember-info-visibility:
+        *
+        * Determines whether the visibility of the info window should be saved when the
+        * completion is hidden, and restored when the completion is shown again.
+        */
+       properties [PROP_REMEMBER_INFO_VISIBILITY] =
+               g_param_spec_boolean ("remember-info-visibility",
+                                     "Remember Info Visibility",
+                                     "Remember Info Visibility",
+                                     FALSE,
+                                     (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
        /**
         * GtkSourceCompletion:select-on-show:
         *
@@ -1359,6 +1390,8 @@ _gtk_source_completion_get_display (GtkSourceCompletion *self)
                _gtk_source_completion_list_set_n_rows (self->display, self->page_size);
                _gtk_source_completion_list_set_font_desc (self->display, self->font_desc);
                _gtk_source_completion_list_set_show_icons (self->display, self->show_icons);
+               _gtk_source_completion_list_set_remember_info_visibility (self->display,
+                                                                         self->remember_info_visibility);
                _gtk_source_assistant_set_mark (GTK_SOURCE_ASSISTANT (self->display),
                                                self->completion_mark);
                _gtk_source_view_add_assistant (self->view,
diff --git a/gtksourceview/gtksourcecompletionlist-private.h b/gtksourceview/gtksourcecompletionlist-private.h
index c0712051..10a03458 100644
--- a/gtksourceview/gtksourcecompletionlist-private.h
+++ b/gtksourceview/gtksourcecompletionlist-private.h
@@ -31,20 +31,22 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (GtkSourceCompletionList, _gtk_source_completion_list, GTK_SOURCE, COMPLETION_LIST, 
GtkSourceAssistant)
 
-GtkSourceCompletionList    *_gtk_source_completion_list_new              (void);
-void                        _gtk_source_completion_list_reposition       (GtkSourceCompletionList    *self);
-GtkSourceCompletionContext *_gtk_source_completion_list_get_context      (GtkSourceCompletionList    *self);
-void                        _gtk_source_completion_list_set_context      (GtkSourceCompletionList    *self,
-                                                                          GtkSourceCompletionContext 
*context);
-gboolean                    _gtk_source_completion_list_get_show_details (GtkSourceCompletionList    *self);
-void                        _gtk_source_completion_list_set_show_details (GtkSourceCompletionList    *self,
-                                                                          gboolean                    
show_details);
-guint                       _gtk_source_completion_list_get_n_rows       (GtkSourceCompletionList    *self);
-void                        _gtk_source_completion_list_set_n_rows       (GtkSourceCompletionList    *self,
-                                                                          guint                       
n_rows);
-void                        _gtk_source_completion_list_set_font_desc    (GtkSourceCompletionList    *self,
-                                                                          const PangoFontDescription 
*font_desc);
-void                        _gtk_source_completion_list_set_show_icons   (GtkSourceCompletionList    *self,
-                                                                          gboolean                    
show_icons);
+GtkSourceCompletionList    *_gtk_source_completion_list_new                          (void);
+void                        _gtk_source_completion_list_reposition                   
(GtkSourceCompletionList    *self);
+GtkSourceCompletionContext *_gtk_source_completion_list_get_context                  
(GtkSourceCompletionList    *self);
+void                        _gtk_source_completion_list_set_context                  
(GtkSourceCompletionList    *self,
+                                                                                      
GtkSourceCompletionContext *context);
+gboolean                    _gtk_source_completion_list_get_show_details             
(GtkSourceCompletionList    *self);
+void                        _gtk_source_completion_list_set_show_details             
(GtkSourceCompletionList    *self,
+                                                                                      gboolean               
     show_details);
+guint                       _gtk_source_completion_list_get_n_rows                   
(GtkSourceCompletionList    *self);
+void                        _gtk_source_completion_list_set_n_rows                   
(GtkSourceCompletionList    *self,
+                                                                                      guint                  
     n_rows);
+void                        _gtk_source_completion_list_set_font_desc                
(GtkSourceCompletionList    *self,
+                                                                                      const 
PangoFontDescription *font_desc);
+void                        _gtk_source_completion_list_set_show_icons               
(GtkSourceCompletionList    *self,
+                                                                                      gboolean               
     show_icons);
+void                        _gtk_source_completion_list_set_remember_info_visibility 
(GtkSourceCompletionList    *self,
+                                                                                      gboolean               
     remember_info_visibility);
 
 G_END_DECLS
diff --git a/gtksourceview/gtksourcecompletionlist.c b/gtksourceview/gtksourcecompletionlist.c
index d1e86f3d..8532951e 100644
--- a/gtksourceview/gtksourcecompletionlist.c
+++ b/gtksourceview/gtksourcecompletionlist.c
@@ -47,6 +47,8 @@ struct _GtkSourceCompletionList
        GtkBox                     *details;
        GtkSourceCompletionCell    *comments;
        GtkLabel                   *alternate_label;
+
+       guint                       remember_info_visibility : 1;
 };
 
 enum {
@@ -60,6 +62,21 @@ G_DEFINE_TYPE (GtkSourceCompletionList, _gtk_source_completion_list, GTK_SOURCE_
 
 static GParamSpec *properties [N_PROPS];
 
+static void
+_gtk_source_completion_list_hide (GtkWidget *widget)
+{
+       GtkSourceCompletionList *self = (GtkSourceCompletionList *)widget;
+
+       g_assert (GTK_SOURCE_IS_COMPLETION_LIST (self));
+
+       GTK_WIDGET_CLASS (_gtk_source_completion_list_parent_class)->hide (widget);
+
+       if (!self->remember_info_visibility)
+       {
+               _gtk_source_completion_list_set_show_details (self, FALSE);
+       }
+}
+
 static void
 _gtk_source_completion_list_show (GtkWidget *widget)
 {
@@ -377,6 +394,7 @@ _gtk_source_completion_list_class_init (GtkSourceCompletionListClass *klass)
 
        widget_class->get_request_mode = _gtk_source_completion_list_get_request_mode;
        widget_class->show = _gtk_source_completion_list_show;
+       widget_class->hide = _gtk_source_completion_list_hide;
 
        assistant_class->get_offset = _gtk_source_completion_list_get_offset;
        assistant_class->get_target_location = _gtk_source_completion_list_get_target_location;
@@ -570,3 +588,12 @@ _gtk_source_completion_list_set_show_icons (GtkSourceCompletionList *self,
 
        _gtk_source_completion_list_box_set_show_icons (self->listbox, show_icons);
 }
+
+void
+_gtk_source_completion_list_set_remember_info_visibility (GtkSourceCompletionList *self,
+                                                          gboolean                 remember_info_visibility)
+{
+       g_return_if_fail (GTK_SOURCE_IS_COMPLETION_LIST (self));
+
+       self->remember_info_visibility = !!remember_info_visibility;
+}
diff --git a/tests/test-completion.c b/tests/test-completion.c
index 6560eb4f..5b3d818c 100644
--- a/tests/test-completion.c
+++ b/tests/test-completion.c
@@ -553,6 +553,10 @@ create_window (void)
                                select_on_show, "active",
                                G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
 
+       g_object_bind_property (completion, "remember-info-visibility",
+                               remember_info_visibility, "active",
+                               G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
+
        g_object_bind_property (completion, "show-icons",
                                show_icons, "active",
                                G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);


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