How to assign view into the tab as the settings?


#1

Need a little help how to assign the view class into the tab instead of the text editor. Just the like the settings tab that render html and event into it. Any idea how it works?


#2

Have a look at the settings-view package https://github.com/atom/settings-view/blob/master/lib/main.coffee. Note that some of the methods used here are deprecated, so here’s a rundown of the steps:

Set the URI you want to use for the view. The settings-view package uses atom://config.

configUri = 'lightnet://my-view'

First a helper function to create the view:

createMyView = (params) ->
  MyView ?= require './my-view'
  myView = new MyView(params)

Then add an opener for it:

atom.workspace.addOpener (uri) ->
  createMyView({uri}) if uri is configUri

Finally, add a command to open the URI you specified, which will call your opener.

atom.commands.add 'atom-workspace', 'lightnet:show-my-view', ->
  atom.workspace.open configUri

If you wanted to handle a specific file type with your view for a custom editor, you need a slightly different opener, and you don’t need the configUri or a command:

path = require 'path'

atom.workspace.addOpener (uri) ->
  createMyView({uri}) if path.extname(uri) is '.ext'

#3

How to setup my-view for simple layout to test that seem not sure but I get some errors?