public static IList <TextSpan> GetHiddenRegions(this IVsEnumHiddenRegions enumHiddenRegions)
        {
            IList <TextSpan> regions = null;

            uint count = GetCount(enumHiddenRegions);

            if (count > 0)
            {
                regions = new List <TextSpan>((int)count);

                var hiddenRegions = new IVsHiddenRegion[count];

                enumHiddenRegions.Reset();
                enumHiddenRegions.Next(count, hiddenRegions, out count);

                for (int i = 0; i < count; i++)
                {
                    IVsHiddenRegion hiddenRegion = hiddenRegions[i];

                    uint state = 0;
                    hiddenRegion.GetState(out state);
                    if ((state & (uint)HIDDEN_REGION_STATE.hrsExpanded) == 0)
                    {
                        TextSpan[] pSpan = new TextSpan[1];
                        hiddenRegion.GetSpan(pSpan);
                        regions.Add(pSpan[0]);
                    }
                }
            }

            return(regions);
        }
        public static IList<TextSpan> GetHiddenRegions(this IVsEnumHiddenRegions enumHiddenRegions)
        {
            IList<TextSpan> regions = null;

            uint count = GetCount(enumHiddenRegions);

            if (count > 0)
            {
                regions = new List<TextSpan>((int)count);

                var hiddenRegions = new IVsHiddenRegion[count];

                enumHiddenRegions.Reset();
                enumHiddenRegions.Next(count, hiddenRegions, out count);

                for (int i = 0; i < count; i++)
                {
                    IVsHiddenRegion hiddenRegion = hiddenRegions[i];

                    uint state = 0;
                    hiddenRegion.GetState(out state);
                    if ((state & (uint)HIDDEN_REGION_STATE.hrsExpanded) == 0)
                    {
                        TextSpan[] pSpan = new TextSpan[1];
                        hiddenRegion.GetSpan(pSpan);
                        regions.Add(pSpan[0]);
                    }
                }
            }

            return regions;
        }
Beispiel #3
0
        //todo:尽在apsx下面才有效,cs文件下无效,不知道为什么
        public void ToggleRegions()
        {
            IVsHiddenTextSession session = HiddenTextSession;

            TextSpan[] aspan = new TextSpan[1];
            aspan[0] = new VSTextView(VSTextView.ActiveTextView).GetWholeTextSpan();

            //获取IVsEnumHiddenRegions
            IVsEnumHiddenRegions ppenum;

            session.EnumHiddenRegions((uint)FIND_HIDDEN_REGION_FLAGS.FHR_ALL_REGIONS, 0, aspan, out ppenum);

            MessageBox.Show(GetHiddenRegionCount(ppenum).ToString());

            //遍历IVsEnumHiddenRegions
            uint fetched;

            IVsHiddenRegion[] aregion = new IVsHiddenRegion[1];
            while (ppenum.Next(1, aregion, out fetched) == VSConstants.S_OK && fetched == 1)
            {
                uint dwState;
                aregion[0].GetState(out dwState);
                dwState ^= (uint)HIDDEN_REGION_STATE.hrsExpanded;
                aregion[0].SetState(dwState, (uint)CHANGE_HIDDEN_REGION_FLAGS.chrDefault);
            }
        }
Beispiel #4
0
        public int GetTipText(IVsHiddenRegion pHidReg, string[] pbstrText = null)
        {
            //pHidReg.Invalidate((uint)CHANGE_HIDDEN_REGION_FLAGS.chrNonUndoable);
            TextSpan[] textSpans = new TextSpan[1];
            pHidReg.GetSpan(textSpans);
            pbstrText[0] = DateTime.Now.ToString();

            return VSConstants.S_OK;
        }
Beispiel #5
0
        public int GetTipText(IVsHiddenRegion pHidReg, string[] pbstrText = null)
        {
            //pHidReg.Invalidate((uint)CHANGE_HIDDEN_REGION_FLAGS.chrNonUndoable);
            TextSpan[] textSpans = new TextSpan[1];
            pHidReg.GetSpan(textSpans);
            pbstrText[0] = DateTime.Now.ToString();

            return(VSConstants.S_OK);
        }
Beispiel #6
0
 public int GetMarkerCommandInfo(IVsHiddenRegion pHidReg, int iItem, string[] pbstrText, uint[] pcmdf)
 {
     MessageBox.Show("GetMarkerCommandInfo");
     return VSConstants.S_OK;
 }
Beispiel #7
0
 public int GetMarkerCommandInfo(IVsHiddenRegion pHidReg, int iItem, string[] pbstrText, uint[] pcmdf)
 {
     MessageBox.Show("GetMarkerCommandInfo");
     return(VSConstants.S_OK);
 }
Beispiel #8
0
 public int ExecMarkerCommand(IVsHiddenRegion region, int cmd)
 {
     return NativeMethods.E_NOTIMPL;
 }
Beispiel #9
0
 public int GetTipText(IVsHiddenRegion region, string[] result)
 {
     if (result != null && result.Length > 0)
     {
         TextSpan[] aspan = new TextSpan[1];
         NativeMethods.ThrowOnFailure(region.GetSpan(aspan));
         result[0] = this.GetText(aspan[0]);
     }
     return NativeMethods.S_OK;
 }
Beispiel #10
0
 public void ToggleRegions()
 {
     IVsHiddenTextSession session = GetHiddenTextSession();
     IVsEnumHiddenRegions ppenum;
     TextSpan[] aspan = new TextSpan[1];
     aspan[0] = GetDocumentSpan();
     NativeMethods.ThrowOnFailure(session.EnumHiddenRegions((uint)FIND_HIDDEN_REGION_FLAGS.FHR_BY_CLIENT_DATA, (uint)SourceConstants.HiddenRegionCookie, aspan, out ppenum));
     uint fetched;
     IVsHiddenRegion[] aregion = new IVsHiddenRegion[1];
     using (new CompoundAction(this, "ToggleAllRegions"))
     {
         while (ppenum.Next(1, aregion, out fetched) == NativeMethods.S_OK && fetched == 1)
         {
             uint dwState;
             aregion[0].GetState(out dwState);
             dwState ^= (uint)HIDDEN_REGION_STATE.hrsExpanded;
             NativeMethods.ThrowOnFailure(aregion[0].SetState(dwState,
                 (uint)CHANGE_HIDDEN_REGION_FLAGS.chrDefault));
         }
     }
 }
        //todo:尽在apsx下面才有效,cs文件下无效,不知道为什么
        public void ToggleRegions()
        {
            IVsHiddenTextSession session = HiddenTextSession;
            TextSpan[] aspan = new TextSpan[1];
            aspan[0] = new VSTextView(VSTextView.ActiveTextView).GetWholeTextSpan();

            //获取IVsEnumHiddenRegions
            IVsEnumHiddenRegions ppenum;
            session.EnumHiddenRegions((uint)FIND_HIDDEN_REGION_FLAGS.FHR_ALL_REGIONS, 0, aspan, out ppenum);

            MessageBox.Show(GetHiddenRegionCount(ppenum).ToString());

            //遍历IVsEnumHiddenRegions
            uint fetched;
            IVsHiddenRegion[] aregion = new IVsHiddenRegion[1];
            while (ppenum.Next(1, aregion, out fetched) == VSConstants.S_OK && fetched == 1)
            {
                uint dwState;
                aregion[0].GetState(out dwState);
                dwState ^= (uint)HIDDEN_REGION_STATE.hrsExpanded;
                aregion[0].SetState(dwState, (uint)CHANGE_HIDDEN_REGION_FLAGS.chrDefault);
            }
        }
Beispiel #12
0
        /// <include file='doc\Source.uex' path='docs/doc[@for="Source.GetTipText"]/*' />
        public virtual int GetTipText(IVsHiddenRegion region, string[] result)
        {
            if (result != null && result.Length > 0) {
                TextSpan[] aspan = new TextSpan[1];
                NativeMethods.ThrowOnFailure(region.GetSpan(aspan));

                // Limit lines.
                TextSpan span = aspan[0];
                int spanLineCount = span.iEndLine - span.iStartLine + 1;
                bool truncated = spanLineCount > lineCountLimitForGetTipText;
                StringBuilder stringBuilder =
                    GetLineSpans(span)
                        .Take(lineCountLimitForGetTipText)
                        .Select(s => LimitLineSpan(s, lineLengthLimitForGetTipText))
                        .Select(lineSpan => this.GetText(lineSpan.span) + (lineSpan.truncated ? "..." : String.Empty))
                        .Aggregate(new StringBuilder(), (sb, lineText) => sb.AppendLine(lineText));

                result[0] = stringBuilder.ToString() + (truncated ? " ..." : String.Empty);
            }
            return NativeMethods.S_OK;
        }
Beispiel #13
0
 public void OnHiddenRegionChange(IVsHiddenRegion pHidReg, HIDDEN_REGION_EVENT EventCode, int fBufferModifiable)
 {
     MessageBox.Show(EventCode.ToString());
 }
Beispiel #14
0
 public int MakeBaseSpanVisible(IVsHiddenRegion pHidReg, TextSpan[] pBaseSpan)
 {
     MessageBox.Show("MakeBaseSpanVisible");
     return(VSConstants.S_OK);
 }
Beispiel #15
0
 public int MakeBaseSpanVisible(IVsHiddenRegion pHidReg, TextSpan[] pBaseSpan)
 {
     MessageBox.Show("MakeBaseSpanVisible");
     return VSConstants.S_OK;
 }
Beispiel #16
0
 /// <include file='doc\Source.uex' path='docs/doc[@for="Source.OnHiddenRegionChange"]/*' />
 public virtual void OnHiddenRegionChange(IVsHiddenRegion region, HIDDEN_REGION_EVENT evt, int fBufferModifiable)
 {
     if (evt == HIDDEN_REGION_EVENT.hreAfterRegionCollapsed) {
         collapsed++;
     } else if (evt == HIDDEN_REGION_EVENT.hreAfterRegionExpanded) {
         collapsed--;
     }
 }
Beispiel #17
0
 public void OnHiddenRegionChange(IVsHiddenRegion pHidReg, HIDDEN_REGION_EVENT EventCode, int fBufferModifiable)
 {
     MessageBox.Show(EventCode.ToString());
 }
Beispiel #18
0
        /// <include file='doc\Source.uex' path='docs/doc[@for="Source.ProcessHiddenRegions"]/*' />
        public virtual void ProcessHiddenRegions(ArrayList hiddenRegions)
        {
            if (!this.doOutlining) {
                return;
            }

            // Compare the existing regions with the new regions and
            // remove any that do not match the new regions.
            IVsHiddenTextSession session = GetHiddenTextSession();
            IVsEnumHiddenRegions ppenum;
            TextSpan[] aspan = new TextSpan[1];
            aspan[0] = GetDocumentSpan();
            NativeMethods.ThrowOnFailure(session.EnumHiddenRegions((uint)FIND_HIDDEN_REGION_FLAGS.FHR_BY_CLIENT_DATA, (uint)Source.HiddenRegionCookie, aspan, out ppenum));
            uint fetched;
            IVsHiddenRegion[] aregion = new IVsHiddenRegion[1];
            int matched = 0;
            int removed = 0;
            int added = 0;

            // Create a list of IVsHiddenRegion objects, sorted in the same order that the
            // authoring sink sorts.  This is necessary because VS core editor does NOT return
            // the regions in the same order that we add them.
            ArrayList regions = new ArrayList();
            ArrayList spans = new ArrayList();

            while (ppenum.Next(1, aregion, out fetched) == NativeMethods.S_OK && fetched == 1) {
                NativeMethods.ThrowOnFailure(aregion[0].GetSpan(aspan));
                TextSpan s = aspan[0];
                int i = spans.Count - 1;
                while (i >= 0) {
                    TextSpan s2 = (TextSpan)spans[i];
                    if (TextSpanHelper.StartsAfterStartOf(s, s2))
                        break;
                    i--;
                }
                spans.Insert(i + 1, s);
                regions.Insert(i + 1, aregion[0]);
            }

            // Iterate over session hidden regions
            // Session hidden regions are the ones the editor currently knows about
            ArrayList regionsToAdd = new ArrayList();
            int iHiddenRegion = 0;
            int cHiddenRegion = hiddenRegions.Count;
            for (int i = 0; i < regions.Count; ++i)
            {
                IVsHiddenRegion sessionHiddenRegion = (IVsHiddenRegion)regions[i];
                TextSpan sessionSpan = (TextSpan)spans[i];

                // Iterate over preceeding sink hidden regions
                // Sink hidden regions are the ones which resulted from a parse
                NewHiddenRegion hiddenRegion = new NewHiddenRegion();
                while (iHiddenRegion < cHiddenRegion)
                {
                    hiddenRegion = (NewHiddenRegion)hiddenRegions[iHiddenRegion];
                    if (hiddenRegion.tsHiddenText.iStartLine >= sessionSpan.iStartLine)
                    {
                        break;
                    }

                    // Add to "ToAdd" regions (add boxed copy to avoid duplicate copies in sink and "ToAdd" collections)
                    // DevNote: Collect "ToAdd" regions rather than doing a hiddenRegions.RemoveAt() to avoid quadratic perf
                    regionsToAdd.Add(hiddenRegions[iHiddenRegion]);

                    ++iHiddenRegion;
                }

                // Check whether matching sink region
                if ((iHiddenRegion < cHiddenRegion) &&
                    TextSpanHelper.IsSameSpan(hiddenRegion.tsHiddenText, sessionSpan) &&
                    HasSameBanner(hiddenRegion, sessionHiddenRegion))
                {
                    // Match (and continue)
                    ++matched;
                    ++iHiddenRegion;
                }
                else
                {
                    // Remove from session (and continue)
                    NativeMethods.ThrowOnFailure(sessionHiddenRegion.Invalidate((int)CHANGE_HIDDEN_REGION_FLAGS.chrNonUndoable));
                    ++removed;
                }
            }

            // Add following sink hidden regions to "ToAdd" regions
            if (iHiddenRegion < cHiddenRegion)
            {
                regionsToAdd.AddRange(hiddenRegions.GetRange(iHiddenRegion, (cHiddenRegion - iHiddenRegion)));
            }

            // Populate given hidden region collection with regions to add
            // DevNote:  This side effect existed in an earlier quadratic algorithm based on removing from
            // the given collection using hiddenRegions.RemoveAt().  Some VSIP may depend on this side effect
            hiddenRegions.Clear();
            hiddenRegions.AddRange(regionsToAdd);

            int start = Environment.TickCount;
            int count = hiddenRegions.Count;
            int iRegion = 0;
            if (count > 0) {
                // For very large documents this can take a while, so add them in chunks of
                // 1000 and stop after 5 seconds.
                int maxTime = this.LanguageService.Preferences.MaxRegionTime;
                int chunkSize = 1000;
                NewHiddenRegion[] chunk = new NewHiddenRegion[chunkSize];
                while (iRegion < count && TimeUtilities.TimeSince(start) < maxTime)
                {
                    int j = 0;
                    NewHiddenRegion r;
                    while (iRegion < count && j < chunkSize)
                    {
                        r = (NewHiddenRegion)hiddenRegions[iRegion];
                        if (!TextSpanHelper.ValidSpan(this, r.tsHiddenText)) {
            #if	LANGTRACE
                            Debug.Assert(false, "Invalid span " + r.tsHiddenText.iStartLine + "," + r.tsHiddenText.iStartIndex + "," + r.tsHiddenText.iEndLine + "," + r.tsHiddenText.iEndIndex);
            #endif
                            break;
                        } else {
                            chunk[j] = r;
                            added++;
                        }
                        iRegion++;
                        j++;
                    }
                    int hr = session.AddHiddenRegions((int)CHANGE_HIDDEN_REGION_FLAGS.chrNonUndoable, j, chunk, null);
                    if (NativeMethods.Failed(hr)) {
                        break; // stop adding if we start getting errors.
                    }
                }
            }

            // Check whether all hidden regions processed
            if (iRegion == count)
            {
                // Depersist outlining (only once)
                if (!haveDepersistedOutlining)
                {
                    haveDepersistedOutlining = true;
                    IVsTextViewEx view = this.service.GetPrimaryViewForSource(this) as IVsTextViewEx;
                    if (view != null)
                    {
                        view.PersistOutliningState();
                    }
                }
            }

            #if	PERFTRACE
            int diff = TimeUtilities.TimeSince(start);
            Trace.WriteLine(String.Format(CultureInfo.InvariantCulture, "Hidden Regions: Matched={0}, Removed={1}, Addded={2}/{3} in {4} ms", matched, removed, added, hiddenRegions.Count, diff));
            #endif
        }
Beispiel #19
0
        private void RemoveHiddenRegions()
        {
            IVsHiddenTextSession session = GetHiddenTextSession();
            IVsEnumHiddenRegions ppenum;
            TextSpan[] aspan = new TextSpan[1];
            aspan[0] = GetDocumentSpan();
            NativeMethods.ThrowOnFailure(session.EnumHiddenRegions((uint)FIND_HIDDEN_REGION_FLAGS.FHR_BY_CLIENT_DATA, (uint)SourceConstants.HiddenRegionCookie, aspan, out ppenum));
            uint fetched;
            IVsHiddenRegion[] aregion = new IVsHiddenRegion[1];
            while (ppenum.Next(1, aregion, out fetched) == NativeMethods.S_OK && fetched == 1)
            {
                NativeMethods.ThrowOnFailure(aregion[0].Invalidate((int)CHANGE_HIDDEN_REGION_FLAGS.chrNonUndoable));
            }

        }
Beispiel #20
0
 internal void ToggleRegions()
 {
     IVsHiddenTextSession session = GetHiddenTextSession();
     IVsEnumHiddenRegions ppenum;
     TextSpan[] aspan = new TextSpan[1];
     aspan[0] = GetDocumentSpan();
     NativeMethods.ThrowOnFailure(session.EnumHiddenRegions((uint)FIND_HIDDEN_REGION_FLAGS.FHR_BY_CLIENT_DATA, (uint)Source.HiddenRegionCookie, aspan, out ppenum));
     uint fetched;
     bool expandAll =false;
     uint numRegions;
     ppenum.GetCount(out numRegions);
     Debug.Assert(numRegions>=0, "GetCount returned a negative number?!");
     if (!(collapsed == 0 || collapsed == numRegions)) {
         //not all regions are in the same state -- expand all
         expandAll = true;
     }
     IVsHiddenRegion[] aregion = new IVsHiddenRegion[1];
     using (new CompoundAction(this, "ToggleAllRegions")) {
         while (ppenum.Next(1, aregion, out fetched) == NativeMethods.S_OK && fetched == 1) {
             uint dwState;
             if (expandAll) {
                 dwState = (uint)HIDDEN_REGION_STATE.hrsExpanded;
             } else {
                 aregion[0].GetState(out dwState);
                 dwState ^= (uint)HIDDEN_REGION_STATE.hrsExpanded;
             }
             NativeMethods.ThrowOnFailure(aregion[0].SetState(dwState,
                 (uint)CHANGE_HIDDEN_REGION_FLAGS.chrDefault));
         }
     }
 }
Beispiel #21
0
 public void OnHiddenRegionChange(IVsHiddenRegion region, HIDDEN_REGION_EVENT evt, int fBufferModifiable)
 {
 }
Beispiel #22
0
 //Banner comparison: in the case of editor controlled region, this is a noop
 //otherwise, compare banners
 //caveat is that GetBanner rountrips null to "...".
 private bool HasSameBanner(NewHiddenRegion r,IVsHiddenRegion region)
 {
     uint behavior;
     region.GetBehavior(out behavior);
     if (behavior == (uint)HIDDEN_REGION_BEHAVIOR.hrbEditorControlled && r.dwBehavior == (uint)HIDDEN_REGION_BEHAVIOR.hrbEditorControlled)
     {
         return true; //the banner text is always a fixed string, which is "..." by default
     }
     string currBanner;
     region.GetBanner(out currBanner);
     //<STRIP>DevDiv185498: Regression from RTM: Collapsed portions of XAML do not stay collapsed</STRIP>
     return r.pszBanner == currBanner || (r.pszBanner == null && currBanner == "...");
 }
Beispiel #23
0
 public int GetMarkerCommandInfo(IVsHiddenRegion region, int item, string[] outText, uint[] flags)
 {
     if (flags != null && flags.Length > 0)
         flags[0] = 0;
     if (outText != null && outText.Length > 0)
         outText[0] = null;
     return NativeMethods.E_NOTIMPL;
 }
Beispiel #24
0
 public int ExecMarkerCommand(IVsHiddenRegion pHidReg, int iItem)
 {
     MessageBox.Show("ExecMarkerCommand");
     return VSConstants.S_OK;
 }
Beispiel #25
0
 public int MakeBaseSpanVisible(IVsHiddenRegion region, TextSpan[] span)
 {
     return NativeMethods.E_NOTIMPL;
 }
Beispiel #26
0
 public int ExecMarkerCommand(IVsHiddenRegion pHidReg, int iItem)
 {
     MessageBox.Show("ExecMarkerCommand");
     return(VSConstants.S_OK);
 }