Update the kali menu patch
Raphaƫl Hertzog
4 years ago
0 | Description: Add support for nested menus | |
1 | Author: Emilio Pozuelo Monfort <[email protected]> | |
0 | From: Emilio Pozuelo Monfort <[email protected]> | |
1 | Date: Wed, 9 Oct 2019 11:17:55 +0200 | |
2 | Subject: Add support for nested menus | |
3 | ||
2 | 4 | Bug-Kali: https://bugs.kali.org/view.php?id=2223 |
3 | 5 | Bug: https://bugzilla.gnome.org/show_bug.cgi?id=739480 |
6 | --- | |
7 | extensions/apps-menu/extension.js | 170 +++++++++++++++++++++++++++++++------- | |
8 | 1 file changed, 139 insertions(+), 31 deletions(-) | |
4 | 9 | |
10 | diff --git a/extensions/apps-menu/extension.js b/extensions/apps-menu/extension.js | |
11 | index 70383af..1e5b884 100644 | |
5 | 12 | --- a/extensions/apps-menu/extension.js |
6 | 13 | +++ b/extensions/apps-menu/extension.js |
7 | @@ -114,29 +114,33 @@ class ApplicationMenuItem extends PopupM | |
8 | } | |
9 | }; | |
10 | ||
14 | @@ -97,30 +97,36 @@ class ApplicationMenuItem extends PopupMenu.PopupBaseMenuItem { | |
15 | }); | |
16 | ||
17 | var CategoryMenuItem = GObject.registerClass( | |
11 | 18 | -class CategoryMenuItem extends PopupMenu.PopupBaseMenuItem { |
12 | - constructor(button, category) { | |
13 | - super(); | |
19 | - _init(button, category) { | |
20 | - super._init(); | |
14 | 21 | - this._category = category; |
15 | 22 | - this._button = button; |
16 | 23 | - |
24 | 31 | + * menu item by ourselves. The _oldX/_oldY variables are not |
25 | 32 | + * initialized as they are only needed for isNavigatingSubmenu */ |
26 | 33 | |
27 | + constructor(button, category) { | |
34 | + _init(button, category) { | |
28 | 35 | let name; |
29 | 36 | - if (this._category) |
30 | 37 | - name = this._category.get_name(); |
31 | 38 | + if (category) |
32 | 39 | + name = category.get_name(); |
33 | 40 | else |
34 | name = _("Favorites"); | |
35 | ||
36 | - this.actor.add_child(new St.Label({ text: name })); | |
37 | - this.actor.connect('motion-event', this._onMotionEvent.bind(this)); | |
38 | + super(name); | |
41 | name = _('Favorites'); | |
42 | ||
43 | - this.add_child(new St.Label({ text: name })); | |
44 | + super._init(name); | |
39 | 45 | + |
40 | 46 | + this._category = category; |
41 | 47 | + this._button = button; |
48 | + | |
49 | this.connect('motion-event', this._onMotionEvent.bind(this)); | |
50 | this.connect('notify::active', this._onActiveChanged.bind(this)); | |
42 | 51 | } |
43 | 52 | |
44 | 53 | activate(event) { |
45 | this._button.selectCategory(this._category, this); | |
54 | this._button.selectCategory(this._category); | |
46 | 55 | - this._button.scrollToCatButton(this); |
47 | 56 | - super.activate(event); |
48 | 57 | + //this._button.scrollToCatButton(this); |
52 | 61 | } |
53 | 62 | |
54 | 63 | _isNavigatingSubmenu([x, y]) { |
55 | @@ -222,12 +226,55 @@ class CategoryMenuItem extends PopupMenu | |
56 | setActive(active, params) { | |
57 | if (active) { | |
58 | this._button.selectCategory(this._category, this); | |
59 | - this._button.scrollToCatButton(this); | |
60 | + //this._button.scrollToCatButton(this); | |
61 | } | |
62 | super.setActive(active, params); | |
63 | } | |
64 | }; | |
65 | ||
64 | @@ -208,11 +214,55 @@ class CategoryMenuItem extends PopupMenu.PopupBaseMenuItem { | |
65 | if (!this.active) | |
66 | return; | |
67 | ||
68 | + this._button.selectCategory(this._category); | |
69 | + //this._button.scrollToCatButton(this); | |
70 | + } | |
71 | +}); | |
72 | + | |
73 | +var ParentCategoryMenuItem = GObject.registerClass( | |
66 | 74 | +class ParentCategoryMenuItem extends PopupMenu.PopupSubMenuMenuItem { |
67 | + constructor(button, category) { | |
75 | + _init(button, category) { | |
68 | 76 | + let name; |
69 | 77 | + if (category) |
70 | 78 | + name = category.get_name(); |
71 | 79 | + else |
72 | 80 | + name = _("Favorites"); |
73 | 81 | + |
74 | + super(name, false); | |
82 | + super._init(name, false); | |
75 | 83 | + |
76 | 84 | + this._category = category; |
77 | 85 | + this._button = button; |
86 | + this.connect('notify::active', this._onActiveChanged.bind(this)); | |
78 | 87 | + } |
79 | 88 | + |
80 | 89 | + activate(event) { |
81 | + this._button.selectCategory(this._category, this); | |
82 | + this._button.scrollToCatButton(this); | |
90 | this._button.selectCategory(this._category); | |
91 | this._button.scrollToCatButton(this); | |
83 | 92 | + super.activate(event); |
84 | 93 | + } |
85 | 94 | + |
86 | + setActive(active, params) { | |
95 | + _onActiveChanged(active) { | |
87 | 96 | + if (active) { |
88 | + this._button.selectCategory(this._category, this); | |
97 | + this._button.selectCategory(this._category); | |
89 | 98 | + //this._button.scrollToCatButton(this); |
90 | 99 | + } |
91 | + super.setActive(active, params); | |
92 | + } | |
93 | +}; | |
94 | + | |
100 | } | |
101 | }); | |
102 | ||
95 | 103 | +class PopupMenuScrollView extends PopupMenu.PopupMenuSection { |
96 | 104 | + constructor() { |
97 | 105 | + super(); |
109 | 117 | class ApplicationsMenu extends PopupMenu.PopupMenu { |
110 | 118 | constructor(sourceActor, arrowAlignment, arrowSide, button) { |
111 | 119 | super(sourceActor, arrowAlignment, arrowSide); |
112 | @@ -462,7 +509,7 @@ class ApplicationsButton extends PanelMe | |
120 | @@ -412,7 +462,7 @@ class ApplicationsButton extends PanelMenu.Button { | |
113 | 121 | _onTreeChanged() { |
114 | 122 | if (this.menu.isOpen) { |
115 | 123 | this._redisplay(); |
118 | 126 | } else { |
119 | 127 | this.reloadFlag = true; |
120 | 128 | } |
121 | @@ -536,7 +583,7 @@ class ApplicationsButton extends PanelMe | |
122 | this._redisplay(); | |
123 | this.reloadFlag = false; | |
124 | } | |
125 | - this.mainBox.show(); | |
126 | + this.mainBox.actor.show(); | |
127 | } | |
128 | super._onOpenStateChanged(menu, open); | |
129 | } | |
130 | @@ -550,13 +597,14 @@ class ApplicationsButton extends PanelMe | |
129 | @@ -477,7 +527,7 @@ class ApplicationsButton extends PanelMenu.Button { | |
130 | this._redisplay(); | |
131 | this.reloadFlag = false; | |
132 | } | |
133 | - this.mainBox.show(); | |
134 | + this.mainBox.actor.show(); | |
135 | } | |
136 | super._onOpenStateChanged(menu, open); | |
137 | } | |
138 | @@ -490,13 +540,14 @@ class ApplicationsButton extends PanelMenu.Button { | |
131 | 139 | |
132 | 140 | _redisplay() { |
133 | 141 | this.applicationsBox.destroy_all_children(); |
141 | 149 | let iter = dir.iter(); |
142 | 150 | let nextType; |
143 | 151 | + let categoryId = dir.get_menu_id(); |
144 | while ((nextType = iter.next()) != GMenu.TreeItemType.INVALID) { | |
145 | if (nextType == GMenu.TreeItemType.ENTRY) { | |
152 | while ((nextType = iter.next()) !== GMenu.TreeItemType.INVALID) { | |
153 | if (nextType === GMenu.TreeItemType.ENTRY) { | |
146 | 154 | let entry = iter.get_entry(); |
147 | @@ -575,8 +623,17 @@ class ApplicationsButton extends PanelMe | |
155 | @@ -515,8 +566,17 @@ class ApplicationsButton extends PanelMenu.Button { | |
148 | 156 | this.applicationsByCategory[categoryId].push('separator'); |
149 | } else if (nextType == GMenu.TreeItemType.DIRECTORY) { | |
157 | } else if (nextType === GMenu.TreeItemType.DIRECTORY) { | |
150 | 158 | let subdir = iter.get_directory(); |
151 | 159 | - if (!subdir.get_is_nodisplay()) |
152 | 160 | - this._loadCategory(categoryId, subdir); |
164 | 172 | } |
165 | 173 | } |
166 | 174 | } |
167 | @@ -597,8 +654,8 @@ class ApplicationsButton extends PanelMe | |
175 | @@ -537,8 +597,8 @@ class ApplicationsButton extends PanelMenu.Button { | |
168 | 176 | } |
169 | 177 | |
170 | 178 | scrollToCatButton(button) { |
174 | 182 | + let catsScrollBoxAlloc = this.categoriesBox.actor.get_allocation_box(); |
175 | 183 | let currentScrollValue = catsScrollBoxAdj.get_value(); |
176 | 184 | let boxHeight = catsScrollBoxAlloc.y2 - catsScrollBoxAlloc.y1; |
177 | let buttonAlloc = button.actor.get_allocation_box(); | |
178 | @@ -612,10 +669,16 @@ class ApplicationsButton extends PanelMe | |
185 | let buttonAlloc = button.get_allocation_box(); | |
186 | @@ -552,10 +612,16 @@ class ApplicationsButton extends PanelMenu.Button { | |
179 | 187 | } |
180 | 188 | |
181 | 189 | _createLayout() { |
191 | 199 | + this.mainBox = new PopupMenu.PopupMenuSection(); |
192 | 200 | + this.mainBox.actor.vertical = false; |
193 | 201 | + this.leftBox = new PopupMenu.PopupMenuSection(); |
194 | this.applicationsScrollBox = new St.ScrollView({ x_fill: true, y_fill: false, | |
195 | y_align: St.Align.START, | |
196 | style_class: 'apps-menu vfade' }); | |
197 | @@ -627,6 +690,7 @@ class ApplicationsButton extends PanelMe | |
202 | this.applicationsScrollBox = new St.ScrollView({ | |
203 | x_fill: true, | |
204 | y_fill: false, | |
205 | @@ -570,6 +636,7 @@ class ApplicationsButton extends PanelMenu.Button { | |
198 | 206 | vscroll.connect('scroll-stop', () => { |
199 | 207 | this.menu.passEvents = false; |
200 | 208 | }); |
201 | 209 | +/* |
202 | this.categoriesScrollBox = new St.ScrollView({ x_fill: true, y_fill: false, | |
203 | y_align: St.Align.START, | |
204 | style_class: 'vfade' }); | |
205 | @@ -637,14 +701,17 @@ class ApplicationsButton extends PanelMe | |
206 | this.leftBox.add(this.categoriesScrollBox, { expand: true, | |
207 | x_fill: true, y_fill: true, | |
208 | y_align: St.Align.START }); | |
209 | - | |
210 | +*/ | |
211 | let activities = new ActivitiesMenuItem(this); | |
212 | +/* | |
213 | this.leftBox.add(activities.actor, { expand: false, | |
214 | x_fill: true, y_fill: false, | |
215 | y_align: St.Align.START }); | |
210 | this.categoriesScrollBox = new St.ScrollView({ | |
211 | x_fill: true, | |
212 | y_fill: false, | |
213 | @@ -586,9 +653,11 @@ class ApplicationsButton extends PanelMenu.Button { | |
214 | y_fill: true, | |
215 | y_align: St.Align.START, | |
216 | }); | |
216 | 217 | +*/ |
217 | 218 | |
218 | 219 | this.applicationsBox = new St.BoxLayout({ vertical: true }); |
221 | 222 | this.categoriesBox = new St.BoxLayout({ vertical: true }); |
222 | 223 | this.categoriesScrollBox.add_actor(this.categoriesBox); |
223 | 224 | |
224 | @@ -652,19 +719,39 @@ class ApplicationsButton extends PanelMe | |
225 | this.mainBox.add(this._createVertSeparator(), { expand: false, x_fill: false, y_fill: true}); | |
226 | this.mainBox.add(this.applicationsScrollBox, { expand: true, x_fill: true, y_fill: true }); | |
225 | @@ -604,12 +673,32 @@ class ApplicationsButton extends PanelMenu.Button { | |
226 | y_fill: true, | |
227 | }); | |
227 | 228 | section.actor.add_actor(this.mainBox); |
228 | 229 | +*/ |
229 | 230 | + this.categoriesBox = new PopupMenuScrollView(); |
249 | 250 | |
250 | 251 | _display() { |
251 | 252 | this._applicationsButtons.clear(); |
252 | - this.mainBox.style=('width: 35em;'); | |
253 | - this.mainBox.style = 'width: 35em;'; | |
253 | 254 | - this.mainBox.hide(); |
254 | + this.mainBox.actor.style=('width: 35em;'); | |
255 | + this.mainBox.actor.style = 'width: 35em;'; | |
255 | 256 | + this.mainBox.actor.hide(); |
256 | 257 | |
257 | //Load categories | |
258 | // Load categories | |
258 | 259 | this.applicationsByCategory = {}; |
259 | this._tree.load_sync(); | |
260 | let root = this._tree.get_root_directory(); | |
261 | let categoryMenuItem = new CategoryMenuItem(this, null); | |
262 | - this.categoriesBox.add_actor(categoryMenuItem.actor); | |
263 | + this.categoriesBox.addMenuItem(categoryMenuItem); | |
264 | let iter = root.iter(); | |
265 | let nextType; | |
266 | while ((nextType = iter.next()) != GMenu.TreeItemType.INVALID) { | |
267 | @@ -673,10 +760,12 @@ class ApplicationsButton extends PanelMe | |
268 | if (!dir.get_is_nodisplay()) { | |
269 | let categoryId = dir.get_menu_id(); | |
270 | this.applicationsByCategory[categoryId] = []; | |
271 | - this._loadCategory(categoryId, dir); | |
272 | - if (this.applicationsByCategory[categoryId].length > 0) { | |
273 | - let categoryMenuItem = new CategoryMenuItem(this, dir); | |
274 | - this.categoriesBox.add_actor(categoryMenuItem.actor); | |
275 | + let categoryMenuItem = new ParentCategoryMenuItem(this, dir); | |
276 | + this._loadCategory(dir, categoryMenuItem); | |
277 | + if (categoryMenuItem.menu.isEmpty()) | |
278 | + categoryMenuItem = new CategoryMenuItem(this, dir); | |
279 | + if (this.applicationsByCategory[categoryId].length > 0 || !categoryMenuItem.menu.isEmpty()) { | |
280 | + this.categoriesBox.addMenuItem(categoryMenuItem); | |
281 | } | |
282 | } | |
260 | @@ -629,10 +718,13 @@ class ApplicationsButton extends PanelMenu.Button { | |
261 | ||
262 | let categoryId = dir.get_menu_id(); | |
263 | this.applicationsByCategory[categoryId] = []; | |
264 | - this._loadCategory(categoryId, dir); | |
265 | - if (this.applicationsByCategory[categoryId].length > 0) { | |
266 | - categoryMenuItem = new CategoryMenuItem(this, dir); | |
267 | - this.categoriesBox.add_actor(categoryMenuItem); | |
268 | + let categoryMenuItem = new ParentCategoryMenuItem(this, dir); | |
269 | + this._loadCategory(dir, categoryMenuItem); | |
270 | + if (categoryMenuItem.menu.isEmpty()) | |
271 | + categoryMenuItem = new CategoryMenuItem(this, dir); | |
272 | + | |
273 | + if (this.applicationsByCategory[categoryId].length > 0 || !categoryMenuItem.menu.isEmpty()) { | |
274 | + this.categoriesBox.addMenuItem(categoryMenuItem); | |
283 | 275 | } |
284 | @@ -687,9 +776,10 @@ class ApplicationsButton extends PanelMe | |
276 | } | |
277 | ||
278 | @@ -641,9 +733,10 @@ class ApplicationsButton extends PanelMenu.Button { | |
285 | 279 | |
286 | 280 | let themeContext = St.ThemeContext.get_for_stage(global.stage); |
287 | 281 | let scaleFactor = themeContext.scale_factor; |
288 | 282 | - let categoriesHeight = this.categoriesBox.height / scaleFactor; |
289 | 283 | + let categoriesHeight = this.categoriesBox.actor.height / scaleFactor; |
290 | let height = Math.round(categoriesHeight) + MENU_HEIGHT_OFFSET + 'px'; | |
291 | - this.mainBox.style+=('height: ' + height); | |
292 | + this.mainBox.actor.style+=('height: ' + height); | |
284 | let height = Math.round(categoriesHeight) + MENU_HEIGHT_OFFSET; | |
285 | - this.mainBox.style += `height: ${height}px`; | |
286 | + this.mainBox.actor.style += `height: ${height}px`; | |
293 | 287 | + this.categoriesBox.box.width = 300; |
294 | 288 | } |
295 | 289 | |
296 | selectCategory(dir, categoryMenuItem) { | |
297 | @@ -704,6 +794,21 @@ class ApplicationsButton extends PanelMe | |
290 | selectCategory(dir) { | |
291 | @@ -658,6 +751,21 @@ class ApplicationsButton extends PanelMenu.Button { | |
298 | 292 | this._displayButtons(this._listApplications(dir.get_menu_id())); |
299 | 293 | else |
300 | 294 | this._displayButtons(this._listApplications(null)); |