From f13d5f135be17f5dfadcc1bae438018ef5317f26 Mon Sep 17 00:00:00 2001 From: moguno Date: Fri, 31 Jul 2015 22:04:00 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=E8=A8=AD=E5=AE=9A=E7=94=BB=E9=9D=A2DSL?= =?UTF-8?q?=E3=81=AB=E3=83=87=E3=82=A3=E3=83=AC=E3=82=AF=E3=83=88=E3=83=AA?= =?UTF-8?q?=E9=81=B8=E6=8A=9E=E3=82=92=E8=BF=BD=E5=8A=A0=E3=81=97=E3=81=9F?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/plugin/settings/builder.rb | 51 ++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/core/plugin/settings/builder.rb b/core/plugin/settings/builder.rb index 57c832b..5df0c45 100644 --- a/core/plugin/settings/builder.rb +++ b/core/plugin/settings/builder.rb @@ -88,27 +88,18 @@ class Plugin::Settings < Gtk::VBox # [config] 設定のキー # [current] 初期のディレクトリ def fileselect(label, config, current=Dir.pwd) - container = input(label, config) - input = container.children.last.children.first - button = Gtk::Button.new('参照') - container.pack_start(button, false) - button.signal_connect('clicked'){ |widget| - dialog = Gtk::FileChooserDialog.new("Open File", - widget.get_ancestor(Gtk::Window), - Gtk::FileChooser::ACTION_OPEN, - nil, - [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL], - [Gtk::Stock::OPEN, Gtk::Dialog::RESPONSE_ACCEPT]) - dialog.current_folder = File.expand_path(current) - if dialog.run == Gtk::Dialog::RESPONSE_ACCEPT - Listener[config].set dialog.filename - input.text = dialog.filename - end - dialog.destroy - } - container + fsselect(label, config, current, Gtk::FileChooser::ACTION_OPEN) end + # ディレクトリを選択する + # ==== Args + # [label] ラベル + # [config] 設定のキー + # [current] 初期のディレクトリ + def dirselect(label, config, current=Dir.pwd) + fsselect(label, config, current, Gtk::FileChooser::ACTION_SELECT_FOLDER) + end + # 一行テキストボックス # ==== Args # [label] ラベル @@ -290,6 +281,28 @@ class Plugin::Settings < Gtk::VBox Listener[config].set w.font_name } button end + def fsselect(label, config, current=Dir.pwd, action) + container = input(label, config) + input = container.children.last.children.first + button = Gtk::Button.new('参照') + container.pack_start(button, false) + button.signal_connect('clicked'){ |widget| + dialog = Gtk::FileChooserDialog.new("Open File", + widget.get_ancestor(Gtk::Window), + action, + nil, + [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL], + [Gtk::Stock::OPEN, Gtk::Dialog::RESPONSE_ACCEPT]) + dialog.current_folder = File.expand_path(current) + if dialog.run == Gtk::Dialog::RESPONSE_ACCEPT + Listener[config].set dialog.filename + input.text = dialog.filename + end + dialog.destroy + } + container + end + def method_missing(*args, &block) @plugin.__send__(*args, &block) end -- 2.4.3