| 1 |
|
| 2 |
|
| 3 |
を表示するプラグイン |
| 4 |
require 'gtk3' |
| 5 |
|
| 6 |
require_relative 'patch' |
| 7 |
|
| 8 |
require 'mui/gtk_contextmenu' |
| 9 |
require 'mui/gtk_compatlistview' |
| 10 |
require 'mui/gtk_crud' |
| 11 |
require 'mui/gtk_extension' |
| 12 |
require 'mui/gtk_intelligent_textview' |
| 13 |
require 'mui/gtk_keyconfig' |
| 14 |
require 'mui/gtk_message_picker' |
| 15 |
require 'mui/gtk_mtk' |
| 16 |
require 'mui/gtk_postbox' |
| 17 |
require 'mui/gtk_pseudo_signal_handler' |
| 18 |
require 'mui/gtk_selectbox' |
| 19 |
require 'mui/gtk_timeline_utils' |
| 20 |
require 'mui/gtk_userlist' |
| 21 |
require 'mui/gtk_webicon' |
| 22 |
|
| 23 |
require_relative 'widget/dialog' |
| 24 |
require_relative 'widget/mikutterwindow' |
| 25 |
require_relative 'widget/miraclepainter' |
| 26 |
require_relative 'widget/tabcontainer' |
| 27 |
require_relative 'widget/tabtoolbar' |
| 28 |
require_relative 'widget/timeline' |
| 29 |
require_relative 'widget/worldshifter' |
| 30 |
|
| 31 |
require_relative 'konami_watcher' |
| 32 |
require_relative 'mainloop' |
| 33 |
require_relative 'slug_dictionary' |
| 34 |
require_relative 'toolbar_generator' |
| 35 |
|
| 36 |
Plugin.create :gtk3 do |
| 37 |
@slug_dictionary = Plugin::Gtk3::SlugDictionary.new |
| 38 |
@tabs_promise = {} |
| 39 |
|
| 40 |
ンドウ作成。 |
| 41 |
るので、Gtk::MikutterWindowクラスを新設してそれを使う |
| 42 |
on_window_created do |i_window| |
| 43 |
window = Plugin::Gtk3::MikutterWindow.new(i_window, self) |
| 44 |
@parent = window |
| 45 |
@slug_dictionary.add(i_window, window) |
| 46 |
window.title = i_window.name |
| 47 |
|
| 48 |
geometry = get_window_geometry(i_window.slug) |
| 49 |
if geometry |
| 50 |
window.set_default_size(*geometry[:size]) |
| 51 |
window.move(*geometry[:position]) |
| 52 |
end |
| 53 |
|
| 54 |
window.ssc(:event) do |t_window, event| |
| 55 |
if event.is_a? Gdk::EventConfigure |
| 56 |
geometry = (UserConfig[:windows_geometry] || {}).melt |
| 57 |
size = t_window.window.geometry[2, 2] |
| 58 |
position = t_window.position |
| 59 |
modified = false |
| 60 |
if geometry&.dig(i_window.slug).is_a?(Hash) |
| 61 |
geometry[i_window.slug] = geometry[i_window.slug].melt |
| 62 |
if geometry[i_window.slug][:size] != size |
| 63 |
modified = geometry[i_window.slug][:size] = size |
| 64 |
end |
| 65 |
if geometry[i_window.slug][:position] != position |
| 66 |
modified = geometry[i_window.slug][:position] = position |
| 67 |
end |
| 68 |
else |
| 69 |
modified = geometry[i_window.slug] = { |
| 70 |
size:, |
| 71 |
position: |
| 72 |
} |
| 73 |
end |
| 74 |
if modified |
| 75 |
UserConfig[:windows_geometry] = geometry |
| 76 |
end |
| 77 |
end |
| 78 |
false |
| 79 |
end |
| 80 |
window.ssc('destroy') do |
| 81 |
Delayer.freeze |
| 82 |
window.destroy |
| 83 |
Mainloop.reserve_exit |
| 84 |
false |
| 85 |
end |
| 86 |
window.ssc(:focus_in_event) do |
| 87 |
i_window.active!(true, true) |
| 88 |
false |
| 89 |
end |
| 90 |
window.ssc('key_press_event') do |_widget, event| |
| 91 |
Plugin::GUI.keypress(Gtk.keyname([event.keyval, event.state]), i_window) |
| 92 |
end |
| 93 |
window.show_all |
| 94 |
end |
| 95 |
|
| 96 |
on_gui_window_change_icon do |i_window, icon| |
| 97 |
window = widgetof(i_window) |
| 98 |
if window |
| 99 |
window.icon = icon.load_pixbuf(width: 256, height: 256) do |pb| |
| 100 |
window.icon = pb unless window.destroyed? |
| 101 |
end |
| 102 |
end |
| 103 |
end |
| 104 |
|
| 105 |
ン作成。 |
| 106 |
NoteBook |
| 107 |
on_pane_created do |i_pane| |
| 108 |
tabpos = %i[top bottom left right].freeze |
| 109 |
|
| 110 |
pane = create_pane(i_pane) |
| 111 |
pane.group_name = '0' |
| 112 |
pane.scrollable = true |
| 113 |
pane.show_border = false |
| 114 |
pane.set_tab_pos(tabpos[UserConfig[:tab_position]]) |
| 115 |
pane.hexpand = true |
| 116 |
tab_position_listener = on_userconfig_modify do |key, val| |
| 117 |
next if key != :tab_position |
| 118 |
if pane.destroyed? |
| 119 |
tab_position_listener.detach |
| 120 |
else |
| 121 |
pane.set_tab_pos(tabpos[val]) |
| 122 |
end |
| 123 |
end |
| 124 |
pane.ssc(:page_reordered) do |_this, tabcontainer, index| |
| 125 |
Plugin.call(:rewind_window_order, i_pane.parent) if i_pane.parent |
| 126 |
i_tab = tabcontainer.i_tab |
| 127 |
if i_tab |
| 128 |
i_pane.reorder_child(i_tab, index) end |
| 129 |
Plugin.call(:after_gui_tab_reordered, i_tab) |
| 130 |
false |
| 131 |
end |
| 132 |
pane.ssc :switch_page do |_, tab| |
| 133 |
i_pane.set_active_child(tab.i_tab, true) |
| 134 |
end |
| 135 |
pane.signal_connect(:page_added) do |_this, tabcontainer, index| |
| 136 |
type_strict tabcontainer => Plugin::Gtk3::TabContainer |
| 137 |
Plugin.call(:rewind_window_order, i_pane.parent) if i_pane.parent |
| 138 |
i_tab = tabcontainer.i_tab |
| 139 |
next false if i_tab.parent == i_pane |
| 140 |
Plugin.call(:after_gui_tab_reparent, i_tab, i_tab.parent, i_pane) |
| 141 |
i_pane.add_child(i_tab, index) |
| 142 |
false |
| 143 |
end |
| 144 |
た時 : このpaneを削除 |
| 145 |
pane.signal_connect(:page_removed) do |
| 146 |
if !pane.destroyed? && pane.children.empty? && pane.parent |
| 147 |
pane.parent.remove(pane) |
| 148 |
tab_position_listener.detach |
| 149 |
pane_order_delete(i_pane) |
| 150 |
i_pane.destroy end |
| 151 |
false |
| 152 |
end |
| 153 |
end |
| 154 |
|
| 155 |
ブ作成。 |
| 156 |
のところをGtk::EventBoxにしておいて、それを実体ということにしておく |
| 157 |
on_tab_created do |i_tab| |
| 158 |
tab = create_tab(i_tab) |
| 159 |
if @tabs_promise[i_tab.slug] |
| 160 |
@tabs_promise[i_tab.slug].call(tab) |
| 161 |
@tabs_promise.delete(i_tab.slug) end |
| 162 |
end |
| 163 |
|
| 164 |
on_cluster_created do |i_cluster| |
| 165 |
pane = create_pane(i_cluster) |
| 166 |
pane.scrollable = true |
| 167 |
pane.ssc(:page_reordered) do |_this, tabcontainer, index| |
| 168 |
tabcontainer.i_tab&.then do |i_tab| |
| 169 |
i_cluster.reorder_child(i_tab, index) |
| 170 |
Plugin.call(:after_gui_tab_reordered, i_tab) |
| 171 |
end |
| 172 |
false |
| 173 |
end |
| 174 |
end |
| 175 |
|
| 176 |
on_fragment_created do |i_fragment| |
| 177 |
create_tab(i_fragment) |
| 178 |
end |
| 179 |
|
| 180 |
を作成する |
| 181 |
|
| 182 |
タブ |
| 183 |
|
| 184 |
|
| 185 |
def create_tab(i_tab) |
| 186 |
tab = Gtk::EventBox.new |
| 187 |
tab.tooltip_text = i_tab.name |
| 188 |
tab.visible_window = false |
| 189 |
@slug_dictionary.add(i_tab, tab) |
| 190 |
tab_update_icon(i_tab) |
| 191 |
tab.ssc(:focus_in_event) do |
| 192 |
i_tab.active!(true, true) |
| 193 |
false |
| 194 |
end |
| 195 |
tab.ssc(:key_press_event) do |_widget, event| |
| 196 |
Plugin::GUI.keypress(Gtk.keyname([event.keyval, event.state]), i_tab) |
| 197 |
end |
| 198 |
tab.ssc(:button_press_event) do |_this, event| |
| 199 |
if event.button == 3 |
| 200 |
Plugin::GUI::Command.menu_pop(i_tab) |
| 201 |
else |
| 202 |
Plugin::GUI.keypress(Gtk.buttonname([event.event_type, event.button, event.state]), i_tab) |
| 203 |
end |
| 204 |
false |
| 205 |
end |
| 206 |
tab.ssc(:destroy) do |
| 207 |
i_tab.destroy |
| 208 |
false |
| 209 |
end |
| 210 |
tab.show_all |
| 211 |
end |
| 212 |
|
| 213 |
on_tab_toolbar_created do |i_tab_toolbar| |
| 214 |
tab_toolbar = Plugin::Gtk3::TabToolbar.new(i_tab_toolbar).show_all |
| 215 |
@slug_dictionary.add(i_tab_toolbar, tab_toolbar) |
| 216 |
end |
| 217 |
|
| 218 |
on_gui_tab_toolbar_join_tab do |i_tab_toolbar, i_tab| |
| 219 |
widget = widgetof(i_tab_toolbar) |
| 220 |
widget_join_tab(i_tab, widget) if widget |
| 221 |
end |
| 222 |
|
| 223 |
ライン作成。 |
| 224 |
on_timeline_created do |i_timeline| |
| 225 |
timeline = Plugin::Gtk3::Timeline.new(i_timeline) |
| 226 |
@slug_dictionary.add(i_timeline, timeline) |
| 227 |
timeline.show_all |
| 228 |
end |
| 229 |
|
| 230 |
on_gui_pane_join_window do |i_pane, i_window| |
| 231 |
window = widgetof(i_window) |
| 232 |
pane = widgetof(i_pane) |
| 233 |
pane.parent && pane.parent != window.panes and pane.parent.remove(pane) |
| 234 |
ペインを追加 |
| 235 |
pane.parent && pane.parent == window.panes or |
| 236 |
window.panes.attach_next_to pane, nil, :left, 1, 1 |
| 237 |
end |
| 238 |
|
| 239 |
on_gui_tab_join_pane do |i_tab, i_pane| |
| 240 |
i_widget = i_tab.children.first |
| 241 |
next unless i_widget |
| 242 |
widget = widgetof(i_widget) |
| 243 |
next unless widget |
| 244 |
tab = widgetof(i_tab) |
| 245 |
pane = widgetof(i_pane) |
| 246 |
old_pane = widget.get_ancestor(Gtk::Notebook) |
| 247 |
if tab && pane && old_pane && (pane != old_pane) |
| 248 |
if tab.parent |
| 249 |
page_num = tab.parent.get_tab_pos_by_tab(tab) |
| 250 |
if page_num |
| 251 |
tab.parent.remove_page(page_num) |
| 252 |
else |
| 253 |
raise Plugin::Gtk::GtkError, "#{tab} not found in #{tab.parent}" end end |
| 254 |
i_tab.children.each do |i_child| |
| 255 |
w_child = widgetof(i_child) |
| 256 |
w_child.parent.remove(w_child) |
| 257 |
widget_join_tab(i_tab, w_child) |
| 258 |
end |
| 259 |
tab.show_all end |
| 260 |
Plugin.call(:rewind_window_order, i_pane.parent) if i_pane.parent |
| 261 |
end |
| 262 |
|
| 263 |
on_gui_timeline_join_tab do |i_timeline, i_tab| |
| 264 |
widget = widgetof(i_timeline) |
| 265 |
widget_join_tab(i_tab, widget) if widget |
| 266 |
end |
| 267 |
|
| 268 |
on_gui_cluster_join_tab do |i_cluster, i_tab| |
| 269 |
widget = widgetof(i_cluster) |
| 270 |
widget_join_tab(i_tab, widget) if widget |
| 271 |
end |
| 272 |
|
| 273 |
on_gui_timeline_add_messages do |i_timeline, messages| |
| 274 |
timeline = widgetof(i_timeline) |
| 275 |
timeline.bulk_add(messages) if timeline && !timeline.destroyed? |
| 276 |
end |
| 277 |
|
| 278 |
on_gui_postbox_join_widget do |i_postbox| |
| 279 |
type_strict i_postbox => Plugin::GUI::Postbox |
| 280 |
i_postbox_parent = i_postbox.parent |
| 281 |
next unless i_postbox_parent |
| 282 |
postbox_parent = widgetof(i_postbox_parent) |
| 283 |
next unless postbox_parent |
| 284 |
postbox = @slug_dictionary.add(i_postbox, postbox_parent.add_postbox(i_postbox)) |
| 285 |
postbox.post.ssc(:focus_in_event) do |
| 286 |
i_postbox.active!(true, true) |
| 287 |
false |
| 288 |
end |
| 289 |
|
| 290 |
postbox.post.ssc('populate-popup') do |_widget, menu| |
| 291 |
(event, items) = Plugin::GUI::Command.get_menu_items(i_postbox) |
| 292 |
|
| 293 |
menu.append(Gtk::SeparatorMenuItem.new) unless items.empty? |
| 294 |
menu2 = Gtk::ContextMenu.new(*items).build!(i_postbox, event, menu) |
| 295 |
menu2.show_all |
| 296 |
true |
| 297 |
end |
| 298 |
|
| 299 |
postbox.post.ssc('key_press_event') do |_widget, event| |
| 300 |
Plugin::GUI.keypress(Gtk.keyname([event.keyval, event.state]), i_postbox) |
| 301 |
end |
| 302 |
postbox.post.ssc(:destroy) do |
| 303 |
i_postbox.destroy |
| 304 |
false |
| 305 |
end |
| 306 |
end |
| 307 |
|
| 308 |
on_gui_tab_change_icon do |i_tab| |
| 309 |
tab_update_icon(i_tab) |
| 310 |
end |
| 311 |
|
| 312 |
on_tab_toolbar_rewind do |i_tab_toolbar| |
| 313 |
tab_toolbar = widgetof(i_tab_toolbar) |
| 314 |
tab_toolbar&.set_button |
| 315 |
end |
| 316 |
|
| 317 |
on_gui_contextmenu do |event, contextmenu| |
| 318 |
widget = widgetof(event.widget) |
| 319 |
if widget |
| 320 |
Gtk::ContextMenu.new(*contextmenu).popup(widget, event) |
| 321 |
end |
| 322 |
end |
| 323 |
|
| 324 |
on_gui_timeline_clear do |i_timeline| |
| 325 |
timeline = widgetof(i_timeline) |
| 326 |
timeline&.clear |
| 327 |
end |
| 328 |
|
| 329 |
on_gui_timeline_scroll do |i_timeline, to| |
| 330 |
timeline = widgetof(i_timeline) or next |
| 331 |
timeline.jump_to to |
| 332 |
end |
| 333 |
|
| 334 |
on_gui_timeline_move_cursor_to do |i_timeline, direction_or_index| |
| 335 |
timeline = widgetof(i_timeline) or next |
| 336 |
|
| 337 |
row = timeline.selected_rows.first or next |
| 338 |
i = case direction_or_index |
| 339 |
when :prev |
| 340 |
[row.index - 1, 0].max |
| 341 |
when :next |
| 342 |
[row.index + 1, timeline.size].min |
| 343 |
else |
| 344 |
next unless direction_or_index.is_a? Integer |
| 345 |
direction_or_index |
| 346 |
end |
| 347 |
|
| 348 |
timeline.select_row_at_index i |
| 349 |
end |
| 350 |
|
| 351 |
on_gui_timeline_set_order do |i_timeline, order| |
| 352 |
widgetof(i_timeline).order = order |
| 353 |
end |
| 354 |
|
| 355 |
filter_gui_timeline_select_messages do |i_timeline, messages| |
| 356 |
timeline = widgetof(i_timeline) |
| 357 |
if timeline |
| 358 |
[i_timeline, |
| 359 |
messages.select(&timeline.method(:include?))] |
| 360 |
else |
| 361 |
[i_timeline, messages] |
| 362 |
end |
| 363 |
end |
| 364 |
|
| 365 |
filter_gui_timeline_reject_messages do |i_timeline, messages| |
| 366 |
w_timeline = widgetof(i_timeline) |
| 367 |
if w_timeline |
| 368 |
[i_timeline, |
| 369 |
messages.reject(&w_timeline.method(:include?))] |
| 370 |
else |
| 371 |
[i_timeline, messages] |
| 372 |
end |
| 373 |
end |
| 374 |
|
| 375 |
on_gui_postbox_post do |i_postbox, options| |
| 376 |
widgetof(i_postbox)&.post_it(world: options[:world]) |
| 377 |
end |
| 378 |
|
| 379 |
時に呼ばれる。 |
| 380 |
ジェットの実体もあわせて削除する。 |
| 381 |
on_gui_destroy do |i_widget| |
| 382 |
widget = widgetof(i_widget) |
| 383 |
if widget && !widget.destroyed? |
| 384 |
if i_widget.is_a?(Plugin::GUI::Tab) && i_widget.parent |
| 385 |
pane = widgetof(i_widget.parent) |
| 386 |
pane&.n_pages&.times do |pagenum| |
| 387 |
if widget == pane.get_tab_label(pane.get_nth_page(pagenum)) |
| 388 |
Plugin.call(:rewind_window_order, i_widget.parent.parent) |
| 389 |
pane.remove_page(pagenum) |
| 390 |
break |
| 391 |
end |
| 392 |
end |
| 393 |
else |
| 394 |
widget.parent&.remove(widget) |
| 395 |
widget.destroy |
| 396 |
end |
| 397 |
end |
| 398 |
end |
| 399 |
|
| 400 |
性のため |
| 401 |
on_mui_tab_regist do |container, name, icon| |
| 402 |
slug = name.to_sym |
| 403 |
i_tab = Plugin::GUI::Tab.instance(slug, name) |
| 404 |
i_tab.set_icon(icon).expand |
| 405 |
i_container = Plugin::GUI::TabChildWidget.instance |
| 406 |
@slug_dictionary.add(i_container, container) |
| 407 |
i_tab << i_container |
| 408 |
@tabs_promise[i_tab.slug] = (@tabs_promise[i_tab.slug] || Deferred.new).next do |_tab| |
| 409 |
widget_join_tab(i_tab, container.show_all) |
| 410 |
end |
| 411 |
end |
| 412 |
|
| 413 |
クトをタブに入れる |
| 414 |
on_gui_nativewidget_join_tab do |i_tab, i_container, container| |
| 415 |
@slug_dictionary.add(i_container, container) |
| 416 |
widget_join_tab(i_tab, container.show_all) |
| 417 |
end |
| 418 |
|
| 419 |
on_gui_nativewidget_join_fragment do |i_fragment, i_container, container| |
| 420 |
@slug_dictionary.add(i_container, container) |
| 421 |
widget_join_tab(i_fragment, container.show_all) |
| 422 |
end |
| 423 |
|
| 424 |
on_gui_window_rewindstatus do |_i_window, text, expire| |
| 425 |
window = @slug_dictionary.get(Plugin::GUI::Window, :default) |
| 426 |
next unless window |
| 427 |
statusbar = window.statusbar |
| 428 |
cid = statusbar.get_context_id('system') |
| 429 |
mid = statusbar.push(cid, text) |
| 430 |
if expire != 0 |
| 431 |
Delayer.new(delay: expire) do |
| 432 |
unless statusbar.destroyed? |
| 433 |
statusbar.remove(cid, mid) |
| 434 |
end |
| 435 |
end |
| 436 |
end |
| 437 |
end |
| 438 |
|
| 439 |
on_gui_child_activated do |i_parent, i_child, activated_by_toolkit| |
| 440 |
type_strict i_parent => Plugin::GUI::HierarchyParent, i_child => Plugin::GUI::HierarchyChild |
| 441 |
unless activated_by_toolkit |
| 442 |
if i_child.is_a?(Plugin::GUI::TabLike) |
| 443 |
i_pane = i_parent |
| 444 |
i_tab = i_child |
| 445 |
pane = widgetof(i_pane) |
| 446 |
tab = widgetof(i_tab) |
| 447 |
pane && tab and pane.page = pane.get_tab_pos_by_tab(tab) |
| 448 |
elsif i_parent.is_a?(Plugin::GUI::Window) |
| 449 |
i_term = i_child.respond_to?(:active_chain) ? i_child.active_chain.last : i_child |
| 450 |
if i_term |
| 451 |
window = widgetof(i_parent) |
| 452 |
widget = widgetof(i_term) |
| 453 |
if window && widget |
| 454 |
if widget.respond_to? :active |
| 455 |
widget.active |
| 456 |
else |
| 457 |
window.set_focus(widget) |
| 458 |
end |
| 459 |
end |
| 460 |
end |
| 461 |
end |
| 462 |
end |
| 463 |
end |
| 464 |
|
| 465 |
on_posted do |_service, messages| |
| 466 |
messages.each do |message| |
| 467 |
replyto_source = message.replyto_source |
| 468 |
if replyto_source |
| 469 |
Plugin::Gtk3::Timeline.update_rows(replyto_source) |
| 470 |
end |
| 471 |
end |
| 472 |
end |
| 473 |
|
| 474 |
on_message_modified(&Plugin::Gtk3::Timeline.method(:update_rows)) |
| 475 |
on_destroyed(&Plugin::Gtk3::Timeline.method(:remove_rows)) |
| 476 |
|
| 477 |
share = ->(_, model) do |
| 478 |
Plugin::Gtk3::Timeline.update_rows(model) |
| 479 |
end |
| 480 |
|
| 481 |
on_share(&share) |
| 482 |
on_before_share(&share) |
| 483 |
on_fail_share(&share) |
| 484 |
on_destroy_share(&share) |
| 485 |
|
| 486 |
favorite = ->(_, _, model) do |
| 487 |
Plugin::Gtk3::Timeline.update_rows(model) |
| 488 |
end |
| 489 |
|
| 490 |
on_favorite(&favorite) |
| 491 |
on_before_favorite(&favorite) |
| 492 |
on_fail_favorite(&favorite) |
| 493 |
|
| 494 |
on_konami_activate do |
| 495 |
Gtk.konami_load |
| 496 |
end |
| 497 |
|
| 498 |
filter_gui_postbox_input_editable do |i_postbox, editable| |
| 499 |
postbox = widgetof(i_postbox) |
| 500 |
if postbox |
| 501 |
[i_postbox, postbox&.post&.editable?] |
| 502 |
else |
| 503 |
[i_postbox, editable] end |
| 504 |
end |
| 505 |
|
| 506 |
filter_gui_timeline_cursor_position do |_i_timeline, _y| |
| 507 |
raise NotImplementedError |
| 508 |
end |
| 509 |
|
| 510 |
filter_gui_timeline_selected_messages do |i_timeline, messages| |
| 511 |
timeline = widgetof(i_timeline) |
| 512 |
if timeline |
| 513 |
[i_timeline, messages + timeline.selected_rows.map(&:model)] |
| 514 |
else |
| 515 |
[i_timeline, messages] |
| 516 |
end |
| 517 |
end |
| 518 |
|
| 519 |
filter_gui_timeline_selected_text do |i_timeline, message, text| |
| 520 |
timeline = widgetof(i_timeline) |
| 521 |
next [i_timeline, message, text] unless timeline |
| 522 |
record = timeline.selected_rows.find { |row| row.model == message } |
| 523 |
next [i_timeline, message, text] unless record |
| 524 |
range = record.textselector_range |
| 525 |
next [i_timeline, message, text] unless range |
| 526 |
if UserConfig[:miraclepainter_expand_custom_emoji] |
| 527 |
adjust = score_of(message).each_with_object(Hash.new(0)) do |note, state| |
| 528 |
if note.respond_to?(:inline_photo) |
| 529 |
換された、絵文字の文字長 |
| 530 |
if range.include?(state[:index]) |
| 531 |
state[:end] += note.description.size - 1 |
| 532 |
elsif state[:index] < range.begin |
| 533 |
state[:begin] += note.description.size - 1 |
| 534 |
end |
| 535 |
state[:index] += 1 |
| 536 |
else |
| 537 |
state[:index] += note.description.size |
| 538 |
end |
| 539 |
end |
| 540 |
range = Range.new(range.begin + adjust[:begin], range.end + adjust[:begin] + adjust[:end], true) |
| 541 |
end |
| 542 |
[i_timeline, message, score_of(message).map(&:description).join[range]] |
| 543 |
end |
| 544 |
|
| 545 |
filter_gui_destroyed do |i_widget| |
| 546 |
if i_widget.is_a? Plugin::GUI::Widget |
| 547 |
[!widgetof(i_widget)] |
| 548 |
else |
| 549 |
[i_widget] |
| 550 |
end |
| 551 |
end |
| 552 |
|
| 553 |
filter_gui_get_gtk_widget do |i_widget| |
| 554 |
[widgetof(i_widget)] |
| 555 |
end |
| 556 |
|
| 557 |
on_gui_dialog do |plugin, title, default, proc, promise| |
| 558 |
Plugin::Gtk3::Dialog.open( |
| 559 |
plugin:, |
| 560 |
title:, |
| 561 |
default:, |
| 562 |
promise:, |
| 563 |
parent: @parent, |
| 564 |
&proc |
| 565 |
) |
| 566 |
end |
| 567 |
|
| 568 |
filter_before_mainloop_exit do |
| 569 |
unless @slug_dictionary.widgets(Plugin::GUI::Window).all?(&:destroyed?) |
| 570 |
error 'Filter before_mainloop_exit was canceled because window already exists.' |
| 571 |
Plugin.filter_cancel! |
| 572 |
end |
| 573 |
[] |
| 574 |
end |
| 575 |
|
| 576 |
_ を入れる |
| 577 |
|
| 578 |
タブ |
| 579 |
ジェット |
| 580 |
def widget_join_tab(i_tab, widget) |
| 581 |
tab = widgetof(i_tab) |
| 582 |
return false unless tab |
| 583 |
i_pane = i_tab.parent |
| 584 |
return false unless i_pane |
| 585 |
pane = widgetof(i_pane) |
| 586 |
return false unless pane |
| 587 |
is_tab = i_tab.is_a?(Plugin::GUI::Tab) |
| 588 |
has_child = is_tab && |
| 589 |
!i_tab.temporary_tab? && |
| 590 |
i_tab.children.any?(Plugin::GUI::TabToolbar) |
| 591 |
if has_child |
| 592 |
Plugin.call(:rewind_window_order, i_pane.parent) |
| 593 |
end |
| 594 |
container_index = pane.get_tab_pos_by_tab(tab) |
| 595 |
if container_index |
| 596 |
container = pane.get_nth_page(container_index) |
| 597 |
if container |
| 598 |
widget.vexpand = i_tab.pack_rule[container.children.size] |
| 599 |
return container.add(widget) |
| 600 |
end |
| 601 |
end |
| 602 |
if tab.parent |
| 603 |
raise Plugin::Gtk3::GtkError, "Gtk Widget #{tab.inspect} of Tab(#{i_tab.slug.inspect}) has parent Gtk Widget #{tab.parent.inspect}" |
| 604 |
end |
| 605 |
container = Plugin::Gtk3::TabContainer.new(i_tab).show_all |
| 606 |
container.ssc(:key_press_event) do |_w, event| |
| 607 |
Plugin::GUI.keypress(Gtk.keyname([event.keyval, event.state]), i_tab) |
| 608 |
end |
| 609 |
widget.vexpand = i_tab.pack_rule[container.children.size] |
| 610 |
container.add(widget) |
| 611 |
pos = where_should_insert_it( |
| 612 |
i_tab, |
| 613 |
pane.each_pages.map do |target_page| |
| 614 |
find_implement_widget_by_gtkwidget(pane.get_tab_label(target_page)) |
| 615 |
end, |
| 616 |
i_tab.parent.children |
| 617 |
) |
| 618 |
pane.insert_page(container, tab, pos) |
| 619 |
pane.set_tab_reorderable(container, true).set_tab_detachable(container, true) |
| 620 |
true |
| 621 |
end |
| 622 |
|
| 623 |
def tab_update_icon(i_tab) |
| 624 |
type_strict i_tab => Plugin::GUI::TabLike |
| 625 |
tab = widgetof(i_tab) |
| 626 |
if tab |
| 627 |
tab.tooltip_text = i_tab.name |
| 628 |
tab.remove(tab.child) if tab.child |
| 629 |
if i_tab.icon |
| 630 |
tab.add(Gtk::WebIcon.new(i_tab.icon, 24, 24).show) |
| 631 |
else |
| 632 |
tab.add(Gtk::Label.new(i_tab.name).show) end end |
| 633 |
self |
| 634 |
end |
| 635 |
|
| 636 |
def get_window_geometry(slug) |
| 637 |
type_strict slug => Symbol |
| 638 |
geometry = UserConfig[:windows_geometry] |
| 639 |
geometry and geometry[slug] |
| 640 |
end |
| 641 |
|
| 642 |
ンを作成 |
| 643 |
|
| 644 |
イン |
| 645 |
|
| 646 |
ebook) |
| 647 |
def create_pane(i_pane) |
| 648 |
pane = Gtk::Notebook.new |
| 649 |
@slug_dictionary.add(i_pane, pane) |
| 650 |
pane.ssc('key_press_event') do |_widget, event| |
| 651 |
Plugin::GUI.keypress(Gtk.keyname([event.keyval, event.state]), i_pane) |
| 652 |
end |
| 653 |
pane.ssc(:destroy) do |
| 654 |
i_pane.destroy if i_pane.destroyed? |
| 655 |
false |
| 656 |
end |
| 657 |
pane.show_all |
| 658 |
end |
| 659 |
|
| 660 |
ン、タブの現在の順序を設定に保存する |
| 661 |
on_rewind_window_order do |i_window| |
| 662 |
if i_window.slug == :default |
| 663 |
panes_order = i_window.children.select { |i_pane| |
| 664 |
i_pane.is_a?(Plugin::GUI::Pane) |
| 665 |
}.map { |i_pane| |
| 666 |
pane = widgetof(i_pane) |
| 667 |
tab_order = pane.each_pages.map { |page| |
| 668 |
find_implement_widget_by_gtkwidget(pane.get_tab_label(page)) |
| 669 |
}.select { |i_widget| |
| 670 |
i_widget && |
| 671 |
!i_widget.temporary_tab? && |
| 672 |
i_widget.children.any? { |child| !child.is_a?(Plugin::GUI::TabToolbar) } |
| 673 |
}.map(&:slug) |
| 674 |
[i_pane.slug, tab_order] unless tab_order.empty? |
| 675 |
}.compact.to_h |
| 676 |
ui_tab_order = (UserConfig[:ui_tab_order] || {}).melt |
| 677 |
ui_tab_order[i_window.slug] = panes_order |
| 678 |
UserConfig[:ui_tab_order] = ui_tab_order |
| 679 |
end |
| 680 |
end |
| 681 |
|
| 682 |
序リストから削除する |
| 683 |
|
| 684 |
イン |
| 685 |
def pane_order_delete(i_pane) |
| 686 |
order = UserConfig[:ui_tab_order].melt |
| 687 |
i_window = i_pane.parent |
| 688 |
order[i_window.slug] = order[i_window.slug].melt |
| 689 |
order[i_window.slug].delete(i_pane.slug) |
| 690 |
UserConfig[:ui_tab_order] = order |
| 691 |
end |
| 692 |
|
| 693 |
kオブジェクトを返す |
| 694 |
|
| 695 |
ペイン、タブ、タイムライン等 |
| 696 |
|
| 697 |
tkオブジェクト |
| 698 |
def widgetof(cuscadable) |
| 699 |
type_strict cuscadable => :slug |
| 700 |
result = @slug_dictionary.get(cuscadable) |
| 701 |
if result&.destroyed? |
| 702 |
nil |
| 703 |
else |
| 704 |
result |
| 705 |
end |
| 706 |
end |
| 707 |
|
| 708 |
するウィジェットのオブジェクトを返す |
| 709 |
|
| 710 |
ジェット |
| 711 |
|
| 712 |
ジェットオブジェクトまたは偽 |
| 713 |
def find_implement_widget_by_gtkwidget(widget) |
| 714 |
@slug_dictionary.imaginally_by_gtk(widget) |
| 715 |
end |
| 716 |
|
| 717 |
するフィルタ |
| 718 |
filter_gui_timeline_get_timeline_max do |i_tl, _| |
| 719 |
[i_tl, widgetof(i_tl).timeline_max] |
| 720 |
end |
| 721 |
|
| 722 |
するフィルタ |
| 723 |
filter_gui_timeline_set_timeline_max do |i_tl, n| |
| 724 |
widgetof(i_tl).timeline_max = n |
| 725 |
[i_tl, n] |
| 726 |
end |
| 727 |
|
| 728 |
メッセージを順に処理するフィルタ |
| 729 |
filter_gui_timeline_each_messages do |i_tl, y| |
| 730 |
widgetof(i_tl).each do |m| |
| 731 |
y << m |
| 732 |
end |
| 733 |
[i_tl, y] |
| 734 |
end |
| 735 |
|
| 736 |
on_clipboard_write do |value| |
| 737 |
Gtk::Clipboard.copy(value) |
| 738 |
end |
| 739 |
|
| 740 |
filter_clipboard_read do |_| |
| 741 |
[Gtk::Clipboard.paste] |
| 742 |
end |
| 743 |
end |
| 744 |
|
| 745 |
module Plugin::Gtk3 |
| 746 |
class GtkError < Exception |
| 747 |
end |
| 748 |
end |