@@ -15,18 +15,18 @@ function reloadExtension() {
15
15
enable ( ) ;
16
16
}
17
17
18
- function populateMenuItems ( menu , cmds ) {
18
+ function populateMenuItems ( menu , cmds , level ) {
19
19
cmds . forEach ( ( cmd ) => {
20
20
if ( cmd . type === 'separator' ) {
21
21
menu . addMenuItem ( new PopupMenu . PopupSeparatorMenuItem ( ) ) ;
22
22
return ;
23
23
}
24
24
if ( ! cmd . title ) { return ; }
25
- if ( cmd . type === 'submenu' ) {
25
+ if ( cmd . type === 'submenu' && level === 0 ) { // Stop submenu from being added after the first level
26
26
let submenu ;
27
27
if ( ! cmd . submenu ) { return ; }
28
28
submenu = new PopupMenu . PopupSubMenuMenuItem ( cmd . title ) ;
29
- populateMenuItems ( submenu . menu , cmd . submenu ) ;
29
+ populateMenuItems ( submenu . menu , cmd . submenu , level + 1 ) ;
30
30
menu . addMenuItem ( submenu ) ;
31
31
return ;
32
32
}
@@ -51,25 +51,29 @@ const CommandMenuPopup = GObject.registerClass(
51
51
class CommandMenuPopup extends PanelMenu . Button {
52
52
_init ( ) {
53
53
super . _init ( 0 ) ;
54
+ let menuTitle = commands . title && commands . title . length > 0 ? commands . title : "" ;
54
55
let box = new St . BoxLayout ( ) ;
56
+ if ( commands . showIcon !== false || ( menuTitle === "" ) ) {
57
+ var menuIcon = commands . icon && commands . icon . length > 0 ? {
58
+ icon_name : commands . icon ,
59
+ style_class : 'system-status-icon'
60
+ } : {
61
+ gicon : Gio . icon_new_for_string ( Me . dir . get_path ( ) + '/icon.svg' ) ,
62
+ style_class : 'system-status-icon' ,
63
+ } ;
64
+ let icon = new St . Icon ( menuIcon ) ;
65
+ box . add ( icon ) ;
66
+ }
55
67
56
- var menuIcon = commands . icon && commands . icon . length > 0 ? {
57
- icon_name : commands . icon ,
58
- style_class : 'system-status-icon'
59
- } : {
60
- gicon : Gio . icon_new_for_string ( Me . dir . get_path ( ) + '/icon.svg' ) ,
61
- style_class : 'system-status-icon' ,
62
- } ;
63
- let icon = new St . Icon ( menuIcon ) ;
64
- box . add ( icon ) ;
65
68
let toplabel = new St . Label ( {
66
- text : commands . text && commands . text . length > 0 ? commands . text : "" ,
69
+ text : menuTitle ,
67
70
y_expand : true ,
68
71
y_align : Clutter . ActorAlign . CENTER
69
72
} ) ;
70
73
box . add ( toplabel ) ;
71
74
this . add_child ( box ) ;
72
- populateMenuItems ( this . menu , commands . menu ) ;
75
+ let level = 0 ;
76
+ populateMenuItems ( this . menu , commands . menu , level ) ;
73
77
74
78
let editBtn = new PopupMenu . PopupMenuItem ( 'Edit Commands' ) ;
75
79
editBtn . connect ( 'activate' , ( ) => {
0 commit comments