class UserConfig

UserConfig 動的な設定

プログラムから動的に変更される設定。 プラグインの設定ではないので注意。

Public Class Methods

[](key) click to toggle source

設定名 key にたいする値を取り出す 値が設定されていない場合、nilを返す。

# File core/userconfig.rb, line 132
def self.[](key)
  UserConfig.instance.at(key, @@defaults[key.to_sym])
end
[]=(key, val) click to toggle source

設定名 key に値 value を関連付ける

# File core/userconfig.rb, line 137
def self.[]=(key, val)
  watchers = synchronize{
    if not(@@watcher[key].empty?)
      before_val = UserConfig.instance.at(key, @@defaults[key.to_sym])
      @@watcher[key].map{ |id|
        proc = if @@watcher_id.has_key?(id)
                 @@watcher_id[id]
               else
                 @@watcher[key].delete(id)
                 nil end
        lambda{ proc.call(key, val, before_val, id) } if proc } end }
  if watchers.is_a? Enumerable
    watchers.each{ |w| w.call if w } end
  UserConfig.instance.store(key, val)
end
connect(key, &watcher) click to toggle source

設定名 key の値が変更されたときに、ブロック watcher を呼び出す。 watcher_idを返す。

# File core/userconfig.rb, line 155
def self.connect(key, &watcher)
  synchronize{
    id = @@watcher_id_count
    @@watcher_id_count += 1
    @@watcher[key] = @@watcher[key].push(id)
    @@watcher_id[id] = watcher
    id
  }
end
disconnect(id) click to toggle source

watcher idが id のwatcherを削除する。

# File core/userconfig.rb, line 166
def self.disconnect(id)
  synchronize{
    @@watcher_id.delete(id)
  }
end
key_add(key, name, slug) click to toggle source
# File core/userconfig.rb, line 182
def self.key_add(key, name, slug)
  type_strict key => String, name => String, slug => Symbol
  keys = UserConfig[:shortcutkey_keybinds].melt
  keys[(keys.keys.max || 0)+1] = {
    :key => key,
    :name => name,
    :slug => slug}
  UserConfig[:shortcutkey_keybinds] = keys end
setup() click to toggle source
# File core/userconfig.rb, line 172
def self.setup
  last_boot_version = UserConfig[:last_boot_version] || [0, 0, 0, 0]
  if last_boot_version < Environment::VERSION.to_a
    UserConfig[:last_boot_version] = Environment::VERSION.to_a
    if last_boot_version == [0, 0, 0, 0]
      key_add "Alt + x", "コンソールを開く", :console_open
    end
  end
end