[gnome-builder] create-project: check that the directory is available
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] create-project: check that the directory is available
- Date: Sun, 28 Aug 2016 19:48:28 +0000 (UTC)
commit c3199e86278b7b5ddec5713c438d78f7e686f788
Author: Christian Hergert <chergert redhat com>
Date: Sun Aug 28 12:46:45 2016 -0700
create-project: check that the directory is available
This is a bit non-ideal since we do synchronous I/O to check if the
directory exists, but it solves the problem at hand for now.
https://bugzilla.gnome.org/show_bug.cgi?id=766447
plugins/create-project/gbp-create-project-widget.c | 37 +++++++++++++++++---
1 files changed, 32 insertions(+), 5 deletions(-)
---
diff --git a/plugins/create-project/gbp-create-project-widget.c
b/plugins/create-project/gbp-create-project-widget.c
index 90ee109..c915180 100644
--- a/plugins/create-project/gbp-create-project-widget.c
+++ b/plugins/create-project/gbp-create-project-widget.c
@@ -38,6 +38,8 @@ struct _GbpCreateProjectWidget
GtkFlowBox *project_template_chooser;
GtkSwitch *versioning_switch;
EggRadioBox *license_chooser;
+
+ guint invalid_directory : 1;
};
enum {
@@ -108,13 +110,30 @@ validate_name (const gchar *name)
return TRUE;
}
+static gboolean
+directory_exists (GbpCreateProjectWidget *self,
+ const gchar *name)
+{
+ g_autoptr(GFile) directory = NULL;
+ g_autoptr(GFile) child = NULL;
+
+ g_assert (GBP_IS_CREATE_PROJECT_WIDGET (self));
+ g_assert (name != NULL);
+
+ directory = egg_file_chooser_entry_get_file (self->project_location_entry);
+ child = g_file_get_child (directory, name);
+
+ self->invalid_directory = g_file_query_exists (child, NULL);
+
+ return self->invalid_directory;
+}
+
static void
gbp_create_project_widget_name_changed (GbpCreateProjectWidget *self,
GtkEntry *entry)
{
const gchar *text;
g_autofree gchar *project_name = NULL;
- g_autofree gchar *project_dir = NULL;
g_assert (GBP_IS_CREATE_PROJECT_WIDGET (self));
g_assert (GTK_IS_ENTRY (entry));
@@ -126,17 +145,22 @@ gbp_create_project_widget_name_changed (GbpCreateProjectWidget *self,
{
g_object_set (self->project_name_entry,
"secondary-icon-name", "dialog-warning-symbolic",
+ "tooltip-text", _("Characters were used which might cause technical issues as a project
name"),
+ NULL);
+ }
+ else if (directory_exists (self, project_name))
+ {
+ g_object_set (self->project_name_entry,
+ "secondary-icon-name", "dialog-warning-symbolic",
+ "tooltip-text", _("Directory already exists with that name"),
NULL);
-
- project_dir = g_strdup ("");
}
else
{
g_object_set (self->project_name_entry,
"secondary-icon-name", NULL,
+ "tooltip-text", NULL,
NULL);
-
- project_dir = g_ascii_strdown (g_strdelimit (project_name, " ", '-'), -1);
}
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_IS_READY]);
@@ -310,6 +334,9 @@ gbp_create_project_widget_is_ready (GbpCreateProjectWidget *self)
g_assert (GBP_IS_CREATE_PROJECT_WIDGET (self));
+ if (self->invalid_directory)
+ return FALSE;
+
text = gtk_entry_get_text (self->project_name_entry);
project_name = g_strstrip (g_strdup (text));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]