[gnome-builder] devhelp: fix "New documentation page" activation
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] devhelp: fix "New documentation page" activation
- Date: Wed, 9 Aug 2017 22:12:13 +0000 (UTC)
commit b0bc434f3282c850cf6c2cce41e1f5a634e80c27
Author: Christian Hergert <chergert redhat com>
Date: Wed Aug 9 15:10:55 2017 -0700
devhelp: fix "New documentation page" activation
This wasn't available previously because the action was tied to the layout
stack (so we can ensure it ends up in the right stack).
This just adds a new action to the "win" action prefix so that we can
activate it from anywhere in the application.
plugins/devhelp/gbp-devhelp-editor-addin.c | 111 ++++++++++++++++++++++++++++
plugins/devhelp/gbp-devhelp-editor-addin.h | 29 +++++++
plugins/devhelp/gbp-devhelp-plugin.c | 4 +
plugins/devhelp/gtk/menus.ui | 2 +-
plugins/devhelp/meson.build | 3 +-
5 files changed, 147 insertions(+), 2 deletions(-)
---
diff --git a/plugins/devhelp/gbp-devhelp-editor-addin.c b/plugins/devhelp/gbp-devhelp-editor-addin.c
new file mode 100644
index 0000000..9e0e0fe
--- /dev/null
+++ b/plugins/devhelp/gbp-devhelp-editor-addin.c
@@ -0,0 +1,111 @@
+/* gbp-devhelp-editor-addin.c
+ *
+ * Copyright (C) 2017 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/>.
+ */
+
+#define G_LOG_DOMAIN "gbp-devhelp-editor-addin"
+
+#include "gbp-devhelp-editor-addin.h"
+#include "gbp-devhelp-view.h"
+
+struct _GbpDevhelpEditorAddin
+{
+ GObject parent_instance;
+ IdeEditorPerspective *editor;
+};
+
+static void
+gbp_devhelp_editor_addin_new_devhelp_view (GSimpleAction *action,
+ GVariant *variant,
+ gpointer user_data)
+{
+ GbpDevhelpEditorAddin *self = user_data;
+ IdeLayoutGrid *grid;
+ GtkWidget *view;
+
+ g_assert (G_IS_SIMPLE_ACTION (action));
+ g_assert (GBP_IS_DEVHELP_EDITOR_ADDIN (self));
+ g_assert (self->editor != NULL);
+
+ view = g_object_new (GBP_TYPE_DEVHELP_VIEW,
+ "visible", TRUE,
+ NULL);
+ grid = ide_editor_perspective_get_grid (self->editor);
+ gtk_container_add (GTK_CONTAINER (grid), view);
+}
+
+static GActionEntry actions[] = {
+ { "new-devhelp-view", gbp_devhelp_editor_addin_new_devhelp_view },
+};
+
+static void
+gbp_devhelp_editor_addin_load (IdeEditorAddin *addin,
+ IdeEditorPerspective *editor)
+{
+ GbpDevhelpEditorAddin *self = (GbpDevhelpEditorAddin *)addin;
+ GtkWidget *win;
+
+ g_assert (GBP_IS_DEVHELP_EDITOR_ADDIN (self));
+ g_assert (IDE_IS_EDITOR_PERSPECTIVE (editor));
+
+ self->editor = editor;
+
+ win = gtk_widget_get_ancestor (GTK_WIDGET (editor), GTK_TYPE_WINDOW);
+
+ if (G_IS_ACTION_MAP (win))
+ g_action_map_add_action_entries (G_ACTION_MAP (win), actions, G_N_ELEMENTS (actions), self);
+}
+
+static void
+gbp_devhelp_editor_addin_unload (IdeEditorAddin *addin,
+ IdeEditorPerspective *editor)
+{
+ GbpDevhelpEditorAddin *self = (GbpDevhelpEditorAddin *)addin;
+ GtkWidget *win;
+
+ g_assert (GBP_IS_DEVHELP_EDITOR_ADDIN (self));
+ g_assert (IDE_IS_EDITOR_PERSPECTIVE (editor));
+
+ win = gtk_widget_get_ancestor (GTK_WIDGET (editor), GTK_TYPE_WINDOW);
+
+ if (G_IS_ACTION_MAP (win))
+ {
+ for (guint i = 0; i < G_N_ELEMENTS (actions); i++)
+ g_action_map_remove_action (G_ACTION_MAP (win), actions[i].name);
+ }
+
+ self->editor = NULL;
+}
+
+static void
+editor_addin_iface_init (IdeEditorAddinInterface *iface)
+{
+ iface->load = gbp_devhelp_editor_addin_load;
+ iface->unload = gbp_devhelp_editor_addin_unload;
+}
+
+G_DEFINE_TYPE_WITH_CODE (GbpDevhelpEditorAddin, gbp_devhelp_editor_addin, G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (IDE_TYPE_EDITOR_ADDIN, editor_addin_iface_init))
+
+static void
+gbp_devhelp_editor_addin_class_init (GbpDevhelpEditorAddinClass *klass)
+{
+}
+
+static void
+gbp_devhelp_editor_addin_init (GbpDevhelpEditorAddin *self)
+{
+}
diff --git a/plugins/devhelp/gbp-devhelp-editor-addin.h b/plugins/devhelp/gbp-devhelp-editor-addin.h
new file mode 100644
index 0000000..764a930
--- /dev/null
+++ b/plugins/devhelp/gbp-devhelp-editor-addin.h
@@ -0,0 +1,29 @@
+/* gbp-devhelp-editor-addin.h
+ *
+ * Copyright (C) 2017 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/>.
+ */
+
+#pragma once
+
+#include <ide.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_DEVHELP_EDITOR_ADDIN (gbp_devhelp_editor_addin_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpDevhelpEditorAddin, gbp_devhelp_editor_addin, GBP, DEVHELP_EDITOR_ADDIN, GObject)
+
+G_END_DECLS
diff --git a/plugins/devhelp/gbp-devhelp-plugin.c b/plugins/devhelp/gbp-devhelp-plugin.c
index 272453c..c0e9f67 100644
--- a/plugins/devhelp/gbp-devhelp-plugin.c
+++ b/plugins/devhelp/gbp-devhelp-plugin.c
@@ -19,6 +19,7 @@
#include <ide.h>
#include <libpeas/peas.h>
+#include "gbp-devhelp-editor-addin.h"
#include "gbp-devhelp-editor-view-addin.h"
#include "gbp-devhelp-layout-stack-addin.h"
@@ -26,6 +27,9 @@ void
peas_register_types (PeasObjectModule *module)
{
peas_object_module_register_extension_type (module,
+ IDE_TYPE_EDITOR_ADDIN,
+ GBP_TYPE_DEVHELP_EDITOR_ADDIN);
+ peas_object_module_register_extension_type (module,
IDE_TYPE_EDITOR_VIEW_ADDIN,
GBP_TYPE_DEVHELP_EDITOR_VIEW_ADDIN);
peas_object_module_register_extension_type (module,
diff --git a/plugins/devhelp/gtk/menus.ui b/plugins/devhelp/gtk/menus.ui
index c5a4e82..0594ead 100644
--- a/plugins/devhelp/gtk/menus.ui
+++ b/plugins/devhelp/gtk/menus.ui
@@ -19,7 +19,7 @@
<attribute name="id">new-documentation-page</attribute>
<attribute name="after">new-file</attribute>
<attribute name="label" translatable="yes">New Documentation Page</attribute>
- <attribute name="action">devhelp.new-view</attribute>
+ <attribute name="action">win.new-devhelp-view</attribute>
</item>
</section>
</menu>
diff --git a/plugins/devhelp/meson.build b/plugins/devhelp/meson.build
index 45e8e4b..286234e 100644
--- a/plugins/devhelp/meson.build
+++ b/plugins/devhelp/meson.build
@@ -11,7 +11,8 @@ devhelp_sources = [
'gbp-devhelp-menu-button.h',
'gbp-devhelp-layout-stack-addin.c',
'gbp-devhelp-layout-stack-addin.h',
-
+ 'gbp-devhelp-editor-addin.c',
+ 'gbp-devhelp-editor-addin.h',
'gbp-devhelp-editor-view-addin.c',
'gbp-devhelp-editor-view-addin.h',
'gbp-devhelp-plugin.c',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]