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
|
# -*- coding: utf-8 -*-
module Plugin::Gtk3
module ToolbarGenerator
# ツールバーに表示するボタンを _container_ にpackする。
# 返された時点では空で、後からボタンが入る(showメソッドは自動的に呼ばれる)。
# ==== Args
# [container] Gtk::Container, packするコンテナ
# ==== Return
# container
def self.generate(container, event, role)
Thread.new {
Plugin.filtering(:command, {}).first.values.select do |command|
command[:visible] and command[:icon] and
command[:role] == role and command[:condition] === event
end
}.next { |commands|
commands.each do |command|
face = command[:show_face] || command[:name] || command[:slug].to_s
name = if defined? face.call then ->(_x) { face.call(event) } else face end
toolitem = ::Gtk::Button.new
toolitem.add(::Gtk::WebIcon.new(command[:icon], 16, 16))
toolitem.tooltip_text = name
toolitem.relief = :none
toolitem.ssc(:clicked) do
current_world, = Plugin.filtering(:world_current, nil)
event.world = current_world
command[:exec].call(event)
true
end
container.add(toolitem)
end
# container.ssc(:realize, &:queue_resize)
container.show_all unless commands.empty?
}.trap { |e|
error 'error on command toolbar:'
error e
}.terminate
container end
end
end
|