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
|
# frozen_string_literal: true
class Plugin::Extract::DatasourceSelectBox < Gtk::HierarchycalSelectBox
def initialize(sources, &block)
super(datasources, sources, &block)
end
def datasources
(Plugin.filtering(:extract_datasources, {}) || [{}]).first.map do |id, source_name|
[id, source_name.is_a?(String) ? source_name.split('/'.freeze) : source_name]
end
end
def menu_pop(widget, _event)
datasource = selected_datasource_names.first
if datasource
contextmenu = Gtk::ContextMenu.new
contextmenu.register(Plugin[:extract]._('データソース slugをコピー'), ©_slug(datasource))
contextmenu.register(Plugin[:extract]._('subscriberをコピー'), ©_subscriber(datasource))
contextmenu.popup(widget, widget)
end
end
def copy_slug(datasource)
->(_optional=nil, _widget=nil) do
Gtk::Clipboard.copy(datasource.to_s)
end
end
def copy_subscriber(datasource)
->(_optional=nil, _widget=nil) do
Gtk::Clipboard.copy(<<~'EOM' % {ds: datasource.to_sym.inspect})
subscribe(:extract_receive_message, %{ds}).each do |message|
end
EOM
end
end
private
def selected_datasource_names
self.selection.to_enum(:selected_each).map {|_, _, iter|
iter[ITER_ID]
}
end
end
|