[gnome-builder] preferences: default project directory setting



commit dcce6b83bed32ba45ea11a558becf593d305cba6
Author: Akshaya Kakkilaya <akshaya kakkilaya gmail com>
Date:   Thu Mar 10 08:17:12 2016 +0530

    preferences: default project directory setting
    
    the default directory for creating new projects can be set in
    preferences
    
    https://bugzilla.gnome.org/show_bug.cgi?id=763163

 data/gsettings/org.gnome.builder.gschema.xml       |    5 +
 data/ui/ide-preferences-file-chooser-button.ui     |   49 ++++
 libide/Makefile.am                                 |    2 +
 libide/ide-preferences.c                           |   23 ++
 libide/ide-preferences.h                           |  282 +++++++++++---------
 libide/preferences/ide-preferences-builtin.c       |    3 +
 .../ide-preferences-file-chooser-button.c          |  246 +++++++++++++++++
 .../ide-preferences-file-chooser-button.h          |   32 +++
 libide/preferences/ide-preferences-perspective.c   |   65 +++++
 libide/resources/libide.gresource.xml              |    1 +
 plugins/git/ide-git-clone-widget.c                 |   16 +-
 11 files changed, 590 insertions(+), 134 deletions(-)
---
diff --git a/data/gsettings/org.gnome.builder.gschema.xml b/data/gsettings/org.gnome.builder.gschema.xml
index 1f6bdcc..95f1f25 100644
--- a/data/gsettings/org.gnome.builder.gschema.xml
+++ b/data/gsettings/org.gnome.builder.gschema.xml
@@ -25,5 +25,10 @@
       <summary>Mine projects</summary>
       <description>Search directories for projects.</description>
     </key>
+    <key name="projects-directory" type="s">
+      <default>"Projects"</default>
+      <summary>Projects directory</summary>
+      <description>Directory for all builder projects</description>
+    </key>
   </schema>
 </schemalist>
diff --git a/data/ui/ide-preferences-file-chooser-button.ui b/data/ui/ide-preferences-file-chooser-button.ui
new file mode 100644
index 0000000..53ec340
--- /dev/null
+++ b/data/ui/ide-preferences-file-chooser-button.ui
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.18 -->
+  <template class="IdePreferencesFileChooserButton" parent="IdePreferencesBin">
+    <child>
+      <object class="GtkBox">
+        <property name="orientation">horizontal</property>
+        <property name="expand">true</property>
+        <property name="spacing">12</property>
+        <property name="visible">true</property>
+        <child>
+          <object class="GtkBox">
+            <property name="orientation">vertical</property>
+            <property name="expand">true</property>
+            <property name="visible">true</property>
+            <child>
+              <object class="GtkLabel" id="title">
+                <property name="vexpand">true</property>
+                <property name="halign">start</property>
+                <property name="visible">true</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkLabel" id="subtitle">
+                <property name="vexpand">true</property>
+                <property name="halign">start</property>
+                <property name="visible">true</property>
+                <style>
+                  <class name="dim-label"/>
+                </style>
+                <attributes>
+                  <attribute name="scale" value="0.83333"/>
+                </attributes>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkFileChooserButton" id="widget">
+            <property name="expand">true</property>
+            <property name="halign">end</property>
+            <property name="valign">center</property>
+            <property name="visible">true</property>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/libide/Makefile.am b/libide/Makefile.am
index 0159ee5..bf6145b 100644
--- a/libide/Makefile.am
+++ b/libide/Makefile.am
@@ -143,6 +143,7 @@ libide_1_0_la_public_headers = \
        local/ide-local-device.h \
        preferences/ide-preferences-bin.h \
        preferences/ide-preferences-entry.h \
+       preferences/ide-preferences-file-chooser-button.h \
        preferences/ide-preferences-flow-box.h \
        preferences/ide-preferences-font-button.h \
        preferences/ide-preferences-group.h \
@@ -293,6 +294,7 @@ libide_1_0_la_public_sources = \
        ide.c \
        local/ide-local-device.c \
        preferences/ide-preferences-entry.c \
+       preferences/ide-preferences-file-chooser-button.c \
        preferences/ide-preferences-flow-box.c \
        preferences/ide-preferences-font-button.c \
        preferences/ide-preferences-group.c \
diff --git a/libide/ide-preferences.c b/libide/ide-preferences.c
index 0a8f8f5..0d13d91 100644
--- a/libide/ide-preferences.c
+++ b/libide/ide-preferences.c
@@ -180,6 +180,29 @@ ide_preferences_add_font_button (IdePreferences *self,
   return IDE_PREFERENCES_GET_IFACE (self)->add_font_button (self, page_name, group_name, schema_id, key, 
title, keywords, priority);
 }
 
+guint
+ide_preferences_add_file_chooser (IdePreferences      *self,
+                                  const gchar         *page_name,
+                                  const gchar         *group_name,
+                                  const gchar         *schema_id,
+                                  const gchar         *key,
+                                  const gchar         *path,
+                                  const gchar         *title,
+                                  const gchar         *subtitle,
+                                  GtkFileChooserAction action,
+                                  const gchar         *keywords,
+                                  gint                 priority)
+{
+  g_return_val_if_fail (IDE_IS_PREFERENCES (self), 0);
+  g_return_val_if_fail (page_name != NULL, 0);
+  g_return_val_if_fail (group_name != NULL, 0);
+  g_return_val_if_fail (schema_id != NULL, 0);
+  g_return_val_if_fail (key != NULL, 0);
+  g_return_val_if_fail (title != NULL, 0);
+
+  return IDE_PREFERENCES_GET_IFACE (self)->add_file_chooser (self, page_name, group_name, schema_id, key, 
path, title, subtitle, action, keywords, priority);
+}
+
 /**
  * ide_preference_remove_id:
  * @widget_id: An preferences widget id
diff --git a/libide/ide-preferences.h b/libide/ide-preferences.h
index a4b9362..3e08465 100644
--- a/libide/ide-preferences.h
+++ b/libide/ide-preferences.h
@@ -31,139 +31,161 @@ struct _IdePreferencesInterface
 {
   GTypeInterface parent_interface;
 
-  void     (*set_page)        (IdePreferences *self,
-                               const gchar    *page_name,
-                               GHashTable     *map);
-  void     (*add_page)        (IdePreferences *self,
-                               const gchar    *page_name,
-                               const gchar    *title,
-                               gint            priority);
-  void     (*add_group)       (IdePreferences *self,
-                               const gchar    *page_name,
-                               const gchar    *group_name,
-                               const gchar    *title,
-                               gint            priority);
-  void     (*add_list_group ) (IdePreferences *self,
-                               const gchar    *page_name,
-                               const gchar    *group_name,
-                               const gchar    *title,
-                               gint            priority);
-  guint    (*add_radio)       (IdePreferences *self,
-                               const gchar    *page_name,
-                               const gchar    *group_name,
-                               const gchar    *schema_id,
-                               const gchar    *key,
-                               const gchar    *path,
-                               const gchar    *variant_string,
-                               const gchar    *title,
-                               const gchar    *subtitle,
-                               const gchar    *keywords,
-                               gint            priority);
-  guint    (*add_font_button) (IdePreferences *self,
-                               const gchar    *page_name,
-                               const gchar    *group_name,
-                               const gchar    *schema_id,
-                               const gchar    *key,
-                               const gchar    *title,
-                               const gchar    *keywords,
-                               gint            priority);
-  guint    (*add_switch)      (IdePreferences *self,
-                               const gchar    *page_name,
-                               const gchar    *group_name,
-                               const gchar    *schema_id,
-                               const gchar    *key,
-                               const gchar    *path,
-                               const gchar    *variant_string,
-                               const gchar    *title,
-                               const gchar    *subtitle,
-                               const gchar    *keywords,
-                               gint            priority);
-  guint    (*add_spin_button) (IdePreferences *self,
-                               const gchar    *page_name,
-                               const gchar    *group_name,
-                               const gchar    *schema_id,
-                               const gchar    *key,
-                               const gchar    *path,
-                               const gchar    *title,
-                               const gchar    *subtitle,
-                               const gchar    *keywords,
-                               gint            priority);
-  guint    (*add_custom)      (IdePreferences *self,
-                               const gchar    *page_name,
-                               const gchar    *group_name,
-                               GtkWidget      *widget,
-                               const gchar    *keywords,
-                               gint            priority);
+  void     (*set_page)         (IdePreferences *self,
+                                const gchar    *page_name,
+                                GHashTable     *map);
+  void     (*add_page)         (IdePreferences *self,
+                                const gchar    *page_name,
+                                const gchar    *title,
+                                gint            priority);
+  void     (*add_group)        (IdePreferences *self,
+                                const gchar    *page_name,
+                                const gchar    *group_name,
+                                const gchar    *title,
+                                gint            priority);
+  void     (*add_list_group )  (IdePreferences *self,
+                                const gchar    *page_name,
+                                const gchar    *group_name,
+                                const gchar    *title,
+                                gint            priority);
+  guint    (*add_radio)        (IdePreferences *self,
+                                const gchar    *page_name,
+                                const gchar    *group_name,
+                                const gchar    *schema_id,
+                                const gchar    *key,
+                                const gchar    *path,
+                                const gchar    *variant_string,
+                                const gchar    *title,
+                                const gchar    *subtitle,
+                                const gchar    *keywords,
+                                gint            priority);
+  guint    (*add_font_button)  (IdePreferences *self,
+                                const gchar    *page_name,
+                                const gchar    *group_name,
+                                const gchar    *schema_id,
+                                const gchar    *key,
+                                const gchar    *title,
+                                const gchar    *keywords,
+                                gint            priority);
+  guint    (*add_switch)       (IdePreferences *self,
+                                const gchar    *page_name,
+                                const gchar    *group_name,
+                                const gchar    *schema_id,
+                                const gchar    *key,
+                                const gchar    *path,
+                                const gchar    *variant_string,
+                                const gchar    *title,
+                                const gchar    *subtitle,
+                                const gchar    *keywords,
+                                gint            priority);
+  guint    (*add_spin_button)  (IdePreferences *self,
+                                const gchar    *page_name,
+                                const gchar    *group_name,
+                                const gchar    *schema_id,
+                                const gchar    *key,
+                                const gchar    *path,
+                                const gchar    *title,
+                                const gchar    *subtitle,
+                                const gchar    *keywords,
+                                gint            priority);
+  guint    (*add_file_chooser) (IdePreferences      *self,
+                                const gchar         *page_name,
+                                const gchar         *group_name,
+                                const gchar         *schema_id,
+                                const gchar         *key,
+                                const gchar         *path,
+                                const gchar         *title,
+                                const gchar         *subtitle,
+                                GtkFileChooserAction action,
+                                const gchar         *keywords,
+                                gint                 priority);
+  guint    (*add_custom)       (IdePreferences *self,
+                                const gchar    *page_name,
+                                const gchar    *group_name,
+                                GtkWidget      *widget,
+                                const gchar    *keywords,
+                                gint            priority);
 
-  gboolean (*remove_id)       (IdePreferences *self,
-                               guint           widget_id);
+  gboolean (*remove_id)        (IdePreferences *self,
+                                guint           widget_id);
 };
 
-void     ide_preferences_add_page        (IdePreferences *self,
-                                          const gchar    *page_name,
-                                          const gchar    *title,
-                                          gint            priority);
-void     ide_preferences_add_group       (IdePreferences *self,
-                                          const gchar    *page_name,
-                                          const gchar    *group_name,
-                                          const gchar    *title,
-                                          gint            priority);
-void     ide_preferences_add_list_group  (IdePreferences *self,
-                                          const gchar    *page_name,
-                                          const gchar    *group_name,
-                                          const gchar    *title,
-                                          gint            priority);
-guint    ide_preferences_add_radio       (IdePreferences *self,
-                                          const gchar    *page_name,
-                                          const gchar    *group_name,
-                                          const gchar    *schema_id,
-                                          const gchar    *key,
-                                          const gchar    *path,
-                                          const gchar    *variant_string,
-                                          const gchar    *title,
-                                          const gchar    *subtitle,
-                                          const gchar    *keywords,
-                                          gint            priority);
-guint    ide_preferences_add_switch      (IdePreferences *self,
-                                          const gchar    *page_name,
-                                          const gchar    *group_name,
-                                          const gchar    *schema_id,
-                                          const gchar    *key,
-                                          const gchar    *path,
-                                          const gchar    *variant_string,
-                                          const gchar    *title,
-                                          const gchar    *subtitle,
-                                          const gchar    *keywords,
-                                          gint            priority);
-guint    ide_preferences_add_spin_button (IdePreferences *self,
-                                          const gchar    *page_name,
-                                          const gchar    *group_name,
-                                          const gchar    *schema_id,
-                                          const gchar    *key,
-                                          const gchar    *path,
-                                          const gchar    *title,
-                                          const gchar    *subtitle,
-                                          const gchar    *keywords,
-                                          gint            priority);
-guint    ide_preferences_add_custom      (IdePreferences *self,
-                                          const gchar    *page_name,
-                                          const gchar    *group_name,
-                                          GtkWidget      *widget,
-                                          const gchar    *keywords,
-                                          gint            priority);
-guint    ide_preferences_add_font_button (IdePreferences *self,
-                                          const gchar    *page_name,
-                                          const gchar    *group_name,
-                                          const gchar    *schema_id,
-                                          const gchar    *key,
-                                          const gchar    *title,
-                                          const gchar    *keywords,
-                                          gint            priority);
-gboolean ide_preferences_remove_id       (IdePreferences *self,
-                                          guint           widget_id);
-void     ide_preferences_set_page        (IdePreferences *self,
-                                          const gchar    *page_name,
-                                          GHashTable     *map);
+void     ide_preferences_add_page         (IdePreferences *self,
+                                           const gchar    *page_name,
+                                           const gchar    *title,
+                                           gint            priority);
+void     ide_preferences_add_group        (IdePreferences *self,
+                                           const gchar    *page_name,
+                                           const gchar    *group_name,
+                                           const gchar    *title,
+                                           gint            priority);
+void     ide_preferences_add_list_group   (IdePreferences *self,
+                                           const gchar    *page_name,
+                                           const gchar    *group_name,
+                                           const gchar    *title,
+                                           gint            priority);
+guint    ide_preferences_add_radio        (IdePreferences *self,
+                                           const gchar    *page_name,
+                                           const gchar    *group_name,
+                                           const gchar    *schema_id,
+                                           const gchar    *key,
+                                           const gchar    *path,
+                                           const gchar    *variant_string,
+                                           const gchar    *title,
+                                           const gchar    *subtitle,
+                                           const gchar    *keywords,
+                                           gint            priority);
+guint    ide_preferences_add_switch       (IdePreferences *self,
+                                           const gchar    *page_name,
+                                           const gchar    *group_name,
+                                           const gchar    *schema_id,
+                                           const gchar    *key,
+                                           const gchar    *path,
+                                           const gchar    *variant_string,
+                                           const gchar    *title,
+                                           const gchar    *subtitle,
+                                           const gchar    *keywords,
+                                           gint            priority);
+guint    ide_preferences_add_spin_button  (IdePreferences *self,
+                                           const gchar    *page_name,
+                                           const gchar    *group_name,
+                                           const gchar    *schema_id,
+                                           const gchar    *key,
+                                           const gchar    *path,
+                                           const gchar    *title,
+                                           const gchar    *subtitle,
+                                           const gchar    *keywords,
+                                           gint            priority);
+guint    ide_preferences_add_custom       (IdePreferences *self,
+                                           const gchar    *page_name,
+                                           const gchar    *group_name,
+                                           GtkWidget      *widget,
+                                           const gchar    *keywords,
+                                           gint            priority);
+guint    ide_preferences_add_font_button  (IdePreferences *self,
+                                           const gchar    *page_name,
+                                           const gchar    *group_name,
+                                           const gchar    *schema_id,
+                                           const gchar    *key,
+                                           const gchar    *title,
+                                           const gchar    *keywords,
+                                           gint            priority);
+guint    ide_preferences_add_file_chooser (IdePreferences      *self,
+                                           const gchar         *page_name,
+                                           const gchar         *group_name,
+                                           const gchar         *schema_id,
+                                           const gchar         *key,
+                                           const gchar         *path,
+                                           const gchar         *title,
+                                           const gchar         *subtitle,
+                                           GtkFileChooserAction action,
+                                           const gchar         *keywords,
+                                           gint                 priority);
+gboolean ide_preferences_remove_id        (IdePreferences *self,
+                                           guint           widget_id);
+void     ide_preferences_set_page         (IdePreferences *self,
+                                           const gchar    *page_name,
+                                           GHashTable     *map);
 
 
 G_END_DECLS
diff --git a/libide/preferences/ide-preferences-builtin.c b/libide/preferences/ide-preferences-builtin.c
index 5da219e..4064082 100644
--- a/libide/preferences/ide-preferences-builtin.c
+++ b/libide/preferences/ide-preferences-builtin.c
@@ -251,6 +251,9 @@ ide_preferences_builtin_register_projects (IdePreferences *preferences)
 {
   ide_preferences_add_page (preferences, "projects", _("Projects"), 450);
 
+  ide_preferences_add_list_group (preferences, "projects", "directory", _("Workspace"), 0);
+  ide_preferences_add_file_chooser (preferences, "projects", "directory", "org.gnome.builder", 
"projects-directory", NULL, _("Projects Directory"), _("A place for all your projects"), 
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, NULL, 0);
+
   ide_preferences_add_list_group (preferences, "projects", "discovery", _("Project Discovery"), 0);
   ide_preferences_add_switch (preferences, "projects", "discovery", "org.gnome.builder", 
"enable-project-miners", NULL, NULL, _("Discover projects on my computer"), _("Scan your computer for 
existing projects"), NULL, 0);
 }
diff --git a/libide/preferences/ide-preferences-file-chooser-button.c 
b/libide/preferences/ide-preferences-file-chooser-button.c
new file mode 100644
index 0000000..277bb4a
--- /dev/null
+++ b/libide/preferences/ide-preferences-file-chooser-button.c
@@ -0,0 +1,246 @@
+/* ide-preferences-file-chooser-button.c
+ *
+ * Copyright (C) 2016 Akshaya Kakkilaya <akshaya kakkilaya gmail 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-macros.h"
+#include "ide-preferences-file-chooser-button.h"
+
+struct _IdePreferencesFileChooserButton
+{
+  IdePreferencesBin    parent_instance;
+
+  gchar                *key;
+  GSettings            *settings;
+
+  GtkFileChooserButton *widget;
+  GtkLabel             *title;
+  GtkLabel             *subtitle;
+};
+
+G_DEFINE_TYPE (IdePreferencesFileChooserButton, ide_preferences_file_chooser_button, 
IDE_TYPE_PREFERENCES_BIN)
+
+enum {
+  PROP_0,
+  PROP_ACTION,
+  PROP_KEY,
+  PROP_SUBTITLE,
+  PROP_TITLE,
+  LAST_PROP
+};
+
+static GParamSpec *properties [LAST_PROP];
+
+static void
+ide_preferences_file_chooser_button_save_folder (IdePreferencesFileChooserButton *self,
+                                                 GtkFileChooserButton            *widget)
+{
+  g_autoptr(GFile) home = NULL;
+  g_autoptr(GFile) folder = NULL;
+  g_autofree gchar *path = NULL;
+
+  g_assert (IDE_IS_PREFERENCES_FILE_CHOOSER_BUTTON (self));
+  g_assert (GTK_IS_FILE_CHOOSER_BUTTON (widget));
+
+  home = g_file_new_for_path (g_get_home_dir ());
+  folder = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (widget));
+  path = g_file_get_relative_path (home, folder);
+
+  g_settings_set_string (self->settings, self->key, path);
+
+}
+
+static void
+ide_preferences_file_chooser_button_connect (IdePreferencesBin *bin,
+                                             GSettings         *settings)
+{
+  IdePreferencesFileChooserButton *self = (IdePreferencesFileChooserButton *)bin;
+  g_autofree gchar *folder = NULL;
+  g_autofree gchar *path = NULL;
+
+  g_assert (IDE_IS_PREFERENCES_FILE_CHOOSER_BUTTON (self));
+  g_assert (G_IS_SETTINGS (settings));
+
+  self->settings = g_object_ref (settings);
+
+  folder = g_settings_get_string (settings, self->key);
+
+  if (!ide_str_empty0 (folder))
+    {
+      path = g_build_filename (g_get_home_dir (), folder, NULL);
+      gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (self->widget), path);
+    }
+
+  g_signal_connect_object (self->widget,
+                           "file-set",
+                           G_CALLBACK (ide_preferences_file_chooser_button_save_folder),
+                           self,
+                           G_CONNECT_SWAPPED);
+}
+
+static gboolean
+ide_preferences_file_chooser_button_matches (IdePreferencesBin *bin,
+                                             IdePatternSpec    *spec)
+{
+  IdePreferencesFileChooserButton *self = (IdePreferencesFileChooserButton *)bin;
+  const gchar *tmp;
+
+  g_assert (IDE_IS_PREFERENCES_FILE_CHOOSER_BUTTON (self));
+  g_assert (spec != NULL);
+
+  tmp = gtk_label_get_label (self->title);
+  if (tmp && ide_pattern_spec_match (spec, tmp))
+    return TRUE;
+
+  tmp = gtk_label_get_label (self->subtitle);
+  if (tmp && ide_pattern_spec_match (spec, tmp))
+    return TRUE;
+
+  if (self->key && ide_pattern_spec_match (spec, self->key))
+    return TRUE;
+
+  return FALSE;
+}
+
+static void
+ide_preferences_file_chooser_button_finalize (GObject *object)
+{
+  IdePreferencesFileChooserButton *self = (IdePreferencesFileChooserButton *)object;
+
+  g_clear_pointer (&self->key, g_free);
+  g_clear_object (&self->settings);
+
+  G_OBJECT_CLASS (ide_preferences_file_chooser_button_parent_class)->finalize (object);
+}
+
+static void
+ide_preferences_file_chooser_button_get_property (GObject    *object,
+                                                  guint       prop_id,
+                                                  GValue     *value,
+                                                  GParamSpec *pspec)
+{
+  IdePreferencesFileChooserButton *self = IDE_PREFERENCES_FILE_CHOOSER_BUTTON (object);
+
+  switch (prop_id)
+    {
+    case PROP_ACTION:
+      g_value_set_enum (value, gtk_file_chooser_get_action (GTK_FILE_CHOOSER (self->widget)));
+      break;
+
+    case PROP_KEY:
+      g_value_set_string (value, self->key);
+      break;
+
+    case PROP_TITLE:
+      g_value_set_string (value, gtk_label_get_label (self->title));
+      break;
+
+    case PROP_SUBTITLE:
+      g_value_set_string (value, gtk_label_get_label (self->title));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_preferences_file_chooser_button_set_property (GObject      *object,
+                                                  guint         prop_id,
+                                                  const GValue *value,
+                                                  GParamSpec   *pspec)
+{
+  IdePreferencesFileChooserButton *self = IDE_PREFERENCES_FILE_CHOOSER_BUTTON (object);
+
+  switch (prop_id)
+    {
+    case PROP_ACTION:
+      gtk_file_chooser_set_action (GTK_FILE_CHOOSER (self->widget), g_value_get_enum (value));
+      break;
+
+    case PROP_KEY:
+      self->key = g_value_dup_string (value);
+      break;
+
+    case PROP_TITLE:
+      gtk_label_set_label (self->title, g_value_get_string (value));
+      break;
+
+    case PROP_SUBTITLE:
+      gtk_label_set_label (self->subtitle, g_value_get_string (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_preferences_file_chooser_button_class_init (IdePreferencesFileChooserButtonClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+  IdePreferencesBinClass *bin_class = IDE_PREFERENCES_BIN_CLASS (klass);
+
+  object_class->finalize = ide_preferences_file_chooser_button_finalize;
+  object_class->get_property = ide_preferences_file_chooser_button_get_property;
+  object_class->set_property = ide_preferences_file_chooser_button_set_property;
+
+  bin_class->connect = ide_preferences_file_chooser_button_connect;
+  bin_class->matches = ide_preferences_file_chooser_button_matches;
+
+  properties [PROP_ACTION] =
+    g_param_spec_enum ("action",
+                       "Action",
+                       "Action",
+                       GTK_TYPE_FILE_CHOOSER_ACTION,
+                       GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+                       (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+
+  properties [PROP_KEY] =
+    g_param_spec_string ("key",
+                         "Key",
+                         "Key",
+                         NULL,
+                         (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+
+  properties [PROP_TITLE] =
+    g_param_spec_string ("title",
+                         "Title",
+                         "Title",
+                         NULL,
+                         (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+
+  properties [PROP_SUBTITLE] =
+    g_param_spec_string ("subtitle",
+                         "Subtitle",
+                         "Subtitle",
+                         NULL,
+                         (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_properties (object_class, LAST_PROP, properties);
+
+  gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/builder/ui/ide-preferences-file-chooser-button.ui");
+  gtk_widget_class_bind_template_child (widget_class, IdePreferencesFileChooserButton, widget);
+  gtk_widget_class_bind_template_child (widget_class, IdePreferencesFileChooserButton, title);
+  gtk_widget_class_bind_template_child (widget_class, IdePreferencesFileChooserButton, subtitle);
+}
+
+static void
+ide_preferences_file_chooser_button_init (IdePreferencesFileChooserButton *self)
+{
+  gtk_widget_init_template (GTK_WIDGET (self));
+}
diff --git a/libide/preferences/ide-preferences-file-chooser-button.h 
b/libide/preferences/ide-preferences-file-chooser-button.h
new file mode 100644
index 0000000..853f407
--- /dev/null
+++ b/libide/preferences/ide-preferences-file-chooser-button.h
@@ -0,0 +1,32 @@
+/* ide-preferences-file-chooser-button.h
+ *
+ * Copyright (C) 2016 Akshaya Kakkilaya <akshaya kakkilaya gmail 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 IDE_PREFERENCES_FILE_CHOOSER_BUTTON_H
+#define IDE_PREFERENCES_FILE_CHOOSER_BUTTON_H
+
+#include "ide-preferences-bin.h"
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_PREFERENCES_FILE_CHOOSER_BUTTON (ide_preferences_file_chooser_button_get_type())
+
+G_DECLARE_FINAL_TYPE (IdePreferencesFileChooserButton, ide_preferences_file_chooser_button, IDE, 
PREFERENCES_FILE_CHOOSER_BUTTON, IdePreferencesBin)
+
+G_END_DECLS
+
+#endif /* IDE_PREFERENCES_FILE_CHOOSER_BUTTON_H */
diff --git a/libide/preferences/ide-preferences-perspective.c 
b/libide/preferences/ide-preferences-perspective.c
index e862e21..09c9fdc 100644
--- a/libide/preferences/ide-preferences-perspective.c
+++ b/libide/preferences/ide-preferences-perspective.c
@@ -27,6 +27,7 @@
 #include "ide-preferences.h"
 #include "ide-preferences-addin.h"
 #include "ide-preferences-builtin.h"
+#include "ide-preferences-file-chooser-button.h"
 #include "ide-preferences-font-button.h"
 #include "ide-preferences-group.h"
 #include "ide-preferences-page.h"
@@ -685,6 +686,69 @@ ide_preferences_perspective_add_font_button (IdePreferences *preferences,
 }
 
 static guint
+ide_preferences_perspective_add_file_chooser (IdePreferences      *preferences,
+                                              const gchar         *page_name,
+                                              const gchar         *group_name,
+                                              const gchar         *schema_id,
+                                              const gchar         *key,
+                                              const gchar         *path,
+                                              const gchar         *title,
+                                              const gchar         *subtitle,
+                                              GtkFileChooserAction action,
+                                              const gchar         *keywords,
+                                              gint                 priority)
+{
+  IdePreferencesPerspective *self = (IdePreferencesPerspective *)preferences;
+  IdePreferencesFileChooserButton *widget;
+  IdePreferencesGroup *group;
+  GtkWidget *page;
+  guint widget_id;
+
+  g_assert (IDE_IS_PREFERENCES_PERSPECTIVE (self));
+  g_assert (page_name != NULL);
+  g_assert (group_name != NULL);
+  g_assert (schema_id != NULL);
+  g_assert (key != NULL);
+  g_assert (title != NULL);
+
+  page = ide_preferences_perspective_get_page (self, page_name);
+
+  if (page == NULL)
+    {
+      g_warning ("No page named \"%s\" could be found.", page_name);
+      return 0;
+    }
+
+  group = ide_preferences_page_get_group (IDE_PREFERENCES_PAGE (page), group_name);
+
+  if (group == NULL)
+    {
+      g_warning ("No such preferences group \"%s\" in page \"%s\"",
+                 group_name, page_name);
+      return 0;
+    }
+
+  widget = g_object_new (IDE_TYPE_PREFERENCES_FILE_CHOOSER_BUTTON,
+                         "action", action,
+                         "key", key,
+                         "priority", priority,
+                         "schema-id", schema_id,
+                         "path", path,
+                         "subtitle", subtitle,
+                         "title", title,
+                         "keywords", keywords,
+                         "visible", TRUE,
+                         NULL);
+
+  ide_preferences_group_add (group, GTK_WIDGET (widget));
+
+  widget_id = ++self->last_widget_id;
+  g_hash_table_insert (self->widgets, GINT_TO_POINTER (widget_id), widget);
+
+  return widget_id;
+}
+
+static guint
 ide_preferences_perspective_add_custom (IdePreferences *preferences,
                                         const gchar    *page_name,
                                         const gchar    *group_name,
@@ -806,6 +870,7 @@ ide_preferences_iface_init (IdePreferencesInterface *iface)
   iface->add_font_button = ide_preferences_perspective_add_font_button;
   iface->add_switch = ide_preferences_perspective_add_switch;
   iface->add_spin_button = ide_preferences_perspective_add_spin_button;
+  iface->add_file_chooser = ide_preferences_perspective_add_file_chooser;
   iface->add_custom = ide_preferences_perspective_add_custom;
   iface->set_page = ide_preferences_perspective_set_page;
   iface->remove_id = ide_preferences_perspective_remove_id;
diff --git a/libide/resources/libide.gresource.xml b/libide/resources/libide.gresource.xml
index cb159c4..be892d8 100644
--- a/libide/resources/libide.gresource.xml
+++ b/libide/resources/libide.gresource.xml
@@ -65,6 +65,7 @@
     <file compressed="true" alias="ide-omni-search-group.ui">../../data/ui/ide-omni-search-group.ui</file>
     <file compressed="true" alias="ide-omni-search-row.ui">../../data/ui/ide-omni-search-row.ui</file>
     <file compressed="true" alias="ide-preferences-entry.ui">../../data/ui/ide-preferences-entry.ui</file>
+    <file compressed="true" 
alias="ide-preferences-file-chooser-button.ui">../../data/ui/ide-preferences-file-chooser-button.ui</file>
     <file compressed="true" 
alias="ide-preferences-font-button.ui">../../data/ui/ide-preferences-font-button.ui</file>
     <file compressed="true" alias="ide-preferences-group.ui">../../data/ui/ide-preferences-group.ui</file>
     <file compressed="true" 
alias="ide-preferences-language-row.ui">../../data/ui/ide-preferences-language-row.ui</file>
diff --git a/plugins/git/ide-git-clone-widget.c b/plugins/git/ide-git-clone-widget.c
index da60e88..0c685bb 100644
--- a/plugins/git/ide-git-clone-widget.c
+++ b/plugins/git/ide-git-clone-widget.c
@@ -22,6 +22,7 @@
 
 #include "egg-animation.h"
 
+#include "ide-macros.h"
 #include "ide-git-clone-widget.h"
 #include "ide-git-remote-callbacks.h"
 
@@ -193,14 +194,21 @@ ide_git_clone_widget_class_init (IdeGitCloneWidgetClass *klass)
 static void
 ide_git_clone_widget_init (IdeGitCloneWidget *self)
 {
-  gchar *projects_dir;
+  g_autoptr(GSettings) settings = NULL;
+  g_autofree gchar *path = NULL;
+  g_autofree gchar *projects_dir = NULL;
 
   gtk_widget_init_template (GTK_WIDGET (self));
 
-  projects_dir = g_build_filename (g_get_home_dir (), _("Projects"), NULL);
-  gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (self->clone_location_button),
+  settings = g_settings_new ("org.gnome.builder");
+  path = g_settings_get_string (settings, "projects-directory");
+
+  if (!ide_str_empty0 (path))
+    {
+      projects_dir = g_build_filename (g_get_home_dir (), path, NULL);
+      gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (self->clone_location_button),
                                        projects_dir);
-  g_free (projects_dir);
+    }
 
   g_signal_connect_object (self->clone_uri_entry,
                            "changed",



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