[gnome-builder] shellcmd: add application addin to manage model load/save
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] shellcmd: add application addin to manage model load/save
- Date: Thu, 8 Aug 2019 20:17:19 +0000 (UTC)
commit 3f3ea90331d6a567caa4d0a3e761b9df7129786a
Author: Christian Hergert <chergert redhat com>
Date: Thu Aug 8 13:13:31 2019 -0700
shellcmd: add application addin to manage model load/save
.../shellcmd/gbp-shellcmd-application-addin.c | 91 ++++++++++++++++++++++
.../shellcmd/gbp-shellcmd-application-addin.h | 35 +++++++++
src/plugins/shellcmd/meson.build | 1 +
src/plugins/shellcmd/shellcmd-plugin.c | 4 +
4 files changed, 131 insertions(+)
---
diff --git a/src/plugins/shellcmd/gbp-shellcmd-application-addin.c
b/src/plugins/shellcmd/gbp-shellcmd-application-addin.c
new file mode 100644
index 000000000..364feb022
--- /dev/null
+++ b/src/plugins/shellcmd/gbp-shellcmd-application-addin.c
@@ -0,0 +1,91 @@
+/* gbp-shellcmd-application-addin.c
+ *
+ * Copyright 2019 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "gbp-shellcmd-application-addin"
+
+#include "config.h"
+
+#include "gbp-shellcmd-application-addin.h"
+
+struct _GbpShellcmdApplicationAddin
+{
+ GObject parent_instance;
+ GbpShellcmdCommandModel *model;
+};
+
+GbpShellcmdCommandModel *
+gbp_shellcmd_application_addin_get_model (GbpShellcmdApplicationAddin *self)
+{
+ g_return_val_if_fail (GBP_IS_SHELLCMD_APPLICATION_ADDIN (self), NULL);
+
+ return self->model;
+}
+
+static void
+gbp_shellcmd_application_addin_load (IdeApplicationAddin *addin,
+ IdeApplication *app)
+{
+ GbpShellcmdApplicationAddin *self = (GbpShellcmdApplicationAddin *)addin;
+ g_autoptr(GError) error = NULL;
+
+ g_assert (GBP_IS_SHELLCMD_APPLICATION_ADDIN (self));
+ g_assert (IDE_IS_APPLICATION (app));
+
+ self->model = gbp_shellcmd_command_model_new ();
+
+ if (!gbp_shellcmd_command_model_load (self->model, NULL, &error))
+ g_warning ("Failed to load external-commands: %s", error->message);
+}
+
+static void
+gbp_shellcmd_application_addin_unload (IdeApplicationAddin *addin,
+ IdeApplication *app)
+{
+ GbpShellcmdApplicationAddin *self = (GbpShellcmdApplicationAddin *)addin;
+ g_autoptr(GError) error = NULL;
+
+ g_assert (GBP_IS_SHELLCMD_APPLICATION_ADDIN (self));
+ g_assert (IDE_IS_APPLICATION (app));
+
+ if (!gbp_shellcmd_command_model_save (self->model, NULL, &error))
+ g_warning ("Failed to save external-commands: %s", error->message);
+
+ g_clear_object (&self->model);
+}
+
+static void
+app_addin_iface_init (IdeApplicationAddinInterface *iface)
+{
+ iface->load = gbp_shellcmd_application_addin_load;
+ iface->unload = gbp_shellcmd_application_addin_unload;
+}
+
+G_DEFINE_TYPE_WITH_CODE (GbpShellcmdApplicationAddin, gbp_shellcmd_application_addin, G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (IDE_TYPE_APPLICATION_ADDIN, app_addin_iface_init))
+
+static void
+gbp_shellcmd_application_addin_class_init (GbpShellcmdApplicationAddinClass *klass)
+{
+}
+
+static void
+gbp_shellcmd_application_addin_init (GbpShellcmdApplicationAddin *self)
+{
+}
diff --git a/src/plugins/shellcmd/gbp-shellcmd-application-addin.h
b/src/plugins/shellcmd/gbp-shellcmd-application-addin.h
new file mode 100644
index 000000000..dc29e3132
--- /dev/null
+++ b/src/plugins/shellcmd/gbp-shellcmd-application-addin.h
@@ -0,0 +1,35 @@
+/* gbp-shellcmd-application-addin.h
+ *
+ * Copyright 2019 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <libide-gui.h>
+
+#include "gbp-shellcmd-command-model.h"
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_SHELLCMD_APPLICATION_ADDIN (gbp_shellcmd_application_addin_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpShellcmdApplicationAddin, gbp_shellcmd_application_addin, GBP,
SHELLCMD_APPLICATION_ADDIN, GObject)
+
+GbpShellcmdCommandModel *gbp_shellcmd_application_addin_get_model (GbpShellcmdApplicationAddin *self);
+
+G_END_DECLS
diff --git a/src/plugins/shellcmd/meson.build b/src/plugins/shellcmd/meson.build
index d0d77039f..a00a0e8ca 100644
--- a/src/plugins/shellcmd/meson.build
+++ b/src/plugins/shellcmd/meson.build
@@ -2,6 +2,7 @@ if get_option('plugin_shellcmd')
plugins_sources += files([
'shellcmd-plugin.c',
+ 'gbp-shellcmd-application-addin.c',
'gbp-shellcmd-command.c',
'gbp-shellcmd-command-model.c',
'gbp-shellcmd-command-provider.c',
diff --git a/src/plugins/shellcmd/shellcmd-plugin.c b/src/plugins/shellcmd/shellcmd-plugin.c
index fe4f15a28..0f316a265 100644
--- a/src/plugins/shellcmd/shellcmd-plugin.c
+++ b/src/plugins/shellcmd/shellcmd-plugin.c
@@ -23,11 +23,15 @@
#include <libide-gui.h>
#include <libpeas/peas.h>
+#include "gbp-shellcmd-application-addin.h"
#include "gbp-shellcmd-command-provider.h"
_IDE_EXTERN void
_gbp_shellcmd_register_types (PeasObjectModule *module)
{
+ peas_object_module_register_extension_type (module,
+ IDE_TYPE_APPLICATION_ADDIN,
+ GBP_TYPE_SHELLCMD_APPLICATION_ADDIN);
peas_object_module_register_extension_type (module,
IDE_TYPE_COMMAND_PROVIDER,
GBP_TYPE_SHELLCMD_COMMAND_PROVIDER);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]