Commit 32573cca authored by Christian Hergert's avatar Christian Hergert
Browse files

workbench: notify changes to current perspective

This allows workbench addins to be notified when the current perspective
has changed. This might be useful when we move to a unified headerbar so
that the addins can enable/disable features.
parent 83671d1a
......@@ -22,6 +22,12 @@
G_DEFINE_INTERFACE (IdeWorkbenchAddin, ide_workbench_addin, G_TYPE_OBJECT)
static void
ide_workbench_addin_real_perspective_set (IdeWorkbenchAddin *self,
IdePerspective *perspective)
{
}
static gchar *
ide_workbench_addin_real_get_id (IdeWorkbenchAddin *self)
{
......@@ -57,6 +63,7 @@ ide_workbench_addin_default_init (IdeWorkbenchAddinInterface *iface)
iface->get_id = ide_workbench_addin_real_get_id;
iface->load = ide_workbench_addin_real_load;
iface->unload = ide_workbench_addin_real_unload;
iface->perspective_set = ide_workbench_addin_real_perspective_set;
}
/**
......@@ -188,3 +195,23 @@ ide_workbench_addin_get_id (IdeWorkbenchAddin *self)
return IDE_WORKBENCH_ADDIN_GET_IFACE (self)->get_id (self);
}
/**
* ide_workbench_addin_perspective_set:
* @self: an #IdeWorkbenchAddin
* @perspective: An #IdePerspective
*
* This function is called when the workbench changes the perspective.
*
* Addins that wish to add buttons to the header bar may want to show or
* hide the widgets in this vfunc.
*/
void
ide_workbench_addin_perspective_set (IdeWorkbenchAddin *self,
IdePerspective *perspective)
{
g_return_if_fail (IDE_IS_WORKBENCH_ADDIN (self));
g_return_if_fail (IDE_IS_PERSPECTIVE (perspective));
IDE_WORKBENCH_ADDIN_GET_IFACE (self)->perspective_set (self, perspective);
}
......@@ -19,6 +19,7 @@
#ifndef IDE_WORKBENCH_ADDIN_H
#define IDE_WORKBENCH_ADDIN_H
#include "ide-perspective.h"
#include "ide-uri.h"
#include "ide-workbench.h"
......@@ -32,45 +33,48 @@ struct _IdeWorkbenchAddinInterface
{
GTypeInterface parent;
gchar *(*get_id) (IdeWorkbenchAddin *self);
void (*load) (IdeWorkbenchAddin *self,
IdeWorkbench *workbench);
void (*unload) (IdeWorkbenchAddin *self,
IdeWorkbench *workbench);
gboolean (*can_open) (IdeWorkbenchAddin *self,
IdeUri *uri,
const gchar *content_type,
gint *priority);
void (*open_async) (IdeWorkbenchAddin *self,
IdeUri *uri,
const gchar *content_type,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean (*open_finish) (IdeWorkbenchAddin *self,
GAsyncResult *result,
GError **error);
gchar *(*get_id) (IdeWorkbenchAddin *self);
void (*load) (IdeWorkbenchAddin *self,
IdeWorkbench *workbench);
void (*unload) (IdeWorkbenchAddin *self,
IdeWorkbench *workbench);
gboolean (*can_open) (IdeWorkbenchAddin *self,
IdeUri *uri,
const gchar *content_type,
gint *priority);
void (*open_async) (IdeWorkbenchAddin *self,
IdeUri *uri,
const gchar *content_type,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean (*open_finish) (IdeWorkbenchAddin *self,
GAsyncResult *result,
GError **error);
void (*perspective_set) (IdeWorkbenchAddin *self,
IdePerspective *perspective);
};
gchar *ide_workbench_addin_get_id (IdeWorkbenchAddin *self);
void ide_workbench_addin_load (IdeWorkbenchAddin *self,
IdeWorkbench *workbench);
void ide_workbench_addin_unload (IdeWorkbenchAddin *self,
IdeWorkbench *workbench);
gboolean ide_workbench_addin_can_open (IdeWorkbenchAddin *self,
IdeUri *uri,
const gchar *content_type,
gint *priority);
void ide_workbench_addin_open_async (IdeWorkbenchAddin *self,
IdeUri *uri,
const gchar *content_type,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean ide_workbench_addin_open_finish (IdeWorkbenchAddin *self,
GAsyncResult *result,
GError **error);
gchar *ide_workbench_addin_get_id (IdeWorkbenchAddin *self);
void ide_workbench_addin_load (IdeWorkbenchAddin *self,
IdeWorkbench *workbench);
void ide_workbench_addin_unload (IdeWorkbenchAddin *self,
IdeWorkbench *workbench);
gboolean ide_workbench_addin_can_open (IdeWorkbenchAddin *self,
IdeUri *uri,
const gchar *content_type,
gint *priority);
void ide_workbench_addin_open_async (IdeWorkbenchAddin *self,
IdeUri *uri,
const gchar *content_type,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean ide_workbench_addin_open_finish (IdeWorkbenchAddin *self,
GAsyncResult *result,
GError **error);
void ide_workbench_addin_perspective_set (IdeWorkbenchAddin *self,
IdePerspective *perspective);
G_END_DECLS
......
......@@ -750,6 +750,23 @@ remove_early_perspectives (gpointer data)
return G_SOURCE_REMOVE;
}
static void
ide_workbench_notify_perspective_set (PeasExtensionSet *set,
PeasPluginInfo *plugin_info,
PeasExtension *exten,
gpointer user_data)
{
IdeWorkbenchAddin *addin = (IdeWorkbenchAddin *)exten;
IdeWorkbench *self = user_data;
g_assert (IDE_IS_WORKBENCH (self));
g_assert (PEAS_IS_EXTENSION_SET (set));
g_assert (plugin_info != NULL);
g_assert (IDE_IS_WORKBENCH_ADDIN (addin));
ide_workbench_addin_perspective_set (addin, self->perspective);
}
void
ide_workbench_set_visible_perspective (IdeWorkbench *self,
IdePerspective *perspective)
......@@ -784,6 +801,11 @@ ide_workbench_set_visible_perspective (IdeWorkbench *self,
remove_early_perspectives,
g_object_ref (self));
}
if (self->addins != NULL)
peas_extension_set_foreach (self->addins,
ide_workbench_notify_perspective_set,
self);
}
const gchar *
......
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