[libhandy] demo: Add a duplicate tab feature to the the tabs demo
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libhandy] demo: Add a duplicate tab feature to the the tabs demo
- Date: Wed, 3 Feb 2021 14:14:09 +0000 (UTC)
commit 70859f8c7e1c1d4a82fd24397b689df37d2fa39b
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Tue Feb 2 18:44:37 2021 +0500
demo: Add a duplicate tab feature to the the tabs demo
This will help showcase hdy_tab_view_add_page().
examples/hdy-tab-view-demo-window.c | 65 +++++++++++++++++++++++++++++-------
examples/hdy-tab-view-demo-window.ui | 4 +++
2 files changed, 57 insertions(+), 12 deletions(-)
---
diff --git a/examples/hdy-tab-view-demo-window.c b/examples/hdy-tab-view-demo-window.c
index fde6d705..7a24a24d 100644
--- a/examples/hdy-tab-view-demo-window.c
+++ b/examples/hdy-tab-view-demo-window.c
@@ -59,20 +59,14 @@ text_to_tooltip (GBinding *binding,
return TRUE;
}
-static void
-tab_new (GSimpleAction *action,
- GVariant *parameter,
- gpointer user_data)
+static HdyTabPage *
+add_page (HdyTabViewDemoWindow *self,
+ HdyTabPage *parent,
+ const gchar *title,
+ GIcon *icon)
{
- HdyTabViewDemoWindow *self = HDY_TAB_VIEW_DEMO_WINDOW (user_data);
- g_autofree gchar *title = NULL;
GtkWidget *content;
HdyTabPage *page;
- GIcon *icon;
- static gint next_page = 1;
-
- title = g_strdup_printf (_("Tab %d"), next_page);
- icon = get_random_icon ();
content = g_object_new (GTK_TYPE_ENTRY,
"visible", TRUE,
@@ -81,7 +75,7 @@ tab_new (GSimpleAction *action,
"valign", GTK_ALIGN_CENTER,
NULL);
- page = hdy_tab_view_append (self->view, GTK_WIDGET (content));
+ page = hdy_tab_view_add_page (self->view, GTK_WIDGET (content), parent);
g_object_bind_property (content, "text",
page, "title",
@@ -95,6 +89,27 @@ tab_new (GSimpleAction *action,
hdy_tab_page_set_icon (page, icon);
hdy_tab_page_set_indicator_activatable (page, TRUE);
+ return page;
+}
+
+static void
+tab_new (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ HdyTabViewDemoWindow *self = HDY_TAB_VIEW_DEMO_WINDOW (user_data);
+ g_autofree gchar *title = NULL;
+ HdyTabPage *page;
+ GtkWidget *content;
+ GIcon *icon;
+ static gint next_page = 1;
+
+ title = g_strdup_printf (_("Tab %d"), next_page);
+ icon = get_random_icon ();
+
+ page = add_page (self, NULL, title, icon);
+ content = hdy_tab_page_get_child (page);
+
hdy_tab_view_set_selected_page (self->view, page);
gtk_widget_grab_focus (content);
@@ -272,6 +287,31 @@ tab_refresh_icon (GSimpleAction *action,
hdy_tab_page_set_icon (get_current_page (self), icon);
}
+static void
+tab_duplicate (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ HdyTabViewDemoWindow *self = HDY_TAB_VIEW_DEMO_WINDOW (user_data);
+ HdyTabPage *parent = get_current_page (self);
+ HdyTabPage *page;
+
+ page = add_page (self, parent,
+ hdy_tab_page_get_title (parent),
+ hdy_tab_page_get_icon (parent));
+
+ hdy_tab_page_set_indicator_icon (page, hdy_tab_page_get_indicator_icon (parent));
+ hdy_tab_page_set_loading (page, hdy_tab_page_get_loading (parent));
+ hdy_tab_page_set_needs_attention (page, hdy_tab_page_get_needs_attention (parent));
+
+ g_object_set_data (G_OBJECT (page),
+ "hdy-tab-view-demo-muted",
+ g_object_get_data (G_OBJECT (parent),
+ "hdy-tab-view-demo-muted"));
+
+ hdy_tab_view_set_selected_page (self->view, page);
+}
+
static GActionEntry action_entries[] = {
{ "window-new", window_new },
{ "tab-new", tab_new },
@@ -290,6 +330,7 @@ static GActionEntry tab_action_entries[] = {
{ "indicator", NULL, NULL, "false", tab_change_indicator },
{ "icon", NULL, NULL, "false", tab_change_icon },
{ "refresh-icon", tab_refresh_icon },
+ { "duplicate", tab_duplicate },
};
static inline void
diff --git a/examples/hdy-tab-view-demo-window.ui b/examples/hdy-tab-view-demo-window.ui
index 65e7b4bc..e6a5aece 100644
--- a/examples/hdy-tab-view-demo-window.ui
+++ b/examples/hdy-tab-view-demo-window.ui
@@ -82,6 +82,10 @@
<attribute name="label" translatable="yes">_Move to New Window</attribute>
<attribute name="action">tab.move-to-new-window</attribute>
</item>
+ <item>
+ <attribute name="label" translatable="yes">D_uplicate</attribute>
+ <attribute name="action">tab.duplicate</attribute>
+ </item>
</section>
<section>
<item>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]