public BufferGraph(ITextBuffer topBuffer, GuardedOperations guardedOperations) { if (topBuffer == null) { throw new ArgumentNullException("topBuffer"); } if (guardedOperations == null) { throw new ArgumentNullException("guardedOperations"); } this.topBuffer = topBuffer; this.guardedOperations = guardedOperations; this.importingProjectionBufferMap.Add(topBuffer, null); // The top buffer has no targets, but it is put here so membership in this map can be used uniformly // to determine whether a buffer is in the buffer graph // Subscribe to content type changed events on the toplevel buffer this.eventHooks.Add(new WeakEventHookForBufferGraph(this, topBuffer)); IProjectionBufferBase projectionBufferBase = topBuffer as IProjectionBufferBase; if (projectionBufferBase != null) { IList <ITextBuffer> sourceBuffers = projectionBufferBase.SourceBuffers; FrugalList <ITextBuffer> dontCare = new FrugalList <ITextBuffer>(); foreach (ITextBuffer sourceBuffer in sourceBuffers) { AddSourceBuffer(projectionBufferBase, sourceBuffer, dontCare); } } }
/// <summary> /// Open a stream reader from the specified stream, using the default encoding /// unless either byte order marks are found (specifying a different encoding) /// or -- if no byte order marks are found -- one of the given encoding detectors /// can deduce an appropriate encoding. /// /// Note that the stream passed to OpenStreamReader must support both Peek and setting /// the position. /// </summary> /// <param name="stream">stream on which to open the stream reader</param> /// <returns>The detected encoding or null.</returns> public static Encoding DetectEncoding(Stream stream, List <Lazy <IEncodingDetector, IEncodingDetectorMetadata> > encodingDetectorExtensions, GuardedOperations guardedOperations) { if (stream == null) { throw new ArgumentNullException(nameof(stream)); } long position = stream.Position; bool isStreamEmpty; Encoding detectedEncoding = CheckForBoM(stream, out isStreamEmpty); // If there was no BoM, try the detector extensions. if (detectedEncoding == null && !isStreamEmpty) { detectedEncoding = SniffForEncoding(stream, encodingDetectorExtensions, guardedOperations); //Rewind the stream. stream.Position = position; } return(detectedEncoding); }
public ElisionBuffer(IProjectionEditResolver resolver, IContentType contentType, ITextBuffer sourceBuffer, NormalizedSpanCollection exposedSpans, ElisionBufferOptions options, ITextDifferencingService textDifferencingService, GuardedOperations guardedOperations) : base(resolver, contentType, textDifferencingService, guardedOperations) { Debug.Assert(sourceBuffer != null); this.sourceBuffer = sourceBuffer; this.sourceSnapshot = sourceBuffer.CurrentSnapshot; BaseBuffer baseSourceBuffer = (BaseBuffer)sourceBuffer; this.eventHook = new WeakEventHook(this, baseSourceBuffer); this.group = baseSourceBuffer.group; this.group.AddMember(this); this.content = new ElisionMap(this.sourceSnapshot, exposedSpans); StringRebuilder newBuilder = StringRebuilder.Empty; for (int i = 0; (i < exposedSpans.Count); ++i) { newBuilder = newBuilder.Append(BufferFactoryService.StringRebuilderFromSnapshotAndSpan(this.sourceSnapshot, exposedSpans[i])); } this.builder = newBuilder; this.elisionOptions = options; this.currentVersion.SetLength(content.Length); this.currentElisionSnapshot = new ElisionSnapshot(this, this.sourceSnapshot, base.currentVersion, this.builder, this.content, (options & ElisionBufferOptions.FillInMappingMode) != 0); this.currentSnapshot = this.currentElisionSnapshot; }
protected IIntellisensePresenter FindPresenter (IIntellisenseSession session, IList <Lazy <IIntellisensePresenterProvider, IOrderableContentTypeMetadata> > orderedPresenterProviders, GuardedOperations guardedOperations) { var buffers = Helpers.GetBuffersForTriggerPoint(session); foreach (var presenterProviderExport in orderedPresenterProviders) { foreach (var buffer in buffers) { foreach (var contentType in presenterProviderExport.Metadata.ContentTypes) { if (buffer.ContentType.IsOfType(contentType)) { IIntellisensePresenter presenter = guardedOperations.InstantiateExtension( session, presenterProviderExport, factory => factory.TryCreateIntellisensePresenter(session)); if (presenter != null) { return(presenter); } } } } } return(null); }
public override bool BuildRegions(OutlineRegionCollection newRegions) { lock (_threadLock) { if (IsDisposed || !EditorTree.IsReady) { return(false); } AstRoot rootNode = null; try { // We are in a background thread so in order to walk the tree // we must obtain the read lock first. rootNode = EditorTree.AcquireReadLock(_treeUserId); if (rootNode != null) { OutliningContext context = new OutliningContext(); context.Regions = newRegions; // Walk the tree and construct new regions rootNode.Accept(this, context); OutlineSections(rootNode, context); } } catch (Exception) { } finally { if (rootNode != null) { EditorTree.ReleaseReadLock(_treeUserId); } else { // Tree was busy. Will try again later. GuardedOperations.DispatchInvoke(() => BackgroundTask.DoTaskOnIdle(), DispatcherPriority.Normal); } } return(true); } }
public ElisionBuffer(IProjectionEditResolver resolver, IContentType contentType, ITextBuffer sourceBuffer, NormalizedSpanCollection exposedSpans, ElisionBufferOptions options, ITextDifferencingService textDifferencingService, GuardedOperations guardedOperations) : base(resolver, contentType, textDifferencingService, guardedOperations) { Debug.Assert(sourceBuffer != null); this.sourceBuffer = sourceBuffer; this.sourceSnapshot = sourceBuffer.CurrentSnapshot; BaseBuffer baseSourceBuffer = (BaseBuffer)sourceBuffer; this.eventHook = new WeakEventHook(this, baseSourceBuffer); this.group = baseSourceBuffer.group; this.group.AddMember(this); this.content = new ElisionMap(this.sourceSnapshot, exposedSpans); this.elisionOptions = options; this.currentVersion.InternalLength = content.Length; this.currentElisionSnapshot = new ElisionSnapshot(this, this.sourceSnapshot, base.currentVersion, this.content, (options & ElisionBufferOptions.FillInMappingMode) != 0); this.currentSnapshot = this.currentElisionSnapshot; }
protected BaseBuffer(IContentType contentType, int initialLength, ITextDifferencingService textDifferencingService, GuardedOperations guardedOperations) { // parameters are validated outside Debug.Assert(contentType != null); this.contentType = contentType; this.currentVersion = new TextVersion(this, 0, 0, initialLength); this.textDifferencingService = textDifferencingService; this.guardedOperations = guardedOperations; }
public BraceCompletionStack(ITextView textView, IBraceCompletionAdornmentServiceFactory adornmentFactory, GuardedOperations guardedOperations) { _adornmentServiceFactory = adornmentFactory; _stack = new Stack <IBraceCompletionSession> (); _textView = textView; _guardedOperations = guardedOperations; RegisterEvents(); }
internal BraceCompletionManager(ITextView textView, IBraceCompletionStack stack, IBraceCompletionAggregatorFactory sessionFactory, GuardedOperations guardedOperations) { _textView = textView; _stack = stack; _sessionFactory = sessionFactory; _guardedOperations = guardedOperations; _sessionAggregator = sessionFactory.CreateAggregator(); GetOptions(); RegisterEvents(); }
public IEditorCommandHandlerService GetService(ITextView textView) { return(textView.Properties.GetOrCreateSingletonProperty(() => { var bufferResolverProvider = GuardedOperations.InvokeBestMatchingFactory(_bufferResolverProviders, textView.TextBuffer.ContentType, _contentTypeRegistryService, errorSource: this); ICommandingTextBufferResolver bufferResolver = null; GuardedOperations.CallExtensionPoint(() => bufferResolver = bufferResolverProvider.CreateResolver(textView)); bufferResolver = bufferResolver ?? new DefaultBufferResolver(textView); return new EditorCommandHandlerService(this, textView, _commandHandlers, bufferResolver); })); }
protected BaseBuffer(IContentType contentType, int initialLength, ITextDifferencingService textDifferencingService, GuardedOperations guardedOperations) { // parameters are validated outside Debug.Assert(contentType != null); this.contentType = contentType; this.currentVersion = new TextVersion(this, new TextImageVersion(initialLength)); // this.builder should be set in calling ctor this.textDifferencingService = textDifferencingService; this.guardedOperations = guardedOperations; }
ISmartIndent CreateSmartIndent(ITextView textView) { if (textView.IsClosed) { return(this); } else { return(GuardedOperations.InvokeBestMatchingFactory (SmartIndentProviders, textView.TextDataModel.ContentType, (provider) => (provider.CreateSmartIndent(textView)), ContentTypeRegistryService, this) ?? this); } }
public int?GetDesiredIndentation(ITextView textView, ITextSnapshotLine line) { var indenter = textView.Properties .GetOrCreateSingletonProperty(typeof(MockSmartIndentationService), () => GuardedOperations.InvokeBestMatchingFactory( Providers, textView.TextBuffer.ContentType, p => p.CreateSmartIndent(textView), ContentTypeRegistry, this) ?? this ); return(indenter.GetDesiredIndentation(line)); }
/// <summary> /// Constructs a new selection Element that is bound to the specified editor canvas /// </summary> /// <param name="wpfTextView"> /// The WPF Text View that hosts this caret /// </param> public SkiaTextCaret( SkiaTextView wpfTextView, SkiaTextSelection selection, ISmartIndentationService smartIndentationService, IEditorFormatMap editorFormatMap, //IClassificationFormatMap classificationFormatMap, GuardedOperations guardedOperations) { // Verify Debug.Assert(wpfTextView != null); _regularBrush = new SKPaint() { Color = SKColors.Red, Typeface = wpfTextView.Typeface, TextSize = 24, LcdRenderText = true, IsAntialias = true, SubpixelText = true }; _wpfTextView = wpfTextView; _selection = selection; _guardedOperations = guardedOperations; _smartIndentationService = smartIndentationService; // Set up initial values _caretAffinity = PositionAffinity.Successor; _insertionPoint = new VirtualSnapshotPoint(new SnapshotPoint(_wpfTextView.TextSnapshot, 0)); //// Set the regular caret brush //_editorFormatMap = editorFormatMap; //// store information related to classifications //_classificationFormatMap = classificationFormatMap; this.SubscribeEvents(); this.UpdateDefaultBrushes(); this.UpdateRegularCaretBrush(); this.UpdateOverwriteCaretBrush(); //Set the default values for the caret to be what they should be for a hidden caret that is not in overwrite mode. _caretBrush = _regularBrush; // Get the caret blink time from the system. If the caret is set not to flash, the return value // will be -1 _blinkInterval = CaretBlinkTimeManager.GetCaretBlinkTime(); if (_blinkInterval > 0) { _blinkTimer = new DispatcherTimer(new TimeSpan(0, 0, 0, 0, _blinkInterval), OnTimerElapsed); } this.UpdateBlinkTimer(); }
/// <summary> /// Resumes tree updates. If changes were made to the text buffer /// since suspend, full parse is performed. /// </summary> internal void Resume() { if (UpdatesSuspended) { UpdatesSuspended = false; if (TextBufferChangedSinceSuspend) { TextBufferChangedSinceSuspend = false; GuardedOperations.DispatchInvoke(() => ProcessPendingTextBufferChanges(async: true), DispatcherPriority.ApplicationIdle); } } }
public ConnectionManager(IWpfTextView textView, ICollection <Lazy <IWpfTextViewConnectionListener, IContentTypeAndTextViewRoleMetadata> > textViewConnectionListeners, GuardedOperations guardedOperations) { if (textView == null) { throw new ArgumentNullException("textView"); } if (textViewConnectionListeners == null) { throw new ArgumentNullException("textViewConnectionListeners"); } if (guardedOperations == null) { throw new ArgumentNullException("guardedOperations"); } _textView = textView; _guardedOperations = guardedOperations; List <Lazy <IWpfTextViewConnectionListener, IContentTypeAndTextViewRoleMetadata> > filteredListeners = UIExtensionSelector.SelectMatchingExtensions(textViewConnectionListeners, _textView.Roles); if (filteredListeners.Count > 0) { foreach (var listenerExport in filteredListeners) { Listener listener = new Listener(listenerExport, guardedOperations); this.listeners.Add(listener); Collection <ITextBuffer> subjectBuffers = textView.BufferGraph.GetTextBuffers(buffer => (Match(listenerExport.Metadata, buffer.ContentType))); if (subjectBuffers.Count > 0) { var instance = listener.Instance; if (instance != null) { _guardedOperations.CallExtensionPoint(instance, () => instance.SubjectBuffersConnected(_textView, ConnectionReason.TextViewLifetime, subjectBuffers)); } } } textView.BufferGraph.GraphBuffersChanged += OnGraphBuffersChanged; textView.BufferGraph.GraphBufferContentTypeChanged += OnGraphBufferContentTypeChanged; } }
public BraceCompletionAggregatorFactory( [ImportMany(typeof(IBraceCompletionSessionProvider))] IEnumerable <Lazy <IBraceCompletionSessionProvider, IBraceCompletionMetadata> > sessionProviders, [ImportMany(typeof(IBraceCompletionContextProvider))] IEnumerable <Lazy <IBraceCompletionContextProvider, IBraceCompletionMetadata> > contextProviders, [ImportMany(typeof(IBraceCompletionDefaultProvider))] IEnumerable <Lazy <IBraceCompletionDefaultProvider, IBraceCompletionMetadata> > defaultProviders, IContentTypeRegistryService contentTypeRegistryService, ITextBufferUndoManagerProvider undoManager, IEditorOperationsFactoryService editorOperationsFactoryService, GuardedOperations guardedOperations) { SessionProviders = sessionProviders; ContextProviders = contextProviders; DefaultProviders = defaultProviders; ContentTypeRegistryService = contentTypeRegistryService; UndoManager = undoManager; EditorOperationsFactoryService = editorOperationsFactoryService; GuardedOperations = guardedOperations; }
internal static IEnumerable <TStyle> GetMatchingPresenterStyles <TSession, TStyle> (TSession session, IList <Lazy <TStyle, IOrderableContentTypeMetadata> > orderedPresenterStyles, GuardedOperations guardedOperations) where TSession : IIntellisenseSession { List <TStyle> styles = new List <TStyle>(); ITextView textView = session.TextView; SnapshotPoint?surfaceBufferPoint = session.GetTriggerPoint(textView.TextSnapshot); if (surfaceBufferPoint == null) { return(styles); } var buffers = Helpers.GetBuffersForTriggerPoint(session).ToList(); foreach (var styleExport in orderedPresenterStyles) { bool usedThisProviderAlready = false; foreach (var buffer in buffers) { foreach (string contentType in styleExport.Metadata.ContentTypes) { if (buffer.ContentType.IsOfType(contentType)) { var style = guardedOperations.InstantiateExtension(styleExport, styleExport); if (!Object.Equals(style, default(TStyle))) { styles.Add(style); } usedThisProviderAlready = true; break; } } if (usedThisProviderAlready) { break; } } } return(styles); }
public override bool BuildRegions(OutlineRegionCollection newRegions) { lock (_threadLock) { if (IsDisposed || !EditorTree.IsReady) { return(false); } AstRoot rootNode = null; try { rootNode = EditorTree.AcquireReadLock(_treeUserId); if (rootNode != null) { OutliningContext context = new OutliningContext(); context.Regions = newRegions; rootNode.Accept(this, context); } } catch (Exception ex) { Debug.Fail(String.Format(CultureInfo.CurrentCulture, "Exception in outliner: {0}", ex.Message)); } finally { if (rootNode != null) { EditorTree.ReleaseReadLock(_treeUserId); } else { // Tree was busy. Will try again later. GuardedOperations.DispatchInvoke(() => BackgroundTask.DoTaskOnIdle(), DispatcherPriority.Normal); } } return(true); } }
/// <summary> /// Constructs a new selection Element /// </summary> public SkiaTextSelection(SkiaTextView wpfTextView, IEditorFormatMap editorFormatMap, GuardedOperations guardedOperations) { // Verify Debug.Assert(wpfTextView != null); _wpfTextView = wpfTextView; _editorFormatMap = editorFormatMap; ActivationTracksFocus = true; // Initialize members _activePoint = _anchorPoint = new VirtualSnapshotPoint(_wpfTextView.TextSnapshot, 0); _selectionMode = TextSelectionMode.Stream; _selectionAdornmentLayer = _wpfTextView.GetAdornmentLayer(PredefinedAdornmentLayers.Selection); _guardedOperations = guardedOperations; this.CreateAndSetPainter("Selected Text", ref _focusedPainter, SKColors.Blue.WithAlpha(80)); this.CreateAndSetPainter("Inactive Selected Text", ref _unfocusedPainter, SKColors.Gray.WithAlpha(80)); this.Painter.Activate(); SubscribeToEvents(); }
public TextBuffer(IContentType contentType, StringRebuilder content, ITextDifferencingService textDifferencingService, GuardedOperations guardedOperations) : this(contentType, content, textDifferencingService, guardedOperations, false) { }
protected BaseProjectionBuffer(IProjectionEditResolver resolver, IContentType contentType, ITextDifferencingService textDifferencingService, GuardedOperations guardedOperations) : base(contentType, 0, textDifferencingService, guardedOperations) { this.resolver = resolver; // null is OK }
public TextBuffer(IContentType contentType, StringRebuilder content, ITextDifferencingService textDifferencingService, GuardedOperations guardedOperations, bool spurnGroup) : base(contentType, content.Length, textDifferencingService, guardedOperations) { // Parameters are validated outside this.group = new BufferGroup(this); this.builder = content; this.spurnGroup = spurnGroup; this.currentSnapshot = this.TakeSnapshot(); }
private static Encoding SniffForEncoding(Stream stream, List <Lazy <IEncodingDetector, IEncodingDetectorMetadata> > orderedEncodingDetectors, GuardedOperations guardedOperations) { long position = stream.Position; foreach (Lazy <IEncodingDetector, IEncodingDetectorMetadata> sniffer in orderedEncodingDetectors) { Encoding encoding = null; try { encoding = sniffer.Value.GetStreamEncoding(stream); } catch (Exception e) { guardedOperations.HandleException(sniffer, e); } //Rewind the stream stream.Position = position; //Return if we smelled something. if (encoding != null) { return(encoding); } } return(null); }
public Listener(Lazy <IWpfTextViewConnectionListener, IContentTypeAndTextViewRoleMetadata> importInfo, GuardedOperations guardedOperations) { this.importInfo = importInfo; this.guardedOperations = guardedOperations; }