private Node CreateVirtualPropertyNode(UserOption virtualProperty) { var vpNode = new Node { Text = virtualProperty.VariableName, Name = virtualProperty.VariableName, Tag = virtualProperty }; vpNode.Style = virtualPropertyNodeStyle; var defaultValueNode = new Node { Text = "Default Value Function", Name = DefaultValueNodeName, Tag = DefaultValueTag }; var validatorNode = new Node { Text = "Validator Function", Name = ValidatorFunctionNodeName, Tag = ValidationTag }; var displayToUserNode = new Node { Text = "Display To User Function", Name = DisplayToUserFunctionNodeName, Tag = DisplayToUserTag }; vpNode.Nodes.Add(defaultValueNode); vpNode.Nodes.Add(validatorNode); vpNode.Nodes.Add(displayToUserNode); virtualPropertyNodes.Add(virtualProperty, vpNode); return(vpNode); }
private void SetPanelToProperty(UserOption option, FunctionTypes type) { SaveCurrentFunctionInfo(); Utility.SuspendPainting(panelContent); ClearPanel(); if (type == FunctionTypes.Validation) { functionScreen.CurrentFunction = option.GetValidatorFunction(); } else if (type == FunctionTypes.DefaultValue) { functionScreen.CurrentFunction = option.GetDefaultValueFunction(); } else if (type == FunctionTypes.DisplayToUser) { functionScreen.CurrentFunction = option.GetDisplayToUserFunction(); } currentVirtualProperty = option; currentVirtualPropertyFunction = type; functionScreen.Populate(); panelContent.Visible = true; Utility.ResumePainting(panelContent); formUserOptionDetails.Visible = true; formUserOptionDetails.UserOption = option; }
private void SetDisplayToUserNodeToDirty(UserOption virtualProperty, bool dirty) { Node currentVPNode = virtualPropertyNodes[virtualProperty]; var dtunode = FindFirstNodeNamed(DisplayToUserFunctionNodeName, currentVPNode.Nodes); SetNodeDirty(dtunode, dirty); }
private void SetValidatorNodeToDirty(UserOption virtualProperty, bool dirty) { Node currentVPNode = virtualPropertyNodes[virtualProperty]; var vnode = FindFirstNodeNamed(ValidatorFunctionNodeName, currentVPNode.Nodes); SetNodeDirty(vnode, dirty); }
private void SetDefaultValueNodeToDirty(UserOption virtualProperty, bool dirty) { Node currentVPNode = virtualPropertyNodes[virtualProperty]; var dfnode = FindFirstNodeNamed(DefaultValueNodeName, currentVPNode.Nodes); SetNodeDirty(dfnode, dirty); }
private void RemoveVirtualProperty_Clicked(object sender, EventArgs e) { if (CanRemoveVirtualProperty() == false) { RibbonBarController.RefreshButtonStatus(this); return; } UserOption userOption = null; Node currentNode = treeAPI.SelectedNode; while (currentNode != null) { if (currentNode.Tag is UserOption) { userOption = (UserOption)currentNode.Tag; break; } currentNode = currentNode.Parent; } if (userOption == null) { throw new Exception("Cannot remove virtual property - cannot find it in the tree list."); } Project.Instance.RemoveUserOption(userOption); currentNode.Remove(); ClearPanel(); }
private void AddNewVirtualProperty_Clicked(object sender, EventArgs e) { if (CanAddNewVirtualProperty() == false) { RibbonBarController.RefreshButtonStatus(this); return; } Type currentType = null; Node currentNode = treeAPI.SelectedNode; while (currentNode != null) { if (currentNode.Tag is Type) { currentType = (Type)currentNode.Tag; break; } currentNode = currentNode.Parent; } if (currentType == null) { throw new Exception("Cannot add a virtual property without selecting a type to add it to."); } UserOption uo = new UserOption("NewVirtualProperty", "", "<Display Text>", "<Description>", null, currentType, true); Project.Instance.AddUserOption(uo); Node node = CreateVirtualPropertyNode(uo); currentNode.Nodes.Add(node); treeAPI.SelectedNode = node; }
public void SetUp() { fileController = MockRepository.GenerateMock<IFileController>(); fileController.Stub(f => f.DirectoryExists("Folder")).Return(true); fileController.Stub(f => f.CanCreateFilesIn("Folder")).Return(true); userOption = new UserOption("var", "Gen", typeof(string), "test-text", "test-description", new string[0], "dv-body", typeof(bool), "validator body", "return true;", true); }
void propertyGridUserOption_UserOptionNameChanged(object sender, TextChangedEventArgs e) { UserOption option = formUserOptionDetails.UserOption; if (!virtualPropertyNodes.ContainsKey(option)) { return; } Node node = virtualPropertyNodes[option]; node.Name = node.Text = option.VariableName; }
private void treeAPI_SelectedIndexChanged(object sender, EventArgs e) { if (treeAPI.SelectedIndex == -1) { ClearPanel(); } Node selectedNode = treeAPI.SelectedNode; if (selectedNode == null) { return; } if (selectedNode.Tag is MethodInfo) { SetPanelToMethod(selectedNode.Tag as MethodInfo); } else if (selectedNode.Tag is UserOption) { formUserOptionDetails.Visible = true; formUserOptionDetails.UserOption = selectedNode.Tag as UserOption; } else if (selectedNode.Parent != null && selectedNode.Parent.Tag is UserOption) { UserOption option = (UserOption)selectedNode.Parent.Tag; if (ReferenceEquals(selectedNode.Tag, ValidationTag)) { SetPanelToProperty(option, FunctionTypes.Validation); } else if (ReferenceEquals(selectedNode.Tag, DefaultValueTag)) { SetPanelToProperty(option, FunctionTypes.DefaultValue); } else if (ReferenceEquals(selectedNode.Tag, DisplayToUserTag)) { SetPanelToProperty(option, FunctionTypes.DisplayToUser); } } RibbonBarController.RefreshButtonStatus(this); }
public virtual UserOption ReadUserOption(XmlNode rootElement) { if (rootElement == null) { throw new DeserialisationException("Could not find Option element"); } CheckVersion(rootElement); NodeProcessor proc = new NodeProcessor(rootElement); var varName = proc.GetString("VariableName"); var varType = GetTypeNamed(proc.GetString("Type")); var displayText = proc.GetString("DisplayText"); var descr = proc.GetString("Description"); var defaultValueBody = proc.GetString("DefaultValue"); var iteratorType = GetTypeNamed(proc.GetString("IteratorName")); var validatorBody = proc.GetString("ValidatorFunction"); var displayToUserBody = proc.GetString("DisplayToUserFunction"); bool resetPerSesion = proc.GetBool("ResetPerSession"); List <string> values = new List <string>(); XmlNodeList valueNodes = rootElement.SelectNodes("Values/Value"); if (valueNodes != null) { foreach (XmlNode valueNode in valueNodes) { values.Add(valueNode.Attributes["value"].Value); } } UserOption uo = new UserOption(varName, "", varType, displayText, descr, values, defaultValueBody, iteratorType, validatorBody, displayToUserBody, resetPerSesion); return(uo); }
private void DisplayValidationFunctionFor(UserOption option) { currentFunctionScreen.CurrentFunction = option.GetValidatorFunction(); currentFunctionScreen.AllowOverride = true; currentFunctionScreen.OverrideFunctionChecked = option.IsValidationFunctionOverridden(); currentFunctionScreen.Visible = true; currentFunctionScreen.Populate(); currentUserOption = option; currentFunctionType = FunctionTypes.Validation; }
private void SetDisplayToUserToDirty(UserOption option, bool dirty) { SetNodeToDirty(option, DisplayToUserFunctionNodeName, dirty); }
public virtual UserOption ReadUserOption(XmlNode rootElement) { if (rootElement == null) throw new DeserialisationException("Could not find Option element"); CheckVersion(rootElement); NodeProcessor proc = new NodeProcessor(rootElement); var varName = proc.GetString("VariableName"); var varType = GetTypeNamed(proc.GetString("Type")); var displayText = proc.GetString("DisplayText"); var descr = proc.GetString("Description"); var defaultValueBody = proc.GetString("DefaultValue"); var iteratorType = GetTypeNamed(proc.GetString("IteratorName")); var validatorBody = proc.GetString("ValidatorFunction"); var displayToUserBody = proc.GetString("DisplayToUserFunction"); bool resetPerSesion = proc.GetBool("ResetPerSession"); List<string> values = new List<string>(); XmlNodeList valueNodes = rootElement.SelectNodes("Values/Value"); if (valueNodes != null) { foreach (XmlNode valueNode in valueNodes) { values.Add(valueNode.Attributes["value"].Value); } } UserOption uo = new UserOption(varName, "", varType, displayText, descr, values, defaultValueBody, iteratorType, validatorBody, displayToUserBody, resetPerSesion); return uo; }
private TabItem CreateNewFunctionTabPage(UserOption userOption, FunctionTypes functionType, bool allowEdit) { var newPage = new TabItem(); var panel = new TabControlPanel { TabItem = newPage, Dock = DockStyle.Fill }; newPage.AttachedControl = panel; switch (functionType) { case FunctionTypes.DefaultValue: newPage.Text = userOption.VariableName + " [Default Value]"; break; case FunctionTypes.DisplayToUser: newPage.Text = userOption.VariableName + " [Display To User]"; break; case FunctionTypes.Validation: newPage.Text = userOption.VariableName + " [Valitation]"; break; } newPage.ImageIndex = 0; newPage.Tag = userOption; newPage.CloseButtonVisible = true; var funcPanel = new ucFunction { Dock = DockStyle.Fill, AllowEdit = allowEdit }; newPage.AttachedControl.Controls.Add(funcPanel); funcPanel.FunctionName = userOption.VariableName; funcPanel.CurrentUserOption = userOption; funcPanel.CurrentUserOptionFunctionType = functionType; funcPanel.Populate(); newPage.ImageIndex = 0; return newPage; }
public void DeleteUserOption(string variableName) { UserOption existingUserOption = FindUserOption(variableName); if (existingUserOption != null) { UserOption[] newUserOptions = new UserOption[UserOptions.Count - 1]; int currentPos = 0; for (int i = 0; i < UserOptions.Count; i++) { UserOption uo = UserOptions[i]; if (uo.VariableName != variableName) { newUserOptions[currentPos] = uo; currentPos++; } } m_userOptions = new List<UserOption>(newUserOptions); IsDirty = true; // Update the functions screen Controller.Instance.MainForm.UcFunctions.PopulateFunctionList(); } else { throw new Exception("Couldn't find user option."); } }
private static bool UserOptionIsUsedInFilenames(UserOption userOption, OutputFolder folder) { foreach (OutputFile file in folder.Files) { if (file.Name.IndexOf("#UserOptions." + userOption.VariableName + "#") >= 0) { return true; } } foreach (OutputFolder subFolder in folder.Folders) { if (subFolder.Name.IndexOf("#UserOptions." + userOption.VariableName + "#") >= 0) { return true; } if (UserOptionIsUsedInFilenames(userOption, subFolder)) { return true; } } return false; }
private void treeOptions_SelectionChanged(object sender, EventArgs e) { if (IgnoreSelectionChanged) return; StoreCurrentFunctionText(); currentUserOption = null; if (treeOptions.SelectedNode == null) return; object tag = treeOptions.SelectedNode.Tag; if (tag is UserOption) { propertyGridUserOption.UserOption = (UserOption)tag; propertyGridUserOption.Visible = true; } else if (tag is string && (string)tag == DefaultValueTag) { DisplayDefaultValueFunctionFor(treeOptions.SelectedNode.Parent.Tag as UserOption); } else if (tag is string && (string)tag == ValidationTag) { DisplayValidationFunctionFor(treeOptions.SelectedNode.Parent.Tag as UserOption); } else if (tag is string && (string)tag == DisplayToUserTag) { DisplayDisplayToUserFunctionFor(treeOptions.SelectedNode.Parent.Tag as UserOption); } else { propertyGridUserOption.Visible = false; } }
private void SetValidatorToDirty(UserOption option, bool dirty) { SetNodeToDirty(option, ValidatorFunctionNodeName, dirty); }
private void SetNodeToDirty(UserOption option, string nodeName, bool dirty) { Node userOptionNode; if (!userOptionNodes.TryGetValue(option, out userOptionNode)) return; Node node = FindFirstNamed(nodeName, userOptionNode.Nodes); if (dirty) node.Text = string.Format("<b>{0} *</b>", nodeName); else node.Text = nodeName; }
/// <summary> /// /// </summary> /// <param name="parentNode"></param> /// <param name="myOption"></param> /// <param name="theirOption"></param> /// <returns>True if the referenced files were different and a node was added, false if they were the same and no node was added.</returns> private bool AddUserOptionNode(TreeListNode parentNode, UserOption myOption, UserOption theirOption) { int originalNumChildNodes = parentNode.Nodes.Count; if (myOption != null && theirOption != null) { if (myOption.Category != theirOption.Category) { AddNodeBoth("Category", theirOption.Category, myOption.Category, parentNode, null); } if (myOption.DefaultValueFunctionBody != theirOption.DefaultValueFunctionBody) { AddNodeBoth("DefaultValueFunctionBody", theirOption.DefaultValueFunctionBody, myOption.DefaultValueFunctionBody, parentNode, null); } if (myOption.Description != theirOption.Description) { AddNodeBoth("Description", theirOption.Description, myOption.Description, parentNode, null); } if (myOption.IteratorType != theirOption.IteratorType) { AddNodeBoth("IteratorType", theirOption.IteratorType, myOption.IteratorType, parentNode, null); } if (myOption.ResetPerSession != theirOption.ResetPerSession) { AddNodeBoth("ResetPerSession", theirOption.ResetPerSession, myOption.ResetPerSession, parentNode, null); } if (myOption.Text != theirOption.Text) { AddNodeBoth("Text", theirOption.Text, myOption.Text, parentNode, null); } // TODO: Handle enum values //if (myOption.Values != theirOption.Category) { AddNodeBoth("Category", theirOption.Category, myOption.Category, parentNode, null); } if (myOption.VariableName != theirOption.VariableName) { AddNodeBoth("VariableName", theirOption.VariableName, myOption.VariableName, parentNode, null); } if (myOption.VarType != theirOption.VarType) { AddNodeBoth("VarType", theirOption.VarType, myOption.VarType, parentNode, null); } return originalNumChildNodes != parentNode.Nodes.Count; } if (theirOption != null) { AddNodeTheirs("Category", theirOption.Category, null, parentNode, null); AddNodeTheirs("DefaultValue", theirOption.DefaultValueFunctionBody, null, parentNode, null); AddNodeTheirs("Description", theirOption.Description, null, parentNode, null); AddNodeTheirs("IteratorType", theirOption.IteratorType, null, parentNode, null); AddNodeTheirs("ResetPerSession", theirOption.ResetPerSession, null, parentNode, null); AddNodeTheirs("Text", theirOption.Text, null, parentNode, null); // TODO: Handle enum values //if (myOption.Values != theirOption.Category) { AddNodeTheirs("Category", myOption.Category, theirOption.Category, parentNode, null); } AddNodeTheirs("VariableName", theirOption.VariableName, null, parentNode, null); AddNodeTheirs("VarType", theirOption.VarType, null, parentNode, null); } else if (myOption != null) { AddNodeMine("Category", null, myOption.Category, parentNode, null); AddNodeMine("DefaultValue", null, myOption.DefaultValueFunctionBody, parentNode, null); AddNodeMine("Description", null, myOption.Description, parentNode, null); AddNodeMine("IteratorType", null, myOption.IteratorType, parentNode, null); AddNodeMine("ResetPerSession", null, myOption.ResetPerSession, parentNode, null); AddNodeMine("Text", null, myOption.Text, parentNode, null); // TODO: Handle enum values //if (myOption.Values != theirOption.Category) { AddNodeMine("Category", myOption.Category, theirOption.Category, parentNode, null); } AddNodeMine("VariableName", null, myOption.VariableName, parentNode, null); AddNodeMine("VarType", null, myOption.VarType, parentNode, null); } return true; }
private void AddNewVirtualProperty_Clicked(object sender, EventArgs e) { if (CanAddNewVirtualProperty() == false) { RibbonBarController.RefreshButtonStatus(this); return; } Type currentType = null; Node currentNode = treeAPI.SelectedNode; while (currentNode != null) { if (currentNode.Tag is Type) { currentType = (Type)currentNode.Tag; break; } currentNode = currentNode.Parent; } if (currentType == null) throw new Exception("Cannot add a virtual property without selecting a type to add it to."); UserOption uo = new UserOption("NewVirtualProperty", "", "<Display Text>", "<Description>", null, currentType, true); Project.Instance.AddUserOption(uo); Node node = CreateVirtualPropertyNode(uo); currentNode.Nodes.Add(node); treeAPI.SelectedNode = node; }
/// <summary> /// Gets a comma-separated list of parameters and their data-types for the function signature. /// </summary> /// <param name="userOption"></param> /// <param name="userOptionFunctionType"></param> /// <returns></returns> private string GetParameterListAsString(UserOption userOption, FunctionTypes userOptionFunctionType) { string paramList = ""; if (userOptionFunctionType == FunctionTypes.DefaultValue || userOptionFunctionType == FunctionTypes.DisplayToUser) { if (userOption.IteratorType != null) { paramList += string.Format("{0} {1}", Utility.GetDemangledGenericTypeName(userOption.IteratorType, Project.Instance.Namespaces).Replace("+", "."), userOption.IteratorType.Name.ToLower()); } } else // Validation function { if (userOption.IteratorType != null) { paramList += string.Format("{0} {1}", Utility.GetDemangledGenericTypeName(userOption.IteratorType, Project.Instance.Namespaces).Replace("+", "."), userOption.IteratorType.Name.ToLower()); } paramList += string.Format(", {0} value, out string failReason", Utility.GetDemangledGenericTypeName(userOption.VarType, Project.Instance.Namespaces).Replace("+", ".")); } return paramList; }
private void SetDefaultValueToDirty(UserOption option, bool dirty) { SetNodeToDirty(option, DefaultValueFunctionNodeName, dirty); }
public void SetUp() { fileController = MockRepository.GenerateMock<IFileController>(); userOption = new UserOption("var", "Gen", typeof(string), "test-text", "test-description", new []{"val1"}, "dv-body", typeof(bool), "validator body", "return true;", true); }
private Node CreateVirtualPropertyNode(UserOption virtualProperty) { var vpNode = new Node { Text = virtualProperty.VariableName, Name = virtualProperty.VariableName, Tag = virtualProperty }; vpNode.Style = virtualPropertyNodeStyle; var defaultValueNode = new Node { Text = "Default Value Function", Name = DefaultValueNodeName, Tag = DefaultValueTag }; var validatorNode = new Node { Text = "Validator Function", Name = ValidatorFunctionNodeName, Tag = ValidationTag }; var displayToUserNode = new Node { Text = "Display To User Function", Name = DisplayToUserFunctionNodeName, Tag = DisplayToUserTag }; vpNode.Nodes.Add(defaultValueNode); vpNode.Nodes.Add(validatorNode); vpNode.Nodes.Add(displayToUserNode); virtualPropertyNodes.Add(virtualProperty, vpNode); return vpNode; }
private Node CreateUserOptionNode(UserOption newUserOption) { var node = new Node { Text = newUserOption.VariableName, Name = newUserOption.VariableName, Tag = newUserOption }; var defaultValueFunctionNode = new Node { Text = "Default Value Function", Name = DefaultValueFunctionNodeName, Tag = DefaultValueTag }; var validationFunctionNode = new Node { Text = "Validation Function", Name = ValidatorFunctionNodeName, Tag = ValidationTag }; var displayToUserFunctionNode = new Node { Text = "Display To User Function", Name = DisplayToUserFunctionNodeName, Tag = DisplayToUserTag }; node.Nodes.Add(defaultValueFunctionNode); node.Nodes.Add(validationFunctionNode); node.Nodes.Add(displayToUserFunctionNode); return node; }
private void DisplayDefaultValueFunctionFor(UserOption option) { currentFunctionScreen.CurrentFunction = option.GetDefaultValueFunction(); currentFunctionScreen.AllowOverride = true; currentFunctionScreen.OverrideFunctionChecked = option.IsDefaultValueFunctionOverridden(); currentFunctionScreen.Visible = true; currentFunctionScreen.Populate(); currentUserOption = option; currentFunctionType = FunctionTypes.DefaultValue; }
internal void CreateNewUserOption() { UserOption newUserOption = new UserOption("NewOption", "General", "<Text displayed to user>", "<Default tooltip text>", new string[0], null, false); Node userOptionNode = CreateUserOptionNode(newUserOption); // Add the user options node to the category node. FindOrCreateCategoryNode(newUserOption.Category).Nodes.Add(userOptionNode); // Add to the node collection userOptionNodes.Add(newUserOption, userOptionNode); userOptionNode.EnsureVisible(); treeOptions.SelectedNode = userOptionNode; Project.Instance.AddUserOption(newUserOption); Project.Instance.IsDirty = true; }