Class: ActionList

Inherits:
Object
  • Object
show all
Defined in:
lib/vimamsa/actions.rb

Instance Method Summary collapse

Constructor Details

#initializeActionList

Returns a new instance of ActionList.



41
42
43
44
# File 'lib/vimamsa/actions.rb', line 41

def initialize
  @acth = []
  @actions = {}
end

Instance Method Details

#[](id) ⇒ Object



58
59
60
# File 'lib/vimamsa/actions.rb', line 58

def [](id)
  @actions[id]
end

#call(id) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/vimamsa/actions.rb', line 62

def call(id)
  @acth << id
  a = @actions[id]
  if a
    a.method.call()
  else
    message("Unknown action: " + id.inspect)
  end
end

#filter_items(item_list, item_key, search_str) ⇒ Object



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/vimamsa/actions.rb', line 145

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_searchObject



76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/vimamsa/actions.rb', line 76

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

Returns:

  • (Boolean)


54
55
56
# File 'lib/vimamsa/actions.rb', line 54

def include?(act)
  return @actions.has_key?(act)
end

#last_actionObject



72
73
74
# File 'lib/vimamsa/actions.rb', line 72

def last_action
  return @acth[-1]
end

#register(id, obj) ⇒ Object



46
47
48
# File 'lib/vimamsa/actions.rb', line 46

def register(id, obj)
  @actions[id] = obj
end

#search_actions_select_callback(search_str, idx) ⇒ Object



130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/vimamsa/actions.rb', line 130

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



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
121
122
123
124
125
126
127
128
# File 'lib/vimamsa/actions.rb', line 91

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

#unregister(id) ⇒ Object



50
51
52
# File 'lib/vimamsa/actions.rb', line 50

def unregister(id)
  @actions.delete(id)
end