Class: VER::Help::DescribeKey
- Inherits:
-
Object
- Object
- VER::Help::DescribeKey
- Defined in:
- lib/ver/help/describe_key.rb
Instance Method Summary collapse
- #destroy ⇒ Object
-
#initialize(parent) ⇒ DescribeKey
constructor
A new instance of DescribeKey.
- #inspect ⇒ Object
- #lookup(sequence) ⇒ Object
- #open_method(method) ⇒ Object
- #send(executable, *args) ⇒ Object
- #setup_widgets ⇒ Object
Constructor Details
#initialize(parent) ⇒ DescribeKey
Returns a new instance of DescribeKey.
4 5 6 7 8 |
# File 'lib/ver/help/describe_key.rb', line 4 def initialize(parent) @parent = parent @full = [] end |
Instance Method Details
#destroy ⇒ Object
69 70 71 72 73 |
# File 'lib/ver/help/describe_key.rb', line 69 def destroy @label.destroy @label_frame.destroy @parent.focus end |
#inspect ⇒ Object
65 66 67 |
# File 'lib/ver/help/describe_key.rb', line 65 def inspect "#<VER::Help::DescribeKey>" end |
#lookup(sequence) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/ver/help/describe_key.rb', line 41 def lookup(sequence) old_callback = @parent.keymap.callback @parent.keymap.callback = self @full << sequence @parent.keymap.enter_key(sequence) ensure @parent.keymap.callback = old_callback end |
#open_method(method) ⇒ Object
75 76 77 78 79 |
# File 'lib/ver/help/describe_key.rb', line 75 def open_method(method) file, line = method.source_location @parent.view.find_or_create(file, line) Tk::After.idle{ destroy } end |
#send(executable, *args) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/ver/help/describe_key.rb', line 51 def send(executable, *args) method = @parent.method(executable) info = <<-INFO Sequence: #{@full.inspect} Mapping: #{method} Arguments: #{args.inspect} INFO @current = method @label.configure text: info @label.bind('<1>'){ open_method(method) } @full.clear end |
#setup_widgets ⇒ Object
10 11 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 37 38 39 |
# File 'lib/ver/help/describe_key.rb', line 10 def @label_frame = Tk::Tile::LabelFrame.new(@parent, text: 'Describe Key') desc = <<-DESC Enter any key combination. Escape closes the dialog. Click on result opens the location of the associated method. DESC @desc = Tk::Tile::Label.new(@label_frame, text: desc).pack @label_frame.place relx: 0.5, rely: 0.5, anchor: :center @label = Tk::Tile::Label.new(@label_frame, text: 'So far:').pack @label.focus @parent.keymap.all_bound_sequences.each do |seq| @label.bind(seq){|event| if event.sequence == '<Key>' sequence = event.unicode sequence = VER::KEYSYMS.fetch(sequence, sequence) sequence = "<#{sequence}>" unless sequence =~ /^([a-zA-Z]|)$/ else sequence = event.sequence end lookup(sequence) if sequence && !sequence.empty? Tk.callback_break } end @label.bind('<Control-q>'){ VER.exit } @label.bind('<Escape>'){ destroy } end |