Module: SkippyLib::Command

Defined in:
modules/command.rb

Overview

A wrapper on top of UI::Command which will automatically pick the appropriate vector file format alternative for icon resources.

Since:

  • 3.0.0

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.new(title, &block) ⇒ Object

Parameters:

  • title (String)

Since:

  • 3.0.0



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'modules/command.rb', line 22

def self.new(title, &block)
  # SketchUp allocate the object by implementing `new` - probably part of
  # older legacy implementation when that was the norm. Because of that the
  # class cannot be sub-classed directly. This module simulates the
  # interface for how UI::Command is created. `new` will create an instance
  # of UI::Command but mix itself into the instance - effectively
  # subclassing it. (yuck!)
  command = UI::Command.new(title) {
    begin
      block.call
    rescue Exception => e # rubocop:disable Lint/RescueException
      if @error_handler.nil?
        raise
      else
        @error_handler.call(e)
      end
    end
  }
  command.extend(self)
  command.instance_variable_set(:@proc, block)
  command
end

.set_error_handler(&block) ⇒ Object

Allows for an error handler to be configured for when commands raises an error. Useful for providing general feedback to the user or error loggers.

Since:

  • 3.0.0



16
17
18
# File 'modules/command.rb', line 16

def self.set_error_handler(&block)
  @error_handler = block
end

Instance Method Details

#invokeObject

Since:

  • 3.0.0



52
53
54
# File 'modules/command.rb', line 52

def invoke
  @proc.call
end

#large_icon=(path) ⇒ Object

Sets the large icon for the command. Provide the full path to the raster image and the method will look for a vector variant in the same folder with the same basename.

Parameters:

  • path (String)

Since:

  • 3.0.0



62
63
64
# File 'modules/command.rb', line 62

def large_icon=(path)
  super(Resource.icon_path(path))
end

#procProc

Returns:

  • (Proc)

Since:

  • 3.0.0



47
48
49
# File 'modules/command.rb', line 47

def proc
  @proc
end

#small_icon=(path) ⇒ Object

Parameters:

  • path (String)

See Also:

  • #large_icon

Since:

  • 3.0.0



70
71
72
# File 'modules/command.rb', line 70

def small_icon=(path)
  super(Resource.icon_path(path))
end