[gnome-builder] editor: close first untitled document when opening another file
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] editor: close first untitled document when opening another file
- Date: Wed, 21 Jan 2015 02:49:46 +0000 (UTC)
commit a5e58408f63bfc6f239c17636dae463711913f33
Author: Christian Hergert <christian hergert me>
Date: Tue Jan 20 18:48:36 2015 -0800
editor: close first untitled document when opening another file
This should make things feel more like we are replacing the untitled file
with the newly opened document.
src/documents/gb-document-grid.c | 41 +++++++++++++++++++++++++++++++++++++
src/documents/gb-document-grid.h | 1 +
src/documents/gb-document-stack.c | 2 +-
src/documents/gb-document-stack.h | 2 +
src/editor/gb-editor-workspace.c | 24 +++++++++++++++++++++
5 files changed, 69 insertions(+), 1 deletions(-)
---
diff --git a/src/documents/gb-document-grid.c b/src/documents/gb-document-grid.c
index 07ed2db..2bfdc8f 100644
--- a/src/documents/gb-document-grid.c
+++ b/src/documents/gb-document-grid.c
@@ -681,6 +681,47 @@ gb_document_grid_get_stack_after (GbDocumentGrid *grid,
}
void
+gb_document_grid_close_untitled (GbDocumentGrid *grid)
+{
+ GList *documents;
+ GList *diter;
+ GList *stacks;
+ GList *siter;
+
+ g_return_if_fail (GB_IS_DOCUMENT_GRID (grid));
+
+ documents = gb_document_manager_get_documents (grid->priv->document_manager);
+ stacks = gb_document_grid_get_stacks (grid);
+
+ g_list_foreach (documents, (GFunc)g_object_ref, NULL);
+ g_list_foreach (stacks, (GFunc)g_object_ref, NULL);
+
+ for (diter = documents; diter; diter = diter->next)
+ {
+ if (gb_document_get_modified (diter->data) ||
+ !gb_document_is_untitled (diter->data))
+ continue;
+
+ for (siter = stacks; siter; siter = siter->next)
+ {
+ GtkWidget *view;
+
+ view = gb_document_stack_find_with_document (siter->data,
+ diter->data);
+ if (view)
+ gb_document_stack_remove_view (siter->data,
+ GB_DOCUMENT_VIEW (view));
+ }
+ }
+
+ g_list_foreach (documents, (GFunc)g_object_unref, NULL);
+ g_list_foreach (stacks, (GFunc)g_object_unref, NULL);
+
+ g_list_free (documents);
+ g_list_free (stacks);
+}
+
+void
gb_document_grid_focus_document (GbDocumentGrid *grid,
GbDocument *document)
{
diff --git a/src/documents/gb-document-grid.h b/src/documents/gb-document-grid.h
index fd0f268..a9c73b6 100644
--- a/src/documents/gb-document-grid.h
+++ b/src/documents/gb-document-grid.h
@@ -67,6 +67,7 @@ GtkWidget *gb_document_grid_get_stack_before (GbDocumentGrid *gri
GList *gb_document_grid_get_stacks (GbDocumentGrid *grid);
void gb_document_grid_focus_document (GbDocumentGrid *grid,
GbDocument *document);
+void gb_document_grid_close_untitled (GbDocumentGrid *grid);
G_END_DECLS
diff --git a/src/documents/gb-document-stack.c b/src/documents/gb-document-stack.c
index b550bb7..7a26da8 100644
--- a/src/documents/gb-document-stack.c
+++ b/src/documents/gb-document-stack.c
@@ -68,7 +68,7 @@ gb_document_stack_new (void)
return g_object_new (GB_TYPE_DOCUMENT_STACK, NULL);
}
-static void
+void
gb_document_stack_remove_view (GbDocumentStack *stack,
GbDocumentView *view)
{
diff --git a/src/documents/gb-document-stack.h b/src/documents/gb-document-stack.h
index af26a63..011b00e 100644
--- a/src/documents/gb-document-stack.h
+++ b/src/documents/gb-document-stack.h
@@ -65,6 +65,8 @@ GType gb_document_stack_get_type (void);
GtkWidget *gb_document_stack_new (void);
void gb_document_stack_focus_document (GbDocumentStack *stack,
GbDocument *document);
+void gb_document_stack_remove_view (GbDocumentStack *stack,
+ GbDocumentView *view);
GbDocumentManager *gb_document_stack_get_document_manager (GbDocumentStack *stack);
void gb_document_stack_set_document_manager (GbDocumentStack *stack,
GbDocumentManager *manager);
diff --git a/src/editor/gb-editor-workspace.c b/src/editor/gb-editor-workspace.c
index 673684e..adda68d 100644
--- a/src/editor/gb-editor-workspace.c
+++ b/src/editor/gb-editor-workspace.c
@@ -71,12 +71,36 @@ gb_editor_workspace_open (GbEditorWorkspace *workspace,
if (!document)
{
+ gboolean close_untitled = FALSE;
+ GList *list;
+
+ /*
+ * If we have a single document open, and it is an untitled document,
+ * we want to close it so that it appears that this new document opens
+ * in its place.
+ */
+ list = gb_document_manager_get_documents (manager);
+ if ((g_list_length (list) == 1) &&
+ gb_document_is_untitled (list->data) &&
+ !gb_document_get_modified (list->data))
+ close_untitled = TRUE;
+ g_list_free (list);
+
+ /*
+ * Now open the new document.
+ */
document = GB_DOCUMENT (gb_editor_document_new ());
gb_editor_document_load_async (GB_EDITOR_DOCUMENT (document),
file, NULL, NULL, NULL);
gb_document_manager_add (manager, document);
gb_document_grid_focus_document (priv->document_grid, document);
g_object_unref (document);
+
+ /*
+ * Now close the existing views if necessary.
+ */
+ if (close_untitled)
+ gb_document_grid_close_untitled (priv->document_grid);
}
else
gb_document_grid_focus_document (priv->document_grid, document);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]