| 1 |
|
| 2 |
|
| 3 |
class Plugin::ExtractGtk::DatasourceSelectBox < Gtk::HierarchycalSelectBox |
| 4 |
def initialize(sources, &) |
| 5 |
super(datasources, sources, &) |
| 6 |
end |
| 7 |
|
| 8 |
def datasources |
| 9 |
(Plugin.filtering(:extract_datasources, {}) || [{}]).first.map do |id, source_name| |
| 10 |
[id, source_name.is_a?(String) ? source_name.split('/') : source_name] |
| 11 |
end |
| 12 |
end |
| 13 |
|
| 14 |
def menu_pop(widget, _event) |
| 15 |
datasource = selected_datasource_names.first |
| 16 |
if datasource |
| 17 |
contextmenu = Gtk::ContextMenu.new |
| 18 |
contextmenu.register(Plugin[:extract]._('データソース slugをコピー'), ©_slug(datasource)) |
| 19 |
contextmenu.register(Plugin[:extract]._('subscriberをコピー'), ©_subscriber(datasource)) |
| 20 |
contextmenu.popup(widget, widget) |
| 21 |
end |
| 22 |
end |
| 23 |
|
| 24 |
def copy_slug(datasource) |
| 25 |
->(_optional=nil, _widget=nil) do |
| 26 |
Gtk::Clipboard.copy(datasource.to_s) |
| 27 |
end |
| 28 |
end |
| 29 |
|
| 30 |
def copy_subscriber(datasource) |
| 31 |
->(_optional=nil, _widget=nil) do |
| 32 |
Gtk::Clipboard.copy(<<~CODE % { ds: datasource.to_sym.inspect }) |
| 33 |
subscribe(:extract_receive_message, %{ds}).each do |message| |
| 34 |
#{' '} |
| 35 |
end |
| 36 |
CODE |
| 37 |
end |
| 38 |
end |
| 39 |
|
| 40 |
private |
| 41 |
|
| 42 |
def selected_datasource_names |
| 43 |
selection.to_enum(:selected_each).map do |_, _, iter| |
| 44 |
iter[ITER_ID] |
| 45 |
end |
| 46 |
end |
| 47 |
end |