This repository was archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 361
Expand file tree
/
Copy pathdialog.coffee
More file actions
50 lines (43 loc) · 1.61 KB
/
dialog.coffee
File metadata and controls
50 lines (43 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
{$, TextEditorView, View} = require 'atom-space-pen-views'
path = require 'path'
module.exports =
class Dialog extends View
@content: ({prompt} = {}) ->
textEditorView = new TextEditorView(mini: true)
textEditorView.getModel().setSoftWrapped(false)
@div class: 'tree-view-dialog', =>
@label prompt, class: 'icon', outlet: 'promptText'
@subview 'miniEditor', textEditorView
@div class: 'error-message', outlet: 'errorMessage'
initialize: ({initialPath, select, iconClass} = {}) ->
@promptText.addClass(iconClass) if iconClass
atom.commands.add @element,
'core:confirm': => @onConfirm(@miniEditor.getText())
'core:cancel': => @cancel()
@miniEditor.on 'blur', => @close()
@miniEditor.getModel().onDidChange => @showError()
@miniEditor.getModel().setText(initialPath)
if select
extension = path.extname(initialPath)
baseName = path.basename(initialPath)
if baseName is extension
selectionEnd = initialPath.length
else
selectionEnd = initialPath.length - extension.length
range = [[0, initialPath.length - baseName.length], [0, selectionEnd]]
@miniEditor.getModel().setSelectedBufferRange(range)
attach: ->
@panel = atom.workspace.addModalPanel(item: this.element)
@miniEditor.focus()
@miniEditor.getModel().scrollToCursorPosition()
close: ->
panelToDestroy = @panel
@panel = null
panelToDestroy?.destroy()
atom.workspace.getActivePane().activate()
cancel: ->
@close()
$('.tree-view').focus()
showError: (message='') ->
@errorMessage.text(message)
@flashError() if message