Skip to content

Commit

Permalink
Merge pull request #286 from wacki4/default_operations_path
Browse files Browse the repository at this point in the history
Allow to select default path for download, and upload
  • Loading branch information
cschindl committed May 13, 2019
2 parents 1398c12 + 8f41ec4 commit 23f9d9b
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 43 deletions.
17 changes: 15 additions & 2 deletions lib/config/config-schema.json
Expand Up @@ -93,6 +93,20 @@
"type": "boolean",
"default": true,
"order": 9
},
"defaultDownloadPath": {
"title": "Default download path",
"description": "Default download path for folders and files, if empty - current system user Download folder.",
"type": "string",
"default": "",
"order": 10
},
"defaultUploadPath": {
"title": "Default upload path",
"description": "Default upload path for folders and files, if empty - current system user Desktop folder.",
"type": "string",
"default": "",
"order": 11
}
},
"order": 5
Expand All @@ -106,8 +120,7 @@
"description": "Specifies the key at which the search is to be used.",
"type": "string",
"default": "Filename",
"enum": [
{
"enum": [{
"value": "Filename",
"description": "Filename"
},
Expand Down
85 changes: 44 additions & 41 deletions lib/ftp-remote-edit.js
Expand Up @@ -268,39 +268,39 @@ class FtpRemoteEdit {
detail: reasonForRequest + '\n-------------------------------\n' + caution,
dismissable: true,
buttons: [{
text: 'Always',
onDidClick: () => {
buttondismiss = true;
notif.dismiss();
addToWhiteList(Storage.getPassword(), reasonForRequest);
resolve(root.config);
}
},
{
text: 'Accept',
onDidClick: () => {
buttondismiss = true;
notif.dismiss();
resolve(root.config);
}
},
{
text: 'Decline',
onDidClick: () => {
buttondismiss = true;
notif.dismiss();
reject('userdeclined');
}
},
{
text: 'Never',
onDidClick: () => {
buttondismiss = true;
notif.dismiss();
addToBlackList(Storage.getPassword(), reasonForRequest);
reject('userdeclined');
}
},
text: 'Always',
onDidClick: () => {
buttondismiss = true;
notif.dismiss();
addToWhiteList(Storage.getPassword(), reasonForRequest);
resolve(root.config);
}
},
{
text: 'Accept',
onDidClick: () => {
buttondismiss = true;
notif.dismiss();
resolve(root.config);
}
},
{
text: 'Decline',
onDidClick: () => {
buttondismiss = true;
notif.dismiss();
reject('userdeclined');
}
},
{
text: 'Never',
onDidClick: () => {
buttondismiss = true;
notif.dismiss();
addToBlackList(Storage.getPassword(), reasonForRequest);
reject('userdeclined');
}
},
]
});

Expand Down Expand Up @@ -628,7 +628,7 @@ class FtpRemoteEdit {
if (!FileSystem.existsSync(fullLocalPath)) {
createLocalPath(fullLocalPath);
}
} catch (err) { }
} catch (err) {}

directory.getConnector().existsDirectory(fullRelativePath).then((result) => {
showMessage('Directory ' + relativePath.trim() + ' already exists', 'error');
Expand Down Expand Up @@ -864,7 +864,7 @@ class FtpRemoteEdit {
if (FileSystem.existsSync(fullLocalPath)) {
FileSystem.unlinkSync(fullLocalPath);
}
} catch (err) { }
} catch (err) {}

file.parent.select();
file.destroy();
Expand Down Expand Up @@ -1189,11 +1189,12 @@ class FtpRemoteEdit {
destObject = destObject.parent;
}

let defaultPath = atom.config.get('ftp-remote-edit.tree.defaultUploadPath') || Electron.remote.app.getPath("desktop");
let srcPath = null;
let destPath = null;

if (type == 'file') {
Electron.remote.dialog.showOpenDialog(null, { title: 'Select file(s) for upload...', defaultPath: Electron.remote.app.getPath("desktop"), buttonLabel: 'Upload', properties: ['openFile', 'multiSelections', 'showHiddenFiles'] }, (filePaths, bookmarks) => {
Electron.remote.dialog.showOpenDialog(null, { title: 'Select file(s) for upload...', defaultPath: defaultPath, buttonLabel: 'Upload', properties: ['openFile', 'multiSelections', 'showHiddenFiles'] }, (filePaths, bookmarks) => {
if (filePaths) {
Promise.all(filePaths.map((filePath) => {
srcPath = filePath;
Expand All @@ -1207,7 +1208,7 @@ class FtpRemoteEdit {
}
});
} else if (type == 'directory') {
Electron.remote.dialog.showOpenDialog(null, { title: 'Select directory for upload...', defaultPath: Electron.remote.app.getPath("desktop"), buttonLabel: 'Upload', properties: ['openDirectory', 'showHiddenFiles'] }, (directoryPaths, bookmarks) => {
Electron.remote.dialog.showOpenDialog(null, { title: 'Select directory for upload...', defaultPath: defaultPath, buttonLabel: 'Upload', properties: ['openDirectory', 'showHiddenFiles'] }, (directoryPaths, bookmarks) => {
if (directoryPaths) {
directoryPaths.forEach((directoryPath, index) => {
srcPath = directoryPath;
Expand All @@ -1231,12 +1232,14 @@ class FtpRemoteEdit {
if (selected.length === 0) return;
if (!Storage.hasPassword()) return;

let defaultPath = atom.config.get('ftp-remote-edit.tree.defaultDownloadPath') || Electron.remote.app.getPath("downloads");

if (selected.view().is('.file')) {
let file = selected.view();
if (file) {
const srcPath = normalize(file.getPath(true) + file.name);

Electron.remote.dialog.showSaveDialog(null, { defaultPath: Electron.remote.app.getPath("downloads") + "/" + file.name }, (destPath) => {
Electron.remote.dialog.showSaveDialog(null, { defaultPath: defaultPath + "/" + file.name }, (destPath) => {
if (destPath) {
self.downloadFile(file.getRoot(), srcPath, destPath, { filesize: file.size }).then(() => {
showMessage('File has been downloaded to ' + destPath, 'success');
Expand All @@ -1251,7 +1254,7 @@ class FtpRemoteEdit {
if (directory) {
const srcPath = normalize(directory.getPath(true));

Electron.remote.dialog.showSaveDialog(null, { defaultPath: Electron.remote.app.getPath("downloads") + "/" + directory.name }, (destPath) => {
Electron.remote.dialog.showSaveDialog(null, { defaultPath: defaultPath + "/" + directory.name }, (destPath) => {
if (destPath) {
self.downloadDirectory(directory.getRoot(), srcPath, destPath).then(() => {
showMessage('Directory has been downloaded to ' + destPath, 'success');
Expand All @@ -1266,7 +1269,7 @@ class FtpRemoteEdit {
if (server) {
const srcPath = normalize(server.getPath(true));

Electron.remote.dialog.showSaveDialog(null, { defaultPath: Electron.remote.app.getPath("downloads") + "/" }, (destPath) => {
Electron.remote.dialog.showSaveDialog(null, { defaultPath: defaultPath + "/" }, (destPath) => {
if (destPath) {
self.downloadDirectory(server, srcPath, destPath).then(() => {
showMessage('Directory has been downloaded to ' + destPath, 'success');
Expand Down Expand Up @@ -1873,7 +1876,7 @@ class FtpRemoteEdit {

editor.saveObject.removeClass('open');
});
} catch (err) { }
} catch (err) {}
}).catch((err) => {
showMessage(err.message, 'error');
});
Expand Down

0 comments on commit 23f9d9b

Please sign in to comment.