[gnome-builder] libide: Add a GFile parameter when creating splits
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] libide: Add a GFile parameter when creating splits
- Date: Fri, 17 Jun 2016 19:09:33 +0000 (UTC)
commit 6236ebc7c91b57a40ac1012576b09b97648a21e5
Author: Matthew Leeds <mleeds redhat com>
Date: Fri Jun 10 21:10:31 2016 -0400
libide: Add a GFile parameter when creating splits
Builder only allows splits (vertical or horizontal) that load the same
buffer as the existing view. This commit adds a GFile parameter to
ide_layout_view_create_split in order to allow a different file to be
loaded (if it's buffer has already been loaded).
https://bugzilla.gnome.org/show_bug.cgi?id=767540
libide/editor/ide-editor-view.c | 24 ++++++++++++++++++++++--
libide/workbench/ide-layout-grid.c | 5 +++--
libide/workbench/ide-layout-stack-actions.c | 18 +++++++++++++-----
libide/workbench/ide-layout-stack.c | 7 +++++--
libide/workbench/ide-layout-view.c | 11 +++++++----
libide/workbench/ide-layout-view.h | 6 ++++--
plugins/devhelp/gbp-devhelp-view.c | 3 ++-
plugins/terminal/gb-terminal-view.c | 3 ++-
8 files changed, 58 insertions(+), 19 deletions(-)
---
diff --git a/libide/editor/ide-editor-view.c b/libide/editor/ide-editor-view.c
index d7e4b02..a06db40 100644
--- a/libide/editor/ide-editor-view.c
+++ b/libide/editor/ide-editor-view.c
@@ -403,15 +403,35 @@ ide_editor_view_set_document (IdeEditorView *self,
}
static IdeLayoutView *
-ide_editor_view_create_split (IdeLayoutView *view)
+ide_editor_view_create_split (IdeLayoutView *view,
+ GFile *file)
{
IdeEditorView *self = (IdeEditorView *)view;
IdeLayoutView *ret;
+ IdeBuffer *buffer;
+ IdeContext *context;
+ IdeBufferManager *buf_mgr;
g_assert (IDE_IS_EDITOR_VIEW (self));
+ if (file == NULL)
+ {
+ buffer = self->document;
+ }
+ else
+ {
+ context = ide_buffer_get_context (self->document);
+ buf_mgr = ide_context_get_buffer_manager (context);
+ buffer = ide_buffer_manager_find_buffer (buf_mgr, file);
+ if (buffer == NULL)
+ {
+ g_warning ("Failed to find buffer for file '%s'", g_file_get_path (file));
+ buffer = self->document;
+ }
+ }
+
ret = g_object_new (IDE_TYPE_EDITOR_VIEW,
- "document", self->document,
+ "document", buffer,
"visible", TRUE,
NULL);
diff --git a/libide/workbench/ide-layout-grid.c b/libide/workbench/ide-layout-grid.c
index 3b7c8ba..473ba05 100644
--- a/libide/workbench/ide-layout-grid.c
+++ b/libide/workbench/ide-layout-grid.c
@@ -277,6 +277,7 @@ static void
ide_layout_grid_stack_split (IdeLayoutGrid *self,
IdeLayoutView *view,
IdeLayoutGridSplit split,
+ GFile *file,
IdeLayoutStack *stack)
{
GtkWidget *target_stack = NULL;
@@ -289,7 +290,7 @@ ide_layout_grid_stack_split (IdeLayoutGrid *self,
switch (split)
{
case IDE_LAYOUT_GRID_SPLIT_LEFT:
- target_view = ide_layout_view_create_split (view);
+ target_view = ide_layout_view_create_split (view, file);
if (target_view == NULL)
return;
@@ -316,7 +317,7 @@ ide_layout_grid_stack_split (IdeLayoutGrid *self,
break;
case IDE_LAYOUT_GRID_SPLIT_RIGHT:
- target_view = ide_layout_view_create_split (view);
+ target_view = ide_layout_view_create_split (view, file);
if (target_view == NULL)
return;
diff --git a/libide/workbench/ide-layout-stack-actions.c b/libide/workbench/ide-layout-stack-actions.c
index 3ae878f..a3c054c 100644
--- a/libide/workbench/ide-layout-stack-actions.c
+++ b/libide/workbench/ide-layout-stack-actions.c
@@ -97,7 +97,7 @@ ide_layout_stack_actions_move_left (GSimpleAction *action,
if (active_view == NULL || !IDE_IS_LAYOUT_VIEW (active_view))
return;
- g_signal_emit_by_name (self, "split", active_view, IDE_LAYOUT_GRID_SPLIT_MOVE_LEFT);
+ g_signal_emit_by_name (self, "split", active_view, IDE_LAYOUT_GRID_SPLIT_MOVE_LEFT, NULL);
}
static void
@@ -114,7 +114,7 @@ ide_layout_stack_actions_move_right (GSimpleAction *action,
if (active_view == NULL || !IDE_IS_LAYOUT_VIEW (active_view))
return;
- g_signal_emit_by_name (self, "split", active_view, IDE_LAYOUT_GRID_SPLIT_MOVE_RIGHT);
+ g_signal_emit_by_name (self, "split", active_view, IDE_LAYOUT_GRID_SPLIT_MOVE_RIGHT, NULL);
}
static void
@@ -159,6 +159,8 @@ ide_layout_stack_actions_split_left (GSimpleAction *action,
{
IdeLayoutStack *self = user_data;
GtkWidget *active_view;
+ const gchar *file_path;
+ g_autoptr(GFile) file = NULL;
g_assert (IDE_IS_LAYOUT_STACK (self));
@@ -166,7 +168,13 @@ ide_layout_stack_actions_split_left (GSimpleAction *action,
if (active_view == NULL || !IDE_IS_LAYOUT_VIEW (active_view))
return;
- g_signal_emit_by_name (self, "split", active_view, IDE_LAYOUT_GRID_SPLIT_LEFT);
+ file_path = g_variant_get_string (param, NULL);
+ if (ide_str_empty0 (file_path))
+ file = NULL;
+ else
+ file = g_file_new_for_path (file_path);
+
+ g_signal_emit_by_name (self, "split", active_view, IDE_LAYOUT_GRID_SPLIT_LEFT, file);
}
static void
@@ -183,7 +191,7 @@ ide_layout_stack_actions_split_right (GSimpleAction *action,
if (active_view == NULL || !IDE_IS_LAYOUT_VIEW (active_view))
return;
- g_signal_emit_by_name (self, "split", active_view, IDE_LAYOUT_GRID_SPLIT_RIGHT);
+ g_signal_emit_by_name (self, "split", active_view, IDE_LAYOUT_GRID_SPLIT_RIGHT, NULL);
}
static void
@@ -298,7 +306,7 @@ static const GActionEntry gbViewStackActions[] = {
{ "previous-view", ide_layout_stack_actions_previous_view },
{ "show-list", ide_layout_stack_actions_show_list },
{ "split-down", NULL, NULL, "false", ide_layout_stack_actions_split_down },
- { "split-left", ide_layout_stack_actions_split_left },
+ { "split-left", ide_layout_stack_actions_split_left, "s", NULL, NULL },
{ "split-right", ide_layout_stack_actions_split_right },
};
diff --git a/libide/workbench/ide-layout-stack.c b/libide/workbench/ide-layout-stack.c
index 6c2eef0..ed861b2 100644
--- a/libide/workbench/ide-layout-stack.c
+++ b/libide/workbench/ide-layout-stack.c
@@ -430,6 +430,8 @@ ide_layout_stack_class_init (IdeLayoutStackClass *klass)
* @self: A #IdeLayoutStack.
* @view: The #IdeLayoutView to split.
* @split_type: (type gint): A #IdeLayoutGridSplit.
+ * @file: A #GFile to be opened in the split, or %NULL to use the existing file. If given,
+ * the @file should have already been loaded by the buffer manager.
*
* Requests a split to be performed on the view.
*
@@ -441,9 +443,10 @@ ide_layout_stack_class_init (IdeLayoutStackClass *klass)
0,
NULL, NULL, NULL,
G_TYPE_NONE,
- 2,
+ 3,
IDE_TYPE_LAYOUT_VIEW,
- IDE_TYPE_LAYOUT_GRID_SPLIT);
+ IDE_TYPE_LAYOUT_GRID_SPLIT,
+ G_TYPE_FILE);
gtk_widget_class_set_css_name (widget_class, "layoutstack");
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/builder/ui/ide-layout-stack.ui");
diff --git a/libide/workbench/ide-layout-view.c b/libide/workbench/ide-layout-view.c
index 809ff23..56ac6ed 100644
--- a/libide/workbench/ide-layout-view.c
+++ b/libide/workbench/ide-layout-view.c
@@ -86,19 +86,22 @@ ide_layout_view_get_can_split (IdeLayoutView *self)
/**
* ide_layout_view_create_split:
* @self: A #IdeLayoutView.
+ * @file: A #GFile already loaded by the #IdeBufferManager, or %NULL to use the
+ * existing buffer.
*
- * Creates a new view similar to @self that can be displayed in a split.
- * If the view does not support splits, %NULL will be returned.
+ * Creates a new view that can be displayed in a split, potentially with a different
+ * buffer. If the view does not support splits, %NULL will be returned.
*
* Returns: (transfer full): A #IdeLayoutView.
*/
IdeLayoutView *
-ide_layout_view_create_split (IdeLayoutView *self)
+ide_layout_view_create_split (IdeLayoutView *self,
+ GFile *file)
{
g_return_val_if_fail (IDE_IS_LAYOUT_VIEW (self), NULL);
if (IDE_LAYOUT_VIEW_GET_CLASS (self)->create_split)
- return IDE_LAYOUT_VIEW_GET_CLASS (self)->create_split (self);
+ return IDE_LAYOUT_VIEW_GET_CLASS (self)->create_split (self, file);
return NULL;
}
diff --git a/libide/workbench/ide-layout-view.h b/libide/workbench/ide-layout-view.h
index 9f58dee..35fa636 100644
--- a/libide/workbench/ide-layout-view.h
+++ b/libide/workbench/ide-layout-view.h
@@ -39,7 +39,8 @@ struct _IdeLayoutViewClass
gboolean (*get_modified) (IdeLayoutView *self);
const gchar *(*get_title) (IdeLayoutView *self);
const gchar *(*get_special_title) (IdeLayoutView *self);
- IdeLayoutView *(*create_split) (IdeLayoutView *self);
+ IdeLayoutView *(*create_split) (IdeLayoutView *self,
+ GFile *file);
void (*set_split_view) (IdeLayoutView *self,
gboolean split_view);
void (*set_back_forward_list) (IdeLayoutView *self,
@@ -52,7 +53,8 @@ struct _IdeLayoutViewClass
};
gboolean ide_layout_view_agree_to_close (IdeLayoutView *self);
-IdeLayoutView *ide_layout_view_create_split (IdeLayoutView *self);
+IdeLayoutView *ide_layout_view_create_split (IdeLayoutView *self,
+ GFile *file);
gboolean ide_layout_view_get_can_preview (IdeLayoutView *self);
gboolean ide_layout_view_get_can_split (IdeLayoutView *self);
const gchar *ide_layout_view_get_title (IdeLayoutView *self);
diff --git a/plugins/devhelp/gbp-devhelp-view.c b/plugins/devhelp/gbp-devhelp-view.c
index fe6b33b..5bf5639 100644
--- a/plugins/devhelp/gbp-devhelp-view.c
+++ b/plugins/devhelp/gbp-devhelp-view.c
@@ -72,7 +72,8 @@ gbp_devhelp_view_notify_title (GbpDevhelpView *self,
}
static IdeLayoutView *
-gbp_devhelp_view_create_split (IdeLayoutView *view)
+gbp_devhelp_view_create_split (IdeLayoutView *view,
+ GFile *file)
{
GbpDevhelpView *self = (GbpDevhelpView *)view;
GbpDevhelpView *other;
diff --git a/plugins/terminal/gb-terminal-view.c b/plugins/terminal/gb-terminal-view.c
index a91a115..de58bc6 100644
--- a/plugins/terminal/gb-terminal-view.c
+++ b/plugins/terminal/gb-terminal-view.c
@@ -352,7 +352,8 @@ style_context_changed (GtkStyleContext *style_context,
}
static IdeLayoutView *
-gb_terminal_create_split (IdeLayoutView *view)
+gb_terminal_create_split (IdeLayoutView *view,
+ GFile *file)
{
IdeLayoutView *new_view;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]