class Plugin::IntentSelector::IntentSelectorListView

Constants

COLUMN_INTENT
COLUMN_INTENT_LABEL
COLUMN_MODEL
COLUMN_MODEL_LABEL
COLUMN_STRING
COLUMN_UUID

Public Class Methods

new() click to toggle source
Calls superclass method Gtk::CRUD.new
# File core/plugin/intent_selector/listview.rb, line 11
def initialize
  super
  intents = intent_catalog
  models = model_catalog
  UserConfig[:intent_selector_rules].each do |record|
    iter = model.model.append
    iter[COLUMN_INTENT] = record[:intent]
    iter[COLUMN_INTENT_LABEL] = intents[record[:intent].to_sym]
    iter[COLUMN_MODEL] = record[:model]
    iter[COLUMN_MODEL_LABEL] = models[record[:model].to_s]
    iter[COLUMN_STRING] = record[:str]
    iter[COLUMN_UUID] = record[:uuid]
  end
end

Public Instance Methods

column_schemer() click to toggle source
# File core/plugin/intent_selector/listview.rb, line 35
def column_schemer
  [{kind: :text, type: Symbol, expand: true, label: _('開く方法')},
   {kind: :text, type: String, expand: true, label: _('対象')},
   {kind: :text, type: String, widget: :input, expand: true, label: _('条件')},
   {type: Symbol, widget: :chooseone, args: [intent_catalog], label: _('開く方法')},
   {type: String, widget: :chooseone, args: [model_catalog], label: _('対象')},
   {type: String},
  ].freeze
end
filter_entry() click to toggle source
# File core/plugin/intent_selector/listview.rb, line 79
def filter_entry
  @filter_entry ||= Gtk::Entry.new.tap do |entry|
    entry.primary_icon_pixbuf = Skin['search.png'].pixbuf(width: 24, height: 24)
    entry.ssc(:changed, self, &gen_refilter)
  end
end
initialize_model() click to toggle source
# File core/plugin/intent_selector/listview.rb, line 26
def initialize_model
  set_model(Gtk::TreeModelFilter.new(Gtk::ListStore.new(*column_schemer.flatten.map{|x| x[:type]})))
  model.set_visible_func{ |model, iter|
    if defined?(@filter_entry) and @filter_entry
      [COLUMN_INTENT, COLUMN_INTENT_LABEL, COLUMN_MODEL, COLUMN_MODEL_LABEL, COLUMN_STRING].any?{ |column| iter[column].to_s.include?(@filter_entry.text) }
    else
      true end }
end
on_created(iter) click to toggle source
# File core/plugin/intent_selector/listview.rb, line 45
def on_created(iter)
  iter[COLUMN_UUID] = SecureRandom.uuid
  iter[COLUMN_INTENT_LABEL] = intent_catalog[iter[COLUMN_INTENT].to_sym]
  iter[COLUMN_MODEL_LABEL] = model_catalog[iter[COLUMN_MODEL].to_s]
  UserConfig[:intent_selector_rules] += [{
    intent: iter[COLUMN_INTENT].to_sym,
    model: iter[COLUMN_MODEL],
    str: iter[COLUMN_STRING],
    rule: 'start',
    uuid: iter[COLUMN_UUID]
  }]
end
on_deleted(iter) click to toggle source
# File core/plugin/intent_selector/listview.rb, line 73
def on_deleted(iter)
  UserConfig[:intent_selector_rules] = UserConfig[:intent_selector_rules].reject do |record|
    record[:uuid] == iter[COLUMN_UUID]
  end
end
on_updated(iter) click to toggle source
# File core/plugin/intent_selector/listview.rb, line 58
def on_updated(iter)
  iter[COLUMN_INTENT_LABEL] = intent_catalog[iter[COLUMN_INTENT].to_sym]
  iter[COLUMN_MODEL_LABEL] = model_catalog[iter[COLUMN_MODEL].to_s]
  UserConfig[:intent_selector_rules] = UserConfig[:intent_selector_rules].map do |record|
    if record[:uuid] == iter[COLUMN_UUID]
      record.merge(
        intent: iter[COLUMN_INTENT].to_sym,
        model: iter[COLUMN_MODEL],
        str: iter[COLUMN_STRING])
    else
      record
    end
  end
end