private void lstParameters_DoubleClick(object sender, EventArgs e) { string paramName = lstParameters.SelectedItems[0].SubItems[0].Text; Project.ParamInfo currentParam = null; foreach (Project.ParamInfo p in CurrentFunction.Parameters) { if (p.Name == paramName) { currentParam = new Project.ParamInfo(p.Name, p.DataType); break; } } frmParameterEdit form = new frmParameterEdit(CurrentFunction, currentParam); if (form.ShowDialog(this) == DialogResult.OK) { ListViewItem item = new ListViewItem(new string[2] { form.CurrentParameter.Name, form.CurrentParameter.DataType.Name }); lstParameters.Items[lstParameters.SelectedItems[0].Index] = item; //lstParameters.Items.Add(item); return; } }
void btnBrowseArchAngelObject_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(Settings.Default.DebugCSPDatabasePath) || !File.Exists(Settings.Default.DebugCSPDatabasePath)) { MessageBox.Show(this, "Please select the ArchAngel project file (.aaproj) you want to read settings from on the Tools -> Options menu. \n\nThis will now be opened for you.", "Missing Data", MessageBoxButtons.OK, MessageBoxIcon.Warning); frmOptions formOpt = new frmOptions(); formOpt.ShowDialog(this); //this.Close(); if (string.IsNullOrEmpty(Settings.Default.DebugCSPDatabasePath) || !File.Exists(Settings.Default.DebugCSPDatabasePath)) { return; } } Cursor = Cursors.WaitCursor; Button button = (Button)sender; Type dataType = null; Label textBox = (Label)button.Tag; if (textBox.Tag.GetType() == typeof(Project.ParamInfo)) { Project.ParamInfo p = (Project.ParamInfo)textBox.Tag; dataType = p.DataType; } else { dataType = textBox.Tag.GetType(); } frmSelectModelObject form = frmSelectModelObject.Instance; //frmSelectModelObject form = new frmSelectModelObject(); //form.Show(); form.ShowObject(this, dataType); if (form.SelectedObject != null) { int index = int.Parse(button.Name.Substring(button.Name.LastIndexOf("_") + 1)); ParametersToPass[index] = form.SelectedObject; if (textBox.Tag != form.SelectedObject) { // One of the parameters have now changed, so clear any previously generated text syntaxEditor1.Text = ""; syntaxEditorFormatted.Text = ""; } textBox.Tag = form.SelectedObject; if (form.SelectedObject != null) { textBox.Text = ArchAngel.Interfaces.ProjectHelper.GetDisplayName(form.SelectedObject); ValuesThatHaveBeenSet[index] = true; } } Cursor = Cursors.Default; }
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; }
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; }
private void Populate() { this.Text = "Preview: " + TheFunction.Name; panel1.Controls.Clear(); int gap = 5; int currentTop = 0; int maxLabelWidth = 0; System.Drawing.Font font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); Label measureLabel = new Label(); measureLabel.BackColor = Color.Transparent; measureLabel.Font = font; Graphics graphics = Graphics.FromHwnd(measureLabel.Handle); string displayText; ParametersToPass = new object[TheFunction.Parameters.Length]; bool parametersMatch = false; List <object> parameterObjects = null; ValuesThatHaveBeenSet = new bool[TheFunction.Parameters.Length]; if (CachedParameteres.ContainsKey(TheFunction)) { parameterObjects = CachedParameteres[TheFunction]; parametersMatch = TheFunction.Parameters.Length == parameterObjects.Count; if (parametersMatch) { for (int i = 0; i < TheFunction.Parameters.Length; i++) { if (parameterObjects[i] == null || !TheFunction.Parameters[i].DataType.IsInstanceOfType(parameterObjects[i])) { parametersMatch = false; } } } } for (int i = 0; i < TheFunction.Parameters.Length; i++) { Project.ParamInfo param = TheFunction.Parameters[i]; displayText = string.Format("{2}. {0} ({1}):", param.Name, param.DataType, i + 1); maxLabelWidth = (float)maxLabelWidth > graphics.MeasureString(displayText, font).Width ? maxLabelWidth : (int)graphics.MeasureString(displayText, new Font("Microsoft Sans Serif", 8.25f)).Width; if (parametersMatch) { ParametersToPass[i] = parameterObjects[i]; ValuesThatHaveBeenSet[i] = true; } } for (int i = 0; i < TheFunction.Parameters.Length; i++) { Project.ParamInfo param = TheFunction.Parameters[i]; // New implementation Label lbl = new Label(); lbl.Text = string.Format("{2}. {0} ({1}):", param.Name, param.DataType, i + 1); lbl.TextAlign = ContentAlignment.BottomLeft; lbl.Width = maxLabelWidth + gap; panel1.Controls.Add(lbl); lbl.Left = gap; if (i == 0) { currentTop = 0; } else { currentTop += lbl.Height + gap; } lbl.Top = currentTop; currentTop = lbl.Bottom; // typeof(ArchAngel.Interfaces.IScriptBaseObject).IsInstanceOfType(param.DataType) if (param.DataType.GetInterface("ArchAngel.Interfaces.IScriptBaseObject") != null) { Label txt = new Label(); txt.BackColor = InvalidColor; txt.Top = currentTop; txt.Left = gap * 4; txt.Tag = param; txt.BorderStyle = BorderStyle.FixedSingle; if (parametersMatch) { txt.Text = ArchAngel.Interfaces.ProjectHelper.GetDisplayName(ParametersToPass[i]); } panel1.Controls.Add(txt); Button btnBrowseArchAngelObject = new Button(); btnBrowseArchAngelObject.Text = "..."; btnBrowseArchAngelObject.BackColor = Color.FromKnownColor(KnownColor.Control); btnBrowseArchAngelObject.Width = btnBrowseArchAngelObject.Height + gap; btnBrowseArchAngelObject.Top = currentTop; btnBrowseArchAngelObject.Tag = txt; btnBrowseArchAngelObject.Name = string.Format("btnBrowseArchAngelObject_{0}", i); btnBrowseArchAngelObject.Click += new EventHandler(btnBrowseArchAngelObject_Click); btnBrowseArchAngelObject.Left = txt.Right + gap; panel1.Controls.Add(btnBrowseArchAngelObject); } else { switch (param.DataType.Name.ToLower()) { case "bool": case "boolean": CheckBox chk = new CheckBox(); chk.Top = currentTop; chk.Left = gap * 4; chk.Name = string.Format("chk_{0}", i); chk.CheckedChanged += new EventHandler(chk_CheckedChanged); panel1.Controls.Add(chk); break; case "int": case "int32": NumEdit numericInt = new NumEdit(); numericInt.BackColor = InvalidColor; numericInt.InputType = NumEdit.NumEditType.Integer; numericInt.Top = currentTop; numericInt.Left = gap * 4; numericInt.Name = string.Format("numericInt_{0}", i); numericInt.TextChanged += new EventHandler(numericInt_TextChanged); panel1.Controls.Add(numericInt); break; case "double": NumEdit numericDouble = new NumEdit(); numericDouble.BackColor = InvalidColor; numericDouble.InputType = NumEdit.NumEditType.Double; numericDouble.Top = currentTop; numericDouble.Left = gap * 4; numericDouble.Name = string.Format("numericDouble_{0}", i); numericDouble.TextChanged += new EventHandler(numericDouble_TextChanged); panel1.Controls.Add(numericDouble); break; case "string": TextBox txt2 = new TextBox(); txt2.BackColor = InvalidColor; txt2.Text = "Not set"; txt2.Top = currentTop; txt2.Left = gap * 4; txt2.Name = string.Format("txt2_{0}", i); txt2.TextChanged += new EventHandler(txt2_TextChanged); panel1.Controls.Add(txt2); break; default: MessageBox.Show(this, "Data type not handled yet: " + param.DataType.Name, "Unexpected Data-Type", MessageBoxButtons.OK, MessageBoxIcon.Warning); break; } } } //if (parametersMatch) //{ // Run(); //} }