/// <summary> /// Checks the availability of insert chartpoint menu item /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CheckAvailability(object sender, EventArgs e) { // get the menu that fired the event var menuCommand = sender as OleMenuCommand; if (menuCommand != null) { menuCommand.Visible = false; menuCommand.Enabled = false; if (extensionServ.GetMode() != EMode.Design) { return; } IProjectChartPoints pPnts = Globals.processor.GetProjectChartPoints(Globals.dte.ActiveDocument.ProjectItem.ContainingProject.Name); if (pPnts == null) { Globals.processor.AddProjectChartPoints(Globals.dte.ActiveDocument.ProjectItem.ContainingProject.Name, out pPnts); } checkPnt = pPnts.CheckCursorPos(); if (checkPnt != null) { if (checkPnt.elems.Count > 0) { menuCommand.Visible = true; menuCommand.Enabled = true; } else { checkPnt = null; } } } }
public SelectVarsDlg(ICheckCPPoint checkPnt) { InitializeComponent(); foreach (ICheckElem classVar in checkPnt.elems) { AddVariable(classVar); } }
public ICheckCPPoint CheckCursorPos() { ICheckCPPoint checkPnt = null; Document activeDoc = ChartPoints.Globals.dte.ActiveDocument; string projName = activeDoc.ProjectItem.ContainingProject.Name; TextSelection sel = (TextSelection)activeDoc.Selection; TextPoint caretPnt = (TextPoint)sel.ActivePoint; VCCodeElement targetClassElem; for (;;) { // checks if we are in text document if (activeDoc == null) { break; } var textDoc = activeDoc.Object() as TextDocument; if (textDoc == null) { break; } // we work only with project items ProjectItem projItem = activeDoc.ProjectItem; if (projItem == null) { break; } // only c++ items FileCodeModel fcModel = projItem.FileCodeModel; if (fcModel == null) { break; } if (fcModel.Language != CodeModelLanguageConstants.vsCMLanguageVC) { break; } vcCodeModel.Synchronize();// !!! MOVE TO METHOD ??? // chartpoint allowed only in class methods CodeElement elem = fcModel.CodeElementFromPoint(caretPnt, vsCMElement.vsCMElementFunction); if (elem == null) { break; } if (elem.Kind != vsCMElement.vsCMElementFunction) { break; } VCCodeFunction targetFunc = (VCCodeFunction)elem; if (targetFunc == null) { break; } // check that we are in method definition (not declaration) in case of declaration in one file & definition in other if (!targetFunc.File.Equals(activeDoc.FullName, StringComparison.OrdinalIgnoreCase)) { break; } // we are working only with class methods not global function targetFunc.CodeModel.Synchronize(); targetFunc.CodeModel.SynchronizeFiles(); foreach (CodeElement _cl in targetFunc.CodeModel.Classes) { foreach (CodeElement _f in _cl.Children) { if (targetFunc.FullName.Equals(_f.FullName, StringComparison.OrdinalIgnoreCase)) { targetFunc = (VCCodeFunction)_f; break; } } } targetClassElem = (VCCodeElement)targetFunc.Parent; if (targetClassElem == null) { break; } if (targetClassElem.Kind != vsCMElement.vsCMElementClass) { targetClassElem = null; break; } VCCodeClass ownerClass = (VCCodeClass)targetClassElem; TextPoint startFuncBody = targetFunc.StartPointOf[vsCMPart.vsCMPartBody, vsCMWhere.vsCMWhereDefinition]; TextPoint endFuncBody = targetFunc.EndPointOf[vsCMPart.vsCMPartBody, vsCMWhere.vsCMWhereDefinition]; EditPoint startPnt = startFuncBody.CreateEditPoint(); EditPoint endPnt = endFuncBody.CreateEditPoint(); startPnt.FindPattern("{", (int)vsFindOptions.vsFindOptionsBackwards); endPnt.FindPattern("}"); if ((caretPnt.Line > startPnt.Line && caretPnt.Line < endPnt.Line) || (caretPnt.Line == startPnt.Line && caretPnt.LineCharOffset >= startPnt.LineCharOffset) || (caretPnt.Line == endPnt.Line && caretPnt.LineCharOffset <= endPnt.LineCharOffset)) { // Oh, oh you're in the body, now.. (c) int linePos = (caretPnt.Line == startPnt.Line ? startPnt.LineCharOffset + 1 : 1 /*0*/); checkPnt = new CheckCPPoint(ownerClass, projName, activeDoc.Name, System.IO.Path.GetFullPath(activeDoc.FullName).ToLower(), caretPnt.Line, linePos); return(checkPnt); } break; } return(checkPnt); }