public void ShowFunction(IWin32Window owner, Project.FunctionInfo function) { TheFunction = function; Populate(); Cursor = Cursors.Default; this.ShowDialog(owner); }
private void mnuHelperItemViewFunction_Click(object sender, EventArgs e) { Controller.MainForm.Cursor = Cursors.WaitCursor; TreeListNode selectedNode = treeListAPIHelper.Selection[0]; Type objectType = (Type)selectedNode.ParentNode.Tag; string methodName = selectedNode[0].ToString(); string functionName = objectType.FullName.Replace("ArchAngel.Providers.Database.", "") + "." + methodName; functionName = functionName.Replace(".", "_"); Project.FunctionInfo function = Project.Instance.FindFunction(functionName); if (function == null) { System.Reflection.MethodInfo method = objectType.GetMethod(methodName); ArchAngel.Interfaces.Attributes.ApiExtensionAttribute[] attributes = (ArchAngel.Interfaces.Attributes.ApiExtensionAttribute[])method.GetCustomAttributes(typeof(ArchAngel.Interfaces.Attributes.ApiExtensionAttribute), true); if (attributes.Length == 0) { throw new NotImplementedException(string.Format("DefaultCodeAttribute not implemented for {0}.{1} yet.", objectType.FullName, methodName)); } Type returnType = method.ReturnType; function = new Project.FunctionInfo(functionName, returnType, "XXX", false, Project.ScriptLanguageTypes.CSharp, string.Format("Override of helper function: {0}.{1}.", objectType.Name, methodName), "XXX", "Helper Overrides"); System.Reflection.ParameterInfo[] parameters = method.GetParameters(); foreach (System.Reflection.ParameterInfo parameter in parameters) { ArchAngel.Designer.Project.ParamInfo par = new Project.ParamInfo(parameter.Name, parameter.ParameterType); function.AddParameter(par); } Project.Instance.AddFunction(function); //int funcCount = Project.Instance.Functions.Length; //Project.FunctionInfo[] coll = new Project.FunctionInfo[funcCount + 1]; //coll[coll.Length - 1] = function; //Array.Copy(Project.Instance.Functions, coll, funcCount); //Project.Instance.Functions = coll; } Project.DefaultValueFunction defValFunc = Project.Instance.FindDefaultValueFunction(functionName); if (defValFunc == null) { Project.ParamInfo[] parameterTypes = new Project.ParamInfo[function.Parameters.Length]; for (int i = 0; i < function.Parameters.Length; i++) { parameterTypes[i] = new Project.ParamInfo(Slyce.Common.Utility.GetCamelCase(function.Parameters[i].Name), function.Parameters[i].DataType); } defValFunc = new Project.DefaultValueFunction(objectType, methodName, false, Project.DefaultValueFunction.FunctionTypes.HelperOverride, false); defValFunc.ParameterTypes = parameterTypes; Project.Instance.DefaultValueFunctions.Add(defValFunc); function.Body = defValFunc.GetFormattedDefaultCode(); Project.Instance.IsDirty = true; } Controller.MainForm.ShowFunction(functionName, defValFunc, false, this); Controller.MainForm.Cursor = Cursors.Default; }
private void DeleteHelperFunction(string functionName) { if (MessageBox.Show(string.Format("Delete {0}?", functionName), "Delete Function", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes) { Project.FunctionInfo function = Project.Instance.FindFunction(functionName); if (function != null) { // Delete function deletes the DefaultValueFunction as well, if it exists. Project.Instance.DeleteFunction(function); } else { Project.DefaultValueFunction defValFunc = Project.Instance.FindDefaultValueFunction(functionName); if (defValFunc != null) { Project.Instance.DefaultValueFunctions.Remove(defValFunc); } } } //Populate(); treeListAPIHelper.Invalidate(); }
public void PopulateFunctionHeader() { bool dirtyStatus = Project.Instance.IsDirty; CurrentFunction = Project.Instance.FindFunction(FunctionName); chkTemplateFunction.Checked = CurrentFunction.IsTemplateFunction; txtName.Text = CurrentFunction.Name; txtDescription.Text = CurrentFunction.Description; for (int i = 0; i < CurrentFunction.Parameters.Length; i++) { Project.ParamInfo param = (Project.ParamInfo)CurrentFunction.Parameters[i]; ListViewItem item = new ListViewItem(new string[2] { param.Name, param.DataType.Name }); item.Tag = param.DataType; lstParameters.Items.Add(item); } ddlReturnType.Items.Clear(); ddlReturnType.Text = ""; ddlReturnType.Items.Clear(); if (CurrentFunction.IsTemplateFunction) { Slyce.Common.SyntaxEditorHelper.Languages[] outputLanguages = (Slyce.Common.SyntaxEditorHelper.Languages[])Enum.GetValues(typeof(Slyce.Common.SyntaxEditorHelper.Languages)); foreach (Slyce.Common.SyntaxEditorHelper.Languages outputLanguage in outputLanguages) { ddlReturnType.Items.Add(Slyce.Common.SyntaxEditorHelper.LanguageNameFromEnum(outputLanguage)); } ddlReturnType.DropDownStyle = ComboBoxStyle.DropDownList; } else { switch (CurrentFunction.ScriptLanguage) { case Project.ScriptLanguageTypes.CSharp: ddlReturnType.Items.AddRange(new string[] { "double", "float", "int", "string", "void" }); break; case Project.ScriptLanguageTypes.VbNet: ddlReturnType.Items.AddRange(new string[] { "Double", "Float", "Int", "String", "Void" }); break; default: throw new NotImplementedException("Script language type not handled yet: " + CurrentFunction.ScriptLanguage.ToString()); } ddlReturnType.DropDownStyle = ComboBoxStyle.DropDown; } ddlReturnType.Text = CurrentFunction.IsTemplateFunction ? CurrentFunction.TemplateReturnLanguage : CurrentFunction.ReturnType.Name; ddlScriptLanguage.Text = Project.ScriptLanguageNameFromEnum(CurrentFunction.ScriptLanguage); #region Fill Categories foreach (string category in Project.Instance.FunctionCategories) { if (ddlCategory.FindStringExact(category) < 0) { ddlCategory.Items.Add(category); } } ddlCategory.Sorted = true; ddlCategory.Text = CurrentFunction.Category; #endregion Project.Instance.IsDirty = dirtyStatus; }
public bool Save() { if (ddlCategory.Text.ToLower().IndexOf("default value") == 0) { MessageBox.Show("'Default Value' is reserved category name and can't be used.", "Invalid Category", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } if (ddlCategory.Text.ToLower().IndexOf("validate") == 0) { MessageBox.Show("'Validate' is reserved category name and can't be used.", "Invalid Category", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } if (txtName.Text == "NewFunction") { MessageBox.Show("'NewFunction' is not a valid name.", "Invalid Name", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } if (txtName.Text.Length == 0) { MessageBox.Show("Please enter a function name", "Function name missing", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtName.Focus(); return(false); } if (!Slyce.Common.Utility.IsValidFunctionName(txtName.Text)) { MessageBox.Show("The function name has some invalid characters. Only alphabetic, numeric and underscores allowed.", "Invalid Function Name", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtName.Focus(); return(false); } if (ddlReturnType.Text.Length == 0) { MessageBox.Show("Please add a return type.", "No return type", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } if ((IsNewFunction && Project.Instance.FindFunction(txtName.Text) != null) || (!IsNewFunction && (CurrentFunction.Name != txtName.Text) && Project.Instance.FindFunction(txtName.Text) != null)) { MessageBox.Show("A function with this name already exists. Please choose another name.", "Duplicate function name", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } bool nameHasChanged = CurrentFunction.Name != txtName.Text; CurrentFunction.Name = txtName.Text; CurrentFunction.Description = txtDescription.Text; int foundIndex = -1; bool mustRefreshFunctionList = IsNewFunction; Project.FunctionInfo fi; for (int i = 0; i < Project.Instance.Functions.Count; i++) { if (Project.Instance.Functions[i].Name == CurrentFunction.Name) { foundIndex = i; } } string templateReturnLanguage = chkTemplateFunction.Checked ? ddlReturnType.Text : ""; Type dataType = chkTemplateFunction.Checked ? typeof(string) : Project.Instance.GetTypeFromReferencedAssemblies(ddlReturnType.Text, true); if (foundIndex >= 0) { fi = Project.Instance.Functions[foundIndex]; } else { mustRefreshFunctionList = true; fi = new Project.FunctionInfo(txtName.Text, dataType, "", chkTemplateFunction.Checked, (Project.ScriptLanguageTypes)Enum.Parse(typeof(Project.ScriptLanguageTypes), ddlScriptLanguage.Text), txtDescription.Text, templateReturnLanguage, ddlCategory.Text); //int funcCount = Project.Instance.Functions.Count; //Project.FunctionInfo[] coll = new Project.FunctionInfo[funcCount + 1]; //coll[coll.Length - 1] = fi; //Array.Copy(Project.Instance.Functions, coll, funcCount); //Project.Instance.Functions = coll; Project.Instance.Functions.Add(fi); foundIndex = Project.Instance.Functions.Count - 1; } if (!IsNewFunction && fi.Name != txtName.Text) { // Name has changed if (MessageBox.Show("Rename this function throughout the code?", "Name Change", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { Project.Instance.RenameFunctionAll(fi.Name, txtName.Text); } Project.Instance.SortFunctions(); mustRefreshFunctionList = true; } fi.Name = txtName.Text; FunctionName = fi.Name; string[] parms = new string[lstParameters.Items.Count]; fi.Parameters = new Project.ParamInfo[lstParameters.Items.Count]; fi.IsTemplateFunction = chkTemplateFunction.Checked; fi.ReturnType = dataType; fi.ScriptLanguage = Project.ScriptLanguageEnumFromName(ddlScriptLanguage.Text); fi.TemplateReturnLanguage = templateReturnLanguage; if (fi.Category != ddlCategory.Text) { mustRefreshFunctionList = true; } fi.Category = ddlCategory.Text; for (int i = 0; i < lstParameters.Items.Count; i++) { string name = lstParameters.Items[i].SubItems[0].Text.Trim(); //string dt = lstParameters.Items[i].SubItems[1].Text.Trim(); fi.Parameters[i] = new Project.ParamInfo(name, (Type)lstParameters.Items[i].Tag); } Project.Instance.Functions[foundIndex] = fi; if (!IsNewFunction) { Controller.MainForm.UcFunctions.RenameSelectedTab(fi.Name); } txtName.Clear(); lstParameters.Items.Clear(); txtName.Focus(); if (nameHasChanged || IsNewFunction) { Project.Instance.SortFunctions(); } Project.Instance.IsDirty = true; if (mustRefreshFunctionList) { Controller.MainForm.PopulateFunctionList(); } return(true); }
public bool Save() { if (ddlCategory.Text.ToLower().IndexOf("default value") == 0) { MessageBox.Show("'Default Value' is reserved category name and can't be used.", "Invalid Category", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return false; } if (ddlCategory.Text.ToLower().IndexOf("validate") == 0) { MessageBox.Show("'Validate' is reserved category name and can't be used.", "Invalid Category", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return false; } if (txtName.Text == "NewFunction") { MessageBox.Show("'NewFunction' is not a valid name.", "Invalid Name", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return false; } if (txtName.Text.Length == 0) { MessageBox.Show("Please enter a function name", "Function name missing", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtName.Focus(); return false; } if (!Slyce.Common.Utility.IsValidFunctionName(txtName.Text)) { MessageBox.Show("The function name has some invalid characters. Only alphabetic, numeric and underscores allowed.", "Invalid Function Name", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtName.Focus(); return false; } if (ddlReturnType.Text.Length == 0) { MessageBox.Show("Please add a return type.", "No return type", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return false; } if ((IsNewFunction && Project.Instance.FindFunction(txtName.Text) != null) || (!IsNewFunction && (CurrentFunction.Name != txtName.Text) && Project.Instance.FindFunction(txtName.Text) != null)) { MessageBox.Show("A function with this name already exists. Please choose another name.", "Duplicate function name", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return false; } bool nameHasChanged = CurrentFunction.Name != txtName.Text; CurrentFunction.Name = txtName.Text; CurrentFunction.Description = txtDescription.Text; int foundIndex = -1; bool mustRefreshFunctionList = IsNewFunction; Project.FunctionInfo fi; for (int i = 0; i < Project.Instance.Functions.Count; i++) { if (Project.Instance.Functions[i].Name == CurrentFunction.Name) { foundIndex = i; } } string templateReturnLanguage = chkTemplateFunction.Checked ? ddlReturnType.Text : ""; Type dataType = chkTemplateFunction.Checked ? typeof(string) : Project.Instance.GetTypeFromReferencedAssemblies(ddlReturnType.Text, true); if (foundIndex >= 0) { fi = Project.Instance.Functions[foundIndex]; } else { mustRefreshFunctionList = true; fi = new Project.FunctionInfo(txtName.Text, dataType, "", chkTemplateFunction.Checked, (Project.ScriptLanguageTypes)Enum.Parse(typeof(Project.ScriptLanguageTypes), ddlScriptLanguage.Text), txtDescription.Text, templateReturnLanguage, ddlCategory.Text); //int funcCount = Project.Instance.Functions.Count; //Project.FunctionInfo[] coll = new Project.FunctionInfo[funcCount + 1]; //coll[coll.Length - 1] = fi; //Array.Copy(Project.Instance.Functions, coll, funcCount); //Project.Instance.Functions = coll; Project.Instance.Functions.Add(fi); foundIndex = Project.Instance.Functions.Count - 1; } if (!IsNewFunction && fi.Name != txtName.Text) { // Name has changed if (MessageBox.Show("Rename this function throughout the code?", "Name Change", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { Project.Instance.RenameFunctionAll(fi.Name, txtName.Text); } Project.Instance.SortFunctions(); mustRefreshFunctionList = true; } fi.Name = txtName.Text; FunctionName = fi.Name; string[] parms = new string[lstParameters.Items.Count]; fi.Parameters = new Project.ParamInfo[lstParameters.Items.Count]; fi.IsTemplateFunction = chkTemplateFunction.Checked; fi.ReturnType = dataType; fi.ScriptLanguage = Project.ScriptLanguageEnumFromName(ddlScriptLanguage.Text); fi.TemplateReturnLanguage = templateReturnLanguage; if (fi.Category != ddlCategory.Text) { mustRefreshFunctionList = true; } fi.Category = ddlCategory.Text; for (int i = 0; i < lstParameters.Items.Count; i++) { string name = lstParameters.Items[i].SubItems[0].Text.Trim(); //string dt = lstParameters.Items[i].SubItems[1].Text.Trim(); fi.Parameters[i] = new Project.ParamInfo(name, (Type)lstParameters.Items[i].Tag); } Project.Instance.Functions[foundIndex] = fi; if (!IsNewFunction) { Controller.MainForm.UcFunctions.RenameSelectedTab(fi.Name); } txtName.Clear(); lstParameters.Items.Clear(); txtName.Focus(); if (nameHasChanged || IsNewFunction) { Project.Instance.SortFunctions(); } Project.Instance.IsDirty = true; if (mustRefreshFunctionList) { Controller.MainForm.PopulateFunctionList(); } return true; }