/// <summary> Show a context menu over a virtual point (connection point). Shown when the developer right clicks over a connection point </summary> /// <param name="virtualPoint"> Target virtual point </param> private void ShowConnectionPointContextMenu(VirtualPoint virtualPoint) { var menu = new GenericMenu(); //create a generic menu menu.AddItem(new GUIContent(UILabels.Disconnect), false, () => { DisconnectVirtualPoint(virtualPoint, true); }); //Disconnect Connection Point menu.ShowAsContext(); //show menu at mouse position }
private static string GetMemberName(TextDocumentHandler handler) { string result = null; if (handler.Document != null && handler.Selection != null) { // If this doesn't work, then try "HOWTO: Get the code element at the cursor from a Visual Studio // .NET macro or add-in" (http://www.mztools.com/articles/2006/mz2006009.aspx). VirtualPoint activePoint = handler.Selection.ActivePoint; foreach (vsCMElement scope in ElementScopes) { try { CodeElement element = activePoint.CodeElement[scope]; if (element != null) { result = element.Name; break; } } catch (COMException) { // There's no element of the specified type around the specified point. } } } return(result); }
public SingleSelection(IMapEditToData map, Selection selection) { this.Anchor = new VirtualPoint(map, selection.AnchorPoint); this.Active = new VirtualPoint(map, selection.ActivePoint); this.Insertion = new VirtualPoint(map, selection.InsertionPoint); this.Affinity = selection.InsertionPointAffinity; }
private void RestoreActiveAndAnchorPoints() { var startPoint = new VirtualPoint(oldAnchor); var endPoint = new VirtualPoint(oldActivePoint); MakeSelection(startPoint, endPoint); }
private static string GetMemberName(TextDocumentHandler handler, Language language) { string result = null; ThreadHelper.ThrowIfNotOnUIThread(); if (handler.Document != null && handler.Selection != null) { // If this doesn't work, then try "HOWTO: Get the code element at the cursor from a Visual Studio // .NET macro or add-in" (http://www.mztools.com/articles/2006/mz2006009.aspx). VirtualPoint activePoint = handler.Selection.ActivePoint; foreach (vsCMElement scope in ElementScopes) { try { CodeElement element = activePoint.CodeElement[scope]; if (element != null && (scope != vsCMElement.vsCMElementNamespace || NamespaceLanguages.Contains(language))) { result = element.Name; break; } } #pragma warning disable CC0004 // Catch block cannot be empty. Comment explains. catch (COMException) { // There's no element of the specified type around the specified point. } #pragma warning restore CC0004 // Catch block cannot be empty } } return(result); }
private static Map AddVirtualPoints(this Map map) { var node1 = new VirtualPoint() { Id = 1, Origin = VirtualPointOrigin.Position1 }; var node2 = new VirtualPoint() { Id = 2, Origin = VirtualPointOrigin.Position2 }; var node3 = new VirtualPoint() { Id = 3, Origin = VirtualPointOrigin.Position1 }; var node4 = new VirtualPoint() { Id = 4, Origin = VirtualPointOrigin.Position2 }; map.Add(node1); map.Add(node2); map.Add(node3); map.Add(node4); var tagNode = map.Nodes.First(n => n is TagNode); var nodeLink = tagNode.NodeLinks.First(); nodeLink.AddVirtualPointAndCalculateItsOffset(node1); nodeLink.AddVirtualPointAndCalculateItsOffset(node2); nodeLink.AddVirtualPointAndCalculateItsOffset(node3); nodeLink.AddVirtualPointAndCalculateItsOffset(node4); return(map); }
// private bool ParseLineDirective(string directive, ref int linenumber, ref string filename) // { // if (!directive.StartsWith("#line ")) // return false; // // int findquote = directive.IndexOf('"'); // if (findquote == -1 || findquote < 7) // return false; // // string linestring = directive.Substring(6, findquote - 6); // linenumber = Convert.ToInt32(linestring); // // int findlastquote = directive.LastIndexOf('"'); // if (findlastquote == findquote || findlastquote >= directive.Length) // return false; // // filename = directive.Substring(findquote + 1, findlastquote - findquote - 1); // // return true; // } // Returns if the current position is valid, and whether the redirected file exists //private bool CheckGotoOriginal(out string redirectedfile, out int redirectedline) //{ //TODO: well, it would be nice to have this, // but I have to first find the #line --without-- moving the cursor // which would be nice but I don't know how to do that currently. //does FindPattern maybe work? //} private CodeElement FindBestElement(VirtualPoint activepoint, CodeElements elements) { foreach (CodeElement ce in elements) { // if (ce.EndPoint.LessThan(activepoint)) // { // continue; // } // else if (ce.StartPoint.GreaterThan(activepoint)) // { // break; // } //ok, on the right line now //now find the correct range if (ce.StartPoint.EqualTo(activepoint) || ce.EndPoint.EqualTo(activepoint) || (ce.StartPoint.LessThan(activepoint) && ce.EndPoint.GreaterThan(activepoint))) { //this is the element we want, actually we should keep looking to see if we get a better match CodeElement childce = FindBestElement(activepoint, ce.Children); if (childce != null) { return(childce); } return(ce); } } return(null); }
//Returns the first class in the file public CodeClass GetClass(ProjectItem activeDocument) { ThreadHelper.ThrowIfNotOnUIThread(); CodeElements fileCodeModel = activeDocument.FileCodeModel.CodeElements; TextSelection textSelection = Dte.ActiveDocument.Selection as TextSelection; VirtualPoint point = textSelection.ActivePoint; CodeElement codeElement = point.CodeElement[vsCMElement.vsCMElementClass]; if (codeElement != null) { if (codeElement.Kind == vsCMElement.vsCMElementClass) //verify if it's a class { return(codeElement as CodeClass); } else if (codeElement.Kind == vsCMElement.vsCMElementVariable) { CodeVariable codeVariable = codeElement as CodeVariable; codeElement = codeVariable.Parent as CodeElement; return(codeElement as CodeClass); } else if (codeElement.Kind == vsCMElement.vsCMElementFunction) { CodeFunction codeFunction = codeElement as CodeFunction; codeElement = codeFunction.Parent as CodeElement; return(codeElement as CodeClass); } } ErrorHandler.ShowMessageBox("Please select a class element."); return(null); }
private void update(int reset = 0) { if (reset == 1) { _data.Text = ""; _data.Line = ""; _data.Anchor = 1; _data.Active = 1; _data.LineBegOffset = 1; _data.LineEndOffset = 1; } else { TextSelection selection = App.ActiveDocument.Selection as TextSelection; VirtualPoint active = selection.ActivePoint; VirtualPoint anchor = selection.AnchorPoint; EditPoint point0 = active.CreateEditPoint(); EditPoint point1 = active.CreateEditPoint(); point0.StartOfLine(); point1.EndOfLine(); _data.Line = point0.GetText(point1); _data.LineBegOffset = toPosition(point0.AbsoluteCharOffset); _data.LineEndOffset = toPosition(point1.AbsoluteCharOffset); point0.StartOfDocument(); point1.EndOfDocument(); _data.Text = point0.GetText(point1); _data.Anchor = toPosition(anchor.AbsoluteCharOffset); _data.Active = toPosition(active.AbsoluteCharOffset); } }
/// <summary> /// Init constructor. /// </summary> public CodeEditPoint(DTE2 application, TextSelection selection, VirtualPoint virtualStartEditPoint, ProjectItem projectItem) { this.application = application; this.selection = selection; this.virtualStartEditPoint = virtualStartEditPoint; this.projectItem = projectItem; }
private string get_method_name(string text, VirtualPoint cursPoint) { // Match the regular expression pattern against a text string. string pat = @"method\s+(.+?)\s*\("; Regex r = new Regex(pat, RegexOptions.IgnoreCase); string methodName = string.Empty; Match m = r.Match(text); while (m.Success) { if (m.Index > cursPoint.AbsoluteCharOffset) { break; } Group g = m.Groups[1]; // CaptureCollection cc = g.Captures; CaptureCollection cc = g.Captures; methodName = cc[0].ToString(); m = m.NextMatch(); } return(methodName); }
private TextBlock FindCurrentStatement(IList <TSqlStatement> statements, VirtualPoint caret, ExecScope scope) { if (statements == null || statements.Count == 0) { return(null); } foreach (var statement in statements) { if (scope == ExecScope.Inner) { IList <TSqlStatement> statementList = GetInnerStatements(statement); TextBlock currentStatement = FindCurrentStatement(statementList, caret, scope); if (currentStatement != null) { return(currentStatement); } } if (IsCaretInsideStatement(statement, caret)) { return(GetTextBlockFromStatement(statement)); } } return(null); }
private static string GetClassName(VirtualPoint virtualPoint) { if (virtualPoint != null) { var codeClass = virtualPoint.CodeElement[vsCMElement.vsCMElementClass] as CodeClass; if (codeClass != null) { return(codeClass.Name); } var codeInterface = virtualPoint.CodeElement[vsCMElement.vsCMElementInterface] as CodeInterface; if (codeInterface != null) { return(codeInterface.Name); } var codeStruct = virtualPoint.CodeElement[vsCMElement.vsCMElementStruct] as CodeStruct; if (codeStruct != null) { return(codeStruct.Name); } var codeEnum = virtualPoint.CodeElement[vsCMElement.vsCMElementEnum] as CodeEnum; if (codeEnum != null) { return(codeEnum.Name); } } return(string.Empty); }
private void MakeSelection(VirtualPoint startPoint, VirtualPoint endPoint) { var selection = (TextSelection)document.Selection; selection.MoveToLineAndOffset(startPoint.Line, startPoint.LineCharOffset); selection.SwapAnchor(); selection.MoveToLineAndOffset(endPoint.Line, endPoint.LineCharOffset, true); }
/// <summary> /// 指定の位置の左の文字を取得します。 /// </summary> private static string GetLeftText(VirtualPoint point, int count) { var editPoint = point.CreateEditPoint(); editPoint.CharLeft(count); return(editPoint.GetText(1)); }
public static List <BezierSurfaceWorldObject> GetAdjacentSurfaces( VirtualPoint virtualPoint ) { return(virtualPoint.GetAdjacentObjects() .Where(t => t is BezierSurfaceWorldObject) .Cast <BezierSurfaceWorldObject>() .ToList()); }
private int locate(int off) { TextSelection selection = _dte.ActiveDocument.Selection as TextSelection; VirtualPoint active = selection.ActivePoint; EditPoint point0 = active.CreateEditPoint(); EditPoint point1 = active.CreateEditPoint(); point0.StartOfDocument(); point1.MoveToAbsoluteOffset(off); string text = point0.GetText(point1); return (off - 1) + length(text, "\r\n", text.Length - 1); }
/// <summary> /// /// </summary> /// <param name="beg"></param> /// <param name="end"></param> /// <param name="value"></param> /// <returns></returns> public bool replace(int beg, int end, string value) { TextSelection selection = _dte.ActiveDocument.Selection as TextSelection; VirtualPoint active = selection.ActivePoint; EditPoint point0 = active.CreateEditPoint(); EditPoint point1 = active.CreateEditPoint(); point0.MoveToAbsoluteOffset(offset(beg)); point1.MoveToAbsoluteOffset(offset(end)); point0.ReplaceText(point1, value, 1); return true; }
/*************************************************************************** * exec */ /** * Retrieves the selected block of text and replaces it with the result of a * call to <c>convertBlock</c>. * * @param sender Command object. ***************************************************************************/ public override void exec(object sender, EventArgs e) { /*----------------------------------------*/ /* Get the document and selection. Indent */ /* offset is current caret position. */ /*----------------------------------------*/ Document doc = app.ActiveDocument; TextSelection select = (TextSelection)doc.Selection; VirtualPoint top = select.TopPoint; VirtualPoint bottom = select.BottomPoint; int indent = select.CurrentColumn - 1; /*--------------------------------------------*/ /* Set edit points at the start and end of */ /* the lines where selection starts and ends. */ /*--------------------------------------------*/ EditPoint ep1 = top.CreateEditPoint(); EditPoint ep2 = bottom.CreateEditPoint(); ep1.MoveToLineAndOffset(top.Line, 1); ep2.MoveToLineAndOffset(bottom.Line, bottom.LineLength + 1); /*---------------------------------------*/ /* Convert the block from the content of */ /* the start and end line of selection. */ /*---------------------------------------*/ string block = convertBlock(ep1.GetText(ep2), indent); if (block != null) { /*------------------------------------*/ /* Open an undo context if none open. */ /*------------------------------------*/ UndoContext undo = app.UndoContext; if (!undo.IsOpen) { undo.Open(GetType().Name, false); } /*----------------------------------------------------------*/ /* Replace the selected block, move the caret to the indent */ /* position on the last line, and close the Undo Context. */ /*----------------------------------------------------------*/ ep1.Delete(ep2); ep1.Insert(block); select.MoveToLineAndOffset(ep1.Line, indent + 1, false); undo.Close(); } }
/// <summary> /// 文字列の終了位置を作成します。 /// </summary> private static EditPoint CreateEndPoint(VirtualPoint point, EditPoint startPoint) { var result = point.CreateEditPoint(); if (point.AtEndOfLine || result.GetText(1) == " ") { return(result); } result = startPoint.CreateEditPoint(); result.WordRight(); return(result); }
public Tuple <int, int> GetVirtualPointCoordinate(VirtualPoint vp) { var realVirtualPoint = vp.GetAdjacentVirtualPointFor(this); Debug.Assert(realVirtualPoint != null); var index = _virtualPoints.IndexOf(realVirtualPoint); var rowLength = 3 * _segmentsU + 1; var x = index % rowLength; var y = index / rowLength; return(new Tuple <int, int>(x, y)); }
/// <summary> /// CodeElementFromPoint /// </summary> /// <param name="fcm">FileCodeModel</param> /// <param name="point">VirtualPoint</param> /// <param name="scopes">vsCMElement</param> /// <returns></returns> private CodeElement CodeElementFromPoint(FileCodeModel fcm, VirtualPoint point, params vsCMElement[] scopes) { foreach (var scope in scopes) { CodeElement codeElement = fcm.CodeElementFromPoint(point, scope); if (codeElement != null) { return(codeElement); } } return(null); }
public static EnvDTE.TextPoint GetCursorTextPoint(DTE dte) { VirtualPoint objCursorTextPoint = null; try { var objTextDocument = (TextDocument)dte.ActiveDocument.Object(); objCursorTextPoint = objTextDocument.Selection.ActivePoint; } // ReSharper disable once EmptyGeneralCatchClause catch (Exception) { //swallow exception } return(objCursorTextPoint); }
private bool GetIncludeInfo(ref string path) { //first we need to find the text thing Document doc = App().ActiveDocument; if (doc != null) { TextDocument text = (TextDocument)doc.Object(""); //this is the current selection's top line # int line = text.Selection.CurrentLine; int col = text.Selection.CurrentColumn; VirtualPoint activepoint = text.Selection.ActivePoint; EditPoint point = activepoint.CreateEditPoint(); point.EndOfLine(); EditPoint endfound = null; TextRanges found = null; bool result = point.FindPattern("opinclude[ \t]+\\\"{.*}\\\"", (int)(vsFindOptions.vsFindOptionsBackwards | vsFindOptions.vsFindOptionsRegularExpression), ref endfound, ref found); if (result) { int foundline = endfound.Line; //NOTE: I think this is correct... int offset = line - foundline - 1; //TODO: get this 1 to be constant in macro expansion! TextRange fullmatch = found.Item(1); // need to break out if the active point wasn't in the line if (fullmatch.StartPoint.Line != activepoint.Line) { return(false); } TextRange filematch = found.Item(2); string filetext = filematch.StartPoint.GetText(filematch.EndPoint); //NOTE: this returns what was in the opinclude, but does not resolve the path path = filetext; return(true); } } return(false); }
/// <summary> /// Initializes selectionTopPoint and selectionBotPoint from active document's selection /// </summary> protected void InitializeSelection() { Document currentDocument = VisualLocalizerPackage.Instance.DTE.ActiveDocument; currentlyProcessedItem = currentDocument.ProjectItem; TextSelection currentSelection = currentDocument.Selection as TextSelection; if (currentSelection == null || currentSelection.IsEmpty) { throw new Exception("Cannot perform this operation on an empty selection."); } selectionTopPoint = currentSelection.BottomPoint; selectionBotPoint = currentSelection.TopPoint; }
private int GetLineNumber() { // get the DTE2 object var dte2 = GetDTE2(); if (dte2 == null) { return(0); } // get currently active cursor location var selection = (TextSelection)dte2.ActiveDocument.Selection; VirtualPoint point = selection.ActivePoint; return(point.Line); // get the line number from the location }
public EditedLine GetEditedLine() { TextSelection textSelection = _document.Selection; if (!String.IsNullOrEmpty(textSelection.Text)) { return(new EditedLine(textSelection.Text, 0)); } VirtualPoint point = textSelection.ActivePoint; EditPoint editPoint = point.CreateEditPoint(); string line = editPoint.GetLines(point.Line, point.Line + 1); int caret = point.LineCharOffset - 1; return(new EditedLine(line, caret)); }
private int GetColumnNumber() { // get the DTE2 object DTE2 dte2 = GetDTE2(); if (dte2 == null) { return(0); } // get currently active cursor position var selection = (TextSelection)dte2.ActiveDocument.Selection; VirtualPoint point = selection.ActivePoint; return(point.DisplayColumn); // get the column number from the location }
/// <summary> /// 文字列の開始位置を作成します。 /// </summary> private static EditPoint CreateStartPoint(VirtualPoint point) { var result = point.CreateEditPoint(); if (point.AtStartOfLine || GetLeftText(point, 1) == " ") { return(result); } result.WordLeft(); var tempPoint = result.CreateEditPoint(); tempPoint.WordRight(); return(point.AbsoluteCharOffset == tempPoint.AbsoluteCharOffset ? point.CreateEditPoint() : result); }
public static void TestCodeElementAtCurrentPoint(VirtualPoint activePoint) { foreach (vsCMElement item in Enum.GetValues(typeof(vsCMElement))) { try { Debug.WriteLine("testing " + item.ToString()); var function = activePoint.CodeElement[item] as CodeFunction; if (function != null) { Debug.WriteLine("found something @: " + item.ToString()); } } catch (Exception) { } } }