Class: UI::Command
Relationships | |
Inherits: | Object |
Overview
The Command class is the preferred class for adding tools to the menus and Ruby toolbars. For example, you could add a menu item and pass it a code block directly, or you could first create a Command
.
Using Commands gives you greater control over how the item works in the ::UI
, and it allows multiple spots in the ::UI
to call the same code. For example, You might want a toolbar button and a context-click menu item to both point to the same command, and to control the tooltip and its “graying” from a single spot in your code.
Class Method Summary
-
.new(menutext) { ... } ⇒ UI::Command
constructor
The new method is used to create a new command.
Instance Attribute Summary
-
#extension ⇒ SketchupExtension?
rw
The #extension method returns the command’s associated extension.
-
#extension=(extension)
rw
The #extension= method explicitly sets the command’s associated extension.
-
#large_icon ⇒ String
rw
The large_icon method returns the icon file for the command’s large icon.
-
#large_icon=(path) ⇒ String
rw
The large_icon= method is used to identify the icon file for the command’s large icon.
-
#menu_text ⇒ String
rw
The menu_text method returns the menu item name for the command.
-
#menu_text=(menuitem) ⇒ String
rw
The menu_text= method is used to set the menu item name for the command.
-
#small_icon ⇒ String
rw
The small_icon method returns the icon file for the command’s small icon.
-
#small_icon=(path) ⇒ String
rw
The small_icon= method is used to identify the icon file for the command’s small icon.
-
#status_bar_text ⇒ String
rw
The status_bar_text method returns the status bar text for the command.
-
#status_bar_text=(text) ⇒ String
rw
The status_bar_text= method is used to set the status bar text for the command.
-
#tooltip ⇒ String
rw
The tooltip method returns command item’s tooltip text.
-
#tooltip=(text) ⇒ String
rw
The #tooltip= method is used to define a command item’s tooltip header.
Instance Method Summary
-
#get_validation_proc ⇒ Proc?
The #get_validation_proc method returns the command’s validation proc.
-
#proc ⇒ Proc
The #proc method returns the command’s proc that is called when the command is invoked.
-
#set_validation_proc { ... } ⇒ UI::Command
The #set_validation_proc method allows you to change whether the command is enabled, checked, etc.
Constructor Details
.new(menutext) { ... } ⇒ Command
Prior to SketchUp 2019 it was not possible to sub-class Command
due to a bug in how SketchUp initialized the class.
The new method is used to create a new command.
Instance Attribute Details
#extension ⇒ SketchupExtension? (rw)
This is an advanced feature that extension developers normally won’t have to deal with. It’s purpose is to address scenarios when SketchUp isn’t able to automatically infer which extension the command belongs to.
The #extension
method returns the command’s associated extension.
#extension=(extension) (rw)
This is an advanced feature that extension developers normally won’t have to deal with. It’s purpose is to address scenarios when SketchUp isn’t able to automatically infer which extension the command belongs to. These scenarios are for example an extension using a library to add its commands or command manager extensions.
The #extension=
method explicitly sets the command’s associated extension.
#large_icon ⇒ String (rw)
The large_icon method returns the icon file for the command’s large icon.
#large_icon=(path) ⇒ String (rw)
The large_icon= method is used to identify the icon file for the command’s large icon. large icons should be 32x32 pixel images for best display quality.
Since SketchUp 2016 it is possible to provide vector images for the command. SVG format for Windows and PDF format for OS X. Since the vector images scale for both small and large icon sizes, you may choose to use only one vector image for both variants.
#small_icon ⇒ String (rw)
The small_icon method returns the icon file for the command’s small icon.
#small_icon=(path) ⇒ String (rw)
The small_icon= method is used to identify the icon file for the command’s small icon. Small icons should be 24x24 pixel images for best display quality.
Since SketchUp 2016 it is possible to provide vector images for the cursors. SVG format for Windows and PDF format for OS X. Since the vector images scale for both small and large icon sizes, you may choose to use only one vector image for both variants.
#status_bar_text ⇒ String (rw)
The status_bar_text method returns the status bar text for the command.
#status_bar_text=(text) ⇒ String (rw)
The status_bar_text= method is used to set the status bar text for the command. This should be a description what the command does.
#tooltip ⇒ String (rw)
The tooltip method returns command item’s tooltip text.
#tooltip=(text) ⇒ String (rw)
The tooltip text should repeat the commands’ title text. For the command description, use #status_bar_text.
The #tooltip=
method is used to define a command item’s tooltip header. Tooltips will appear when the command is attached to a tool bar and the user hovers their cursor over the icon.
Instance Method Details
#get_validation_proc ⇒ Proc
?
The #get_validation_proc
method returns the command’s validation proc.
#proc ⇒ Proc
The #proc
method returns the command’s proc that is called when the command is invoked.
#set_validation_proc { ... } ⇒ Command
Avoid disabling an command as it often isn’t obvious to the user why it is disabled. Prefer keeping the command enabled but show an error message if pressed when it cannot be used.
The #set_validation_proc
method allows you to change whether the command is enabled, checked, etc. For instance, the command toggling a dialog window may be displayed as checked while the dialog is open.