File: tablike.rb

package info (click to toggle)
mikutter 5.0.4%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 9,700 kB
  • sloc: ruby: 21,307; sh: 181; makefile: 19
file content (99 lines) | stat: -rw-r--r-- 2,326 bytes parent folder | download | duplicates (3)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# -*- coding: utf-8 -*-

module Plugin::GUI::TabLike

  attr_reader :icon
  attr_accessor :deletable

  def initialize(*args)
    @expand = true
    super
  end

  # できるだけ小さく表示する
  # ==== Return
  # self
  def shrink
    @expand = false
    self end

  # できるだけ大きく表示する
  # ==== Return
  # self
  def expand(new = true)
    @expand = new
    self end

  def expand?
    @expand end

  def pack_rule
    @pack_rule ||= [] end

  def add_child(child, *args)
    result = super(child, *args)
    pack_rule[children.index(child)] = expand?
    result end
  alias << add_child

  # タイムラインを作成してこの中に入れる
  # ==== Args
  # [slug] タイムラインスラッグ
  # [&proc] 処理
  # ==== Return
  # 新しく作成したタイムライン
  def timeline(slug, &proc)
    timeline = Plugin::GUI::Timeline.instance(slug)
    self << timeline
    timeline.instance_eval(&proc) if proc
    timeline end

  # プロフィールを作成してこの中に入れる
  # ==== Args
  # [slug] プロフィールスラッグ
  # [&proc] 処理
  # ==== Return
  # 新しく作成したプロフィール
  def cluster(slug, &proc)
    cluster = Plugin::GUI::Cluster.instance(slug)
    self << cluster
    pack_rule.push(expand?)
    cluster.instance_eval(&proc) if proc
    cluster end

  # UIツールキットのウィジェット(Gtk等)をタブに入れる
  # ==== Args
  # [widget] ウィジェット
  # ==== Return
  # self
  def nativewidget(widget)
    i_container = Plugin::GUI::TabChildWidget.instance
    self << i_container
    Plugin.call("gui_nativewidget_join_#{self.class.role}".to_sym, self, i_container, widget)
    pack_rule.push(expand?)
    self end

  def set_icon(icon)
    icon_model = case icon
    when Diva::Model
      icon
    when String, URI, Addressable::URI, Diva::URI
      Plugin.collect(:photo_filter, icon, Pluggaloid::COLLECT).first || Skin[:notfound]
    else
      raise RuntimeError, "Unexpected class `#{icon.class}'."
    end
    if @icon != icon_model
      @icon = icon_model
      Plugin.call(:gui_tab_change_icon, self) end
    self end

  def set_deletable(new)
    @deletable = new
    self end

  def name=(new_name)
    result = super new_name
    Plugin.call(:gui_tab_change_icon, self)
    result end

end