| 1 |
|
| 2 |
ドウパーツ共通 |
| 3 |
|
| 4 |
module Plugin::GUI::Widget |
| 5 |
|
| 6 |
class << self |
| 7 |
def included(klass) |
| 8 |
klass.extend(Extended) |
| 9 |
end |
| 10 |
end |
| 11 |
|
| 12 |
module Extended |
| 13 |
する。また、引数なしで呼び出した場合は現在のロールを返す |
| 14 |
|
| 15 |
いロール |
| 16 |
|
| 17 |
が省略された場合は現在のロール |
| 18 |
def role(new = nil) |
| 19 |
if new |
| 20 |
@role = new |
| 21 |
else |
| 22 |
@role end end |
| 23 |
|
| 24 |
ら _role_ をもつクラスを探す |
| 25 |
|
| 26 |
すロール |
| 27 |
|
| 28 |
クラスがあればそのクラス、無ければnil |
| 29 |
def find_role_ancestor(find) |
| 30 |
if role == find |
| 31 |
self |
| 32 |
elsif respond_to? :parent_class and parent_class |
| 33 |
parent_class.find_role_ancestor(find) end end |
| 34 |
end |
| 35 |
|
| 36 |
で、このウィジェットを破棄する。 |
| 37 |
動的に切り離される。 |
| 38 |
|
| 39 |
|
| 40 |
def destroy |
| 41 |
if not destroyed? |
| 42 |
Plugin.call(:gui_destroy, self) |
| 43 |
self.class.cuscaded.delete(slug) |
| 44 |
@destroy = true |
| 45 |
if @unload_hook and self.plugin |
| 46 |
plugin = Plugin.instance(self.plugin) |
| 47 |
if plugin |
| 48 |
plugin.detach(:unload, @unload_hook) end end end |
| 49 |
self end |
| 50 |
|
| 51 |
ィジェットが削除されているかどうかを調べる。 |
| 52 |
の場合も真を返す。 |
| 53 |
|
| 54 |
れているなら真 |
| 55 |
def destroyed? |
| 56 |
return true if defined?(@destroy) and @destroy |
| 57 |
Plugin.filtering(:gui_destroyed, self).first end |
| 58 |
|
| 59 |
てinstance_evalする。 |
| 60 |
ドで存在しないものは、 _delegate_ のものを呼ぶ。 |
| 61 |
|
| 62 |
オブジェクト |
| 63 |
渡す引数 |
| 64 |
するブロック |
| 65 |
|
| 66 |
ックの戻り値 |
| 67 |
def instance_eval_with_delegate(delegate, *rest, &proc) |
| 68 |
before_delegatee = @delegate |
| 69 |
begin |
| 70 |
@delegate = delegate |
| 71 |
instance_exec(*rest, &proc) |
| 72 |
ensure |
| 73 |
@delegate = before_delegatee |
| 74 |
end |
| 75 |
end |
| 76 |
|
| 77 |
def inspect |
| 78 |
"#<#{self.class.to_s}(role=#{self.class.role},slug=#{slug})>" |
| 79 |
end |
| 80 |
|
| 81 |
def to_s |
| 82 |
inspect |
| 83 |
end |
| 84 |
|
| 85 |
...}}形式の連想配列で返す |
| 86 |
|
| 87 |
係の連想配列 |
| 88 |
def to_h(&block) |
| 89 |
if is_a?(Plugin::GUI::HierarchyParent) |
| 90 |
if block |
| 91 |
children.to_h { |child| block.call(child.slug, child.to_h) } |
| 92 |
else |
| 93 |
children.to_h { |child| [child.slug, child.to_h] } |
| 94 |
end |
| 95 |
end |
| 96 |
end |
| 97 |
|
| 98 |
def method_missing(*args, &block) |
| 99 |
if defined?(@delegate) and @delegate |
| 100 |
@delegate.__send__(*args, &block) |
| 101 |
else |
| 102 |
super end end |
| 103 |
|
| 104 |
end |