| 1 |
|
| 2 |
|
| 3 |
require 'mui/cairo_timeline' |
| 4 |
require 'mui/gtk_dark_matter_prification' |
| 5 |
require 'mui/gtk_tree_view_pretty_scroll' |
| 6 |
|
| 7 |
require 'gtk3' |
| 8 |
|
| 9 |
class Gtk::TimeLine::InnerTL < Gtk::CompatListView |
| 10 |
|
| 11 |
include Gtk::TreeViewPrettyScroll |
| 12 |
include Gtk::InnerTLDarkMatterPurification |
| 13 |
|
| 14 |
attr_writer :force_retrieve_in_reply_to |
| 15 |
attr_accessor :postbox, :imaginary |
| 16 |
type_register('GtkInnerTL') |
| 17 |
|
| 18 |
返すときに使う |
| 19 |
Record = Data.define(:uri, :message, :order, :miracle_painter) |
| 20 |
|
| 21 |
URI = 0 |
| 22 |
MESSAGE = 1 |
| 23 |
ORDER = 2 |
| 24 |
MIRACLE_PAINTER = 3 |
| 25 |
|
| 26 |
def self.current_tl |
| 27 |
ctl = @@current_tl and @@current_tl.toplevel.focus.get_ancestor(Gtk::TimeLine::InnerTL) rescue nil |
| 28 |
ctl if(ctl.is_a?(Gtk::TimeLine::InnerTL) and not ctl.destroyed?) |
| 29 |
end |
| 30 |
|
| 31 |
|
| 32 |
き継ぐ元のInnerTL |
| 33 |
def initialize(from = nil) |
| 34 |
super() |
| 35 |
@force_retrieve_in_reply_to = :auto |
| 36 |
@@current_tl ||= self |
| 37 |
@iter_dict = {} |
| 38 |
@order = ->(m) { m.modified.to_i } |
| 39 |
self.name = 'timeline' |
| 40 |
set_headers_visible(false) |
| 41 |
set_enable_search(false) |
| 42 |
last_geo = nil |
| 43 |
selection.mode = Gtk::SELECTION_MULTIPLE |
| 44 |
get_column(0).set_sizing(Gtk::TreeViewColumn::AUTOSIZE) |
| 45 |
extend(from) if from |
| 46 |
set_events end |
| 47 |
|
| 48 |
def cell_renderer_message |
| 49 |
@cell_renderer_message ||= Gtk::CellRendererMessage.new |
| 50 |
end |
| 51 |
|
| 52 |
def column_schemer |
| 53 |
[ {:renderer => lambda{ |x,y| |
| 54 |
cell_renderer_message.tree = self |
| 55 |
cell_renderer_message |
| 56 |
}, |
| 57 |
:kind => :uri, :widget => :text, :type => String, :label => ''}, |
| 58 |
{:kind => :text, :widget => :text, :type => Diva::Model}, |
| 59 |
{:kind => :text, :type => Integer}, |
| 60 |
{:kind => :text, :type => Object} |
| 61 |
].freeze |
| 62 |
end |
| 63 |
|
| 64 |
def get_order(m) |
| 65 |
@order.call(m) end |
| 66 |
|
| 67 |
を登録する。ブロックは一つの Message を受け取り、数値を返す |
| 68 |
|
| 69 |
を決めるブロック |
| 70 |
|
| 71 |
|
| 72 |
def set_order(&block) |
| 73 |
@order = block end |
| 74 |
|
| 75 |
def menu_pop(widget, event) |
| 76 |
end |
| 77 |
|
| 78 |
def handle_row_activated |
| 79 |
end |
| 80 |
|
| 81 |
def create_postbox(options, &block) |
| 82 |
options = options.dup |
| 83 |
options[:before_post_hook] = ->(this) { |
| 84 |
get_ancestor(Gtk::Window).set_focus(self) unless self.destroyed? } |
| 85 |
pb = Gtk::PostBox.new(**options).show_all |
| 86 |
postbox.pack_start(pb, expand: false) |
| 87 |
pb.on_delete(&block) if block |
| 88 |
get_ancestor(Gtk::Window).set_focus(pb.post) |
| 89 |
pb end |
| 90 |
private :create_postbox |
| 91 |
|
| 92 |
def reply(options = {}) |
| 93 |
ctl = Gtk::TimeLine::InnerTL.current_tl |
| 94 |
pb = nil |
| 95 |
if ctl |
| 96 |
pb = create_postbox(options) |
| 97 |
ctl.selection.unselect_all end |
| 98 |
pb end |
| 99 |
|
| 100 |
def postbox_delegation_generator(i_timeline) |
| 101 |
->(params) { |
| 102 |
i_timeline.create_postbox(params) } end |
| 103 |
private :postbox_delegation_generator |
| 104 |
|
| 105 |
def add_postbox(i_postbox) |
| 106 |
投稿しても消えない)PostBoxの処理 |
| 107 |
入っているときはそのままにしておく |
| 108 |
options = i_postbox.options.dup |
| 109 |
if options[:delegate_other] && !options[:delegate_other].respond_to?(:to_proc) |
| 110 |
i_timeline = i_postbox.ancestor_of(Plugin::GUI::Timeline) |
| 111 |
options[:delegate_other] = postbox_delegation_generator(i_timeline) |
| 112 |
options[:postboxstorage] = postbox end |
| 113 |
create_postbox(options) end |
| 114 |
|
| 115 |
def get_active_messages |
| 116 |
get_active_iterators.map{ |iter| iter[1] } end |
| 117 |
|
| 118 |
def get_active_iterators |
| 119 |
selected = [] |
| 120 |
if not destroyed? |
| 121 |
selection.selected_each{ |model, path, iter| |
| 122 |
selected << iter } end |
| 123 |
selected end |
| 124 |
|
| 125 |
def get_active_pathes |
| 126 |
selected = [] |
| 127 |
if not destroyed? |
| 128 |
selection.selected_each{ |model, path, iter| |
| 129 |
selected << path } end |
| 130 |
selected end |
| 131 |
|
| 132 |
ラムの値を _value_ にセットする。 |
| 133 |
value_ を返す |
| 134 |
def update!(message, column, value) |
| 135 |
iter = get_iter_by_message(message) |
| 136 |
if iter |
| 137 |
iter[column] = value |
| 138 |
高さが変わる可能性がある |
| 139 |
iter[MIRACLE_PAINTER].reset_height |
| 140 |
value end end |
| 141 |
|
| 142 |
ンの内容を全て削除する |
| 143 |
|
| 144 |
|
| 145 |
def clear |
| 146 |
deleted = @iter_dict |
| 147 |
@iter_dict = {} |
| 148 |
deleted.values.each{ |iter| iter[MIRACLE_PAINTER].destroy } |
| 149 |
model.clear end |
| 150 |
|
| 151 |
取得する。なければnilを返す。 |
| 152 |
def get_record(path) |
| 153 |
iter = model.get_iter(path) |
| 154 |
if iter |
| 155 |
Record.new(iter[0], iter[1], iter[2], iter[3]) end end |
| 156 |
|
| 157 |
返す。なければnilを返す。 |
| 158 |
def get_path_by_message(message) |
| 159 |
get_path_and_iter_by_message(message)[1] end |
| 160 |
|
| 161 |
造体を返す。なければnilを返す。 |
| 162 |
def get_record_by_message(message) |
| 163 |
get_record_by_uri(message.uri.to_s) end |
| 164 |
|
| 165 |
造体を返す。なければnilを返す。 |
| 166 |
def get_record_by_uri(uri) |
| 167 |
path = get_path_and_iter_by_uri(uri)[1] |
| 168 |
if path |
| 169 |
get_record(path) end end |
| 170 |
|
| 171 |
def force_retrieve_in_reply_to |
| 172 |
if(:auto == @force_retrieve_in_reply_to) |
| 173 |
UserConfig[:retrieve_force_mumbleparent] |
| 174 |
else |
| 175 |
@force_retrieve_in_reply_to end end |
| 176 |
|
| 177 |
れているかを返す |
| 178 |
|
| 179 |
れているかどうかを確認するMessage |
| 180 |
|
| 181 |
れていれば真 |
| 182 |
def include?(message) |
| 183 |
@iter_dict.has_key?(message.uri.to_s) end |
| 184 |
|
| 185 |
できるように登録しておく |
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
def set_iter_dict(iter) |
| 191 |
uri = iter[URI] |
| 192 |
if not @iter_dict.has_key?(uri) |
| 193 |
@iter_dict[uri] = iter |
| 194 |
iters = @iter_dict |
| 195 |
iter[MIRACLE_PAINTER].signal_connect(:destroy) { |
| 196 |
iters.delete(uri) |
| 197 |
false } end |
| 198 |
self end |
| 199 |
|
| 200 |
|
| 201 |
nd()した時に呼ばれる |
| 202 |
def extended |
| 203 |
if @destroy_child_miraclepainters and signal_handler_is_connected?(@destroy_child_miraclepainters) |
| 204 |
signal_handler_disconnect(@destroy_child_miraclepainters) end end |
| 205 |
|
| 206 |
private |
| 207 |
|
| 208 |
容をコピーする |
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
def extend(from) |
| 214 |
@force_retrieve_in_reply_to = from.instance_eval{ @force_retrieve_in_reply_to } |
| 215 |
@imaginary = from.imaginary |
| 216 |
from.extended |
| 217 |
from.model.each{ |from_model, from_path, from_iter| |
| 218 |
iter = model.append |
| 219 |
iter[URI] = from_iter[URI] |
| 220 |
iter[MESSAGE] = from_iter[MESSAGE] |
| 221 |
iter[ORDER] = from_iter[ORDER] |
| 222 |
iter[MIRACLE_PAINTER] = from_iter[MIRACLE_PAINTER].set_tree(self) |
| 223 |
set_iter_dict(iter) } |
| 224 |
self |
| 225 |
end |
| 226 |
|
| 227 |
def set_events |
| 228 |
@destroy_child_miraclepainters = signal_connect(:destroy) { |
| 229 |
model.each{ |m, p, iter| |
| 230 |
iter[MIRACLE_PAINTER].destroy } |
| 231 |
} |
| 232 |
signal_connect(:focus_in_event){ |
| 233 |
@@current_tl.selection.unselect_all if not(@@current_tl.destroyed?) and @@current_tl and @@current_tl != self |
| 234 |
@@current_tl = self |
| 235 |
false } end |
| 236 |
|
| 237 |
返す。なければnilを返す。 |
| 238 |
def get_iter_by_message(message) |
| 239 |
get_path_and_iter_by_message(message)[2] end |
| 240 |
|
| 241 |
返す。なければnilを返す。 |
| 242 |
def get_iter_by_uri(uri) |
| 243 |
get_path_and_iter_by_uri(uri)[2] end |
| 244 |
|
| 245 |
見つからなかった場合は空の配列を返す。 |
| 246 |
def get_path_and_iter_by_message(message) |
| 247 |
get_path_and_iter_by_uri(message.uri.to_s) end |
| 248 |
|
| 249 |
def get_path_and_iter_by_uri(uri) |
| 250 |
uri = uri.to_s |
| 251 |
iter = @iter_dict[uri] |
| 252 |
if iter |
| 253 |
if iter[MIRACLE_PAINTER].destroyed? |
| 254 |
warn "destroyed miracle painter in cache (##{uri})" |
| 255 |
@iter_dict.delete(uri) |
| 256 |
[] |
| 257 |
else |
| 258 |
[model, iter.path, iter] end |
| 259 |
else |
| 260 |
[] end end |
| 261 |
|
| 262 |
end |