[gnome-builder] prefs: add preference to enable jump to last position feature.
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] prefs: add preference to enable jump to last position feature.
- Date: Wed, 8 Oct 2014 23:55:17 +0000 (UTC)
commit 429698975c7153176decd2c48aadf9acd83f2e8c
Author: Christian Hergert <christian hergert me>
Date: Wed Oct 8 16:55:10 2014 -0700
prefs: add preference to enable jump to last position feature.
This requires at least performing a `make install-gsettings-schemas or
you will get a crash when hitting the gsettings code.
`make install` works too.
data/org.gnome.builder.editor.gschema.xml.in | 6 ++++
src/editor/gb-editor-tab.c | 15 +++++++++
src/preferences/gb-preferences-window.c | 40 +++++++++++--------------
src/resources/ui/gb-preferences-window.ui | 26 +++++++++++++++++
4 files changed, 65 insertions(+), 22 deletions(-)
---
diff --git a/data/org.gnome.builder.editor.gschema.xml.in b/data/org.gnome.builder.editor.gschema.xml.in
index 8bfa20e..200f987 100644
--- a/data/org.gnome.builder.editor.gschema.xml.in
+++ b/data/org.gnome.builder.editor.gschema.xml.in
@@ -5,5 +5,11 @@
<summary>Enable VIM keybindings</summary>
<description>Whether or not VIM style keybindings should be used in the source code
editor.</description>
</key>
+ <key name="restore-insert-mark" type="b">
+ <default>true</default>
+ <summary>Restore last position</summary>
+ <summary>Jump to the last position when reopening a file.</summary>
+ <description>Whether or not VIM style keybindings should be used in the source code
editor.</description>
+ </key>
</schema>
</schemalist>
diff --git a/src/editor/gb-editor-tab.c b/src/editor/gb-editor-tab.c
index fab3a2a..beea4b5 100644
--- a/src/editor/gb-editor-tab.c
+++ b/src/editor/gb-editor-tab.c
@@ -1343,14 +1343,29 @@ gb_editor_tab_load_file_mark (GbEditorTab *tab)
GbEditorFileMark *mark;
GtkTextBuffer *buffer;
GtkTextIter iter;
+ GSettings *settings;
+ gboolean load_mark;
GFile *file;
guint line;
guint column;
g_return_if_fail (GB_IS_EDITOR_TAB (tab));
+ settings = g_settings_new ("org.gnome.builder.editor");
+ load_mark = g_settings_get_boolean (settings, "restore-insert-mark");
+ g_clear_object (&settings);
+
buffer = GTK_TEXT_BUFFER (tab->priv->document);
+ if (!load_mark)
+ {
+ gtk_text_buffer_get_start_iter (buffer, &iter);
+ gtk_text_buffer_select_range (buffer, &iter, &iter);
+ gb_gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (tab->priv->source_view),
+ &iter, 0.0, TRUE, 0.5, 0.5);
+ return;
+ }
+
file = gtk_source_file_get_location (tab->priv->file);
marks = gb_editor_file_marks_get_default ();
mark = gb_editor_file_marks_get_for_file (marks, file);
diff --git a/src/preferences/gb-preferences-window.c b/src/preferences/gb-preferences-window.c
index e9a4cf6..afef37a 100644
--- a/src/preferences/gb-preferences-window.c
+++ b/src/preferences/gb-preferences-window.c
@@ -36,6 +36,7 @@ struct _GbPreferencesWindowPrivate
GtkStack *stack;
GtkSwitch *vim_switch;
+ GtkSwitch *restore_insert_mark_switch;
GtkEntry *git_author_name_entry;
GtkEntry *git_author_email_entry;
@@ -75,13 +76,20 @@ gb_preferences_window_section_changed (GtkStack *stack,
static void
load_editor (GbPreferencesWindow *window)
{
+ GbPreferencesWindowPrivate *priv;
GSettings *settings;
g_return_if_fail (GB_IS_PREFERENCES_WINDOW (window));
+ priv = window->priv;
+
settings = g_settings_new ("org.gnome.builder.editor");
- g_settings_bind (settings, "vim-mode", window->priv->vim_switch, "active",
+ g_settings_bind (settings, "vim-mode",
+ priv->vim_switch, "active",
+ G_SETTINGS_BIND_DEFAULT);
+ g_settings_bind (settings, "restore-insert-mark",
+ priv->restore_insert_mark_switch, "active",
G_SETTINGS_BIND_DEFAULT);
g_object_unref (settings);
@@ -175,27 +183,15 @@ gb_preferences_window_class_init (GbPreferencesWindowClass *klass)
gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/builder/ui/gb-preferences-window.ui");
- gtk_widget_class_bind_template_child_private (widget_class,
- GbPreferencesWindow,
- right_header_bar);
- gtk_widget_class_bind_template_child_private (widget_class,
- GbPreferencesWindow,
- search_bar);
- gtk_widget_class_bind_template_child_private (widget_class,
- GbPreferencesWindow,
- search_entry);
- gtk_widget_class_bind_template_child_private (widget_class,
- GbPreferencesWindow,
- stack);
- gtk_widget_class_bind_template_child_private (widget_class,
- GbPreferencesWindow,
- vim_switch);
- gtk_widget_class_bind_template_child_private (widget_class,
- GbPreferencesWindow,
- git_author_name_entry);
- gtk_widget_class_bind_template_child_private (widget_class,
- GbPreferencesWindow,
- git_author_email_entry);
+
+ gtk_widget_class_bind_template_child_private (widget_class, GbPreferencesWindow, git_author_email_entry);
+ gtk_widget_class_bind_template_child_private (widget_class, GbPreferencesWindow, git_author_name_entry);
+ gtk_widget_class_bind_template_child_private (widget_class, GbPreferencesWindow,
restore_insert_mark_switch);
+ gtk_widget_class_bind_template_child_private (widget_class, GbPreferencesWindow, right_header_bar);
+ gtk_widget_class_bind_template_child_private (widget_class, GbPreferencesWindow, search_bar);
+ gtk_widget_class_bind_template_child_private (widget_class, GbPreferencesWindow, search_entry);
+ gtk_widget_class_bind_template_child_private (widget_class, GbPreferencesWindow, stack);
+ gtk_widget_class_bind_template_child_private (widget_class, GbPreferencesWindow, vim_switch);
g_type_ensure (GB_TYPE_SIDEBAR);
}
diff --git a/src/resources/ui/gb-preferences-window.ui b/src/resources/ui/gb-preferences-window.ui
index 2e10c4e..a3487af 100644
--- a/src/resources/ui/gb-preferences-window.ui
+++ b/src/resources/ui/gb-preferences-window.ui
@@ -136,6 +136,32 @@
<property name="height">1</property>
</packing>
</child>
+ <child>
+ <object class="GtkLabel" id="restore_insert_mark_label">
+ <property name="visible">True</property>
+ <property name="halign">start</property>
+ <property name="hexpand">True</property>
+ <property name="label" translatable="Yes">Jump to last position when reopening a
file.</property>
+ </object>
+ <packing>
+ <property name="left-attach">0</property>
+ <property name="width">1</property>
+ <property name="top-attach">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSwitch" id="restore_insert_mark_switch">
+ <property name="visible">True</property>
+ <property name="active">False</property>
+ </object>
+ <packing>
+ <property name="left-attach">1</property>
+ <property name="width">1</property>
+ <property name="top-attach">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="name">editor</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]