[gtksourceview/wip/chergert/gsv-gtk4: 224/259] completion: implement GtkSourceCompletion:show-icons
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/gsv-gtk4: 224/259] completion: implement GtkSourceCompletion:show-icons
- Date: Mon, 21 Sep 2020 23:27:48 +0000 (UTC)
commit de33d2beddfd2d40f8cea1bdf276ece669595cbe
Author: Christian Hergert <chergert redhat com>
Date: Tue Sep 8 13:58:37 2020 -0700
completion: implement GtkSourceCompletion:show-icons
This existed in the previous implementation of completion, and so we should
keep it around for compatibility.
gtksourceview/GtkSourceView.css | 1 +
gtksourceview/gtksourcecompletion.c | 42 +++++++++++++++++++---
gtksourceview/gtksourcecompletionlist-private.h | 2 ++
gtksourceview/gtksourcecompletionlist.c | 9 +++++
gtksourceview/gtksourcecompletionlistbox-private.h | 2 ++
gtksourceview/gtksourcecompletionlistbox.c | 17 ++++++++-
.../gtksourcecompletionlistboxrow-private.h | 1 +
gtksourceview/gtksourcecompletionlistboxrow.c | 2 ++
tests/test-completion.c | 8 +++--
9 files changed, 76 insertions(+), 8 deletions(-)
---
diff --git a/gtksourceview/GtkSourceView.css b/gtksourceview/GtkSourceView.css
index 5ab92f7c..b3e1787d 100644
--- a/gtksourceview/GtkSourceView.css
+++ b/gtksourceview/GtkSourceView.css
@@ -56,6 +56,7 @@ GtkSourceAssistant.completion list row cell.icon {
GtkSourceAssistant.completion list row cell.typed-text {
margin-left: 6px;
margin-right: 6px;
+ min-height: 28px;
}
GtkSourceAssistant.completion list row cell.after {
margin-right: 6px;
diff --git a/gtksourceview/gtksourcecompletion.c b/gtksourceview/gtksourcecompletion.c
index 3dbecba5..629bc9ca 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 icon column is visible */
+ guint show_icons : 1;
+
guint disposed : 1;
};
@@ -129,6 +132,7 @@ enum {
PROP_BUFFER,
PROP_PAGE_SIZE,
PROP_SELECT_ON_SHOW,
+ PROP_SHOW_ICONS,
PROP_VIEW,
N_PROPS
};
@@ -869,6 +873,10 @@ gtk_source_completion_get_property (GObject *object,
g_value_set_boolean (value, _gtk_source_completion_get_select_on_show (self));
break;
+ case PROP_SHOW_ICONS:
+ g_value_set_boolean (value, self->show_icons);
+ break;
+
case PROP_VIEW:
g_value_set_object (value, self->view);
break;
@@ -892,6 +900,15 @@ gtk_source_completion_set_property (GObject *object,
gtk_source_completion_set_select_on_show (self, g_value_get_boolean (value));
break;
+ case PROP_SHOW_ICONS:
+ self->show_icons = g_value_get_boolean (value);
+ if (self->display != NULL)
+ {
+ _gtk_source_completion_list_set_show_icons (self->display, self->show_icons);
+ }
+ g_object_notify_by_pspec (object, pspec);
+ break;
+
case PROP_VIEW:
gtk_source_completion_set_view (self, g_value_get_object (value));
break;
@@ -953,6 +970,19 @@ gtk_source_completion_class_init (GtkSourceCompletionClass *klass)
FALSE,
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ /**
+ * GtkSourceCompletion:show-icons:
+ *
+ * The "show-icons" property denotes if icons should be displayed within
+ * the list of completions presented to the user.
+ */
+ properties [PROP_SHOW_ICONS] =
+ g_param_spec_boolean ("show-icons",
+ "Show Icons",
+ "If icons should be shown in the completion results",
+ TRUE,
+ (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
/**
* GtkSourceCompletion:view:
*
@@ -962,11 +992,11 @@ gtk_source_completion_class_init (GtkSourceCompletionClass *klass)
* Since: 5.0
*/
properties [PROP_VIEW] =
- g_param_spec_object ("view",
- "View",
- "The text view for which to provide completion",
- GTK_SOURCE_TYPE_VIEW,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
+ g_param_spec_object ("view",
+ "View",
+ "The text view for which to provide completion",
+ GTK_SOURCE_TYPE_VIEW,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, N_PROPS, properties);
@@ -1064,6 +1094,7 @@ gtk_source_completion_init (GtkSourceCompletion *self)
self->context_signals = gtk_source_signal_group_new (GTK_SOURCE_TYPE_COMPLETION_CONTEXT);
self->view_signals = gtk_source_signal_group_new (GTK_SOURCE_TYPE_VIEW);
self->page_size = DEFAULT_PAGE_SIZE;
+ self->show_icons = TRUE;
/*
* We want to be notified when the context switches from no results to
@@ -1327,6 +1358,7 @@ _gtk_source_completion_get_display (GtkSourceCompletion *self)
self->display = _gtk_source_completion_list_new ();
_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_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 1b7f06fa..c0712051 100644
--- a/gtksourceview/gtksourcecompletionlist-private.h
+++ b/gtksourceview/gtksourcecompletionlist-private.h
@@ -44,5 +44,7 @@ void _gtk_source_completion_list_set_n_rows (GtkSou
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);
G_END_DECLS
diff --git a/gtksourceview/gtksourcecompletionlist.c b/gtksourceview/gtksourcecompletionlist.c
index fb853098..d1e86f3d 100644
--- a/gtksourceview/gtksourcecompletionlist.c
+++ b/gtksourceview/gtksourcecompletionlist.c
@@ -561,3 +561,12 @@ _gtk_source_completion_list_reposition (GtkSourceCompletionList *self)
gtk_native_check_resize (GTK_NATIVE (self->info));
}
}
+
+void
+_gtk_source_completion_list_set_show_icons (GtkSourceCompletionList *self,
+ gboolean show_icons)
+{
+ g_return_if_fail (GTK_SOURCE_IS_COMPLETION_LIST (self));
+
+ _gtk_source_completion_list_box_set_show_icons (self->listbox, show_icons);
+}
diff --git a/gtksourceview/gtksourcecompletionlistbox-private.h
b/gtksourceview/gtksourcecompletionlistbox-private.h
index 16dcacbf..5f453705 100644
--- a/gtksourceview/gtksourcecompletionlistbox-private.h
+++ b/gtksourceview/gtksourcecompletionlistbox-private.h
@@ -52,5 +52,7 @@ gboolean _gtk_source_completion_list_box_key_activates
const GdkKeyEvent
*key);
int _gtk_source_completion_list_box_get_alternate (GtkSourceCompletionListBox
*self);
guint _gtk_source_completion_list_box_get_n_alternates (GtkSourceCompletionListBox
*self);
+void _gtk_source_completion_list_box_set_show_icons (GtkSourceCompletionListBox
*self,
+ gboolean
show_icons);
G_END_DECLS
diff --git a/gtksourceview/gtksourcecompletionlistbox.c b/gtksourceview/gtksourcecompletionlistbox.c
index 07301719..c0979739 100644
--- a/gtksourceview/gtksourcecompletionlistbox.c
+++ b/gtksourceview/gtksourcecompletionlistbox.c
@@ -82,6 +82,9 @@ struct _GtkSourceCompletionListBox
/* Gesture to handle button press/touch events. */
GtkGesture *click_gesture;
+
+ /* If icons are visible */
+ guint show_icons : 1;
};
typedef struct
@@ -861,6 +864,7 @@ gtk_source_completion_list_box_do_update (GtkSourceCompletionListBox *self,
state.context,
provider,
proposal,
+ self->show_icons,
has_alternates);
if (gtk_widget_get_visible (iter))
@@ -875,7 +879,7 @@ gtk_source_completion_list_box_do_update (GtkSourceCompletionListBox *self,
else
{
_gtk_source_completion_list_box_row_display (GTK_SOURCE_COMPLETION_LIST_BOX_ROW
(iter),
- NULL, NULL, NULL, FALSE);
+ NULL, NULL, NULL, self->show_icons,
FALSE);
gtk_widget_hide (GTK_WIDGET (iter));
}
@@ -1263,3 +1267,14 @@ _gtk_source_completion_list_box_get_n_alternates (GtkSourceCompletionListBox *se
return self->alternates ? self->alternates->len : 0;
}
+
+void
+_gtk_source_completion_list_box_set_show_icons (GtkSourceCompletionListBox *self,
+ gboolean show_icons)
+{
+ g_return_if_fail (GTK_SOURCE_IS_COMPLETION_LIST_BOX (self));
+
+ self->show_icons = !!show_icons;
+
+ gtk_source_completion_list_box_queue_update (self);
+}
diff --git a/gtksourceview/gtksourcecompletionlistboxrow-private.h
b/gtksourceview/gtksourcecompletionlistboxrow-private.h
index 7e2edda5..ab3fa8c0 100644
--- a/gtksourceview/gtksourcecompletionlistboxrow-private.h
+++ b/gtksourceview/gtksourcecompletionlistboxrow-private.h
@@ -36,6 +36,7 @@ void _gtk_source_completion_list_box_row_display (G
GtkSourceCompletionContext
*context,
GtkSourceCompletionProvider
*provider,
GtkSourceCompletionProposal
*proposal,
+ gboolean
show_icons,
gboolean
has_alternates);
gint _gtk_source_completion_list_box_row_get_x_offset (GtkSourceCompletionListBoxRow
*self,
GtkWidget
*toplevel);
diff --git a/gtksourceview/gtksourcecompletionlistboxrow.c b/gtksourceview/gtksourcecompletionlistboxrow.c
index 6de79b6a..c64e358b 100644
--- a/gtksourceview/gtksourcecompletionlistboxrow.c
+++ b/gtksourceview/gtksourcecompletionlistboxrow.c
@@ -90,6 +90,7 @@ _gtk_source_completion_list_box_row_display (GtkSourceCompletionListBoxRow *self
GtkSourceCompletionContext *context,
GtkSourceCompletionProvider *provider,
GtkSourceCompletionProposal *proposal,
+ gboolean show_icons,
gboolean has_alternates)
{
g_return_if_fail (GTK_SOURCE_IS_COMPLETION_LIST_BOX_ROW (self));
@@ -112,6 +113,7 @@ _gtk_source_completion_list_box_row_display (GtkSourceCompletionListBoxRow *self
gtk_source_completion_provider_display (provider, context, proposal, self->after);
}
+ gtk_widget_set_visible (GTK_WIDGET (self->icon), show_icons);
gtk_widget_set_visible (GTK_WIDGET (self->more), has_alternates);
}
diff --git a/tests/test-completion.c b/tests/test-completion.c
index a5face65..6560eb4f 100644
--- a/tests/test-completion.c
+++ b/tests/test-completion.c
@@ -550,8 +550,12 @@ create_window (void)
main_loop);
g_object_bind_property (completion, "select-on-show",
- select_on_show, "active",
- G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
+ select_on_show, "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);
create_completion (source_view, completion);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]