Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow server path in uri hander #245

Merged
merged 3 commits into from
Jan 27, 2019
Merged
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
7 changes: 7 additions & 0 deletions lib/config/config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@
"type": "boolean",
"default": true,
"order": 9
},
"alwaysReopenFile": {
"title": "Always reopen file",
"description": "If file is opened it will be always reloaded",
"type": "boolean",
"default": false,
"order": 10
}
},
"order": 5
Expand Down
26 changes: 23 additions & 3 deletions lib/ftp-remote-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class FtpRemoteEdit {
'ftp-remote-edit:copy-remote-path': () => self.copyRemotePath(),
'ftp-remote-edit:finder': () => self.remotePathFinder(),
'ftp-remote-edit:finder-reindex-cache': () => self.remotePathFinder(true),
'ftp-remote-edit:open-file': () => self.reopenRemoteFile(),
}));

self.treeView = new TreeView();
Expand Down Expand Up @@ -118,7 +119,7 @@ class FtpRemoteEdit {
handleURI(parsedUri) {
const self = this;

let regex = /(\/)?([a-z0-9_\-]{1,5}:\/\/)(([^:]{1,})((:(.{1,}))?[\@\x40]))?([a-z0-9_\-.]+)(:([0-9]*))?/gi;
let regex = /(\/)?([a-z0-9_\-]{1,5}:\/\/)(([^:]{1,})((:(.{1,}))?[\@\x40]))?([a-z0-9_\-.]+)(:([0-9]*))?(.*)/gi;
let is_matched = parsedUri.path.match(regex);

if (is_matched) {
Expand All @@ -129,6 +130,7 @@ class FtpRemoteEdit {
let password = matched[7];
let host = matched[8];
let port = matched[10];
let path = matched[11] || "/";

let new_server_config = {
"name": protocol + username + '@' + host,
Expand All @@ -138,7 +140,7 @@ class FtpRemoteEdit {
"password": password,
"sftp": (protocol == 'sftp://'),
"privatekeyfile": "",
"remote": "/"
"remote": path
};
if (self.debug) {
console.log("Adding new server by uri handler", new_server_config);
Expand All @@ -158,7 +160,7 @@ class FtpRemoteEdit {
localPath = normalize(Path.join(localPath.slice(0, localPath.lastIndexOf(root.getPath())), file).replace(/\/+/g, Path.sep), Path.sep);
try {
let file = self.treeView.getElementByLocalPath(localPath, root, 'file');
file.open();
file.open(false, reload);
return true;
} catch (ex) {
if (self.debug) {
Expand Down Expand Up @@ -437,6 +439,24 @@ class FtpRemoteEdit {
self.configurationView.attach();
}

reopenRemoteFile() {
const self = this;
const selected = self.treeView.list.find('.selected');

if (selected.length === 0) return;

if (selected) {
if (selected.view()
.is('.file')) {
file = selected.view();
}

if (file) {
file.open(false,true);
}
}
}

newFile() {
const self = this;
const selected = self.treeView.list.find('.selected');
Expand Down
22 changes: 11 additions & 11 deletions lib/views/directory-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,14 @@ class DirectoryView extends View {
});

directories.sort(function (a, b) {
if (a.name < b.name) return -1;
if (a.name > b.name) return 1;
if (a.name.toLowerCase() < b.name.toLowerCase()) return -1;
if (a.name.toLowerCase() > b.name.toLowerCase()) return 1;
return 0;
});

files.sort(function (a, b) {
if (a.name < b.name) return -1;
if (a.name > b.name) return 1;
if (a.name.toLowerCase() < b.name.toLowerCase()) return -1;
if (a.name.toLowerCase() > b.name.toLowerCase()) return 1;
return 0;
});

Expand Down Expand Up @@ -223,8 +223,8 @@ class DirectoryView extends View {

if (!atom.config.get('ftp-remote-edit.tree.sortFoldersBeforeFiles')) {
entries.sort(function (a, b) {
if (a.name < b.name) return -1;
if (a.name > b.name) return 1;
if (a.name.toLowerCase() < b.name.toLowerCase()) return -1;
if (a.name.toLowerCase() > b.name.toLowerCase()) return 1;
return 0;
});
}
Expand Down Expand Up @@ -428,11 +428,11 @@ class DirectoryView extends View {
if (sortFoldersBeforeFiles) {
if (a.classList.contains('directory') && b.classList.contains('file')) return -1;
if (a.classList.contains('file') && b.classList.contains('directory')) return 1;
if (a.spacePenView.name < b.spacePenView.name) return -1;
if (a.spacePenView.name > b.spacePenView.name) return 1;
if (a.spacePenView.name.toLowerCase() < b.spacePenView.name.toLowerCase()) return -1;
if (a.spacePenView.name.toLowerCase() > b.spacePenView.name.toLowerCase()) return 1;
} else {
if (a.spacePenView.name < b.spacePenView.name) return -1;
if (a.spacePenView.name > b.spacePenView.name) return 1;
if (a.spacePenView.name.toLowerCase() < b.spacePenView.name.toLowerCase()) return -1;
if (a.spacePenView.name.toLowerCase() > b.spacePenView.name.toLowerCase()) return 1;
}
return 0;
})
Expand Down Expand Up @@ -1020,7 +1020,7 @@ class DirectoryView extends View {

// Delete local directory
deleteLocalPath(fullLocalPath);

self.destroy();
})
.catch(function (err) {
Expand Down
12 changes: 9 additions & 3 deletions lib/views/file-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,21 @@ class FileView extends View {
element.label.removeClass('icon-sync').removeClass('spin');
};

open(pending = false) {
open(pending = false, reload = false) {
const self = this;

let queueItem = null;

reload = reload || atom.config.get('ftp-remote-edit.tree.alwaysReopenFile');

// Check if file is already opened in texteditor
if (self.getTextEditor(self.getLocalPath(true) + self.name, true)) {
atom.workspace.open(self.getLocalPath(true) + self.name, { pending: pending, searchAllPanes: true })
return false;
if(reload) {
self.getTextEditor(self.getLocalPath(true) + self.name, true).destroy();
} else {
atom.workspace.open(self.getLocalPath(true) + self.name, { pending: pending, searchAllPanes: true })
return false;
}
}

// Check if file is already in Queue
Expand Down
4 changes: 4 additions & 0 deletions menus/ftp-remote-edit.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@
{
"type": "separator"
},
{
"label": "Open/Reopen File",
"command": "ftp-remote-edit:open-file"
},
{
"label": "Rename",
"command": "ftp-remote-edit:rename"
Expand Down