blog.vi-kan.net One thought after another

atom.io: opening a new document

Opening documents in atom.io, is managed through the open method of the workspace object.

To open a new document in atom.io, omit the URI parameter of the open call:

{CompositeDisposable} = require 'atom'

module.exports = MyPackage =

    subscriptions: null

    activate: (state) ->
        # Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable
        @subscriptions = new CompositeDisposable

        # Register command that toggles this view
        @subscriptions.add atom.commands.add 'atom-workspace', 'my-package:execute': => @execute()

    deactivate: ->
        @subscriptions.dispose()

    execute: ->
        # no URI given
        atom.workspace.open()

When saving the document, you will be prompted for a filename.

If you provide a URI to a non-existing file, a new document will be created with that filename. The file is not created before you hit the save command. You will not be prompted for filename.

execute: ->
    # URI for non-existing URI given
    atom.workspace.open('c:\\temp\\temp.txt')

If you do not provide a full URI, just a name, it will use the current projects root folder. If no project is open, you will get a new un-named document.

execute: ->
    # relative URI for non-existing file
    atom.workspace.open('newdoc')

At this time, this is undocumented behavior, but hopefully, not for long.

comments powered by Disqus