Skip to content

Commit 2008f5e

Browse files
committed
Add import and update the menu
1 parent 7c90fb0 commit 2008f5e

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

lib/nsync/atom-helper.coffee

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ module.exports = helper =
102102
@treeView()?.entryForPath(path).reload()
103103
@treeView()?.selectEntryForPath(pathToSelect or path)
104104

105+
selectedPath: ->
106+
@treeView()?.selectedPath
107+
105108
findTextEditorByElement: (element) ->
106109
atom.workspace.getTextEditors().find (editor) ->
107110
editor.element is element

lib/nsync/nsync-helper.coffee

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ fs = require 'fs-plus'
22
_ = require 'underscore-plus'
33
_path = require 'path'
44
nsync = require 'nsync-fs'
5+
remote = require 'remote'
6+
dialog = remote.require 'dialog'
57
atomHelper = require './atom-helper'
68
executeCustomCommand = require './custom-commands'
79
SingleSocket = require 'single-socket'
@@ -49,6 +51,32 @@ onSave = ({target}) ->
4951
content = new Buffer(text).toString('base64')
5052
nsync.save(path, content)
5153

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)
5280

5381
module.exports = helper = (activationState) ->
5482
disposables = new CompositeDisposable
@@ -57,7 +85,7 @@ module.exports = helper = (activationState) ->
5785
'learn-ide:save': onSave
5886
'learn-ide:save-as': unimplemented
5987
'learn-ide:save-all': unimplemented
60-
'learn-ide:import': @onImport
88+
'learn-ide:import': onImport
6189
'learn-ide:file-open': unimplemented
6290
'learn-ide:add-project': unimplemented
6391

0 commit comments

Comments
 (0)