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
- #mode ⇒ 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
70 71 72 73 74 |
# File 'lib/ver/help/describe_key.rb', line 70 def destroy @label.destroy @label_frame.destroy @parent.focus end |
#inspect ⇒ Object
66 67 68 |
# File 'lib/ver/help/describe_key.rb', line 66 def inspect "#<VER::Help::DescribeKey>" end |
#lookup(sequence) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/ver/help/describe_key.rb', line 41 def lookup(sequence) @full << sequence @parent.keymap.enter_key(self, sequence) rescue => ex VER.error(ex) end |
#mode ⇒ Object
48 49 50 |
# File 'lib/ver/help/describe_key.rb', line 48 def mode @parent.keymap.mode 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{ destroy } end |
#send(executable, *args) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/ver/help/describe_key.rb', line 52 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 |