Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ The `.remote-sync.json` in your project root will use these options:
| `ignore` | Array | [".remote-sync.json",".git/**"] | Array of [minimatch](https://github.com/isaacs/minimatch) patterns of files to ignore |
| `watch` | Array | [] | Array of files (relative to project root - starting with "/") to watch for changes |
| `uploadMirrors` | Array | [] | Transport mirror config array when upload |
| `uploadOnSave` | Boolean | false | Whether or not to upload the current file when saved |
| `uploadOnSave` | Boolean | false | Whether or not to upload the current file when saved (also syncs deletes and renames done in TreeView) |
| `saveOnUpload` | Boolean | false | Whether or not to save a modified file before uploading |
| `useAtomicWrites` | Boolean | false | Upload file using a temporary filename before moving to its final location (only used for SCP) |
| `deleteLocal` | Boolean | false | Whether or not to delete the local file / folder after remote delete |
Expand Down
99 changes: 75 additions & 24 deletions index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -114,30 +114,81 @@ module.exports =
initProject(projectPaths)

disposables.add atom.workspace.observeTextEditors (editor) ->
onDidSave = editor.onDidSave (e) ->
fullPath = e.path
[projectPath, relativePath] = atom.project.relativizePath(fullPath)
return unless projectPath

projectPath = fs.realpathSync(projectPath)
projectObj = projectDict[projectPath]
return unless projectObj

if fs.realpathSync(fullPath) == fs.realpathSync(projectObj.configPath)
projectObj = reload(projectPath)

return unless projectObj.host.uploadOnSave
projectObj.uploadFile(fs.realpathSync(fullPath))


onDidDestroy = editor.onDidDestroy ->
disposables.remove onDidSave
disposables.remove onDidDestroy
onDidDestroy.dispose()
onDidSave.dispose()

disposables.add onDidSave
disposables.add onDidDestroy
atom.packages.activatePackage('tree-view').then ((pkg) ->
treeView = pkg.mainModule.treeView
onDidSave = editor.onDidSave (e) ->
fullPath = e.path
[projectPath, relativePath] = atom.project.relativizePath(fullPath)
return unless projectPath

projectPath = fs.realpathSync(projectPath)
projectObj = projectDict[projectPath]
return unless projectObj

if fs.realpathSync(fullPath) == fs.realpathSync(projectObj.configPath)
projectObj = reload(projectPath)

return unless projectObj.host.uploadOnSave
projectObj.uploadFile(fs.realpathSync(fullPath))

onDidDelete = treeView.onEntryDeleted (e) ->
fullPath = e.path
[projectPath, relativePath] = atom.project.relativizePath(fullPath)

return unless projectPath

projectPath = fs.realpathSync(projectPath)
projectObj = projectDict[projectPath]
return unless projectObj

# if fs.realpathSync(fullPath) == fs.realpathSync(projectObj.configPath)
# projectObj = reload(projectPath)

return unless projectObj.host.uploadOnSave
remotePath = projectObj.host.target + relativePath
projectObj.deleteFile(fullPath)
return

onDidRename = treeView.onEntryMoved (e) ->
initialPath = e.initialPath
newPath = e.newPath
[projectPath, relativePath] = atom.project.relativizePath(newPath)
console.log newPath, projectPath, relativePath
return unless projectPath

projectPath = fs.realpathSync(projectPath)
projectObj = projectDict[projectPath]
return unless projectObj

# if fs.realpathSync(fullPath) == fs.realpathSync(projectObj.configPath)
# projectObj = reload(projectPath)

return unless projectObj.host.uploadOnSave
remotePath = projectObj.host.target + relativePath

# rename the lazy way by deleting and re-uploading
projectObj.uploadFile(fs.realpathSync(newPath))
projectObj.deleteFile(initialPath)
return

onDidDestroy = editor.onDidDestroy ->
disposables.remove onDidSave
disposables.remove onDidDelete
disposables.remove onDidRename
disposables.remove onDidDestroy

onDidSave.dispose()
onDidDelete.dispose()
onDidRename.dispose()
onDidDestroy.dispose()

disposables.add onDidSave
disposables.add onDidDelete
disposables.add onDidRename
disposables.add onDidDestroy
), (reason) ->
atom.notifications.addWarning 'The tree-view package is not loaded.', description: reason.message
return

deactivate: ->
disposables.dispose()
Expand Down
2 changes: 1 addition & 1 deletion lib/view/host-view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ConfigView extends View
@subview 'watch', new TextEditorView(mini: true, placeholderText: "Files that will be automatically watched on project open")

@div =>
@label " uploadOnSave", =>
@label " uploadOnSave (also syncs deletes and renames done in TreeView)", =>
@input type: 'checkbox', outlet: 'uploadOnSave'

@div =>
Expand Down