activate_gnome/activate_gnome@isjerryxiao/prefs.js

159 lines
4.9 KiB
JavaScript
Raw Normal View History

2021-10-31 20:36:34 +08:00
const Gio = imports.gi.Gio
const Gtk = imports.gi.Gtk
const ExtensionUtils = imports.misc.extensionUtils
const Me = ExtensionUtils.getCurrentExtension()
function init() {
}
function buildPrefsWidget() {
this.settings = ExtensionUtils.getSettings(Me.metadata['settings-schema'])
let prefsWidget = new Gtk.Box({
orientation: Gtk.Orientation.VERTICAL,
halign: Gtk.Align.CENTER,
spacing: 6,
margin_top: 12,
margin_bottom: 12,
margin_start: 6,
margin_end: 6,
})
// line 1
2022-06-07 18:51:08 +08:00
let label_line_1 = new Gtk.Label({
2021-10-31 20:36:34 +08:00
label: '<b>Line 1</b>',
margin_top: 6,
use_markup: true,
})
2022-06-07 18:51:08 +08:00
prefsWidget.append(label_line_1)
2021-10-31 20:36:34 +08:00
2022-06-07 18:51:08 +08:00
let entry_line_1 = new Gtk.Entry({
2021-10-31 20:36:34 +08:00
margin_top: 6,
hexpand: true,
})
2022-06-07 18:51:08 +08:00
entry_line_1.set_width_chars(30)
prefsWidget.append(entry_line_1)
2021-10-31 20:36:34 +08:00
// line 2
2022-06-07 18:51:08 +08:00
let label_line_2 = new Gtk.Label({
2021-10-31 20:36:34 +08:00
label: '<b>Line 2</b>',
margin_top: 6,
use_markup: true,
})
2022-06-07 18:51:08 +08:00
prefsWidget.append(label_line_2)
2021-10-31 20:36:34 +08:00
2022-06-07 18:51:08 +08:00
let entry_line_2 = new Gtk.Entry({
2021-10-31 20:36:34 +08:00
margin_top: 6,
hexpand: true,
})
2022-06-07 18:51:08 +08:00
entry_line_2.set_width_chars(30)
prefsWidget.append(entry_line_2)
2021-10-31 20:36:34 +08:00
2022-06-07 18:51:08 +08:00
// line 2 vertical position
let label_line_2_vertical_position = new Gtk.Label({
2021-10-31 20:36:34 +08:00
label: '<b>Vertical Position</b>',
margin_top: 12,
use_markup: true,
})
2022-06-07 18:51:08 +08:00
prefsWidget.append(label_line_2_vertical_position)
2021-10-31 20:36:34 +08:00
2022-06-07 18:51:08 +08:00
let scale_line_2_vertical_position = new Gtk.Scale({
2022-03-19 15:45:05 +08:00
adjustment: new Gtk.Adjustment({lower: 0.01, upper: 1.0, step_increment: 0.01, page_increment: 0.1}),
2021-10-31 20:36:34 +08:00
margin_top: 6,
2022-06-07 18:51:08 +08:00
draw_value: false,
2021-10-31 20:36:34 +08:00
digits: 4,
})
2022-06-07 18:51:08 +08:00
prefsWidget.append(scale_line_2_vertical_position)
2021-10-31 20:36:34 +08:00
2022-06-07 18:51:08 +08:00
// line 2 horizontal position
let label_line_2_horizontal_position = new Gtk.Label({
2021-10-31 20:36:34 +08:00
label: '<b>Horizontal Position</b>',
margin_top: 6,
use_markup: true,
})
2022-06-07 18:51:08 +08:00
prefsWidget.append(label_line_2_horizontal_position)
2021-10-31 20:36:34 +08:00
2022-06-07 18:51:08 +08:00
let scale_line_2_horizontal_position = new Gtk.Scale({
2022-03-19 15:45:05 +08:00
adjustment: new Gtk.Adjustment({lower: 0.01, upper: 1.0, step_increment: 0.01, page_increment: 0.1}),
2021-10-31 20:36:34 +08:00
margin_top: 6,
2022-06-07 18:51:08 +08:00
draw_value: false,
2021-10-31 20:36:34 +08:00
digits: 4,
})
2022-06-07 18:51:08 +08:00
prefsWidget.append(scale_line_2_horizontal_position)
// line 1 text size
let label_line_1_text_size = new Gtk.Label({
label: '<b>Line 1 Text Size</b>',
margin_top: 12,
use_markup: true,
})
prefsWidget.append(label_line_1_text_size)
let spinbutton_line_1_text_size = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({lower: 1.0, upper: 65535.0, step_increment: 1.0, page_increment: 10.0}),
margin_top: 6,
numeric: true,
digits: 1,
})
prefsWidget.append(spinbutton_line_1_text_size)
// line 2 text size
let label_line_2_text_size = new Gtk.Label({
label: '<b>Line 2 Text Size</b>',
margin_top: 6,
use_markup: true,
})
prefsWidget.append(label_line_2_text_size)
let spinbutton_line_2_text_size = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({lower: 1.0, upper: 65535.0, step_increment: 1.0, page_increment: 10.0}),
margin_top: 6,
numeric: true,
digits: 1,
})
prefsWidget.append(spinbutton_line_2_text_size)
2021-10-31 20:36:34 +08:00
2022-03-19 15:45:05 +08:00
// opacity
2022-06-07 18:51:08 +08:00
let label_opacity = new Gtk.Label({
2022-03-19 15:45:05 +08:00
label: '<b>Opacity</b>',
margin_top: 6,
use_markup: true,
})
2022-06-07 18:51:08 +08:00
prefsWidget.append(label_opacity)
2022-03-19 15:45:05 +08:00
2022-06-07 18:51:08 +08:00
let scale_opacity = new Gtk.Scale({
2022-03-19 15:45:05 +08:00
adjustment: new Gtk.Adjustment({lower: 0.1, upper: 255, step_increment: 0.1, page_increment: 1}),
margin_top: 6,
draw_value: false,
digits: 1,
})
2022-06-07 18:51:08 +08:00
prefsWidget.append(scale_opacity)
2022-03-19 15:45:05 +08:00
2022-06-07 18:51:08 +08:00
let button_reset = new Gtk.Button({
2021-10-31 20:36:34 +08:00
label: 'reset',
margin_top: 12,
2022-03-19 15:45:05 +08:00
margin_bottom: 6,
2021-10-31 20:36:34 +08:00
})
2022-06-07 18:51:08 +08:00
button_reset.connect('clicked', () => {
2021-10-31 20:36:34 +08:00
this.settings.reset('text-l1')
this.settings.reset('text-l2')
this.settings.reset('l2-vertical')
this.settings.reset('l2-horizontal')
2022-06-07 18:51:08 +08:00
this.settings.reset('size-l1')
this.settings.reset('size-l2')
2022-03-19 15:45:05 +08:00
this.settings.reset('opacity')
2021-10-31 20:36:34 +08:00
})
2022-06-07 18:51:08 +08:00
prefsWidget.append(button_reset)
this.settings.bind('text-l1', entry_line_1, 'text', Gio.SettingsBindFlags.DEFAULT)
this.settings.bind('text-l2', entry_line_2, 'text', Gio.SettingsBindFlags.DEFAULT)
this.settings.bind('l2-vertical', scale_line_2_vertical_position.adjustment, 'value', Gio.SettingsBindFlags.DEFAULT)
this.settings.bind('l2-horizontal', scale_line_2_horizontal_position.adjustment, 'value', Gio.SettingsBindFlags.DEFAULT)
this.settings.bind('size-l1', spinbutton_line_1_text_size.adjustment, 'value', Gio.SettingsBindFlags.DEFAULT)
this.settings.bind('size-l2', spinbutton_line_2_text_size.adjustment, 'value', Gio.SettingsBindFlags.DEFAULT)
this.settings.bind('opacity', scale_opacity.adjustment, 'value', Gio.SettingsBindFlags.DEFAULT)
2021-10-31 20:36:34 +08:00
return prefsWidget
}