プロジェクト

全般

プロフィール

機能 #1195 » 1195_2.patch

cob odo, 2018-03-30 23:26

差分を表示:

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: [], filters: {}, use_preview: false)
80
    fsselect(label, config, dir: dir, action: Gtk::FileChooser::ACTION_OPEN, title: title, shortcuts: shortcuts, filters: filters, use_preview: use_preview)
81 81
  end
82 82

  
83 83
  # ファイルを選択する
......
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: [])
98
    fsselect(label, config, dir: dir, action: Gtk::FileChooser::ACTION_SELECT_FOLDER, title: title, shortcuts: shortcuts)
99 99
  end
100 100

  
101 101
  # 一行テキストボックス
......
374 374
      self[config] = w.font_name }
375 375
    button end
376 376

  
377
  def fsselect(label, config, dir: Dir.pwd, action: Gtk::FileChooser::ACTION_OPEN, title: label)
377
  def fsselect(label, config, dir: Dir.pwd, action: Gtk::FileChooser::ACTION_OPEN, title: label, shortcuts: [], filters: {}, use_preview: false)
378 378
    container = input(label, config)
379 379
    input = container.children.last.children.first
380 380
    button = Gtk::Button.new(Plugin[:settings]._('参照'))
381 381
    container.pack_start(button, false)
382
    button.signal_connect(:clicked, &gen_fileselect_dialog_generator(title, action, dir, config: config, &input.method(:text=)))
382
    button.signal_connect(:clicked, &gen_fileselect_dialog_generator(title, action, dir, config: config, shortcuts: shortcuts, filters: filters, use_preview: use_preview, &input.method(:text=)))
383 383
    container
384 384
  end
385 385

  
......
443 443
    end
444 444
  end
445 445

  
446
  def gen_fileselect_dialog_generator(title, action, dir, config:, &result_callback)
446
  def gen_fileselect_dialog_generator(title, action, dir, config:, shortcuts: [], filters: {}, use_preview: false, &result_callback)
447 447
    ->(widget) do
448 448
      dialog = Gtk::FileChooserDialog.new(title,
449 449
                                          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

  
456
      filters.each do |name, exts|
457
        filter = Gtk::FileFilter.new
458
        filter.name = name
459
        exts.each do |ext|
460
          filter.add_pattern("*.#{ext}")
461
        end
462
        dialog.add_filter(filter)
463
      end
464

  
465
      shortcuts.select { |dir|
466
        !dialog.shortcut_folders.include?(dir)
467
      }.each { |dir|
468
        begin
469
          dialog.add_shortcut_folder(dir)
470
        rescue => e
471
          puts e
472
          puts e.backtrace
473
        end
474
      }
475

  
476
      if use_preview
477
        preview = Gtk::Image.new
478
        dialog.preview_widget = preview
479
        dialog.signal_connect("update-preview") do
480
          begin
481
            path = dialog.preview_filename
482
            pixbuf = Gdk::Pixbuf.new(file: path, width: 256, height: 256)
483
            preview.set_pixbuf(pixbuf)
484
            dialog.set_preview_widget_active(true)
485
          rescue => e
486
            dialog.set_preview_widget_active(false)
487
          end
488
        end
489
      end
490

  
455 491
      dialog.ssc_atonce(:response, &gen_fs_dialog_response_callback(config, &result_callback))
456 492
      dialog.show_all
457 493
      false
(2-2/2)