private void editWorkspaceToolStripMenuItem_Click(object sender, EventArgs e) { Workspace ws = Workspace.Current; using (EditWorkspaceDialog dialog = new EditWorkspaceDialog()) { dialog.EditWorkspace(ws); dialog.ShowDialog(); if (dialog.Workspace != null) { Workspace.SaveWorkspaceFile(dialog.Workspace); MainWindow.Instance.SetWorkspace(dialog.Workspace.FileName, false); } } }
/// <summary> /// Set the workspace for the editor. /// <param name="workspaceName">The current workspace.</param> /// <param name="automatic">If ture, the workspace dialog will not be shown.</param> /// </summary> public bool SetWorkspace(string workSpaceFile, bool bNew) { bool setWorkspace = false; try { Workspace workspace = null; if (bNew) { using (EditWorkspaceDialog dialog = new EditWorkspaceDialog()) { dialog.ShowDialog(); // check if we have a valid result if (dialog.Workspace != null) { Workspace.SaveWorkspaceFile(dialog.Workspace); } workspace = dialog.Workspace; } } else { workspace = Workspace.LoadWorkspaceFile(workSpaceFile); } if (workspace != null) { bool bReopen = false; if (Workspace.Current != null) { BehaviorTreeViewDock.CloseAll(); if (Workspace.Current.Name == workspace.Name) { //reopen those opened behaviors if the same workspace is opened again bReopen = true; } } behaviorTreeList.Enabled = false; Workspace.Current = workspace; // Display the file version this.Text = workspace.Name + " - BehaviacDesigner " + this.ProductVersion; behaviorTreeList.UnLoadPlugins(nodeTreeList); behaviorTreeList.LoadPlugins(nodeTreeList, (Plugin.EditMode == EditModes.Design)); behaviorTreeList.UnLoadXMLPlugins(); setWorkspace = behaviorTreeList.LoadXMLPlugins(workspace.XMLFolder, workspace.XMLPlugins); behaviorTreeList.BehaviorFolder = workspace.Folder; Behavior.BehaviorPath = behaviorTreeList.BehaviorFolder; m_Watcher.Path = behaviorTreeList.BehaviorFolder; m_Watcher.Filter = "*.xml"; m_Watcher.IncludeSubdirectories = true; m_Watcher.NotifyFilter = NotifyFilters.LastWrite; //m_Watcher.SynchronizingObject = behaviorTreeList; m_Watcher.Changed += new FileSystemEventHandler(OnChanged); m_Watcher.EnableRaisingEvents = true; postSetWorkspace(); // reopen the last opened behaviors. if (setWorkspace && bReopen) { foreach (string bt in BehaviorTreeViewDock.LastOpenedBehaviors) { UIUtilities.ShowBehaviorTree(bt); } BehaviorTreeViewDock.LastOpenedBehaviors.Clear(); } // check if we found any exporter this.exportAllMenuItem.Enabled &= (Plugin.Exporters.Count > 0); // check if we found any file managers this.saveAllMenuItem.Enabled &= behaviorTreeList.HasFileManagers(); behaviorTreeList.Enabled = true; if (MetaStoreDock.IsVisible()) { MetaStoreDock.Inspect(); } } } catch (Exception ex) { MessageBox.Show(ex.Message, Resources.WorkspaceError, MessageBoxButtons.OK); } return setWorkspace; }