[gnome-builder/wip/chergert/dspy] dspy: add dedicated dspy workspace



commit 9b3989d8ff1a21447a357c0654c9993cc91d60b9
Author: Christian Hergert <chergert redhat com>
Date:   Fri Apr 12 14:42:10 2019 -0700

    dspy: add dedicated dspy workspace

 data/org.gnome.Builder.desktop.in.in          |   4 +
 src/plugins/dspy/dspy-plugin.c                |   5 +
 src/plugins/dspy/dspy.gresource.xml           |   1 +
 src/plugins/dspy/dspy.plugin                  |   1 +
 src/plugins/dspy/gbp-dspy-application-addin.c | 163 ++++++++++++++++++++++++++
 src/plugins/dspy/gbp-dspy-application-addin.h |  31 +++++
 src/plugins/dspy/gbp-dspy-workspace.c         |  61 ++++++++++
 src/plugins/dspy/gbp-dspy-workspace.h         |  33 ++++++
 src/plugins/dspy/gbp-dspy-workspace.ui        |  28 +++++
 src/plugins/dspy/meson.build                  |   2 +
 10 files changed, 329 insertions(+)
---
diff --git a/data/org.gnome.Builder.desktop.in.in b/data/org.gnome.Builder.desktop.in.in
index 87a592a31..caa25919c 100644
--- a/data/org.gnome.Builder.desktop.in.in
+++ b/data/org.gnome.Builder.desktop.in.in
@@ -30,3 +30,7 @@ Exec=gnome-builder --clone
 [Desktop Action new-editor]
 Name=New Editor Workspace
 Exec=gnome-builder --editor
+
+[Desktop Action dspy]
+Name=DBus Inspector
+Exec=gnome-builder --dspy
diff --git a/src/plugins/dspy/dspy-plugin.c b/src/plugins/dspy/dspy-plugin.c
index 85bd90efc..9f85e75f1 100644
--- a/src/plugins/dspy/dspy-plugin.c
+++ b/src/plugins/dspy/dspy-plugin.c
@@ -20,14 +20,19 @@
 
 #include "config.h"
 
+#include <libide-gui.h>
 #include <libide-editor.h>
 #include <libpeas/peas.h>
 
+#include "gbp-dspy-application-addin.h"
 #include "gbp-dspy-workspace-addin.h"
 
 _IDE_EXTERN void
 _gbp_dspy_register_types (PeasObjectModule *module)
 {
+  peas_object_module_register_extension_type (module,
+                                              IDE_TYPE_APPLICATION_ADDIN,
+                                              GBP_TYPE_DSPY_APPLICATION_ADDIN);
   peas_object_module_register_extension_type (module,
                                               IDE_TYPE_WORKSPACE_ADDIN,
                                               GBP_TYPE_DSPY_WORKSPACE_ADDIN);
diff --git a/src/plugins/dspy/dspy.gresource.xml b/src/plugins/dspy/dspy.gresource.xml
index 0f8c29e72..fc9dd987b 100644
--- a/src/plugins/dspy/dspy.gresource.xml
+++ b/src/plugins/dspy/dspy.gresource.xml
@@ -6,5 +6,6 @@
     <file preprocess="xml-stripblanks">dspy-name-row.ui</file>
     <file preprocess="xml-stripblanks">dspy-name-view.ui</file>
     <file preprocess="xml-stripblanks">gbp-dspy-surface.ui</file>
+    <file preprocess="xml-stripblanks">gbp-dspy-workspace.ui</file>
   </gresource>
 </gresources>
diff --git a/src/plugins/dspy/dspy.plugin b/src/plugins/dspy/dspy.plugin
index b98a209a9..5f341dbe9 100644
--- a/src/plugins/dspy/dspy.plugin
+++ b/src/plugins/dspy/dspy.plugin
@@ -7,3 +7,4 @@ Embedded=_gbp_dspy_register_types
 Module=dspy
 Name=DBus Connection Explorer
 X-Workspace-Kind=primary;editor;
+X-At-Startup=true
diff --git a/src/plugins/dspy/gbp-dspy-application-addin.c b/src/plugins/dspy/gbp-dspy-application-addin.c
new file mode 100644
index 000000000..0f274e707
--- /dev/null
+++ b/src/plugins/dspy/gbp-dspy-application-addin.c
@@ -0,0 +1,163 @@
+/* gbp-dspy-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-dspy-application-addin"
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+
+#include "gbp-dspy-application-addin.h"
+#include "gbp-dspy-workspace.h"
+
+struct _GbpDspyApplicationAddin
+{
+  GObject parent_instance;
+};
+
+static void
+gbp_dspy_application_addin_add_option_entries (IdeApplicationAddin *addin,
+                                               IdeApplication      *app)
+{
+  g_assert (GBP_IS_DSPY_APPLICATION_ADDIN (addin));
+  g_assert (G_IS_APPLICATION (app));
+
+  g_application_add_main_option (G_APPLICATION (app),
+                                 "dspy",
+                                 0,
+                                 G_OPTION_FLAG_IN_MAIN,
+                                 G_OPTION_ARG_NONE,
+                                 _("Display DBus inspector"),
+                                 NULL);
+}
+
+static void
+gbp_dspy_application_addin_handle_command_line (IdeApplicationAddin     *addin,
+                                                IdeApplication          *application,
+                                                GApplicationCommandLine *cmdline)
+{
+  IdeApplication *app = (IdeApplication *)application;
+  GVariantDict *options;
+
+  g_assert (IDE_IS_APPLICATION_ADDIN (addin));
+  g_assert (IDE_IS_APPLICATION (app));
+  g_assert (G_IS_APPLICATION_COMMAND_LINE (cmdline));
+
+  if ((options = g_application_command_line_get_options_dict (cmdline)) &&
+      g_variant_dict_contains (options, "dspy"))
+    {
+      g_autoptr(IdeWorkbench) workbench = NULL;
+      g_autoptr(GFile) workdir = NULL;
+      GbpDspyWorkspace *workspace;
+      IdeContext *context;
+
+      workbench = ide_workbench_new ();
+      ide_application_add_workbench (app, workbench);
+
+      context = ide_workbench_get_context (workbench);
+
+      workdir = g_application_command_line_create_file_for_arg (cmdline, ".");
+      ide_context_set_workdir (context, workdir);
+
+      workspace = gbp_dspy_workspace_new (application);
+      ide_workbench_add_workspace (workbench, IDE_WORKSPACE (workspace));
+      ide_workbench_focus_workspace (workbench, IDE_WORKSPACE (workspace));
+
+      ide_application_set_command_line_handled (application, cmdline, TRUE);
+    }
+}
+
+static void
+dspy_action_cb (GSimpleAction *action,
+                GVariant      *param,
+                gpointer       user_data)
+{
+  g_autoptr(IdeWorkbench) workbench = NULL;
+  g_autoptr(GFile) workdir = NULL;
+  GbpDspyWorkspace *workspace;
+  IdeContext *context;
+
+  g_assert (IDE_IS_MAIN_THREAD ());
+  g_assert (GBP_IS_DSPY_APPLICATION_ADDIN (user_data));
+
+  workbench = ide_workbench_new ();
+  ide_application_add_workbench (IDE_APPLICATION_DEFAULT, workbench);
+
+  context = ide_workbench_get_context (workbench);
+
+  workdir = g_file_new_for_path (ide_get_projects_dir ());
+  ide_context_set_workdir (context, workdir);
+
+  workspace = gbp_dspy_workspace_new (IDE_APPLICATION_DEFAULT);
+  ide_workbench_add_workspace (workbench, IDE_WORKSPACE (workspace));
+  ide_workbench_focus_workspace (workbench, IDE_WORKSPACE (workspace));
+}
+
+static GActionEntry actions[] = {
+  { "dspy", dspy_action_cb },
+};
+
+static void
+gbp_dspy_application_addin_load (IdeApplicationAddin *addin,
+                                 IdeApplication      *application)
+{
+  g_assert (IDE_IS_MAIN_THREAD ());
+  g_assert (IDE_IS_APPLICATION_ADDIN (addin));
+  g_assert (IDE_IS_APPLICATION (application));
+
+  g_action_map_add_action_entries (G_ACTION_MAP (application),
+                                   actions,
+                                   G_N_ELEMENTS (actions),
+                                   addin);
+}
+
+static void
+gbp_dspy_application_addin_unload (IdeApplicationAddin *addin,
+                                   IdeApplication      *application)
+{
+  g_assert (IDE_IS_MAIN_THREAD ());
+  g_assert (IDE_IS_APPLICATION_ADDIN (addin));
+  g_assert (IDE_IS_APPLICATION (application));
+
+  for (guint i = 0; i < G_N_ELEMENTS (actions); i++)
+    g_action_map_remove_action (G_ACTION_MAP (application), actions[i].name);
+}
+
+static void
+app_addin_iface_init (IdeApplicationAddinInterface *iface)
+{
+  iface->load = gbp_dspy_application_addin_load;
+  iface->unload = gbp_dspy_application_addin_unload;
+  iface->add_option_entries = gbp_dspy_application_addin_add_option_entries;
+  iface->handle_command_line = gbp_dspy_application_addin_handle_command_line;
+}
+
+G_DEFINE_TYPE_WITH_CODE (GbpDspyApplicationAddin, gbp_dspy_application_addin, G_TYPE_OBJECT,
+                         G_IMPLEMENT_INTERFACE (IDE_TYPE_APPLICATION_ADDIN, app_addin_iface_init))
+
+static void
+gbp_dspy_application_addin_class_init (GbpDspyApplicationAddinClass *klass)
+{
+}
+
+static void
+gbp_dspy_application_addin_init (GbpDspyApplicationAddin *self)
+{
+}
diff --git a/src/plugins/dspy/gbp-dspy-application-addin.h b/src/plugins/dspy/gbp-dspy-application-addin.h
new file mode 100644
index 000000000..6086bcfff
--- /dev/null
+++ b/src/plugins/dspy/gbp-dspy-application-addin.h
@@ -0,0 +1,31 @@
+/* gbp-dspy-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>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_DSPY_APPLICATION_ADDIN (gbp_dspy_application_addin_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpDspyApplicationAddin, gbp_dspy_application_addin, GBP, DSPY_APPLICATION_ADDIN, 
GObject)
+
+G_END_DECLS
diff --git a/src/plugins/dspy/gbp-dspy-workspace.c b/src/plugins/dspy/gbp-dspy-workspace.c
new file mode 100644
index 000000000..ad7a556c9
--- /dev/null
+++ b/src/plugins/dspy/gbp-dspy-workspace.c
@@ -0,0 +1,61 @@
+/* gbp-dspy-workspace.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-dspy-workspace"
+
+#include "config.h"
+
+#include "gbp-dspy-workspace.h"
+
+struct _GbpDspyWorkspace
+{
+  IdeWorkspace  parent_instance;
+  IdeHeaderBar *header_bar;
+};
+
+G_DEFINE_TYPE (GbpDspyWorkspace, gbp_dspy_workspace, IDE_TYPE_WORKSPACE)
+
+static void
+gbp_dspy_workspace_class_init (GbpDspyWorkspaceClass *klass)
+{
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+  IdeWorkspaceClass *workspace_class = IDE_WORKSPACE_CLASS (klass);
+
+  ide_workspace_class_set_kind (workspace_class, "dspy");
+
+  gtk_widget_class_set_template_from_resource (widget_class, "/plugins/dspy/gbp-dspy-workspace.ui");
+  gtk_widget_class_bind_template_child (widget_class, GbpDspyWorkspace, header_bar);
+}
+
+static void
+gbp_dspy_workspace_init (GbpDspyWorkspace *self)
+{
+  gtk_widget_init_template (GTK_WIDGET (self));
+}
+
+GbpDspyWorkspace *
+gbp_dspy_workspace_new (IdeApplication *application)
+{
+  g_return_val_if_fail (IDE_IS_APPLICATION (application), NULL);
+
+  return g_object_new (GBP_TYPE_DSPY_WORKSPACE,
+                       "application", application,
+                       NULL);
+}
diff --git a/src/plugins/dspy/gbp-dspy-workspace.h b/src/plugins/dspy/gbp-dspy-workspace.h
new file mode 100644
index 000000000..ddf1e16a3
--- /dev/null
+++ b/src/plugins/dspy/gbp-dspy-workspace.h
@@ -0,0 +1,33 @@
+/* gbp-dspy-workspace.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>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_DSPY_WORKSPACE (gbp_dspy_workspace_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpDspyWorkspace, gbp_dspy_workspace, GBP, DSPY_WORKSPACE, IdeWorkspace)
+
+GbpDspyWorkspace *gbp_dspy_workspace_new (IdeApplication *application);
+
+G_END_DECLS
diff --git a/src/plugins/dspy/gbp-dspy-workspace.ui b/src/plugins/dspy/gbp-dspy-workspace.ui
new file mode 100644
index 000000000..95fa09274
--- /dev/null
+++ b/src/plugins/dspy/gbp-dspy-workspace.ui
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="GbpDspyWorkspace" parent="IdeWorkspace">
+    <property name="default-width">750</property>
+    <property name="default-height">450</property>
+    <child type="titlebar">
+      <object class="IdeHeaderBar" id="header_bar">
+        <property name="show-close-button">true</property>
+        <property name="show-fullscreen-button">false</property>
+        <property name="menu-id">dspy-workspace-menu</property>
+        <property name="visible">true</property>
+      </object>
+    </child>
+    <child internal-child="surfaces">
+      <object class="GtkStack" id="surfaces">
+        <property name="visible">true</property>
+        <child>
+          <object class="GbpDspySurface">
+            <property name="visible">true</property>
+          </object>
+          <packing>
+            <property name="name">dspy</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/src/plugins/dspy/meson.build b/src/plugins/dspy/meson.build
index 9962deae7..baa1c644f 100644
--- a/src/plugins/dspy/meson.build
+++ b/src/plugins/dspy/meson.build
@@ -7,7 +7,9 @@ plugins_sources += files([
   'dspy-name-row.c',
   'dspy-name-view.c',
   'dspy-path-model.c',
+  'gbp-dspy-application-addin.c',
   'gbp-dspy-surface.c',
+  'gbp-dspy-workspace.c',
   'gbp-dspy-workspace-addin.c',
 ])
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]