ModraUp Ruby API Documentation Ruby API Reference

Class: UI::Command

Inherits:
Object
  • Object
show all

Overview

A command with a menu label, tooltip, icon, and Ruby block to run when clicked. Attach it to a toolbar with UI::Toolbar#add_item.

Examples:

cmd = UI::Command.new("Beep") { UI.beep }
cmd.tooltip = "Beep"
UI::Toolbar.new("Test").add_item(cmd)

Class Method Summary # collapse

Instance Method Summary # collapse

Class Method Details

Command.new(title) { } ⇒ command

The block must be provided to be called when clicked.

Parameters:

  • title (String)

Returns:

  • (UI::Command)

Raises:

  • [ArgumentError] No block provided

Examples:

UI::Command.new("Beep") { UI.beep }

Instance Method Details

command.tooltip ⇒ String

Hover tooltip.

Returns:

  • (String)

Examples:

UI::Command.new("Beep") { }.tooltip

command.tooltip = text ⇒ text

Set the tooltip for the command.

Parameters:

  • text (String)

Returns:

  • (String)

Examples:

cmd = UI::Command.new("Beep") { }
cmd.tooltip = "Play a tone"

command.status_bar_text ⇒ String

Status bar description.

Returns:

  • (String)

Examples:

UI::Command.new("Beep") { }.status_bar_text

command.status_bar_text = text ⇒ text

Set the status bar summary.

Parameters:

  • text (String)

Returns:

  • (String)

Examples:

cmd = UI::Command.new("Beep") { }
cmd.status_bar_text = "Play the system sound"

command.small_icon ⇒ String

Path to the small icon (may be an empty string).

Returns:

  • (String)

Examples:

UI::Command.new("Beep") { }.small_icon

command.small_icon = path ⇒ path

Set the small icon file for the toolbar. Must be assigned before using UI::Toolbar#add_item; the path must exist.

Parameters:

  • path (String) Icon file. For a relative path, the host first looks in the directory containing the Ruby script that assigned the icon.

Returns:

  • (String)

Examples:

cmd = UI::Command.new("Test") { UI.beep }
cmd.small_icon = File.join(__dir__, "icons", "test.png")
cmd.large_icon = cmd.small_icon
UI::Toolbar.new("Test").add_item(cmd)

command.large_icon ⇒ String

Path to the large icon (may be an empty string).

Returns:

  • (String)

Examples:

UI::Command.new("Beep") { }.large_icon

command.large_icon = path ⇒ path

Set the large icon file for the toolbar. If no small_icon is provided, the toolbar will use this path.

Parameters:

  • path (String) Icon file. For a relative path, the host first looks in the directory containing the Ruby script that assigned the icon.

Returns:

  • (String)

Examples:

cmd.large_icon = File.join(__dir__, "icons", "test.png")

command.proc ⇒ Proc

A block to be called when the command is invoked.

Returns:

  • (Proc)

Examples:

UI::Command.new("Beep") { UI.beep }.proc.call

command.set_validation_proc { } ⇒ self

Set the validation block, which should return MF_ENABLED or similar.

Returns:

  • (UI::Command)

Yields:

  • @yieldreturn [Integer]

Raises:

  • [ArgumentError] No block provided

Examples:

cmd = UI::Command.new("Beep") { UI.beep }
cmd.set_validation_proc { MF_ENABLED }

command.get_validation_proc ⇒ Proc, nil

Current validation block.

Returns:

  • (Proc, nil)

Examples:

UI::Command.new("Beep") { }.get_validation_proc

command.extension ⇒ Object

Associated SketchupExtension (optional).

Returns:

  • (SketchupExtension, nil)

Examples:

UI::Command.new("Beep") { }.extension

command.extension = ext ⇒ ext

Record the associated extension.

Parameters:

  • ext (SketchupExtension)

Returns:

  • (SketchupExtension)

Examples:

cmd = UI::Command.new("Beep") { }
cmd.extension = SketchupExtension.new("Demo", "demo.rb")