Merge branch 'master' of github.com:github/atom

This commit is contained in:
Corey Johnson & Nathan Sobo 2012-04-27 10:25:45 -06:00
commit d737d97a81
6 changed files with 98 additions and 1 deletions

View File

@ -13,7 +13,7 @@ NSString *stringFromCefV8Value(const CefRefPtr<CefV8Value>& value) {
NativeHandler::NativeHandler() : CefV8Handler() {
m_object = CefV8Value::CreateObject(NULL);
const char *functionNames[] = {"exists", "read", "write", "absolute", "list", "isFile", "isDirectory", "remove", "asyncList", "open", "openDialog", "quit", "writeToPasteboard", "readFromPasteboard", "showDevTools", "newWindow", "saveDialog", "exit", "watchPath", "unwatchPath"};
const char *functionNames[] = {"exists", "read", "write", "absolute", "list", "isFile", "isDirectory", "remove", "asyncList", "open", "openDialog", "quit", "writeToPasteboard", "readFromPasteboard", "showDevTools", "newWindow", "saveDialog", "exit", "watchPath", "unwatchPath", "makeDirectory"};
NSUInteger arrayLength = sizeof(functionNames) / sizeof(const char *);
for (NSUInteger i = 0; i < arrayLength; i++) {
const char *functionName = functionNames[i];
@ -308,6 +308,18 @@ bool NativeHandler::Execute(const CefString& name,
return true;
}
else if (name == "makeDirectory") {
NSString *path = stringFromCefV8Value(arguments[0]);
NSFileManager *fm = [NSFileManager defaultManager];
NSError *error = nil;
[fm createDirectoryAtPath:path withIntermediateDirectories:NO attributes:nil error:&error];
if (error) {
exception = [[error localizedDescription] UTF8String];
}
return true;
}
return false;
};

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

@ -66,6 +66,9 @@ module.exports =
write: (path, content) ->
$native.write(path, content)
makeDirectory: (path) ->
$native.makeDirectory(path)
async:
list: (path) ->
deferred = $.Deferred()

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);
}