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 opening remote files #184

Merged
merged 4 commits into from
Dec 3, 2018
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
2 changes: 2 additions & 0 deletions lib/console2/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ export default class InkTerminal extends PaneItem {

resize () {
let {cols, rows} = this.terminal.proposeGeometry()
// resize twice with different sizes to actually force a resize:
this.terminal.resize(cols - 2, rows)
this.terminal.resize(cols - 1, rows)
}

Expand Down
3 changes: 3 additions & 0 deletions lib/ink.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ module.exports = Ink =
consumeStatusBar: (bar) ->
exportables.progress().consumeStatusBar bar

consumeRemoteFileOpener: (opener) ->
exportables.Opener().consumeRemoteFileOpener(opener)

provide: ->
obj =
util:
Expand Down
45 changes: 41 additions & 4 deletions lib/util/opener.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,41 @@
import {focusEditorPane} from './pane-item'
import {existsSync} from 'fs'

export function open (pathOrId, line, {pending = false, existingOnly = true} = {}) {
let remoteFileOpener = undefined
let allowremote = false

export function open (pathOrId, line, {pending = false, existingOnly = true, remote = false} = {}) {
focusEditorPane()
let id = getUntitledId(pathOrId)
return id ? openEditorById(id, line) :
(!existingOnly || existsSync(pathOrId)) ?
atom.workspace.open(pathOrId, {initialLine: line, searchAllPanes: true, pending}) : Promise.resolve(false)

if (id) {
return openEditorById(id, line)
} else if (allowremote && remoteFileOpener) {
return new Promise((resolve, reject) => {
let disposable = atom.workspace.observeActiveTextEditor(ed => {
if (ed) {
let ep = ed.getPath()
if (ep) {
ep = ep.replace(/\\/g, '/')
if (ep.indexOf(pathOrId) > -1) {
ed.setCursorBufferPosition([line, 0])
if (disposable) disposable.dispose()
}
}
}
})
if (remoteFileOpener(pathOrId)) {
resolve(true)
} else {
resolve(false)
if (disposable) disposable.dispose()
}
})
} else if (!existingOnly || existsSync(pathOrId)) {
return atom.workspace.open(pathOrId, {initialLine: line, searchAllPanes: true, pending})
} else {
return Promise.resolve(false)
}
}

export function isUntitled(pathOrId) {
Expand All @@ -19,6 +48,14 @@ export function getUntitledId (file) {
return id != null ? id[1] : false
}

export function consumeRemoteFileOpener (o) {
remoteFileOpener = o
}

export function allowRemoteFiles (val) {
allowremote = val
}

function openEditorById (id, line) {
return new Promise((resolve) => {
for (const pane of atom.workspace.getPanes()) {
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
"versions": {
"^1.0.0": "consumeStatusBar"
}
},
"ftp-remote.openFile": {
"versions": {
"0.1.0": "consumeRemoteFileOpener"
}
}
}
}