プロジェクト

全般

プロフィール

機能 #1195 » 1195.patch

cob odo, 2018-03-30 15:40

差分を表示:

core/mui/gtk_form_dsl.rb
76 76
  # [label] ラベル
77 77
  # [config] キー
78 78
  # [dir] 初期のディレクトリ
79
  def fileselect(label, config, _current=Dir.pwd, dir: _current, title: label.to_s)
80
    fsselect(label, config, dir: dir, action: Gtk::FileChooser::ACTION_OPEN, title: title)
79
  def fileselect(label, config, _current=Dir.pwd, dir: _current, title: label.to_s, shortcuts: nil)
80
    fsselect(label, config, dir: dir, action: Gtk::FileChooser::ACTION_OPEN, title: title, shortcuts: shortcuts)
81 81
  end
82 82
  # ファイルを選択する
......
94 94
  # [label] ラベル
95 95
  # [config] 設定のキー
96 96
  # [current] 初期のディレクトリ
97
  def dirselect(label, config, _current=Dir.pwd, dir: _current, title: label.to_s)
98
    fsselect(label, config, dir: dir, action: Gtk::FileChooser::ACTION_SELECT_FOLDER, title: title)
97
  def dirselect(label, config, _current=Dir.pwd, dir: _current, title: label.to_s, shortcuts: nil)
98
    fsselect(label, config, dir: dir, action: Gtk::FileChooser::ACTION_SELECT_FOLDER, title: title, shortcuts: shortcuts)
99 99
  end
100 100
  # 一行テキストボックス
......
374 374
      self[config] = w.font_name }
375 375
    button end
376
  def fsselect(label, config, dir: Dir.pwd, action: Gtk::FileChooser::ACTION_OPEN, title: label)
376
  def fsselect(label, config, dir: Dir.pwd, action: Gtk::FileChooser::ACTION_OPEN, title: label, shortcuts: nil)
377 377
    container = input(label, config)
378 378
    input = container.children.last.children.first
379 379
    button = Gtk::Button.new(Plugin[:settings]._('参照'))
380 380
    container.pack_start(button, false)
381
    button.signal_connect(:clicked, &gen_fileselect_dialog_generator(title, action, dir, config: config, &input.method(:text=)))
381
    button.signal_connect(:clicked, &gen_fileselect_dialog_generator(title, action, dir, config: config, shortcuts: shortcuts, &input.method(:text=)))
382 382
    container
383 383
  end
......
443 443
    end
444 444
  end
445
  def gen_fileselect_dialog_generator(title, action, dir, config:, &result_callback)
445
  def gen_fileselect_dialog_generator(title, action, dir, config:, shortcuts: nil, &result_callback)
446 446
    ->(widget) do
447 447
      dialog = Gtk::FileChooserDialog.new(title,
448 448
                                          widget.get_ancestor(Gtk::Window),
......
452 452
                                          [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL],
453 453
                                          [Gtk::Stock::OPEN, Gtk::Dialog::RESPONSE_ACCEPT])
454 454
      dialog.current_folder = File.expand_path(dir)
455
      shortcuts.to_a.select { |dir|
456
        !dialog.shortcut_folders.include?(dir)
457
      }.each { |dir|
458
        begin
459
          dialog.add_shortcut_folder(dir)
460
        rescue => e
461
          puts e
462
          puts e.backtrace
463
        end
464
      }
455 465
      dialog.ssc_atonce(:response, &gen_fs_dialog_response_callback(config, &result_callback))
456 466
      dialog.show_all
457 467
      false
(1-1/2)