[gtksourceview/wip/chergert/gsv-gtk4] assistant: move resize/reposition to base class
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/gsv-gtk4] assistant: move resize/reposition to base class
- Date: Thu, 10 Sep 2020 23:39:09 +0000 (UTC)
commit 91a137154c64975f1d7d533e0f3c445547c921b3
Author: Christian Hergert <chergert redhat com>
Date: Thu Sep 10 16:36:33 2020 -0700
assistant: move resize/reposition to base class
gtksourceview/gtksourceassistant-private.h | 1 +
gtksourceview/gtksourceassistant.c | 32 ++++++++++++++++-
gtksourceview/gtksourcecompletion.c | 1 -
gtksourceview/gtksourcecompletionlist.c | 55 +++++++-----------------------
gtksourceview/gtksourcecompletionlist.ui | 4 +--
5 files changed, 47 insertions(+), 46 deletions(-)
---
diff --git a/gtksourceview/gtksourceassistant-private.h b/gtksourceview/gtksourceassistant-private.h
index 7bc6d55f..d8d2084b 100644
--- a/gtksourceview/gtksourceassistant-private.h
+++ b/gtksourceview/gtksourceassistant-private.h
@@ -54,6 +54,7 @@ void _gtk_source_assistant_set_mark (GtkSourceAssistant *assist
GtkTextMark *mark);
void _gtk_source_assistant_set_child (GtkSourceAssistant *assistant,
GtkWidget *child);
+void _gtk_source_assistant_reposition (GtkSourceAssistant *assistant);
void _gtk_source_assistant_destroy (GtkSourceAssistant *assistant);
G_END_DECLS
diff --git a/gtksourceview/gtksourceassistant.c b/gtksourceview/gtksourceassistant.c
index b9cd434a..3c7e383d 100644
--- a/gtksourceview/gtksourceassistant.c
+++ b/gtksourceview/gtksourceassistant.c
@@ -126,6 +126,8 @@ _gtk_source_assistant_update_position (GtkSourceAssistant *assistant)
gtk_popover_set_pointing_to (GTK_POPOVER (assistant), &rect);
}
+ gtk_native_check_resize (GTK_NATIVE (assistant));
+
if (priv->child != NULL)
{
children = _gtk_source_assistant_child_get_attached (priv->child);
@@ -145,6 +147,34 @@ _gtk_source_assistant_update_position (GtkSourceAssistant *assistant)
}
}
+static void
+_gtk_source_assistant_update_size (GtkSourceAssistant *self)
+{
+ int min_width;
+ int nat_width;
+
+ g_assert (GTK_SOURCE_IS_ASSISTANT (self));
+
+ /* Hack to force the sizing request, otherwise the popover does
+ * not shrink as results are reduced.
+ */
+ gtk_widget_set_size_request (GTK_WIDGET (self), -1, -1);
+ gtk_widget_measure (GTK_WIDGET (self),
+ GTK_ORIENTATION_HORIZONTAL,
+ -1,
+ &min_width, &nat_width, NULL, NULL);
+ gtk_widget_set_size_request (GTK_WIDGET (self), min_width, -1);
+}
+
+void
+_gtk_source_assistant_reposition (GtkSourceAssistant *self)
+{
+ g_return_if_fail (GTK_SOURCE_IS_ASSISTANT (self));
+
+ _gtk_source_assistant_update_size (self);
+ _gtk_source_assistant_update_position (self);
+}
+
static void
_gtk_source_assistant_show (GtkWidget *widget)
{
@@ -152,7 +182,7 @@ _gtk_source_assistant_show (GtkWidget *widget)
g_assert (GTK_SOURCE_IS_ASSISTANT (assistant));
- _gtk_source_assistant_update_position (assistant);
+ _gtk_source_assistant_reposition (assistant);
GTK_WIDGET_CLASS (_gtk_source_assistant_parent_class)->show (widget);
}
diff --git a/gtksourceview/gtksourcecompletion.c b/gtksourceview/gtksourcecompletion.c
index 8b5eaf7e..1e1f47dd 100644
--- a/gtksourceview/gtksourcecompletion.c
+++ b/gtksourceview/gtksourcecompletion.c
@@ -158,7 +158,6 @@ display_show (GtkSourceCompletionList *display)
{
g_assert (GTK_SOURCE_IS_COMPLETION_LIST (display));
- _gtk_source_completion_list_reposition (display);
gtk_widget_show (GTK_WIDGET (display));
gtk_widget_grab_focus (GTK_WIDGET (display));
}
diff --git a/gtksourceview/gtksourcecompletionlist.c b/gtksourceview/gtksourcecompletionlist.c
index 8532951e..06962768 100644
--- a/gtksourceview/gtksourcecompletionlist.c
+++ b/gtksourceview/gtksourcecompletionlist.c
@@ -84,8 +84,6 @@ _gtk_source_completion_list_show (GtkWidget *widget)
g_assert (GTK_SOURCE_IS_COMPLETION_LIST (self));
- _gtk_source_completion_list_reposition (self);
-
GTK_WIDGET_CLASS (_gtk_source_completion_list_parent_class)->show (widget);
if (_gtk_source_completion_list_get_show_details (self))
@@ -219,9 +217,17 @@ _gtk_source_completion_list_notify_alternates_cb (GtkSourceCompletionList *se
}
static void
-_gtk_source_completion_list_notify_proposal (GtkSourceCompletionList *self,
- GParamSpec *pspec,
- GtkSourceCompletionListBox *listbox)
+_gtk_source_completion_list_reposition_cb (GtkSourceCompletionList *self)
+{
+ g_assert (GTK_SOURCE_IS_COMPLETION_LIST (self));
+
+ _gtk_source_assistant_reposition (GTK_SOURCE_ASSISTANT (self));
+}
+
+static void
+_gtk_source_completion_list_notify_proposal_cb (GtkSourceCompletionList *self,
+ GParamSpec *pspec,
+ GtkSourceCompletionListBox *listbox)
{
g_assert (GTK_SOURCE_IS_COMPLETION_LIST (self));
g_assert (GTK_SOURCE_IS_COMPLETION_LIST_BOX (listbox));
@@ -422,8 +428,8 @@ _gtk_source_completion_list_class_init (GtkSourceCompletionListClass *klass)
gtk_widget_class_bind_template_child (widget_class, GtkSourceCompletionList, listbox);
gtk_widget_class_bind_template_child (widget_class, GtkSourceCompletionList, scroller);
gtk_widget_class_bind_template_child (widget_class, GtkSourceCompletionList, show_details);
- gtk_widget_class_bind_template_callback (widget_class, _gtk_source_completion_list_reposition);
- gtk_widget_class_bind_template_callback (widget_class, _gtk_source_completion_list_notify_proposal);
+ gtk_widget_class_bind_template_callback (widget_class,
_gtk_source_completion_list_notify_proposal_cb);
+ gtk_widget_class_bind_template_callback (widget_class, _gtk_source_completion_list_reposition_cb);
g_type_ensure (GTK_SOURCE_TYPE_COMPLETION_LIST_BOX);
}
@@ -545,41 +551,6 @@ _gtk_source_completion_list_set_font_desc (GtkSourceCompletionList *self,
_gtk_source_completion_list_box_set_font_desc (self->listbox, font_desc);
}
-void
-_gtk_source_completion_list_reposition (GtkSourceCompletionList *self)
-{
- int old_x_offset, old_y_offset;
- int x_offset = 0, y_offset = 0;
- int min_width, nat_width;
-
- g_return_if_fail (GTK_SOURCE_IS_COMPLETION_LIST (self));
-
- /* Hack to force the sizing request, otherwise the popover does
- * not shrink as results are reduced.
- */
- gtk_widget_set_size_request (GTK_WIDGET (self), -1, -1);
- gtk_widget_measure (GTK_WIDGET (self),
- GTK_ORIENTATION_HORIZONTAL,
- -1,
- &min_width, &nat_width, NULL, NULL);
- gtk_widget_set_size_request (GTK_WIDGET (self), min_width, -1);
-
- /* Reposition the popup if we have a new offset */
- _gtk_source_completion_list_get_offset (GTK_SOURCE_ASSISTANT (self), &x_offset, &y_offset);
- gtk_popover_get_offset (GTK_POPOVER (self), &old_x_offset, &old_y_offset);
- if (old_x_offset != x_offset || old_y_offset != y_offset)
- {
- gtk_popover_set_offset (GTK_POPOVER (self), x_offset, y_offset);
- }
-
- gtk_native_check_resize (GTK_NATIVE (self));
-
- if (gtk_widget_get_visible (GTK_WIDGET (self->info)))
- {
- gtk_native_check_resize (GTK_NATIVE (self->info));
- }
-}
-
void
_gtk_source_completion_list_set_show_icons (GtkSourceCompletionList *self,
gboolean show_icons)
diff --git a/gtksourceview/gtksourcecompletionlist.ui b/gtksourceview/gtksourcecompletionlist.ui
index 588e3841..6209a694 100644
--- a/gtksourceview/gtksourcecompletionlist.ui
+++ b/gtksourceview/gtksourcecompletionlist.ui
@@ -16,8 +16,8 @@
<child>
<object class="GtkSourceCompletionListBox" id="listbox">
<property name="can-focus">false</property>
- <signal name="notify::proposal" handler="_gtk_source_completion_list_notify_proposal"
swapped="true"/>
- <signal name="reposition" handler="_gtk_source_completion_list_reposition" swapped="true"/>
+ <signal name="notify::proposal" handler="_gtk_source_completion_list_notify_proposal_cb"
swapped="true"/>
+ <signal name="reposition" handler="_gtk_source_completion_list_reposition_cb"
swapped="true"/>
</object>
</child>
</object>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]