Debian Codegraph @

plugin/gtk3/toolbar_generator.rb

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2
3 module Plugin::Gtk3
4 module ToolbarGenerator
5 # ツールバーに表示するボタンを _container_ にpackする。
6 # 返された時点では空で、後からボタンが入る(showメソッドは自動的に呼ばれる)。
7 # ==== Args
8 # [container] Gtk::Container, packするコンテナ
9 # ==== Return
10 # container
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 # container.ssc(:realize, &:queue_resize)
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