File: command.rb

package info (click to toggle)
mikutter 3.8.6%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 10,544 kB
  • sloc: ruby: 20,548; sh: 99; makefile: 19
file content (43 lines) | stat: -rw-r--r-- 1,697 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
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
40
41
42
43
# -*- coding: utf-8 -*-

module Plugin::GUI
  class Command

    class << self
      def get_menu_items(widget = get_active_widget)
        type_strict widget => Plugin::GUI::Widget
        labels = []
        contextmenu = []
        timeline = widget.is_a?(Plugin::GUI::Timeline) ? widget : widget.active_class_of(Plugin::GUI::Timeline)
        event = Plugin::GUI::Event.new(:contextmenu, widget, timeline ? timeline.selected_messages : [])
        Plugin.filtering(:command, Hash.new).first.values.each{ |record|
          if(record[:visible] and widget.class.find_role_ancestor(record[:role]))
            index = where_should_insert_it(record[:slug].to_s, labels, UserConfig[:mumble_contextmenu_order] || [])
            labels.insert(index, record[:slug].to_s)
            face = record[:show_face] || record[:name] || record[:slug].to_s
            name = if defined? face.call then lambda{ |x| face.call(event) } else face end
            contextmenu.insert(index, [name,
                                       lambda{ |x| record[:condition] === event },
                                       lambda{ |x| record[:exec].call(event) },
                                       record[:icon]]) end }

        [event,contextmenu]
      end

      def menu_pop(widget = get_active_widget)
        (event, contextmenu) = get_menu_items(widget)

        Plugin.call(:gui_contextmenu, event, contextmenu)
      end

      # フォーカスされているウィジェットを返す。
      # ==== Return
      # 現在アクティブなウィジェット
      def get_active_widget
        chain = Plugin::GUI::Window.active.active_chain
        chain.last if chain
      end
    end

  end
end