Class: Nobbie::Wx::Command::ComponentAwareCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/nobbie/wx/command.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ ComponentAwareCommand

Returns a new instance of ComponentAwareCommand.



6
7
8
# File 'lib/nobbie/wx/command.rb', line 6

def initialize(path)
  @path = path
end

Instance Method Details

#componentObject



10
11
12
# File 'lib/nobbie/wx/command.rb', line 10

def component
  @component ||= @path.find_component
end

#ensure_enabled(id = nil) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/nobbie/wx/command.rb', line 24

def ensure_enabled(id = nil)
  #is_enabled takes an id for menu's
  enabled = id.nil? ? component.is_enabled : component.is_enabled(id)

  Kernel.raise(ComponentDisabledException,
    "cannot: #{describe} because component is disabled") unless enabled
end

#handle_unsupported_operation_for_componentObject



14
15
16
17
# File 'lib/nobbie/wx/command.rb', line 14

def handle_unsupported_operation_for_component
  Kernel.raise(UnsupportedOperationForComponentException,
    "cannot: #{describe} because component #{component.class} does not support it")
end

#handle_value_not_foundObject



19
20
21
22
# File 'lib/nobbie/wx/command.rb', line 19

def handle_value_not_found
  Kernel.raise(ValueNotFoundException,
    "cannot: #{describe} because value #{@value} not found")
end

#highlight(component = component) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/nobbie/wx/command.rb', line 32

def highlight(component = component)
  Kernel.raise "highlight requires a block" unless block_given?

  begin
    unless [Menu, Panel].include?(component.class)
      #puts "highlight on: #{component.class} - #{component.name}"
      original_colour = component.background_colour
      component.background_colour = Colour.from_hex('#FFFF00')

      #todo: these were previously disabled
      #component.refresh
      component.update
    end
    result = yield component
    unless component.is_a?(Menu)
      component.update
    end
    return result
  ensure
    unless [Menu, Panel].include?(component.class)
      #puts "highlight off: #{component.class} - #{component.name}"
      component.background_colour = original_colour
      component.refresh
      #component.update
    end
  end
end