@@ -2,6 +2,8 @@ fs = require 'fs-plus'
2
2
_ = require ' underscore-plus'
3
3
_path = require ' path'
4
4
nsync = require ' nsync-fs'
5
+ remote = require ' remote'
6
+ dialog = remote .require ' dialog'
5
7
atomHelper = require ' ./atom-helper'
6
8
executeCustomCommand = require ' ./custom-commands'
7
9
SingleSocket = require ' single-socket'
@@ -49,6 +51,32 @@ onSave = ({target}) ->
49
51
content = new Buffer (text).toString (' base64' )
50
52
nsync .save (path, content)
51
53
54
+ onImport = ->
55
+ dialog .showOpenDialog
56
+ title : ' Import Files' ,
57
+ properties : [' openFile' , ' multiSelections' ]
58
+ , (paths ) ->
59
+ importLocalPaths (paths)
60
+
61
+ importLocalPaths = (localPaths ) ->
62
+ localPaths = [localPaths] if typeof localPaths is ' string'
63
+ targetPath = atomHelper .selectedPath ()
64
+ targetNode = nsync .getNode (targetPath)
65
+
66
+ localPaths .forEach (path) ->
67
+ fs .readFile path, ' base64' , (err , data ) ->
68
+ if err?
69
+ return console .error ' Unable to import file:' , path, err
70
+
71
+ base = _path .basename (path)
72
+ newPath = _path .posix .join (targetNode .path , base)
73
+
74
+ if nsync .hasPath (newPath)
75
+ atomHelper .warn ' Learn IDE: cannot save file' ,
76
+ detail : " There is already an existing remote file with path: #{ newPath} "
77
+ return
78
+
79
+ nsync .save (newPath, data)
52
80
53
81
module .exports = helper = (activationState ) ->
54
82
disposables = new CompositeDisposable
@@ -57,7 +85,7 @@ module.exports = helper = (activationState) ->
57
85
' learn-ide:save' : onSave
58
86
' learn-ide:save-as' : unimplemented
59
87
' learn-ide:save-all' : unimplemented
60
- ' learn-ide:import' : @ onImport
88
+ ' learn-ide:import' : onImport
61
89
' learn-ide:file-open' : unimplemented
62
90
' learn-ide:add-project' : unimplemented
63
91
0 commit comments