| 1 |
|
| 2 |
ウパーツ階層構造の子 |
| 3 |
|
| 4 |
module Plugin::GUI::HierarchyChild |
| 5 |
|
| 6 |
class << self |
| 7 |
def included(klass) |
| 8 |
if klass.include?(Plugin::GUI::HierarchyParent) |
| 9 |
raise "Plugin::GUI::HierarchyChild must be included before the Plugin::GUI::HierarchyParent." |
| 10 |
end |
| 11 |
klass.extend(Extended) |
| 12 |
end |
| 13 |
end |
| 14 |
|
| 15 |
attr_reader :parent |
| 16 |
|
| 17 |
に設定 |
| 18 |
|
| 19 |
親 |
| 20 |
|
| 21 |
|
| 22 |
def set_parent(parent) |
| 23 |
type_strict parent => @parent_class |
| 24 |
return self if @parent == parent |
| 25 |
@parent.remove(self) if @parent |
| 26 |
@parent = parent |
| 27 |
if self.class.set_parent_event |
| 28 |
Plugin.call(self.class.set_parent_event, self, parent) end |
| 29 |
self end |
| 30 |
|
| 31 |
def active_class_of(klass) |
| 32 |
self if is_a? klass end |
| 33 |
|
| 34 |
_a? 関係にあるものを返す |
| 35 |
|
| 36 |
すクラス |
| 37 |
|
| 38 |
ウィジェットかnil |
| 39 |
def ancestor_of(klass) |
| 40 |
return self if is_a?(klass) |
| 41 |
case @parent |
| 42 |
when Plugin::GUI::HierarchyChild |
| 43 |
@parent.ancestor_of(klass) |
| 44 |
when klass |
| 45 |
@parent |
| 46 |
end |
| 47 |
end |
| 48 |
|
| 49 |
、selfをアクティブに設定する |
| 50 |
|
| 51 |
ではなく、直接これをアクティブに指定されたなら真 |
| 52 |
入力でアクティブになった場合真 |
| 53 |
|
| 54 |
|
| 55 |
def active!(just_this=true, by_toolkit=false) |
| 56 |
@parent.set_active_child(self, by_toolkit).active!(false, by_toolkit) |
| 57 |
self end |
| 58 |
|
| 59 |
module Extended |
| 60 |
attr_reader :parent_class |
| 61 |
|
| 62 |
発生させるイベントを設定する |
| 63 |
def set_parent_event(event = nil) |
| 64 |
if event |
| 65 |
@set_parent_event = event |
| 66 |
else |
| 67 |
@set_parent_event end end |
| 68 |
|
| 69 |
親にはこのクラスのインスタンス以外認めない |
| 70 |
|
| 71 |
クラス |
| 72 |
def set_parent_class(klass) |
| 73 |
@parent_class = klass end |
| 74 |
|
| 75 |
たどっていって、一番上の親クラスを返す |
| 76 |
def ancestor |
| 77 |
if @parent_class.respond_to? :ancestor |
| 78 |
@parent_class.ancestor |
| 79 |
else |
| 80 |
@parent_class end end |
| 81 |
|
| 82 |
ィブなインスタンスを返す |
| 83 |
|
| 84 |
なインスタンス又はnil |
| 85 |
def active |
| 86 |
widget = ancestor.active |
| 87 |
widget.active_class_of(self) if widget end |
| 88 |
|
| 89 |
end |
| 90 |
|
| 91 |
end |