working title

This commit is contained in:
Loic Nageleisen 2015-02-19 18:11:25 +01:00
parent ffbe36efec
commit 1a8657b3d4
13 changed files with 234 additions and 77 deletions

View file

@ -0,0 +1,58 @@
{View, TextEditorView} = require 'atom'
module.exports =
class ExCommandModeInputView extends View
@content: ->
@div class: 'command-mode-input', =>
@div class: 'editor-container', outlet: 'editorContainer', =>
@subview 'editor', new TextEditorView(mini: true)
initialize: (@viewModel, opts = {})->
if opts.class?
@editorContainer.addClass opts.class
if opts.hidden
@editorContainer.addClass 'hidden-input'
@singleChar = opts.singleChar
@defaultText = opts.defaultText ? ''
@panel = atom.workspace.addBottomPanel(item: this, priority: 100)
@focus()
@handleEvents()
handleEvents: ->
if @singleChar?
@editor.find('input').on 'textInput', @autosubmit
@editor.on 'core:confirm', @confirm
@editor.on 'core:cancel', @cancel
@editor.find('input').on 'blur', @cancel
stopHandlingEvents: ->
if @singleChar?
@editor.find('input').off 'textInput', @autosubmit
@editor.off 'core:confirm', @confirm
@editor.off 'core:cancel', @cancel
@editor.find('input').off 'blur', @cancel
autosubmit: (event) =>
@editor.setText(event.originalEvent.data)
@confirm()
confirm: =>
@value = @editor.getText() or @defaultText
@viewModel.confirm(@)
@remove()
focus: =>
@editorContainer.find('.editor').focus()
cancel: (e) =>
@viewModel.cancel(@)
@remove()
remove: =>
@stopHandlingEvents()
atom.workspace.getActivePane().activate()
@panel.destroy()