Class: VER::Executor::ExFuzzyFileFinder
- Inherits:
-
Entry
show all
- Defined in:
- lib/ver/executor/fuzzy_file_finder.rb
Constant Summary
collapse
- FFF =
::FuzzyFileFinder
Constants inherited
from VER::Entry
VER::Entry::BACKWARD_WORD, VER::Entry::FORWARD_WORD
Instance Attribute Summary
Attributes inherited from Entry
#callback, #caller, #parent, #tabcount, #tree, #update_on_change, #ybar
Attributes included from Keymapped
#major_mode
Instance Method Summary
collapse
Methods inherited from Entry
#accept_line, #cancel, #completion, #destroy, #initialize, #next_line, #on_delete, #on_insert, #prev_line, #speed_selection, #subset, #sync_value_with_tree_selection, #tree_selection_value, #update_only
Methods included from Keymapped
#minor_mode, #minor_mode?
Methods inherited from VER::Entry
#accept_line, #beginning_of_history, #cursor=, #delete, #delete_next_char, #delete_next_word, #delete_prev_char, #delete_prev_word, #deleting, #end_of_history, #end_of_line, #error, #event, #events, #insert, #insert_selection, #insert_string, #insert_tab, #kill, #kill_end_of_line, #killing, #message, #next_char, #next_history, #next_word, #paste, #prev_char, #prev_word, #previous_history, #sel_end_of_line, #sel_next_char, #sel_next_word, #sel_prev_char, #sel_prev_word, #sel_start_of_line, #start_of_line, #style, #transpose_chars, #value=, #virtual_movement
Instance Method Details
#action(path) ⇒ Object
93
94
95
96
97
|
# File 'lib/ver/executor/fuzzy_file_finder.rb', line 93
def action(path)
throw(:invalid) unless File.file?(path)
VER.find_or_create_buffer(path)
callback.destroy(false)
end
|
#after_update ⇒ Object
40
41
42
43
44
45
|
# File 'lib/ver/executor/fuzzy_file_finder.rb', line 40
def after_update
total = tree.winfo_width - 50
tree.column('highlighted_path', width: total, stretch: true)
tree.column('score', width: 50, stretch: false)
end
|
#choices(value) ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/ver/executor/fuzzy_file_finder.rb', line 76
def choices(value)
choices = @fffinder.find(value).
sort_by{|match| [-match[:score], match[:path]] }
choices.map{|match|
[
match[:path],
match[:abbr],
match[:directory],
match[:name],
match[:highlighted_directory],
match[:highlighted_name],
match[:highlighted_path],
match[:score].round(2),
]
}
end
|
#completed=(values) ⇒ Object
8
9
10
11
|
# File 'lib/ver/executor/fuzzy_file_finder.rb', line 8
def completed=(values)
path = Pathname(values.first)
self.value = path.relative_path_from(@pwd).to_s
end
|
#setup ⇒ Object
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
|
# File 'lib/ver/executor/fuzzy_file_finder.rb', line 13
def setup
tree.configure(
show: [:headings],
columns: %w[
path abbr directory name highlighted_directory highlighted_name
highlighted_path score
],
displaycolumns: %w[
highlighted_path score
],
)
tree.heading('path', text: 'Path')
tree.heading('abbr', text: 'Abbr')
tree.heading('directory', text: 'Directory')
tree.heading('name', text: 'Name')
tree.heading('highlighted_directory', text: 'Fuzzy Directory')
tree.heading('highlighted_name', text: 'Fuzzy Name')
tree.heading('highlighted_path', text: 'Fuzzy Path')
tree.heading('score', text: 'Score')
tree.column('path', stretch: true)
tree.column('score', width: 50, stretch: false)
setup_fff
end
|
#setup_fff ⇒ Object
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/ver/executor/fuzzy_file_finder.rb', line 47
def setup_fff
@pwd = Pathname(Dir.pwd)
setup_fff_with(caller.project_root)
rescue FFF::TooManyEntries
setup_fff_with(@pwd)
rescue FFF::TooManyEntries
caller.message "The FuzzyFileFinder is overwhelmed by the amount of files"
callback.destroy
Tk.callback_break
end
|
#setup_fff_with(root) ⇒ Object
58
59
60
|
# File 'lib/ver/executor/fuzzy_file_finder.rb', line 58
def setup_fff_with(root)
@fffinder = FFF.new(root.to_s)
end
|
#update_items(values) ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/ver/executor/fuzzy_file_finder.rb', line 62
def update_items(values)
values.map do |value|
score = value.last
tag =
if score < 0.25; :icy
elsif score < 0.5; :cold
elsif score < 0.75; :warm
else; :hot
end
tree.insert(nil, :end, values: [*value], tags: [tag])
end
end
|