-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprefs.js
119 lines (101 loc) · 3.23 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
import { ExtensionPreferences } from "resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js";
import Adw from "gi://Adw";
import GLib from "gi://GLib";
import Gio from "gi://Gio";
import Gtk from "gi://Gtk";
export default class TogglerPreferences extends ExtensionPreferences {
fillPreferencesWindow(window) {
const settings = this.getSettings();
const page = new Adw.PreferencesPage();
const mainGroup = new Adw.PreferencesGroup({
title: "Main Settings",
});
page.add(mainGroup);
const workspacesGroup = new Adw.PreferencesGroup({
title: "Workspaces Mode",
description: "When the terminal window is not in the active workspace",
});
page.add(workspacesGroup);
// App ID
const rowId = new Adw.ActionRow({
title: "Terminal App ID",
subtitle: "/usr/share/applications/",
});
mainGroup.add(rowId);
const entryId = new Gtk.Entry({
placeholder_text: "org.gnome.Terminal.desktop",
text: settings.get_string("terminal-id"),
valign: Gtk.Align.CENTER,
hexpand: true,
});
settings.bind(
"terminal-id",
entryId,
"text",
Gio.SettingsBindFlags.DEFAULT,
);
rowId.add_suffix(entryId);
rowId.activatable_widget = entryId;
// Shortcut
const rowShortcut = new Adw.ActionRow({
title: "Keyboard Shortcut",
subtitle: "<special_key>regular_key",
});
mainGroup.add(rowShortcut);
const entryShortcut = new Gtk.Entry({
placeholder_text: "<Control>space",
text: settings.get_string("terminal-shortcut-text"),
valign: Gtk.Align.CENTER,
hexpand: true,
});
settings.bind(
"terminal-shortcut-text",
entryShortcut,
"text",
Gio.SettingsBindFlags.DEFAULT,
);
rowShortcut.add_suffix(entryShortcut);
rowShortcut.activatable_widget = entryShortcut;
// Workspaces
const actionGroup = new Gio.SimpleActionGroup();
actionGroup.add_action(settings.create_action("workspaces-mode"));
page.insert_action_group("toggler", actionGroup);
const workspaceModes = [
{
mode: 0,
title: "Move the terminal window to the current workspace",
},
{
mode: 1,
title: "Switch to the workspace with the terminal window",
},
{
mode: 2,
title: "Launch a new terminal instance in the current workspace",
},
];
for (const { mode, title } of workspaceModes) {
const check = new Gtk.CheckButton({
action_name: "toggler.workspaces-mode",
action_target: new GLib.Variant("i", mode),
});
const row = new Adw.ActionRow({
activatable_widget: check,
title,
});
row.add_prefix(check);
workspacesGroup.add(row);
}
settings.connect("changed::terminal-shortcut-text", () => {
const shortcutText = settings.get_string("terminal-shortcut-text");
const [success, key, mods] = Gtk.accelerator_parse(shortcutText);
if (success && Gtk.accelerator_valid(key, mods)) {
const shortcut = Gtk.accelerator_name(key, mods);
settings.set_strv("terminal-shortcut", [shortcut]);
} else {
settings.set_strv("terminal-shortcut", []);
}
});
window.add(page);
}
}