diff --git a/core/mui/gtk_form_dsl.rb b/core/mui/gtk_form_dsl.rb index 0fadc81..c127006 100644 --- a/core/mui/gtk_form_dsl.rb +++ b/core/mui/gtk_form_dsl.rb @@ -76,8 +76,8 @@ module Gtk::FormDSL # [label] ラベル # [config] キー # [dir] 初期のディレクトリ - def fileselect(label, config, _current=Dir.pwd, dir: _current, title: label.to_s) - fsselect(label, config, dir: dir, action: Gtk::FileChooser::ACTION_OPEN, title: title) + def fileselect(label, config, _current=Dir.pwd, dir: _current, title: label.to_s, shortcuts: nil) + fsselect(label, config, dir: dir, action: Gtk::FileChooser::ACTION_OPEN, title: title, shortcuts: shortcuts) end # ファイルを選択する @@ -94,8 +94,8 @@ module Gtk::FormDSL # [label] ラベル # [config] 設定のキー # [current] 初期のディレクトリ - def dirselect(label, config, _current=Dir.pwd, dir: _current, title: label.to_s) - fsselect(label, config, dir: dir, action: Gtk::FileChooser::ACTION_SELECT_FOLDER, title: title) + def dirselect(label, config, _current=Dir.pwd, dir: _current, title: label.to_s, shortcuts: nil) + fsselect(label, config, dir: dir, action: Gtk::FileChooser::ACTION_SELECT_FOLDER, title: title, shortcuts: shortcuts) end # 一行テキストボックス @@ -374,12 +374,12 @@ module Gtk::FormDSL self[config] = w.font_name } button end - def fsselect(label, config, dir: Dir.pwd, action: Gtk::FileChooser::ACTION_OPEN, title: label) + def fsselect(label, config, dir: Dir.pwd, action: Gtk::FileChooser::ACTION_OPEN, title: label, shortcuts: nil) container = input(label, config) input = container.children.last.children.first button = Gtk::Button.new(Plugin[:settings]._('参照')) container.pack_start(button, false) - button.signal_connect(:clicked, &gen_fileselect_dialog_generator(title, action, dir, config: config, &input.method(:text=))) + button.signal_connect(:clicked, &gen_fileselect_dialog_generator(title, action, dir, config: config, shortcuts: shortcuts, &input.method(:text=))) container end @@ -443,7 +443,7 @@ module Gtk::FormDSL end end - def gen_fileselect_dialog_generator(title, action, dir, config:, &result_callback) + def gen_fileselect_dialog_generator(title, action, dir, config:, shortcuts: nil, &result_callback) ->(widget) do dialog = Gtk::FileChooserDialog.new(title, widget.get_ancestor(Gtk::Window), @@ -452,6 +452,16 @@ module Gtk::FormDSL [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL], [Gtk::Stock::OPEN, Gtk::Dialog::RESPONSE_ACCEPT]) dialog.current_folder = File.expand_path(dir) + shortcuts.to_a.select { |dir| + !dialog.shortcut_folders.include?(dir) + }.each { |dir| + begin + dialog.add_shortcut_folder(dir) + rescue => e + puts e + puts e.backtrace + end + } dialog.ssc_atonce(:response, &gen_fs_dialog_response_callback(config, &result_callback)) dialog.show_all false