From 130361fc1c52c7d41cd85a3f33814edebd82eee3 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Thu, 31 May 2012 15:54:40 -0700 Subject: [PATCH] Keybinding view is an extension --- src/app/keymaps/atom.coffee | 3 +- src/app/keymaps/keybindings-view.coffee | 5 +++ src/app/root-view.coffee | 18 ----------- src/extensions/keybindings-view/index.coffee | 1 + .../keybindings-view/keybindings-view.coffee | 31 +++++++++++++++++++ static/atom.css | 22 +------------ static/keybinding-view.css | 18 +++++++++++ 7 files changed, 57 insertions(+), 41 deletions(-) create mode 100644 src/app/keymaps/keybindings-view.coffee create mode 100644 src/extensions/keybindings-view/index.coffee create mode 100644 src/extensions/keybindings-view/keybindings-view.coffee create mode 100644 static/keybinding-view.css diff --git a/src/app/keymaps/atom.coffee b/src/app/keymaps/atom.coffee index 028588691..ea88bbb3a 100644 --- a/src/app/keymaps/atom.coffee +++ b/src/app/keymaps/atom.coffee @@ -4,5 +4,4 @@ window.keymap.bindKeys '*' right: 'move-right' left: 'move-left' down: 'move-down' - up: 'move-up' - 'ctrl-?': 'toggle-keybindings-view' \ No newline at end of file + up: 'move-up' \ No newline at end of file diff --git a/src/app/keymaps/keybindings-view.coffee b/src/app/keymaps/keybindings-view.coffee new file mode 100644 index 000000000..99c2344cd --- /dev/null +++ b/src/app/keymaps/keybindings-view.coffee @@ -0,0 +1,5 @@ +window.keymap.bindKeys '*', + 'ctrl-?': 'keybindings-view:attach' + +window.keymap.bindKeys ".keybindings-view", + 'escape': 'keybindings-view:detach' \ No newline at end of file diff --git a/src/app/root-view.coffee b/src/app/root-view.coffee index e3362d7b1..34aaa5113 100644 --- a/src/app/root-view.coffee +++ b/src/app/root-view.coffee @@ -29,7 +29,6 @@ class RootView extends View extensions: null extensionStates: null fontSize: 18 - keybindingsView: null initialize: (pathToOpen) -> @extensions = {} @@ -60,7 +59,6 @@ class RootView extends View @on 'increase-font-size', => @setFontSize(@getFontSize() + 1) @on 'decrease-font-size', => @setFontSize(@getFontSize() - 1) - @on 'toggle-keybindings-view', => @toggleKeybindingsView() afterAttach: (onDom) -> @focus() if onDom @@ -116,22 +114,6 @@ class RootView extends View if not previousActiveEditor or editor.buffer.path != previousActiveEditor.buffer.path @trigger 'active-editor-path-change', editor.buffer.path - toggleKeybindingsView: -> - if @keybindingsView? - @keybindingsView.remove() - @keybindingsView = null - else - keybindings = @activeKeybindings() - @keybindingsView = $$ -> - @div class: 'keybindings-view', => - @ul => - for keystroke, command of keybindings - @li => - @span class: 'keystroke', "#{keystroke}" - @span "#{command}" - - @append(@keybindingsView) - activeKeybindings: -> keymap.bindingsForElement(document.activeElement) diff --git a/src/extensions/keybindings-view/index.coffee b/src/extensions/keybindings-view/index.coffee new file mode 100644 index 000000000..d1bc7b87c --- /dev/null +++ b/src/extensions/keybindings-view/index.coffee @@ -0,0 +1 @@ +module.exports = require 'keybindings-view/keybindings-view' \ No newline at end of file diff --git a/src/extensions/keybindings-view/keybindings-view.coffee b/src/extensions/keybindings-view/keybindings-view.coffee new file mode 100644 index 000000000..e2a641369 --- /dev/null +++ b/src/extensions/keybindings-view/keybindings-view.coffee @@ -0,0 +1,31 @@ +{View, $$} = require 'space-pen' + +module.exports = +class KeybindingsView extends View + @activate: (rootView, state) -> + requireStylesheet 'keybinding-view.css' + @instance = new this(rootView) + + @content: (rootView) -> + @div class: 'keybindings-view', tabindex: -1, => + @ul outlet: 'keybindingList' + + initialize: (@rootView) -> + @rootView.on 'keybindings-view:attach', => @attach() + @on 'keybindings-view:detach', => @detach() + + attach: -> + @keybindingList.empty() + @keybindingList.append $$ -> + for keystroke, command of rootView.activeKeybindings() + @li => + @span class: 'keystroke', "#{keystroke}" + @span ":" + @span "#{command}" + + @rootView.append(this) + @focus() + + detach: -> + super() + @rootView.focus() diff --git a/static/atom.css b/static/atom.css index e774c3fc5..dd65fe811 100644 --- a/static/atom.css +++ b/static/atom.css @@ -61,24 +61,4 @@ body { .error { background: #991212; -webkit-transition: background 200ms ease-out; -} - -.keybindings-view { - position: absolute; - width: 100%; - height: 100%; - top: 0px; - left: 0px; - background-color: white; - overflow: scroll; - opacity: 0.9; -} - -.keybindings-view li .keystroke { - font-weight: bold; - float: left; - text-align: right; - padding-right: 10px; - width: 100px; -} - +} \ No newline at end of file diff --git a/static/keybinding-view.css b/static/keybinding-view.css new file mode 100644 index 000000000..9e3312e02 --- /dev/null +++ b/static/keybinding-view.css @@ -0,0 +1,18 @@ +.keybindings-view { + position: absolute; + width: 100%; + height: 100%; + top: 0px; + left: 0px; + background-color: white; + overflow: scroll; + opacity: 0.9; +} + +.keybindings-view li .keystroke { + font-weight: bold; + float: left; + text-align: right; + padding-right: 10px; + width: 200px; +}