[gnome-builder/wip/project-selector: 28/66] project-selector: allow opening project
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/project-selector: 28/66] project-selector: allow opening project
- Date: Wed, 8 Apr 2015 01:05:10 +0000 (UTC)
commit 8193bf050ab264d0fa50784eb6ddfb061ef25774
Author: Christian Hergert <christian hergert me>
Date: Thu Apr 2 19:21:44 2015 -0700
project-selector: allow opening project
src/app/gb-application.c | 54 +++++++++++++++++++++++-----------
src/app/gb-application.h | 3 ++
src/dialogs/gb-new-project-dialog.c | 40 ++++++++++++++++++++++++-
3 files changed, 77 insertions(+), 20 deletions(-)
---
diff --git a/src/app/gb-application.c b/src/app/gb-application.c
index 4fe9820..67328fe 100644
--- a/src/app/gb-application.c
+++ b/src/app/gb-application.c
@@ -401,6 +401,40 @@ cleanup:
g_application_release (G_APPLICATION (self));
}
+void
+gb_application_open_project (GbApplication *self,
+ GFile *file,
+ GPtrArray *additional_files)
+{
+ g_autoptr(GFile) directory = NULL;
+ g_autoptr(GTask) task = NULL;
+ g_autoptr(GPtrArray) ar = NULL;
+
+ g_return_if_fail (GB_IS_APPLICATION (self));
+ g_return_if_fail (G_IS_FILE (file));
+
+ task = g_task_new (self, NULL, NULL, NULL);
+
+ if (additional_files)
+ ar = g_ptr_array_ref (additional_files);
+ else
+ ar = g_ptr_array_new ();
+
+ g_task_set_task_data (task, g_ptr_array_ref (ar), (GDestroyNotify)g_ptr_array_unref);
+
+ if (g_file_query_file_type (file, 0, NULL) == G_FILE_TYPE_DIRECTORY)
+ directory = g_object_ref (file);
+ else
+ directory = g_file_get_parent (file);
+
+ g_application_hold (G_APPLICATION (self));
+
+ ide_context_new_async (directory,
+ NULL,
+ gb_application__context_new_cb,
+ g_object_ref (task));
+}
+
static void
gb_application_open (GApplication *application,
GFile **files,
@@ -444,25 +478,9 @@ gb_application_open (GApplication *application,
*/
if (ar && ar->len)
{
- g_autoptr(GFile) directory = NULL;
- g_autoptr(GTask) task = NULL;
- GFile *file;
-
- task = g_task_new (self, NULL, NULL, NULL);
- g_task_set_task_data (task, g_ptr_array_ref (ar), (GDestroyNotify)g_ptr_array_unref);
-
- file = g_ptr_array_index (ar, 0);
-
- if (g_file_query_file_type (file, 0, NULL) == G_FILE_TYPE_DIRECTORY)
- directory = g_object_ref (file);
- else
- directory = g_file_get_parent (file);
+ GFile *file = g_ptr_array_index (ar, 0);
- ide_context_new_async (directory,
- NULL,
- gb_application__context_new_cb,
- g_object_ref (task));
- g_application_hold (G_APPLICATION (self));
+ gb_application_open_project (self, file, ar);
}
IDE_EXIT;
diff --git a/src/app/gb-application.h b/src/app/gb-application.h
index 93650a2..757541b 100644
--- a/src/app/gb-application.h
+++ b/src/app/gb-application.h
@@ -27,6 +27,9 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (GbApplication, gb_application, GB, APPLICATION, GtkApplication)
+void gb_application_open_project (GbApplication *self,
+ GFile *file,
+ GPtrArray *additional_files);
void gb_application_show_projects_window (GbApplication *self);
G_END_DECLS
diff --git a/src/dialogs/gb-new-project-dialog.c b/src/dialogs/gb-new-project-dialog.c
index f90628c..d47d3dc 100644
--- a/src/dialogs/gb-new-project-dialog.c
+++ b/src/dialogs/gb-new-project-dialog.c
@@ -18,12 +18,13 @@
#include <glib/gi18n.h>
+#include "gb-application.h"
#include "gb-new-project-dialog.h"
#include "gb-widget.h"
struct _GbNewProjectDialog
{
- GtkDialog parent_instance;
+ GtkDialog parent_instance;
GtkButton *back_button;
GtkButton *cancel_button;
@@ -65,6 +66,34 @@ gb_new_project_dialog__cancel_button_clicked (GbNewProjectDialog *self,
}
static void
+gb_new_project_dialog__create_button_clicked (GbNewProjectDialog *self,
+ GtkButton *cancel_button)
+{
+ GApplication *app;
+ GtkWidget *visible_child;
+
+ g_assert (GB_IS_NEW_PROJECT_DIALOG (self));
+ g_assert (GTK_IS_BUTTON (cancel_button));
+
+ app = g_application_get_default ();
+
+ visible_child = gtk_stack_get_visible_child (self->stack);
+
+ if (visible_child == GTK_WIDGET (self->file_chooser))
+ {
+ g_autoptr(GFile) file = NULL;
+
+ file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (self->file_chooser));
+
+ if (file != NULL)
+ {
+ gb_application_open_project (GB_APPLICATION (app), file, NULL);
+ gtk_window_close (GTK_WINDOW (self));
+ }
+ }
+}
+
+static void
gb_new_project_dialog__open_list_box_row_activated (GbNewProjectDialog *self,
GtkListBoxRow *row,
GtkListBox *list_box)
@@ -115,12 +144,13 @@ gb_new_project_dialog_create_filters (GbNewProjectDialog *self)
g_assert (GB_IS_NEW_PROJECT_DIALOG (self));
- /* autotools filter */
+ /* autotools filter (IdeAutotoolsBuildSystem) */
filter = gtk_file_filter_new ();
gtk_file_filter_set_name (filter, _("Autotools Project (configure.ac)"));
gtk_file_filter_add_pattern (filter, "configure.ac");
list = g_list_append (list, filter);
+ /* any directory filter (IdeDirectoryBuildSystem) */
filter = gtk_file_filter_new ();
gtk_file_filter_set_name (filter, _("Any Directory"));
gtk_file_filter_add_pattern (filter, "*");
@@ -233,6 +263,12 @@ gb_new_project_dialog_init (GbNewProjectDialog *self)
self,
G_CONNECT_SWAPPED);
+ g_signal_connect_object (self->create_button,
+ "clicked",
+ G_CALLBACK (gb_new_project_dialog__create_button_clicked),
+ self,
+ G_CONNECT_SWAPPED);
+
g_signal_connect_object (self->open_list_box,
"row-activated",
G_CALLBACK (gb_new_project_dialog__open_list_box_row_activated),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]