From 2f740f78ca6ae1118aff1e9acb3b200a8b4d7844 Mon Sep 17 00:00:00 2001 From: Yevgen Muntyan <17531749+muntyan@users.noreply.github.com> Date: Tue, 18 Jan 2011 21:36:06 -0800 Subject: [PATCH] Simplified active/focused view/tab business: views belong to tabs, tabs belong to windows, docs also track views --- moo/mooedit/mooedit-impl.h | 4 +- moo/mooedit/mooedit.c | 6 +-- moo/mooedit/mooedittab.c | 2 + moo/mooedit/mooeditview.c | 5 ++- moo/mooedit/mooeditwindow-impl.h | 4 +- moo/mooedit/mooeditwindow.c | 77 +++++++++++++------------------- 6 files changed, 42 insertions(+), 56 deletions(-) diff --git a/moo/mooedit/mooedit-impl.h b/moo/mooedit/mooedit-impl.h index 1c46f6c1..79449e0b 100644 --- a/moo/mooedit/mooedit-impl.h +++ b/moo/mooedit/mooedit-impl.h @@ -28,12 +28,12 @@ G_BEGIN_DECLS extern MooEditList *_moo_edit_instances; -void _moo_edit_set_focused_view (MooEdit *doc, - MooEditView *view); void _moo_edit_add_view (MooEdit *doc, MooEditView *view); void _moo_edit_remove_view (MooEdit *doc, MooEditView *view); +void _moo_edit_set_active_view (MooEdit *doc, + MooEditView *view); gboolean _moo_edit_is_busy (MooEdit *doc); MooEditState _moo_edit_get_state (MooEdit *doc); diff --git a/moo/mooedit/mooedit.c b/moo/mooedit/mooedit.c index ef1fab9a..2a5e2394 100644 --- a/moo/mooedit/mooedit.c +++ b/moo/mooedit/mooedit.c @@ -321,13 +321,13 @@ moo_edit_dispose (GObject *object) void -_moo_edit_set_focused_view (MooEdit *doc, - MooEditView *view) +_moo_edit_set_active_view (MooEdit *doc, + MooEditView *view) { g_return_if_fail (MOO_IS_EDIT (doc)); g_return_if_fail (MOO_IS_EDIT_VIEW (view)); - g_assert (moo_edit_view_array_find (doc->priv->views, view) >= 0); + g_return_if_fail (moo_edit_view_array_find (doc->priv->views, view) >= 0); doc->priv->active_view = view; } diff --git a/moo/mooedit/mooedittab.c b/moo/mooedit/mooedittab.c index 39782f08..be49ac83 100644 --- a/moo/mooedit/mooedittab.c +++ b/moo/mooedit/mooedittab.c @@ -4,6 +4,7 @@ #include "mooedittab-impl.h" #include "mooeditview-impl.h" +#include "mooeditwindow-impl.h" #include "mooedit-impl.h" #include @@ -176,6 +177,7 @@ _moo_edit_tab_set_focused_view (MooEditTab *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; + _moo_edit_window_set_active_tab (moo_edit_tab_get_window (tab), tab); } MooEditWindow * diff --git a/moo/mooedit/mooeditview.c b/moo/mooedit/mooeditview.c index 78c08ed2..4a98c935 100644 --- a/moo/mooedit/mooeditview.c +++ b/moo/mooedit/mooeditview.c @@ -6,6 +6,7 @@ #include "mooedit/mooeditview-priv.h" #include "mooedit/mooedit-impl.h" #include "mooedit/mooeditwindow-impl.h" +#include "mooedit/mooedittab-impl.h" #include "mooedit/mooeditor-impl.h" #include "mooedit/mooeditbookmark.h" #include "mooedit/mooeditprefs.h" @@ -137,8 +138,8 @@ moo_edit_view_focus_in (GtkWidget *widget, if (GTK_WIDGET_CLASS (moo_edit_view_parent_class)->focus_in_event) retval = GTK_WIDGET_CLASS (moo_edit_view_parent_class)->focus_in_event (widget, event); - _moo_edit_set_focused_view (view->priv->doc, view); - _moo_edit_window_set_focused_view (moo_edit_view_get_window (view), view); + _moo_edit_set_active_view (view->priv->doc, view); + _moo_edit_tab_set_focused_view (moo_edit_view_get_tab (view), view); return retval; } diff --git a/moo/mooedit/mooeditwindow-impl.h b/moo/mooedit/mooeditwindow-impl.h index ed90642a..6786000b 100644 --- a/moo/mooedit/mooeditwindow-impl.h +++ b/moo/mooedit/mooeditwindow-impl.h @@ -14,8 +14,8 @@ void _moo_edit_window_insert_doc (MooEditWindow *window, MooEditView *after); void _moo_edit_window_remove_doc (MooEditWindow *window, MooEdit *doc); -void _moo_edit_window_set_focused_view (MooEditWindow *window, - MooEditView *view); +void _moo_edit_window_set_active_tab (MooEditWindow *window, + MooEditTab *tab); void _moo_edit_window_update_title (void); void _moo_edit_window_set_use_tabs (void); diff --git a/moo/mooedit/mooeditwindow.c b/moo/mooedit/mooeditwindow.c index eef1ab1e..492c4594 100644 --- a/moo/mooedit/mooeditwindow.c +++ b/moo/mooedit/mooeditwindow.c @@ -99,7 +99,7 @@ struct MooEditWindowPrivate { GtkWidget *doc_paned; MooNotebookArray *notebooks; - MooEditView *active_view; + MooEditTab *active_tab; guint save_params_idle; char *title_format; @@ -2008,7 +2008,6 @@ move_tab_to_split_view (MooEditWindow *window, GtkWidget *label; MooEdit *doc; int n_pages1, n_pages2; - MooEditView *active_view; g_return_if_fail (MOO_IS_EDIT_WINDOW (window)); g_return_if_fail (MOO_IS_EDIT_TAB (tab)); @@ -2049,11 +2048,7 @@ move_tab_to_split_view (MooEditWindow *window, g_object_ref (tab); - active_view = window->priv->active_view; - window->priv->active_view = NULL; - - if (!active_view || moo_edit_view_get_tab (active_view) != tab) - active_view = moo_edit_tab_get_active_view (tab); + window->priv->active_tab = NULL; gtk_container_remove (GTK_CONTAINER (old_nb), GTK_WIDGET (tab)); label = create_tab_label (window, tab, doc); @@ -2061,27 +2056,20 @@ move_tab_to_split_view (MooEditWindow *window, moo_notebook_insert_page (new_nb, GTK_WIDGET (tab), label, moo_notebook_get_current_page (new_nb) + 1); - moo_edit_window_set_active_view (window, active_view); + moo_edit_window_set_active_view (window, moo_edit_tab_get_active_view (tab)); edit_changed (window, doc); g_object_unref (tab); } void -_moo_edit_window_set_focused_view (MooEditWindow *window, - MooEditView *view) +_moo_edit_window_set_active_tab (MooEditWindow *window, + MooEditTab *tab) { - MooEditTab *tab; - g_return_if_fail (MOO_IS_EDIT_WINDOW (window)); - g_return_if_fail (MOO_IS_EDIT_VIEW (view)); - - tab = moo_edit_view_get_tab (view); g_return_if_fail (MOO_IS_EDIT_TAB (tab)); - - window->priv->active_view = view; - - _moo_edit_tab_set_focused_view (tab, view); + g_return_if_fail (moo_edit_tab_get_window (tab) == window); + window->priv->active_tab = tab; } static void @@ -2268,16 +2256,8 @@ get_active_notebook (MooEditWindow *window) else if (!GTK_WIDGET_VISIBLE (nb1)) return nb2; - if (window->priv->active_view) - { - MooEditTab *tab = moo_edit_view_get_tab (window->priv->active_view); - if (moo_notebook_page_num (nb1, GTK_WIDGET (tab)) >= 0) - return nb1; - else if (moo_notebook_page_num (nb2, GTK_WIDGET (tab)) >= 0) - return nb2; - else - g_return_val_if_reached (nb1); - } + if (window->priv->active_tab) + return MOO_NOTEBOOK (gtk_widget_get_parent (GTK_WIDGET (window->priv->active_tab))); if (moo_notebook_get_n_pages (nb1) > 0) return nb1; @@ -2547,13 +2527,23 @@ moo_edit_window_get_active_doc (MooEditWindow *window) */ MooEditView * moo_edit_window_get_active_view (MooEditWindow *window) +{ + MooEditTab *tab = moo_edit_window_get_active_tab (window); + return tab ? moo_edit_tab_get_active_view (tab) : NULL; +} + +/** + * moo_edit_window_get_active_tab: + */ +MooEditTab * +moo_edit_window_get_active_tab (MooEditWindow *window) { g_return_val_if_fail (MOO_IS_EDIT_WINDOW (window), NULL); if (moo_notebook_array_is_empty (window->priv->notebooks)) return NULL; - if (!window->priv->active_view) + if (!window->priv->active_tab) { GtkWidget *tab; int page; @@ -2567,20 +2557,10 @@ moo_edit_window_get_active_view (MooEditWindow *window) return NULL; tab = moo_notebook_get_nth_page (notebook, page); - window->priv->active_view = moo_edit_tab_get_active_view (MOO_EDIT_TAB (tab)); + window->priv->active_tab = MOO_EDIT_TAB (tab); } - return window->priv->active_view; -} - -/** - * moo_edit_window_get_active_tab: - */ -MooEditTab * -moo_edit_window_get_active_tab (MooEditWindow *window) -{ - MooEditView *view = moo_edit_window_get_active_view (window); - return view ? moo_edit_view_get_tab (view) : NULL; + return window->priv->active_tab; } @@ -2640,7 +2620,7 @@ moo_edit_window_set_active_view (MooEditWindow *window, page = get_view_page_num (window, view, ¬ebook); g_return_if_fail (page >= 0); - window->priv->active_view = view; + window->priv->active_tab = moo_edit_view_get_tab (view); moo_notebook_set_current_page (notebook, page); gtk_widget_grab_focus (GTK_WIDGET (view)); } @@ -2983,24 +2963,27 @@ _moo_edit_window_remove_doc (MooEditWindow *window, MooEditViewArray *views; gboolean had_focus = FALSE; MooNotebook *notebook = NULL; + MooEditTab *tab; guint i; g_return_if_fail (MOO_IS_EDIT_WINDOW (window)); g_return_if_fail (MOO_IS_EDIT (doc)); + tab = moo_edit_get_tab (doc); + g_return_if_fail (MOO_IS_EDIT_TAB (tab)); + views = moo_edit_get_views (doc); g_return_if_fail (moo_edit_view_array_get_size (views) > 0); page = get_view_page_num (window, views->elms[0], ¬ebook); g_return_if_fail (notebook != NULL && page >= 0); + if (tab == window->priv->active_tab) + window->priv->active_tab = NULL; + for (i = 0; i < views->n_elms; ++i) { MooEditView *view = views->elms[i]; - - if (view == window->priv->active_view) - window->priv->active_view = NULL; - had_focus = had_focus || GTK_WIDGET_HAS_FOCUS (view); }