Commit 9d95d659 authored by Daniel Buch Hansen's avatar Daniel Buch Hansen Committed by Christian Hergert
Browse files

gui: bridge GApplication.open signal to IdeApplicationAddin.open

This adds a new vfunc for application addins to open files and wires up
the GApplication.open callback to dispatch the signal to addins.
parent 1eec5434
......@@ -84,6 +84,32 @@ ide_application_addin_activate (IdeApplicationAddin *self,
IDE_APPLICATION_ADDIN_GET_IFACE (self)->activate (self, application);
}
/**
* ide_application_addin_open:
* @self: a #IdeApplicationAddin
* @application: an #ideApplication
* @files: an array of #GFile
* @n_files: number of #GFile elements in @files
* @hint: hint
*
* This function is activated when the #GApplication::open signal is emitted.
*
* Since: 3.32
*/
void
ide_application_addin_open (IdeApplicationAddin *self,
IdeApplication *application,
GFile **files,
gint n_files,
const gchar *hint)
{
g_return_if_fail (IDE_IS_APPLICATION_ADDIN (self));
g_return_if_fail (IDE_IS_APPLICATION (application));
if (IDE_APPLICATION_ADDIN_GET_IFACE (self)->open)
IDE_APPLICATION_ADDIN_GET_IFACE (self)->open (self, application, files, n_files, hint);
}
/**
* ide_application_addin_load:
* @self: An #IdeApplicationAddin.
......
......@@ -55,6 +55,11 @@ struct _IdeApplicationAddinInterface
IdeApplication *application);
void (*activate) (IdeApplicationAddin *self,
IdeApplication *application);
void (*open) (IdeApplicationAddin *self,
IdeApplication *application,
GFile **files,
gint n_files,
const gchar *hint);
void (*add_option_entries) (IdeApplicationAddin *self,
IdeApplication *application);
void (*handle_command_line) (IdeApplicationAddin *self,
......@@ -66,6 +71,12 @@ struct _IdeApplicationAddinInterface
IdeWorkbench *workbench);
};
IDE_AVAILABLE_IN_3_32
void ide_application_addin_open (IdeApplicationAddin *self,
IdeApplication *application,
GFile **files,
gint n_files,
const gchar *hint);
IDE_AVAILABLE_IN_3_32
void ide_application_addin_activate (IdeApplicationAddin *self,
IdeApplication *application);
......
......@@ -43,6 +43,14 @@ G_DEFINE_TYPE (IdeApplication, ide_application, DZL_TYPE_APPLICATION)
#define IS_UI_PROCESS(app) ((app)->type == NULL)
typedef struct
{
IdeApplication *self;
GFile **files;
gint n_files;
const gchar *hint;
} OpenData;
static void
ide_application_add_platform_data (GApplication *app,
GVariantBuilder *builder)
......@@ -270,6 +278,53 @@ ide_application_activate (GApplication *app)
IDE_EXIT;
}
static void
ide_application_open_cb (PeasExtensionSet *set,
PeasPluginInfo *plugin_info,
PeasExtension *exten,
gpointer user_data)
{
IdeApplicationAddin *app_addin = (IdeApplicationAddin*) exten;
OpenData *data = user_data;
g_assert (PEAS_IS_EXTENSION_SET (set));
g_assert (plugin_info != NULL);
g_assert (IDE_IS_APPLICATION_ADDIN (app_addin));
g_assert (data != NULL);
g_assert (IDE_IS_APPLICATION (data->self));
g_assert (data->files != NULL);
ide_application_addin_open (app_addin, data->self, data->files, data->n_files, data->hint);
}
static void
ide_application_open (GApplication *app,
GFile **files,
gint n_files,
const gchar *hint)
{
IdeApplication *self = (IdeApplication*)app;
OpenData data;
IDE_ENTRY;
g_assert (IDE_IS_MAIN_THREAD ());
g_assert (IDE_IS_APPLICATION (self));
g_assert (files);
g_assert (n_files > 0);
g_assert (hint);
data.self = self;
data.files = files;
data.n_files = n_files;
data.hint = hint;
if (self->addins != NULL)
peas_extension_set_foreach (self->addins, ide_application_open_cb, &data);
IDE_EXIT;
}
static void
ide_application_dispose (GObject *object)
{
......@@ -305,6 +360,7 @@ ide_application_class_init (IdeApplicationClass *klass)
object_class->dispose = ide_application_dispose;
app_class->activate = ide_application_activate;
app_class->open = ide_application_open;
app_class->add_platform_data = ide_application_add_platform_data;
app_class->command_line = ide_application_command_line;
app_class->local_command_line = ide_application_local_command_line;
......@@ -340,7 +396,7 @@ _ide_application_new (gboolean standalone,
const gchar *plugin,
const gchar *dbus_address)
{
GApplicationFlags flags = G_APPLICATION_HANDLES_COMMAND_LINE;
GApplicationFlags flags = G_APPLICATION_HANDLES_COMMAND_LINE | G_APPLICATION_HANDLES_OPEN;
IdeApplication *self;
if (standalone || ide_str_equal0 (type, "worker"))
......
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