プロジェクト

全般

プロフィール

機能 #1195

完了

form DSLのfileselectでadd_shortcut_folderできる機能がほしい

cob odo さんがほぼ6年前に追加. ほぼ6年前に更新.

ステータス:
終了
優先度:
通常
担当者:
対象バージョン:
開始日:
2018-03-30
期日:
進捗率:

0%

プラグイン名:

説明

https://github.com/moguno/mikutter-uwm-hommage/blob/master/penguin.rb#L33 にあるようなことがDSLでできたら便利かなと思いました。

fileselect "ファイル", :filepath, shortcuts: [path1, path2]

のような感じで、オプション引数でディレクトリの一覧を取るようなイメージです。


ファイル

1195.patch (3.09 KB) 1195.patch cob odo, 2018-03-30 15:40
1195_2.patch (3.98 KB) 1195_2.patch cob odo, 2018-03-30 23:26

toshi_a 初音 さんがほぼ6年前に更新

  • 対象バージョン3.6 から 3.7 に変更

ショートカットのディレクトリってこんな感じで生やせるんですね。確かにバンドルプラグインでも、skinディレクトリをコレクションに入れておいたり出来ると便利そうです

cob odo さんがほぼ6年前に更新

↓のようなモンキーパッチで動きました(引数を追加してまわっただけ)

module Gtk::FormDSL
  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

  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

  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, shortcuts: shortcuts, &input.method(:text=)))
    container
  end

  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),
                                          action,
                                          nil,
                                          [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
    end
  end
end

書いてから思いましたが、uwm-hommageの https://github.com/moguno/mikutter-uwm-hommage/blob/master/penguin.rb#L33 周辺にあるfilterやpreview_widgetも欲しくなってきますね……

toshi_a 初音 さんがほぼ6年前に更新

パッチにしてほしいンゴですね

cob odo さんがほぼ6年前に更新

こういった感じです

cob odo さんがほぼ6年前に更新

全部入りパッチも作ってみました。

mikutter上のコンソールで試すコードは↓こんな感じです。

shortcuts = ['/home/cobodo/repos/mikutter/core/skin/data']
filters = {
  'png' => ['png', 'PNG'],
  'jpg' => ['jpg', 'JPG', 'jpeg', 'JPEG'],
  'gif' => ['gif', 'GIF'],
}
Plugin[:gui].dialog "fileselect test" do
  fileselect "画像", :image_path, shortcuts: shortcuts, filters: filters, use_preview: true
end
  • shortcuts: ショートカットディレクトリのstringのリスト。
  • filters: keyが表示名、valueが拡張子のリストになっているHash。
  • use_preview: trueでプレビュー表示。デフォルトはfalse。

filtersはちょっと複雑すぎる気もします。

プレビューのサイズは256x256固定にしてありますが、設定で制御できるといいのかもしれません。

toshi_a 初音 さんがほぼ6年前に更新

  • ステータス新規 から レビュー待ち に変更
  • 担当者cob odo にセット

topic/1195-fileselect-add-shortcuts-folder にpushしました。問題なければ develop にmergeしてください。

もらったパッチに次のような変更を加えています。

  • rdocを書いた
  • photoselectにも同様のオプションを提供
    • use_previewフラグがデフォルトでtrue
    • その環境でGdkPixbufが解釈できる全ての画像フォーマットをfiltersのデフォルト値に設定

cob odo さんがほぼ6年前に更新

  • ステータスレビュー待ち から 終了 に変更

ありがとうございました。問題なさそうでしたのでdevelopにmergeしました。
チケットは終了にしておきます。

他の形式にエクスポート: Atom PDF