/// <summary> /// Sets the workspace you want to edit. /// </summary> /// <param name="ws">The workspace which will be edited.</param> internal void EditWorkspace(Workspace ws) { // fill the form nameTextBox.Text= ws.Name; behaviorFolderTextBox.Text= ws.Folder; exportFolderTextBox.Text= ws.DefaultExportFolder; // select plugins for(int i= 0; i <checkedListBox.Items.Count; ++i) { if(ws.Plugins.Contains( (string) checkedListBox.Items[i] )) checkedListBox.SetItemChecked(i, true); } }
/// <summary> /// Handles when the cancel button is pressed. /// </summary> private void cancelButton_Click(object sender, EventArgs e) { // we did not edit or create a workspace _workspace= null; Close(); }
/// <summary> /// Handles when the done button is pressed. /// </summary> private void doneButton_Click(object sender, EventArgs e) { string name= nameTextBox.Text.Trim(); string folder= behaviorFolderTextBox.Text.Trim(); string defaultExportFolder= exportFolderTextBox.Text.Trim(); // create the given folder if it does not exist if(!Directory.Exists(folder)) Directory.CreateDirectory(folder); // create the given export folder if it does not exist if(defaultExportFolder !=string.Empty && !Directory.Exists(defaultExportFolder)) Directory.CreateDirectory(defaultExportFolder); // check if this is a valid name, if we have plugins selected and if the selected folder exists if(name.Length >0 && checkedListBox.CheckedItems.Count >0 && Directory.Exists(folder)) { // create the updated or new workspace _workspace= new Workspace(name, folder, defaultExportFolder); // update plugins foreach(string plugin in checkedListBox.CheckedItems) _workspace.AddPlugin(plugin); Close(); } }
/// <summary> /// Loads the present workspaces. /// </summary> /// <param name="filename">The name of the Xml file loaded.</param> private void LoadWorkspacesFile(string filename) { XmlDocument xml= new XmlDocument(); xml.Load(filename); XmlNode root= xml.ChildNodes[1]; GetAttribute(root, "selected", out _recentlySelectedWorkspace); // load workspaces foreach(XmlNode node in root) { if(node.NodeType ==XmlNodeType.Element && node.Name =="workspace") { string name= GetAttribute(node, "name"); string folder= GetAttribute(node, "folder"); // we get this as an optional parameter to stay compatible with the old files string defaultExportFolder; GetAttribute(node, "export", out defaultExportFolder); Workspace ws= new Workspace(name, folder, defaultExportFolder); // load plugins foreach(XmlNode subnode in node) { if(subnode.NodeType ==XmlNodeType.Element && subnode.Name =="plugin") { if(subnode.InnerText.Trim() !=string.Empty) ws.AddPlugin(subnode.InnerText.Trim()); } } // add the loaded workspace to the lists _workspaces.Add(ws); comboBox.Items.Add(ws); if(ws.Name ==_recentlySelectedWorkspace) comboBox.SelectedItem= ws; } } }