Class: VER::Help::DescribeKey

Inherits:
Object
  • Object
show all
Includes:
Keymap::Results
Defined in:
lib/ver/help/describe_key.rb

Instance Method Summary collapse

Constructor Details

#initialize(parent) ⇒ DescribeKey

Returns a new instance of DescribeKey.



6
7
8
9
10
# File 'lib/ver/help/describe_key.rb', line 6

def initialize(parent)
  @parent = parent
  @full = []
  setup_widgets
end

Instance Method Details

#inspectObject



72
73
74
# File 'lib/ver/help/describe_key.rb', line 72

def inspect
  "#<VER::Help::DescribeKey>"
end

#lookup(pattern) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/ver/help/describe_key.rb', line 38

def lookup(pattern)
  @full << pattern

  case found = @parent.major_mode.resolve(@full)
  when Incomplete
    info = found.to_s
  when Impossible
    @full.clear
    info = found.to_s
  else
    @full.clear
    mode, action = found
    handler = action.handler || @parent.inspect
    invocation = action.invocation

    info = <<-INFO
Mode:        #{mode.name}
Handler:     #{handler}
Invocation:  #{invocation.inspect}
    INFO

    message(info){
      open_method(action.to_method(@parent))
    }
  end
rescue => ex
  VER.error(ex)
end

#message(string, &action) ⇒ Object



67
68
69
70
# File 'lib/ver/help/describe_key.rb', line 67

def message(string, &action)
  @label.configure(text: string)
  @label.bind('<1>', &action)
end

#open_method(method) ⇒ Object



76
77
78
79
80
# File 'lib/ver/help/describe_key.rb', line 76

def open_method(method)
  file, line = method.source_location
  VER.find_or_create_buffer(file, line)
  Tk::After.idle{ @label_frame.destroy }
end

#setup_widgetsObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ver/help/describe_key.rb', line 12

def setup_widgets
  @label_frame = Tk::Tile::LabelFrame.new(@parent, text: 'Describe Key')
  desc = <<-DESC
Enter any key combination.
<Escape> closes this dialog.
Click on result opens the location of the associated action.
  DESC
  @desc = Tk::Tile::Label.new(@label_frame, text: desc).pack
  @label_frame.place(
    relx: 0.5,
    rely: 0.5,
    relwidth: 0.9,
    anchor: :center
  )
  @label = Tk::Tile::Label.new(@label_frame, text: 'So far:').pack
  @label.focus

  @parent.major_mode.bound_keys.each do |key|
    @label.bind(key){|event| lookup(key) }
  end

  @label.bind('<Escape>'){ @label_frame.destroy }
  @label.bind('<FocusOut>'){ @label_frame.destroy }
  @label.bind('<Destroy>'){ @parent.focus }
end