-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathprefs.js
163 lines (130 loc) · 4.72 KB
/
prefs.js
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
const Lang = imports.lang;
const Gtk = imports.gi.Gtk;
const Local = imports.misc.extensionUtils.getCurrentExtension();
const Convenience = Local.imports.convenience;
const Settings = Local.imports.settings;
const guuid = 'SystemMenu'
const Gettext = imports.gettext.domain(guuid);
const _ = Gettext.gettext;
// global local variables
let main_frame = null;
// area token
let area_token_box = null;
let area_token_label = null;
let area_token_input = null;
// position
let position_box = null;
let position_label = null;
let position_input = null;
// software token
let software_token_box = null;
let software_token_label = null;
let software_token_input = null;
// save settings box
let save_settings_box = null;
let save_settings_button = null;
let save_settings_spacer = null;
// settings
let settings = null;
let settings_data = null;
let area = 'left';
// dummy one
function init(){
Convenience.initTranslations(guuid);
}
function onComboChangedArea() {
let activeItem = area_token_input.get_active();
if (activeItem >= 0) {
if (activeItem==0) area = 'left';
if (activeItem==1) area = 'center';
if (activeItem==2) area = 'right';
}
}
function widget_initliaze()
{
// initilize main frame
main_frame = new Gtk.Box({ orientation: Gtk.Orientation.VERTICAL, border_width: 10 });
// area
area_token_box = new Gtk.Box({orientation: Gtk.Orientation.HORIZONTAL});
area_token_label = new Gtk.Label({label: _("Area"), xalign: 0, margin_right: 30 });
area_token_input = new Gtk.ComboBoxText();
let areas = [_("Left"), _("Center"), _("Right")];
for (let i = 0; i < areas.length; i++)
area_token_input.append_text(areas[i]);
area_token_input.set_active (0);
area_token_input.connect ('changed', Lang.bind (this, onComboChangedArea));
// position
position_box = new Gtk.Box({orientation: Gtk.Orientation.HORIZONTAL, margin_top: 15});
position_label = new Gtk.Label({label: _("Position"), xalign: 0});
position_input = Gtk.HScale.new_with_range(-1, 25, -1);
// software center
software_token_box = new Gtk.Box({orientation: Gtk.Orientation.HORIZONTAL, margin_top: 15});
software_token_label = new Gtk.Label({label: _("Software center"), xalign: 0, margin_right: 30 });
software_token_input = new Gtk.Entry({ hexpand: true, text: "" });
// save settings box
save_settings_box = new Gtk.Box({orientation: Gtk.Orientation.VERTICAL });
save_settings_spacer = new Gtk.Box({orientation: Gtk.Orientation.VERTICAL, vexpand: true, hexpand: true });
save_settings_button = new Gtk.Button({label: _("Save Settings") });
}
function widget_packaging()
{
// auth
area_token_box.pack_start(area_token_label, false, false, 15);
area_token_box.pack_start(area_token_input, true, true, 15);
// reefresh
position_box.pack_start(position_label, false, false, 15);
position_box.pack_start(position_input, true, true, 15);
// software center
software_token_box.pack_start(software_token_label, false, false, 15);
software_token_box.pack_start(software_token_input, true, true, 15);
// save settings
save_settings_box.pack_start(save_settings_spacer, true, true, 15);
save_settings_box.pack_start(save_settings_button, false, false, 15);
main_frame.add(area_token_box);
main_frame.add(position_box)
main_frame.add(software_token_box);
main_frame.add(save_settings_box);
}
function widget_connect()
{
// save settings action
save_settings_button.connect('clicked', Lang.bind(this, save_settings_button_callback));
}
// callbacks
function save_settings_button_callback()
{
// get the settings
settings = Convenience.getSettings();
settings_data = Settings.getSettings(settings);
// update the values
settings_data.area = area;
settings_data.position = position_input.get_value();
settings_data.software = software_token_input.get_text();
settings.set_string("settings-json", JSON.stringify(settings_data));
}
// setting init values
function widget_init_values()
{
// setup settings
settings = Convenience.getSettings();
settings_data = Settings.getSettings(settings);
// set the saved area token value
if (settings_data.area=='left') area_token_input.set_active(0);
if (settings_data.area=='center') area_token_input.set_active(1);
if (settings_data.area=='right') area_token_input.set_active(2);
// set the save refresh value
position_input.set_value(settings_data.position);
// set the saved software token value
software_token_input.set_text(settings_data.software);
}
function buildPrefsWidget()
{
// lifecycle
widget_initliaze();
widget_packaging();
widget_connect();
widget_init_values();
// show frame
main_frame.show_all();
return main_frame;
}