aboutsummaryrefslogtreecommitdiffstats
path: root/core/plugin/gui/timeline.rb
blob: 125d62f9085a38015a0abab4dec2ce755c7774a6 (plain)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# -*- coding: utf-8 -*-

require_relative 'pane'
require_relative 'cuscadable'
require_relative 'hierarchy_child'
require_relative 'tab'
require_relative 'widget'

class Plugin::GUI::Timeline

  include Plugin::GUI::Cuscadable
  include Plugin::GUI::HierarchyChild
  include Plugin::GUI::HierarchyParent
  include Plugin::GUI::Widget

  role :timeline

  set_parent_event :gui_timeline_join_tab

  def initialize(*args)
    super
    Plugin.call(:timeline_created, self)
  end

  def <<(argument)
    messages = argument.is_a?(Enumerable) ? argument : Array[argument]
    Plugin.call(:gui_timeline_add_messages, self, messages)
  end

  # タイムラインの中のツイートを全て削除する
  def clear
    Plugin.call(:gui_timeline_clear, self) end

  # タイムラインの一番上にスクロール
  def scroll_to_top
    Plugin.call(:gui_timeline_scroll_to_top, self) end

  # このタイムラインをアクティブにする。また、子のPostboxは非アクティブにする
  # ==== Return
  # self
  def active!(just_this=true, by_toolkit=false)
    set_active_child(nil, by_toolkit) if just_this
    super end

  # タイムラインに _messages_ が含まれているなら真を返す
  # ==== Args
  # [*messages] Message タイムラインに含まれているか確認するMessageオブジェクト。配列や引数で複数指定した場合は、それら全てが含まれているかを返す
  # ==== Return
  # _messages_ が含まれているなら真
  def include?(*messages)
    args = messages.flatten.freeze
    detected = Plugin.filtering(:gui_timeline_select_messages, self, args)
    detected.is_a? Array and detected[1].size == args.size end

  # _messages_ のうち、Timelineに含まれているMessageを返す
  # ==== Args
  # [messages] Enumerable タイムラインに含まれているか確認するMessage
  # ==== Return
  # Enumerable _messages_ で指定された中で、selfに含まれるもの
  def in_message(messages)
    detected = Plugin.filtering(:gui_timeline_select_messages, self, messages)
    if detected.is_a? Enumerable
      detected[1]
    else
      [] end end

  # _messages_ のうち、Timelineに含まれていないMessageを返す
  # ==== Args
  # [messages] Enumerable タイムラインに含まれているか確認するMessageオブジェクト
  # ==== Return
  # Enumerable _messages_ で指定された中で、selfに含まれていないもの
  def not_in_message(messages)
    detected = Plugin.filtering(:gui_timeline_reject_messages, self, messages)
    if detected.is_a? Enumerable
      detected[1]
    else
      [] end end

  # 選択されているMessageを返す
  # ==== Return
  # 選択されているMessage
  def selected_messages
    messages = Plugin.filtering(:gui_timeline_selected_messages, self, [])
    messages[1] if messages.is_a? Array end

  # _in_reply_to_message_ に対するリプライを入力するPostboxを作成してタイムライン上に表示する
  # ==== Args
  # [in_reply_to_message] リプライ先のツイート
  # [options] Postboxのオプション
  def create_reply_postbox(in_reply_to_message, options = {})
    create_postbox(options.merge(to: [in_reply_to_message],
                                 header: "@#{in_reply_to_message.user.idname} "))
  end

  # _in_reply_to_message_ に対するリプライを入力するPostboxを作成してタイムライン上に表示する
  # ==== Args
  # [options] Postboxのオプション
  def create_postbox(options = {})
    i_postbox = Plugin::GUI::Postbox.instance
    i_postbox.options = options
    self.add_child i_postbox
  end

  # Postboxを作成してこの中に入れる
  # ==== Args
  # [options] 設定値
  # ==== Return
  # 新しく作成したPostbox
  def postbox(options = {})
    postbox = Plugin::GUI::Postbox.instance
    postbox.options = options
    self.add_child postbox
    postbox
  end

  # このタイムライン内の _message_ の部分文字列が選択されている場合それを返す。
  # 何も選択されていない場合はnilを返す
  # ==== Args
  # [message] 調べるMessageのインスタンス
  # ==== Return
  # 選択されたテキスト
  def selected_text(message)
    result = Plugin.filtering(:gui_timeline_selected_text, self, message, nil)
    result.last if result end

  # Messageを並べる順序を数値で返すブロックを設定する
  # ==== Args
  # [&block] 並び順
  # ==== Return
  # self
  def order(&block)
    Plugin.call(:gui_timeline_set_order, self, block)
  end

end