public bool CanRenameVariable(ILuaIntellisenseDocument document) { VariableExpression expression; List <LuatValue.IReference> definitions; return(CanRenameVariable(document, out expression, out definitions)); }
private void RemoveNavigationBar(ILuaIntellisenseDocument document) { if (document == null) { return; } if (document.SyntaxEditorControl == null) { return; } var se = document.SyntaxEditorControl.As <ActiproSoftware.SyntaxEditor.SyntaxEditor>(); if (se == null) { return; } var panel = se.Parent.As <Control>(); if (panel == null) { return; } var navBar = panel.Controls["NavBar"]; if (navBar == null) { return; } panel.Controls.Remove(navBar); }
private static bool CanGoto(ILuaIntellisenseDocument document) { return ((document != null) && (document.SyntaxEditorControl != null) && (((ActiproSoftware.SyntaxEditor.SyntaxEditor)document.SyntaxEditorControl).SelectedView != null)); }
public void GotoDefinition(ILuaIntellisenseDocument document) { if (!CanGoto(document)) { return; } Func <Expression, List <LuatValue.IReference> > func = expression => { var definitions = new List <LuatValue.IReference>(); foreach (LuatValue value in expression.ResolvedValues.Values) { var variable = value as LuatVariable; if (variable != null) { definitions.Merge(variable.Assignments.ToArray()); } } return(definitions); }; GotoDefinitions("Goto definition", document, func); }
private void AddNavigationBar(ILuaIntellisenseDocument document) { if (!UseNavigationBar) { return; } if (document == null) { return; } if (document.SyntaxEditorControl == null) { return; } var se = document.SyntaxEditorControl.As <ActiproSoftware.SyntaxEditor.SyntaxEditor>(); if (se == null) { return; } var panel = se.Parent.As <Control>(); if (panel == null) { return; } if (panel.Controls["NavBar"] != null) { return; } var navBar = new NavigationBar { Width = panel.Width, Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right, Tag = "NavBar", Editor = se }; panel.Controls.Add(navBar); se.Top = navBar.Height; se.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Top; se.Dock = DockStyle.None; se.Width = panel.Width; se.Height = panel.Height - se.Top; }
private static LuatScript CreateLuatScript(ILuaIntellisenseDocument document) { var table = new LuatTable(null) { Description = Helpers.Decorate(document.Name, DecorationType.Code) }; var luatScript = LuatScript.Create(); luatScript.Table = table; luatScript.Path = document.Uri.LocalPath; luatScript.Reference = document; luatScript.Name = document.Name; return luatScript; }
private void UnregisterIntellipromptTipImageHandler(ILuaIntellisenseDocument document) { if (document == null) { return; } if (document.SyntaxEditorControl != null) { var se = (ActiproSoftware.SyntaxEditor.SyntaxEditor)document.SyntaxEditorControl; se.IntelliPromptTipImageRequested -= IntelliPromptTipImageRequested; } }
private void RegisterIntellipromptTipImageHandler(ILuaIntellisenseDocument document) { if (document == null) { return; } if (document.SyntaxEditorControl != null) { var se = (ActiproSoftware.SyntaxEditor.SyntaxEditor)document.SyntaxEditorControl; se.IntelliPromptTipImageRequested -= IntelliPromptTipImageRequested; // lame, but makes sure we don't register more than once se.IntelliPromptTipImageRequested += IntelliPromptTipImageRequested; } }
/// <summary> /// Triggers process of the given ILuaIntellisenseDocument /// </summary> /// <param name="script"></param> private void ParseScript(ILuaIntellisenseDocument script) { if (script == null) { return; } // don't use script.SyntaxEditorControl in case the file isn't open in the editor var document = new Document(); document.Text = script.Contents; document.Filename = script.Uri.LocalPath; document.Language = m_language; // triggers a reparse }
private static LuatScript CreateLuatScript(ILuaIntellisenseDocument document) { var table = new LuatTable(null) { Description = Helpers.Decorate(document.Name, DecorationType.Code) }; var luatScript = LuatScript.Create(); luatScript.Table = table; luatScript.Path = document.Uri.LocalPath; luatScript.Reference = document; luatScript.Name = document.Name; return(luatScript); }
public void GotoReference(ILuaIntellisenseDocument document) { if (!CanGoto(document)) { return; } Func <Expression, List <LuatValue.IReference> > func = expression => { var definitions = new List <LuatValue.IReference>(); foreach (LuatValue value in expression.ResolvedValues.Values) { definitions.Merge(value.References.ToArray()); } return(definitions); }; GotoDefinitions("Goto reference", document, func); }
private static bool CanRenameVariable(ILuaIntellisenseDocument document, out VariableExpression expression, out List <LuatValue.IReference> definitions) { expression = null; definitions = null; if (!CanGoto(document)) { return(false); } if (document.SyntaxEditorControl == null) { return(false); } var se = (ActiproSoftware.SyntaxEditor.SyntaxEditor)document.SyntaxEditorControl; if ((se.SelectedView == null) || (se.SelectedView.Selection == null)) { return(false); } expression = GetExpressionAt(se.Document, se.SelectedView.Selection.StartOffset) as VariableExpression; if (expression == null) { return(false); } definitions = new List <LuatValue.IReference>(); foreach (LuatValue value in expression.ResolvedValues.Values) { var variable = value.As <LuatVariable>(); if (variable != null) { definitions.Merge(variable.References.ToArray()); } } return(definitions.Count > 0); }
private void RegisterScript(ILuaIntellisenseDocument script, LuatTable parentPublicTable) { var table = new LuatTable(null); var publicTable = new LuatTable(table); // Chain the public tables using metatable indices so that a child script can // access the content of the parent's public table at global scope. publicTable.SetMetadataIndexTable(parentPublicTable); // Expose the content of the public table at global scope table.SetMetadataIndexTable(publicTable); // Register the script var luatScript = LuatScript.Create(); luatScript.Name = script.Name; luatScript.Table = table; luatScript.Path = script.Uri.LocalPath; luatScript.Reference = script; m_scripts.Add(luatScript); table.Description = Helpers.Decorate(script.Name, DecorationType.Code); }
public void RenameVariable(ILuaIntellisenseDocument document) { VariableExpression expression; List<LuatValue.IReference> definitions; if (!CanRenameVariable(document, out expression, out definitions)) return; using (var dialog = new RenameVariableForm()) { dialog.InputText = expression.DisplayText; var se = (ActiproSoftware.SyntaxEditor.SyntaxEditor)document.SyntaxEditorControl; if (dialog.ShowDialog(se) != DialogResult.OK) return; if (CheckVariableNameInUse(expression, dialog.InputText)) { const string message = "A variable with this name already exists. Do you want to continue?"; const string caption = "Warning"; if (MessageBox.Show(message, caption, MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.Cancel) return; } try { // save cursor and scroll pos to set it back to where it was after we are done replacing //int caretPos = se.Caret.Offset; //int scrollPos = se.SelectedView.FirstVisibleDisplayLineIndex; var options = new FindReplaceOptions { FindText = expression.DisplayText, MatchCase = true, MatchWholeWord = true, ReplaceText = dialog.InputText, SearchHiddenText = true, SearchType = FindReplaceSearchType.Normal }; se.Document.FindReplace.ReplaceAll(options); //// remove duplicates (for instance, if scripts are referenced multiple times in a project) //for (var i = 0; i < definitions.Count; ++i) //{ // var original = definitions[i]; // var duplicates = new List<LuatValue.IReference>(); // for (var j = i + 1; j < definitions.Count; ++j) // { // var potentialDuplicate = definitions[j]; // if ((original.Line == potentialDuplicate.Line) && // (original.TextRange.StartOffset == potentialDuplicate.TextRange.StartOffset) && // (original.TextRange.EndOffset == potentialDuplicate.TextRange.EndOffset) && // (string.Compare(original.Path, potentialDuplicate.Path, true) == 0)) // { // duplicates.Add(potentialDuplicate); // } // } // foreach (LuatValue.IReference duplicate in duplicates) // definitions.Remove(duplicate); //} //// remove spans that are included in larger spans //for (var i = 0; i < definitions.Count; ++i) //{ // var original = definitions[i]; // var duplicates = new List<LuatValue.IReference>(); // foreach (var potentialDuplicate in definitions) // { // if (ReferenceEquals(original, potentialDuplicate)) // continue; // if (string.Compare(original.Path, potentialDuplicate.Path, true) != 0) // continue; // if ((potentialDuplicate.TextRange.StartOffset >= original.TextRange.StartOffset) && // (potentialDuplicate.TextRange.EndOffset <= original.TextRange.EndOffset)) // { // duplicates.Add(potentialDuplicate); // } // } // foreach (LuatValue.IReference duplicate in duplicates) // definitions.Remove(duplicate); //} //// sort the references so we replace the text bottom to top to avoid invalidating the //// other references text range //definitions.Sort( // (a, b) => // { // TextRange aRange = ((SyntaxEditorTextRange)a.TextRange).ToTextRange(); // TextRange bRange = ((SyntaxEditorTextRange)b.TextRange).ToTextRange(); // return bRange.FirstOffset.CompareTo(aRange.FirstOffset); // }); //foreach (LuatValue.IReference reference in definitions) //{ // TextRange textRange = ((SyntaxEditorTextRange)reference.TextRange).ToTextRange(); // se.Document.ReplaceText(DocumentModificationType.Replace, textRange, dialog.InputText); //} //// adjust the position of the cursor based on changes made to the document //int diff = dialog.InputText.Length - expression.DisplayText.Length; //caretPos += (diff * (definitions.Count - 1)); //se.Caret.Offset = caretPos; //se.SelectedView.FirstVisibleDisplayLineIndex = scrollPos; } catch (Exception ex) { ex.ToString(); } } }
public bool CanRenameVariable(ILuaIntellisenseDocument document) { VariableExpression expression; List<LuatValue.IReference> definitions; return CanRenameVariable(document, out expression, out definitions); }
public void DocumentClosed(ILuaIntellisenseDocument document) { UnregisterIntellipromptTipImageHandler(document); RemoveNavigationBar(document); }
private static void GotoDefinitions(string title, ILuaIntellisenseDocument document, Func<Expression, List<LuatValue.IReference>> func) { if ((document == null) || (document.SyntaxEditorControl == null) || (func == null)) return; var se = (ActiproSoftware.SyntaxEditor.SyntaxEditor)document.SyntaxEditorControl; if ((se.Document == null) || (se.SelectedView == null)) return; var expression = GetExpressionAt(se.Document, se.SelectedView.Selection.StartOffset); if (expression == null) return; var definitions = func(expression); if (definitions == null) return; if (definitions.Count == 0) return; if (definitions.Count == 1) { definitions[0].Goto(); return; } using (var gfx = se.SelectedView.CreateGraphics()) { var menu = new ContextMenuStrip { ImageList = LuaIntellisenseIcons.GetImageList() }; SkinService.ApplyActiveSkin(menu); KeyValuePair<string, LuatValue.IReference[]>[] groups = definitions.GroupItems(a => a.Context, a => a); ToolStripLabel label; { label = new ToolStripLabel(title) {Enabled = false}; menu.Items.Add(label); } int index = 0; foreach (KeyValuePair<string, LuatValue.IReference[]> group in groups) { menu.Items.Add(new ToolStripSeparator()); if (groups.Length > 0) { label = new ToolStripLabel("Context: " + group.Key) { Enabled = false }; menu.Items.Add(label); } var items = new List<ToolStripItem>(); foreach (LuatValue.IReference definition in group.Value) { string text = GetReferenceText(definition, document.Project); string file = System.IO.Path.GetFileName(definition.Path); int line = definition.Line; LuatValue.GotoReference gotoRef = definition.Goto; var item = new ToolStripMenuItem { ImageIndex = (int)(definition.Value != null ? definition.Value.Type.Icon : LuaIntellisenseIconType.Unknown), Text = string.Format("&{0} {1}({2}): {3}", index++, file, line, text), Font = se.Font, Tag = line }; item.Width = (int)gfx.MeasureString(item.Text, item.Font).Width; item.Click += (s, e) => gotoRef(); items.Add(item); } menu.Items.AddRange(items.OrderBy(x => (int)x.Tag).ToArray()); } var rect = se.SelectedView.GetCharacterBounds(se.SelectedView.Selection.StartOffset); menu.Show(se, rect.Location); } }
private static bool CanGoto(ILuaIntellisenseDocument document) { return (document != null) && (document.SyntaxEditorControl != null) && (((ActiproSoftware.SyntaxEditor.SyntaxEditor)document.SyntaxEditorControl).SelectedView != null); }
private void AddNavigationBar(ILuaIntellisenseDocument document) { if (!UseNavigationBar) return; if (document == null) return; if (document.SyntaxEditorControl == null) return; var se = document.SyntaxEditorControl.As<ActiproSoftware.SyntaxEditor.SyntaxEditor>(); if (se == null) return; var panel = se.Parent.As<Control>(); if (panel == null) return; if (panel.Controls["NavBar"] != null) return; var navBar = new NavigationBar { Width = panel.Width, Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right, Tag = "NavBar", Editor = se }; panel.Controls.Add(navBar); se.Top = navBar.Height; se.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Top; se.Dock = DockStyle.None; se.Width = panel.Width; se.Height = panel.Height - se.Top; }
public void DocumentOpened(ILuaIntellisenseDocument document) { AddNavigationBar(document); RegisterIntellipromptTipImageHandler(document); ReparseDocuments(new[] { document }); }
private static void GotoDefinitions(string title, ILuaIntellisenseDocument document, Func <Expression, List <LuatValue.IReference> > func) { if ((document == null) || (document.SyntaxEditorControl == null) || (func == null)) { return; } var se = (ActiproSoftware.SyntaxEditor.SyntaxEditor)document.SyntaxEditorControl; if ((se.Document == null) || (se.SelectedView == null)) { return; } var expression = GetExpressionAt(se.Document, se.SelectedView.Selection.StartOffset); if (expression == null) { return; } var definitions = func(expression); if (definitions == null) { return; } if (definitions.Count == 0) { return; } if (definitions.Count == 1) { definitions[0].Goto(); return; } using (var gfx = se.SelectedView.CreateGraphics()) { var menu = new ContextMenuStrip { ImageList = LuaIntellisenseIcons.GetImageList() }; SkinService.ApplyActiveSkin(menu); KeyValuePair <string, LuatValue.IReference[]>[] groups = definitions.GroupItems(a => a.Context, a => a); ToolStripLabel label; { label = new ToolStripLabel(title) { Enabled = false }; menu.Items.Add(label); } int index = 0; foreach (KeyValuePair <string, LuatValue.IReference[]> group in groups) { menu.Items.Add(new ToolStripSeparator()); if (groups.Length > 0) { label = new ToolStripLabel("Context: " + group.Key) { Enabled = false }; menu.Items.Add(label); } var items = new List <ToolStripItem>(); foreach (LuatValue.IReference definition in group.Value) { string text = GetReferenceText(definition, document.Project); string file = System.IO.Path.GetFileName(definition.Path); int line = definition.Line; LuatValue.GotoReference gotoRef = definition.Goto; var item = new ToolStripMenuItem { ImageIndex = (int)(definition.Value != null ? definition.Value.Type.Icon : LuaIntellisenseIconType.Unknown), Text = string.Format("&{0} {1}({2}): {3}", index++, file, line, text), Font = se.Font, Tag = line }; item.Width = (int)gfx.MeasureString(item.Text, item.Font).Width; item.Click += (s, e) => gotoRef(); items.Add(item); } menu.Items.AddRange(items.OrderBy(x => (int)x.Tag).ToArray()); } var rect = se.SelectedView.GetCharacterBounds(se.SelectedView.Selection.StartOffset); menu.Show(se, rect.Location); } }
public bool CanGotoReference(ILuaIntellisenseDocument document) { return(CanGoto(document)); }
private void RegisterIntellipromptTipImageHandler(ILuaIntellisenseDocument document) { if (document == null) return; if (document.SyntaxEditorControl != null) { var se = (ActiproSoftware.SyntaxEditor.SyntaxEditor)document.SyntaxEditorControl; se.IntelliPromptTipImageRequested -= IntelliPromptTipImageRequested; // lame, but makes sure we don't register more than once se.IntelliPromptTipImageRequested += IntelliPromptTipImageRequested; } }
private void UnregisterIntellipromptTipImageHandler(ILuaIntellisenseDocument document) { if (document == null) return; if (document.SyntaxEditorControl != null) { var se = (ActiproSoftware.SyntaxEditor.SyntaxEditor)document.SyntaxEditorControl; se.IntelliPromptTipImageRequested -= IntelliPromptTipImageRequested; } }
private void RemoveNavigationBar(ILuaIntellisenseDocument document) { if (document == null) return; if (document.SyntaxEditorControl == null) return; var se = document.SyntaxEditorControl.As<ActiproSoftware.SyntaxEditor.SyntaxEditor>(); if (se == null) return; var panel = se.Parent.As<Control>(); if (panel == null) return; var navBar = panel.Controls["NavBar"]; if (navBar == null) return; panel.Controls.Remove(navBar); }
public bool CanGotoDefinition(ILuaIntellisenseDocument document) { return(CanGoto(document)); }
private static bool CanRenameVariable(ILuaIntellisenseDocument document, out VariableExpression expression, out List<LuatValue.IReference> definitions) { expression = null; definitions = null; if (!CanGoto(document)) return false; if (document.SyntaxEditorControl == null) return false; var se = (ActiproSoftware.SyntaxEditor.SyntaxEditor)document.SyntaxEditorControl; if ((se.SelectedView == null) || (se.SelectedView.Selection == null)) return false; expression = GetExpressionAt(se.Document, se.SelectedView.Selection.StartOffset) as VariableExpression; if (expression == null) return false; definitions = new List<LuatValue.IReference>(); foreach (LuatValue value in expression.ResolvedValues.Values) { var variable = value.As<LuatVariable>(); if (variable != null) definitions.Merge(variable.References.ToArray()); } return definitions.Count > 0; }
public void GotoDefinition(ILuaIntellisenseDocument document) { if (!CanGoto(document)) return; Func<Expression, List<LuatValue.IReference>> func = expression => { var definitions = new List<LuatValue.IReference>(); foreach (LuatValue value in expression.ResolvedValues.Values) { var variable = value as LuatVariable; if (variable != null) definitions.Merge(variable.Assignments.ToArray()); } return definitions; }; GotoDefinitions("Goto definition", document, func); }
public bool CanGotoReference(ILuaIntellisenseDocument document) { return CanGoto(document); }
public void GotoReference(ILuaIntellisenseDocument document) { if (!CanGoto(document)) return; Func<Expression, List<LuatValue.IReference>> func = expression => { var definitions = new List<LuatValue.IReference>(); foreach (LuatValue value in expression.ResolvedValues.Values) { definitions.Merge(value.References.ToArray()); } return definitions; }; GotoDefinitions("Goto reference", document, func); }
public void RenameVariable(ILuaIntellisenseDocument document) { VariableExpression expression; List <LuatValue.IReference> definitions; if (!CanRenameVariable(document, out expression, out definitions)) { return; } using (var dialog = new RenameVariableForm()) { dialog.InputText = expression.DisplayText; var se = (ActiproSoftware.SyntaxEditor.SyntaxEditor)document.SyntaxEditorControl; if (dialog.ShowDialog(se) != DialogResult.OK) { return; } if (CheckVariableNameInUse(expression, dialog.InputText)) { const string message = "A variable with this name already exists. Do you want to continue?"; const string caption = "Warning"; if (MessageBox.Show(message, caption, MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.Cancel) { return; } } try { // save cursor and scroll pos to set it back to where it was after we are done replacing //int caretPos = se.Caret.Offset; //int scrollPos = se.SelectedView.FirstVisibleDisplayLineIndex; var options = new FindReplaceOptions { FindText = expression.DisplayText, MatchCase = true, MatchWholeWord = true, ReplaceText = dialog.InputText, SearchHiddenText = true, SearchType = FindReplaceSearchType.Normal }; se.Document.FindReplace.ReplaceAll(options); //// remove duplicates (for instance, if scripts are referenced multiple times in a project) //for (var i = 0; i < definitions.Count; ++i) //{ // var original = definitions[i]; // var duplicates = new List<LuatValue.IReference>(); // for (var j = i + 1; j < definitions.Count; ++j) // { // var potentialDuplicate = definitions[j]; // if ((original.Line == potentialDuplicate.Line) && // (original.TextRange.StartOffset == potentialDuplicate.TextRange.StartOffset) && // (original.TextRange.EndOffset == potentialDuplicate.TextRange.EndOffset) && // (string.Compare(original.Path, potentialDuplicate.Path, true) == 0)) // { // duplicates.Add(potentialDuplicate); // } // } // foreach (LuatValue.IReference duplicate in duplicates) // definitions.Remove(duplicate); //} //// remove spans that are included in larger spans //for (var i = 0; i < definitions.Count; ++i) //{ // var original = definitions[i]; // var duplicates = new List<LuatValue.IReference>(); // foreach (var potentialDuplicate in definitions) // { // if (ReferenceEquals(original, potentialDuplicate)) // continue; // if (string.Compare(original.Path, potentialDuplicate.Path, true) != 0) // continue; // if ((potentialDuplicate.TextRange.StartOffset >= original.TextRange.StartOffset) && // (potentialDuplicate.TextRange.EndOffset <= original.TextRange.EndOffset)) // { // duplicates.Add(potentialDuplicate); // } // } // foreach (LuatValue.IReference duplicate in duplicates) // definitions.Remove(duplicate); //} //// sort the references so we replace the text bottom to top to avoid invalidating the //// other references text range //definitions.Sort( // (a, b) => // { // TextRange aRange = ((SyntaxEditorTextRange)a.TextRange).ToTextRange(); // TextRange bRange = ((SyntaxEditorTextRange)b.TextRange).ToTextRange(); // return bRange.FirstOffset.CompareTo(aRange.FirstOffset); // }); //foreach (LuatValue.IReference reference in definitions) //{ // TextRange textRange = ((SyntaxEditorTextRange)reference.TextRange).ToTextRange(); // se.Document.ReplaceText(DocumentModificationType.Replace, textRange, dialog.InputText); //} //// adjust the position of the cursor based on changes made to the document //int diff = dialog.InputText.Length - expression.DisplayText.Length; //caretPos += (diff * (definitions.Count - 1)); //se.Caret.Offset = caretPos; //se.SelectedView.FirstVisibleDisplayLineIndex = scrollPos; } catch (Exception ex) { ex.ToString(); } } }
/// <summary> /// Triggers process of the given ILuaIntellisenseDocument /// </summary> /// <param name="script"></param> private void ParseScript(ILuaIntellisenseDocument script) { if (script == null) return; // don't use script.SyntaxEditorControl in case the file isn't open in the editor var document = new Document(); document.Text = script.Contents; document.Filename = script.Uri.LocalPath; document.Language = m_language; // triggers a reparse }
public bool CanGotoDefinition(ILuaIntellisenseDocument document) { return CanGoto(document); }