aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authortoshi <toshi@03aab468-d3d2-4883-8b12-f661bbf03fa8>2012-09-14 17:17:19 +0000
committertoshi <toshi@03aab468-d3d2-4883-8b12-f661bbf03fa8>2012-09-14 17:17:19 +0000
commitdce91066d5f544fcf81fc8649ce227ac4da78f67 (patch)
tree1721ccf46b5ac8ceb1eadf034b508323e8e8572b /core
parent9acdb9a8e4b64c9a0e9ee7c341abd1c3496dfee1 (diff)
downloadmikutter-dce91066d5f544fcf81fc8649ce227ac4da78f67.tar.gz
投稿ボックスにフォーカスを移動するコマンド
git-svn-id: svn://toshia.dip.jp/mikutter/trunk@975 03aab468-d3d2-4883-8b12-f661bbf03fa8
Diffstat (limited to 'core')
-rw-r--r--core/plugin/command/command.rb26
-rw-r--r--core/plugin/gui/hierarchy_child.rb22
-rw-r--r--core/plugin/gui/pane.rb2
-rw-r--r--core/plugin/gui/timeline.rb5
-rw-r--r--core/plugin/gui/window.rb2
-rw-r--r--core/plugin/shortcutkey/shortcutkey.rb2
6 files changed, 53 insertions, 6 deletions
diff --git a/core/plugin/command/command.rb b/core/plugin/command/command.rb
index 74ca8e19..4df272d2 100644
--- a/core/plugin/command/command.rb
+++ b/core/plugin/command/command.rb
@@ -185,6 +185,19 @@ Plugin.create :command do
focus_move_widget(opt.widget, 1)
end
+ command(:focus_to_postbox,
+ name: '投稿ボックスにフォーカス',
+ condition: lambda{ |opt| not opt.widget.is_a? Plugin::GUI::Postbox },
+ visible: false,
+ role: :window) do |opt|
+ focus_move_to_nearest_postbox(opt.widget.active_chain.last)
+ end
+
+
+ # フォーカスを _widget_ から _distance_ に移動する
+ # ==== Args
+ # [widget] 起点となるウィジェット
+ # [distance] 移動距離
def focus_move_widget(widget, distance)
type_strict widget => Plugin::GUI::HierarchyParent
type_strict widget => Plugin::GUI::HierarchyChild
@@ -201,4 +214,17 @@ Plugin.create :command do
end
end
+ # 一番近い postbox にフォーカスを与える
+ # ==== Args
+ # [widget] 基準となるウィジェット
+ def focus_move_to_nearest_postbox(widget)
+ notice "called: given widget #{widget.inspect}"
+ if widget.is_a? Plugin::GUI::HierarchyParent
+ postbox = widget.children.find{ |w| w.is_a? Plugin::GUI::Postbox }
+ notice "found postbox: #{postbox.inspect}"
+ if postbox
+ return postbox.active! end end
+ if widget.is_a? Plugin::GUI::HierarchyChild
+ focus_move_to_nearest_postbox(widget.parent) end end
+
end
diff --git a/core/plugin/gui/hierarchy_child.rb b/core/plugin/gui/hierarchy_child.rb
index 661af695..ece0c607 100644
--- a/core/plugin/gui/hierarchy_child.rb
+++ b/core/plugin/gui/hierarchy_child.rb
@@ -28,6 +28,28 @@ module Plugin::GUI::HierarchyChild
def active_class_of(klass)
self if is_a? klass end
+ # 先祖のうち、 _klass_ と is_a? 関係にあるものを返す
+ # ==== Args
+ # [klass] 探すクラス
+ # ==== Return
+ # マッチしたウィジェットかfalse
+ def ancestor_of(klass)
+ if self.is_a? klass
+ self
+ elsif @parent.is_a? Plugin::GUI::HierarchyChild
+ @parent.ancestor_of(klass)
+ else @parent.is_a? klass
+ @parent end end
+
+ # 親を再帰的に辿り、selfをアクティブに設定する
+ # ==== Args
+ # [just_this] 再帰的に呼び出されたのではなく、直接これをアクティブに指定されたなら真
+ # ==== Return
+ # self
+ def active!(just_this=true)
+ @parent.set_active_child(self).active!(false)
+ self end
+
module Extended
attr_reader :parent_class
diff --git a/core/plugin/gui/pane.rb b/core/plugin/gui/pane.rb
index 483333e8..4b5667a4 100644
--- a/core/plugin/gui/pane.rb
+++ b/core/plugin/gui/pane.rb
@@ -25,7 +25,7 @@ class Plugin::GUI::Pane
Plugin.call(:pane_created, self)
end
- def active!
+ def active!(just_this=true)
@@default = self
super end
diff --git a/core/plugin/gui/timeline.rb b/core/plugin/gui/timeline.rb
index 47cb3a7c..748f9a79 100644
--- a/core/plugin/gui/timeline.rb
+++ b/core/plugin/gui/timeline.rb
@@ -33,9 +33,8 @@ class Plugin::GUI::Timeline
# このタイムラインをアクティブにする。また、子のPostboxは非アクティブにする
# ==== Return
# self
- def active!
- @active_child = false
- set_active_child(nil)
+ def active!(just_this=true)
+ set_active_child(nil) if just_this
super end
# 選択されているMessageを返す
diff --git a/core/plugin/gui/window.rb b/core/plugin/gui/window.rb
index 016f0542..a0fd561f 100644
--- a/core/plugin/gui/window.rb
+++ b/core/plugin/gui/window.rb
@@ -23,7 +23,7 @@ class Plugin::GUI::Window
end
# self がアクティブになったことを報告する
- def active!
+ def active!(just_this=true)
@@active = self
end
diff --git a/core/plugin/shortcutkey/shortcutkey.rb b/core/plugin/shortcutkey/shortcutkey.rb
index 771c9f53..af2a0a61 100644
--- a/core/plugin/shortcutkey/shortcutkey.rb
+++ b/core/plugin/shortcutkey/shortcutkey.rb
@@ -81,7 +81,7 @@ Plugin.create :shortcutkey do
if behavior[:key] == key
cmd = commands[behavior[:slug]]
if cmd and widget.class.find_role_ancestor(cmd[:role])
- if cmd[:condition] === event
+ if (:timeline == cmd[:role] ? !event.messages.empty? : true) and cmd[:condition] === event
notice "command executed :#{behavior[:slug]}"
executed = true
cmd[:exec].call(event) end end end }