aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorToshiaki Asai <toshi.alternative@gmail.com>2016-10-20 12:38:13 +0900
committerToshiaki Asai <toshi.alternative@gmail.com>2016-10-20 12:38:13 +0900
commit1bac7e548cb46d4c4b267c7a5736bf5b34852f3d (patch)
treecccc39efd8c9f41fda59a231a72b1b9719149fe8
parentba09a362083ddb8628480f521ad2642c310eee6a (diff)
downloadmikutter-1bac7e548cb46d4c4b267c7a5736bf5b34852f3d.tar.gz
intent_token: 設定画面から関連付け情報を編集 refs #905
-rw-r--r--core/plugin/intent/intent.rb8
-rw-r--r--core/plugin/intent_selector/intent_selector.rb13
-rw-r--r--core/plugin/intent_selector/listview.rb108
3 files changed, 128 insertions, 1 deletions
diff --git a/core/plugin/intent/intent.rb b/core/plugin/intent/intent.rb
index 862a1a84..12cc69fc 100644
--- a/core/plugin/intent/intent.rb
+++ b/core/plugin/intent/intent.rb
@@ -3,6 +3,10 @@ require_relative 'model/intent'
require_relative 'model/intent_token'
Plugin.create(:intent) do
+ # 全てのIntentを列挙するためのフィルタ
+ defevent :intent_catalog,
+ prototype: [:<<]
+
# _uri_ を開くことができる Model を列挙するためのフィルタ
defevent :model_of_uri,
prototype: [URI, :<<]
@@ -40,6 +44,10 @@ Plugin.create(:intent) do
end
[target_model_slug, intents]
end
+ filter_intent_all do |intents|
+ intents << my_intent
+ [intents]
+ end
add_event(:"intent_open_#{slug}", &proc)
self
end
diff --git a/core/plugin/intent_selector/intent_selector.rb b/core/plugin/intent_selector/intent_selector.rb
index ffb5a8d6..3cc0e45f 100644
--- a/core/plugin/intent_selector/intent_selector.rb
+++ b/core/plugin/intent_selector/intent_selector.rb
@@ -1,7 +1,9 @@
# -*- coding: utf-8 -*-
+require_relative 'listview'
Plugin.create(:intent_selector) do
UserConfig[:intent_selector_rules] ||= []
+
on_intent_select do |intents, model|
case model
when Retriever::Model
@@ -13,6 +15,15 @@ Plugin.create(:intent_selector) do
end
end
+ settings(_('関連付け')) do
+ listview = Plugin::IntentSelector::IntentSelectorListView.new
+ pack_start(Gtk::VBox.new(false, 4).
+ closeup(listview.filter_entry).
+ add(Gtk::HBox.new(false, 4).
+ add(listview).
+ closeup(listview.buttons(Gtk::VBox))))
+ end
+
# _model:_ または _uri:_ を開くintentを _intents_ の中から選び出し、その方法で開く。
# このメソッドは、まず設定されたルールでintentを選出し、一つにintentが定まれば直ちにそれで開く。
# 候補が一つに絞れなかった場合は、intent選択ダイアログを表示して、ユーザに決定を仰ぐ。
@@ -97,7 +108,7 @@ Plugin.create(:intent_selector) do
def add_intent_rule(intent:, str:, rule:, model_slug:)
unless UserConfig[:intent_selector_rules].any?{|r| r[:intent].to_sym == intent.slug && r[:str] == str && r[:rule] == rule }
- UserConfig[:intent_selector_rules] += [{intent: intent.slug, model: model_slug, str: str, rule: rule}]
+ UserConfig[:intent_selector_rules] += [{uuid: SecureRandom.uuid, intent: intent.slug, model: model_slug, str: str, rule: rule}]
end
end
diff --git a/core/plugin/intent_selector/listview.rb b/core/plugin/intent_selector/listview.rb
new file mode 100644
index 00000000..ae37ba52
--- /dev/null
+++ b/core/plugin/intent_selector/listview.rb
@@ -0,0 +1,108 @@
+# -*- coding: utf-8 -*-
+
+module Plugin::IntentSelector
+ class IntentSelectorListView < ::Gtk::CRUD
+ COLUMN_INTENT_LABEL = 0
+ COLUMN_MODEL_LABEL = 1
+ COLUMN_STRING = 2
+ COLUMN_INTENT = 3
+ COLUMN_MODEL = 4
+ COLUMN_UUID = 5
+
+ 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
+
+ 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
+
+ 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
+
+ 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
+
+ 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
+
+ def on_deleted(iter)
+ UserConfig[:intent_selector_rules] = UserConfig[:intent_selector_rules].reject do |record|
+ record[:uuid] == iter[COLUMN_UUID]
+ end
+ end
+
+ private
+
+ def filter_entry
+ @filter_entry ||= Gtk::Entry.new.tap do |entry|
+ entry.primary_icon_pixbuf = Gdk::WebImageLoader.pixbuf(MUI::Skin.get("search.png"), 24, 24)
+ entry.ssc(:changed, self, &gen_refilter)
+ end
+ end
+
+ def gen_refilter
+ proc do
+ model.refilter
+ end
+ end
+
+ def _(str)
+ Plugin[:intent_selector]._(str)
+ end
+
+ def intent_catalog
+ Hash[Plugin.filtering(:intent_all, []).first.map{|i|[i.slug, i.label]}]
+ end
+
+ def model_catalog
+ Hash[Plugin.filtering(:retrievers, []).first.map{|s|[s[:slug].to_s,s[:name]]}].merge('': _('(未定義)'))
+ end
+
+ end
+end