Pressing 'm' in tree view brings up a move dialog

This commit is contained in:
Corey Johnson
2012-04-26 17:12:56 -07:00
parent fbcd8e43a0
commit 0a39ca25a9
4 changed files with 82 additions and 0 deletions

View File

@@ -276,6 +276,51 @@ describe "TreeView", ->
rootDirectoryView.trigger 'tree-view:open-selected-entry'
expect(rootView.activeEditor()).toBeUndefined()
describe "file modification", ->
[fileElement, rootDirPath, dirPath, filePath] = []
beforeEach ->
treeView.deactivate()
rootDirPath = "/tmp/atom-tests"
dirPath = fs.join(rootDirPath, "test-dir")
filePath = fs.join(dirPath, "test-file.txt")
fs.makeDirectory(rootDirPath)
fs.makeDirectory(dirPath)
fs.write(filePath, "doesn't matter")
rootView = new RootView(pathToOpen: rootDirPath)
project = rootView.project
treeView = new TreeView(rootView)
dirView = treeView.root.entries.find('.directory:contains(test-dir)').view()
dirView.expand()
fileElement = treeView.find('.file:contains(test-file.txt)')
afterEach ->
fs.remove(rootDirPath)
describe "tree-view:move", ->
describe "when a file is selected", ->
moveDialog = null
beforeEach ->
fileElement.click()
treeView.trigger "tree-view:move"
moveDialog = treeView.find(".move-dialog").view()
it "opens a move dialog with the file's current path populated", ->
expect(moveDialog).toExist()
expect(moveDialog.editor.getText()).toBe(project.relativize(filePath))
expect(moveDialog.editor.getSelectedText()).toBe fs.base(filePath)
expect(moveDialog.editor.isFocused).toBeTruthy()
describe "when the move dialog's editor loses focus", ->
it "removes the dialog", ->
treeView.attachToDom()
treeView.focus()
expect(moveDialog.parent()).not.toExist()
describe "file system events", ->
temporaryFilePath = null

View File

@@ -2,4 +2,5 @@ window.keymap.bindKeys '.tree-view'
'right': 'tree-view:expand-directory'
'left': 'tree-view:collapse-directory'
'enter': 'tree-view:open-selected-entry'
'm': 'tree-view:move'

View File

@@ -25,6 +25,7 @@ class TreeView extends View
@on 'tree-view:expand-directory', => @expandDirectory()
@on 'tree-view:collapse-directory', => @collapseDirectory()
@on 'tree-view:open-selected-entry', => @openSelectedEntry()
@on 'tree-view:move', => @move()
@rootView.on 'active-editor-path-change', => @selectActiveFile()
deactivate: ->
@@ -70,6 +71,15 @@ class TreeView extends View
else if selectedEntry.is('.file')
@rootView.open(selectedEntry.attr('path'))
move: ->
entry = @selectedEntry()
dialog = new MoveDialog(@rootView.project, entry.attr('path'))
@append dialog
dialog.css
top: entry.position().top + entry.outerHeight() + @scrollTop()
left: 0
selectedEntry: ->
@find('.selected')
@@ -144,3 +154,20 @@ class DirectoryView extends View
view = $(this).view()
view.entryStates = childEntryStates
view.expand()
Editor = require 'editor'
fs = require 'fs'
class MoveDialog extends View
@content: ->
@div class: 'move-dialog', =>
@subview 'editor', new Editor(mini: true)
initialize: (@project, path) ->
@editor.focus()
@editor.on 'focusout', => @remove()
relativePath = @project.relativize(path)
@editor.setText(relativePath)
baseName = fs.base(path)
range = [[0, relativePath.length - baseName.length], [0, relativePath.length]]
@editor.setSelectionBufferRange(range)

View File

@@ -1,4 +1,5 @@
.tree-view {
position: relative;
height: 100%;
background: black;
color: white;
@@ -34,3 +35,11 @@
color: black;
}
.move-dialog {
position: absolute;
width: 100%;
background-color: #444;
border: 2px solid #222;
-webkit-box-shadow: 0 0 3px 3px rgba(0, 0, 0, .5);
}