Class: VER::View::List

Inherits:
Struct
  • Object
show all
Defined in:
lib/ver/view/list.rb

Direct Known Subclasses

Buffer, Ex, FuzzyFileFinder, Grep, Methods, Syntax, Theme, Window

Defined Under Namespace

Classes: Buffer, Ex, FuzzyFileFinder, Grep, Methods, Syntax, Theme, Window

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, &block) ⇒ List

Returns a new instance of List.



12
13
14
15
16
17
18
19
# File 'lib/ver/view/list.rb', line 12

def initialize(parent, &block)
  self.parent, self.callback = parent, block

  setup_widgets
  setup_keymap
  setup_events
  on_update
end

Instance Attribute Details

#callbackObject

Returns the value of attribute callback

Returns:

  • (Object)

    the current value of callback



2
3
4
# File 'lib/ver/view/list.rb', line 2

def callback
  @callback
end

#entryObject

Returns the value of attribute entry

Returns:

  • (Object)

    the current value of entry



2
3
4
# File 'lib/ver/view/list.rb', line 2

def entry
  @entry
end

#frameObject

Returns the value of attribute frame

Returns:

  • (Object)

    the current value of frame



2
3
4
# File 'lib/ver/view/list.rb', line 2

def frame
  @frame
end

#listObject

Returns the value of attribute list

Returns:

  • (Object)

    the current value of list



2
3
4
# File 'lib/ver/view/list.rb', line 2

def list
  @list
end

#parentObject

Returns the value of attribute parent

Returns:

  • (Object)

    the current value of parent



2
3
4
# File 'lib/ver/view/list.rb', line 2

def parent
  @parent
end

#tagObject

Returns the value of attribute tag

Returns:

  • (Object)

    the current value of tag



2
3
4
# File 'lib/ver/view/list.rb', line 2

def tag
  @tag
end

Instance Method Details

#cancelObject



95
96
97
# File 'lib/ver/view/list.rb', line 95

def cancel
  destroy
end

#completionObject



135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/ver/view/list.rb', line 135

def completion
  values = list.get(0, :end)

  if values.size == 1
    entry.value = values.first
  elsif values.size > 1
    require 'abbrev'
    if found = values.abbrev[entry.value]
      entry.value = found
    end
  end
end

#destroyObject



99
100
101
102
103
104
# File 'lib/ver/view/list.rb', line 99

def destroy
  entry.destroy
  list.destroy
  frame.destroy
  parent.focus
end

#line_downObject



79
80
81
82
83
84
85
86
87
# File 'lib/ver/view/list.rb', line 79

def line_down
  index = list.curselection.first + 1
  max = list.size

  if index < max
    list.selection_clear(0, 'end')
    select_index(index)
  end
end

#line_upObject



70
71
72
73
74
75
76
77
# File 'lib/ver/view/list.rb', line 70

def line_up
  index = list.curselection.first - 1

  if index >= 0
    list.selection_clear(0, 'end')
    select_index(index)
  end
end

#message(string) ⇒ Object



148
149
150
# File 'lib/ver/view/list.rb', line 148

def message(string)
  parent.status.message(string)
end

#on_updateObject



60
61
62
63
64
# File 'lib/ver/view/list.rb', line 60

def on_update
  update
  list.selection_set(0)
  list.activate(0)
end

#pick(item) ⇒ Object



114
115
116
117
118
119
120
121
# File 'lib/ver/view/list.rb', line 114

def pick(item)
  if list.size > 0
    pick_action(item)
    destroy
  else
    message "VER is confused, what did you actually want to do?"
  end
end

#pick_action(*args) ⇒ Object



131
132
133
# File 'lib/ver/view/list.rb', line 131

def pick_action(*args)
  callback.call(*args) if callback
end

#pick_firstObject



123
124
125
# File 'lib/ver/view/list.rb', line 123

def pick_first
  pick list.get(0)
end

#pick_selectionObject



127
128
129
# File 'lib/ver/view/list.rb', line 127

def pick_selection
  pick list.get(list.curselection.first)
end

#quitObject



66
67
68
# File 'lib/ver/view/list.rb', line 66

def quit
  VER.exit
end

#select_index(index) ⇒ Object



89
90
91
92
93
# File 'lib/ver/view/list.rb', line 89

def select_index(index)
  list.selection_set(index)
  list.activate(index)
  list.see(index)
end

#setup_eventsObject

Setup this event, because Keymap gets very confused when you bind ‘Key’ and we don’t want to break the event-chain anyway



56
57
58
# File 'lib/ver/view/list.rb', line 56

def setup_events
  entry.bind('<<Inserted>>'){ on_update }
end

#setup_keymapObject



44
45
46
47
48
49
50
51
52
# File 'lib/ver/view/list.rb', line 44

def setup_keymap
  keymap_name = VER.options.keymap

  @list_keymap = Keymap.get(
    name: keymap_name, receiver: self, widget: list, mode: :list_view_list)

  @entry_keymap = Keymap.get(
    name: keymap_name, receiver: entry, widget: entry, mode: :list_view_entry)
end

#setup_widgetsObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ver/view/list.rb', line 21

def setup_widgets
  self.frame = Tk::Frame.new.pack fill: :both, expand: true

  self.list = list = Tk::Listbox.new(frame)
  list.configure(
    setgrid: true,
    width: 0,
    background: '#000',
    foreground: '#fff',
    selectforeground: '#000',
    selectbackground: '#fff',
    exportselection: false,
    font: VER.options[:font]
  )
  list.pack fill: :both, expand: true

  self.entry = entry = View::Entry.new(frame)
  entry.configure font: VER.options[:font]
  entry.pack fill: :x, expand: false
  entry.focus
  entry.list_view = self
end

#sublist(list, input = entry.value) ⇒ Object



106
107
108
109
110
111
112
# File 'lib/ver/view/list.rb', line 106

def sublist(list, input = entry.value)
  if input == input.downcase
    list.select{|item| item.to_s.downcase.include?(input) }
  else
    list.select{|item| item.to_s.include?(input) }
  end
end