           title: title
           paths: [path]
         @addProject(moveProject)
+
+  createProjectManagerView: (state) ->
+    unless @projectManagerView?
+      ProjectManagerView = require './project-manager-view'
+      @projectManagerView = new ProjectManagerView(state.projectManagerViewState)
+    @projectManagerView
+
+  createProjectManagerAddView: (state) ->
+    unless @projectManagerAddView?
+      ProjectManagerAddView = require './project-manager-add-view'
+      @projectManagerAddView = new ProjectManagerAddView(state.projectManagerAddViewState)
+    @projectManagerAddView

ProjectManagerView = require './project-manager-view'
ProjectManagerAddView = require './project-manager-add-view'
CSON = require 'season'

module.exports =
  configDefaults:


  activate: (state) ->
    @file = "#{@fileDir}/#{@filename}"

    atom.workspaceView.command 'project-manager:save-project', =>
      @createProjectManagerAddView(state).toggle(@)
    atom.workspaceView.command 'project-manager:toggle', =>
      @createProjectManagerView(state).toggle(@)
    atom.workspaceView.command 'project-manager:edit-projects', =>
      @editProjects()

    fs.exists @file, (exists) =>
      unless exists
        fs.open @file, 'a', (err, fd) ->
          # Migrate current project
          if not err and state.projectsMigrated?
            @migrate(state)

  addProject: (project) ->
    CSON = require 'season'
    projects = CSON.readFileSync(@file)
    projects[project.title] = project
    CSON.writeFileSync(@file, projects)
