[gtksourceview] completion: add seperator between proposals of differing providers
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] completion: add seperator between proposals of differing providers
- Date: Sat, 3 Sep 2022 18:29:33 +0000 (UTC)
commit 700ff51a5a213e7f8b64682ed98ab7f36d5cc7bd
Author: Christian Hergert <chergert redhat com>
Date: Sat Sep 3 11:28:48 2022 -0700
completion: add seperator between proposals of differing providers
This helps to create some visual separation between proposals that come
from different providers. At some point, we might also want to include
the provider title (or at least provide a way to display that via a
property on GtkSourceCompletion).
gtksourceview/GtkSourceView.css | 8 ++++++
gtksourceview/gtksourcecompletionlistbox.c | 38 ++++++++++++++++++++++++---
gtksourceview/gtksourcecompletionlistboxrow.c | 6 +++++
3 files changed, 49 insertions(+), 3 deletions(-)
---
diff --git a/gtksourceview/GtkSourceView.css b/gtksourceview/GtkSourceView.css
index fb684fe3..f0fe96bc 100644
--- a/gtksourceview/GtkSourceView.css
+++ b/gtksourceview/GtkSourceView.css
@@ -32,6 +32,14 @@ GtkSourceAssistant.completion list {
border-top-right-radius: 11px;
margin: 0px;
}
+GtkSourceAssistant.completion list separator.horizontal {
+ margin-top: 2px;
+ margin-bottom: 2px;
+}
+GtkSourceAssistant.completion list row:selected:not(:backdrop) {
+ background: @theme_selected_bg_color;
+ color: @theme_selected_fg_color;
+}
GtkSourceAssistant.completion list,
GtkSourceAssistant.completion list row:not(:selected):not(:hover),
GtkSourceAssistant.completion list row cell {
diff --git a/gtksourceview/gtksourcecompletionlistbox.c b/gtksourceview/gtksourcecompletionlistbox.c
index 4c002b0d..a8f7d209 100644
--- a/gtksourceview/gtksourcecompletionlistbox.c
+++ b/gtksourceview/gtksourcecompletionlistbox.c
@@ -829,6 +829,7 @@ static void
gtk_source_completion_list_box_do_update (GtkSourceCompletionListBox *self,
gboolean update_selection)
{
+ GtkSourceCompletionProvider *last_provider = NULL;
UpdateState state = {0};
g_assert (GTK_SOURCE_IS_COMPLETION_LIST_BOX (self));
@@ -857,9 +858,15 @@ gtk_source_completion_list_box_do_update (GtkSourceCompletionListBox *self,
{
GtkSourceCompletionProposal *proposal = NULL;
GtkSourceCompletionProvider *provider = NULL;
+ GtkWidget *header;
gboolean has_alternates = FALSE;
- g_assert (GTK_SOURCE_IS_COMPLETION_LIST_BOX_ROW (iter));
+ if (!GTK_SOURCE_IS_COMPLETION_LIST_BOX_ROW (iter))
+ {
+ continue;
+ }
+
+ header = gtk_list_box_row_get_header (GTK_LIST_BOX_ROW (iter));
if (state.selected >= 0 && state.position == (guint)state.selected)
{
@@ -896,16 +903,20 @@ gtk_source_completion_list_box_do_update (GtkSourceCompletionListBox *self,
has_alternates);
gtk_widget_show (iter);
+ gtk_widget_set_visible (header, provider != last_provider && last_provider);
}
else
{
- gtk_widget_hide (GTK_WIDGET (iter));
+ gtk_widget_hide (iter);
+ gtk_widget_hide (header);
_gtk_source_completion_list_box_row_display (GTK_SOURCE_COMPLETION_LIST_BOX_ROW
(iter),
NULL, NULL, NULL, self->show_icons,
FALSE);
}
state.position++;
+ last_provider = provider;
+
g_clear_object (&proposal);
g_clear_object (&provider);
}
@@ -1005,15 +1016,21 @@ _gtk_source_completion_list_box_set_n_rows (GtkSourceCompletionListBox *self,
for (guint i = 0; i < n_rows; i++)
{
GtkWidget *row;
+ GtkWidget *header;
row = _gtk_source_completion_list_box_row_new ();
+ header = gtk_list_box_row_get_header (GTK_LIST_BOX_ROW (row));
+
gtk_widget_set_can_focus (GTK_WIDGET (row), FALSE);
+
_gtk_source_completion_list_box_row_attach (GTK_SOURCE_COMPLETION_LIST_BOX_ROW (row),
self->before_size_group,
self->typed_text_size_group,
self->after_size_group);
_gtk_source_completion_list_box_row_set_attrs (GTK_SOURCE_COMPLETION_LIST_BOX_ROW
(row),
self->font_attrs);
+
+ gtk_box_append (self->box, header);
gtk_box_append (self->box, row);
}
@@ -1173,7 +1190,17 @@ _gtk_source_completion_list_box_get_first (GtkSourceCompletionListBox *self)
{
g_return_val_if_fail (GTK_SOURCE_IS_COMPLETION_LIST_BOX (self), NULL);
- return GTK_SOURCE_COMPLETION_LIST_BOX_ROW (gtk_widget_get_first_child (GTK_WIDGET (self->box)));
+ for (GtkWidget *child = gtk_widget_get_first_child (GTK_WIDGET (self->box));
+ child != NULL;
+ child = gtk_widget_get_next_sibling (child))
+ {
+ if (GTK_SOURCE_IS_COMPLETION_LIST_BOX_ROW (child))
+ {
+ return GTK_SOURCE_COMPLETION_LIST_BOX_ROW (child);
+ }
+ }
+
+ return NULL;
}
void
@@ -1277,6 +1304,11 @@ _gtk_source_completion_list_box_set_font_desc (GtkSourceCompletionListBox *self,
iter != NULL;
iter = gtk_widget_get_next_sibling (iter))
{
+ if (!GTK_SOURCE_IS_COMPLETION_LIST_BOX_ROW (iter))
+ {
+ continue;
+ }
+
_gtk_source_completion_list_box_row_set_attrs (GTK_SOURCE_COMPLETION_LIST_BOX_ROW (iter),
self->font_attrs);
}
diff --git a/gtksourceview/gtksourcecompletionlistboxrow.c b/gtksourceview/gtksourcecompletionlistboxrow.c
index c64e358b..ea710a32 100644
--- a/gtksourceview/gtksourcecompletionlistboxrow.c
+++ b/gtksourceview/gtksourcecompletionlistboxrow.c
@@ -77,6 +77,12 @@ static void
gtk_source_completion_list_box_row_init (GtkSourceCompletionListBoxRow *self)
{
gtk_widget_init_template (GTK_WIDGET (self));
+
+ gtk_list_box_row_set_header (GTK_LIST_BOX_ROW (self),
+ g_object_new (GTK_TYPE_SEPARATOR,
+ "orientation", GTK_ORIENTATION_HORIZONTAL,
+ "visible", FALSE,
+ NULL));
}
GtkWidget *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]