[gnome-builder] omnibar: wire up pausable operations into the omnibar



commit 230ed30f689adc5e1fe6a4f2cf076813eff867df
Author: Christian Hergert <chergert redhat com>
Date:   Tue Sep 5 01:15:32 2017 -0700

    omnibar: wire up pausable operations into the omnibar

 libide/libide.gresource.xml               |    1 +
 libide/meson.build                        |    2 +
 libide/workbench/ide-omni-bar.c           |   12 ++-
 libide/workbench/ide-omni-bar.ui          |   64 +----------
 libide/workbench/ide-omni-pausable-row.c  |  168 +++++++++++++++++++++++++++++
 libide/workbench/ide-omni-pausable-row.h  |   36 ++++++
 libide/workbench/ide-omni-pausable-row.ui |   57 ++++++++++
 7 files changed, 278 insertions(+), 62 deletions(-)
---
diff --git a/libide/libide.gresource.xml b/libide/libide.gresource.xml
index b59f2db..5da4954 100644
--- a/libide/libide.gresource.xml
+++ b/libide/libide.gresource.xml
@@ -77,6 +77,7 @@
     <file compressed="true" preprocess="xml-stripblanks" 
alias="ide-greeter-perspective.ui">greeter/ide-greeter-perspective.ui</file>
     <file compressed="true" preprocess="xml-stripblanks" 
alias="ide-greeter-project-row.ui">greeter/ide-greeter-project-row.ui</file>
     <file compressed="true" preprocess="xml-stripblanks" 
alias="ide-omni-bar.ui">workbench/ide-omni-bar.ui</file>
+    <file compressed="true" preprocess="xml-stripblanks" 
alias="ide-omni-pausable-row.ui">workbench/ide-omni-pausable-row.ui</file>
     <file compressed="true" preprocess="xml-stripblanks" 
alias="ide-preferences-language-row.ui">preferences/ide-preferences-language-row.ui</file>
     <file compressed="true" preprocess="xml-stripblanks" 
alias="ide-run-button.ui">runner/ide-run-button.ui</file>
     <file compressed="true" preprocess="xml-stripblanks" 
alias="ide-transfer-row.ui">transfers/ide-transfer-row.ui</file>
diff --git a/libide/meson.build b/libide/meson.build
index d63e58e..acec572 100644
--- a/libide/meson.build
+++ b/libide/meson.build
@@ -632,6 +632,8 @@ libide_sources = libide_generated_headers + libide_public_sources + [
   'util/ide-ref-ptr.h',
   'util/ide-window-settings.c',
   'util/ide-window-settings.h',
+  'workbench/ide-omni-pausable-row.c',
+  'workbench/ide-omni-pausable-row.h',
   'workbench/ide-workbench-actions.c',
   'workbench/ide-workbench-private.h',
   'workbench/ide-workbench-shortcuts.c',
diff --git a/libide/workbench/ide-omni-bar.c b/libide/workbench/ide-omni-bar.c
index c27dae7..b594f0c 100644
--- a/libide/workbench/ide-omni-bar.c
+++ b/libide/workbench/ide-omni-bar.c
@@ -23,6 +23,7 @@
 
 #include "ide-context.h"
 #include "ide-debug.h"
+#include "ide-internal.h"
 
 #include "buildsystem/ide-build-manager.h"
 #include "buildsystem/ide-build-pipeline.h"
@@ -34,6 +35,7 @@
 #include "util/ide-gtk.h"
 #include "vcs/ide-vcs.h"
 #include "workbench/ide-omni-bar.h"
+#include "workbench/ide-omni-pausable-row.h"
 
 #define LOOPER_INTERVAL_SECONDS 5
 #define SETTLE_MESSAGE_COUNT 2
@@ -120,7 +122,7 @@ struct _IdeOmniBar
   GtkButton            *cancel_button;
   GtkLabel             *config_name_label;
   GtkStack             *message_stack;
-  GtkListBox           *operations_list;
+  DzlListBox           *pausables;
   GtkPopover           *popover;
   GtkLabel             *popover_branch_label;
   GtkLabel             *popover_config_label;
@@ -213,6 +215,7 @@ ide_omni_bar_context_set (GtkWidget  *widget,
   IdeOmniBar *self = (IdeOmniBar *)widget;
   IdeConfigurationManager *config_manager = NULL;
   IdeBuildManager *build_manager = NULL;
+  GListModel *pausables = NULL;
   IdeProject *project = NULL;
   IdeVcs *vcs = NULL;
 
@@ -229,6 +232,7 @@ ide_omni_bar_context_set (GtkWidget  *widget,
       build_manager = ide_context_get_build_manager (context);
       config_manager = ide_context_get_configuration_manager (context);
       project = ide_context_get_project (context);
+      pausables = _ide_context_get_pausables (context);
     }
 
   dzl_binding_group_set_source (self->build_manager_bindings, build_manager);
@@ -237,6 +241,7 @@ ide_omni_bar_context_set (GtkWidget  *widget,
   dzl_signal_group_set_target (self->config_manager_signals, config_manager);
   dzl_binding_group_set_source (self->project_bindings, project);
   dzl_binding_group_set_source (self->vcs_bindings, vcs);
+  dzl_list_box_set_model (self->pausables, pausables);
 
   if (config_manager != NULL)
     ide_omni_bar__config_manager__notify_current (self, NULL, config_manager);
@@ -497,7 +502,7 @@ ide_omni_bar_class_init (IdeOmniBarClass *klass)
   gtk_widget_class_bind_template_child (widget_class, IdeOmniBar, config_name_label);
   gtk_widget_class_bind_template_child (widget_class, IdeOmniBar, event_box);
   gtk_widget_class_bind_template_child (widget_class, IdeOmniBar, message_stack);
-  gtk_widget_class_bind_template_child (widget_class, IdeOmniBar, operations_list);
+  gtk_widget_class_bind_template_child (widget_class, IdeOmniBar, pausables);
   gtk_widget_class_bind_template_child (widget_class, IdeOmniBar, popover);
   gtk_widget_class_bind_template_child (widget_class, IdeOmniBar, popover_branch_label);
   gtk_widget_class_bind_template_child (widget_class, IdeOmniBar, popover_build_result_label);
@@ -509,6 +514,9 @@ ide_omni_bar_class_init (IdeOmniBarClass *klass)
   gtk_widget_class_bind_template_child (widget_class, IdeOmniBar, popover_runtime_label);
   gtk_widget_class_bind_template_child (widget_class, IdeOmniBar, popover_warnings_label);
   gtk_widget_class_bind_template_child (widget_class, IdeOmniBar, project_label);
+
+  g_type_ensure (IDE_TYPE_OMNI_PAUSABLE_ROW);
+  g_type_ensure (DZL_TYPE_LIST_BOX);
 }
 
 static void
diff --git a/libide/workbench/ide-omni-bar.ui b/libide/workbench/ide-omni-bar.ui
index 44898d2..b997bf6 100644
--- a/libide/workbench/ide-omni-bar.ui
+++ b/libide/workbench/ide-omni-bar.ui
@@ -508,68 +508,12 @@
               </object>
             </child>
             <child>
-              <object class="GtkListBox">
+              <object class="DzlListBox" id="pausables">
+                <property name="row-type-name">IdeOmniPausableRow</property>
+                <property name="property-name">pausable</property>
                 <property name="selection-mode">none</property>
                 <property name="hexpand">true</property>
-                <property name="visible">false</property>
-                <child>
-                  <object class="GtkListBoxRow" id="operations_list">
-                    <property name="visible">true</property>
-                    <child>
-                      <object class="GtkGrid">
-                        <property name="margin">12</property>
-                        <property name="row-spacing">6</property>
-                        <property name="column-spacing">12</property>
-                        <property name="visible">true</property>
-                        <child>
-                          <object class="GtkLabel">
-                            <property name="hexpand">true</property>
-                            <property name="xalign">0.0</property>
-                            <property name="visible">true</property>
-                            <property name="label" translatable="yes">Indexing Source Code</property>
-                            <attributes>
-                              <attribute name="weight" value="bold"/>
-                            </attributes>
-                          </object>
-                          <packing>
-                            <property name="top-attach">0</property>
-                            <property name="left-attach">0</property>
-                          </packing>
-                        </child>
-                        <child>
-                          <object class="GtkLabel">
-                            <property name="hexpand">true</property>
-                            <property name="xalign">0.0</property>
-                            <property name="visible">true</property>
-                            <property name="label" translatable="yes">Search, diagnostics and autocompletion 
may be limited until complete.</property>
-                          </object>
-                          <packing>
-                            <property name="top-attach">1</property>
-                            <property name="left-attach">0</property>
-                          </packing>
-                        </child>
-                        <child>
-                          <object class="GtkToggleButton">
-                            <property name="halign">center</property>
-                            <property name="valign">center</property>
-                            <property name="visible">true</property>
-                            <child>
-                              <object class="GtkImage">
-                                <property name="icon-name">media-playback-pause-symbolic</property>
-                                <property name="visible">true</property>
-                              </object>
-                            </child>
-                          </object>
-                          <packing>
-                            <property name="top-attach">0</property>
-                            <property name="left-attach">1</property>
-                            <property name="height">2</property>
-                          </packing>
-                        </child>
-                      </object>
-                    </child>
-                  </object>
-                </child>
+                <property name="visible">true</property>
               </object>
             </child>
           </object>
diff --git a/libide/workbench/ide-omni-pausable-row.c b/libide/workbench/ide-omni-pausable-row.c
new file mode 100644
index 0000000..6a893b0
--- /dev/null
+++ b/libide/workbench/ide-omni-pausable-row.c
@@ -0,0 +1,168 @@
+/* ide-omni-pausable-row.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 "ide-omni-pausable-row"
+
+#include "ide-pausable.h"
+
+#include "workbench/ide-omni-pausable-row.h"
+
+struct _IdeOmniPausableRow
+{
+  DzlListBoxRow    parent_instance;
+
+  DzlBindingGroup *group;
+  IdePausable     *pausable;
+
+  GtkToggleButton *button;
+  GtkLabel        *title;
+  GtkLabel        *subtitle;
+};
+
+enum {
+  PROP_0,
+  PROP_PAUSABLE,
+  N_PROPS
+};
+
+G_DEFINE_TYPE (IdeOmniPausableRow, ide_omni_pausable_row, DZL_TYPE_LIST_BOX_ROW)
+
+static GParamSpec *properties [N_PROPS];
+
+static void
+ide_omni_pausable_row_dispose (GObject *object)
+{
+  IdeOmniPausableRow *self = (IdeOmniPausableRow *)object;
+
+  g_clear_object (&self->group);
+  g_clear_object (&self->pausable);
+
+  G_OBJECT_CLASS (ide_omni_pausable_row_parent_class)->dispose (object);
+}
+
+static void
+ide_omni_pausable_row_get_property (GObject    *object,
+                                    guint       prop_id,
+                                    GValue     *value,
+                                    GParamSpec *pspec)
+{
+  IdeOmniPausableRow *self = IDE_OMNI_PAUSABLE_ROW (object);
+
+  switch (prop_id)
+    {
+    case PROP_PAUSABLE:
+      g_value_set_object (value, ide_omni_pausable_row_get_pausable (self));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_omni_pausable_row_set_property (GObject      *object,
+                                    guint         prop_id,
+                                    const GValue *value,
+                                    GParamSpec   *pspec)
+{
+  IdeOmniPausableRow *self = IDE_OMNI_PAUSABLE_ROW (object);
+
+  switch (prop_id)
+    {
+    case PROP_PAUSABLE:
+      ide_omni_pausable_row_set_pausable (self, g_value_get_object (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_omni_pausable_row_class_init (IdeOmniPausableRowClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  object_class->dispose = ide_omni_pausable_row_dispose;
+  object_class->get_property = ide_omni_pausable_row_get_property;
+  object_class->set_property = ide_omni_pausable_row_set_property;
+
+  properties [PROP_PAUSABLE] =
+    g_param_spec_object ("pausable", NULL, NULL,
+                         IDE_TYPE_PAUSABLE,
+                         G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+  g_object_class_install_properties (object_class, N_PROPS, properties);
+
+  gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/builder/ui/ide-omni-pausable-row.ui");
+  gtk_widget_class_bind_template_child (widget_class, IdeOmniPausableRow, button);
+  gtk_widget_class_bind_template_child (widget_class, IdeOmniPausableRow, title);
+  gtk_widget_class_bind_template_child (widget_class, IdeOmniPausableRow, subtitle);
+}
+
+static void
+ide_omni_pausable_row_init (IdeOmniPausableRow *self)
+{
+  gtk_widget_init_template (GTK_WIDGET (self));
+
+  self->group = dzl_binding_group_new ();
+
+  dzl_binding_group_bind (self->group, "title", self->title, "label", 0);
+  dzl_binding_group_bind (self->group, "subtitle", self->subtitle, "label", 0);
+  dzl_binding_group_bind (self->group, "paused", self->button, "active",
+                          G_BINDING_BIDIRECTIONAL);
+}
+
+GtkWidget *
+ide_omni_pausable_row_new (IdePausable *pausable)
+{
+  g_return_val_if_fail (!pausable || IDE_IS_PAUSABLE (pausable), NULL);
+
+  return g_object_new (IDE_TYPE_OMNI_PAUSABLE_ROW,
+                       "pausable", pausable,
+                       NULL);
+}
+
+/**
+ * ide_omni_pausable_row_get_pausable:
+ * @self: a #IdeOmniPausableRow
+ *
+ * Returns: (transfer none): An #IdePausable or %NULL
+ */
+IdePausable *
+ide_omni_pausable_row_get_pausable (IdeOmniPausableRow *self)
+{
+  g_return_val_if_fail (IDE_IS_OMNI_PAUSABLE_ROW (self), NULL);
+
+  return self->pausable;
+}
+
+void
+ide_omni_pausable_row_set_pausable (IdeOmniPausableRow *self,
+                                    IdePausable        *pausable)
+{
+  g_return_if_fail (IDE_IS_OMNI_PAUSABLE_ROW (self));
+  g_return_if_fail (!pausable || IDE_IS_PAUSABLE (pausable));
+
+  if (g_set_object (&self->pausable, pausable))
+    {
+      dzl_binding_group_set_source (self->group, pausable);
+      g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_PAUSABLE]);
+    }
+}
diff --git a/libide/workbench/ide-omni-pausable-row.h b/libide/workbench/ide-omni-pausable-row.h
new file mode 100644
index 0000000..bd3eeb2
--- /dev/null
+++ b/libide/workbench/ide-omni-pausable-row.h
@@ -0,0 +1,36 @@
+/* ide-omni-pausable-row.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 <dazzle.h>
+
+#include "ide-types.h"
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_OMNI_PAUSABLE_ROW (ide_omni_pausable_row_get_type())
+
+G_DECLARE_FINAL_TYPE (IdeOmniPausableRow, ide_omni_pausable_row, IDE, OMNI_PAUSABLE_ROW, GtkListBoxRow)
+
+GtkWidget   *ide_omni_pausable_row_new          (IdePausable        *pausable);
+IdePausable *ide_omni_pausable_row_get_pausable (IdeOmniPausableRow *self);
+void         ide_omni_pausable_row_set_pausable (IdeOmniPausableRow *self,
+                                                 IdePausable        *pausable);
+
+G_END_DECLS
diff --git a/libide/workbench/ide-omni-pausable-row.ui b/libide/workbench/ide-omni-pausable-row.ui
new file mode 100644
index 0000000..f15f2a4
--- /dev/null
+++ b/libide/workbench/ide-omni-pausable-row.ui
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="IdeOmniPausableRow" parent="DzlListBoxRow">
+    <child>
+      <object class="GtkGrid">
+        <property name="margin">12</property>
+        <property name="row-spacing">6</property>
+        <property name="column-spacing">12</property>
+        <property name="visible">true</property>
+        <child>
+          <object class="GtkLabel" id="title">
+            <property name="hexpand">true</property>
+            <property name="xalign">0.0</property>
+            <property name="visible">true</property>
+            <property name="wrap">true</property>
+            <attributes>
+              <attribute name="weight" value="bold"/>
+            </attributes>
+          </object>
+          <packing>
+            <property name="top-attach">0</property>
+            <property name="left-attach">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="subtitle">
+            <property name="hexpand">true</property>
+            <property name="xalign">0.0</property>
+            <property name="visible">true</property>
+          </object>
+          <packing>
+            <property name="top-attach">1</property>
+            <property name="left-attach">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkToggleButton" id="button">
+            <property name="halign">center</property>
+            <property name="valign">center</property>
+            <property name="visible">true</property>
+            <child>
+              <object class="GtkImage">
+                <property name="icon-name">media-playback-pause-symbolic</property>
+                <property name="visible">true</property>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="top-attach">0</property>
+            <property name="left-attach">1</property>
+            <property name="height">2</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>


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