| 1 |
|
| 2 |
|
| 3 |
module Plugin::Gtk3 |
| 4 |
module ToolbarGenerator |
| 5 |
タンを _container_ にpackする。 |
| 6 |
らボタンが入る(showメソッドは自動的に呼ばれる)。 |
| 7 |
|
| 8 |
コンテナ |
| 9 |
|
| 10 |
|
| 11 |
def self.generate(container, event, role) |
| 12 |
Thread.new { |
| 13 |
Plugin.filtering(:command, {}).first.values.select do |command| |
| 14 |
command[:visible] and command[:icon] and |
| 15 |
command[:role] == role and command[:condition] === event |
| 16 |
end |
| 17 |
}.next { |commands| |
| 18 |
commands.each do |command| |
| 19 |
face = command[:show_face] || command[:name] || command[:slug].to_s |
| 20 |
name = if defined? face.call then ->(_x) { face.call(event) } else face end |
| 21 |
toolitem = ::Gtk::Button.new |
| 22 |
toolitem.add(::Gtk::WebIcon.new(command[:icon], 16, 16)) |
| 23 |
toolitem.tooltip_text = name |
| 24 |
toolitem.relief = :none |
| 25 |
toolitem.ssc(:clicked) do |
| 26 |
current_world, = Plugin.filtering(:world_current, nil) |
| 27 |
event.world = current_world |
| 28 |
command[:exec].call(event) |
| 29 |
true |
| 30 |
end |
| 31 |
container.add(toolitem) |
| 32 |
end |
| 33 |
|
| 34 |
container.show_all unless commands.empty? |
| 35 |
}.trap { |e| |
| 36 |
error 'error on command toolbar:' |
| 37 |
error e |
| 38 |
}.terminate |
| 39 |
container end |
| 40 |
end |
| 41 |
end |