Opening file in cloud9 using external link


#1

I’m curious if there is any existing way to open a file for editing using external link? E.g. I’m opening some link like https://ide.c9.io/mymachine?file=/path/to/file&line=42 and it would open for editing /path/to/file at line 42. Or at least just file itself.

If not… I know that your SDK allows to open new tabs. Can it read URL params? And is there any way to scroll to the exact line?

Thanks.


#2

welcome.js plugin does something similar by opening preview at the startup https://github.com/c9/c9.ide.welcome/blob/master/welcome.js#L71-L75
and the link_handler.js has a function to parse and open urls in the form /path/to/file:5:10


#3

Thanks to my colleague, we have this snippet that should be put to Init script (Cloud9 > Open Your Init Script):

function openEditorTab () {
    if (window.location.hash.match(/#editfile-(.*):([0-9]+)/)) {
        var file = "/" + RegExp.$1;
        var line = RegExp.$2;
        services.fs.exists(file, function(exists) {
            if (!exists) return;
            services.tabManager.openFile(file, true, function(err, tab) {
                var editor = tab.editor;
                editor.ace.gotoLine(line, 0, true);
                editor.focus();
            });
        });
    }
}

openEditorTab();
window.addEventListener("hashchange", openEditorTab, false);

Now to open a certain file at certain line you just need to call:

window.open('https://ide.c9.io/username/workspace#editfile-full/path/to/file:5', 'c9win');