| 1 |
|
| 2 |
ウパーツ階層構造の親 |
| 3 |
スメソッドとしてactiveを実装している必要がある |
| 4 |
|
| 5 |
module Plugin::GUI::HierarchyParent |
| 6 |
|
| 7 |
class << self |
| 8 |
def included(klass) |
| 9 |
klass.extend(Extended) |
| 10 |
end |
| 11 |
end |
| 12 |
|
| 13 |
attr_reader :active_child |
| 14 |
|
| 15 |
追加する |
| 16 |
|
| 17 |
インスタンス |
| 18 |
るインデックス |
| 19 |
|
| 20 |
|
| 21 |
def add_child(child, index=children.size) |
| 22 |
type_strict child => Plugin::GUI::HierarchyChild |
| 23 |
return self if child.parent == self |
| 24 |
children.insert(index, child) |
| 25 |
child.set_parent(self) |
| 26 |
@active_child ||= child |
| 27 |
self end |
| 28 |
alias << add_child |
| 29 |
|
| 30 |
dex_ 以降はひとつづつシフトする |
| 31 |
|
| 32 |
子 |
| 33 |
れるインデックス |
| 34 |
def reorder_child(child, new_index) |
| 35 |
type_strict child => Plugin::GUI::HierarchyChild |
| 36 |
if children.include?(child) |
| 37 |
@children.delete(child) |
| 38 |
@children.insert(new_index, child) |
| 39 |
Plugin.call(:gui_child_reordered, self, child, new_index) |
| 40 |
else |
| 41 |
error "the widget #{child.inspect} is not child of #{self.inspect}" end |
| 42 |
self end |
| 43 |
|
| 44 |
削除する |
| 45 |
|
| 46 |
除する子 |
| 47 |
|
| 48 |
|
| 49 |
def remove(child) |
| 50 |
children.delete(child) |
| 51 |
if @active_child == child |
| 52 |
@active_child = nil end |
| 53 |
self end |
| 54 |
|
| 55 |
配列を返す |
| 56 |
|
| 57 |
の配列 |
| 58 |
def children |
| 59 |
@children ||= [] end |
| 60 |
|
| 61 |
ティブに設定する |
| 62 |
|
| 63 |
ィブにする子 |
| 64 |
入力でアクティブになった場合真 |
| 65 |
|
| 66 |
|
| 67 |
def set_active_child(child, by_toolkit=false) |
| 68 |
type_strict child => tcor(Plugin::GUI::HierarchyChild, NilClass) |
| 69 |
@active_child = child |
| 70 |
Plugin.call(:gui_child_activated, self, child, by_toolkit) if child |
| 71 |
self end |
| 72 |
|
| 73 |
下の、アクティブな祖先のリストを返す。 |
| 74 |
|
| 75 |
、孫、…のリスト 又は空の配列 |
| 76 |
def active_chain |
| 77 |
if @active_child |
| 78 |
result = [@active_child] |
| 79 |
ancestors = @active_child.respond_to?(:active_chain) && @active_child.active_chain |
| 80 |
ancestors ? result + ancestors : result |
| 81 |
else |
| 82 |
[] end end |
| 83 |
|
| 84 |
最初に _klass_ とis_a関係にあるものを返す。 |
| 85 |
|
| 86 |
ラス |
| 87 |
|
| 88 |
か見つからなければnil |
| 89 |
def active_class_of(klass) |
| 90 |
active_chain.find{ |child| child.is_a? klass } end |
| 91 |
|
| 92 |
module Extended |
| 93 |
フォルトのインスタンスを返す |
| 94 |
def add_default |
| 95 |
active end |
| 96 |
end |
| 97 |
end |