Debian Codegraph @

plugin/gui/timeline.rb

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2
3 require_relative 'pane'
4 require_relative 'cuscadable'
5 require_relative 'hierarchy_child'
6 require_relative 'tab'
7 require_relative 'widget'
8
9 class Plugin::GUI::Timeline
10
11 include Plugin::GUI::Cuscadable
12 include Plugin::GUI::HierarchyChild
13 include Plugin::GUI::HierarchyParent
14 include Plugin::GUI::Widget
15
16 include Enumerable
17
18 role :timeline
19
20 set_parent_event :gui_timeline_join_tab
21
22 def initialize(*args)
23 super
24 Plugin.call(:timeline_created, self)
25 end
26
27 def <<(argument)
28 messages = argument.is_a?(Enumerable) ? argument : Array[argument]
29 Plugin.call(:gui_timeline_add_messages, self, messages)
30 end
31
32 # タイムラインの中のツイートを全て削除する
33 def clear
34 Plugin.call(:gui_timeline_clear, self) end
35
36 # タイムラインの一番上にスクロール
37 def scroll_to_top
38 Plugin.call(:gui_timeline_scroll_to_top, self) end
39
40 # このタイムラインをアクティブにする。また、子のPostboxは非アクティブにする
41 # ==== Return
42 # self
43 def active!(just_this=true, by_toolkit=false)
44 set_active_child(nil, by_toolkit) if just_this
45 super end
46
47 # タイムラインに _messages_ が含まれているなら真を返す
48 # ==== Args
49 # [*messages] Message タイムラインに含まれているか確認するMessageオブジェクト。配列や引数で複数指定した場合は、それら全てが含まれているかを返す
50 # ==== Return
51 # _messages_ が含まれているなら真
52 def include?(*messages)
53 args = messages.flatten.freeze
54 detected = Plugin.filtering(:gui_timeline_select_messages, self, args)
55 detected.is_a? Array and detected[1].size == args.size end
56
57 # _messages_ のうち、Timelineに含まれているMessageを返す
58 # ==== Args
59 # [messages] Enumerable タイムラインに含まれているか確認するMessage
60 # ==== Return
61 # Enumerable _messages_ で指定された中で、selfに含まれるもの
62 def in_message(messages)
63 detected = Plugin.filtering(:gui_timeline_select_messages, self, messages)
64 if detected.is_a? Enumerable
65 detected[1]
66 else
67 [] end end
68
69 # _messages_ のうち、Timelineに含まれていないMessageを返す
70 # ==== Args
71 # [messages] Enumerable タイムラインに含まれているか確認するMessageオブジェクト
72 # ==== Return
73 # Enumerable _messages_ で指定された中で、selfに含まれていないもの
74 def not_in_message(messages)
75 detected = Plugin.filtering(:gui_timeline_reject_messages, self, messages)
76 if detected.is_a? Enumerable
77 detected[1]
78 else
79 [] end end
80
81 # 選択されているMessageを返す
82 # ==== Return
83 # 選択されているMessage
84 def selected_messages
85 messages = Plugin.filtering(:gui_timeline_selected_messages, self, [])
86 messages[1] if messages.is_a? Array end
87
88 # _in_reply_to_message_ に対するリプライを入力するPostboxを作成してタイムライン上に表示する
89 # ==== Args
90 # [in_reply_to_message] リプライ先のツイート
91 # [options] Postboxのオプション
92 def create_reply_postbox(in_reply_to_message, options = {})
93 create_postbox(options.merge(to: [in_reply_to_message],
94 header: "@#{in_reply_to_message.user.idname} "))
95 end
96
97 # _in_reply_to_message_ に対するリプライを入力するPostboxを作成してタイムライン上に表示する
98 # ==== Args
99 # [options] Postboxのオプション
100 def create_postbox(options = {})
101 i_postbox = Plugin::GUI::Postbox.instance
102 i_postbox.options = options
103 self.add_child i_postbox
104 end
105
106 # Postboxを作成してこの中に入れる
107 # ==== Args
108 # [options] 設定値
109 # ==== Return
110 # 新しく作成したPostbox
111 def postbox(options = {})
112 postbox = Plugin::GUI::Postbox.instance
113 postbox.options = options
114 self.add_child postbox
115 postbox
116 end
117
118 # このタイムライン内の _message_ の部分文字列が選択されている場合それを返す。
119 # 何も選択されていない場合はnilを返す
120 # ==== Args
121 # [message] 調べるMessageのインスタンス
122 # ==== Return
123 # 選択されたテキスト
124 def selected_text(message)
125 result = Plugin.filtering(:gui_timeline_selected_text, self, message, nil)
126 result.last if result end
127
128 # Messageを並べる順序を数値で返すブロックを設定する
129 # ==== Args
130 # [&block] 並び順
131 # ==== Return
132 # self
133 def order(&block)
134 Plugin.call(:gui_timeline_set_order, self, block)
135 end
136
137 # このタイムライン内の _message_ を繰り返し処理する
138 def each(&block)
139 if block
140 Plugin.collect(:gui_timeline_each_messages, self).each(&block)
141 else
142 Plugin.collect(:gui_timeline_each_messages, self)
143 end
144 end
145
146 def size
147 to_a.size
148 end
149
150 # timeline_maxを取得する
151 def timeline_max
152 Plugin.filtering(:gui_timeline_get_timeline_max, self, nil)[1] || UserConfig[:timeline_max]
153 end
154
155 # timeline_maxを設定する
156 def timeline_max=(n)
157 Plugin.filtering(:gui_timeline_set_timeline_max, self, n)
158 end
159 end