Debian Codegraph @

plugin/extract_gtk/edit_window.rb

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2
3 require 'mui/gtk_hierarchycal_selectbox'
4
5 require_relative 'option_widget'
6 require_relative 'datasource_select_box'
7
8 require 'observer'
9
10 module Plugin::ExtractGtk
11 end
12
13 class Plugin::ExtractGtk::EditWindow < Gtk::Window
14 attr_reader :extract
15
16 # ==== Args
17 # [extract] 抽出タブ設定 (Plugin::Extract::Setting)
18 # [plugin] プラグインのインスタンス (Plugin)
19 def initialize(extract, plugin)
20 @plugin = plugin
21 @extract = extract
22 super(_('%{name} - 抽出タブ - %{application_name}') % { name:, application_name: Environment::NAME })
23
24 notebook = Gtk::Notebook.new
25 notebook.expand = true
26 notebook.append_page(source_widget, Gtk::Label.new(_('データソース')))
27 notebook.append_page(condition_widget, Gtk::Label.new(_('絞り込み条件')))
28 notebook.append_page(option_widget, Gtk::Label.new(_('オプション')))
29 add(Gtk::Grid.new
30 .tap { |grid| grid.orientation = :vertical }
31 .add(notebook)
32 .add(ok_button.tap { |w| w.halign = :end }))
33 ssc(:destroy) do
34 @extract.notify_update
35 false
36 end
37 set_size_request 480, 320
38 show_all
39 end
40
41 def name
42 @extract.name
43 end
44
45 def sexp
46 @extract.sexp
47 end
48
49 def id
50 @extract.id
51 end
52
53 def sources
54 @extract.sources
55 end
56
57 def slug
58 @extract.slug
59 end
60
61 def sound
62 @extract.sound
63 end
64
65 def popup
66 @extract.popup
67 end
68
69 def order
70 @extract.order
71 end
72
73 def icon
74 @extract.icon
75 end
76
77 def source_widget
78 datasources_box = Plugin::ExtractGtk::DatasourceSelectBox.new(sources) do
79 modify_value(sources: datasources_box.selected.to_a)
80 end
81 @source_widget ||= Gtk::ScrolledWindow.new.add datasources_box
82 end
83
84 def condition_widget
85 @condition_widget ||= Gtk::MessagePicker.new(sexp.freeze) {
86 modify_value sexp: @condition_widget.to_a
87 }.tap { |w| w.expand = true }
88 end
89
90 def option_widget
91 Plugin::ExtractGtk::OptionWidget.new(@plugin, @extract) do
92 input _('名前'), :name
93 shortcuts = [Skin.default_dir]
94 Skin.user_dir and shortcuts << Skin.user_dir
95 photoselect(_('アイコン'), :icon, dir: Skin.path, shortcuts:)
96 settings _('通知') do
97 fileselect _('サウンド'), :sound,
98 dir: File.join(Skin.default_dir, 'sounds'),
99 shortcuts: [File.join(Skin.default_dir, 'sounds')],
100 filters: { _('非圧縮音声ファイル (*.wav, *.aiff)') => ['wav', 'WAV', 'aiff', 'AIFF'],
101 _('FLAC (*.flac, *.fla)') => ['flac', 'FLAC', 'fla', 'FLA'],
102 _('MPEG-1/2 Audio Layer-3 (*.mp3)') => ['mp3', 'MP3'],
103 _('Ogg (*.ogg)') => ['ogg', 'OGG'],
104 _('全てのファイル') => ['*'] }
105 boolean _('ポップアップ'), :popup, switch: true
106 end
107 select(_('並び順'), :order, Plugin.collect(:extract_order).to_h { |o| [o.slug.to_s, o.name] })
108 end
109 end
110
111 def ok_button
112 Gtk::Button.new(label: _('閉じる')).tap do |button|
113 button.ssc(:clicked) do
114 destroy
115 end
116 end
117 end
118
119 def refresh_title
120 set_title _('%{name} - 抽出タブ - %{application_name}') % { name:, application_name: Environment::NAME }
121 end
122
123 private
124
125 def modify_value(new_values)
126 @extract.merge(new_values)
127 refresh_title
128 @extract.notify_update
129 self
130 end
131
132 def _(message)
133 @plugin._(message)
134 end
135 end