Skip to content

Commit 95f037b

Browse files
author
Jeremy Wootten
authored
Ensure tab toggle label is always correct (#1145)
* Make settings source of truth for indent-width etc * Do not allow individual documents to change global settings * Update document when settings change * Code style
1 parent fa17876 commit 95f037b

2 files changed

Lines changed: 7 additions & 23 deletions

File tree

src/Widgets/FormatBar.vala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,23 +173,24 @@ public class Code.FormatBar : Gtk.Grid {
173173
tab_popover.add (tab_grid);
174174

175175
tab_toggle.bind_property ("active", tab_popover, "visible", GLib.BindingFlags.BIDIRECTIONAL);
176-
Scratch.settings.changed["indent-width"].connect (() => format_tab_header ());
177-
Scratch.settings.changed["spaces-instead-of-tabs"].connect (() => format_tab_header ());
176+
Scratch.settings.changed["indent-width"].connect (format_tab_header);
177+
Scratch.settings.changed["spaces-instead-of-tabs"].connect (format_tab_header);
178178
}
179179

180180
private void format_tab_header () {
181181
var indent_width = Scratch.settings.get_int ("indent-width");
182182
var spaces_instead_of_tabs = Scratch.settings.get_boolean ("spaces-instead-of-tabs");
183-
if (doc != null) {
184-
indent_width = (int)doc.source_view.tab_width;
185-
spaces_instead_of_tabs = doc.source_view.insert_spaces_instead_of_tabs;
186-
}
187183

188184
if (spaces_instead_of_tabs) {
189185
tab_toggle.text = ngettext ("%d Space", "%d Spaces", indent_width).printf (indent_width);
190186
} else {
191187
tab_toggle.text = ngettext ("%d Tab", "%d Tabs", indent_width).printf (indent_width);
192188
}
189+
190+
if (doc != null) {
191+
doc.source_view.tab_width = (uint)indent_width;
192+
doc.source_view.insert_spaces_instead_of_tabs = spaces_instead_of_tabs;
193+
}
193194
}
194195

195196
private void format_line_header () {

src/Widgets/SourceView.vala

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,6 @@ namespace Scratch.Widgets {
207207
return !start.equal (end);
208208
}
209209

210-
~SourceView () {
211-
// Update settings when an instance is deleted
212-
update_settings ();
213-
}
214-
215210
public void change_syntax_highlight_from_file (File file) {
216211
try {
217212
var info = file.query_info ("standard::*", FileQueryInfoFlags.NONE, null);
@@ -298,18 +293,6 @@ namespace Scratch.Widgets {
298293
style_changed (source_buffer.style_scheme);
299294
}
300295

301-
private void update_settings () {
302-
var source_buffer = (Gtk.SourceBuffer) buffer;
303-
Scratch.settings.set_boolean ("show-right-margin", show_right_margin);
304-
Scratch.settings.set_int ("right-margin-position", (int) right_margin_position);
305-
Scratch.settings.set_boolean ("highlight-matching-brackets", source_buffer.highlight_matching_brackets);
306-
Scratch.settings.set_boolean ("spaces-instead-of-tabs", insert_spaces_instead_of_tabs);
307-
Scratch.settings.set_int ("indent-width", (int) tab_width);
308-
Scratch.settings.set_string ("font", font);
309-
Scratch.settings.set_string ("style-scheme", source_buffer.style_scheme.id);
310-
style_changed (source_buffer.style_scheme);
311-
}
312-
313296
public void go_to_line (int line, int offset = 0) {
314297
Gtk.TextIter it;
315298
buffer.get_iter_at_line (out it, line - 1);

0 commit comments

Comments
 (0)