After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 763163 - add default projects directory to builder preferences
add default projects directory to builder preferences
Status: RESOLVED FIXED
Product: gnome-builder
Classification: Other
Component: general
unspecified
Other All
: Normal enhancement
: ---
Assigned To: GNOME Builder Maintainers
GNOME Builder Maintainers
Depends on:
Blocks:
 
 
Reported: 2016-03-06 05:46 UTC by Christian Hergert
Modified: 2016-03-11 23:38 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
added default projects directory to preferences (16.15 KB, patch)
2016-03-10 03:05 UTC, Akshaya Kakkilaya
none Details | Review
improved previous patch (40.25 KB, patch)
2016-03-10 20:35 UTC, Akshaya Kakkilaya
none Details | Review
added GtkFileChooserAction property (41.26 KB, patch)
2016-03-11 10:15 UTC, Akshaya Kakkilaya
committed Details | Review

Description Christian Hergert 2016-03-06 05:46:57 UTC
We should add a new preference to Builder to specify the default projects directory.

1) Add new string key "projects-directory" to org.gnome.builder gsettings schema.
2) Add a preference for this in the Projects page. (See libide/preferences/ide-prefernces-builtin.c)
3) Update the git clone widget to use this directory by default (See plugins/git/ide-git-clone-widget.c:200
4) Update the autotools project miner to mine this directory. **

** We also need to come up with a way for plugins to add additional directories to be mined. For example, the jhbuild plugin might want to add the jhbuild source checkout directory, so that those projects automatically show up (and it might be different than your projects directory).

I don't yet have a proper answer for **, which is why this is not yet implemented this way.
Comment 1 Akshaya Kakkilaya 2016-03-10 03:05:40 UTC
Created attachment 323563 [details] [review]
added default projects directory to preferences

I have implemented the setting in ide-git-clone-widget.
I will implement it in autotools in another patch.
Comment 2 Christian Hergert 2016-03-10 03:55:08 UTC
Review of attachment 323563 [details] [review]:

Mostly just coding style fixes.

::: libide/Makefile.am
@@ -416,2 +416,3 @@
 	preferences/ide-preferences-bin.c \
 	preferences/ide-preferences-bin-private.h \
+	preferences/ide-preferences-file-chooser-button.c \

Put this with the other public_headers.

::: libide/preferences/ide-preferences-builtin.c
@@ -252,2 +255,5 @@
   ide_preferences_add_page (preferences, "projects", _("Projects"), 450);
 
+  ide_preferences_add_list_group (preferences, "projects", "directory", _("Projects Directory"), 0);
+
+  widget = g_object_new (IDE_TYPE_PREFERENCES_FILE_CHOOSER_BUTTON,

I think there is a strong chance we'll need to use this again, so make a vfunc for it in IdePreferences instead of using add_custom().

Something like ide_preferences_add_file_chooser() (and then implement it in IdePreferencesPerspective to use this widget).

@@ -254,0 +257,7 @@
+  ide_preferences_add_list_group (preferences, "projects", "directory", _("Projects Directory"), 0);
+
+  widget = g_object_new (IDE_TYPE_PREFERENCES_FILE_CHOOSER_BUTTON,
... 4 more ...

I think we need to come up with better wording than "Default path"

::: libide/preferences/ide-preferences-file-chooser-button.c
@@ +1,3 @@
+/* ide-preferences-file-chooser-button.c
+ *
+ * Copyright (C) 2015 Christian Hergert <christian@hergert.me>

Nice of you to give me copyright, but this should be you.

@@ +26,3 @@
+  GSettings              *settings;
+
+  GtkFileChooserButton *widget;

alignment is off

@@ +44,3 @@
+
+static void
+ide_preferences_file_chooser_button_save_folder (IdePreferencesFileChooserButton *self,

alignment

@@ +50,3 @@
+  g_autoptr(GFile) folder = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (widget));
+  g_autofree gchar *path = g_file_get_relative_path (home, folder);
+

Our coding style is to not call functions before precondition checks. So these should be "g_autoptr(Foo) foo = NULL;", then g_assert()s, then foo = some_func ();

The one exception to this are the _get_instance_private() "functions", which are really just static inlines with interger math and are therefore safe against invalid pointers. Also, I guess we tend to ignore assertions in finalize/get_property/set_property/init.

@@ +57,3 @@
+static void
+ide_preferences_file_chooser_button_connect (IdePreferencesBin *bin,
+                                             GSettings          *settings)

alignment

@@ +60,3 @@
+{
+  IdePreferencesFileChooserButton *self = (IdePreferencesFileChooserButton *)bin;
+  g_autofree gchar *folder;

always set to NULL with autofree.

@@ +63,3 @@
+  g_autofree gchar *path;
+
+  self->settings = g_object_ref (settings);

g_assert (IDE_IS_PREFERENCES_FILE_CHOOSER (self)); before dereferencing anything.

@@ +66,3 @@
+
+  folder = g_settings_get_string (settings, self->key);
+  path = g_build_filename (g_get_home_dir (), folder, NULL);

check folder for NULL or empty string before building the filename

@@ +100,3 @@
+    case PROP_KEY:
+      g_value_set_string (value, self->key);
+      break;

newline after break;

@@ +125,3 @@
+    case PROP_KEY:
+      self->key = g_value_dup_string (value);
+      break;

same

::: libide/preferences/ide-preferences-file-chooser-button.h
@@ +1,3 @@
+/* ide-preferences-file-chooser-button.h
+ *
+ * Copyright (C) 2015 Christian Hergert <christian@hergert.me>

same

::: plugins/git/ide-git-clone-widget.c
@@ -195,2 +195,3 @@
 {
   gchar *projects_dir;
+  g_autoptr(GSettings) settings = g_settings_new ("org.gnome.builder");

Would prefer declarations separate from assignment.
Comment 3 Akshaya Kakkilaya 2016-03-10 20:35:56 UTC
Created attachment 323663 [details] [review]
improved previous patch
Comment 4 Christian Hergert 2016-03-10 22:29:56 UTC
Review of attachment 323663 [details] [review]:

Nice work! couple more things to make this more generally reusable.

::: data/ui/ide-preferences-file-chooser-button.ui
@@ +40,3 @@
+        <child>
+          <object class="GtkFileChooserButton" id="widget">
+            <property name="action">select-folder</property>

And keep this in sync with whatever the default enum value is for the action property you will add to IdePreferencesFileChooserButton.

::: libide/ide-preferences.h
@@ -102,61 +112,61 @@
-void     ide_preferences_add_page        (IdePreferences *self,
-                                          const gchar    *page_name,
-                                          const gchar    *title,
... 58 more ...
+void     ide_preferences_add_page         (IdePreferences *self,
+                                           const gchar    *page_name,
+                                           const gchar    *title,
... 58 more ...

Add a GtkFileChooserAction paramater to this so the caller can specifiy if its a  open/save/select-folder/create-folder.

::: libide/preferences/ide-preferences-file-chooser-button.c
@@ +36,3 @@
+enum {
+  PROP_0,
+  PROP_KEY,

Add PROP_ACTION which is a GTK_TYPE_FILE_CHOOSER_ACTION (GtkFileChooserAction) property. It should get/set the action property on the GtkFileChooserButton.
Comment 5 Akshaya Kakkilaya 2016-03-11 10:15:06 UTC
Created attachment 323691 [details] [review]
added GtkFileChooserAction property
Comment 6 Christian Hergert 2016-03-11 23:38:49 UTC
Thanks! Great work!