     case Add = 0
     case Remove = 1
   }
+
+  // Context indicating that a new config should be added after a document save completes.
+  private static var PostSaveContextAddConfig = 0
 
   @IBOutlet var configArrayController: NSArrayController!
   @IBOutlet weak var addRemoveSegmentedControl: NSSegmentedControl!

      let additionalFilePaths = bazelPackages.map() { "\($0)/BUILD" }
      guard let projectName = projectDocument.projectName,
                generatorConfigFolderURL = projectDocument.generatorConfigFolderURL else {
        // TODO(abaire): Force a save.
        NSBeep()
        return
      }


    projectDocument.error(String(format: fmt, errorInfo))
  }

  func document(doc:NSDocument, didSave:Bool, contextInfo: UnsafeMutablePointer<Void>) {
    if contextInfo == &ProjectEditorConfigManagerViewController.PostSaveContextAddConfig {
      if didSave {
        didClickAddConfig(nil)
      }
    }
  }

  // MARK: - Private methods

  private func didClickAddConfig(sender: AnyObject?) {
    let projectDocument = representedObject as! TulsiProjectDocument

    // Adding a config to a project with no bazel packages is disallowed.
    guard let bazelPackages = projectDocument.bazelPackages where !bazelPackages.isEmpty else {
      // This should be prevented by the UI, so spawn a bug message and beep.
      projectDocument.info("Bug: Add config invoked on a project with no packages.")
      NSBeep()
      return
    }
