Moved MooEditTab to a separate file

This commit is contained in:
Yevgen Muntyan 2011-01-18 21:15:41 -08:00
parent 23e565b7fe
commit 5f7ae0fa77
9 changed files with 495 additions and 456 deletions

View File

@ -50,6 +50,8 @@ source_files = \
../moo/mooedit/mooedit-private.h\
../moo/mooedit/mooedit-script.c\
../moo/mooedit/mooedit-script.h\
../moo/mooedit/mooedittab.c\
../moo/mooedit/mooedittab.h\
../moo/mooedit/mooedittypes.h\
../moo/mooedit/mooeditview.c\
../moo/mooedit/mooeditview.h\

View File

@ -50,9 +50,11 @@ moo_sources += \
mooedit/mooedit-private.h \
mooedit/mooeditprogress.h \
mooedit/mooeditprogress.c \
mooedit/mooedittab.c \
mooedit/mooedittab.h \
mooedit/mooedittab-impl.h \
mooedit/mooeditwindow.c \
mooedit/mooeditwindow-impl.h \
mooedit/mooeditwindow-priv.h \
mooedit/mooeditfileinfo.c \
mooedit/moofold.c \
mooedit/moofold.h \

View File

@ -30,6 +30,7 @@
#include "mooedit/mootextbuffer.h"
#include "mooedit/mooeditfiltersettings.h"
#include "mooedit/mooeditor-impl.h"
#include "mooedit/mooedittab-impl.h"
#include "mooedit/mooeditwindow-impl.h"
#include "mooedit/moolangmgr.h"
#include "marshals.h"

View File

@ -0,0 +1,27 @@
#ifndef MOO_EDIT_TAB_IMPL_H
#define MOO_EDIT_TAB_IMPL_H
#include "mooedittab.h"
#include "mooeditprogress.h"
G_BEGIN_DECLS
MooEditTab *_moo_edit_tab_new (MooEdit *doc);
MooEditProgress *_moo_edit_tab_create_progress (MooEditTab *tab);
void _moo_edit_tab_destroy_progress (MooEditTab *tab);
void _moo_edit_tab_focus_next_view (MooEditTab *tab);
void _moo_edit_tab_set_focused_view (MooEditTab *tab,
MooEditView *view);
gboolean _moo_edit_tab_set_split_horizontal (MooEditTab *tab,
gboolean split);
gboolean _moo_edit_tab_set_split_vertical (MooEditTab *tab,
gboolean split);
gboolean _moo_edit_tab_get_split_horizontal (MooEditTab *tab);
gboolean _moo_edit_tab_get_split_vertical (MooEditTab *tab);
G_END_DECLS
#endif /* MOO_EDIT_TAB_IMPL_H */

440
moo/mooedit/mooedittab.c Normal file
View File

@ -0,0 +1,440 @@
/**
* class:MooEditTab: (parent GtkVBox) (moo.doc-object-name tab)
**/
#include "mooedittab-impl.h"
#include "mooeditview-impl.h"
#include "mooedit-impl.h"
#include <mooutils/moocompat.h>
struct MooEditTab
{
GtkVBox base;
MooEditProgress *progress;
GtkWidget *hpaned;
GtkWidget *vpaned1;
GtkWidget *vpaned2;
MooEdit *doc;
MooEditView *active_view;
};
struct MooEditTabClass
{
GtkVBoxClass base_class;
};
MOO_DEFINE_OBJECT_ARRAY (MooEditTab, moo_edit_tab)
G_DEFINE_TYPE (MooEditTab, moo_edit_tab, GTK_TYPE_VBOX)
/**************************************************************************************************
*
* MooEditTab
*
*************************************************************************************************/
static void
moo_edit_tab_init (MooEditTab *tab)
{
gtk_box_set_homogeneous (GTK_BOX (tab), FALSE);
tab->hpaned = gtk_hpaned_new ();
tab->vpaned1 = gtk_vpaned_new ();
tab->vpaned2 = gtk_vpaned_new ();
gtk_paned_pack1 (GTK_PANED (tab->hpaned), tab->vpaned1, TRUE, FALSE);
gtk_paned_pack2 (GTK_PANED (tab->hpaned), tab->vpaned2, TRUE, FALSE);
gtk_widget_show (tab->hpaned);
gtk_box_pack_start (GTK_BOX (tab), tab->hpaned, TRUE, TRUE, 0);
}
static void
moo_edit_tab_dispose (GObject *object)
{
MooEditTab *tab = MOO_EDIT_TAB (object);
if (tab->doc)
{
g_object_unref (tab->doc);
tab->doc = NULL;
}
G_OBJECT_CLASS (moo_edit_tab_parent_class)->dispose (object);
}
static void
moo_edit_tab_class_init (MooEditTabClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->dispose = moo_edit_tab_dispose;
}
static GtkWidget *
create_view_scrolled_window (MooEditView *view)
{
GtkWidget *swin = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swin),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (swin),
GTK_SHADOW_ETCHED_IN);
gtk_container_add (GTK_CONTAINER (swin), GTK_WIDGET (view));
gtk_widget_show_all (swin);
return swin;
}
static GtkWidget *
create_view_in_scrolled_window (MooEditTab *tab)
{
MooEditView *view = _moo_edit_view_new (tab->doc);
_moo_edit_view_set_tab (view, tab);
return create_view_scrolled_window (view);
}
MooEditTab *
_moo_edit_tab_new (MooEdit *doc)
{
MooEditView *view;
MooEditTab *tab;
GtkWidget *swin;
g_return_val_if_fail (moo_edit_get_n_views (doc) == 1, NULL);
tab = g_object_new (MOO_TYPE_EDIT_TAB, NULL);
tab->doc = g_object_ref (doc);
view = moo_edit_get_view (doc);
_moo_edit_view_set_tab (view, tab);
swin = create_view_scrolled_window (view);
gtk_paned_pack1 (GTK_PANED (tab->vpaned1), swin, TRUE, FALSE);
gtk_widget_show (tab->vpaned1);
gtk_widget_show (GTK_WIDGET (tab));
return tab;
}
MooEdit *
moo_edit_tab_get_doc (MooEditTab *tab)
{
g_return_val_if_fail (MOO_IS_EDIT_TAB (tab), NULL);
return tab->doc;
}
MooEditViewArray *
moo_edit_tab_get_views (MooEditTab *tab)
{
MooEditViewArray *views;
int i;
g_return_val_if_fail (MOO_IS_EDIT_TAB (tab), NULL);
views = moo_edit_view_array_new ();
for (i = 0; i < 2; ++i)
{
GList *children = gtk_container_get_children (GTK_CONTAINER (i == 0 ? tab->vpaned1 : tab->vpaned2));
while (children)
{
MooEditView *view = MOO_EDIT_VIEW (gtk_bin_get_child (children->data));
moo_edit_view_array_append (views, view);
children = g_list_delete_link (children, children);
}
}
return views;
}
MooEditView *
moo_edit_tab_get_active_view (MooEditTab *tab)
{
g_return_val_if_fail (MOO_IS_EDIT_TAB (tab), NULL);
if (!tab->active_view)
{
int i;
for (i = 0; !tab->active_view && i < 2; ++i)
{
GList *children = gtk_container_get_children (GTK_CONTAINER (i == 0 ? tab->vpaned1 : tab->vpaned2));
if (children)
tab->active_view = MOO_EDIT_VIEW (gtk_bin_get_child (children->data));
g_list_free (children);
}
}
return tab->active_view;
}
void
_moo_edit_tab_set_focused_view (MooEditTab *tab,
MooEditView *view)
{
g_return_if_fail (MOO_IS_EDIT_TAB (tab));
g_return_if_fail (MOO_IS_EDIT_VIEW (view));
g_return_if_fail (moo_edit_view_get_tab (view) == tab);
tab->active_view = view;
}
MooEditWindow *
moo_edit_tab_get_window (MooEditTab *tab)
{
GtkWidget *toplevel;
g_return_val_if_fail (MOO_IS_EDIT_TAB (tab), NULL);
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tab));
if (!toplevel || !GTK_WIDGET_TOPLEVEL (toplevel))
return NULL;
g_return_val_if_fail (MOO_IS_EDIT_WINDOW (toplevel), NULL);
return MOO_EDIT_WINDOW (toplevel);
}
static MooEditView *
moo_edit_tab_get_view (MooEditTab *tab, int ipaned, int iview)
{
GtkWidget *paned;
GtkWidget *swin;
g_return_val_if_fail (ipaned == 1 || ipaned == 2, NULL);
g_return_val_if_fail (iview == 1 || iview == 2, NULL);
if (ipaned == 1)
paned = tab->vpaned1;
else
paned = tab->vpaned2;
if (iview == 1)
swin = gtk_paned_get_child1 (GTK_PANED (paned));
else
swin = gtk_paned_get_child2 (GTK_PANED (paned));
return swin ? MOO_EDIT_VIEW (gtk_bin_get_child (GTK_BIN (swin))) : NULL;
}
void
_moo_edit_tab_focus_next_view (MooEditTab *tab)
{
int i = 0;
int cur;
MooEditView *focus_chain[4] = { 0 };
MooEditView *view;
g_return_if_fail (MOO_IS_EDIT_TAB (tab));
focus_chain[i++] = moo_edit_tab_get_view (tab, 1, 1);
if (GTK_WIDGET_VISIBLE (tab->vpaned2))
{
if ((view = moo_edit_tab_get_view (tab, 2, 1)))
focus_chain[i++] = view;
g_assert (view != NULL);
if ((view = moo_edit_tab_get_view (tab, 2, 2)))
focus_chain[i++] = view;
}
if ((view = moo_edit_tab_get_view (tab, 1, 2)))
focus_chain[i++] = view;
for (cur = 0; cur < 4; ++cur)
if (focus_chain[cur] && GTK_WIDGET_HAS_FOCUS (focus_chain[cur]))
break;
cur++;
if (cur >= 4 || !focus_chain[cur])
cur = 0;
gtk_widget_grab_focus (GTK_WIDGET (focus_chain[cur]));
}
/*
* +-------------+
* | | |
* | | |
* | | |
* | | |
* | | |
* +-------------+
*/
gboolean
_moo_edit_tab_get_split_horizontal (MooEditTab *tab)
{
g_return_val_if_fail (MOO_IS_EDIT_TAB (tab), FALSE);
return GTK_WIDGET_VISIBLE (tab->vpaned1) &&
GTK_WIDGET_VISIBLE (tab->vpaned2);
}
/*
* +-------------+
* | | |
* | | |
* | | |
* | | |
* | | |
* +-------------+
*/
gboolean
_moo_edit_tab_set_split_horizontal (MooEditTab *tab,
gboolean split)
{
g_return_val_if_fail (MOO_IS_EDIT_TAB (tab), FALSE);
if (!!split == _moo_edit_tab_get_split_horizontal (tab))
return FALSE;
if (!split)
{
gboolean has_focus;
MooEditView *view1 = moo_edit_tab_get_view (tab, 2, 1);
MooEditView *view2 = moo_edit_tab_get_view (tab, 2, 2);
g_assert (view1 != NULL);
has_focus = (view1 && GTK_WIDGET_HAS_FOCUS (view1)) ||
(view2 && GTK_WIDGET_HAS_FOCUS (view2));
if (view1)
{
_moo_edit_remove_view (tab->doc, view1);
gtk_container_remove (GTK_CONTAINER (tab->vpaned2), GTK_WIDGET (view1)->parent);
}
if (view2)
{
_moo_edit_remove_view (tab->doc, view2);
gtk_container_remove (GTK_CONTAINER (tab->vpaned2), GTK_WIDGET (view2)->parent);
}
gtk_widget_hide (tab->vpaned2);
if (has_focus)
gtk_widget_grab_focus (GTK_WIDGET (moo_edit_tab_get_view (tab, 1, 1)));
}
else
{
GtkWidget *swin;
MooEditView *view1 = moo_edit_tab_get_view (tab, 1, 1);
MooEditView *view2 = moo_edit_tab_get_view (tab, 1, 2);
g_assert (view1 != NULL);
g_assert (!GTK_WIDGET_VISIBLE (tab->vpaned2));
g_assert (!gtk_container_get_children (GTK_CONTAINER (tab->vpaned2)));
if (view1)
{
swin = create_view_in_scrolled_window (tab);
gtk_paned_pack1 (GTK_PANED (tab->vpaned2), swin, TRUE, FALSE);
}
if (view2)
{
swin = create_view_in_scrolled_window (tab);
gtk_paned_pack2 (GTK_PANED (tab->vpaned2), swin, TRUE, FALSE);
}
gtk_widget_show_all (tab->vpaned2);
}
return TRUE;
}
/*
* +--------------+
* | |
* | |
* |--------------|
* | |
* | |
* +--------------+
*/
gboolean
_moo_edit_tab_get_split_vertical (MooEditTab *tab)
{
g_return_val_if_fail (MOO_IS_EDIT_TAB (tab), FALSE);
return gtk_paned_get_child1 (GTK_PANED (tab->vpaned1)) &&
gtk_paned_get_child2 (GTK_PANED (tab->vpaned1));
}
/*
* +--------------+
* | |
* | |
* |--------------|
* | |
* | |
* +--------------+
*/
gboolean
_moo_edit_tab_set_split_vertical (MooEditTab *tab,
gboolean split)
{
g_return_val_if_fail (MOO_IS_EDIT_TAB (tab), FALSE);
if (!!split == _moo_edit_tab_get_split_vertical (tab))
return FALSE;
if (!split)
{
gboolean has_focus;
MooEditView *view1;
MooEditView *view2;
view1 = moo_edit_tab_get_view (tab, 1, 2);
view2 = moo_edit_tab_get_view (tab, 2, 2);
g_assert (view1 != NULL);
has_focus = (view1 && GTK_WIDGET_HAS_FOCUS (view1)) ||
(view2 && GTK_WIDGET_HAS_FOCUS (view2));
if (view1)
{
_moo_edit_remove_view (tab->doc, view1);
gtk_container_remove (GTK_CONTAINER (tab->vpaned1), GTK_WIDGET (view1)->parent);
}
if (view2)
{
_moo_edit_remove_view (tab->doc, view2);
gtk_container_remove (GTK_CONTAINER (tab->vpaned2), GTK_WIDGET (view2)->parent);
}
if (has_focus)
gtk_widget_grab_focus (GTK_WIDGET (moo_edit_tab_get_view (tab, 1, 1)));
}
else
{
GtkWidget *swin;
swin = create_view_in_scrolled_window (tab);
gtk_paned_pack2 (GTK_PANED (tab->vpaned1), swin, TRUE, FALSE);
if (GTK_WIDGET_VISIBLE (tab->vpaned2))
{
g_assert (gtk_paned_get_child1 (GTK_PANED (tab->vpaned2)) != NULL);
swin = create_view_in_scrolled_window (tab);
gtk_paned_pack2 (GTK_PANED (tab->vpaned2), swin, TRUE, FALSE);
}
}
return TRUE;
}
MooEditProgress *
_moo_edit_tab_create_progress (MooEditTab *tab)
{
g_return_val_if_fail (MOO_IS_EDIT_TAB (tab), NULL);
g_return_val_if_fail (!tab->progress, tab->progress);
tab->progress = _moo_edit_progress_new ();
gtk_box_pack_start (GTK_BOX (tab), GTK_WIDGET (tab->progress), FALSE, FALSE, 0);
gtk_box_reorder_child (GTK_BOX (tab), GTK_WIDGET (tab->progress), 0);
return tab->progress;
}
void
_moo_edit_tab_destroy_progress (MooEditTab *tab)
{
g_return_if_fail (MOO_IS_EDIT_TAB (tab));
g_return_if_fail (tab->progress != NULL);
gtk_widget_destroy (GTK_WIDGET (tab->progress));
tab->progress = NULL;
}

12
moo/mooedit/mooedittab.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef MOO_EDIT_TAB_H
#define MOO_EDIT_TAB_H
#include <mooedit/mooedittypes.h>
G_BEGIN_DECLS
G_END_DECLS
#endif /* MOO_EDIT_TAB_H */

View File

@ -19,12 +19,6 @@ void _moo_edit_window_set_focused_view (MooEditWindow *window,
void _moo_edit_window_update_title (void);
void _moo_edit_window_set_use_tabs (void);
void _moo_edit_tab_set_focused_view (MooEditTab *tab,
MooEditView *view);
MooEditProgress *_moo_edit_tab_create_progress (MooEditTab *tab);
void _moo_edit_tab_destroy_progress (MooEditTab *tab);
G_END_DECLS
#endif /* MOO_EDIT_WINDOW_IMPL_H */

View File

@ -1,29 +0,0 @@
#ifndef MOO_EDIT_WINDOW_PRIV_H
#define MOO_EDIT_WINDOW_PRIV_H
#include "mooeditwindow-impl.h"
G_BEGIN_DECLS
struct MooEditTab
{
GtkVBox base;
MooEditProgress *progress;
GtkWidget *hpaned;
GtkWidget *vpaned1;
GtkWidget *vpaned2;
MooEdit *doc;
MooEditView *active_view;
};
struct MooEditTabClass
{
GtkVBoxClass base_class;
};
G_END_DECLS
#endif /* MOO_EDIT_WINDOW_PRIV_H */

View File

@ -17,10 +17,6 @@
* class:MooEditWindow: (parent MooWindow) (moo.doc-object-name window)
**/
/**
* class:MooEditTab: (parent GtkVBox) (moo.doc-object-name tab)
**/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@ -28,10 +24,11 @@
#define MOOEDIT_COMPILATION
#include "mooedit/mooedit-impl.h"
#include "mooedit/mooeditdialogs.h"
#include "mooedit/mooeditwindow-priv.h"
#include "mooedit/mooeditwindow-impl.h"
#include "mooedit/mooedit-accels.h"
#include "mooedit/mooeditor-impl.h"
#include "mooedit/mooeditview-impl.h"
#include "mooedit/mooedittab-impl.h"
#include "mooedit/mooeditfiltersettings.h"
#include "mooedit/moolang.h"
#include "mooedit/mootextbuffer.h"
@ -116,7 +113,6 @@ struct MooEditWindowPrivate {
};
MOO_DEFINE_OBJECT_ARRAY (MooEditWindow, moo_edit_window)
MOO_DEFINE_OBJECT_ARRAY (MooEditTab, moo_edit_tab)
enum {
TARGET_MOO_EDIT_TAB = 1,
@ -291,9 +287,6 @@ static void action_print_preview (MooEditWindow *window);
static void action_print_pdf (MooEditWindow *window);
#endif
static void moo_edit_tab_set_focused_view (MooEditTab *tab,
MooEditView *view);
static MooEditTab *moo_edit_tab_new (MooEdit *doc);
static void split_view_horizontal_toggled (MooEditWindow *window,
gboolean active);
static void split_view_vertical_toggled (MooEditWindow *window,
@ -302,7 +295,6 @@ static void action_focus_next_split_view (MooEditWindow *window)
static void update_split_view_actions (MooEditWindow *window);
G_DEFINE_TYPE (MooEditTab, moo_edit_tab, GTK_TYPE_VBOX)
G_DEFINE_TYPE (MooEditWindow, moo_edit_window, MOO_TYPE_WINDOW)
enum {
@ -2089,7 +2081,7 @@ _moo_edit_window_set_focused_view (MooEditWindow *window,
window->priv->active_view = view;
moo_edit_tab_set_focused_view (tab, view);
_moo_edit_tab_set_focused_view (tab, view);
}
static void
@ -2905,7 +2897,7 @@ _moo_edit_window_insert_doc (MooEditWindow *window,
g_assert (moo_edit_get_n_views (doc) == 1);
tab = moo_edit_tab_new (doc);
tab = _moo_edit_tab_new (doc);
_moo_edit_window_insert_tab (window, tab, after_view);
}
@ -4648,388 +4640,9 @@ out:
/**************************************************************************************************
*
* MooEditTab
* tabs
*
*************************************************************************************************/
static void
moo_edit_tab_init (MooEditTab *tab)
{
gtk_box_set_homogeneous (GTK_BOX (tab), FALSE);
tab->hpaned = gtk_hpaned_new ();
tab->vpaned1 = gtk_vpaned_new ();
tab->vpaned2 = gtk_vpaned_new ();
gtk_paned_pack1 (GTK_PANED (tab->hpaned), tab->vpaned1, TRUE, FALSE);
gtk_paned_pack2 (GTK_PANED (tab->hpaned), tab->vpaned2, TRUE, FALSE);
gtk_widget_show (tab->hpaned);
gtk_box_pack_start (GTK_BOX (tab), tab->hpaned, TRUE, TRUE, 0);
}
static void
moo_edit_tab_dispose (GObject *object)
{
MooEditTab *tab = MOO_EDIT_TAB (object);
if (tab->doc)
{
g_object_unref (tab->doc);
tab->doc = NULL;
}
G_OBJECT_CLASS (moo_edit_tab_parent_class)->dispose (object);
}
static void
moo_edit_tab_class_init (MooEditTabClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->dispose = moo_edit_tab_dispose;
}
static GtkWidget *
create_view_scrolled_window (MooEditView *view)
{
GtkWidget *swin = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swin),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (swin),
GTK_SHADOW_ETCHED_IN);
gtk_container_add (GTK_CONTAINER (swin), GTK_WIDGET (view));
gtk_widget_show_all (swin);
return swin;
}
static GtkWidget *
create_view_in_scrolled_window (MooEditTab *tab)
{
MooEditView *view = _moo_edit_view_new (tab->doc);
_moo_edit_view_set_tab (view, tab);
return create_view_scrolled_window (view);
}
static MooEditTab *
moo_edit_tab_new (MooEdit *doc)
{
MooEditView *view;
MooEditTab *tab;
GtkWidget *swin;
g_return_val_if_fail (moo_edit_get_n_views (doc) == 1, NULL);
tab = g_object_new (MOO_TYPE_EDIT_TAB, NULL);
tab->doc = g_object_ref (doc);
view = moo_edit_get_view (doc);
_moo_edit_view_set_tab (view, tab);
swin = create_view_scrolled_window (view);
gtk_paned_pack1 (GTK_PANED (tab->vpaned1), swin, TRUE, FALSE);
gtk_widget_show (tab->vpaned1);
gtk_widget_show (GTK_WIDGET (tab));
return tab;
}
MooEdit *
moo_edit_tab_get_doc (MooEditTab *tab)
{
g_return_val_if_fail (MOO_IS_EDIT_TAB (tab), NULL);
return tab->doc;
}
MooEditViewArray *
moo_edit_tab_get_views (MooEditTab *tab)
{
MooEditViewArray *views;
int i;
g_return_val_if_fail (MOO_IS_EDIT_TAB (tab), NULL);
views = moo_edit_view_array_new ();
for (i = 0; i < 2; ++i)
{
GList *children = gtk_container_get_children (GTK_CONTAINER (i == 0 ? tab->vpaned1 : tab->vpaned2));
while (children)
{
MooEditView *view = MOO_EDIT_VIEW (gtk_bin_get_child (children->data));
moo_edit_view_array_append (views, view);
children = g_list_delete_link (children, children);
}
}
return views;
}
MooEditView *
moo_edit_tab_get_active_view (MooEditTab *tab)
{
g_return_val_if_fail (MOO_IS_EDIT_TAB (tab), NULL);
if (!tab->active_view)
{
int i;
for (i = 0; !tab->active_view && i < 2; ++i)
{
GList *children = gtk_container_get_children (GTK_CONTAINER (i == 0 ? tab->vpaned1 : tab->vpaned2));
if (children)
tab->active_view = MOO_EDIT_VIEW (gtk_bin_get_child (children->data));
g_list_free (children);
}
}
return tab->active_view;
}
static void
moo_edit_tab_set_focused_view (MooEditTab *tab,
MooEditView *view)
{
g_return_if_fail (MOO_IS_EDIT_TAB (tab));
g_return_if_fail (MOO_IS_EDIT_VIEW (view));
g_return_if_fail (moo_edit_view_get_tab (view) == tab);
tab->active_view = view;
}
MooEditWindow *
moo_edit_tab_get_window (MooEditTab *tab)
{
GtkWidget *toplevel;
g_return_val_if_fail (MOO_IS_EDIT_TAB (tab), NULL);
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tab));
if (!toplevel || !GTK_WIDGET_TOPLEVEL (toplevel))
return NULL;
g_return_val_if_fail (MOO_IS_EDIT_WINDOW (toplevel), NULL);
return MOO_EDIT_WINDOW (toplevel);
}
static MooEditView *
moo_edit_tab_get_view (MooEditTab *tab, int ipaned, int iview)
{
GtkWidget *paned;
GtkWidget *swin;
g_return_val_if_fail (ipaned == 1 || ipaned == 2, NULL);
g_return_val_if_fail (iview == 1 || iview == 2, NULL);
if (ipaned == 1)
paned = tab->vpaned1;
else
paned = tab->vpaned2;
if (iview == 1)
swin = gtk_paned_get_child1 (GTK_PANED (paned));
else
swin = gtk_paned_get_child2 (GTK_PANED (paned));
return swin ? MOO_EDIT_VIEW (gtk_bin_get_child (GTK_BIN (swin))) : NULL;
}
static void
moo_edit_tab_focus_next_view (MooEditTab *tab)
{
int i = 0;
int cur;
MooEditView *focus_chain[4] = { 0 };
MooEditView *view;
focus_chain[i++] = moo_edit_tab_get_view (tab, 1, 1);
if (GTK_WIDGET_VISIBLE (tab->vpaned2))
{
if ((view = moo_edit_tab_get_view (tab, 2, 1)))
focus_chain[i++] = view;
g_assert (view != NULL);
if ((view = moo_edit_tab_get_view (tab, 2, 2)))
focus_chain[i++] = view;
}
if ((view = moo_edit_tab_get_view (tab, 1, 2)))
focus_chain[i++] = view;
for (cur = 0; cur < 4; ++cur)
if (focus_chain[cur] && GTK_WIDGET_HAS_FOCUS (focus_chain[cur]))
break;
cur++;
if (cur >= 4 || !focus_chain[cur])
cur = 0;
gtk_widget_grab_focus (GTK_WIDGET (focus_chain[cur]));
}
/*
* +-------------+
* | | |
* | | |
* | | |
* | | |
* | | |
* +-------------+
*/
static gboolean
moo_edit_tab_get_split_horizontal (MooEditTab *tab)
{
g_return_val_if_fail (MOO_IS_EDIT_TAB (tab), FALSE);
return GTK_WIDGET_VISIBLE (tab->vpaned1) &&
GTK_WIDGET_VISIBLE (tab->vpaned2);
}
/*
* +-------------+
* | | |
* | | |
* | | |
* | | |
* | | |
* +-------------+
*/
static gboolean
moo_edit_tab_set_split_horizontal (MooEditTab *tab,
gboolean split)
{
g_return_val_if_fail (MOO_IS_EDIT_TAB (tab), FALSE);
if (!!split == moo_edit_tab_get_split_horizontal (tab))
return FALSE;
if (!split)
{
gboolean has_focus;
MooEditView *view1 = moo_edit_tab_get_view (tab, 2, 1);
MooEditView *view2 = moo_edit_tab_get_view (tab, 2, 2);
g_assert (view1 != NULL);
has_focus = (view1 && GTK_WIDGET_HAS_FOCUS (view1)) ||
(view2 && GTK_WIDGET_HAS_FOCUS (view2));
if (view1)
{
_moo_edit_remove_view (tab->doc, view1);
gtk_container_remove (GTK_CONTAINER (tab->vpaned2), GTK_WIDGET (view1)->parent);
}
if (view2)
{
_moo_edit_remove_view (tab->doc, view2);
gtk_container_remove (GTK_CONTAINER (tab->vpaned2), GTK_WIDGET (view2)->parent);
}
gtk_widget_hide (tab->vpaned2);
if (has_focus)
gtk_widget_grab_focus (GTK_WIDGET (moo_edit_tab_get_view (tab, 1, 1)));
}
else
{
GtkWidget *swin;
MooEditView *view1 = moo_edit_tab_get_view (tab, 1, 1);
MooEditView *view2 = moo_edit_tab_get_view (tab, 1, 2);
g_assert (view1 != NULL);
g_assert (!GTK_WIDGET_VISIBLE (tab->vpaned2));
g_assert (!gtk_container_get_children (GTK_CONTAINER (tab->vpaned2)));
if (view1)
{
swin = create_view_in_scrolled_window (tab);
gtk_paned_pack1 (GTK_PANED (tab->vpaned2), swin, TRUE, FALSE);
}
if (view2)
{
swin = create_view_in_scrolled_window (tab);
gtk_paned_pack2 (GTK_PANED (tab->vpaned2), swin, TRUE, FALSE);
}
gtk_widget_show_all (tab->vpaned2);
}
return TRUE;
}
/*
* +--------------+
* | |
* | |
* |--------------|
* | |
* | |
* +--------------+
*/
static gboolean
moo_edit_tab_get_split_vertical (MooEditTab *tab)
{
g_return_val_if_fail (MOO_IS_EDIT_TAB (tab), FALSE);
return gtk_paned_get_child1 (GTK_PANED (tab->vpaned1)) &&
gtk_paned_get_child2 (GTK_PANED (tab->vpaned1));
}
/*
* +--------------+
* | |
* | |
* |--------------|
* | |
* | |
* +--------------+
*/
static gboolean
moo_edit_tab_set_split_vertical (MooEditTab *tab,
gboolean split)
{
g_return_val_if_fail (MOO_IS_EDIT_TAB (tab), FALSE);
if (!!split == moo_edit_tab_get_split_vertical (tab))
return FALSE;
if (!split)
{
gboolean has_focus;
MooEditView *view1;
MooEditView *view2;
view1 = moo_edit_tab_get_view (tab, 1, 2);
view2 = moo_edit_tab_get_view (tab, 2, 2);
g_assert (view1 != NULL);
has_focus = (view1 && GTK_WIDGET_HAS_FOCUS (view1)) ||
(view2 && GTK_WIDGET_HAS_FOCUS (view2));
if (view1)
{
_moo_edit_remove_view (tab->doc, view1);
gtk_container_remove (GTK_CONTAINER (tab->vpaned1), GTK_WIDGET (view1)->parent);
}
if (view2)
{
_moo_edit_remove_view (tab->doc, view2);
gtk_container_remove (GTK_CONTAINER (tab->vpaned2), GTK_WIDGET (view2)->parent);
}
if (has_focus)
gtk_widget_grab_focus (GTK_WIDGET (moo_edit_tab_get_view (tab, 1, 1)));
}
else
{
GtkWidget *swin;
swin = create_view_in_scrolled_window (tab);
gtk_paned_pack2 (GTK_PANED (tab->vpaned1), swin, TRUE, FALSE);
if (GTK_WIDGET_VISIBLE (tab->vpaned2))
{
g_assert (gtk_paned_get_child1 (GTK_PANED (tab->vpaned2)) != NULL);
swin = create_view_in_scrolled_window (tab);
gtk_paned_pack2 (GTK_PANED (tab->vpaned2), swin, TRUE, FALSE);
}
}
return TRUE;
}
static void
split_view_horizontal_toggled (MooEditWindow *window,
@ -5037,7 +4650,7 @@ split_view_horizontal_toggled (MooEditWindow *window,
{
MooEditTab *tab = ACTIVE_TAB (window);
g_return_if_fail (tab != NULL);
if (moo_edit_tab_set_split_horizontal (tab, active))
if (_moo_edit_tab_set_split_horizontal (tab, active))
update_split_view_actions (window);
}
@ -5047,7 +4660,7 @@ split_view_vertical_toggled (MooEditWindow *window,
{
MooEditTab *tab = ACTIVE_TAB (window);
g_return_if_fail (tab != NULL);
if (moo_edit_tab_set_split_vertical (tab, active))
if (_moo_edit_tab_set_split_vertical (tab, active))
update_split_view_actions (window);
}
@ -5056,7 +4669,7 @@ action_focus_next_split_view (MooEditWindow *window)
{
MooEditTab *tab = ACTIVE_TAB (window);
g_return_if_fail (tab != NULL);
moo_edit_tab_focus_next_view (tab);
_moo_edit_tab_focus_next_view (tab);
update_doc_view_actions (window);
}
@ -5080,8 +4693,8 @@ update_split_view_actions (MooEditWindow *window)
action_split_vertical = moo_window_get_action (MOO_WINDOW (window), "SplitViewVertical");
g_return_if_fail (action_split_vertical != NULL);
has_split_horizontal = moo_edit_tab_get_split_horizontal (tab);
has_split_vertical = moo_edit_tab_get_split_vertical (tab);
has_split_horizontal = _moo_edit_tab_get_split_horizontal (tab);
has_split_vertical = _moo_edit_tab_get_split_vertical (tab);
gtk_action_set_sensitive (action_cycle, has_split_horizontal || has_split_vertical);
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action_split_horizontal), has_split_horizontal);
@ -5092,26 +4705,3 @@ update_split_view_actions (MooEditWindow *window)
sync_proxies (action_split_horizontal);
sync_proxies (action_split_vertical);
}
MooEditProgress *
_moo_edit_tab_create_progress (MooEditTab *tab)
{
g_return_val_if_fail (MOO_IS_EDIT_TAB (tab), NULL);
g_return_val_if_fail (!tab->progress, tab->progress);
tab->progress = _moo_edit_progress_new ();
gtk_box_pack_start (GTK_BOX (tab), GTK_WIDGET (tab->progress), FALSE, FALSE, 0);
gtk_box_reorder_child (GTK_BOX (tab), GTK_WIDGET (tab->progress), 0);
return tab->progress;
}
void
_moo_edit_tab_destroy_progress (MooEditTab *tab)
{
g_return_if_fail (MOO_IS_EDIT_TAB (tab));
g_return_if_fail (tab->progress != NULL);
gtk_widget_destroy (GTK_WIDGET (tab->progress));
tab->progress = NULL;
}