[gnome-builder/wip/project-selector: 5/9] project-window: start rendering discovered items from project miner



commit f90b11ca766dc92e90bef7707c8a638d62a05a07
Author: Christian Hergert <christian hergert me>
Date:   Mon Mar 30 00:16:55 2015 -0700

    project-window: start rendering discovered items from project miner

 data/ui/gb-project-window.ui      |   55 ++++++++++-
 src/workbench/gb-project-window.c |  204 ++++++++++++++++++++++++++++++++++++-
 2 files changed, 257 insertions(+), 2 deletions(-)
---
diff --git a/data/ui/gb-project-window.ui b/data/ui/gb-project-window.ui
index 549bbba..fde543f 100644
--- a/data/ui/gb-project-window.ui
+++ b/data/ui/gb-project-window.ui
@@ -2,12 +2,65 @@
 <interface>
   <!-- interface-requires gtk+ 3.15 -->
   <template class="GbProjectWindow" parent="GtkApplicationWindow">
+    <property name="default-width">800</property>
+    <property name="default-height">600</property>
     <child type="titlebar">
       <object class="GtkHeaderBar">
         <property name="show-close-button">true</property>
         <property name="title" translatable="yes">Builder</property>
         <property name="visible">true</property>
         <child>
+          <object class="GtkButton">
+            <property name="visible">true</property>
+            <style>
+              <class name="image-button"/>
+            </style>
+            <child>
+              <object class="GtkImage">
+                <property name="icon-name">list-add-symbolic</property>
+                <property name="visible">true</property>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="pack-type">start</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkMenuButton">
+            <property name="visible">true</property>
+            <style>
+              <class name="image-button"/>
+            </style>
+            <child>
+              <object class="GtkImage">
+                <property name="icon-name">open-menu-symbolic</property>
+                <property name="visible">true</property>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="pack-type">end</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkToggleButton" id="select_button">
+            <property name="visible">true</property>
+            <style>
+              <class name="image-button"/>
+            </style>
+            <child>
+              <object class="GtkImage">
+                <property name="icon-name">object-select-symbolic</property>
+                <property name="visible">true</property>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="pack-type">end</property>
+          </packing>
+        </child>
+        <child>
           <object class="GtkToggleButton">
             <property name="visible">true</property>
             <style>
@@ -36,7 +89,7 @@
             <property name="vexpand">true</property>
             <property name="visible">true</property>
             <child>
-              <object class="GtkListBox">
+              <object class="GtkListBox" id="listbox">
                 <property name="visible">true</property>
               </object>
             </child>
diff --git a/src/workbench/gb-project-window.c b/src/workbench/gb-project-window.c
index 20c35bb..79c12bf 100644
--- a/src/workbench/gb-project-window.c
+++ b/src/workbench/gb-project-window.c
@@ -16,6 +16,14 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE
+#endif
+
+#define G_LOG_DOMAIN "gb-project-window"
+
+#include <glib/gi18n.h>
+
 #include "gb-project-window.h"
 #include "gb-widget.h"
 
@@ -23,7 +31,8 @@ struct _GbProjectWindow
 {
   GtkApplicationWindow parent_instance;
 
-  GtkListBox *listbox;
+  GtkListBox      *listbox;
+  GtkToggleButton *select_button;
 };
 
 G_DEFINE_TYPE (GbProjectWindow, gb_project_window, GTK_TYPE_APPLICATION_WINDOW)
@@ -41,6 +50,197 @@ gb_project_window_new (void)
   return g_object_new (GB_TYPE_PROJECT_WINDOW, NULL);
 }
 
+static GtkWidget *
+create_row (GbProjectWindow *self,
+            IdeProjectInfo  *project_info)
+{
+  g_autofree gchar *markup = NULL;
+  const gchar *name;
+  GtkListBoxRow *row;
+  GtkBox *box;
+  GtkImage *image;
+  GtkArrow *arrow;
+  GtkLabel *label;
+  GtkCheckButton *check;
+  GtkRevealer *revealer;
+
+  g_assert (GB_IS_PROJECT_WINDOW (self));
+  g_assert (IDE_IS_PROJECT_INFO (project_info));
+
+  name = ide_project_info_get_name (project_info);
+  markup = g_strdup_printf ("<b>%s</b>", name);
+
+  row = g_object_new (GTK_TYPE_LIST_BOX_ROW,
+                      "visible", TRUE,
+                      NULL);
+  g_object_set_data_full (G_OBJECT (row),
+                          "IDE_PROJECT_ITEM",
+                          g_object_ref (project_info),
+                          g_object_unref);
+
+  box = g_object_new (GTK_TYPE_BOX,
+                      "orientation", GTK_ORIENTATION_HORIZONTAL,
+                      "visible", TRUE,
+                      "margin", 12,
+                      NULL);
+
+  check = g_object_new (GTK_TYPE_CHECK_BUTTON,
+                        "visible", TRUE,
+                        NULL);
+
+  image = g_object_new (GTK_TYPE_IMAGE,
+                        "icon-name", "folder",
+                        "pixel-size", 64,
+                        "margin-end", 12,
+                        "margin-start", 12,
+                        "visible", TRUE,
+                        NULL);
+
+  label = g_object_new (GTK_TYPE_LABEL,
+                        "label", markup,
+                        "hexpand", TRUE,
+                        "use-markup", TRUE,
+                        "visible", TRUE,
+                        "xalign", 0.0f,
+                        NULL);
+
+  revealer = g_object_new (GTK_TYPE_REVEALER,
+                           "reveal-child", FALSE,
+                           "transition-type", GTK_REVEALER_TRANSITION_TYPE_SLIDE_RIGHT,
+                           "visible", TRUE,
+                           NULL);
+  g_object_bind_property (self->select_button, "active",
+                          revealer, "reveal-child",
+                          G_BINDING_SYNC_CREATE);
+
+  G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+  arrow = g_object_new (GTK_TYPE_ARROW,
+                        "arrow-type", GTK_ARROW_RIGHT,
+                        "visible", TRUE,
+                        NULL);
+  G_GNUC_END_IGNORE_DEPRECATIONS
+
+  gtk_container_add (GTK_CONTAINER (revealer), GTK_WIDGET (check));
+  gtk_container_add (GTK_CONTAINER (box), GTK_WIDGET (revealer));
+  gtk_container_add (GTK_CONTAINER (box), GTK_WIDGET (image));
+  gtk_container_add (GTK_CONTAINER (box), GTK_WIDGET (label));
+  gtk_container_add (GTK_CONTAINER (box), GTK_WIDGET (arrow));
+  gtk_container_add (GTK_CONTAINER (row), GTK_WIDGET (box));
+
+  return GTK_WIDGET (row);
+}
+
+static void
+gb_project_window__miner_discovered_cb (GbProjectWindow *self,
+                                        IdeProjectInfo  *project_info,
+                                        IdeProjectMiner *miner)
+{
+  GtkWidget *row;
+
+  g_assert (GB_IS_PROJECT_WINDOW (self));
+  g_assert (IDE_IS_PROJECT_INFO (project_info));
+  g_assert (IDE_IS_PROJECT_MINER (miner));
+
+  row = create_row (self, project_info);
+
+  gtk_container_add (GTK_CONTAINER (self->listbox), row);
+}
+
+static void
+gb_project_window__miner_mine_cb (GObject      *object,
+                                  GAsyncResult *result,
+                                  gpointer      user_data)
+{
+  g_autoptr(GbProjectWindow) self = user_data;
+  IdeProjectMiner *miner = (IdeProjectMiner *)object;
+  GError *error = NULL;
+
+  g_assert (GB_IS_PROJECT_WINDOW (self));
+
+  if (!ide_project_miner_mine_finish (miner, result, &error))
+    {
+      g_warning ("%s", error->message);
+      g_clear_error (&error);
+    }
+}
+
+static void
+gb_project_window__listbox_header_cb (GtkListBoxRow *row,
+                                      GtkListBoxRow *before,
+                                      gpointer       user_data)
+{
+  g_assert (GTK_IS_LIST_BOX_ROW (row));
+  g_assert (!before || GTK_IS_LIST_BOX_ROW (before));
+
+  if (before != NULL)
+    gtk_list_box_row_set_header (row,
+                                 g_object_new (GTK_TYPE_SEPARATOR,
+                                               "orientation", GTK_ORIENTATION_HORIZONTAL,
+                                               "visible", TRUE,
+                                               NULL));
+}
+
+static gint
+gb_project_window__listbox_sort (GtkListBoxRow *row1,
+                                 GtkListBoxRow *row2,
+                                 gpointer       user_data)
+{
+  IdeProjectInfo *info1;
+  IdeProjectInfo *info2;
+  const gchar *name1;
+  const gchar *name2;
+
+  g_assert (GTK_IS_LIST_BOX_ROW (row1));
+  g_assert (GTK_IS_LIST_BOX_ROW (row2));
+
+  info1 = g_object_get_data (G_OBJECT (row1), "IDE_PROJECT_ITEM");
+  info2 = g_object_get_data (G_OBJECT (row2), "IDE_PROJECT_ITEM");
+
+  g_assert (IDE_IS_PROJECT_INFO (info1));
+  g_assert (IDE_IS_PROJECT_INFO (info2));
+
+  name1 = ide_project_info_get_name (info1);
+  name2 = ide_project_info_get_name (info2);
+
+  if (name1 == NULL)
+    return 1;
+  else if (name2 == NULL)
+    return -1;
+  else
+    return strcasecmp (name1, name2);
+}
+
+static void
+gb_project_window_constructed (GObject *object)
+{
+  GbProjectWindow *self = (GbProjectWindow *)object;
+  g_autoptr(IdeProjectMiner) miner = NULL;
+
+  miner = g_object_new (IDE_TYPE_AUTOTOOLS_PROJECT_MINER,
+                        "root-directory", NULL,
+                        NULL);
+
+  g_signal_connect_object (miner,
+                           "discovered",
+                           G_CALLBACK (gb_project_window__miner_discovered_cb),
+                           self,
+                           G_CONNECT_SWAPPED);
+
+  ide_project_miner_mine_async (miner,
+                                NULL,
+                                gb_project_window__miner_mine_cb,
+                                g_object_ref (self));
+
+  gtk_list_box_set_header_func (self->listbox,
+                                gb_project_window__listbox_header_cb,
+                                NULL, NULL);
+  gtk_list_box_set_sort_func (self->listbox,
+                              gb_project_window__listbox_sort,
+                              NULL, NULL);
+
+  G_OBJECT_CLASS (gb_project_window_parent_class)->constructed (object);
+}
+
 static void
 gb_project_window_finalize (GObject *object)
 {
@@ -84,6 +284,7 @@ gb_project_window_class_init (GbProjectWindowClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
+  object_class->constructed = gb_project_window_constructed;
   object_class->finalize = gb_project_window_finalize;
   object_class->get_property = gb_project_window_get_property;
   object_class->set_property = gb_project_window_set_property;
@@ -91,6 +292,7 @@ gb_project_window_class_init (GbProjectWindowClass *klass)
   GB_WIDGET_CLASS_TEMPLATE (klass, "gb-project-window.ui");
 
   GB_WIDGET_CLASS_BIND (klass, GbProjectWindow, listbox);
+  GB_WIDGET_CLASS_BIND (klass, GbProjectWindow, select_button);
 }
 
 static void


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