| 1 |
|
| 2 |
require_relative 'complete' |
| 3 |
require_relative 'model/command' |
| 4 |
Plugin.create(:quickstep) do |
| 5 |
command(:quickstep, |
| 6 |
name: _('Quick Step'), |
| 7 |
condition: lambda { |opt| true }, |
| 8 |
icon: Skin[:search], |
| 9 |
visible: true, |
| 10 |
role: :window) do |opt| |
| 11 |
if tab?(:quickstep) |
| 12 |
Plugin::GUI::Tab.instance(:quickstep).active! |
| 13 |
next |
| 14 |
end |
| 15 |
|
| 16 |
tab(:quickstep, _('QuickStep 検索')) do |
| 17 |
set_icon Skin[:search] |
| 18 |
set_deletable true |
| 19 |
temporary_tab true |
| 20 |
grid = Gtk::Grid.new |
| 21 |
grid.orientation = :vertical |
| 22 |
grid.hexpand = true |
| 23 |
put_widget grid |
| 24 |
nativewidget grid |
| 25 |
active! |
| 26 |
end |
| 27 |
end |
| 28 |
|
| 29 |
intent Plugin::Quickstep::Command, label: _('mikutterコマンド') do |intent_token| |
| 30 |
window = Plugin::GUI::Window.active |
| 31 |
command = intent_token.model |
| 32 |
world, = Plugin.filtering(:world_current, nil) |
| 33 |
event = Plugin::GUI::Event.new(event: :quickstep, |
| 34 |
widget: window, |
| 35 |
world: world, |
| 36 |
messages: []) |
| 37 |
command[:exec].call(event) if command[:condition] === event |
| 38 |
end |
| 39 |
|
| 40 |
れに対してintentを発行する候補を出す |
| 41 |
filter_quickstep_query do |query, yielder| |
| 42 |
if URI::DEFAULT_PARSER.make_regexp.match?(query) |
| 43 |
yielder << Diva::URI!(query) |
| 44 |
end |
| 45 |
[query, yielder] |
| 46 |
end |
| 47 |
|
| 48 |
filter_quickstep_query do |query, yielder| |
| 49 |
if !query.empty? |
| 50 |
commands, = Plugin.filtering(:command, Hash.new) |
| 51 |
commands.each do |command_slug, options| |
| 52 |
if options[:role] == :window and (options[:name].include?(query) or command_slug.to_s.include?(query)) |
| 53 |
yielder << Plugin::Quickstep::Command.new(options.merge(slug: command_slug)) |
| 54 |
end |
| 55 |
end |
| 56 |
end |
| 57 |
[query, yielder] |
| 58 |
end |
| 59 |
|
| 60 |
def put_widget(grid) |
| 61 |
search = Gtk::Entry.new |
| 62 |
search.hexpand = true |
| 63 |
complete = Plugin::Quickstep::Complete.new(search) |
| 64 |
complete.valign = :fill |
| 65 |
complete.vexpand = true |
| 66 |
search.ssc(:activate, &gen_search_activate_callback(complete)) |
| 67 |
search.ssc(:realize, &gen_search_realize_callback) |
| 68 |
search.ssc(:key_press_event, &gen_common_shortcutkey_callback) |
| 69 |
complete.ssc(:key_press_event, &gen_common_shortcutkey_callback) |
| 70 |
|
| 71 |
grid << search << complete |
| 72 |
|
| 73 |
complete |
| 74 |
end |
| 75 |
|
| 76 |
def gen_search_activate_callback(complete) |
| 77 |
->(_) do |
| 78 |
tab(:quickstep).destroy |
| 79 |
selected = complete.selection.selected |
| 80 |
Plugin.call(:open, selected[Plugin::Quickstep::Store::COL_MODEL]) if selected |
| 81 |
end |
| 82 |
end |
| 83 |
|
| 84 |
def gen_search_realize_callback |
| 85 |
->(this) do |
| 86 |
this.get_ancestor(Gtk::Window).set_focus(this) |
| 87 |
false |
| 88 |
end |
| 89 |
end |
| 90 |
|
| 91 |
def gen_common_shortcutkey_callback |
| 92 |
->(widget, event) do |
| 93 |
case ::Gtk::keyname([event.keyval, event.state]) |
| 94 |
when 'Escape' |
| 95 |
tab(:quickstep).destroy |
| 96 |
true |
| 97 |
end |
| 98 |
end |
| 99 |
end |
| 100 |
end |