Codebase list gnome-shell-extensions / c7b0e6f
Update the kali menu patch Raphaƫl Hertzog 4 years ago
1 changed file(s) with 102 addition(s) and 108 deletion(s). Raw diff Collapse all Expand all
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
24 Bug-Kali: https://bugs.kali.org/view.php?id=2223
35 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(-)
49
10 diff --git a/extensions/apps-menu/extension.js b/extensions/apps-menu/extension.js
11 index 70383af..1e5b884 100644
512 --- a/extensions/apps-menu/extension.js
613 +++ 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(
1118 -class CategoryMenuItem extends PopupMenu.PopupBaseMenuItem {
12 - constructor(button, category) {
13 - super();
19 - _init(button, category) {
20 - super._init();
1421 - this._category = category;
1522 - this._button = button;
1623 -
2431 + * menu item by ourselves. The _oldX/_oldY variables are not
2532 + * initialized as they are only needed for isNavigatingSubmenu */
2633
27 + constructor(button, category) {
34 + _init(button, category) {
2835 let name;
2936 - if (this._category)
3037 - name = this._category.get_name();
3138 + if (category)
3239 + name = category.get_name();
3340 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);
3945 +
4046 + this._category = category;
4147 + this._button = button;
48 +
49 this.connect('motion-event', this._onMotionEvent.bind(this));
50 this.connect('notify::active', this._onActiveChanged.bind(this));
4251 }
4352
4453 activate(event) {
45 this._button.selectCategory(this._category, this);
54 this._button.selectCategory(this._category);
4655 - this._button.scrollToCatButton(this);
4756 - super.activate(event);
4857 + //this._button.scrollToCatButton(this);
5261 }
5362
5463 _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(
6674 +class ParentCategoryMenuItem extends PopupMenu.PopupSubMenuMenuItem {
67 + constructor(button, category) {
75 + _init(button, category) {
6876 + let name;
6977 + if (category)
7078 + name = category.get_name();
7179 + else
7280 + name = _("Favorites");
7381 +
74 + super(name, false);
82 + super._init(name, false);
7583 +
7684 + this._category = category;
7785 + this._button = button;
86 + this.connect('notify::active', this._onActiveChanged.bind(this));
7887 + }
7988 +
8089 + 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);
8392 + super.activate(event);
8493 + }
8594 +
86 + setActive(active, params) {
95 + _onActiveChanged(active) {
8796 + if (active) {
88 + this._button.selectCategory(this._category, this);
97 + this._button.selectCategory(this._category);
8998 + //this._button.scrollToCatButton(this);
9099 + }
91 + super.setActive(active, params);
92 + }
93 +};
94 +
100 }
101 });
102
95103 +class PopupMenuScrollView extends PopupMenu.PopupMenuSection {
96104 + constructor() {
97105 + super();
109117 class ApplicationsMenu extends PopupMenu.PopupMenu {
110118 constructor(sourceActor, arrowAlignment, arrowSide, button) {
111119 super(sourceActor, arrowAlignment, arrowSide);
112 @@ -462,7 +509,7 @@ class ApplicationsButton extends PanelMe
120 @@ -412,7 +462,7 @@ class ApplicationsButton extends PanelMenu.Button {
113121 _onTreeChanged() {
114122 if (this.menu.isOpen) {
115123 this._redisplay();
118126 } else {
119127 this.reloadFlag = true;
120128 }
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 {
131139
132140 _redisplay() {
133141 this.applicationsBox.destroy_all_children();
141149 let iter = dir.iter();
142150 let nextType;
143151 + 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) {
146154 let entry = iter.get_entry();
147 @@ -575,8 +623,17 @@ class ApplicationsButton extends PanelMe
155 @@ -515,8 +566,17 @@ class ApplicationsButton extends PanelMenu.Button {
148156 this.applicationsByCategory[categoryId].push('separator');
149 } else if (nextType == GMenu.TreeItemType.DIRECTORY) {
157 } else if (nextType === GMenu.TreeItemType.DIRECTORY) {
150158 let subdir = iter.get_directory();
151159 - if (!subdir.get_is_nodisplay())
152160 - this._loadCategory(categoryId, subdir);
164172 }
165173 }
166174 }
167 @@ -597,8 +654,8 @@ class ApplicationsButton extends PanelMe
175 @@ -537,8 +597,8 @@ class ApplicationsButton extends PanelMenu.Button {
168176 }
169177
170178 scrollToCatButton(button) {
174182 + let catsScrollBoxAlloc = this.categoriesBox.actor.get_allocation_box();
175183 let currentScrollValue = catsScrollBoxAdj.get_value();
176184 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 {
179187 }
180188
181189 _createLayout() {
191199 + this.mainBox = new PopupMenu.PopupMenuSection();
192200 + this.mainBox.actor.vertical = false;
193201 + 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 {
198206 vscroll.connect('scroll-stop', () => {
199207 this.menu.passEvents = false;
200208 });
201209 +/*
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 });
216217 +*/
217218
218219 this.applicationsBox = new St.BoxLayout({ vertical: true });
221222 this.categoriesBox = new St.BoxLayout({ vertical: true });
222223 this.categoriesScrollBox.add_actor(this.categoriesBox);
223224
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 });
227228 section.actor.add_actor(this.mainBox);
228229 +*/
229230 + this.categoriesBox = new PopupMenuScrollView();
249250
250251 _display() {
251252 this._applicationsButtons.clear();
252 - this.mainBox.style=('width: 35em;');
253 - this.mainBox.style = 'width: 35em;';
253254 - this.mainBox.hide();
254 + this.mainBox.actor.style=('width: 35em;');
255 + this.mainBox.actor.style = 'width: 35em;';
255256 + this.mainBox.actor.hide();
256257
257 //Load categories
258 // Load categories
258259 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);
283275 }
284 @@ -687,9 +776,10 @@ class ApplicationsButton extends PanelMe
276 }
277
278 @@ -641,9 +733,10 @@ class ApplicationsButton extends PanelMenu.Button {
285279
286280 let themeContext = St.ThemeContext.get_for_stage(global.stage);
287281 let scaleFactor = themeContext.scale_factor;
288282 - let categoriesHeight = this.categoriesBox.height / scaleFactor;
289283 + 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`;
293287 + this.categoriesBox.box.width = 300;
294288 }
295289
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 {
298292 this._displayButtons(this._listApplications(dir.get_menu_id()));
299293 else
300294 this._displayButtons(this._listApplications(null));