Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FormatBar: absorb line width guide settings #1237

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
11 changes: 0 additions & 11 deletions src/Dialogs/PreferencesDialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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:"));
Expand All @@ -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);
Expand Down
51 changes: 41 additions & 10 deletions src/Widgets/FormatBar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -233,21 +233,48 @@ public class Code.FormatBar : Gtk.Box {
}

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_menubutton);
line_popover.position = Gtk.PositionType.BOTTOM;
line_popover.add (line_grid);
var line_popover = new Gtk.Popover (line_menubutton) {
position = Gtk.PositionType.BOTTOM
};
line_popover.add (box);

line_menubutton.popover = line_popover;

Expand All @@ -260,6 +287,10 @@ public class Code.FormatBar : Gtk.Box {
// 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) {
Expand Down