| 1 |
|
| 2 |
|
| 3 |
module Plugin::ExtractGtk |
| 4 |
end |
| 5 |
|
| 6 |
|
| 7 |
タブの一覧 |
| 8 |
|
| 9 |
|
| 10 |
class Plugin::ExtractGtk::ExtractTabList < Gtk::TreeView |
| 11 |
ICON_SIZE = 16 |
| 12 |
|
| 13 |
COL_ICON = 0 |
| 14 |
COL_NAME = 1 |
| 15 |
COL_SLUG = 2 |
| 16 |
COL_SOUND = 3 |
| 17 |
COL_POPUP = 4 |
| 18 |
|
| 19 |
def initialize(plugin) |
| 20 |
super(Gtk::ListStore.new( |
| 21 |
GdkPixbuf::Pixbuf, |
| 22 |
String, |
| 23 |
Symbol, |
| 24 |
GdkPixbuf::Pixbuf, |
| 25 |
GdkPixbuf::Pixbuf |
| 26 |
)) |
| 27 |
|
| 28 |
append_column Gtk::TreeViewColumn.new( |
| 29 |
'', |
| 30 |
Gtk::CellRendererPixbuf.new, |
| 31 |
pixbuf: COL_ICON |
| 32 |
) |
| 33 |
append_column(Gtk::TreeViewColumn.new( |
| 34 |
plugin._('名前'), |
| 35 |
Gtk::CellRendererText.new, |
| 36 |
text: COL_NAME |
| 37 |
).tap { |col| col.expand = true }) |
| 38 |
append_column Gtk::TreeViewColumn.new( |
| 39 |
'', |
| 40 |
Gtk::CellRendererPixbuf.new, |
| 41 |
pixbuf: COL_SOUND |
| 42 |
) |
| 43 |
append_column Gtk::TreeViewColumn.new( |
| 44 |
'', |
| 45 |
Gtk::CellRendererPixbuf.new, |
| 46 |
pixbuf: COL_POPUP |
| 47 |
) |
| 48 |
|
| 49 |
extract_tabs.each(&method(:add_record)) |
| 50 |
register_signal_handlers |
| 51 |
end |
| 52 |
|
| 53 |
いる抽出タブのslugを返す |
| 54 |
|
| 55 |
lug。何も選択されていない場合はnil |
| 56 |
def selected_slug |
| 57 |
selected_iter = selection.selected |
| 58 |
selected_iter[COL_SLUG].to_sym if selected_iter |
| 59 |
end |
| 60 |
|
| 61 |
ドを追加する |
| 62 |
|
| 63 |
xtract::Setting) |
| 64 |
|
| 65 |
|
| 66 |
def add_record(record) |
| 67 |
iter = model.append |
| 68 |
setup_iter iter, record |
| 69 |
self |
| 70 |
end |
| 71 |
|
| 72 |
とにリストビューを更新する |
| 73 |
|
| 74 |
:Extract::Setting) |
| 75 |
def update_record(record) |
| 76 |
update_iter = model.to_enum(:each) |
| 77 |
.map { |_, _, iter| iter } |
| 78 |
.find { |iter| record[:slug].to_sym == iter[COL_SLUG].to_sym } |
| 79 |
setup_iter update_iter, record if update_iter |
| 80 |
end |
| 81 |
|
| 82 |
をリストから削除する |
| 83 |
|
| 84 |
抽出タブのslug |
| 85 |
|
| 86 |
|
| 87 |
def remove_record(record_slug) |
| 88 |
record_slug = record_slug.to_sym |
| 89 |
remove_iter = model.to_enum(:each).map { |_, _, iter| iter }.find { |iter| record_slug == iter[COL_SLUG].to_sym } |
| 90 |
model.remove(remove_iter) if remove_iter |
| 91 |
self |
| 92 |
end |
| 93 |
|
| 94 |
private |
| 95 |
|
| 96 |
def register_signal_handlers |
| 97 |
ルクリックして設定を開く |
| 98 |
ssc(:button_press_event) do |_, ev| |
| 99 |
next if ev.event_type != Gdk::EventType::BUTTON2_PRESS |
| 100 |
slug = selected_slug |
| 101 |
if slug |
| 102 |
Plugin.call(:extract_open_edit_dialog, slug) |
| 103 |
true |
| 104 |
end |
| 105 |
end |
| 106 |
end |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
ドの配列を返す |
| 111 |
|
| 112 |
ードの配列 |
| 113 |
def extract_tabs |
| 114 |
Plugin.filtering(:extract_tabs_get, []).first |
| 115 |
end |
| 116 |
|
| 117 |
レコードの内容をコピーする |
| 118 |
|
| 119 |
|
| 120 |
xtract::Setting) |
| 121 |
def setup_iter(iter, record) |
| 122 |
size = { width: Gdk.scale(ICON_SIZE), height: Gdk.scale(ICON_SIZE) } |
| 123 |
set_icon = ->(col, photo) do |
| 124 |
iter[col] = photo.load_pixbuf(**size) do |pb| |
| 125 |
iter[col] = pb unless destroyed? |
| 126 |
end |
| 127 |
end |
| 128 |
|
| 129 |
iter[COL_NAME] = record[:name] |
| 130 |
iter[COL_SLUG] = record[:slug] |
| 131 |
if record[:icon] |
| 132 |
photo = Enumerator.new { |y| |
| 133 |
Plugin.filtering :photo_filter, record[:icon], y |
| 134 |
}.first |
| 135 |
set_icon.(COL_ICON, photo) |
| 136 |
end |
| 137 |
if record[:sound].to_s.empty? |
| 138 |
set_icon.(COL_SOUND, Skin[:notify_sound_off]) |
| 139 |
else |
| 140 |
set_icon.(COL_SOUND, Skin[:notify_sound_on]) |
| 141 |
end |
| 142 |
if record[:popup] |
| 143 |
set_icon.(COL_POPUP, Skin[:notify_popup_on]) |
| 144 |
else |
| 145 |
set_icon.(COL_POPUP, Skin[:notify_popup_off]) |
| 146 |
end |
| 147 |
end |
| 148 |
end |