Exemplo n.º 1
0
        /// <summary>
        /// Attempts to find a <see cref="ICollapsible" /> associated with the specified <see
        /// cref="IMembers" />.
        /// </summary>
        /// <param name="item">The IMembers CodeItem.</param>
        /// <param name="manager">The outlining manager to get all regions</param>
        /// <param name="textView">The textview to find collapsibles in</param>
        /// <returns>The <see cref="ICollapsible" /> on the same starting line, otherwise null.</returns>
        private static ICollapsible FindCollapsibleFromCodeItem(CodeItem item, IOutliningManager manager, IWpfTextView textView)
        {
            if (item.Kind == CodeItemKindEnum.ImplementedInterface)
            {
                return(null);
            }
            if (item.StartLine > textView.TextBuffer.CurrentSnapshot.LineCount)
            {
                return(null);
            }

            try
            {
                var snapshotLine = textView.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(item.StartLine);
                var collapsibles = manager.GetAllRegions(snapshotLine.Extent);

                return((from collapsible in collapsibles
                        let startLine = GetStartLineForCollapsible(collapsible)
                                        where startLine == item.StartLine
                                        select collapsible).FirstOrDefault());
            }
            catch (ArgumentOutOfRangeException e)
            {
                LogHelper.Log($"FindCollapsibleFromCodeItem failed for item {item.Name}, exception: {e.Message}");
                return(null);
            }
            catch (ObjectDisposedException e)
            {
                LogHelper.Log($"FindCollapsibleFromCodeItem failed because of disposed {e.ObjectName}");
                return(null);
            }
        }
Exemplo n.º 2
0
        public CodeViewUserControl(Window window, ColumnDefinition column = null,
                                   IWpfTextView textView           = null, IOutliningManager outliningManager = null,
                                   VisualStudioWorkspace workspace = null, CodeNavMargin margin               = null, DTE dte = null)
        {
            InitializeComponent();

            // Setup viewmodel as datacontext
            CodeDocumentViewModel = new CodeDocumentViewModel();
            DataContext           = CodeDocumentViewModel;

            // Setup backgroundworker to update datacontext
            _backgroundWorker = new BackgroundWorker {
                WorkerSupportsCancellation = true
            };
            _backgroundWorker.DoWork             += BackgroundWorker_DoWork;
            _backgroundWorker.RunWorkerCompleted += BackgroundWorker_RunWorkerCompleted;

            _window          = window;
            _column          = column;
            TextView         = textView;
            OutliningManager = outliningManager;
            _workspace       = workspace;
            _margin          = margin;
            Dte = dte;

            VSColorTheme.ThemeChanged += VSColorTheme_ThemeChanged;
        }
Exemplo n.º 3
0
    public void VsTextViewCreated(IVsTextView textViewAdapter)
    {
        IComponentModel componentModel = (IComponentModel)ServiceProvider.GlobalProvider.GetService(typeof(SComponentModel));

        if (componentModel != null)
        {
            IOutliningManagerService outliningManagerService = componentModel.GetService <IOutliningManagerService>();
            _editorAdaptersFactoryService = componentModel.GetService <IVsEditorAdaptersFactoryService>();
            if (outliningManagerService != null)
            {
                if (textViewAdapter != null && _editorAdaptersFactoryService != null)
                {
                    var textView     = _editorAdaptersFactoryService.GetWpfTextView(textViewAdapter);
                    var snapshot     = textView.TextSnapshot;
                    var snapshotSpan = new Microsoft.VisualStudio.Text.SnapshotSpan(snapshot, new Microsoft.VisualStudio.Text.Span(0, snapshot.Length));
                    _outliningManager = outliningManagerService.GetOutliningManager(textView);
                    var regions = _outliningManager.GetAllRegions(snapshotSpan);
                    foreach (var reg in regions)
                    {
                        _outliningManager.TryCollapse(reg);
                    }
                }
            }
        }
    }
Exemplo n.º 4
0
        public static void SyncAllRegions(IOutliningManager manager, IWpfTextView textView, IEnumerable <CodeItem> document)
        {
            if (manager == null)
            {
                return;
            }

            _manager  = manager;
            _textView = textView;

            foreach (var item in document)
            {
                if (!(item is IMembers))
                {
                    continue;
                }

                var collapsible = FindCollapsibleFromCodeItem(item, manager, textView);

                if (collapsible == null)
                {
                    (item as IMembers).IsExpanded = true;
                }
                else
                {
                    (item as IMembers).IsExpanded = !collapsible.IsCollapsed;
                }

                (item as IMembers).IsExpandedChanged += OnIsExpandedChanged;

                SyncAllRegions(manager, textView, (item as IMembers).Members);
            }
        }
Exemplo n.º 5
0
        internal static IIncrementalSearch CreateIncrementalSearch(
            ITextView textView,
            IVimLocalSettings settings,
            IVimData vimData,
            ISearchService search = null,
            IOutliningManager outliningManager = null,
            IStatusUtil statusUtil             = null)
        {
            vimData    = vimData ?? new VimData();
            search     = search ?? CreateSearchService(settings.GlobalSettings);
            statusUtil = statusUtil ?? new StatusUtil();
            var nav        = CreateTextStructureNavigator(textView.TextBuffer);
            var operations = CreateCommonOperations(
                textView: textView,
                localSettings: settings,
                outlining: outliningManager,
                vimData: vimData,
                searchService: search);

            return(new IncrementalSearch(
                       operations,
                       settings,
                       nav,
                       statusUtil,
                       vimData));
        }
Exemplo n.º 6
0
        public CodeNavMargin(IWpfTextViewHost textViewHost, DTE dte, IOutliningManager outliningManager,
                             VisualStudioWorkspace workspace, MarginSideEnum side)
        {
            // Wire up references for the event handlers in RegisterEvents
            _dte              = dte;
            _textView         = textViewHost.TextView;
            _window           = GetWindow(textViewHost, dte);
            _outliningManager = outliningManager;
            _workspace        = workspace;
            MarginSide        = side;

            // If we can not find the window we belong to we can not do anything
            if (_window == null)
            {
                return;
            }

            // Add the view/content to the margin area
            _codeNavGrid   = CreateGrid(textViewHost);
            _codeNavColumn = _codeNavGrid.ColumnDefinitions[Settings.Default.MarginSide == MarginSideEnum.Left ? 0 : 2];
            Children.Add(_codeNavGrid);

            RegisterEvents();

            LogHelper.Log($"CodeNav initialized for {_window.Caption}");
        }
 /// <summary>
 /// Gets or creates an adornment manager for a particular text view.
 /// </summary>
 public static AdornmentManager GetOrCreateAdornmentManager(IWpfTextView textView, string adornmentLayer, IOutliningManager outliningManager, Logger logger) {
   Contract.Requires(textView != null);
   Contract.Requires(!String.IsNullOrEmpty(adornmentLayer));
   Contract.Requires(outliningManager != null);
   Contract.Requires(logger != null);
   Contract.Ensures(Contract.Result<AdornmentManager>() != null);
   return textView.Properties.GetOrCreateSingletonProperty<AdornmentManager>(adornmentLayer, delegate { return new AdornmentManager(textView, adornmentLayer, outliningManager, logger); });
 }
Exemplo n.º 8
0
 public FoldingManagerAdapter(
     IWpfTextView textView,
     IOutliningManagerService outliningManagerService)
 {
     _outliningManager = outliningManagerService.GetOutliningManager(textView);
     _outliningManager.RegionsExpanded  += OnExpanded;
     _outliningManager.RegionsCollapsed += OnCollapsed;
 }
        public void TextViewCreated(IWpfTextView textView)
        {
            IOutliningManager outliningManager = OutliningManagerService?.GetOutliningManager(textView);

            if (outliningManager != null)
            {
                outliningManager.RegionsChanged += OutliningManager_RegionsChanged;
            }
        }
        internal IEnumerable <ICollapsible> GetCollapsiblesForCurrentSelection(IOutliningManager outliningManager, ITextView textView)
        {
            if (outliningManager == null)
            {
                return(null);
            }

            // Try for all collapsibles which are contained within the selection span
            SnapshotSpan  selectionSnapshotSpan    = textView.Selection.StreamSelectionSpan.SnapshotSpan;
            ITextSnapshot selectionSnapshot        = selectionSnapshotSpan.Snapshot;
            var           intersectingCollapsibles = outliningManager.GetAllRegions(selectionSnapshotSpan);
            var           filteredCollapsibles     = intersectingCollapsibles.Where(collapsible => selectionSnapshotSpan.Contains(collapsible.Extent.GetSpan(selectionSnapshot)));
            var           tornoffCollapsibles      = GetTornoffCollapsibles(filteredCollapsibles);

            if (tornoffCollapsibles != null)
            {
                return(tornoffCollapsibles);
            }

            // Try for innermost collapsibles which intersect and start within the selection span
            filteredCollapsibles = intersectingCollapsibles.Where(collapsible => selectionSnapshotSpan.Contains(collapsible.Extent.GetSpan(selectionSnapshot).Start));
            tornoffCollapsibles  = GetInnermostCollapsibles(selectionSnapshot, filteredCollapsibles);
            if (tornoffCollapsibles != null)
            {
                return(tornoffCollapsibles);
            }

            // Try for all collapsibles which are contained within the selection's first line
            ITextSnapshotLine selectionStartLine = selectionSnapshot.GetLineFromPosition(selectionSnapshotSpan.Start);
            SnapshotSpan      selectionFirstLine = new SnapshotSpan(selectionSnapshot, selectionStartLine.Start, selectionStartLine.Length);

            intersectingCollapsibles = outliningManager.GetAllRegions(selectionFirstLine);
            filteredCollapsibles     = intersectingCollapsibles.Where(collapsible => selectionFirstLine.Contains(collapsible.Extent.GetSpan(selectionSnapshot)));
            tornoffCollapsibles      = GetTornoffCollapsibles(filteredCollapsibles);
            if (tornoffCollapsibles != null)
            {
                return(tornoffCollapsibles);
            }

            // Try for innermost collapsibles which intersect and start within the selection's first line
            filteredCollapsibles = intersectingCollapsibles.Where(collapsible => selectionFirstLine.Contains(collapsible.Extent.GetSpan(selectionSnapshot).Start));
            tornoffCollapsibles  = GetInnermostCollapsibles(selectionSnapshot, filteredCollapsibles);
            if (tornoffCollapsibles != null)
            {
                return(tornoffCollapsibles);
            }

            // Try for innermost collapsibles which simply intersect the selection's first line
            tornoffCollapsibles = GetInnermostCollapsibles(selectionSnapshot, intersectingCollapsibles);
            if (tornoffCollapsibles != null)
            {
                return(tornoffCollapsibles);
            }

            return(null);
        }
Exemplo n.º 11
0
        public static void EnsureCollapsed(this IOutliningManager outliningManager)
        {
            outliningManager.ToggleAllOutliningExpansion();

            if ((outliningManager.GetOutliningState(outliningManager.Document.CurrentSnapshot.SnapshotRange) & OutliningState.HasExpandedNodeStart)
                == OutliningState.HasExpandedNodeStart)
            {
                outliningManager.ToggleAllOutliningExpansion();
            }
        }
        public ITagger <T> CreateTagger <T>(ITextBuffer buffer) where T : ITag
        {
            IOutliningManager manager = UserOutliningManager.GetManager(buffer);

            if (typeof(T) == typeof(IOutliningRegionTag))
            {
                return(manager.GetOutliningTagger() as ITagger <T>);
            }
            return(manager.GetGlyphTagger() as ITagger <T>);
        }
        private void OutliningManager_RegionsChanged(object sender, RegionsChangedEventArgs e)
        {
            const string xmlDocCollapsedFormStart = "/// <summary>";

            IOutliningManager outliningManager = sender as IOutliningManager;

            outliningManager.CollapseAll(e.AffectedSpan, c => c?.CollapsedForm?.ToString()?.StartsWith(xmlDocCollapsedFormStart) ?? false && !c.IsCollapsed && c.IsCollapsible);

            //Unsubscribe from RegionsChanged after initial change
            outliningManager.RegionsChanged -= OutliningManager_RegionsChanged;
        }
Exemplo n.º 14
0
        private RegionExpander(IWpfTextView view, IOutliningManager outliningManager)
        {
            _view = view ?? throw new ArgumentNullException("view");
            if (outliningManager == null)
            {
                return;
            }
            _outliningManager = outliningManager;

            _view.Closed += OnViewClosed;
            _outliningManager.RegionsCollapsed += OnRegionCollapsed;
        }
Exemplo n.º 15
0
        private async Task ExpandAllRegionsContainingSpanAsync(SnapshotSpan selectedSpan, IWpfTextView textView)
        {
            IOutliningManager outliningManager = await ServiceProvider.GetOutliningManagerAsync(textView);

            if (outliningManager == null)
            {
                return;
            }

            outliningManager.GetCollapsedRegions(selectedSpan, exposedRegionsOnly: false)
            .ForEach(region => outliningManager.Expand(region));
        }
Exemplo n.º 16
0
        private RegionTextViewHandler(IWpfTextView textView, IOutliningManagerService outliningManagerService)
        {
            _outliningManager = outliningManagerService.GetOutliningManager(textView);

            if (_outliningManager == null)
            {
                return;
            }

            _textView = textView;
            _outliningManager.RegionsCollapsed += OnRegionsCollapsed;
            _textView.Closed += OnClosed;
        }
Exemplo n.º 17
0
        public static IFoldManager CreateFoldManager(
            ITextView textView,
            IStatusUtil statusUtil             = null,
            IOutliningManager outliningManager = null)
        {
            statusUtil = statusUtil ?? new StatusUtil();
            var option = FSharpOption.CreateForReference(outliningManager);

            return(new FoldManager(
                       textView,
                       new FoldData(textView.TextBuffer),
                       statusUtil,
                       option));
        }
        DiagnosticService(IWpfTextView textView, IComponentModel componentModel) {
            var viewTagAggregatorFactoryService = componentModel.GetService<IViewTagAggregatorFactoryService>();
            var outliningManagerService         = componentModel.GetService<IOutliningManagerService>();

            _textView           = textView;
            _errorTagAggregator = viewTagAggregatorFactoryService.CreateTagAggregator<DiagnosticErrorTag>(textView);
            _outliningManager   = outliningManagerService.GetOutliningManager(textView);
            _diagnosticMapping  = new Dictionary<DiagnosticSeverity, ReadOnlyCollection<IMappingTagSpan<DiagnosticErrorTag>>>();
            _waitingForAnalysis = true;
            
            _textView.Closed                       += OnTextViewClosed;
            _textView.TextBuffer.Changed           += OnTextBufferChanged;
            _errorTagAggregator.BatchedTagsChanged += OnBatchedTagsChanged;
        }
Exemplo n.º 19
0
        public void R_OutlineToggleAll()
        {
            string text = _files.LoadDestinationFile("lsfit.r");

            using (var script = new TestScript(text, RContentTypeDefinition.ContentType)) {
                script.DoIdle(500);

                IOutliningManagerService svc = EditorShell.Current.ExportProvider.GetExportedValue <IOutliningManagerService>();
                IOutliningManager        mgr = svc.GetOutliningManager(EditorWindow.CoreEditor.View);
                var snapshot = EditorWindow.TextBuffer.CurrentSnapshot;

                var viewLines = EditorWindow.CoreEditor.View.TextViewLines;
                viewLines.Count.Should().Be(40);
                script.DoIdle(500);

                EditorWindow.ExecCommand(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.OUTLN_TOGGLE_ALL);
                script.DoIdle(1000);

                IEnumerable <ICollapsed> collapsed = mgr.GetCollapsedRegions(new SnapshotSpan(snapshot, new Span(0, snapshot.Length)));
                collapsed.Count().Should().Be(20);

                EditorWindow.ExecCommand(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.OUTLN_TOGGLE_ALL);
                script.DoIdle(500);

                viewLines = EditorWindow.CoreEditor.View.TextViewLines;
                viewLines.Count.Should().Be(40);

                EditorWindow.ExecCommand(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.OUTLN_STOP_HIDING_ALL);
                script.DoIdle(200);
                mgr.Enabled.Should().Be(false);

                EditorWindow.ExecCommand(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.OUTLN_START_AUTOHIDING);
                script.DoIdle(200);
                mgr.Enabled.Should().Be(true);

                script.MoveDown(9);
                EditorWindow.ExecCommand(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.OUTLN_TOGGLE_CURRENT);
                script.DoIdle(500);

                collapsed = mgr.GetCollapsedRegions(new SnapshotSpan(snapshot, new Span(0, snapshot.Length)));
                collapsed.Count().Should().Be(1);

                EditorWindow.ExecCommand(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.OUTLN_TOGGLE_CURRENT);
                script.DoIdle(200);

                collapsed = mgr.GetCollapsedRegions(new SnapshotSpan(snapshot, new Span(0, snapshot.Length)));
                collapsed.Count().Should().Be(0);
            }
        }
Exemplo n.º 20
0
        public async Task R_OutlineToggleAll()
        {
            string text = _files.LoadDestinationFile("lsfit.r");

            using (var script = await _editorHost.StartScript(_exportProvider, text, "filename", RContentTypeDefinition.ContentType, null)) {
                script.DoIdle(500);

                IOutliningManagerService svc = _exportProvider.GetExportedValue <IOutliningManagerService>();
                IOutliningManager        mgr = svc.GetOutliningManager(script.View);
                var snapshot = script.TextBuffer.CurrentSnapshot;

                var viewLines = script.View.TextViewLines;
                viewLines.Count.Should().Be(22);
                script.DoIdle(500);

                script.Execute(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.OUTLN_TOGGLE_ALL);
                script.DoIdle(1000);

                IEnumerable <ICollapsed> collapsed = mgr.GetCollapsedRegions(new SnapshotSpan(snapshot, new Span(0, snapshot.Length)));
                collapsed.Count().Should().Be(20);

                script.Execute(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.OUTLN_TOGGLE_ALL);
                script.DoIdle(500);

                viewLines = script.View.TextViewLines;
                viewLines.Count.Should().Be(22);

                script.Execute(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.OUTLN_STOP_HIDING_ALL);
                script.DoIdle(200);
                mgr.Enabled.Should().Be(false);

                script.Execute(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.OUTLN_START_AUTOHIDING);
                script.DoIdle(200);
                mgr.Enabled.Should().Be(true);

                script.MoveDown(9);
                script.Execute(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.OUTLN_TOGGLE_CURRENT);
                script.DoIdle(500);

                collapsed = mgr.GetCollapsedRegions(new SnapshotSpan(snapshot, new Span(0, snapshot.Length)));
                collapsed.Count().Should().Be(1);

                script.Execute(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.OUTLN_TOGGLE_CURRENT);
                script.DoIdle(200);

                collapsed = mgr.GetCollapsedRegions(new SnapshotSpan(snapshot, new Span(0, snapshot.Length)));
                collapsed.Count().Should().Be(0);
            }
        }
Exemplo n.º 21
0
        private void OnClosed(object sender, EventArgs e)
        {
            if (_outliningManager != null)
            {
                _outliningManager.RegionsCollapsed -= OnRegionsCollapsed;
            }

            if (_textView != null)
            {
                _textView.Closed -= OnClosed;
            }

            _textView         = null;
            _outliningManager = null;
        }
Exemplo n.º 22
0
 private void Create(params string[] lines)
 {
     _textView          = EditorUtil.CreateTextView(lines);
     _visualBuffer      = _textView.TextViewModel.VisualBuffer;
     _adhocOutliner     = EditorUtil.FactoryService.AdhocOutlinerFactory.GetAdhocOutliner(_textView.TextBuffer);
     _outliningeManager = EditorUtil.FactoryService.OutliningManagerService.GetOutliningManager(_textView);
     _statusUtil        = new Mock <IStatusUtil>(MockBehavior.Strict);
     _foldData          = EditorUtil.FactoryService.FoldManagerFactory.GetFoldData(_textView.TextBuffer);
     _foldManagerRaw    = new FoldManager(
         _textView,
         _foldData,
         _statusUtil.Object,
         FSharpOption.Create(EditorUtil.FactoryService.OutliningManagerService.GetOutliningManager(_textView)));
     _foldManager = _foldManagerRaw;
 }
Exemplo n.º 23
0
        /// <summary>
        /// Maps the line number to the real line number as it's currently displayed in the text view.
        /// So if a region is collapsed, all diagnostics in this region should be mapped to the same line.
        /// </summary>
        /// <param name="textView">The <see cref="IWpfTextView"/>.</param>
        /// <param name="lineNumber">The number of the line.</param>
        /// <param name="outliningManager">The <see cref="IOutliningManager"/>.</param>
        /// <returns>The real line number.</returns>
        public static int GetRealLineNumber(IWpfTextView textView, int lineNumber, IOutliningManager outliningManager)
        {
            try
            {
                // a line could not get any further than 0 even by collapsing regions
                if (lineNumber == 0)
                {
                    return(0);
                }

                // if no snapshot line found return 0
                var lineSnapshot = textView.GetSnapshotForLineNumber(lineNumber);
                if (lineSnapshot == null)
                {
                    return(0);
                }

                // if no collapsed region than line number fits as normal
                var snapshotSpan = lineSnapshot.Extent;
                var region       = outliningManager?.GetCollapsedRegions(snapshotSpan) ?? Enumerable.Empty <ICollapsible>();
                if (!region.Any())
                {
                    return(lineNumber);
                }

                // I assume that the longest collapsed region is the outermost
                var regionSnapshot = region
                                     .Select(x => x.Extent.GetSpan(textView.TextSnapshot))
                                     .ToDictionary(x => x.Length)
                                     .OrderByDescending(x => x.Key)
                                     .First()
                                     .Value;

                var collapsedLineNumber = textView.TextSnapshot.GetLineNumberFromPosition(regionSnapshot.End.Position);
                return(collapsedLineNumber);
            }
            catch (ObjectDisposedException ex)
            {
                if (ex.ObjectName == "OutliningMnger")
                {
                    // TODO: when we have a logger service add logging
                }

                // I assume that this case seems to happen, if the TextView gets closed and we receive a
                // DiagnosticChanged event right in the time frame before we dispose the whole container graph.
                return(lineNumber);
            }
        }
Exemplo n.º 24
0
 private void Create(params string[] lines)
 {
     _textView = CreateTextView(lines);
     _textBuffer = _textView.TextBuffer;
     _visualBuffer = _textView.TextViewModel.VisualBuffer;
     _adhocOutliner = EditorUtilsFactory.GetOrCreateOutliner(_textView.TextBuffer);
     _outliningeManager = OutliningManagerService.GetOutliningManager(_textView);
     _statusUtil = new Mock<IStatusUtil>(MockBehavior.Strict);
     _foldData = FoldManagerFactory.GetFoldData(_textView.TextBuffer);
     _foldManagerRaw = new FoldManager(
         _textView,
         _foldData,
         _statusUtil.Object,
         FSharpOption.Create(OutliningManagerService.GetOutliningManager(_textView)));
     _foldManager = _foldManagerRaw;
 }
Exemplo n.º 25
0
        internal static ICommonOperations CreateCommonOperations(
            ITextView textView,
            IVimLocalSettings localSettings,
            IOutliningManager outlining            = null,
            IStatusUtil statusUtil                 = null,
            ISearchService searchService           = null,
            IUndoRedoOperations undoRedoOperations = null,
            IVimData vimData = null,
            IVimHost vimHost = null,
            ITextStructureNavigator navigator = null,
            IClipboardDevice clipboardDevice  = null,
            IFoldManager foldManager          = null)
        {
            var editorOperations = EditorUtil.GetOperations(textView);
            var editorOptions    = EditorUtil.FactoryService.EditorOptionsFactory.GetOptions(textView);
            var jumpList         = new JumpList(new TrackingLineColumnService());
            var keyMap           = new KeyMap();

            foldManager        = foldManager ?? new FoldManager(textView.TextBuffer);
            statusUtil         = statusUtil ?? new StatusUtil();
            searchService      = searchService ?? CreateSearchService(localSettings.GlobalSettings);
            undoRedoOperations = undoRedoOperations ??
                                 new UndoRedoOperations(statusUtil, FSharpOption <ITextUndoHistory> .None, editorOperations);
            vimData         = vimData ?? new VimData();
            vimHost         = vimHost ?? new MockVimHost();
            navigator       = navigator ?? CreateTextStructureNavigator(textView.TextBuffer);
            clipboardDevice = clipboardDevice ?? new MockClipboardDevice();
            var operationsData = new OperationsData(
                editorOperations,
                editorOptions,
                foldManager,
                jumpList,
                keyMap,
                localSettings,
                outlining != null ? FSharpOption.Create(outlining) : FSharpOption <IOutliningManager> .None,
                CreateRegisterMap(clipboardDevice),
                searchService,
                statusUtil,
                textView,
                undoRedoOperations,
                vimData,
                vimHost,
                navigator);

            return(new CommonOperations(operationsData));
        }
Exemplo n.º 26
0
        public void TextViewCreated(IWpfTextView textView)
        {
            if (OutliningManagerService == null || textView == null)
            {
                return;
            }

            IOutliningManager outliningManager = OutliningManagerService.GetOutliningManager(textView);

            if (outliningManager == null)
            {
                return;
            }

            outliningManager.RegionsChanged += OnRegionsChanged;
            wpfTextView = textView;
        }
Exemplo n.º 27
0
 internal static ICommonOperations CreateCommonOperations(
     ITextView textView,
     IVimLocalSettings localSettings,
     IOutliningManager outlining = null,
     IStatusUtil statusUtil = null,
     ISearchService searchService = null,
     IUndoRedoOperations undoRedoOperations = null,
     IVimData vimData = null,
     IVimHost vimHost = null,
     ITextStructureNavigator navigator = null,
     IClipboardDevice clipboardDevice = null,
     IFoldManager foldManager = null)
 {
     var editorOperations = EditorUtil.GetOperations(textView);
     var editorOptions = EditorUtil.FactoryService.EditorOptionsFactory.GetOptions(textView);
     var jumpList = new JumpList(new TrackingLineColumnService());
     var keyMap = new KeyMap();
     foldManager = foldManager ?? new FoldManager(textView.TextBuffer);
     statusUtil = statusUtil ?? new StatusUtil();
     searchService = searchService ?? CreateSearchService(localSettings.GlobalSettings);
     undoRedoOperations = undoRedoOperations ??
                          new UndoRedoOperations(statusUtil, FSharpOption<ITextUndoHistory>.None);
     vimData = vimData ?? new VimData();
     vimHost = vimHost ?? new MockVimHost();
     navigator = navigator ?? CreateTextStructureNavigator(textView.TextBuffer);
     clipboardDevice = clipboardDevice ?? new MockClipboardDevice();
     var operationsData = new OperationsData(
         editorOperations,
         editorOptions,
         foldManager,
         jumpList,
         keyMap,
         localSettings,
         outlining != null ? FSharpOption.Create(outlining) : FSharpOption<IOutliningManager>.None,
         CreateRegisterMap(clipboardDevice),
         searchService,
         EditorUtil.FactoryService.SmartIndentationService,
         statusUtil,
         textView,
         undoRedoOperations,
         vimData,
         vimHost,
         navigator);
     return new CommonOperations(operationsData);
 }
Exemplo n.º 28
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Selector"/> class.
        /// </summary>
        /// <param name="view"></param>
        /// <param name="textSearchService"></param>
        /// <param name="editorOperationsService"></param>
        /// <param name="textStructureNavigator"></param>
        /// <param name="outliningManagerService"></param>
        public Selector(
            IWpfTextView view,
            ITextSearchService textSearchService,
            IEditorOperationsFactoryService editorOperationsService,
            ITextStructureNavigator textStructureNavigator,
            IOutliningManagerService outliningManagerService)
        {
            this.view = view;

            // Services
            this.textSearchService      = textSearchService;
            this.EditorOperations       = editorOperationsService.GetEditorOperations(this.view);
            this.textStructureNavigator = textStructureNavigator;
            this.outliningManager       = outliningManagerService?.GetOutliningManager(this.view);
            this.Dte = ServiceProvider.GlobalProvider.GetService(typeof(DTE)) as DTE2;

            this.Selections     = new List <Selection>();
            this.historyManager = new HistoryManager();
        }
Exemplo n.º 29
0
		public TextRenderer(ProgressiveScroll progressiveScroll, ITextView textView, IOutliningManager outliningManager)
		{
			_progressiveScroll = progressiveScroll;
			TextVisual = new DrawingVisual();

			_textView = textView;
			_outliningManager = outliningManager;
			_bitmapWidth = Options.ScrollBarWidth;
			_bitmapHeight = 0;
			_bitmapStride = (_bitmapWidth * _pixelFormat.BitsPerPixel + 7) / 8;
			_bitmapPixels = null;

			_width = _bitmapWidth;
			_height = _bitmapHeight;
			_stride = _bitmapStride;
			_pixels = null;

			_lineRatio = 1.0;
		}
Exemplo n.º 30
0
        public TextRenderer(ProgressiveScroll progressiveScroll, ITextView textView, IOutliningManager outliningManager)
        {
            _progressiveScroll = progressiveScroll;
            TextVisual         = new DrawingVisual();

            _textView         = textView;
            _outliningManager = outliningManager;
            _bitmapWidth      = Options.ScrollBarWidth;
            _bitmapHeight     = 0;
            _bitmapStride     = (_bitmapWidth * _pixelFormat.BitsPerPixel + 7) / 8;
            _bitmapPixels     = null;

            _width  = _bitmapWidth;
            _height = _bitmapHeight;
            _stride = _bitmapStride;
            _pixels = null;

            _lineRatio = 1.0;
        }
Exemplo n.º 31
0
        /// <summary>
        /// Attempts to find a <see cref="ICollapsible" /> associated with the specified <see
        /// cref="IMembers" />.
        /// </summary>
        /// <param name="item">The IMembers CodeItem.</param>
        /// <param name="manager">The outlining manager to get all regions</param>
        /// <param name="textView">The textview to find collapsibles in</param>
        /// <returns>The <see cref="ICollapsible" /> on the same starting line, otherwise null.</returns>
        private static ICollapsible FindCollapsibleFromCodeItem(CodeItem item, IOutliningManager manager, IWpfTextView textView)
        {
            if (item.Kind == CodeItemKindEnum.ImplementedInterface)
            {
                return(null);
            }
            if (item.StartLine > textView.TextBuffer.CurrentSnapshot.LineCount)
            {
                return(null);
            }

            var snapshotLine = textView.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(item.StartLine);
            var collapsibles = manager.GetAllRegions(snapshotLine.Extent);

            return((from collapsible in collapsibles
                    let startLine = GetStartLineForCollapsible(collapsible)
                                    where startLine == item.StartLine
                                    select collapsible).FirstOrDefault());
        }
Exemplo n.º 32
0
		public ProgressiveScroll(
			IWpfTextViewMargin containerMargin,
			IWpfTextView textView,
			IOutliningManager outliningManager,
			ITagAggregator<ChangeTag> changeTagAggregator,
			ITagAggregator<IVsVisibleTextMarkerTag> markerTagAggregator,
			ITagAggregator<IErrorTag> errorTagAggregator,
			EnvDTE.Debugger debugger,
			SimpleScrollBar scrollBar,
			ColorSet colors)
		{
			_containerMargin = containerMargin;

			ProgressiveScrollDict.Add(this);

			Colors = colors;
			_textView = textView;
			_scrollBar = scrollBar;
			_markerTagAggregator = markerTagAggregator;
			_errorTagAggregator = errorTagAggregator;

			RegisterEvents();
			InitSettings();

			_textRenderer = new TextRenderer(this, _textView, outliningManager);
			if (Options.RenderTextEnabled)
			{
				Visuals.Add(_textRenderer.TextVisual);
			}

			MarksVisual = new DrawingVisual();
			Visuals.Add(MarksVisual);

			_changeRenderer = new ChangeRenderer(_textView, changeTagAggregator, scrollBar);
			_highlightRenderer = new HighlightRenderer(_textView, scrollBar);
			_markerRenderer = new MarkerRenderer(_textView, markerTagAggregator, errorTagAggregator, debugger, scrollBar);

			foreach (var visual in Visuals)
			{
				AddVisualChild(visual);
			}
		}
Exemplo n.º 33
0
        public ProgressiveScroll(
            IWpfTextViewMargin containerMargin,
            IWpfTextView textView,
            IOutliningManager outliningManager,
            ITagAggregator <ChangeTag> changeTagAggregator,
            ITagAggregator <IVsVisibleTextMarkerTag> markerTagAggregator,
            ITagAggregator <IErrorTag> errorTagAggregator,
            EnvDTE.Debugger debugger,
            SimpleScrollBar scrollBar,
            ColorSet colors)
        {
            _containerMargin = containerMargin;

            ProgressiveScrollDict.Add(this);

            Colors               = colors;
            _textView            = textView;
            _scrollBar           = scrollBar;
            _markerTagAggregator = markerTagAggregator;
            _errorTagAggregator  = errorTagAggregator;

            RegisterEvents();
            InitSettings();

            _textRenderer = new TextRenderer(this, _textView, outliningManager);
            if (Options.RenderTextEnabled)
            {
                Visuals.Add(_textRenderer.TextVisual);
            }

            MarksVisual = new DrawingVisual();
            Visuals.Add(MarksVisual);

            _changeRenderer    = new ChangeRenderer(_textView, changeTagAggregator, scrollBar);
            _highlightRenderer = new HighlightRenderer(_textView, scrollBar);
            _markerRenderer    = new MarkerRenderer(_textView, markerTagAggregator, errorTagAggregator, debugger, scrollBar);

            foreach (var visual in Visuals)
            {
                AddVisualChild(visual);
            }
        }
Exemplo n.º 34
0
        public RelativeNumber(IWpfTextView textView, IEditorFormatMap formatMap, IWpfTextViewMargin containerMargin, IOutliningManager outliningManager)
        {
            this.textView = textView;
            this.formatMap = formatMap;
            this.containerMargin = containerMargin;
            this.outliningManager = outliningManager;

            this.ClipToBounds = true;
            TextOptions.SetTextFormattingMode(this, TextFormattingMode.Ideal);
            TextOptions.SetTextRenderingMode(this, TextRenderingMode.ClearType);

            textView.Caret.PositionChanged += OnCaretPositionChanged;
            textView.Options.OptionChanged += OnOptionChanged;
            textView.LayoutChanged += OnLayoutChanged;
            textView.ViewportHeightChanged += (sender, args) => ApplyNumbers();
            formatMap.FormatMappingChanged += (sender, args) => ApplyNumbers();
            textView.ViewportWidthChanged += OnViewportWidthChanged;

            HideVSLineNumbers();
        }
Exemplo n.º 35
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Selector"/> class.
        /// </summary>
        /// <param name="view"></param>
        /// <param name="textSearchService"></param>
        /// <param name="IEditorOperationsFactoryService"></param>
        /// <param name="IEditorFormatMapService"></param>
        /// <param name="ITextStructureNavigator"></param>
        /// <param name="IOutliningManagerService"></param>
        public Selector(
            IWpfTextView view,
            ITextSearchService textSearchService,
            IEditorOperationsFactoryService editorOperationsService,
            IEditorFormatMapService formatMapService         = null,
            ITextStructureNavigator textStructureNavigator   = null,
            IOutliningManagerService outliningManagerService = null
            )
        {
            this.view = view;

            // Services
            this.textSearchService      = textSearchService ?? throw new ArgumentNullException("textSearchService");
            this.editorOperations       = editorOperationsService.GetEditorOperations(this.view);
            this.textStructureNavigator = textStructureNavigator;
            this.outliningManager       = outliningManagerService?.GetOutliningManager(this.view);
            this.Dte = ServiceProvider.GlobalProvider.GetService(typeof(DTE)) as DTE2;

            this.Selections = new List <Selection>();
        }
Exemplo n.º 36
0
        protected void Create(params string[] lines)
        {
            _vimHost = (MockVimHost)Vim.VimHost;
            _textView = CreateTextView(lines);
            _textBuffer = _textView.TextBuffer;
            _vimTextBuffer = CreateVimTextBufferCore(_textBuffer);
            _localSettings = _vimTextBuffer.LocalSettings;

            var foldManager = CreateFoldManager(_textView);

            _factory = new MockRepository(MockBehavior.Loose);
            _statusUtil = _factory.Create<IStatusUtil>();
            _bulkOperations = new TestableBulkOperations();

            var vimBufferData = CreateVimBufferData(
                _vimTextBuffer,
                _textView,
                statusUtil: _statusUtil.Object);
            _jumpList = vimBufferData.JumpList;
            _windowSettings = vimBufferData.WindowSettings;

            _vimData = Vim.VimData;
            _macroRecorder = Vim.MacroRecorder;
            _globalSettings = Vim.GlobalSettings;

            var operations = CreateCommonOperations(vimBufferData);
            var lineChangeTracker = new LineChangeTracker(vimBufferData);
            _motionUtil = new MotionUtil(vimBufferData, operations);
            _commandUtil = new CommandUtil(
                vimBufferData,
                _motionUtil,
                operations,
                foldManager,
                new InsertUtil(vimBufferData, _motionUtil, operations),
                _bulkOperations,
                MouseDevice,
                lineChangeTracker);

            var outliningManagerService = CompositionContainer.GetExportedValue<IOutliningManagerService>();
            _outliningManager = outliningManagerService.GetOutliningManager(_textView);
        }
        /// <summary>
        /// Initializes a new AdornmentManger.
        /// </summary>
        /// <remarks>
        /// Use <see cref="AdornmentManager.GetOrCreateAdornmentManager"/> to create a new AdornmentManager.
        /// </remarks>
        private AdornmentManager(IWpfTextView textView, string adornmentLayer, IOutliningManager outliningManager, Logger logger)
        {
            Contract.Requires(textView != null);
            Contract.Requires(!String.IsNullOrEmpty(adornmentLayer));
            Contract.Requires(outliningManager != null);
            Contract.Requires(logger != null);

            _logger                          = logger;
            _logger.Failed                  += OnFailed;
            _textView                        = textView;
            _layer                           = textView.GetAdornmentLayer(adornmentLayer);
            _textView.LayoutChanged         += OnLayoutChanged;
            _textView.Closed                += OnTextViewClosed;
            _textView.ViewportHeightChanged += UpdateStaticAdornments;
            _textView.ViewportWidthChanged  += UpdateStaticAdornments;
            //_textView.Caret.PositionChanged += OnCaretMoved;
            //textView.MouseHover += OnMouseHover;
            _outliningManager = outliningManager;
            _outliningManager.RegionsCollapsed += OnRegionsCollapsed;
            _outliningManager.RegionsExpanded  += OnRegionsExpanded;
        }
Exemplo n.º 38
0
        public RelativeNumber(IWpfTextView textView, IEditorFormatMap formatMap, IWpfTextViewMargin containerMargin, IOutliningManager outliningManager)
        {
            this.textView         = textView;
            this.formatMap        = formatMap;
            this.containerMargin  = containerMargin;
            this.outliningManager = outliningManager;

            this.ClipToBounds = true;
            TextOptions.SetTextFormattingMode(this, TextFormattingMode.Ideal);
            TextOptions.SetTextRenderingMode(this, TextRenderingMode.ClearType);

            textView.Caret.PositionChanged += OnCaretPositionChanged;
            textView.Options.OptionChanged += OnOptionChanged;
            textView.LayoutChanged         += OnLayoutChanged;
            textView.ViewportHeightChanged += (sender, args) => ApplyNumbers();
            formatMap.FormatMappingChanged += (sender, args) => ApplyNumbers();
            textView.ViewportWidthChanged  += OnViewportWidthChanged;
            textView.GotAggregateFocus     += GotFocusHandler;
            textView.LostAggregateFocus    += LostFocusHandler;
            HideVSLineNumbers();
        }
Exemplo n.º 39
0
    /// <summary>
    /// Initializes a new AdornmentManger.
    /// </summary>
    /// <remarks>
    /// Use <see cref="AdornmentManager.GetOrCreateAdornmentManager"/> to create a new AdornmentManager.
    /// </remarks>
    private AdornmentManager(IWpfTextView textView, string adornmentLayer, IOutliningManager outliningManager, Logger logger) {
      Contract.Requires(textView != null);
      Contract.Requires(!String.IsNullOrEmpty(adornmentLayer));
      Contract.Requires(outliningManager != null);
      Contract.Requires(logger != null);

      _logger = logger;
      _logger.Failed += OnFailed;
      _textView = textView;
      _layer = textView.GetAdornmentLayer(adornmentLayer);
      _textView.LayoutChanged += OnLayoutChanged;
      _textView.Closed += OnTextViewClosed;
      _textView.ViewportHeightChanged += UpdateStaticAdornments;
      _textView.ViewportWidthChanged += UpdateStaticAdornments;
      //_textView.Caret.PositionChanged += OnCaretMoved;
      //textView.MouseHover += OnMouseHover;
      _outliningManager = outliningManager;
      _outliningManager.RegionsCollapsed += OnRegionsCollapsed;
      _outliningManager.RegionsExpanded += OnRegionsExpanded;
    }
Exemplo n.º 40
0
 internal static IIncrementalSearch CreateIncrementalSearch(
     ITextView textView,
     IVimLocalSettings settings,
     IVimData vimData,
     ISearchService search = null,
     IOutliningManager outliningManager = null,
     IStatusUtil statusUtil = null)
 {
     search = search ?? new SearchService(EditorUtil.FactoryService.TextSearchService, settings.GlobalSettings);
     statusUtil = statusUtil ?? new StatusUtil();
     var nav = CreateTextStructureNavigator(textView.TextBuffer);
     var operations = CreateCommonOperations(
         textView: textView,
         localSettings: settings,
         outlining: outliningManager,
         vimData: vimData);
     return new IncrementalSearch(
         operations,
         settings,
         nav,
         search,
         statusUtil,
         vimData);
 }
Exemplo n.º 41
0
 internal OperationsImpl(ITextView view, IEditorOperations opts, IOutliningManager outlining, IVimHost host, IJumpList jumpList, IVimLocalSettings settings, IUndoRedoOperations undoRedoOpts)
     : base(view, opts, outlining, host, jumpList, settings, undoRedoOpts)
 {
 }