Skip to content

Commit 0bdefd9

Browse files
committed
fix #33
1 parent 92a559f commit 0bdefd9

File tree

2 files changed

+64
-47
lines changed

2 files changed

+64
-47
lines changed

lib/RemoteSync.coffee

Lines changed: 55 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -37,58 +37,70 @@ module.exports =
3737
statusView.update "question", "Couldn't find config"
3838

3939
atom.workspaceView.command "remote-sync:download-all", ->
40-
return logger.error("#{configPath} doesn't exist") if not settings
40+
return if checkSetting()
4141
download(atom.project.getPath())
4242

4343
atom.workspaceView.command "remote-sync:reload-config", ->
4444
load()
4545

46-
atom.workspaceView.command 'remote-sync:upload', (e)->
47-
return logger.error("#{configPath} doesn't exist") if not settings
48-
[localPath, isFile] = getSelectPath e
49-
if isFile
50-
handleSave(localPath)
51-
else
52-
uploadPath(localPath)
53-
54-
atom.workspaceView.command 'remote-sync:download', (e)->
55-
return logger.error("#{configPath} doesn't exist") if not settings
56-
[localPath, isFile] = getSelectPath e
57-
if isFile
58-
return if settings.isIgnore(localPath)
59-
localPath = atom.project.relativize(localPath)
60-
getTransport().download(path.join(settings.target, localPath).replace(/\\/g, "/"))
61-
else
62-
download(localPath)
46+
atom.workspaceView.command 'remote-sync:upload-folder', (e)->
47+
return if checkSetting()
48+
uploadPath($(e.target).view().getPath())
49+
50+
atom.workspaceView.command 'remote-sync:upload-file', (e)->
51+
return if checkSetting()
52+
handleSave($(e.target).view().getPath())
53+
54+
atom.workspaceView.command 'remote-sync:download-file', (e)->
55+
return if checkSetting()
56+
localPath = $(e.target).view().getPath()
57+
return if settings.isIgnore(localPath)
58+
realPath = atom.project.relativize(localPath)
59+
realPath = path.join(settings.target, realPath).replace(/\\/g, "/")
60+
getTransport().download(realPath)
61+
62+
atom.workspaceView.command 'remote-sync:download-folder', (e)->
63+
return if checkSetting()
64+
download($(e.target).view().getPath())
65+
66+
atom.workspaceView.command 'remote-sync:diff-file', (e)->
67+
return if checkSetting()
68+
localPath = $(e.target).view().getPath()
69+
return if settings.isIgnore(localPath)
70+
realPath = atom.project.relativize(localPath)
71+
realPath = path.join(settings.target, realPath).replace(/\\/g, "/")
6372

64-
atom.workspaceView.command 'remote-sync:diff', (e)->
65-
return logger.error("#{configPath} doesn't exist") if not settings
66-
[localPath, isFile] = getSelectPath e
6773
os = require "os" if not os
68-
targetPath = path.join os.tmpDir(), "remote-sync-"+path.basename(localPath)
69-
diff = ->
70-
diffCmd = atom.config.get('remote-sync.difftoolCommand')
71-
exec = require("child_process").exec if not exec
72-
exec "#{diffCmd} #{localPath} #{targetPath}", (err)->
73-
logger.error """Check the field value of difftool Command in your settings (remote-sync).
74-
Command error: #{err}
75-
command: #{diffCmd} #{localPath} #{targetPath}
76-
"""
77-
78-
if isFile
79-
return if settings.isIgnore(localPath)
80-
getTransport().download(path.join(settings.target, atom.project.relativize(localPath)).replace(/\\/g, "/"), targetPath, diff)
81-
else
82-
download(localPath, targetPath, diff)
74+
targetPath = path.join os.tmpDir(), "remote-sync"
8375

84-
findFileParent = (node) ->
85-
parent = node.parent()
86-
return parent if parent.is('.file') or parent.is('.directory')
87-
findFileParent(parent)
76+
getTransport().download realPath, targetPath, ->
77+
diff localPath, targetPath
8878

89-
getSelectPath = (e) ->
90-
selected = findFileParent($(e.target))
91-
[selected.view().getPath(), selected.is('.file')]
79+
atom.workspaceView.command 'remote-sync:diff-folder', (e)->
80+
return if checkSetting()
81+
localPath = $(e.target).view().getPath()
82+
os = require "os" if not os
83+
targetPath = path.join os.tmpDir(), "remote-sync"
84+
85+
download localPath, targetPath, ->
86+
diff localPath, targetPath
87+
88+
diff = (localPath, targetPath) ->
89+
targetPath = path.join(targetPath, path.basename(localPath))
90+
diffCmd = atom.config.get('remote-sync.difftoolCommand')
91+
exec = require("child_process").exec if not exec
92+
exec "#{diffCmd} #{localPath} #{targetPath}", (err)->
93+
return if not err
94+
logger.error """Check [difftool Command] in your settings (remote-sync).
95+
Command error: #{err}
96+
command: #{diffCmd} #{localPath} #{targetPath}
97+
"""
98+
99+
checkSetting = ->
100+
if not settings
101+
logger.error("#{configPath} doesn't exist")
102+
return true
103+
return false
92104

93105
download = (localPath, targetPath, callback)->
94106
if not downloadCmd

menus/context.cson

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
'context-menu':
2-
'.tree-view > li.directory':
2+
'.tree-view .file':
33
'Remote Sync':
4-
'upload': 'remote-sync:upload'
5-
'download': 'remote-sync:download'
6-
'diff': 'remote-sync:diff'
4+
'Upload File': 'remote-sync:upload-file'
5+
'Download File': 'remote-sync:download-file'
6+
'Diff File': 'remote-sync:diff-file'
7+
'.tree-view .header.list-item':
8+
'Remote Sync':
9+
'Upload Folder': 'remote-sync:upload-folder'
10+
'Download Folder': 'remote-sync:download-folder'
11+
'Diff Folder': 'remote-sync:diff-folder'

0 commit comments

Comments
 (0)