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; }
private void closeTabPageToolStripMenuItem_Click(object sender, EventArgs e) { if (tabStrip1.SelectedTab != null) { ucFunction function = (ucFunction)tabStrip1.SelectedTab.AttachedControl.Controls["ucFunction"]; if (function.IsDirty)// && //(function.DefaultValueFunction == null || // function.DefaultValueFunction.UseCustomCode)) { if ( MessageBox.Show(this, "You have modified the code of the function you are closing without saving. Save the changes?", "Save Changes", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { function.Save(); } } //else if (function.DefaultValueFunction != null && !function.DefaultValueFunction.UseCustomCode) //{ // if (Project.Instance.FindFunction(function.CurrentFunction.Name, function.CurrentFunction.Parameters) != null) // { // Project.Instance.DeleteFunction(function.CurrentFunction); // } //} tabStrip1.Tabs.Remove(tabStrip1.SelectedTab); if (tabStrip1.SelectedTab != null) { tabStrip1.SelectedTab.AttachedControl.Controls["ucFunction"].Controls[3].Focus(); } } }
public ucFunction GetFunctionScreen(string functionName, ParamInfo[] parameters) { foreach (TabItem tab in tabStrip1.Tabs) { ucFunction functionScreen = (ucFunction)tab.AttachedControl.Controls["ucFunction"]; FunctionInfo func = functionScreen.CurrentFunction; if (func.Name == functionName && func.Parameters.Count == parameters.Length) { bool found = true; for (int i = 0; i < func.Parameters.Count; i++) { if (func.Parameters[i].DataType.FullName != parameters[i].DataType.FullName) { found = false; break; } } if (found) { return functionScreen; } } } return null; }
public static void FindNext()//string textToFind, Scope scope, SearchFunctions searchFunctions, FindReplaceOptions options) { switch (searchFunctions) { case SearchFunctions.CurrentFunction: ucFunction functionPage = Controller.Instance.MainForm.UcFunctions.GetCurrentlyDisplayedFunctionPage(); if (functionPage != null) { FunctionInfo function = functionPage.CurrentFunction; SyntaxEditor editor = functionPage.syntaxEditor1; FindInText(editor.Text, Options.FindText, scope, function, function.IsTemplateFunction, Options, editor.SelectedView.Selection.StartOffset, true); } break; case SearchFunctions.OpenFunctions: break; case SearchFunctions.AllFunctions: break; default: throw new NotImplementedException("Not coded yet."); } }
public FunctionRunner(ucFunction functionScreen, FunctionInfo function) { //string outputSyntaxFilePath = Slyce.Common.SyntaxEditorHelper.GetLanguageFileName(Project.Instance.TextLanguage); //btnTest.Enabled = true; CurrentFunction = function; //OriginalCompileFolderName = Project.Instance.CompileFolderName; //syntaxEditor1.Document.Language = ActiproSoftware.SyntaxEditor.Addons.Dynamic.DynamicSyntaxLanguage.LoadFromXml(outputSyntaxFilePath, 0); }
private void listResults_DoubleClick(object sender, EventArgs e) { if (listResults.SelectedItems.Count > 0) { FunctionInfo function = (FunctionInfo)listResults.SelectedItems[0].Tag; Controller.Instance.MainForm.ShowFunction(function, null); ucFunction functionScreen = Controller.Instance.MainForm.UcFunctions.GetCurrentlyDisplayedFunctionPage(); ActiproSoftware.SyntaxEditor.SyntaxEditor editor = functionScreen.syntaxEditor1; editor.SelectedView.Selection.StartOffset = int.Parse(listResults.SelectedItems[0].SubItems[1].Text); editor.SelectedView.Selection.EndOffset = int.Parse(listResults.SelectedItems[0].SubItems[1].Text) + int.Parse(listResults.SelectedItems[0].SubItems[2].Text); } }
public ucApiExtensions() { InitializeComponent(); functionScreen = new ucFunction(); functionScreen.Dock = DockStyle.Fill; panelContent.Controls.Add(functionScreen); virtualPropertyNodeStyle.TextColor = Color.DarkSlateBlue; functionScreen.IsDirtyChanged += functionScreen_IsDirtyChanged; formUserOptionDetails.UserOptionNameChanged += propertyGridUserOption_UserOptionNameChanged; formUserOptionDetails.Visible = false; }
public ucOptions() { InitializeComponent(); currentFunctionScreen = new ucFunction(); currentFunctionScreen.Visible = false; panelContent.Controls.Add(currentFunctionScreen); currentFunctionScreen.Dock = DockStyle.Fill; currentFunctionScreen.IsDirtyChanged += currentFunctionScreen_IsDirtyChanged; currentFunctionScreen.ResetDefaultCode += currentFunctionScreen_ResetDefaultCode; propertyGridUserOption.UserOptionNameChanged += propertyGridUserOption_UserOptionNameChanged; propertyGridUserOption.UserOptionCategoryChanged += propertyGridUserOption_UserOptionCategoryChanged; }
/// <summary> /// Removes the specified tab and closes the screen if no more tabs remain. /// </summary> /// <param name="tab">Tab to remove.</param> internal void RemoveTab(TabItem tab) { foreach (Control ctl in tab.AttachedControl.Controls) { if (ctl.GetType() == typeof(ucFunction)) { ucFunction function = (ucFunction)ctl; if (function.IsDirty)// && //(function.DefaultValueFunction == null || // function.DefaultValueFunction.UseCustomCode)) { DialogResult result = MessageBox.Show(this, "You have modified the code of the function you are closing without saving. Save the changes?", "Save Changes: " + function.CurrentFunction.Name, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning); switch (result) { case DialogResult.Yes: function.Save(); break; case DialogResult.Cancel: return; } } //else if (function.DefaultValueFunction != null && // !function.DefaultValueFunction.UseCustomCode && // !function.DefaultValueFunction.IsForUserOption) //{ // if (Project.Instance.FindFunction(function.CurrentFunction.Name, function.CurrentFunction.Parameters) != null) // { // Project.Instance.DeleteFunction(function.CurrentFunction); // } //} } } if (tabStrip1.Tabs.Contains(tab)) { tabStrip1.Tabs.Remove(tab); } if (tabStrip1.Tabs.Count == 0) { tabStrip1.Visible = false; lblStatus.Visible = true; Refresh(); } Refresh(); }
public ucFunction GetFunctionPanel(FunctionInfo function) { foreach (TabItem tab in tabStrip1.Tabs) { ucFunction functionScreen = (ucFunction)tab.AttachedControl.Controls["ucFunction"]; if (functionScreen.CurrentFunction == function) { return functionScreen; } } ShowFunction(function, null); foreach (TabItem tab in tabStrip1.Tabs) { ucFunction functionScreen = (ucFunction)tab.AttachedControl.Controls["ucFunction"]; if (functionScreen.CurrentFunction == function) { return functionScreen; } } throw new Exception("We shouldn't be here."); }
private TabItem CreateNewFunctionTabPage(FunctionInfo function, bool allowEdit) { TabItem newPage = new TabItem(); TabControlPanel panel = new TabControlPanel(); panel.TabItem = newPage; panel.Dock = DockStyle.Fill; newPage.AttachedControl = panel; newPage.Text = function.Name; newPage.ImageIndex = 0; newPage.Tag = function; newPage.CloseButtonVisible = true; ucFunction funcPanel = new ucFunction(); funcPanel.Dock = DockStyle.Fill; funcPanel.AllowEdit = allowEdit; newPage.AttachedControl.Controls.Add(funcPanel); funcPanel.FunctionName = function.Name; funcPanel.CurrentFunction = function; //funcPanel.DefaultValueFunction = defaultValueFunction; funcPanel.Populate(); switch (SyntaxEditorHelper.GetScriptingLanguage(function.ScriptLanguage)) { case TemplateContentLanguage.CSharp: newPage.ImageIndex = 3; break; case TemplateContentLanguage.VbDotNet: newPage.ImageIndex = 5; break; case TemplateContentLanguage.Sql: newPage.ImageIndex = 0; break; case TemplateContentLanguage.Html: newPage.ImageIndex = 4; break; case TemplateContentLanguage.Css: newPage.ImageIndex = 2; break; case TemplateContentLanguage.IniFile: newPage.ImageIndex = 0; break; case TemplateContentLanguage.JScript: newPage.ImageIndex = 0; break; case TemplateContentLanguage.Python: newPage.ImageIndex = 0; break; case TemplateContentLanguage.VbScript: newPage.ImageIndex = 5; break; case TemplateContentLanguage.Xml: newPage.ImageIndex = 6; break; case TemplateContentLanguage.PlainText: newPage.ImageIndex = 0; break; default: throw new Exception("This function return type not handled yet in ShowFunction: " + funcPanel.ReturnType); } return newPage; }
public static void Search(string textToFind) { if (Options == null) { return; } if (textToFind == "NONE_SPECIFIED") { textToFind = Options.FindText; } Options.FindText = textToFind; SearchHelper.RunFind(); if (SearchHelper.FoundLocations.Count == 0) { return; } if (CurrentIndex < 0) { CurrentIndex = 0; } if (CurrentIndex < SearchHelper.FoundLocations.Count - 1) { CurrentIndex++; } else if (SearchHelper.FoundLocations.Count >= 0) { CurrentIndex = 0; } bool found; // We now have a collection of indexes, so let's look for the actual words switch (searchFunctions) { case SearchFunctions.CurrentFunction: ucFunction currentFunctionPage = Controller.Instance.MainForm.UcFunctions.GetCurrentlyDisplayedFunctionPage(); if (currentFunctionPage == null) { return; } if (SearchHelper.FoundLocations.Count > 0 && SearchHelper.FoundLocations[0].Function != currentFunctionPage.CurrentFunction) { scope = SearchHelper.Scope.Both; searchFunctions = SearchHelper.SearchFunctions.AllFunctions; SearchHelper.RunFind(); } SyntaxEditor editor = currentFunctionPage.syntaxEditor1; int currentStartPos = editor.SelectedView.Selection.StartOffset + 1; CurrentIndex = -1; found = false; for (int foundLocIndex = 0; foundLocIndex < SearchHelper.FoundLocations.Count; foundLocIndex++) { if (SearchHelper.FoundLocations[foundLocIndex].Function == currentFunctionPage.CurrentFunction) { if (CurrentIndex < 0) { CurrentIndex = foundLocIndex; } CurrentIndex = foundLocIndex; if (SearchHelper.FoundLocations[foundLocIndex].StartPos > currentStartPos) { CurrentIndex = foundLocIndex; found = true; break; } } } if (!found) { CurrentIndex = 0; } if (CurrentIndex < 0) { return; } editor.SelectedView.Selection.StartOffset = SearchHelper.FoundLocations[CurrentIndex].StartPos; editor.SelectedView.Selection.EndOffset = SearchHelper.FoundLocations[CurrentIndex].StartPos + SearchHelper.FoundLocations[CurrentIndex].Length; break; case SearchFunctions.OpenFunctions: case SearchFunctions.AllFunctions: // This is just highlighting the text in all open functions // Make sure highlighting starts from the currently selected position CurrentIndex = -1; ucFunction currentFunctionPage2 = Controller.Instance.MainForm.UcFunctions.GetCurrentlyDisplayedFunctionPage(); found = false; if (currentFunctionPage2 != null) { int selectedPos = currentFunctionPage2.syntaxEditor1.SelectedView.Selection.StartOffset + currentFunctionPage2.syntaxEditor1.SelectedView.Selection.Length; if (SearchHelper.FoundLocations.Count > 0) { for (int i = 0; i < SearchHelper.FoundLocations.Count; i++) { if (SearchHelper.FoundLocations[i].Function == currentFunctionPage2.CurrentFunction) { if (CurrentIndex < 0) { CurrentIndex = i; } CurrentIndex = i; if (SearchHelper.FoundLocations[i].StartPos > selectedPos) { found = true; break; } } } } } if (!found) { if (SearchHelper.FoundLocations.Count > 0) { if (CurrentIndex < SearchHelper.FoundLocations.Count - 1) { CurrentIndex++; } else { CurrentIndex = 0; } } } for (int i = 0; i < Controller.Instance.MainForm.UcFunctions.tabStrip1.Tabs.Count; i++) { if (Controller.Instance.MainForm.UcFunctions.GetFunctionScreenByTabIndex(i).CurrentFunction == SearchHelper.FoundLocations[CurrentIndex].Function) { Controller.Instance.MainForm.UcFunctions.tabStrip1.SelectedTabIndex = i; } } if (Controller.Instance.MainForm.UcFunctions.tabStrip1.SelectedTab != null) { currentFunctionPage2 = Controller.Instance.MainForm.UcFunctions.GetCurrentlyDisplayedFunctionPage(); currentFunctionPage2.syntaxEditor1.SelectedView.Selection.StartOffset = SearchHelper.FoundLocations[CurrentIndex].StartPos; currentFunctionPage2.syntaxEditor1.SelectedView.Selection.EndOffset = SearchHelper.FoundLocations[CurrentIndex].StartPos + SearchHelper.FoundLocations[CurrentIndex].Length; break; } break; default: throw new NotImplementedException("Not coded yet."); } }
/// <summary> /// /// </summary> /// <param name="textToFind"></param> /// <param name="replacementText"></param> /// <returns>Number of replacements made.</returns> public static int ReplaceAll(string textToFind, string replacementText) { SearchHelper.Search(textToFind); int padIncrement = replacementText.Length - textToFind.Length; for (int i = 0; i < SearchHelper.FoundLocations.Count; i++) { FunctionInfo currentFunction = SearchHelper.FoundLocations[i].Function; int pad = 0; bool iHasBeenIncremented; switch (SearchHelper.searchFunctions) { case SearchHelper.SearchFunctions.CurrentFunction: ucFunction currentFunctionScreen = Controller.Instance.MainForm.UcFunctions.GetCurrentlyDisplayedFunctionPage(); if (currentFunctionScreen.CurrentFunction == currentFunction) { SyntaxEditor editor = currentFunctionScreen.syntaxEditor1; StringBuilder sb = new StringBuilder(editor.Document.Text, editor.Document.Text.Length + 100); sb.Replace("\r\n", "\n"); iHasBeenIncremented = false; try { editor.SuspendPainting(); while (i < SearchHelper.FoundLocations.Count && SearchHelper.FoundLocations[i].Function == currentFunction) { sb.Remove(SearchHelper.FoundLocations[i].StartPos + pad, SearchHelper.FoundLocations[i].Length); sb.Insert(SearchHelper.FoundLocations[i].StartPos + pad, replacementText); pad += padIncrement; iHasBeenIncremented = true; i++; } editor.Document.Text = sb.ToString(); } finally { editor.ResumePainting(); } // Make sure we don't skip any locations, because the for loop at // the top-level also increments i. if (iHasBeenIncremented) { i--; } } //for (int tabCounter = 0; tabCounter < Controller.Instance.MainForm.UcFunctions.tabStrip1.Pages.Count; tabCounter++) break; case SearchHelper.SearchFunctions.OpenFunctions: for (int tabCounter = 0; tabCounter < Controller.Instance.MainForm.UcFunctions.tabStrip1.Tabs.Count; tabCounter++) { ucFunction functionScreen = Controller.Instance.MainForm.UcFunctions.GetFunctionScreenByTabIndex(tabCounter); if (functionScreen.CurrentFunction == currentFunction) { SyntaxEditor editor = functionScreen.syntaxEditor1; StringBuilder sb = new StringBuilder(editor.Document.Text, editor.Document.Text.Length + 100); sb.Replace("\r\n", "\n"); iHasBeenIncremented = false; try { editor.SuspendPainting(); while (i < SearchHelper.FoundLocations.Count && SearchHelper.FoundLocations[i].Function == currentFunction) { sb.Remove(SearchHelper.FoundLocations[i].StartPos + pad, SearchHelper.FoundLocations[i].Length); sb.Insert(SearchHelper.FoundLocations[i].StartPos + pad, replacementText); pad += padIncrement; iHasBeenIncremented = true; i++; } editor.Document.Text = sb.ToString(); } finally { editor.ResumePainting(); } // Make sure we don't skip any locations, because the for loop at // the top-level also increments i. if (iHasBeenIncremented) { i--; } } } break; case SearchHelper.SearchFunctions.AllFunctions: bool functionIsOpen = false; for (int tabCounter = 0; tabCounter < Controller.Instance.MainForm.UcFunctions.tabStrip1.Tabs.Count; tabCounter++) { ucFunction functionScreen2 = Controller.Instance.MainForm.UcFunctions.GetFunctionScreenByTabIndex(tabCounter); if (functionScreen2.CurrentFunction == currentFunction) { functionIsOpen = true; SyntaxEditor editor = functionScreen2.syntaxEditor1; StringBuilder sb = new StringBuilder(editor.Document.Text, editor.Document.Text.Length + 100); sb.Replace("\r\n", "\n"); iHasBeenIncremented = false; while (i < SearchHelper.FoundLocations.Count && SearchHelper.FoundLocations[i].Function == currentFunction) { try { editor.SuspendPainting(); sb.Remove(SearchHelper.FoundLocations[i].StartPos + pad, SearchHelper.FoundLocations[i].Length); sb.Insert(SearchHelper.FoundLocations[i].StartPos + pad, replacementText); editor.Document.Text = sb.ToString(); } finally { editor.ResumePainting(); } pad += padIncrement; iHasBeenIncremented = true; i++; } // Make sure we don't skip any locations, because the for loop at // the top-level also increments i. if (iHasBeenIncremented) { i--; } } } if (!functionIsOpen) { FunctionInfo function = SearchHelper.FoundLocations[i].Function; iHasBeenIncremented = false; while (i < SearchHelper.FoundLocations.Count && SearchHelper.FoundLocations[i].Function == currentFunction) { function.Body = function.Body.Replace("\r\n", "\n"); function.Body = function.Body.Remove(SearchHelper.FoundLocations[i].StartPos + pad, SearchHelper.FoundLocations[i].Length); function.Body = function.Body.Insert(SearchHelper.FoundLocations[i].StartPos + pad, replacementText); pad += padIncrement; iHasBeenIncremented = true; i++; } // Make sure we don't skip any locations, because the for loop at // the top-level also increments i. if (iHasBeenIncremented) { i--; } } break; default: throw new NotImplementedException("Not coded yet."); } } return(SearchHelper.FoundLocations.Count); }
public void HighlightError(int lineNum, int characterPosition, string message, int switchOffset, string functionName, List<ParamInfo> parameters, bool isWarning) { ShowErrors(); FunctionInfo function = Project.Instance.FindFunction(functionName, parameters); if (tabStrip1.InvokeRequired) { CrossThreadHelper.SetCrossThreadProperty(tabStrip1, "Height", ClientSize.Height - tabStrip1.Top - 200); } else { tabStrip1.Height = ClientSize.Height - tabStrip1.Top - 200; } ListViewItem lvi; if (lineNum >= 0) { SyntaxEditor syntaxEditor1 = null; ucFunction currentPage = GetCurrentlyDisplayedFunctionPage(); if (currentPage != null && currentPage.CurrentFunction == function) { foreach (Control ctl in tabStrip1.SelectedTab.AttachedControl.Controls) { if (ctl.GetType() == typeof(ucFunction)) { syntaxEditor1 = ((ucFunction)ctl).syntaxEditor1; break; } } MarkErrorWord(syntaxEditor1, lineNum, characterPosition, message); } lvi = new ListViewItem(new[] { functionName, message, lineNum.ToString(), characterPosition.ToString() }); lvi.Tag = function; lvi.StateImageIndex = lvi.ImageIndex = isWarning ? 1 : 0; if (listErrors.InvokeRequired) { CrossThreadHelper.CallCrossThreadMethod(listErrors.Items, "Add", new object[] { lvi }); } else { listErrors.Items.Add(lvi); } } else { if (lineNum == 0) { lvi = new ListViewItem(new[] { functionName, message, "Func Header", "" }); } else { lvi = new ListViewItem(new[] { functionName, message, "", "" }); } lvi.StateImageIndex = lvi.ImageIndex = isWarning ? 1 : 0; lvi.Tag = function; listErrors.Items.Add(lvi); SuperTooltipInfo sti = new SuperTooltipInfo(functionName, null, message, null, null, eTooltipColor.Office2003); } }