[gnome-builder/wip/gtk4-port] plugins/create-project: add popover for language selection
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/gtk4-port] plugins/create-project: add popover for language selection
- Date: Fri, 27 May 2022 00:46:33 +0000 (UTC)
commit f24e248bb176ccf841b1df756965e7157ed56147
Author: Christian Hergert <chergert redhat com>
Date: Thu May 26 17:43:08 2022 -0700
plugins/create-project: add popover for language selection
.../create-project/gbp-create-project-widget.c | 23 ++++++++
.../create-project/gbp-create-project-widget.ui | 68 +++++++++++++++++++++-
2 files changed, 89 insertions(+), 2 deletions(-)
---
diff --git a/src/plugins/create-project/gbp-create-project-widget.c
b/src/plugins/create-project/gbp-create-project-widget.c
index 28e7e5be7..15e9b18d5 100644
--- a/src/plugins/create-project/gbp-create-project-widget.c
+++ b/src/plugins/create-project/gbp-create-project-widget.c
@@ -40,6 +40,7 @@ struct _GbpCreateProjectWidget
IdeTemplateInput *input;
AdwEntryRow *location;
GtkMenuButton *template_button;
+ GtkMenuButton *language_button;
};
enum {
@@ -81,6 +82,26 @@ template_activated_cb (GbpCreateProjectWidget *self,
ide_template_input_set_template (self->input, id);
}
+static void
+language_activated_cb (GbpCreateProjectWidget *self,
+ guint position,
+ GtkListView *list_view)
+{
+ g_autoptr(GtkStringObject) string = NULL;
+ GListModel *model;
+
+ g_assert (GBP_IS_CREATE_PROJECT_WIDGET (self));
+ g_assert (GTK_IS_LIST_VIEW (list_view));
+
+ model = G_LIST_MODEL (gtk_list_view_get_model (list_view));
+ string = g_list_model_get_item (model, position);
+
+ gtk_menu_button_popdown (self->language_button);
+
+ ide_template_input_set_language (self->input,
+ gtk_string_object_get_string (string));
+}
+
static void
on_location_changed_cb (GbpCreateProjectWidget *self,
GtkEditable *editable)
@@ -195,9 +216,11 @@ gbp_create_project_widget_class_init (GbpCreateProjectWidgetClass *klass)
gtk_widget_class_bind_template_child (widget_class, GbpCreateProjectWidget, input);
gtk_widget_class_bind_template_child (widget_class, GbpCreateProjectWidget, location);
gtk_widget_class_bind_template_child (widget_class, GbpCreateProjectWidget, main);
+ gtk_widget_class_bind_template_child (widget_class, GbpCreateProjectWidget, language_button);
gtk_widget_class_bind_template_child (widget_class, GbpCreateProjectWidget, template_button);
gtk_widget_class_bind_template_callback (widget_class, template_activated_cb);
+ gtk_widget_class_bind_template_callback (widget_class, language_activated_cb);
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
diff --git a/src/plugins/create-project/gbp-create-project-widget.ui
b/src/plugins/create-project/gbp-create-project-widget.ui
index 50175c749..35761723d 100644
--- a/src/plugins/create-project/gbp-create-project-widget.ui
+++ b/src/plugins/create-project/gbp-create-project-widget.ui
@@ -93,12 +93,76 @@
<object class="AdwActionRow">
<property name="title" translatable="yes">Language</property>
<child type="suffix">
- <object class="GtkMenuButton">
+ <object class="GtkMenuButton" id="language_button">
<property name="valign">center</property>
- <property name="label">C</property>
+ <property name="label" bind-source="input" bind-property="language"
bind-flags="sync-create"/>
<style>
<class name="flat"/>
</style>
+ <property name="popover">
+ <object class="GtkPopover">
+ <child>
+ <object class="GtkFrame">
+ <property name="margin-bottom">6</property>
+ <property name="margin-end">6</property>
+ <property name="margin-start">6</property>
+ <property name="margin-top">6</property>
+ <child>
+ <object class="GtkScrolledWindow">
+ <property name="propagate-natural-height">true</property>
+ <property name="propagate-natural-width">true</property>
+ <property name="min-content-width">150</property>
+ <property name="min-content-height">200</property>
+ <child>
+ <object class="GtkListView">
+ <signal name="activate" handler="language_activated_cb"
swapped="true" object="GbpCreateProjectWidget"/>
+ <property name="model">
+ <object class="GtkSingleSelection">
+ <property name="model" bind-source="input"
bind-property="languages-model" bind-flags="sync-create"/>
+ </object>
+ </property>
+ <property name="orientation">vertical</property>
+ <property name="single-click-activate">true</property>
+ <property name="factory">
+ <object class="GtkBuilderListItemFactory">
+ <property name="bytes"><![CDATA[
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <template class="GtkListItem">
+ <property name="child">
+ <object class="GtkBox">
+ <property name="spacing">6</property>
+ <property name="margin-top">6</property>
+ <property name="margin-bottom">6</property>
+ <property name="margin-start">6</property>
+ <property name="margin-end">6</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="xalign">0</property>
+ <property name="hexpand">true</property>
+ <binding name="label">
+ <lookup name="string" type="GtkStringObject">
+ <lookup name="item">GtkListItem</lookup>
+ </lookup>
+ </binding>
+ </object>
+ </child>
+ </object>
+ </property>
+ </template>
+</interface>
+]]>
+ </property>
+ </object>
+ </property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </property>
</object>
</child>
</object>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]