[gnome-builder] run-tools: add plugin for running project
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] run-tools: add plugin for running project
- Date: Sun, 17 Jul 2016 10:23:24 +0000 (UTC)
commit 02f0d894e52904e23437c41904d6aa01ad3b31b0
Author: Christian Hergert <chergert redhat com>
Date: Sun Jul 17 03:17:19 2016 -0700
run-tools: add plugin for running project
This adds the necessary UI components to the workbench for to run the
project after build/installing the target.
configure.ac | 2 +
plugins/Makefile.am | 1 +
plugins/run-tools/Makefile.am | 27 +++
plugins/run-tools/configure.ac | 12 +
plugins/run-tools/gbp-run-plugin.c | 28 +++
plugins/run-tools/gbp-run-workbench-addin.c | 296 +++++++++++++++++++++++++++
plugins/run-tools/gbp-run-workbench-addin.h | 32 +++
plugins/run-tools/run-tools.plugin | 11 +
8 files changed, 409 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 1b7f016..a4a02a1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -301,6 +301,7 @@ m4_include([plugins/mingw/configure.ac])
m4_include([plugins/project-tree/configure.ac])
m4_include([plugins/python-gi-imports-completion/configure.ac])
m4_include([plugins/python-pack/configure.ac])
+m4_include([plugins/run-tools/configure.ac])
m4_include([plugins/support/configure.ac])
m4_include([plugins/symbol-tree/configure.ac])
m4_include([plugins/sysmon/configure.ac])
@@ -593,6 +594,7 @@ echo " Project Tree ......................... : ${enable_project_tree_plugin}"
echo " Python GObject Introspection ......... : ${enable_python_gi_imports_completion_plugin}"
echo " Python Jedi Autocompletion ........... : ${enable_jedi_plugin}"
echo " Python Language Pack ................. : ${enable_python_pack_plugin}"
+echo " Run Tools ............................ : ${enable_run_tools_plugin}"
echo " Support .............................. : ${enable_support_plugin}"
echo " System Monitor ....................... : ${enable_sysmon_plugin}"
echo " Symbol Tree .......................... : ${enable_symbol_tree_plugin}"
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 1504dec..d1617c8 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -26,6 +26,7 @@ SUBDIRS = \
project-tree \
python-gi-imports-completion \
python-pack \
+ run-tools \
support \
symbol-tree \
sysmon \
diff --git a/plugins/run-tools/Makefile.am b/plugins/run-tools/Makefile.am
new file mode 100644
index 0000000..c3dc7cf
--- /dev/null
+++ b/plugins/run-tools/Makefile.am
@@ -0,0 +1,27 @@
+if ENABLE_RUN_TOOLS_PLUGIN
+
+DISTCLEANFILES =
+BUILT_SOURCES =
+CLEANFILES =
+EXTRA_DIST = $(plugin_DATA)
+
+plugindir = $(libdir)/gnome-builder/plugins
+plugin_LTLIBRARIES = librun-tools-plugin.la
+dist_plugin_DATA = run-tools.plugin
+
+librun_tools_plugin_la_CFLAGS = \
+ $(PLUGIN_CFLAGS) \
+ -DG_LOG_DOMAIN="\"run-tools\"" \
+ $(NULL)
+librun_tools_plugin_la_LDFLAGS = $(PLUGIN_LDFLAGS)
+librun_tools_plugin_la_SOURCES = \
+ gbp-run-plugin.c \
+ gbp-run-workbench-addin.c \
+ gbp-run-workbench-addin.h \
+ $(NULL)
+
+include $(top_srcdir)/plugins/Makefile.plugin
+
+endif
+
+-include $(top_srcdir)/git.mk
diff --git a/plugins/run-tools/configure.ac b/plugins/run-tools/configure.ac
new file mode 100644
index 0000000..61b1378
--- /dev/null
+++ b/plugins/run-tools/configure.ac
@@ -0,0 +1,12 @@
+# --enable-run-tools-plugin=yes/no
+AC_ARG_ENABLE([run-tools-plugin],
+ [AS_HELP_STRING([--enable-run-tools-plugin=@<:@yes/no@:>@],
+ [Run with support for run tools and panels.])],
+ [enable_run_tools_plugin=$enableval],
+ [enable_run_tools_plugin=yes])
+
+# for if ENABLE_RUN_TOOLS_PLUGIN in Makefile.am
+AM_CONDITIONAL(ENABLE_RUN_TOOLS_PLUGIN, test x$enable_run_tools_plugin != xno)
+
+# Ensure our makefile is generated by autoconf
+AC_CONFIG_FILES([plugins/run-tools/Makefile])
diff --git a/plugins/run-tools/gbp-run-plugin.c b/plugins/run-tools/gbp-run-plugin.c
new file mode 100644
index 0000000..cae5a1d
--- /dev/null
+++ b/plugins/run-tools/gbp-run-plugin.c
@@ -0,0 +1,28 @@
+/* gbp-run-plugin.c
+ *
+ * Copyright (C) 2016 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/>.
+ */
+
+#include <ide.h>
+#include <libpeas/peas.h>
+
+#include "gbp-run-workbench-addin.h"
+
+void
+peas_register_types (PeasObjectModule *module)
+{
+ peas_object_module_register_extension_type (module, IDE_TYPE_WORKBENCH_ADDIN,
GBP_TYPE_RUN_WORKBENCH_ADDIN);
+}
diff --git a/plugins/run-tools/gbp-run-workbench-addin.c b/plugins/run-tools/gbp-run-workbench-addin.c
new file mode 100644
index 0000000..d9a04b8
--- /dev/null
+++ b/plugins/run-tools/gbp-run-workbench-addin.c
@@ -0,0 +1,296 @@
+/* gbp-run-workbench-addin.c
+ *
+ * Copyright (C) 2016 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/>.
+ */
+
+#include <glib/gi18n.h>
+
+#include "gbp-run-workbench-addin.h"
+
+struct _GbpRunWorkbenchAddin
+{
+ GObject parent_instance;
+
+ IdeWorkbench *workbench;
+};
+
+static void workbench_addin_init_iface (IdeWorkbenchAddinInterface *iface);
+
+G_DEFINE_TYPE_EXTENDED (GbpRunWorkbenchAddin, gbp_run_workbench_addin, G_TYPE_OBJECT, 0,
+ G_IMPLEMENT_INTERFACE (IDE_TYPE_WORKBENCH_ADDIN,
+ workbench_addin_init_iface))
+
+static void
+gbp_run_workbench_addin_run_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ IdeRunManager *run_manager = (IdeRunManager *)object;
+ g_autoptr(GTask) task = user_data;
+ GError *error = NULL;
+
+ IDE_ENTRY;
+
+ g_assert (IDE_IS_RUN_MANAGER (run_manager));
+ g_assert (G_IS_TASK (task));
+
+ if (!ide_run_manager_run_finish (run_manager, result, &error))
+ {
+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ g_warning ("%s", error->message);
+ g_task_return_error (task, error);
+ IDE_GOTO (failure);
+ }
+
+ g_task_return_boolean (task, TRUE);
+
+failure:
+ IDE_EXIT;
+}
+
+static IdeBuildTarget *
+find_best_target (GPtrArray *targets)
+{
+ IdeBuildTarget *ret = NULL;
+ guint i;
+
+ g_assert (targets != NULL);
+
+ for (i = 0; i < targets->len; i++)
+ {
+ IdeBuildTarget *target = g_ptr_array_index (targets, i);
+ g_autoptr(GFile) installdir = NULL;
+
+ installdir = ide_build_target_get_install_directory (target);
+
+ if (installdir == NULL)
+ continue;
+
+ if (ret == NULL)
+ ret = target;
+
+ /* TODO: Compare likelyhood of primary binary */
+ }
+
+ return ret;
+}
+
+static void
+gbp_run_workbench_addin_get_build_targets_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ IdeBuildSystem *build_system = (IdeBuildSystem *)object;
+ GbpRunWorkbenchAddin *self;
+ g_autoptr(GPtrArray) targets = NULL;
+ g_autoptr(GTask) task = user_data;
+ IdeBuildTarget *best_match;
+ IdeRunManager *run_manager;
+ GCancellable *cancellable;
+ IdeContext *context;
+ GError *error = NULL;
+
+ IDE_ENTRY;
+
+ g_assert (IDE_IS_BUILD_SYSTEM (build_system));
+ g_assert (G_IS_ASYNC_RESULT (result));
+ g_assert (G_IS_TASK (task));
+
+ self = g_task_get_source_object (task);
+ cancellable = g_task_get_cancellable (task);
+
+ g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
+ g_assert (GBP_IS_RUN_WORKBENCH_ADDIN (self));
+ g_assert (IDE_IS_WORKBENCH (self->workbench));
+
+ targets = ide_build_system_get_build_targets_finish (build_system, result, &error);
+
+ if (targets == NULL)
+ {
+ g_task_return_error (task, error);
+ IDE_EXIT;
+ }
+
+ best_match = find_best_target (targets);
+
+ if (best_match == NULL)
+ {
+ g_task_return_new_error (task,
+ G_IO_ERROR,
+ G_IO_ERROR_FAILED,
+ "%s",
+ _("Failed to locate build target"));
+ IDE_EXIT;
+ }
+
+ context = ide_workbench_get_context (self->workbench);
+ run_manager = ide_context_get_run_manager (context);
+
+ ide_run_manager_run_async (run_manager,
+ best_match,
+ cancellable,
+ gbp_run_workbench_addin_run_cb,
+ g_steal_pointer (&task));
+
+ IDE_EXIT;
+}
+
+static void
+gbp_run_workbench_addin_run (GSimpleAction *action,
+ GVariant *param,
+ gpointer user_data)
+{
+ GbpRunWorkbenchAddin *self = user_data;
+ g_autoptr(GTask) task = NULL;
+ IdeBuildSystem *build_system;
+ IdeContext *context;
+
+ IDE_ENTRY;
+
+ g_assert (G_IS_SIMPLE_ACTION (action));
+ g_assert (GBP_IS_RUN_WORKBENCH_ADDIN (self));
+
+ context = ide_workbench_get_context (self->workbench);
+ build_system = ide_context_get_build_system (context);
+
+ task = g_task_new (self, NULL, NULL, NULL);
+ g_task_set_source_tag (task, gbp_run_workbench_addin_run);
+
+ ide_build_system_get_build_targets_async (build_system,
+ NULL,
+ gbp_run_workbench_addin_get_build_targets_cb,
+ g_steal_pointer (&task));
+
+ IDE_EXIT;
+}
+
+static void
+gbp_run_workbench_addin_stop (GSimpleAction *action,
+ GVariant *param,
+ gpointer user_data)
+{
+ GbpRunWorkbenchAddin *self = user_data;
+ IdeRunManager *run_manager;
+ IdeContext *context;
+
+ IDE_ENTRY;
+
+ g_assert (G_IS_SIMPLE_ACTION (action));
+ g_assert (GBP_IS_RUN_WORKBENCH_ADDIN (self));
+
+ context = ide_workbench_get_context (self->workbench);
+ run_manager = ide_context_get_run_manager (context);
+
+ ide_run_manager_cancel (run_manager);
+
+ IDE_EXIT;
+}
+
+static void
+gbp_run_workbench_addin_load (IdeWorkbenchAddin *addin,
+ IdeWorkbench *workbench)
+{
+ GbpRunWorkbenchAddin *self = (GbpRunWorkbenchAddin *)addin;
+ g_autoptr(GSimpleActionGroup) group = NULL;
+ IdeWorkbenchHeaderBar *headerbar;
+ IdeRunManager *run_manager;
+ IdeContext *context;
+ GtkWidget *button;
+ static const GActionEntry entries[] = {
+ { "run", gbp_run_workbench_addin_run },
+ { "stop", gbp_run_workbench_addin_stop },
+ };
+
+ g_assert (GBP_IS_RUN_WORKBENCH_ADDIN (self));
+ g_assert (IDE_IS_WORKBENCH (workbench));
+
+ self->workbench = workbench;
+
+ context = ide_workbench_get_context (workbench);
+ run_manager = ide_context_get_run_manager (context);
+
+ headerbar = ide_workbench_get_headerbar (workbench);
+
+ button = g_object_new (GTK_TYPE_BUTTON,
+ "action-name", "run-tools.run",
+ "focus-on-click", FALSE,
+ "child", g_object_new (GTK_TYPE_IMAGE,
+ "icon-name", "media-playback-start-symbolic",
+ "visible", TRUE,
+ NULL),
+ NULL);
+ g_object_bind_property (run_manager, "busy", button, "visible", G_BINDING_SYNC_CREATE |
G_BINDING_INVERT_BOOLEAN);
+ ide_widget_add_style_class (button, "image-button");
+ ide_workbench_header_bar_insert_right (headerbar, button, GTK_PACK_START, 0);
+
+ button = g_object_new (GTK_TYPE_BUTTON,
+ "action-name", "run-tools.stop",
+ "focus-on-click", FALSE,
+ "child", g_object_new (GTK_TYPE_IMAGE,
+ "icon-name", "media-playback-stop-symbolic",
+ "visible", TRUE,
+ NULL),
+ NULL);
+ g_object_bind_property (run_manager, "busy", button, "visible", G_BINDING_SYNC_CREATE);
+ ide_widget_add_style_class (button, "image-button");
+ ide_workbench_header_bar_insert_right (headerbar, button, GTK_PACK_START, 0);
+
+ group = g_simple_action_group_new ();
+ g_action_map_add_action_entries (G_ACTION_MAP (group), entries, G_N_ELEMENTS (entries), self);
+ gtk_widget_insert_action_group (GTK_WIDGET (workbench), "run-tools", G_ACTION_GROUP (group));
+
+ g_object_bind_property (run_manager,
+ "busy",
+ g_action_map_lookup_action (G_ACTION_MAP (group), "run"),
+ "enabled",
+ G_BINDING_SYNC_CREATE | G_BINDING_INVERT_BOOLEAN);
+
+ g_object_bind_property (run_manager,
+ "busy",
+ g_action_map_lookup_action (G_ACTION_MAP (group), "stop"),
+ "enabled",
+ G_BINDING_SYNC_CREATE);
+}
+
+static void
+gbp_run_workbench_addin_unload (IdeWorkbenchAddin *addin,
+ IdeWorkbench *workbench)
+{
+ GbpRunWorkbenchAddin *self = (GbpRunWorkbenchAddin *)addin;
+
+ g_assert (GBP_IS_RUN_WORKBENCH_ADDIN (self));
+ g_assert (IDE_IS_WORKBENCH (workbench));
+ g_assert (workbench == self->workbench);
+
+ self->workbench = NULL;
+}
+
+static void
+workbench_addin_init_iface (IdeWorkbenchAddinInterface *iface)
+{
+ iface->load = gbp_run_workbench_addin_load;
+ iface->unload = gbp_run_workbench_addin_unload;
+}
+
+static void
+gbp_run_workbench_addin_class_init (GbpRunWorkbenchAddinClass *klass)
+{
+}
+
+static void
+gbp_run_workbench_addin_init (GbpRunWorkbenchAddin *self)
+{
+}
diff --git a/plugins/run-tools/gbp-run-workbench-addin.h b/plugins/run-tools/gbp-run-workbench-addin.h
new file mode 100644
index 0000000..d7c655d
--- /dev/null
+++ b/plugins/run-tools/gbp-run-workbench-addin.h
@@ -0,0 +1,32 @@
+/* gbp-run-workbench-addin.h
+ *
+ * Copyright (C) 2016 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/>.
+ */
+
+#ifndef GBP_RUN_WORKBENCH_ADDIN_H
+#define GBP_RUN_WORKBENCH_ADDIN_H
+
+#include <ide.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_RUN_WORKBENCH_ADDIN (gbp_run_workbench_addin_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpRunWorkbenchAddin, gbp_run_workbench_addin, GBP, RUN_WORKBENCH_ADDIN, GObject)
+
+G_END_DECLS
+
+#endif /* GBP_RUN_WORKBENCH_ADDIN_H */
diff --git a/plugins/run-tools/run-tools.plugin b/plugins/run-tools/run-tools.plugin
new file mode 100644
index 0000000..6116bb1
--- /dev/null
+++ b/plugins/run-tools/run-tools.plugin
@@ -0,0 +1,11 @@
+[Plugin]
+Module=run-tools-plugin
+Name=Run Tools
+Description=Tools to run a project
+Authors=Christian Hergert <chergert redhat com>
+Copyright=Copyright © 2016 Christian Hergert
+Depends=editor
+Hidden=true
+Builtin=true
+X-Tool-Name=run
+X-Tool-Description=Run a project
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]