icyrock.com

Home

GNOME experiments - basic popup menu

2017-Jan-31 19:41
gnome-experimentsjavascript

Adding a popup menu to Gnome Shell top panel is really easy:

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
const Main = imports.ui.main
const PanelMenu = imports.ui.panelMenu
const PopupMenu = imports.ui.popupMenu
const St = imports.gi.St
 
let button
 
const init = function() {
  button = new PanelMenu.Button(St.Align.START, 'Text', false)
 
  const icon = new St.Icon({
    icon_name: 'dialog-error',
    style_class: 'system-status-icon'
  })
  button.actor.add_actor(icon)
 
  const item = new PopupMenu.PopupMenuItem('Sample item')
  button.menu.addMenuItem(item)
}
 
const enable = function() {
  const role = 'popup-menu-example'
  delete Main.panel.statusArea[role]
  Main.panel.addToStatusArea(role, button, 0, 'right')
 
  button.menu.open()
}
 
const disable = function() {
  button.emit('destroy')
}

Here's how it looks: