[gnome-builder/wip/project-selector: 8/10] project-window: load workbench when row is activated
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/project-selector: 8/10] project-window: load workbench when row is activated
- Date: Mon, 30 Mar 2015 21:54:46 +0000 (UTC)
commit dab515edf2be7472874488a49cc1680e4f4052a5
Author: Christian Hergert <christian hergert me>
Date: Mon Mar 30 00:35:25 2015 -0700
project-window: load workbench when row is activated
Not sure this is how we want to do things long term, but it sure is nice
to be able to just select a project and go.
src/workbench/gb-project-window.c | 114 ++++++++++++++++++++++++++++++++++++-
1 files changed, 111 insertions(+), 3 deletions(-)
---
diff --git a/src/workbench/gb-project-window.c b/src/workbench/gb-project-window.c
index 79c12bf..55ab520 100644
--- a/src/workbench/gb-project-window.c
+++ b/src/workbench/gb-project-window.c
@@ -24,8 +24,10 @@
#include <glib/gi18n.h>
+#include "gb-editor-document.h"
#include "gb-project-window.h"
#include "gb-widget.h"
+#include "gb-workbench.h"
struct _GbProjectWindow
{
@@ -50,6 +52,106 @@ gb_project_window_new (void)
return g_object_new (GB_TYPE_PROJECT_WINDOW, NULL);
}
+static void
+get_default_size (GtkRequisition *req)
+{
+ GdkScreen *screen;
+ GdkRectangle rect;
+ gint primary;
+
+ screen = gdk_screen_get_default ();
+ primary = gdk_screen_get_primary_monitor (screen);
+ gdk_screen_get_monitor_geometry (screen, primary, &rect);
+
+ req->width = rect.width * 0.75;
+ req->height = rect.height * 0.75;
+}
+
+static IdeBuffer *
+gb_project_window__buffer_manager_create_buffer_cb (IdeBufferManager *buffer_manager,
+ IdeFile *file,
+ IdeContext *context)
+{
+ return g_object_new (GB_TYPE_EDITOR_DOCUMENT,
+ "context", context,
+ "file", file,
+ "highlight-diagnostics", TRUE,
+ NULL);
+}
+
+static void
+gb_project_window__context_new_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ g_autoptr(GbProjectWindow) self = user_data;
+ g_autoptr(IdeContext) context = NULL;
+ GbWorkbench *workbench;
+ IdeBufferManager *bufmgr;
+ GtkRequisition req;
+ GError *error = NULL;
+
+ g_assert (GB_IS_PROJECT_WINDOW (self));
+
+ context = ide_context_new_finish (result, &error);
+
+ if (context == NULL)
+ {
+ /* TODO: error dialog */
+ g_warning ("%s", error->message);
+ g_clear_error (&error);
+ return;
+ }
+
+ bufmgr = ide_context_get_buffer_manager (context);
+ g_signal_connect (bufmgr,
+ "create-buffer",
+ G_CALLBACK (gb_project_window__buffer_manager_create_buffer_cb),
+ context);
+
+ get_default_size (&req);
+
+ workbench = g_object_new (GB_TYPE_WORKBENCH,
+ "application", g_application_get_default (),
+ "context", context,
+ "default-width", req.width,
+ "default-height", req.height,
+ "title", _("Builder"),
+ NULL);
+ gtk_window_maximize (GTK_WINDOW (workbench));
+ gtk_window_present (GTK_WINDOW (workbench));
+
+ gtk_window_close (GTK_WINDOW (self));
+}
+
+static void
+gb_project_window__listbox_row_activated_cb (GbProjectWindow *self,
+ GtkListBoxRow *row,
+ GtkListBox *listbox)
+{
+ IdeProjectInfo *project_info;
+ GFile *directory;
+ GFile *file;
+
+ g_assert (GB_IS_PROJECT_WINDOW (self));
+ g_assert (GTK_IS_LIST_BOX_ROW (row));
+ g_assert (GTK_IS_LIST_BOX (listbox));
+
+ project_info = g_object_get_data (G_OBJECT (row), "IDE_PROJECT_INFO");
+ g_assert (IDE_IS_PROJECT_INFO (project_info));
+
+ directory = ide_project_info_get_directory (project_info);
+ file = ide_project_info_get_file (project_info);
+
+ if (file != NULL)
+ directory = file;
+
+ ide_context_new_async (directory,
+ NULL,
+ gb_project_window__context_new_cb,
+ g_object_ref (self));
+}
+
static GtkWidget *
create_row (GbProjectWindow *self,
IdeProjectInfo *project_info)
@@ -74,7 +176,7 @@ create_row (GbProjectWindow *self,
"visible", TRUE,
NULL);
g_object_set_data_full (G_OBJECT (row),
- "IDE_PROJECT_ITEM",
+ "IDE_PROJECT_INFO",
g_object_ref (project_info),
g_object_unref);
@@ -193,8 +295,8 @@ gb_project_window__listbox_sort (GtkListBoxRow *row1,
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");
+ info1 = g_object_get_data (G_OBJECT (row1), "IDE_PROJECT_INFO");
+ info2 = g_object_get_data (G_OBJECT (row2), "IDE_PROJECT_INFO");
g_assert (IDE_IS_PROJECT_INFO (info1));
g_assert (IDE_IS_PROJECT_INFO (info2));
@@ -299,4 +401,10 @@ static void
gb_project_window_init (GbProjectWindow *self)
{
gtk_widget_init_template (GTK_WIDGET (self));
+
+ g_signal_connect_object (self->listbox,
+ "row-activated",
+ G_CALLBACK (gb_project_window__listbox_row_activated_cb),
+ self,
+ G_CONNECT_SWAPPED);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]