[gnome-builder/editor-layout] get basic loading working, remove multinotebook
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/editor-layout] get basic loading working, remove multinotebook
- Date: Wed, 26 Nov 2014 09:34:45 +0000 (UTC)
commit 28805b59b3a810106969438485962d1603583599
Author: Christian Hergert <christian hergert me>
Date: Wed Nov 26 01:34:37 2014 -0800
get basic loading working, remove multinotebook
src/editor/gb-editor-commands.c | 46 +++++-------------
src/editor/gb-editor-workspace-private.h | 4 +-
src/editor/gb-editor-workspace.c | 25 ++--------
src/resources/ui/gb-editor-workspace.ui | 10 ----
src/tabs/gb-tab-grid.c | 77 +++++++++++++++++++++--------
src/tabs/gb-tab-grid.h | 5 ++
src/tabs/gb-tab-stack.c | 18 +++++++
7 files changed, 98 insertions(+), 87 deletions(-)
---
diff --git a/src/editor/gb-editor-commands.c b/src/editor/gb-editor-commands.c
index 4828006..406dc03 100644
--- a/src/editor/gb-editor-commands.c
+++ b/src/editor/gb-editor-commands.c
@@ -611,22 +611,14 @@ static void
gb_editor_commands_open (GbEditorWorkspace *workspace,
GbEditorTab *tab)
{
- GbEditorWorkspacePrivate *priv;
GtkFileChooserDialog *dialog;
GtkWidget *toplevel;
GtkWidget *suggested;
GtkResponseType response;
- GbNotebook *notebook;
- GbTab *active_tab;
g_return_if_fail (GB_IS_EDITOR_WORKSPACE (workspace));
g_return_if_fail (!tab || GB_IS_EDITOR_TAB (tab));
- priv = workspace->priv;
-
- active_tab = gb_multi_notebook_get_active_tab (priv->multi_notebook);
- notebook = gb_multi_notebook_get_active_notebook (priv->multi_notebook);
-
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (workspace));
dialog = g_object_new (GTK_TYPE_FILE_CHOOSER_DIALOG,
@@ -656,6 +648,7 @@ gb_editor_commands_open (GbEditorWorkspace *workspace,
{
GSList *files;
GSList *iter;
+ GbEditorTab *new_tab;
files = gtk_file_chooser_get_files (GTK_FILE_CHOOSER (dialog));
@@ -663,15 +656,13 @@ gb_editor_commands_open (GbEditorWorkspace *workspace,
{
GFile *file = iter->data;
- if (!tab || !gb_editor_tab_get_is_default (GB_EDITOR_TAB (active_tab)))
- {
- tab = GB_EDITOR_TAB (gb_editor_tab_new ());
- gb_notebook_add_tab (notebook, GB_TAB (tab));
- gtk_widget_show (GTK_WIDGET (tab));
- }
+ new_tab = g_object_new (GB_TYPE_EDITOR_TAB,
+ "visible", TRUE,
+ NULL);
+ gtk_container_add (GTK_CONTAINER (workspace->priv->tab_grid),
+ GTK_WIDGET (new_tab));
- gb_editor_tab_open_file (tab, file);
- gb_notebook_raise_tab (notebook, GB_TAB (tab));
+ gb_editor_tab_open_file (new_tab, file);
g_clear_object (&file);
}
@@ -686,27 +677,14 @@ static void
gb_editor_commands_new_tab (GbEditorWorkspace *workspace,
GbEditorTab *tab)
{
- GbEditorWorkspacePrivate *priv;
- GbNotebook *notebook;
- gint page;
-
g_return_if_fail (GB_IS_EDITOR_WORKSPACE (workspace));
- priv = workspace->priv;
-
- notebook = gb_multi_notebook_get_active_notebook (priv->multi_notebook);
-
tab = g_object_new (GB_TYPE_EDITOR_TAB,
"visible", TRUE,
NULL);
- gb_notebook_add_tab (notebook, GB_TAB (tab));
-
- gtk_container_child_get (GTK_CONTAINER (notebook), GTK_WIDGET (tab),
- "position", &page,
- NULL);
- gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), page);
-
- gtk_widget_grab_focus (GTK_WIDGET (tab));
+ gtk_container_add (GTK_CONTAINER (workspace->priv->tab_grid),
+ GTK_WIDGET (tab));
+ gb_tab_grid_focus_tab (workspace->priv->tab_grid, GB_TAB (tab));
}
static gboolean
@@ -891,7 +869,7 @@ gb_editor_commands_highlight_mode (GSimpleAction *action,
g_assert (GB_IS_EDITOR_WORKSPACE (workspace));
- tab = gb_multi_notebook_get_active_tab (workspace->priv->multi_notebook);
+ tab = gb_tab_grid_get_active (workspace->priv->tab_grid);
if (GB_IS_TAB (tab))
{
@@ -939,7 +917,7 @@ gb_editor_commands_activate (GSimpleAction *action,
if (!command)
return;
- tab = gb_multi_notebook_get_active_tab (workspace->priv->multi_notebook);
+ tab = gb_tab_grid_get_active (workspace->priv->tab_grid);
if (!tab && command->requires_tab)
return;
diff --git a/src/editor/gb-editor-workspace-private.h b/src/editor/gb-editor-workspace-private.h
index 24cc6c3..d130aa1 100644
--- a/src/editor/gb-editor-workspace-private.h
+++ b/src/editor/gb-editor-workspace-private.h
@@ -22,8 +22,8 @@
#include <gtk/gtk.h>
#include "gb-editor-tab.h"
-#include "gb-multi-notebook.h"
#include "gb-notebook.h"
+#include "gb-tab-grid.h"
G_BEGIN_DECLS
@@ -31,8 +31,8 @@ struct _GbEditorWorkspacePrivate
{
GSimpleActionGroup *actions;
GHashTable *command_map;
- GbMultiNotebook *multi_notebook;
GtkPaned *paned;
+ GbTabGrid *tab_grid;
};
G_END_DECLS
diff --git a/src/editor/gb-editor-workspace.c b/src/editor/gb-editor-workspace.c
index c80755e..1249b48 100644
--- a/src/editor/gb-editor-workspace.c
+++ b/src/editor/gb-editor-workspace.c
@@ -21,7 +21,6 @@
#include "gb-editor-commands.h"
#include "gb-editor-workspace.h"
#include "gb-editor-workspace-private.h"
-#include "gb-multi-notebook.h"
#include "gb-tab-grid.h"
#include "gb-tree.h"
@@ -37,27 +36,18 @@ gb_editor_workspace_open (GbEditorWorkspace *workspace,
GFile *file)
{
GbEditorTab *tab;
- GbNotebook *notebook;
- gint page;
g_return_if_fail (GB_IS_EDITOR_WORKSPACE (workspace));
g_return_if_fail (G_IS_FILE (file));
- notebook = gb_multi_notebook_get_active_notebook (workspace->priv->multi_notebook);
-
tab = g_object_new (GB_TYPE_EDITOR_TAB,
"visible", TRUE,
NULL);
- gb_notebook_add_tab (notebook, GB_TAB (tab));
-
- gtk_container_child_get (GTK_CONTAINER (notebook), GTK_WIDGET (tab),
- "position", &page,
- NULL);
- gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), page);
+ gtk_container_add (GTK_CONTAINER (workspace->priv->tab_grid),
+ GTK_WIDGET (tab));
+ gb_tab_grid_focus_tab (workspace->priv->tab_grid, GB_TAB (tab));
gb_editor_tab_open_file (tab, file);
-
- gtk_widget_grab_focus (GTK_WIDGET (tab));
}
static GActionGroup *
@@ -72,14 +62,10 @@ static void
gb_editor_workspace_grab_focus (GtkWidget *widget)
{
GbEditorWorkspace *workspace = GB_EDITOR_WORKSPACE (widget);
- GbTab *tab;
g_return_if_fail (GB_IS_EDITOR_WORKSPACE (workspace));
- tab = gb_multi_notebook_get_active_tab (workspace->priv->multi_notebook);
-
- if (tab)
- gtk_widget_grab_focus (GTK_WIDGET (tab));
+ gtk_widget_grab_focus (GTK_WIDGET (workspace->priv->tab_grid));
}
static void
@@ -108,11 +94,10 @@ gb_editor_workspace_class_init (GbEditorWorkspaceClass *klass)
gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/builder/ui/gb-editor-workspace.ui");
- gtk_widget_class_bind_template_child_private (widget_class, GbEditorWorkspace, multi_notebook);
gtk_widget_class_bind_template_child_private (widget_class, GbEditorWorkspace, paned);
+ gtk_widget_class_bind_template_child_private (widget_class, GbEditorWorkspace, tab_grid);
g_type_ensure (GB_TYPE_EDITOR_TAB);
- g_type_ensure (GB_TYPE_MULTI_NOTEBOOK);
g_type_ensure (GB_TYPE_TAB_GRID);
g_type_ensure (GB_TYPE_TREE);
}
diff --git a/src/resources/ui/gb-editor-workspace.ui b/src/resources/ui/gb-editor-workspace.ui
index b3846cd..ff61362 100644
--- a/src/resources/ui/gb-editor-workspace.ui
+++ b/src/resources/ui/gb-editor-workspace.ui
@@ -36,7 +36,6 @@
</child>
</object>
</child>
-<child><object class="GtkBox"><property name="visible">True</property>
<child>
<object class="GbTabGrid" id="tab_grid">
<property name="visible">True</property>
@@ -55,15 +54,6 @@
</child>
</object>
</child>
- <child>
- <object class="GbMultiNotebook" id="multi_notebook">
- <property name="group-name">GB_EDITOR_WORKSPACE</property>
- <property name="hexpand">True</property>
- <property name="visible">false</property>
- <property name="show-tabs">False</property>
- </object>
- </child>
-</object></child>
</object>
</child>
</template>
diff --git a/src/tabs/gb-tab-grid.c b/src/tabs/gb-tab-grid.c
index 36677bf..70a0a47 100644
--- a/src/tabs/gb-tab-grid.c
+++ b/src/tabs/gb-tab-grid.c
@@ -166,41 +166,40 @@ gb_tab_grid_get_last_focused (GbTabGrid *grid)
return grid->priv->last_focused_stack;
}
+GbTab *
+gb_tab_grid_get_active (GbTabGrid *grid)
+{
+ GbTabStack *last_focused_stack;
+ GtkWidget *ret = NULL;
+
+ g_return_val_if_fail (GB_IS_TAB_GRID (grid), NULL);
+
+ last_focused_stack = gb_tab_grid_get_last_focused (grid);
+
+ if (last_focused_stack)
+ if ((ret = gb_tab_stack_get_active (last_focused_stack)))
+ return GB_TAB (ret);
+
+ return NULL;
+}
+
static void
gb_tab_grid_add (GtkContainer *container,
GtkWidget *child)
{
- GbTabGridPrivate *priv;
GbTabGrid *self = (GbTabGrid *) container;
- GtkWidget *stack = NULL;
- GtkWidget *toplevel;
+ GbTabStack *stack = NULL;
g_return_if_fail (GB_IS_TAB_GRID (self));
g_return_if_fail (GTK_IS_WIDGET (child));
- priv = self->priv;
-
if (GB_IS_TAB (child))
{
- /*
- * Try to find the currently focused view.
- */
- toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self));
- if (toplevel && GTK_IS_WINDOW (toplevel))
- {
- if ((stack = gtk_window_get_focus (GTK_WINDOW (toplevel))))
- while (stack && !GB_IS_TAB_STACK (stack))
- stack = gtk_widget_get_parent (stack);
-
- }
-
- if (!stack)
- stack = gb_tab_grid_get_first_stack (self);
-
+ stack = gb_tab_grid_get_last_focused (self);
gtk_container_add (GTK_CONTAINER (stack), child);
}
else
- gtk_paned_add1 (GTK_PANED (priv->top_hpaned), child);
+ gtk_paned_add1 (GTK_PANED (self->priv->top_hpaned), child);
}
static GList *
@@ -736,6 +735,41 @@ gb_tab_grid_realize (GtkWidget *widget)
}
}
+void
+gb_tab_grid_focus_tab (GbTabGrid *grid,
+ GbTab *tab)
+{
+ GList *stacks;
+ GList *iter;
+
+ g_return_if_fail (GB_IS_TAB_GRID (grid));
+ g_return_if_fail (GB_IS_TAB (tab));
+
+ stacks = gb_tab_grid_get_stacks (grid);
+
+ for (iter = stacks; iter; iter = iter->next)
+ {
+ if (gb_tab_stack_contains_tab (iter->data, tab))
+ {
+ gb_tab_stack_focus_tab (iter->data, tab);
+ break;
+ }
+ }
+}
+
+static void
+gb_tab_grid_grab_focus (GtkWidget *widget)
+{
+ GbTabGrid *grid = (GbTabGrid *)widget;
+ GbTabStack *stack;
+
+ g_return_if_fail (GB_IS_TAB_GRID (grid));
+
+ stack = gb_tab_grid_get_last_focused (grid);
+
+ gtk_widget_grab_focus (GTK_WIDGET (stack));
+}
+
static void
gb_tab_grid_finalize (GObject *object)
{
@@ -762,6 +796,7 @@ gb_tab_grid_class_init (GbTabGridClass *klass)
object_class->finalize = gb_tab_grid_finalize;
widget_class->realize = gb_tab_grid_realize;
+ widget_class->grab_focus = gb_tab_grid_grab_focus;
container_class->add = gb_tab_grid_add;
}
diff --git a/src/tabs/gb-tab-grid.h b/src/tabs/gb-tab-grid.h
index cebb5a0..0230b3e 100644
--- a/src/tabs/gb-tab-grid.h
+++ b/src/tabs/gb-tab-grid.h
@@ -21,6 +21,8 @@
#include <gtk/gtk.h>
+#include "gb-tab.h"
+
G_BEGIN_DECLS
#define GB_TYPE_TAB_GRID (gb_tab_grid_get_type())
@@ -50,6 +52,9 @@ struct _GbTabGridClass
GtkWidget *gb_tab_grid_new (void);
GType gb_tab_grid_get_type (void) G_GNUC_CONST;
+GbTab *gb_tab_grid_get_active (GbTabGrid *grid);
+void gb_tab_grid_focus_tab (GbTabGrid *grid,
+ GbTab *tab);
void gb_tab_grid_move_tab_right (GbTabGrid *grid,
GbTab *tab);
void gb_tab_grid_focus_next_tab (GbTabGrid *grid,
diff --git a/src/tabs/gb-tab-stack.c b/src/tabs/gb-tab-stack.c
index 8feab91..549176d 100644
--- a/src/tabs/gb-tab-stack.c
+++ b/src/tabs/gb-tab-stack.c
@@ -143,6 +143,24 @@ gb_tab_stack_focus_iter (GbTabStack *stack,
return ret;
}
+gboolean
+gb_tab_stack_focus_tab (GbTabStack *stack,
+ GbTab *tab)
+{
+ GtkTreeIter iter;
+
+ g_return_if_fail (GB_IS_TAB_STACK (stack));
+ g_return_if_fail (GB_IS_TAB (tab));
+
+ if (gb_tab_stack_get_tab_iter (stack, tab, &iter))
+ {
+ gb_tab_stack_focus_iter (stack, &iter);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
void
gb_tab_stack_remove_tab (GbTabStack *stack,
GbTab *tab)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]