[gnome-todo] sidebar: Activate task list panel
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-todo] sidebar: Activate task list panel
- Date: Sun, 9 Jun 2019 19:52:01 +0000 (UTC)
commit 8d1a54a70897c15e3dbc531d4f0f8c9b3433abc7
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Sun Jun 9 01:02:36 2019 -0300
sidebar: Activate task list panel
By introducing a new action to GtdWindow, we can generically
activate any panel we want, with any property we want.
src/gtd-task-list-panel.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++
src/gtd-window.c | 36 +++++++++++++++++++++++++++
src/sidebar/gtd-sidebar.c | 39 ++++++++++++++++++++---------
3 files changed, 127 insertions(+), 11 deletions(-)
---
diff --git a/src/gtd-task-list-panel.c b/src/gtd-task-list-panel.c
index 17b3868..8d2c132 100644
--- a/src/gtd-task-list-panel.c
+++ b/src/gtd-task-list-panel.c
@@ -24,6 +24,7 @@
#include "gtd-color-button.h"
#include "gtd-debug.h"
+#include "gtd-manager.h"
#include "gtd-panel.h"
#include "gtd-provider.h"
#include "gtd-task-list.h"
@@ -375,6 +376,67 @@ gtd_task_list_panel_get_subtitle (GtdPanel *panel)
return NULL;
}
+static void
+gtd_task_list_panel_activate (GtdPanel *panel,
+ GVariant *parameters)
+{
+ GtdTaskListPanel *self;
+ GVariantDict dict;
+ GtdTaskList *list;
+ GListModel *model;
+ const gchar *task_list_id;
+ const gchar *provider_id;
+ guint i;
+
+ GTD_ENTRY;
+
+ self = GTD_TASK_LIST_PANEL (panel);
+
+ /*
+ * The task list panel must receive an a{sv} and looks for:
+ *
+ * * provider-id: the id of the provider
+ * * task-list-id: the id of the task list
+ *
+ * So it can find the task list from the GtdManager.
+ */
+
+ g_variant_dict_init (&dict, parameters);
+ g_variant_dict_lookup (&dict, "provider-id", "&s", &provider_id);
+ g_variant_dict_lookup (&dict, "task-list-id", "&s", &task_list_id);
+
+ GTD_TRACE_MSG ("Activating %s with 'provider-id': %s and 'task-list-id': %s",
+ G_OBJECT_TYPE_NAME (self),
+ provider_id,
+ task_list_id);
+
+ model = gtd_manager_get_task_lists_model (gtd_manager_get_default ());
+ list = NULL;
+
+ for (i = 0; i < g_list_model_get_n_items (model); i++)
+ {
+ g_autoptr (GtdTaskList) task_list = NULL;
+ GtdProvider *provider;
+
+ task_list = g_list_model_get_item (model, i);
+ if (g_strcmp0 (gtd_object_get_uid (GTD_OBJECT (task_list)), task_list_id) != 0)
+ continue;
+
+ provider = gtd_task_list_get_provider (task_list);
+ if (g_strcmp0 (gtd_provider_get_id (provider), provider_id) != 0)
+ return;
+
+ list = task_list;
+ break;
+ }
+
+ g_assert (list != NULL);
+
+ gtd_task_list_panel_set_task_list (self, list);
+
+ GTD_EXIT;
+}
+
static void
gtd_panel_iface_init (GtdPanelInterface *iface)
{
@@ -386,6 +448,7 @@ gtd_panel_iface_init (GtdPanelInterface *iface)
iface->get_popover = gtd_task_list_panel_get_popover;
iface->get_priority = gtd_task_list_panel_get_priority;
iface->get_subtitle = gtd_task_list_panel_get_subtitle;
+ iface->activate = gtd_task_list_panel_activate;
}
diff --git a/src/gtd-window.c b/src/gtd-window.c
index 772ed43..4de4f0f 100644
--- a/src/gtd-window.c
+++ b/src/gtd-window.c
@@ -377,6 +377,33 @@ on_active_state_changed_cb (GObject *object,
GTD_EXIT;
}
+static void
+on_action_activate_panel_activated_cb (GSimpleAction *simple,
+ GVariant *parameters,
+ gpointer user_data)
+{
+ g_autoptr (GVariant) panel_parameters = NULL;
+ g_autofree gchar *panel_id = NULL;
+ GtdWindow *self;
+ GtdPanel *panel;
+
+ self = GTD_WINDOW (user_data);
+
+ g_variant_get (parameters,
+ "(sv)",
+ &panel_id,
+ &panel_parameters);
+
+ g_debug ("Activating panel '%s'", panel_id);
+
+ panel = (GtdPanel *) gtk_stack_get_child_by_name (self->stack, panel_id);
+ g_return_if_fail (panel && GTD_IS_PANEL (panel));
+
+ gtd_panel_activate (panel, panel_parameters);
+
+ gtk_stack_set_visible_child (self->stack, GTK_WIDGET (panel));
+}
+
static void
on_cancel_selection_button_clicked (GtkWidget *button,
GtdWindow *self)
@@ -675,8 +702,17 @@ gtd_window_class_init (GtdWindowClass *klass)
static void
gtd_window_init (GtdWindow *self)
{
+ static const GActionEntry entries[] = {
+ { "activate-panel", on_action_activate_panel_activated_cb, "(sv)" },
+ };
+
gtk_widget_init_template (GTK_WIDGET (self));
+ g_action_map_add_action_entries (G_ACTION_MAP (self),
+ entries,
+ G_N_ELEMENTS (entries),
+ self);
+
/* Task list panel */
self->task_list_panel = GTD_PANEL (gtd_task_list_panel_new ());
on_panel_added_cb (gtd_manager_get_default (), self->task_list_panel, self);
diff --git a/src/sidebar/gtd-sidebar.c b/src/sidebar/gtd-sidebar.c
index e59f5a9..512aa31 100644
--- a/src/sidebar/gtd-sidebar.c
+++ b/src/sidebar/gtd-sidebar.c
@@ -316,7 +316,11 @@ on_listbox_row_activated_cb (GtkListBox *panels_listbox,
{
GtdPanel *panel = gtd_sidebar_panel_row_get_panel (GTD_SIDEBAR_PANEL_ROW (row));
- gtk_stack_set_visible_child (self->panel_stack, GTK_WIDGET (panel));
+ gtk_widget_activate_action (GTK_WIDGET (self),
+ "win.activate-panel",
+ g_variant_new ("(sv)",
+ gtd_panel_get_panel_name (panel),
+ g_variant_new_maybe (G_VARIANT_TYPE_VARIANT, NULL)));
}
else if (GTD_IS_SIDEBAR_PROVIDER_ROW (row))
{
@@ -324,16 +328,29 @@ on_listbox_row_activated_cb (GtkListBox *panels_listbox,
}
else if (GTD_IS_SIDEBAR_LIST_ROW (row))
{
- GtdTaskList *list = gtd_sidebar_list_row_get_task_list (GTD_SIDEBAR_LIST_ROW (row));
-
- /*
- * First, update the tasklist. This must be done before changing the
- * stack's visible child, otherwise we hit an assertion failure.
- */
- gtd_task_list_panel_set_task_list (GTD_TASK_LIST_PANEL (self->task_list_panel), list);
-
- /* Show the task list panel */
- gtk_stack_set_visible_child (self->panel_stack, GTK_WIDGET (self->task_list_panel));
+ g_autoptr (GVariant) panel_params = NULL;
+ GVariantBuilder builder;
+ GtdProvider *provider;
+ GtdTaskList *list;
+
+ list = gtd_sidebar_list_row_get_task_list (GTD_SIDEBAR_LIST_ROW (row));
+ provider = gtd_task_list_get_provider (list);
+
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
+ g_variant_builder_add (&builder, "{sv}",
+ "provider-id",
+ g_variant_new_string (gtd_provider_get_id (provider)));
+ g_variant_builder_add (&builder, "{sv}",
+ "task-list-id",
+ g_variant_new_string (gtd_object_get_uid (GTD_OBJECT (list))));
+
+ panel_params = g_variant_new ("(sv)",
+ "task-list-panel",
+ g_variant_builder_end (&builder));
+
+ gtk_widget_activate_action (GTK_WIDGET (self),
+ "win.activate-panel",
+ g_steal_pointer (&panel_params));
}
else if (row == self->archive_row)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]