[gnome-builder/editor-layout] bring back restore file position when loading a file
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/editor-layout] bring back restore file position when loading a file
- Date: Mon, 1 Dec 2014 10:14:50 +0000 (UTC)
commit 5a333dd1985ad8569de8afdbee486b5dab84f9f7
Author: Christian Hergert <christian hergert me>
Date: Mon Dec 1 02:14:38 2014 -0800
bring back restore file position when loading a file
src/editor/gb-editor-tab.c | 55 ++++++++++++++++++++++++++++++++++++++
src/editor/gb-editor-tab.h | 29 ++++++++++---------
src/editor/gb-editor-workspace.c | 9 +++++-
3 files changed, 78 insertions(+), 15 deletions(-)
---
diff --git a/src/editor/gb-editor-tab.c b/src/editor/gb-editor-tab.c
index 91229cc..f60cac3 100644
--- a/src/editor/gb-editor-tab.c
+++ b/src/editor/gb-editor-tab.c
@@ -24,6 +24,8 @@
#include "gb-editor-frame-private.h"
#include "gb-editor-tab.h"
#include "gb-editor-tab-private.h"
+#include "gb-editor-file-mark.h"
+#include "gb-editor-file-marks.h"
#include "gb-log.h"
#include "gb-widget.h"
@@ -223,6 +225,8 @@ gb_editor_tab_open_file_cb (GObject *source_object,
g_clear_error (&error);
}
+ gb_editor_tab_restore_file_mark (tab);
+
gb_widget_fade_hide (GTK_WIDGET (tab->priv->progress_bar));
g_object_unref (tab);
@@ -254,6 +258,57 @@ gb_editor_tab_open_file (GbEditorTab *tab,
}
void
+gb_editor_tab_restore_file_mark (GbEditorTab *tab)
+{
+ GbEditorTabPrivate *priv;
+ GtkSourceFile *file;
+ GSettings *settings;
+ gboolean restore_mark;
+ GFile *location;
+
+ g_return_if_fail (GB_IS_EDITOR_TAB (tab));
+
+ priv = tab->priv;
+
+ settings = g_settings_new ("org.gnome.builder.editor");
+ restore_mark = g_settings_get_boolean (settings, "restore-insert-mark");
+ g_object_unref (settings);
+
+ if (!restore_mark)
+ {
+ GtkTextIter iter;
+
+ gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (tab->priv->document),
+ &iter);
+ gtk_text_buffer_select_range (GTK_TEXT_BUFFER (tab->priv->document),
+ &iter, &iter);
+ return;
+ }
+
+ file = gb_editor_document_get_file (priv->document);
+ location = gtk_source_file_get_location (file);
+
+ if (location)
+ {
+ GbEditorFileMarks *marks;
+ GbEditorFileMark *mark;
+ guint line;
+ guint column;
+
+ marks = gb_editor_file_marks_get_default ();
+ mark = gb_editor_file_marks_get_for_file (marks, location);
+
+ if (mark)
+ {
+ line = gb_editor_file_mark_get_line (mark);
+ column = gb_editor_file_mark_get_column (mark);
+
+ gb_editor_tab_scroll_to_line (tab, line, column);
+ }
+ }
+}
+
+void
gb_editor_tab_toggle_split (GbEditorTab *tab)
{
gboolean active;
diff --git a/src/editor/gb-editor-tab.h b/src/editor/gb-editor-tab.h
index bd769f9..0d96771 100644
--- a/src/editor/gb-editor-tab.h
+++ b/src/editor/gb-editor-tab.h
@@ -51,20 +51,21 @@ struct _GbEditorTabClass
GbTabClass parent_class;
};
-GbEditorTab *gb_editor_tab_new (void);
-GType gb_editor_tab_get_type (void) G_GNUC_CONST;
-void gb_editor_tab_save (GbEditorTab *tab);
-void gb_editor_tab_save_as (GbEditorTab *tab);
-void gb_editor_tab_open_file (GbEditorTab *tab,
- GFile *file);
-void gb_editor_tab_scroll_up (GbEditorTab *tab);
-void gb_editor_tab_scroll_down (GbEditorTab *tab);
-void gb_editor_tab_toggle_split (GbEditorTab *tab);
-void gb_editor_tab_find (GbEditorTab *tab);
-void gb_editor_tab_reformat (GbEditorTab *tab);
-void gb_editor_tab_scroll_to_line (GbEditorTab *tab,
- guint line,
- guint line_offset);
+GbEditorTab *gb_editor_tab_new (void);
+GType gb_editor_tab_get_type (void) G_GNUC_CONST;
+void gb_editor_tab_save (GbEditorTab *tab);
+void gb_editor_tab_save_as (GbEditorTab *tab);
+void gb_editor_tab_open_file (GbEditorTab *tab,
+ GFile *file);
+void gb_editor_tab_scroll_up (GbEditorTab *tab);
+void gb_editor_tab_scroll_down (GbEditorTab *tab);
+void gb_editor_tab_toggle_split (GbEditorTab *tab);
+void gb_editor_tab_find (GbEditorTab *tab);
+void gb_editor_tab_reformat (GbEditorTab *tab);
+void gb_editor_tab_scroll_to_line (GbEditorTab *tab,
+ guint line,
+ guint line_offset);
+void gb_editor_tab_restore_file_mark (GbEditorTab *tab);
G_END_DECLS
diff --git a/src/editor/gb-editor-workspace.c b/src/editor/gb-editor-workspace.c
index c40a90e..eeac693 100644
--- a/src/editor/gb-editor-workspace.c
+++ b/src/editor/gb-editor-workspace.c
@@ -28,7 +28,9 @@ enum {
LAST_PROP
};
-G_DEFINE_TYPE_WITH_PRIVATE (GbEditorWorkspace, gb_editor_workspace, GB_TYPE_WORKSPACE)
+G_DEFINE_TYPE_WITH_PRIVATE (GbEditorWorkspace,
+ gb_editor_workspace,
+ GB_TYPE_WORKSPACE)
void
gb_editor_workspace_open (GbEditorWorkspace *workspace,
@@ -219,12 +221,17 @@ open_tab (GSimpleAction *action,
GFile *file = iter->data;
tab = gb_editor_tab_new ();
+
gb_editor_tab_open_file (tab, file);
+
gtk_container_add (GTK_CONTAINER (workspace->priv->tab_grid),
GTK_WIDGET (tab));
+
gtk_widget_show (GTK_WIDGET (tab));
gtk_widget_grab_focus (GTK_WIDGET (tab));
+ gb_editor_tab_restore_file_mark (tab);
+
g_clear_object (&file);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]