-
-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathPreferencesDialog.vala
More file actions
197 lines (167 loc) · 8.39 KB
/
PreferencesDialog.vala
File metadata and controls
197 lines (167 loc) · 8.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
// -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*-
/*
* Copyright (c) 2011-2017 elementary LLC (https://elementary.io)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Authored by: Giulio Collura <random.cpp@gmail.com>
* Mario Guerriero <mario@elementaryos.org>
* Fabio Zaramella <ffabio.96.x@gmail.com>
*/
namespace Scratch.Dialogs {
public class Preferences : Granite.Dialog {
private Gtk.Stack main_stack;
private Gtk.Switch highlight_matching_brackets;
private Gtk.Switch use_custom_font;
private Gtk.FontButton select_font;
private Gtk.Switch show_mini_map;
public Preferences (Gtk.Window? parent, Services.PluginsManager plugins) {
Object (
deletable: false,
resizable: false,
title: _("Preferences"),
transient_for: parent
);
create_layout (plugins);
}
construct {
var smart_cut_copy_info = new Gtk.Image.from_icon_name ("dialog-information-symbolic", Gtk.IconSize.MENU);
smart_cut_copy_info.halign = Gtk.Align.START;
smart_cut_copy_info.tooltip_text = _("Cutting or copying without an active selection will cut or copy the entire current line");
var indent_width = new Gtk.SpinButton.with_range (1, 24, 1);
Scratch.settings.bind ("indent-width", indent_width, "value", SettingsBindFlags.DEFAULT);
var general_grid = new Gtk.Grid ();
general_grid.column_spacing = 12;
general_grid.row_spacing = 6;
general_grid.attach (new Granite.HeaderLabel (_("General")), 0, 0, 3);
general_grid.attach (new SettingsLabel (_("Save files when changed:")), 0, 1);
general_grid.attach (new SettingsSwitch ("autosave"), 1, 1, 2);
general_grid.attach (new SettingsLabel (_("Smart cut/copy lines:")), 0, 2);
general_grid.attach (new SettingsSwitch ("smart-cut-copy"), 1, 2);
general_grid.attach (smart_cut_copy_info, 2, 2);
general_grid.attach (new Granite.HeaderLabel (_("Tabs")), 0, 3, 3);
general_grid.attach (new SettingsLabel (_("Automatic indentation:")), 0, 4);
general_grid.attach (new SettingsSwitch ("auto-indent"), 1, 4, 2);
general_grid.attach (new SettingsLabel (_("Insert spaces instead of tabs:")), 0, 5);
general_grid.attach (new SettingsSwitch ("spaces-instead-of-tabs"), 1, 5, 2);
general_grid.attach (new SettingsLabel (_("Strip trailing whitespace:")), 0, 6);
general_grid.attach (new SettingsSwitch ("strip-trailing-on-save"), 1, 6, 2);
general_grid.attach (new SettingsLabel (_("Tab width:")), 0, 7);
general_grid.attach (indent_width, 1, 7, 2);
main_stack = new Gtk.Stack () {
margin = 12
};
main_stack.add_titled (general_grid, "behavior", _("Behavior"));
main_stack.add_titled (get_editor_box (), "interface", _("Interface"));
var main_stackswitcher = new Gtk.StackSwitcher ();
main_stackswitcher.set_stack (main_stack);
main_stackswitcher.halign = Gtk.Align.CENTER;
var main_grid = new Gtk.Grid () {
row_spacing = 12
};
main_grid.attach (main_stackswitcher, 0, 0);
main_grid.attach (main_stack, 0, 1);
border_width = 0;
get_content_area ().add (main_grid);
var close_button = (Gtk.Button) add_button (_("Close"), Gtk.ResponseType.CLOSE);
close_button.clicked.connect (() => {
destroy ();
});
}
private void create_layout (Services.PluginsManager plugins) {
// Plugin hook function
plugins.hook_preferences_dialog (this);
if (Peas.Engine.get_default ().get_plugin_list ().length () > 0) {
var pbox = plugins.get_view ();
pbox.vexpand = true;
main_stack.add_titled (pbox, "extensions", _("Extensions"));
}
}
private Gtk.Widget get_editor_box () {
var content = new Gtk.Grid ();
content.row_spacing = 6;
content.column_spacing = 12;
var editor_header = new Granite.HeaderLabel (_("Editor"));
var highlight_matching_brackets_label = new SettingsLabel (_("Highlight matching brackets:"));
highlight_matching_brackets = new SettingsSwitch ("highlight-matching-brackets");
var line_wrap_label = new SettingsLabel (_("Line wrap:"));
var line_wrap = new SettingsSwitch ("line-wrap");
var draw_spaces_label = new SettingsLabel (_("Visible whitespace:"));
var draw_spaces_switch = new DrawSpacesSwitch () {
halign = Gtk.Align.START,
valign = Gtk.Align.CENTER
};
var show_mini_map_label = new SettingsLabel (_("Show Mini Map:"));
show_mini_map = new SettingsSwitch ("show-mini-map");
var font_header = new Granite.HeaderLabel (_("Font"));
var use_custom_font_label = new SettingsLabel (_("Custom font:"));
use_custom_font = new Gtk.Switch ();
use_custom_font.halign = Gtk.Align.START;
use_custom_font.valign = Gtk.Align.CENTER;
Scratch.settings.bind ("use-system-font", use_custom_font, "active", SettingsBindFlags.INVERT_BOOLEAN);
select_font = new Gtk.FontButton ();
select_font.hexpand = true;
Scratch.settings.bind ("font", select_font, "font-name", SettingsBindFlags.DEFAULT);
Scratch.settings.bind ("use-system-font", select_font, "sensitive", SettingsBindFlags.INVERT_BOOLEAN);
content.attach (editor_header, 0, 0, 3, 1);
content.attach (highlight_matching_brackets_label, 0, 2, 1, 1);
content.attach (highlight_matching_brackets, 1, 2, 1, 1);
content.attach (line_wrap_label, 0, 3, 1, 1);
content.attach (line_wrap, 1, 3, 1, 1);
content.attach (draw_spaces_label, 0, 4, 1, 1);
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 (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);
content.attach (select_font, 2, 9, 1, 1);
return content;
}
private class SettingsLabel : Gtk.Label {
public SettingsLabel (string text) {
label = text;
halign = Gtk.Align.END;
margin_start = 12;
}
}
private class SettingsSwitch : Gtk.Switch {
public SettingsSwitch (string setting) {
halign = Gtk.Align.START;
valign = Gtk.Align.CENTER;
Scratch.settings.bind (setting, this, "active", SettingsBindFlags.DEFAULT);
}
}
private class DrawSpacesSwitch : Gtk.Switch {
public string string_value {
get {
return active ? "Always" : "For Selection";
}
set {
active = (value == "Always");
}
}
public DrawSpacesSwitch () {
halign = Gtk.Align.START;
valign = Gtk.Align.CENTER;
notify["active"].connect (() => {
string_value = active ? "Always" : "For Selection";
});
Scratch.settings.bind ("draw-spaces", this, "string_value", SettingsBindFlags.DEFAULT);
}
}
}
}