workspace: Add parameters to activation

So that workspaces can pass any kind of data to other
workspaces. The input is purposely left undefined.
parent 32c18796
......@@ -76,6 +76,7 @@ struct _GtdWindow
GtdWorkspace *current_workspace;
GListStore *workspaces;
GVariant *parameters;
PeasExtensionSet *workspaces_set;
......@@ -257,11 +258,15 @@ on_action_activate_workspace_activated_cb (GSimpleAction *simple,
GVariant *state,
gpointer user_data)
{
g_autofree gchar *workspace_id = NULL;
GtdWindow *self;
const gchar *workspace_id;
self = GTD_WINDOW (user_data);
workspace_id = g_variant_get_string (state, NULL);
g_variant_get (state,
"(sv)",
&workspace_id,
&self->parameters,
NULL);
gtk_stack_set_visible_child_name (self->stack, workspace_id);
}
......@@ -356,6 +361,7 @@ on_stack_visible_child_cb (GtkStack *stack,
GParamSpec *pspec,
GtdWindow *self)
{
g_autoptr (GVariant) parameters = NULL;
g_autoptr (GIcon) workspace_icon = NULL;
GtdWorkspace *new_workspace;
......@@ -372,7 +378,8 @@ on_stack_visible_child_cb (GtkStack *stack,
if (!new_workspace)
GTD_RETURN ();
gtd_workspace_activate (new_workspace);
parameters = g_steal_pointer (&self->parameters);
gtd_workspace_activate (new_workspace, parameters);
workspace_icon = gtd_workspace_get_icon (new_workspace);
gtd_menu_button_set_gicon (self->workspaces_menu_button, workspace_icon);
......@@ -620,7 +627,7 @@ static void
gtd_window_init (GtdWindow *self)
{
static const GActionEntry entries[] = {
{ "activate-workspace", on_action_activate_workspace_activated_cb, "s" },
{ "activate-workspace", on_action_activate_workspace_activated_cb, "(sv)" },
{ "toggle-fullscreen", NULL, NULL, "false", on_action_toggle_fullscreen_state_changed_cb },
};
......
......@@ -125,17 +125,19 @@ gtd_workspace_get_icon (GtdWorkspace *self)
/**
* gtd_workspace_activate:
* @self: a #GtdWorkspace
* @parameters: (nullable): workspace-specific parameters
*
* Activates @self. This happens when the workspace
* becomes the active workspace in the main window.
*/
void
gtd_workspace_activate (GtdWorkspace *self)
gtd_workspace_activate (GtdWorkspace *self,
GVariant *parameters)
{
g_return_if_fail (GTD_IS_WORKSPACE (self));
if (GTD_WORKSPACE_GET_IFACE (self)->activate)
GTD_WORKSPACE_GET_IFACE (self)->activate (self);
GTD_WORKSPACE_GET_IFACE (self)->activate (self, parameters);
}
/**
......
......@@ -39,7 +39,8 @@ struct _GtdWorkspaceInterface
GIcon* (*get_icon) (GtdWorkspace *self);
void (*activate) (GtdWorkspace *self);
void (*activate) (GtdWorkspace *self,
GVariant *parameters);
void (*deactivate) (GtdWorkspace *self);
};
......@@ -52,7 +53,8 @@ gint gtd_workspace_get_priority (GtdWorkspace
GIcon* gtd_workspace_get_icon (GtdWorkspace *self);
void gtd_workspace_activate (GtdWorkspace *self);
void gtd_workspace_activate (GtdWorkspace *self,
GVariant *parameters);
void gtd_workspace_deactivate (GtdWorkspace *self);
......
......@@ -316,7 +316,8 @@ gtd_task_lists_workspace_get_icon (GtdWorkspace *workspace)
}
static void
gtd_task_lists_workspace_activate (GtdWorkspace *workspace)
gtd_task_lists_workspace_activate (GtdWorkspace *workspace,
GVariant *parameters)
{
GtdTaskListsWorkspace *self = GTD_TASK_LISTS_WORKSPACE (workspace);
GtdWindow *window = GTD_WINDOW (gtk_widget_get_root (GTK_WIDGET (self)));
......@@ -324,7 +325,17 @@ gtd_task_lists_workspace_activate (GtdWorkspace *workspace)
gtd_window_embed_widget_in_header (window, self->start_box, GTK_POS_LEFT);
gtd_window_embed_widget_in_header (window, self->end_box, GTK_POS_RIGHT);
gtd_sidebar_activate (self->sidebar);
if (parameters)
{
const gchar *panel_id = g_variant_get_string (parameters, NULL);
g_debug ("Activating panel '%s'", panel_id);
gtk_stack_set_visible_child_name (self->stack, panel_id);
}
else
{
gtd_sidebar_activate (self->sidebar);
}
}
static void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment