File: edit_window.rb

package info (click to toggle)
mikutter 5.1.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,780 kB
  • sloc: ruby: 22,912; sh: 186; makefile: 21
file content (135 lines) | stat: -rw-r--r-- 3,480 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# -*- coding: utf-8 -*-

require 'mui/gtk_hierarchycal_selectbox'

require_relative 'option_widget'
require_relative 'datasource_select_box'

require 'observer'

module Plugin::ExtractGtk
end

class Plugin::ExtractGtk::EditWindow < Gtk::Window
  attr_reader :extract

  # ==== Args
  # [extract] 抽出タブ設定 (Plugin::Extract::Setting)
  # [plugin] プラグインのインスタンス (Plugin)
  def initialize(extract, plugin)
    @plugin = plugin
    @extract = extract
    super(_('%{name} - 抽出タブ - %{application_name}') % { name:, application_name: Environment::NAME })

    notebook = Gtk::Notebook.new
    notebook.expand = true
    notebook.append_page(source_widget, Gtk::Label.new(_('データソース')))
    notebook.append_page(condition_widget, Gtk::Label.new(_('絞り込み条件')))
    notebook.append_page(option_widget, Gtk::Label.new(_('オプション')))
    add(Gtk::Grid.new
        .tap { |grid| grid.orientation = :vertical }
        .add(notebook)
        .add(ok_button.tap { |w| w.halign = :end }))
    ssc(:destroy) do
      @extract.notify_update
      false
    end
    set_size_request 480, 320
    show_all
  end

  def name
    @extract.name
  end

  def sexp
    @extract.sexp
  end

  def id
    @extract.id
  end

  def sources
    @extract.sources
  end

  def slug
    @extract.slug
  end

  def sound
    @extract.sound
  end

  def popup
    @extract.popup
  end

  def order
    @extract.order
  end

  def icon
    @extract.icon
  end

  def source_widget
    datasources_box = Plugin::ExtractGtk::DatasourceSelectBox.new(sources) do
      modify_value(sources: datasources_box.selected.to_a)
    end
    @source_widget ||= Gtk::ScrolledWindow.new.add datasources_box
  end

  def condition_widget
    @condition_widget ||= Gtk::MessagePicker.new(sexp.freeze) {
      modify_value sexp: @condition_widget.to_a
    }.tap { |w| w.expand = true }
  end

  def option_widget
    Plugin::ExtractGtk::OptionWidget.new(@plugin, @extract) do
      input _('名前'), :name
      shortcuts = [Skin.default_dir]
      Skin.user_dir and shortcuts << Skin.user_dir
      photoselect(_('アイコン'), :icon, dir: Skin.path, shortcuts:)
      settings _('通知') do
        fileselect _('サウンド'), :sound,
                   dir: File.join(Skin.default_dir, 'sounds'),
                   shortcuts: [File.join(Skin.default_dir, 'sounds')],
                   filters: { _('非圧縮音声ファイル (*.wav, *.aiff)') => ['wav', 'WAV', 'aiff', 'AIFF'],
                              _('FLAC (*.flac, *.fla)') => ['flac', 'FLAC', 'fla', 'FLA'],
                              _('MPEG-1/2 Audio Layer-3 (*.mp3)') => ['mp3', 'MP3'],
                              _('Ogg (*.ogg)') => ['ogg', 'OGG'],
                              _('全てのファイル') => ['*'] }
        boolean _('ポップアップ'), :popup, switch: true
      end
      select(_('並び順'), :order, Plugin.collect(:extract_order).to_h { |o| [o.slug.to_s, o.name] })
    end
  end

  def ok_button
    Gtk::Button.new(label: _('閉じる')).tap do |button|
      button.ssc(:clicked) do
        destroy
      end
    end
  end

  def refresh_title
    set_title _('%{name} - 抽出タブ - %{application_name}') % { name:, application_name: Environment::NAME }
  end

  private

  def modify_value(new_values)
    @extract.merge(new_values)
    refresh_title
    @extract.notify_update
    self
  end

  def _(message)
    @plugin._(message)
  end
end