[gnome-builder] vcsui: invalidate build pipeline when branch changes



commit 6a03e96b83b5840e97d567b1f29c492f0ec34e33
Author: Christian Hergert <chergert redhat com>
Date:   Tue Feb 12 12:58:15 2019 -0800

    vcsui: invalidate build pipeline when branch changes
    
    This monitors the IdeVcs:branch-name property for changes and invalidates
    the current build pipeline via ide_build_manager_invalidate() so that new
    build directories may be setup and configured.
    
    Related #794

 src/plugins/vcsui/gbp-vcsui-workbench-addin.c | 130 ++++++++++++++++++++++++++
 src/plugins/vcsui/gbp-vcsui-workbench-addin.h |  31 ++++++
 src/plugins/vcsui/meson.build                 |   1 +
 src/plugins/vcsui/vcsui-plugin.c              |   4 +
 4 files changed, 166 insertions(+)
---
diff --git a/src/plugins/vcsui/gbp-vcsui-workbench-addin.c b/src/plugins/vcsui/gbp-vcsui-workbench-addin.c
new file mode 100644
index 000000000..9e18159d9
--- /dev/null
+++ b/src/plugins/vcsui/gbp-vcsui-workbench-addin.c
@@ -0,0 +1,130 @@
+/* gbp-vcsui-workbench-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-vcsui-workbench-addin"
+
+#include "config.h"
+
+#include <dazzle.h>
+#include <libide-gui.h>
+#include <libide-vcs.h>
+
+#include "gbp-vcsui-workbench-addin.h"
+
+struct _GbpVcsuiWorkbenchAddin
+{
+  GObject parent_instance;
+
+  DzlSignalGroup *vcs_signals;
+};
+
+static void
+on_notify_branch_name (GbpVcsuiWorkbenchAddin *self,
+                       GParamSpec             *pspec,
+                       IdeVcs                 *vcs)
+{
+  g_autoptr(IdeContext) context = NULL;
+  IdeBuildManager *build_manager;
+
+  IDE_ENTRY;
+
+  g_assert (IDE_IS_MAIN_THREAD ());
+  g_assert (GBP_IS_VCSUI_WORKBENCH_ADDIN (self));
+  g_assert (IDE_IS_VCS (vcs));
+
+  context = ide_object_ref_context (IDE_OBJECT (vcs));
+
+  /* Short-circuit if no project is loaded */
+  if (!context || !ide_context_has_project (context))
+    return;
+
+  if ((build_manager = ide_build_manager_from_context (context)))
+    ide_build_manager_invalidate (build_manager);
+
+  IDE_EXIT;
+}
+
+static void
+gbp_vcsui_workbench_addin_vcs_changed (IdeWorkbenchAddin *addin,
+                                       IdeVcs            *vcs)
+{
+  GbpVcsuiWorkbenchAddin *self = (GbpVcsuiWorkbenchAddin *)addin;
+
+  g_assert (IDE_IS_MAIN_THREAD ());
+  g_assert (GBP_IS_VCSUI_WORKBENCH_ADDIN (self));
+  g_assert (!vcs || IDE_IS_VCS (vcs));
+
+  dzl_signal_group_set_target (self->vcs_signals, vcs);
+
+  if (vcs != NULL)
+    on_notify_branch_name (self, NULL, vcs);
+}
+
+static void
+gbp_vcsui_workbench_addin_load (IdeWorkbenchAddin *addin,
+                                IdeWorkbench      *workbench)
+{
+  GbpVcsuiWorkbenchAddin *self = (GbpVcsuiWorkbenchAddin *)addin;
+
+  g_assert (IDE_IS_MAIN_THREAD ());
+  g_assert (GBP_IS_VCSUI_WORKBENCH_ADDIN (self));
+  g_assert (IDE_IS_WORKBENCH (workbench));
+
+  self->vcs_signals = dzl_signal_group_new (G_TYPE_OBJECT);
+  dzl_signal_group_connect_object (self->vcs_signals,
+                                   "notify::branch-name",
+                                   G_CALLBACK (on_notify_branch_name),
+                                   self,
+                                   G_CONNECT_SWAPPED);
+}
+
+static void
+gbp_vcsui_workbench_addin_unload (IdeWorkbenchAddin *addin,
+                                  IdeWorkbench      *workbench)
+{
+  GbpVcsuiWorkbenchAddin *self = (GbpVcsuiWorkbenchAddin *)addin;
+
+  g_assert (GBP_IS_VCSUI_WORKBENCH_ADDIN (self));
+  g_assert (IDE_IS_WORKBENCH (workbench));
+
+  dzl_signal_group_set_target (self->vcs_signals, NULL);
+  g_clear_object (&self->vcs_signals);
+}
+
+static void
+workbench_addin_iface_init (IdeWorkbenchAddinInterface *iface)
+{
+  iface->load = gbp_vcsui_workbench_addin_load;
+  iface->unload = gbp_vcsui_workbench_addin_unload;
+  iface->vcs_changed = gbp_vcsui_workbench_addin_vcs_changed;
+}
+
+G_DEFINE_TYPE_WITH_CODE (GbpVcsuiWorkbenchAddin, gbp_vcsui_workbench_addin, G_TYPE_OBJECT,
+                         G_IMPLEMENT_INTERFACE (IDE_TYPE_WORKBENCH_ADDIN, workbench_addin_iface_init))
+
+static void
+gbp_vcsui_workbench_addin_class_init (GbpVcsuiWorkbenchAddinClass *klass)
+{
+}
+
+static void
+gbp_vcsui_workbench_addin_init (GbpVcsuiWorkbenchAddin *self)
+{
+}
diff --git a/src/plugins/vcsui/gbp-vcsui-workbench-addin.h b/src/plugins/vcsui/gbp-vcsui-workbench-addin.h
new file mode 100644
index 000000000..e1c4cb4fb
--- /dev/null
+++ b/src/plugins/vcsui/gbp-vcsui-workbench-addin.h
@@ -0,0 +1,31 @@
+/* gbp-vcsui-workbench-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 <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_VCSUI_WORKBENCH_ADDIN (gbp_vcsui_workbench_addin_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpVcsuiWorkbenchAddin, gbp_vcsui_workbench_addin, GBP, VCSUI_WORKBENCH_ADDIN, GObject)
+
+G_END_DECLS
diff --git a/src/plugins/vcsui/meson.build b/src/plugins/vcsui/meson.build
index 0d198a0af..f85a51df3 100644
--- a/src/plugins/vcsui/meson.build
+++ b/src/plugins/vcsui/meson.build
@@ -2,6 +2,7 @@ plugins_sources += files([
   'vcsui-plugin.c',
   'gbp-vcsui-tree-addin.c',
   'gbp-vcsui-editor-page-addin.c',
+  'gbp-vcsui-workbench-addin.c',
 ])
 
 plugin_vcsui_resources = gnome.compile_resources(
diff --git a/src/plugins/vcsui/vcsui-plugin.c b/src/plugins/vcsui/vcsui-plugin.c
index 3d9d2f601..0645ba3cc 100644
--- a/src/plugins/vcsui/vcsui-plugin.c
+++ b/src/plugins/vcsui/vcsui-plugin.c
@@ -29,6 +29,7 @@
 
 #include "gbp-vcsui-editor-page-addin.h"
 #include "gbp-vcsui-tree-addin.h"
+#include "gbp-vcsui-workbench-addin.h"
 
 _IDE_EXTERN void
 _gbp_vcsui_register_types (PeasObjectModule *module)
@@ -39,4 +40,7 @@ _gbp_vcsui_register_types (PeasObjectModule *module)
   peas_object_module_register_extension_type (module,
                                               IDE_TYPE_TREE_ADDIN,
                                               GBP_TYPE_VCSUI_TREE_ADDIN);
+  peas_object_module_register_extension_type (module,
+                                              IDE_TYPE_WORKBENCH_ADDIN,
+                                              GBP_TYPE_VCSUI_WORKBENCH_ADDIN);
 }


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