[gnome-builder/wip/project-tree] views: allow raising a document without focusing
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/project-tree] views: allow raising a document without focusing
- Date: Thu, 18 Jun 2015 02:02:38 +0000 (UTC)
commit e3917401191cfbf8b61c9ec2c40e534bf3cacfa5
Author: Christian Hergert <christian hergert me>
Date: Wed Jun 17 19:01:28 2015 -0700
views: allow raising a document without focusing
src/views/gb-view-grid.c | 19 +++++++--
src/views/gb-view-grid.h | 3 +
src/views/gb-view-stack.c | 94 ++++++++++++++++++++++++++-------------------
src/views/gb-view-stack.h | 3 +
4 files changed, 74 insertions(+), 45 deletions(-)
---
diff --git a/src/views/gb-view-grid.c b/src/views/gb-view-grid.c
index 825e7dd..ee434ff 100644
--- a/src/views/gb-view-grid.c
+++ b/src/views/gb-view-grid.c
@@ -574,9 +574,11 @@ gb_view_grid_get_stack_after (GbViewGrid *self,
return NULL;
}
+
void
-gb_view_grid_focus_document (GbViewGrid *self,
- GbDocument *document)
+gb_view_grid_raise_document (GbViewGrid *self,
+ GbDocument *document,
+ gboolean focus)
{
GList *stacks;
GList *iter;
@@ -595,7 +597,7 @@ gb_view_grid_focus_document (GbViewGrid *self,
if (view)
{
- gb_view_stack_focus_document (stack, document);
+ gb_view_stack_raise_document (stack, document, focus);
goto cleanup;
}
}
@@ -603,14 +605,21 @@ gb_view_grid_focus_document (GbViewGrid *self,
g_assert (stacks);
if (self->last_focus)
- gb_view_stack_focus_document (self->last_focus, document);
+ gb_view_stack_raise_document (self->last_focus, document, focus);
else
- gb_view_stack_focus_document (stacks->data, document);
+ gb_view_stack_raise_document (stacks->data, document, focus);
cleanup:
g_list_free (stacks);
}
+void
+gb_view_grid_focus_document (GbViewGrid *self,
+ GbDocument *document)
+{
+ gb_view_grid_raise_document (self, document, TRUE);
+}
+
static void
gb_view_grid_grab_focus (GtkWidget *widget)
{
diff --git a/src/views/gb-view-grid.h b/src/views/gb-view-grid.h
index 49007f1..57541d6 100644
--- a/src/views/gb-view-grid.h
+++ b/src/views/gb-view-grid.h
@@ -53,6 +53,9 @@ GList *gb_view_grid_get_stacks (GbViewGrid *grid);
void gb_view_grid_focus_document (GbViewGrid *grid,
GbDocument *document);
GtkWidget *gb_view_grid_get_last_focus (GbViewGrid *self);
+void gb_view_grid_raise_document (GbViewGrid *self,
+ GbDocument *document,
+ gboolean focus);
GbDocument *gb_view_grid_find_document_typed (GbViewGrid *self,
GType document_type);
diff --git a/src/views/gb-view-stack.c b/src/views/gb-view-stack.c
index c7bb48d..63b83e7 100644
--- a/src/views/gb-view-stack.c
+++ b/src/views/gb-view-stack.c
@@ -681,45 +681,6 @@ gb_view_stack_find_with_document (GbViewStack *self,
return ret;
}
-void
-gb_view_stack_focus_document (GbViewStack *self,
- GbDocument *document)
-{
- GtkWidget *view;
-
- g_return_if_fail (GB_IS_VIEW_STACK (self));
- g_return_if_fail (GB_IS_DOCUMENT (document));
-
- view = gb_view_stack_find_with_document (self, document);
-
- if (view != NULL && GB_IS_VIEW (view))
- {
- gb_view_stack_set_active_view (self, view);
- gtk_widget_grab_focus (view);
- return;
- }
-
- view = gb_document_create_view (document);
-
- if (view == NULL)
- {
- g_warning ("Document %s failed to create a view",
- gb_document_get_title (document));
- return;
- }
-
- if (!GB_IS_VIEW (view))
- {
- g_warning ("Document %s did not create a GbView instance.",
- gb_document_get_title (document));
- return;
- }
-
- gb_view_stack_add (GTK_CONTAINER (self), view);
- gb_view_stack_set_active_view (self, view);
- gtk_widget_grab_focus (view);
-}
-
static void
gb_view_stack__navigate_to_load_cb (GObject *object,
GAsyncResult *result,
@@ -765,6 +726,7 @@ gb_view_stack_focus_location (GbViewStack *self,
IdeBufferManager *buffer_manager;
IdeBuffer *buffer;
IdeFile *file;
+ GFile *gfile;
g_return_if_fail (GB_IS_VIEW_STACK (self));
g_return_if_fail (location != NULL);
@@ -777,8 +739,10 @@ gb_view_stack_focus_location (GbViewStack *self,
g_assert (file != NULL);
g_assert (IDE_IS_FILE (file));
+ gfile = ide_file_get_file (file);
+
buffer_manager = ide_context_get_buffer_manager (self->context);
- buffer = ide_buffer_manager_find_buffer (buffer_manager, file);
+ buffer = ide_buffer_manager_find_buffer (buffer_manager, gfile);
if (buffer != NULL && GB_IS_DOCUMENT (buffer))
{
@@ -837,3 +801,53 @@ gb_view_stack_get_views (GbViewStack *self)
return gtk_container_get_children (GTK_CONTAINER (self->stack));
}
+
+void
+gb_view_stack_raise_document (GbViewStack *self,
+ GbDocument *document,
+ gboolean focus)
+{
+ GtkWidget *view;
+
+ g_return_if_fail (GB_IS_VIEW_STACK (self));
+ g_return_if_fail (GB_IS_DOCUMENT (document));
+
+ view = gb_view_stack_find_with_document (self, document);
+
+ if (view != NULL && GB_IS_VIEW (view))
+ {
+ gb_view_stack_set_active_view (self, view);
+ if (focus)
+ gtk_widget_grab_focus (view);
+ return;
+ }
+
+ view = gb_document_create_view (document);
+
+ if (view == NULL)
+ {
+ g_warning ("Document %s failed to create a view",
+ gb_document_get_title (document));
+ return;
+ }
+
+ if (!GB_IS_VIEW (view))
+ {
+ g_warning ("Document %s did not create a GbView instance.",
+ gb_document_get_title (document));
+ return;
+ }
+
+ gb_view_stack_add (GTK_CONTAINER (self), view);
+ gb_view_stack_set_active_view (self, view);
+
+ if (focus)
+ gtk_widget_grab_focus (view);
+}
+
+void
+gb_view_stack_focus_document (GbViewStack *self,
+ GbDocument *document)
+{
+ gb_view_stack_raise_document (self, document, TRUE);
+}
diff --git a/src/views/gb-view-stack.h b/src/views/gb-view-stack.h
index fa4b433..24c0321 100644
--- a/src/views/gb-view-stack.h
+++ b/src/views/gb-view-stack.h
@@ -46,6 +46,9 @@ void gb_view_stack_focus_document (GbViewStack *self,
void gb_view_stack_focus_location (GbViewStack *self,
IdeSourceLocation *location);
GList *gb_view_stack_get_views (GbViewStack *self);
+void gb_view_stack_raise_document (GbViewStack *self,
+ GbDocument *document,
+ gboolean focus);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]