API-Version: 1.9

GtkMenu

Widget that will be created when a context menu is shown, can be used to add custom items to the menu

new GtkMenu()

Source:

Extends

Methods

add(widget)

Adds a child to a GtkWidget, note that the function can only be called on widgets derived from GtkContainer

Parameters:
Name Type Description
widget GtkWidget

The widget to add to the container

Inherited From:
Source:

addItems(items[])

Add menu items to the menu

Parameters:
Name Type Description
items[] Array

Array of menu items and callbacks, if an item is null or label or callback is omitted it will be a separator

Properties
Name Type Argument Description
callback GtkMenu~onMenuActivate <optional>

Callback called when the item is clicked, must be defined if it isn't a submenu

menu GtkMenu <optional>

A gtk menu that will get a submenu of the menu, must be defined if callback is omitted

label String <optional>

Label of the item, if omitted it will be a separator, if an character is preceded by an underscore it will be used as an accelerator key, to use a literal underscore in a label use a double underscore

position Number <optional>

Position of the item or separator starting at 0, if omitted it will be appended

Source:
Example
 

Signal.connect("contextMenu", function(wv, menu) {
    var submenu = new GtkWidget("GtkMenu");

    var submenuItems = [ 
        { 
            label : "Copy url to clipboard", 
            callback : function() 
            {
                clipboard.set(Selection.clipboard, wv.uri);
            } 
        }, 
        { 
            label : "Copy url to primary", 
            callback : function() 
            {
                clipboard.set(Selection.primary, wv.uri);
            } 
        }
    ];

    var menuItems = [
        // append separator
        null, 
        // append a menu item
        { 
            label : "Copy current url", 
            menu : submenu
        }
    ];

   submenu.addItems(submenuItems);
   menu.addItems(menuItems);
});

blockSignal(id)

Blocks emission of a signal

Parameters:
Name Type Description
id Number

The signal id retrieved from GObject#connect

Inherited From:
Source:

connect(name, callback, after) → {Number}

Connect to a GObject-signal. Note that all signals are connected using the signal::- or with notify::-prefix. If connecting to a signal the signal::-prefix must be omitted. The callback function will have the same parameters as the GObject signal callback without the first parameter, however some parameters may be undefined if they cannot be converted to javascript objects. All signal handlers are executed after dwb’s default handler.

Parameters:
Name Type Argument Description
name String

The signal name.

callback GObject~connectCallback

Callback that will be called when the signal is emitted.

after Boolean <optional>

Whether to connect after the default signal handler.

Inherited From:
Source:
Returns:

The signal id of this signal

Type
Number

connectBlocked(name, callback, after) → {Number}

Connect to a gobject-signal but block the emission of the own callback during execution of the callback. Useful if the object is connected to a notify event and the the property is changed in the callback function.

Parameters:
Name Type Argument Description
name String

The signal name.

callback Function

Callback that will be called when the signal is emitted.

after Boolean <optional>

Whether to connect after the default signal handler.

Inherited From:
Source:
Returns:

The signal id of this signal

Type
Number

destroy()

Destroys a widget

Inherited From:
Source:

disconnect(id) → {Boolean}

Disconnects from a signal

Parameters:
Name Type Description
id Number

The signal id retrieved from GObject.connect

Inherited From:
Source:
Returns:

Whether a signal was found and disconnected

Type
Boolean

getChildren() → {Array[GtkWidget]}

Gets all children of a widget. Note that this function can only be called on widgets derived from GtkContainer.

Since:
  • 1.9
Inherited From:
Source:
Returns:

An array of children or an empty array if the widget has no children

Type
Array[GtkWidget]

notify(name, callback, after) → {Number}

Connects to a property change notification

Parameters:
Name Type Argument Description
name String

The property name, can also be in camelcase.

callback GObject~notifyCallback

Callback that will be called when the property changes

after Boolean <optional>

Whether to connect after the default handler.

Inherited From:
Source:
Returns:

The signal id of this signal

Type
Number

notifyBlocked(name, callback, after) → {Number}

Connects to a property change notification but with signal blocking. Must be used if the property is modified in the callback function.

Parameters:
Name Type Argument Description
name String

The property name, can also be in camelcase.

callback GObject~notifyCallback

Callback that will be called when the property changes

after Boolean <optional>

Whether to connect after the default handler.

Inherited From:
Deprecated:
  • Yes
Source:
Returns:

The signal id of this signal

Type
Number
Example
 
gui.statusLabel.notifyBlocked("label", function() {
     this.label += "foo"; 
});

packEnd(child, expand, fill, padding)

Adds a widget to a GtkBox

Parameters:
Name Type Description
child GtkWidget

The child widget

expand Boolean

Whether to expand the widget

fill Boolean

Whether to fill the remaining space

padding Number

Padding in the box

Inherited From:
Source:

packStart(child, expand, fill, padding)

Adds a widget to a GtkBox

Parameters:
Name Type Description
child GtkWidget

The child widget

expand Boolean

Whether to expand the widget

fill Boolean

Whether to fill the remaining space

padding Number

Padding in the box

Inherited From:
Source:

remove(widget)

Removes a child from a GtkWidget, note that the function can only be called on widgets derived from GtkContainer

Parameters:
Name Type Description
widget GtkWidget

The widget to remove from the container

Since:
  • 1.9
Inherited From:
Source:

reorderChild(child, position)

Moves a widget in a GtkBox or a GtkMenu to a new Position

Parameters:
Name Type Description
child GtkWidget

The child widget

position Number

Whether to expand the widget

Inherited From:
Source:

unblockSignal(id)

Unblocks a signal that was blocked with GObject#blockSignal

Parameters:
Name Type Description
id Number

The signal id retrieved from GObject#connect

Inherited From:
Source:

Type Definitions

onMenuActivate()

Called when a menu item was activated that was added to the popup menu, this will refer to the GtkMenuItem.

Source: