Debian Codegraph @

plugin/shortcutkey/shortcutkey.rb

raw symbols SCIP
1 # -*- coding:utf-8 -*-
2 require_relative 'shortcutkey_listview'
3
4 Plugin.create :shortcutkey do
5
6 filter_keypress do |key, widget, executed|
7 type_strict key => String, widget => Plugin::GUI::Widget
8 keybinds = (UserConfig[:shortcutkey_keybinds] || Hash.new)
9 commands = lazy{ Plugin.filtering(:command, Hash.new).first }
10 timeline = widget.is_a?(Plugin::GUI::Timeline) ? widget : widget.active_class_of(Plugin::GUI::Timeline)
11 current_world, = Plugin.filtering(:world_current, nil)
12 keybinds.values.lazy.select{|keyconf|
13 keyconf[:key] == key
14 }.select{|keyconf|
15 role = commands.dig(keyconf[:slug], :role)
16 role && widget.class.find_role_ancestor(role)
17 }.map{|keyconf|
18 [ commands[keyconf[:slug]],
19 Plugin::GUI::Event.new(
20 event: :contextmenu,
21 widget: widget,
22 messages: timeline ? timeline.selected_messages : [],
23 world: world_by_uri(keyconf[:world]) || current_world
24 )
25 ]
26 }.select{|command, event|
27 command[:condition] === event
28 }.each do |command, event|
29 executed = true
30 command[:exec].(event)
31 end
32 [key, widget, executed]
33 end
34
35 settings _("ショートカットキー") do
36 listview = Plugin::Shortcutkey::ShortcutKeyListView.new(Plugin[:shortcutkey])
37 listview.halign = :fill
38 listview.hexpand = true
39 listview.vexpand = true
40
41 filter_entry = listview.filter_entry = Gtk::Entry.new
42 filter_entry.primary_icon_pixbuf = Skin[:search].pixbuf(width: 24, height: 24)
43 filter_entry.ssc(:changed){
44 listview.model.refilter
45 }
46
47 grid = Gtk::Grid.new
48 grid.orientation = :vertical
49 grid.row_spacing = 6
50 grid << filter_entry << Gtk::Grid.new.tap do |grid|
51 grid.vexpand = true
52 grid.column_spacing = 6
53 grid << ::Gtk::ScrolledWindow.new.add(listview).set_valign(:fill) << listview.buttons(:vertical).set_valign(:start)
54 end
55
56 native grid
57 end
58
59 def world_by_uri(uri)
60 Plugin.collect(:worlds).find{|w| w.uri.to_s == uri }
61 end
62
63 end