Class: ActionList
- Inherits:
-
Object
- Object
- ActionList
- Defined in:
- lib/vimamsa/actions.rb
Instance Method Summary collapse
- #[](id) ⇒ Object
- #call(id) ⇒ Object
- #filter_items(item_list, item_key, search_str) ⇒ Object
- #gui_search ⇒ Object
- #include?(act) ⇒ Boolean
-
#initialize ⇒ ActionList
constructor
A new instance of ActionList.
- #last_action ⇒ Object
- #register(id, obj) ⇒ Object
- #search_actions_select_callback(search_str, idx) ⇒ Object
- #search_actions_update_callback(search_str = "") ⇒ Object
Constructor Details
#initialize ⇒ ActionList
Returns a new instance of ActionList.
37 38 39 40 |
# File 'lib/vimamsa/actions.rb', line 37 def initialize @acth = [] @actions = {} end |
Instance Method Details
#[](id) ⇒ Object
50 51 52 |
# File 'lib/vimamsa/actions.rb', line 50 def [](id) @actions[id] end |
#call(id) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/vimamsa/actions.rb', line 54 def call(id) @acth << id a = @actions[id] if a a.method.call() else ("Unknown action: " + id.inspect) end end |
#filter_items(item_list, item_key, search_str) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/vimamsa/actions.rb', line 137 def filter_items(item_list, item_key, search_str) item_hash = {} # debug item_list.inspect scores = Parallel.map(item_list, in_threads: 8) do |item| if item[:str].class != String puts item.inspect exit! end [item, srn_dst(search_str, item[:str])] end scores.sort_by! { |x| -x[1] } debug scores.inspect scores = scores[0..30] return scores end |
#gui_search ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/vimamsa/actions.rb', line 68 def gui_search() l = [] opt = { :title => "Search for actions", :desc => "Fuzzy search for actions. <up> or <down> to change selcted. <enter> to select current.", :columns => [{ :title => "Shortcut", :id => 0 }, { :title => "Action", :id => 1 }] } @select_keys = ["h", "l", "f", "d", "s", "a", "g", "z"] gui_select_update_window(l, @select_keys.collect { |x| x.upcase }, self.method("search_actions_select_callback"), self.method("search_actions_update_callback"), opt) end |
#include?(act) ⇒ Boolean
46 47 48 |
# File 'lib/vimamsa/actions.rb', line 46 def include?(act) return @actions.has_key?(act) end |
#last_action ⇒ Object
64 65 66 |
# File 'lib/vimamsa/actions.rb', line 64 def last_action return @acth[-1] end |
#register(id, obj) ⇒ Object
42 43 44 |
# File 'lib/vimamsa/actions.rb', line 42 def register(id, obj) @actions[id] = obj end |
#search_actions_select_callback(search_str, idx) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/vimamsa/actions.rb', line 122 def search_actions_select_callback(search_str, idx) item = @item_list[idx][2] acc = item[0][:action] debug "Selected:" + acc.to_s gui_select_window_close(0) if acc.class == String eval(acc) elsif acc.class == Symbol debug "Symbol" call(acc) end end |
#search_actions_update_callback(search_str = "") ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/vimamsa/actions.rb', line 83 def search_actions_update_callback(search_str = "") return [] if search_str == "" item_list2 = [] for act_id in @actions.keys act = @actions[act_id] item = {} item[:key] = "" for mode_str in ["C", "V"] c_kbd = vma.kbd.act_bindings[mode_str][act_id] if c_kbd.class == String item[:key] = "[#{mode_str}] #{c_kbd} " item[:key] = "" if item[:key].size > 15 break end end # c_kbd = vma.kbd.act_bindings[mode_str][nfo[:action]] item[:action] = act_id item[:str] = act_id.to_s if @actions[act_id].method_name != "" item[:str] = @actions[act_id].method_name end item_list2 << item end item_list = item_list2 a = filter_items(item_list, 0, search_str) debug a.inspect r = a.collect { |x| [x[0][0], 0, x] } debug r.inspect @item_list = r r = a.collect { |x| [x[0][:key], x[0][:str]] } return r end |