From f20d5a5d3049162e6b768ddb4b3cdaefe54f71e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Fri, 13 Jan 2023 17:50:38 -0800 Subject: [PATCH] FormatBar: absorb line width guide settings --- src/Dialogs/PreferencesDialog.vala | 11 ------- src/Widgets/FormatBar.vala | 51 ++++++++++++++++++++++++------ 2 files changed, 41 insertions(+), 21 deletions(-) diff --git a/src/Dialogs/PreferencesDialog.vala b/src/Dialogs/PreferencesDialog.vala index f5878982e6..de8dd8158e 100644 --- a/src/Dialogs/PreferencesDialog.vala +++ b/src/Dialogs/PreferencesDialog.vala @@ -128,14 +128,6 @@ namespace Scratch.Dialogs { var show_mini_map_label = new SettingsLabel (_("Show Mini Map:")); show_mini_map = new SettingsSwitch ("show-mini-map"); - var show_right_margin_label = new SettingsLabel (_("Line width guide:")); - var show_right_margin = new SettingsSwitch ("show-right-margin"); - - var right_margin_position = new Gtk.SpinButton.with_range (1, 250, 1); - right_margin_position.hexpand = true; - Scratch.settings.bind ("right-margin-position", right_margin_position, "value", SettingsBindFlags.DEFAULT); - Scratch.settings.bind ("show-right-margin", right_margin_position, "sensitive", SettingsBindFlags.DEFAULT); - var font_header = new Granite.HeaderLabel (_("Font")); var use_custom_font_label = new SettingsLabel (_("Custom font:")); @@ -158,9 +150,6 @@ namespace Scratch.Dialogs { content.attach (draw_spaces_switch, 1, 4, 2, 1); content.attach (show_mini_map_label, 0, 5, 1, 1); content.attach (show_mini_map, 1, 5, 1, 1); - content.attach (show_right_margin_label, 0, 6, 1, 1); - content.attach (show_right_margin, 1, 6, 1, 1); - content.attach (right_margin_position, 2, 7, 1, 1); content.attach (font_header, 0, 7, 3, 1); content.attach (use_custom_font_label , 0, 9, 1, 1); content.attach (use_custom_font, 1, 9, 1, 1); diff --git a/src/Widgets/FormatBar.vala b/src/Widgets/FormatBar.vala index 458f63fb6a..6b078fb111 100644 --- a/src/Widgets/FormatBar.vala +++ b/src/Widgets/FormatBar.vala @@ -201,21 +201,48 @@ public class Code.FormatBar : Gtk.Grid { } private void create_line_popover () { + var line_width_modelbutton = new Granite.SwitchModelButton (_("Line Width Guide")); + + var line_width_label = new Gtk.Label (_("Line width:")) { + halign = Gtk.Align.START, + hexpand = true + }; + + var line_width = new Gtk.SpinButton.with_range (1, 250, 1); + + var line_width_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 12) { + margin_top = 6, + margin_end = 12, + margin_start = 12, + }; + line_width_box.add (line_width_label); + line_width_box.add (line_width); + var goto_label = new Gtk.Label (_("Go To Line:")); - goto_label.xalign = 1; goto_entry = new Gtk.Entry (); - var line_grid = new Gtk.Grid (); - line_grid.margin = 12; - line_grid.column_spacing = 12; - line_grid.attach (goto_label, 0, 0, 1, 1); - line_grid.attach (goto_entry, 1, 0, 1, 1); - line_grid.show_all (); + var goto_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 12) { + margin_top = 6, + margin_end = 12, + margin_start = 12, + }; + goto_box.add (goto_label); + goto_box.add (goto_entry); + + var box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0) { + margin_top = 6, + margin_bottom = 12 + }; + box.add (line_width_modelbutton); + box.add (line_width_box); + box.add (goto_box); + box.show_all (); - var line_popover = new Gtk.Popover (line_toggle); - line_popover.position = Gtk.PositionType.BOTTOM; - line_popover.add (line_grid); + var line_popover = new Gtk.Popover (line_toggle) { + position = Gtk.PositionType.BOTTOM + }; + line_popover.add (box); line_toggle.bind_property ("active", line_popover, "visible", GLib.BindingFlags.BIDIRECTIONAL); // We need to connect_after because otherwise, the text isn't parsed into the "value" property and we only get the previous value @@ -229,6 +256,10 @@ public class Code.FormatBar : Gtk.Grid { // Focuses parent to the source view, so that the cursor, which indicates line and column is actually visible. doc.source_view.grab_focus (); }); + + Scratch.settings.bind ("right-margin-position", line_width, "value", SettingsBindFlags.DEFAULT); + Scratch.settings.bind ("show-right-margin", line_width_box, "sensitive", SettingsBindFlags.GET); + Scratch.settings.bind ("show-right-margin", line_width_modelbutton, "active", SettingsBindFlags.DEFAULT); } public void set_document (Scratch.Services.Document doc) {