Save and restore cursor in each split view

This commit is contained in:
Yevgen Muntyan 2011-01-18 22:01:18 -08:00
parent 2f740f78ca
commit 841e953d2a
5 changed files with 54 additions and 0 deletions

View File

@ -29,6 +29,7 @@ struct MooEditPrivate {
GtkTextBuffer *buffer;
MooEditViewArray *views;
MooEditView *active_view;
gboolean dead_active_view;
gulong modified_changed_handler_id;
guint apply_config_idle;

View File

@ -324,12 +324,35 @@ void
_moo_edit_set_active_view (MooEdit *doc,
MooEditView *view)
{
GtkTextBuffer *buffer;
g_return_if_fail (MOO_IS_EDIT (doc));
g_return_if_fail (MOO_IS_EDIT_VIEW (view));
g_return_if_fail (moo_edit_view_array_find (doc->priv->views, view) >= 0);
buffer = moo_edit_get_buffer (doc);
if (doc->priv->active_view != NULL && doc->priv->active_view != view)
{
GtkTextIter iter;
GtkTextMark *mark = _moo_edit_view_get_fake_cursor_mark (doc->priv->active_view);
gtk_text_buffer_get_iter_at_mark (buffer, &iter, gtk_text_buffer_get_insert (buffer));
gtk_text_buffer_move_mark (buffer, mark, &iter);
}
if (doc->priv->dead_active_view ||
(doc->priv->active_view != NULL && doc->priv->active_view != view))
{
GtkTextIter iter;
GtkTextBuffer *buffer = moo_edit_get_buffer (doc);
GtkTextMark *mark = _moo_edit_view_get_fake_cursor_mark (view);
gtk_text_buffer_get_iter_at_mark (buffer, &iter, mark);
gtk_text_buffer_place_cursor (buffer, &iter);
}
doc->priv->active_view = view;
doc->priv->dead_active_view = FALSE;
}
void
@ -359,7 +382,10 @@ _moo_edit_remove_view (MooEdit *doc,
g_return_if_fail (moo_edit_view_array_find (doc->priv->views, view) >= 0);
if (view == doc->priv->active_view)
{
doc->priv->active_view = NULL;
doc->priv->dead_active_view = TRUE;
}
g_object_ref (view);

View File

@ -10,6 +10,8 @@ void _moo_edit_view_unset_doc (MooEditView *view);
void _moo_edit_view_set_tab (MooEditView *view,
MooEditTab *tab);
GtkTextMark *_moo_edit_view_get_fake_cursor_mark (MooEditView *view);
void _moo_edit_view_apply_prefs (MooEditView *view);
void _moo_edit_view_apply_config (MooEditView *view);

View File

@ -10,6 +10,7 @@ struct MooEditViewPrivate
MooEdit *doc;
MooEditor *editor;
MooEditTab *tab;
GtkTextMark *fake_cursor_mark;
};
G_END_DECLS

View File

@ -76,6 +76,13 @@ moo_edit_view_dispose (GObject *object)
{
MooEditView *view = MOO_EDIT_VIEW (object);
if (view->priv->fake_cursor_mark)
{
GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
gtk_text_buffer_delete_mark (buffer, view->priv->fake_cursor_mark);
view->priv->fake_cursor_mark = NULL;
}
if (view->priv->doc)
{
_moo_edit_remove_view (view->priv->doc, view);
@ -192,6 +199,23 @@ moo_edit_view_get_window (MooEditView *view)
}
GtkTextMark *
_moo_edit_view_get_fake_cursor_mark (MooEditView *view)
{
g_return_val_if_fail (MOO_IS_EDIT_VIEW (view), NULL);
if (!view->priv->fake_cursor_mark)
{
GtkTextIter iter;
GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
gtk_text_buffer_get_start_iter (buffer, &iter);
view->priv->fake_cursor_mark = gtk_text_buffer_create_mark (buffer, NULL, &iter, FALSE);
}
return view->priv->fake_cursor_mark;
}
void
_moo_edit_view_apply_config (MooEditView *view)
{