[gnome-builder] plugins/sysprof: drop workspace addin
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] plugins/sysprof: drop workspace addin
- Date: Fri, 29 Jul 2022 20:10:36 +0000 (UTC)
commit 50503178669b0c903a29c193a28e3f6a65d9baec
Author: Christian Hergert <chergert redhat com>
Date: Fri Jul 29 13:02:39 2022 -0700
plugins/sysprof: drop workspace addin
We can do this all with the workbench addin now and even better, it will
have actions like context.workbench.sysprof.run and
context.workbench.sysprof.open-capture.
The later action can also now be used from an editor workspace, not just
from a project workspace so you can view an existing capture easily.
src/plugins/sysprof/gbp-sysprof-workbench-addin.c | 147 +++++++++++-
src/plugins/sysprof/gbp-sysprof-workspace-addin.c | 274 ----------------------
src/plugins/sysprof/gbp-sysprof-workspace-addin.h | 31 ---
src/plugins/sysprof/gtk/keybindings.json | 2 +-
src/plugins/sysprof/gtk/menus.ui | 2 +-
src/plugins/sysprof/meson.build | 1 -
src/plugins/sysprof/sysprof-plugin.c | 4 -
7 files changed, 136 insertions(+), 325 deletions(-)
---
diff --git a/src/plugins/sysprof/gbp-sysprof-workbench-addin.c
b/src/plugins/sysprof/gbp-sysprof-workbench-addin.c
index 05c6718cb..852f7857f 100644
--- a/src/plugins/sysprof/gbp-sysprof-workbench-addin.c
+++ b/src/plugins/sysprof/gbp-sysprof-workbench-addin.c
@@ -24,6 +24,8 @@
#include <glib/gi18n.h>
+#include <sysprof-ui.h>
+
#include <libide-gui.h>
#include <libide-threading.h>
@@ -33,7 +35,12 @@
struct _GbpSysprofWorkbenchAddin
{
GObject parent_instance;
+
IdeWorkbench *workbench;
+
+ guint project_loaded : 1;
+ guint run_manager_busy : 1;
+ guint sanity_check : 1;
};
typedef struct
@@ -42,6 +49,16 @@ typedef struct
GbpSysprofPage *page;
} FindPageWithFile;
+static void gbp_sysprof_workbench_addin_open_capture (GbpSysprofWorkbenchAddin *self,
+ GVariant *param);
+static void gbp_sysprof_workbench_addin_run (GbpSysprofWorkbenchAddin *self,
+ GVariant *param);
+
+IDE_DEFINE_ACTION_GROUP (GbpSysprofWorkbenchAddin, gbp_sysprof_workbench_addin, {
+ { "open-capture", gbp_sysprof_workbench_addin_open_capture },
+ { "run", gbp_sysprof_workbench_addin_run },
+})
+
static void
find_page_with_file (IdePage *page,
gpointer user_data)
@@ -160,6 +177,88 @@ gbp_sysprof_workbench_addin_load (IdeWorkbenchAddin *addin,
self->workbench = workbench;
}
+static void
+update_action_enabled (GbpSysprofWorkbenchAddin *self)
+{
+ gboolean enabled;
+
+ g_assert (GBP_IS_SYSPROF_WORKBENCH_ADDIN (self));
+
+ enabled = !self->run_manager_busy && self->project_loaded && self->sanity_check;
+ gbp_sysprof_workbench_addin_set_action_enabled (self, "run", enabled);
+}
+
+static void
+gbp_sysprof_workbench_addin_notify_busy_cb (GbpSysprofWorkbenchAddin *self,
+ GParamSpec *pspec,
+ IdeRunManager *run_manager)
+{
+ g_assert (GBP_IS_SYSPROF_WORKBENCH_ADDIN (self));
+ g_assert (IDE_IS_RUN_MANAGER (run_manager));
+
+ self->run_manager_busy = ide_run_manager_get_busy (run_manager);
+
+ update_action_enabled (self);
+}
+
+static void
+gbp_sysprof_workbench_addin_check_supported_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ g_autoptr(GbpSysprofWorkbenchAddin) self = user_data;
+ g_autoptr(GError) error = NULL;
+
+ IDE_ENTRY;
+
+ g_assert (IDE_IS_MAIN_THREAD ());
+ g_assert (G_IS_ASYNC_RESULT (result));
+ g_assert (GBP_IS_SYSPROF_WORKBENCH_ADDIN (self));
+
+ if (!sysprof_check_supported_finish (result, &error))
+ {
+ g_warning ("Sysprof-3 is not supported, will not enable profiler: %s",
+ error->message);
+ IDE_EXIT;
+ }
+
+ self->sanity_check = TRUE;
+
+ update_action_enabled (self);
+
+ IDE_EXIT;
+}
+
+static void
+gbp_sysprof_workbench_addin_project_loaded (IdeWorkbenchAddin *addin,
+ IdeProjectInfo *project_info)
+{
+ GbpSysprofWorkbenchAddin *self = (GbpSysprofWorkbenchAddin *)addin;
+ IdeRunManager *run_manager;
+ IdeContext *context;
+
+ g_assert (IDE_IS_MAIN_THREAD ());
+ g_assert (GBP_IS_SYSPROF_WORKBENCH_ADDIN (self));
+ g_assert (IDE_IS_WORKBENCH (self->workbench));
+
+ self->project_loaded = TRUE;
+
+ context = ide_workbench_get_context (self->workbench);
+ run_manager = ide_run_manager_from_context (context);
+
+ g_signal_connect_object (run_manager,
+ "notify::busy",
+ G_CALLBACK (gbp_sysprof_workbench_addin_notify_busy_cb),
+ self,
+ G_CONNECT_SWAPPED);
+
+ gbp_sysprof_workbench_addin_notify_busy_cb (self, NULL, run_manager);
+
+ sysprof_check_supported_async (NULL,
+ gbp_sysprof_workbench_addin_check_supported_cb,
+ g_object_ref (self));
+}
+
static void
gbp_sysprof_workbench_addin_unload (IdeWorkbenchAddin *addin,
IdeWorkbench *workbench)
@@ -178,11 +277,27 @@ workbench_addin_iface_init (IdeWorkbenchAddinInterface *iface)
{
iface->load = gbp_sysprof_workbench_addin_load;
iface->unload = gbp_sysprof_workbench_addin_unload;
+ iface->project_loaded = gbp_sysprof_workbench_addin_project_loaded;
iface->can_open = gbp_sysprof_workbench_addin_can_open;
iface->open_async = gbp_sysprof_workbench_addin_open_async;
iface->open_finish = gbp_sysprof_workbench_addin_open_finish;
}
+G_DEFINE_FINAL_TYPE_WITH_CODE (GbpSysprofWorkbenchAddin, gbp_sysprof_workbench_addin, G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (G_TYPE_ACTION_GROUP,
gbp_sysprof_workbench_addin_init_action_group)
+ G_IMPLEMENT_INTERFACE (IDE_TYPE_WORKBENCH_ADDIN, workbench_addin_iface_init))
+
+static void
+gbp_sysprof_workbench_addin_class_init (GbpSysprofWorkbenchAddinClass *klass)
+{
+}
+
+static void
+gbp_sysprof_workbench_addin_init (GbpSysprofWorkbenchAddin *self)
+{
+ gbp_sysprof_workbench_addin_set_action_enabled (self, "run", FALSE);
+}
+
static void
on_native_dialog_response_cb (GbpSysprofWorkbenchAddin *self,
int response_id,
@@ -253,20 +368,26 @@ gbp_sysprof_workbench_addin_open_capture (GbpSysprofWorkbenchAddin *self,
gtk_native_dialog_show (GTK_NATIVE_DIALOG (native));
}
-IDE_DEFINE_ACTION_GROUP (GbpSysprofWorkbenchAddin, gbp_sysprof_workbench_addin, {
- { "open-capture", gbp_sysprof_workbench_addin_open_capture },
-})
-
-G_DEFINE_FINAL_TYPE_WITH_CODE (GbpSysprofWorkbenchAddin, gbp_sysprof_workbench_addin, G_TYPE_OBJECT,
- G_IMPLEMENT_INTERFACE (G_TYPE_ACTION_GROUP,
gbp_sysprof_workbench_addin_init_action_group)
- G_IMPLEMENT_INTERFACE (IDE_TYPE_WORKBENCH_ADDIN, workbench_addin_iface_init))
-
static void
-gbp_sysprof_workbench_addin_class_init (GbpSysprofWorkbenchAddinClass *klass)
+gbp_sysprof_workbench_addin_run (GbpSysprofWorkbenchAddin *self,
+ GVariant *param)
{
-}
+ PeasPluginInfo *plugin_info;
+ IdeRunManager *run_manager;
+ IdeContext *context;
-static void
-gbp_sysprof_workbench_addin_init (GbpSysprofWorkbenchAddin *self)
-{
+ IDE_ENTRY;
+
+ g_assert (IDE_IS_MAIN_THREAD ());
+ g_assert (GBP_IS_SYSPROF_WORKBENCH_ADDIN (self));
+ g_assert (IDE_IS_WORKBENCH (self->workbench));
+
+ plugin_info = peas_engine_get_plugin_info (peas_engine_get_default (), "sysprof");
+ context = ide_workbench_get_context (self->workbench);
+ run_manager = ide_run_manager_from_context (context);
+
+ ide_run_manager_set_run_tool_from_plugin_info (run_manager, plugin_info);
+ ide_run_manager_run_async (run_manager, NULL, NULL, NULL);
+
+ IDE_EXIT;
}
diff --git a/src/plugins/sysprof/gtk/keybindings.json b/src/plugins/sysprof/gtk/keybindings.json
index 413a17b0d..57b0b1681 100644
--- a/src/plugins/sysprof/gtk/keybindings.json
+++ b/src/plugins/sysprof/gtk/keybindings.json
@@ -1,3 +1,3 @@
{ "trigger" : "<Control>s", "action" : "sysprof.save-as", "when" : "inPageWithTypeName(\"GbpSysprofPage\")",
"phase" : "capture" },
-{ "trigger" : "<Control><Shift><Alt>p", "action" : "sysprof.run", "when" : "hasProject()", "phase" :
"capture" },
+{ "trigger" : "<Control><Shift><Alt>p", "action" : "context.workbench.sysprof.run", "when" : "hasProject()",
"phase" : "capture" },
{ "trigger" : "<Control>w", "action" : "frame.close-page-or-frame", "when" :
"inPageWithTypeName(\"GbpSysprofPage\")", "phase" : "capture" },
diff --git a/src/plugins/sysprof/gtk/menus.ui b/src/plugins/sysprof/gtk/menus.ui
index 5173f55da..7df30372e 100644
--- a/src/plugins/sysprof/gtk/menus.ui
+++ b/src/plugins/sysprof/gtk/menus.ui
@@ -15,7 +15,7 @@
<item>
<attribute name="id">sysprof-run-handler</attribute>
<attribute name="after">default-run-handler</attribute>
- <attribute name="action">sysprof.run</attribute>
+ <attribute name="action">context.workbench.sysprof.run</attribute>
<attribute name="label" translatable="yes">Run with Profiler</attribute>
<attribute name="verb-icon">builder-profiler-symbolic</attribute>
<attribute name="accel"><Control><Shift><Alt>p</attribute>
diff --git a/src/plugins/sysprof/meson.build b/src/plugins/sysprof/meson.build
index c54dc33a3..2d21e312b 100644
--- a/src/plugins/sysprof/meson.build
+++ b/src/plugins/sysprof/meson.build
@@ -24,7 +24,6 @@ plugins_sources += files([
'gbp-sysprof-page.c',
'gbp-sysprof-tool.c',
'gbp-sysprof-workbench-addin.c',
- 'gbp-sysprof-workspace-addin.c',
])
plugin_sysprof_resources = gnome.compile_resources(
diff --git a/src/plugins/sysprof/sysprof-plugin.c b/src/plugins/sysprof/sysprof-plugin.c
index 6d6c97db3..a727a711e 100644
--- a/src/plugins/sysprof/sysprof-plugin.c
+++ b/src/plugins/sysprof/sysprof-plugin.c
@@ -29,7 +29,6 @@
#include "gbp-sysprof-tool.h"
#include "gbp-sysprof-workbench-addin.h"
-#include "gbp-sysprof-workspace-addin.h"
_IDE_EXTERN void
_gbp_sysprof_register_types (PeasObjectModule *module)
@@ -42,7 +41,4 @@ _gbp_sysprof_register_types (PeasObjectModule *module)
peas_object_module_register_extension_type (module,
IDE_TYPE_WORKBENCH_ADDIN,
GBP_TYPE_SYSPROF_WORKBENCH_ADDIN);
- peas_object_module_register_extension_type (module,
- IDE_TYPE_WORKSPACE_ADDIN,
- GBP_TYPE_SYSPROF_WORKSPACE_ADDIN);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]