-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmenuItems.js
122 lines (112 loc) · 3.73 KB
/
menuItems.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
/* Panel Indicators GNOME Shell extension
*
* Copyright (C) 2019 Leandro Vital <leavitals@gmail.com>
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
const GObject = imports.gi.GObject;
var MenuItems = GObject.registerClass({
GTypeName: "MenuItems",
},
class MenuItems extends GObject.Object {
_init (settings) {
super._init();
this.settings = settings;
}
getItems() {
let itemsString = this.settings.get_string("items");
return this.itemsToArray(itemsString);
}
itemsToArray(itemsString) {
let items = itemsString.split("|");
let itemsArray = new Array();
for (let indexItem in items) {
let itemDatas = items[indexItem].split(";");
let item = {
"label": itemDatas[0],
"enable": (itemDatas[1] == "1"),
"position": (itemDatas[2] == "1"),
"shortcut": itemDatas[3]
};
itemsArray.push(item);
}
return itemsArray;
}
changeOrder(index, posRel) {
let items = this.getItems();
if ((posRel < 0 && index > 0) || (posRel > 0 && index < (items.length - 1))) {
let temp = items[index];
items.splice(index, 1);
items.splice(parseInt(index) + posRel, 0, temp);
this.setItems(items);
return true;
}
return false;
}
changeEnable(index, value) {
let items = this.getItems();
if (index < 0 && index >= items.length) {
return false;
}
items[index]["enable"] = value;
this.setItems(items);
return true;
}
changePosition(index, value) {
let items = this.getItems();
if (index < 0 && index >= items.length) {
return false;
}
items[index]["position"] = value;
this.setItems(items);
return true;
}
setItems(items) {
let itemsString = this.itemsToString(items);
this.settings.set_string("items", itemsString);
}
itemsToString(itemsArray) {
let items = new Array()
for (let indexItem in itemsArray) {
let itemDatasArray = itemsArray[indexItem];
let itemDatasString = itemDatasArray["label"] + ";" + (itemDatasArray["enable"] ? "1" : "0") + ";" + (itemDatasArray["position"] ? "1" : "0") + ";" + itemDatasArray["shortcut"];
items.push(itemDatasString);
}
return items.join("|");
}
getEnableItems() {
let items = this.getItems();
let indexItem;
let itemsEnable = new Array();
for (indexItem in items) {
let item = items[indexItem];
if (item["enable"]) {
itemsEnable.push(item["shortcut"]);
}
}
return itemsEnable;
}
getCenterItems() {
let items = this.getItems();
let indexItem;
let itemsEnable = new Array();
for (indexItem in items) {
let item = items[indexItem];
if (item["enable"] && item["position"]) {
itemsEnable.push(item["shortcut"]);
}
}
return itemsEnable;
}
});