///////////////////////////////////////////////////////////////////////////////////////////////////// // PUBLIC PROCEDURES ///////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Sets the current statement indicator, by finding the next breakpoint after the specified snapshot offset. /// </summary> /// <param name="document">The editor document.</param> /// <param name="startSnapshotOffset">The starting snapshot offset to examine.</param> /// <returns>The current statement snapshot offset.</returns> public static TextSnapshotOffset SetCurrentStatement(IEditorDocument document, TextSnapshotOffset startSnapshotOffset) { if (!startSnapshotOffset.IsDeleted) { // Create search options (only allow enabled breakpoints) var options = new TagSearchOptions <BreakpointIndicatorTag>(); options.Filter = (tr => tr.Tag.IsEnabled); // Find the next breakpoint var tagRange = document.IndicatorManager.Breakpoints.FindNext(startSnapshotOffset, options); if (tagRange != null) { // Get the snapshot range of the breakpoint var snapshotRange = tagRange.VersionRange.Translate(startSnapshotOffset.Snapshot); var currentStatementSnapshotOffset = new TextSnapshotOffset(snapshotRange.Snapshot, snapshotRange.EndOffset); // Set the current statement indicator range document.IndicatorManager.CurrentStatement.SetInstance(snapshotRange); return(currentStatementSnapshotOffset); } } // Remove any current statement indicator document.IndicatorManager.CurrentStatement.Clear(); return(TextSnapshotOffset.Deleted); }
protected virtual void Dispose(bool disposing) { if (_document != null) { ServiceManager.RemoveService<IEditorInstance>(ViewBuffer); _document.Dispose(); _document = null; } }
protected virtual void Dispose(bool disposing) { ViewBuffer?.RemoveService(this); DiskBuffer?.RemoveService(this); _document?.Dispose(); _document = null; }
/// <summary> /// Retrieves document instance from text buffer /// </summary> public static IEditorDocument FromTextBuffer(ITextBuffer textBuffer) { IEditorDocument document = TryFromTextBuffer(textBuffer); Debug.Assert(document != null, "No editor document available"); return(document); }
/// <summary> /// Creates contained language host with default settings. /// </summary> /// <param name="document">Markdown editor document</param> /// <param name="textBuffer">Contained language text buffer</param> /// <param name="coreShell"></param> public MdContainedLanguageHost(IEditorDocument document, ITextBuffer textBuffer, ICoreShell coreShell) { _textBuffer = textBuffer; _coreShell = coreShell; _document = document; _document.DocumentClosing += OnDocumentClosing; ServiceManager.AddService<IContainedLanguageHost>(this, textBuffer, coreShell); }
protected virtual void Dispose(bool disposing) { if (_document != null) { ServiceManager.RemoveService <IEditorInstance>(ViewBuffer); _document.Dispose(); _document = null; } }
/// <summary> /// Creates contained language host with default settings. /// </summary> /// <param name="document">Markdown editor document</param> /// <param name="textBuffer">Contained language text buffer</param> public MdContainedLanguageHost(IEditorDocument document, ITextBuffer textBuffer) { _textBuffer = textBuffer; _document = document; _document.DocumentClosing += OnDocumentClosing; ServiceManager.AddService <IContainedLanguageHost>(this, textBuffer); }
/// <summary> /// Creates contained language host with default settings. /// </summary> /// <param name="document">Markdown editor document</param> /// <param name="editorBuffer">Contained language text buffer</param> public MdContainedLanguageHost(IEditorDocument document, IEditorBuffer editorBuffer) { _textBuffer = editorBuffer.As <ITextBuffer>(); _document = document; _document.Closing += OnDocumentClosing; editorBuffer.AddService(this); }
/// <summary> /// Creates contained language host with default settings. /// </summary> /// <param name="document">Markdown editor document (top-level)</param> /// <param name="containedLanguageBuffer">Contained language text buffer</param> public RContainedLanguageHost(IEditorDocument document, ITextBuffer containedLanguageBuffer) { _document = document; _document.Closing += OnDocumentClosing; var containedTextBuffer = containedLanguageBuffer; containedTextBuffer.AddService(this); new RExpressionTermFilter(containedTextBuffer); }
public EditorInstance(ITextBuffer diskBuffer, IEditorDocumentFactory documentFactory) { if (diskBuffer == null) throw new ArgumentNullException(nameof(diskBuffer)); if (documentFactory == null) throw new ArgumentNullException(nameof(documentFactory)); ViewBuffer = diskBuffer; _document = documentFactory.CreateDocument(this); ServiceManager.AddService<IEditorInstance>(this, ViewBuffer); }
protected EditorViewModel(IEditorDocument document, IEditorBuffer viewBuffer = null) { Check.ArgumentNull(nameof(document), document); DiskBuffer = document.EditorBuffer; DiskBuffer.AddService(this); ViewBuffer = viewBuffer ?? DiskBuffer; if (viewBuffer != null) { ViewBuffer.AddService(this); } _document = document; }
public ProjectionEditorInstance(ITextBuffer diskBuffer, IEditorDocumentFactory documentFactory, ICoreShell coreShell) { if (diskBuffer == null) { throw new ArgumentNullException(nameof(diskBuffer)); } if (documentFactory == null) { throw new ArgumentNullException(nameof(documentFactory)); } DiskBuffer = diskBuffer; _document = documentFactory.CreateDocument(this); var projectionBufferManager = ProjectionBufferManager.FromTextBuffer(diskBuffer); ViewBuffer = projectionBufferManager.ViewBuffer; ServiceManager.AddService<IEditorInstance>(this, DiskBuffer, coreShell); }
public EditorInstance(ITextBuffer diskBuffer, IEditorDocumentFactory documentFactory, ICoreShell coreShell) { if (diskBuffer == null) { throw new ArgumentNullException(nameof(diskBuffer)); } if (documentFactory == null) { throw new ArgumentNullException(nameof(documentFactory)); } ViewBuffer = DiskBuffer = diskBuffer; _document = documentFactory.CreateDocument(this); ServiceManager.AddService <IEditorInstance>(this, ViewBuffer, coreShell); }
public QueryModel() { ModelUrl = "/query"; ApplicationModel.Current.Server.Value.RawUrl = null; queryDocument = new EditorDocument() { Language = SyntaxEditorHelper.LoadLanguageDefinitionFromResourceStream("RavenQuery.langdef") }; ExceptionLine = -1; ExceptionColumn = -1; CollectionSource = new QueryDocumentsCollectionSource(); Observable.FromEventPattern <QueryStatisticsUpdatedEventArgs>(h => CollectionSource.QueryStatisticsUpdated += h, h => CollectionSource.QueryStatisticsUpdated -= h) .SampleResponsive(TimeSpan.FromSeconds(0.5)) .TakeUntil(Unloaded) .ObserveOnDispatcher() .Subscribe(e => { QueryTime = e.EventArgs.QueryTime; Results = e.EventArgs.Statistics; }); Observable.FromEventPattern <QueryErrorEventArgs>(h => CollectionSource.QueryError += h, h => CollectionSource.QueryError -= h) .ObserveOnDispatcher() .Subscribe(e => HandleQueryError(e.EventArgs.Exception)); DocumentsResult = new DocumentsModel(CollectionSource) { Header = "Results", DocumentNavigatorFactory = (id, index) => DocumentNavigator.Create(id, index, IndexName, CollectionSource.TemplateQuery), }; QueryErrorMessage = new Observable <string>(); IsErrorVisible = new Observable <bool>(); SortBy = new BindableCollection <StringRef>(x => x.Value); SortBy.CollectionChanged += HandleSortByChanged; SortByOptions = new BindableCollection <string>(x => x); Suggestions = new BindableCollection <FieldAndTerm>(x => x.Field); DynamicOptions = new BindableCollection <string>(x => x) { "AllDocs" }; }
public static IEnumerable <string> GetTextOfAllTokensMatchingType(this IEditorDocument document, string tokenType) { var reader = document.CurrentSnapshot.GetReader(0); while (!reader.IsAtSnapshotEnd) { var token = reader.PeekToken(); if (token.Key == tokenType) { yield return(reader.ReadText(token.Length)); } else { reader.ReadToken(); } } }
/// <summary> /// Retrieves document instance from text buffer /// </summary> public static IEditorDocument TryFromTextBuffer(ITextBuffer textBuffer) { IEditorDocument document = ServiceManager.GetService <IEditorDocument>(textBuffer); if (document == null) { TextViewData viewData = TextViewConnectionListener.GetTextViewDataForBuffer(textBuffer); if (viewData != null && viewData.LastActiveView != null) { MdMainController controller = MdMainController.FromTextView(viewData.LastActiveView); if (controller != null && controller.TextBuffer != null) { document = ServiceManager.GetService <MdEditorDocument>(controller.TextBuffer); } } } return(document); }
public ProjectionEditorInstance(ITextBuffer diskBuffer, IEditorDocumentFactory documentFactory) { if (diskBuffer == null) { throw new ArgumentNullException(nameof(diskBuffer)); } if (documentFactory == null) { throw new ArgumentNullException(nameof(documentFactory)); } DiskBuffer = diskBuffer; _document = documentFactory.CreateDocument(this); var projectionBufferManager = ProjectionBufferManager.FromTextBuffer(diskBuffer); ViewBuffer = projectionBufferManager.ViewBuffer; ServiceManager.AddService <IEditorInstance>(this, DiskBuffer); }
public QueryIndexAutoComplete(IList <string> fields, string indexName, IEditorDocument queryDocument) { if (indexName != null && queryDocument != null) { this.indexName = indexName; this.queryDocument = queryDocument; queryDocument.ObserveTextChanged() .Throttle(TimeSpan.FromSeconds(0.2)) .ObserveOnDispatcher() .SubscribeWeakly(this, (target, _) => target.GetTermsForUsedFields()); CompletionProvider = new QueryIntelliPromptProvider(fields, indexName, fieldsTermsDictionary); } else { CompletionProvider = new QueryIntelliPromptProvider(fields, null, null); } this.fields.Match(fields); }
public QueryIndexAutoComplete(IList<string> fields, string indexName, IEditorDocument queryDocument) { if (indexName != null && queryDocument != null) { this.indexName = indexName; this.queryDocument = queryDocument; queryDocument.ObserveTextChanged() .Throttle(TimeSpan.FromSeconds(0.2)) .ObserveOnDispatcher() .SubscribeWeakly(this, (target, _) => target.GetTermsForUsedFields()); CompletionProvider = new QueryIntelliPromptProvider(fields, indexName, fieldsTermsDictionary); } else { CompletionProvider = new QueryIntelliPromptProvider(fields, null, null); } this.fields.Match(fields); }
private Task WhenParsingComplete(IEditorDocument document) { var tcs = new TaskCompletionSource <bool>(); if ((document.ParseData as ILLParseData).Snapshot == document.CurrentSnapshot) { tcs.SetResult(true); } else { EventHandler <ParseDataPropertyChangedEventArgs> completed = null; completed = (s, e) => { tcs.SetResult(true); document.ParseDataChanged -= completed; }; document.ParseDataChanged += completed; } return(tcs.Task); }
public QueryModel() { ModelUrl = "/query"; ApplicationModel.Current.Server.Value.RawUrl = null; SelectedTransformer = new Observable <string> { Value = "None" }; SelectedTransformer.PropertyChanged += (sender, args) => Requery(); ApplicationModel.DatabaseCommands.GetTransformersAsync(0, 256).ContinueOnSuccessInTheUIThread(transformers => { Transformers = new List <string> { "None" }; Transformers.AddRange(transformers.Select(definition => definition.Name)); OnPropertyChanged(() => Transformers); }); queryDocument = new EditorDocument { Language = SyntaxEditorHelper.LoadLanguageDefinitionFromResourceStream("RavenQuery.langdef") }; ExceptionLine = -1; ExceptionColumn = -1; CollectionSource = new QueryDocumentsCollectionSource(); Observable.FromEventPattern <QueryStatisticsUpdatedEventArgs>(h => CollectionSource.QueryStatisticsUpdated += h, h => CollectionSource.QueryStatisticsUpdated -= h) .SampleResponsive(TimeSpan.FromSeconds(0.5)) .TakeUntil(Unloaded) .ObserveOnDispatcher() .Subscribe(e => { QueryTime = e.EventArgs.QueryTime; Results = e.EventArgs.Statistics; }); Observable.FromEventPattern <QueryErrorEventArgs>(h => CollectionSource.QueryError += h, h => CollectionSource.QueryError -= h) .ObserveOnDispatcher() .Subscribe(e => HandleQueryError(e.EventArgs.Exception)); DocumentsResult = new DocumentsModel(CollectionSource) { Header = "Results", DocumentNavigatorFactory = (id, index) => DocumentNavigator.Create(id, index, IndexName, CollectionSource.TemplateQuery), }; QueryErrorMessage = new Observable <string>(); IsErrorVisible = new Observable <bool>(); SortBy = new BindableCollection <StringRef>(x => x.Value); SortBy.CollectionChanged += HandleSortByChanged; SortByOptions = new BindableCollection <string>(x => x); Suggestions = new BindableCollection <FieldAndTerm>(x => x.Field); DynamicOptions = new BindableCollection <string>(x => x) { "AllDocs" }; AvailableIndexes = new BindableCollection <string>(x => x); SpatialQuery = new SpatialQueryModel { IndexName = indexName }; }
public ShiftClass ShiftProgram(IEditorDocument doc, ShiftViewModel shift) { ShiftClass result; if (doc is KukaViewModel) { var kukaViewModel = doc as KukaViewModel; var shiftClass = new ShiftClass { Source = ShiftProgram(kukaViewModel.Source, shift) }; if (!string.IsNullOrEmpty(kukaViewModel.Data.Text)) { shiftClass.Data = ShiftProgram(kukaViewModel.Data, shift); } result = shiftClass; } else { var shiftClass = new ShiftClass { Source = ShiftProgram(doc.TextBox, shift) }; result = shiftClass; } return result; }
internal void Close(IEditorDocument fileToClose) { Files.Remove(fileToClose); // ReSharper disable once ExplicitCallerInfoArgument RaisePropertyChanged("ActiveEditor"); }
public static ITextView GetFirstView(this IEditorDocument document) { return(document.TextBuffer.GetFirstView()); }
public QueryModel() { ModelUrl = "/query"; ApplicationModel.Current.Server.Value.RawUrl = null; queryDocument = new EditorDocument() { Language = SyntaxEditorHelper.LoadLanguageDefinitionFromResourceStream("RavenQuery.langdef") }; ExceptionLine = -1; ExceptionColumn = -1; CollectionSource = new QueryDocumentsCollectionSource(); Observable.FromEventPattern<QueryStatisticsUpdatedEventArgs>(h => CollectionSource.QueryStatisticsUpdated += h, h => CollectionSource.QueryStatisticsUpdated -= h) .SampleResponsive(TimeSpan.FromSeconds(0.5)) .TakeUntil(Unloaded) .ObserveOnDispatcher() .Subscribe(e => { QueryTime = e.EventArgs.QueryTime; Results = e.EventArgs.Statistics; }); Observable.FromEventPattern<QueryErrorEventArgs>(h => CollectionSource.QueryError += h, h => CollectionSource.QueryError -= h) .ObserveOnDispatcher() .Subscribe(e => HandleQueryError(e.EventArgs.Exception)); DocumentsResult = new DocumentsModel(CollectionSource) { Header = "Results", DocumentNavigatorFactory = (id, index) => DocumentNavigator.Create(id, index, IndexName, CollectionSource.TemplateQuery), }; QueryErrorMessage = new Observable<string>(); IsErrorVisible = new Observable<bool>(); SortBy = new BindableCollection<StringRef>(x => x.Value); SortBy.CollectionChanged += HandleSortByChanged; SortByOptions = new BindableCollection<string>(x => x); Suggestions = new BindableCollection<FieldAndTerm>(x => x.Field); DynamicOptions = new BindableCollection<string>(x => x) {"AllDocs"}; }
private Task WhenParsingComplete(IEditorDocument editorDocument) { var tcs = new TaskCompletionSource<bool>(); if ((editorDocument.ParseData as ILLParseData).Snapshot == editorDocument.CurrentSnapshot) { tcs.SetResult(true); } else { EventHandler<ParseDataPropertyChangedEventArgs> completed = null; completed = (s, e) => { tcs.SetResult(true); editorDocument.ParseDataChanged -= completed; }; editorDocument.ParseDataChanged += completed; } return tcs.Task; }
private bool EditorDocumentHasErrors(IEditorDocument editorDocument) { var parseData = editorDocument.ParseData as ILLParseData; return parseData != null && parseData.Errors.Any(); }
private bool EditorDocumentHasErrors(IEditorDocument editorDocument) { var parseData = editorDocument.ParseData as ILLParseData; return(parseData != null && parseData.Errors.Any()); }
public static ITextBuffer TextBuffer(this IEditorDocument document) => document.EditorBuffer.As <ITextBuffer>();
public QueryModel() { ModelUrl = "/query"; ApplicationModel.Current.Server.Value.RawUrl = null; SelectedTransformer = new Observable<string> { Value = "None" }; SelectedTransformer.PropertyChanged += (sender, args) => Requery(); ApplicationModel.DatabaseCommands.GetTransformersAsync(0, 256).ContinueOnSuccessInTheUIThread(transformers => { Transformers = new List<string>{"None"}; Transformers.AddRange(transformers.Select(definition => definition.Name)); OnPropertyChanged(() => Transformers); }); queryDocument = new EditorDocument { Language = SyntaxEditorHelper.LoadLanguageDefinitionFromResourceStream("RavenQuery.langdef") }; ExceptionLine = -1; ExceptionColumn = -1; CollectionSource = new QueryDocumentsCollectionSource(); Observable.FromEventPattern<QueryStatisticsUpdatedEventArgs>(h => CollectionSource.QueryStatisticsUpdated += h, h => CollectionSource.QueryStatisticsUpdated -= h) .SampleResponsive(TimeSpan.FromSeconds(0.5)) .TakeUntil(Unloaded) .ObserveOnDispatcher() .Subscribe(e => { QueryTime = e.EventArgs.QueryTime; Results = e.EventArgs.Statistics; }); Observable.FromEventPattern<QueryErrorEventArgs>(h => CollectionSource.QueryError += h, h => CollectionSource.QueryError -= h) .ObserveOnDispatcher() .Subscribe(e => HandleQueryError(e.EventArgs.Exception)); DocumentsResult = new DocumentsModel(CollectionSource) { Header = "Results", DocumentNavigatorFactory = (id, index) => DocumentNavigator.Create(id, index, IndexName, CollectionSource.TemplateQuery), }; QueryErrorMessage = new Observable<string>(); IsErrorVisible = new Observable<bool>(); SortBy = new BindableCollection<StringRef>(x => x.Value); SortBy.CollectionChanged += HandleSortByChanged; SortByOptions = new BindableCollection<string>(x => x); Suggestions = new BindableCollection<FieldAndTerm>(x => x.Field); DynamicOptions = new BindableCollection<string>(x => x) {"AllDocs"}; AvailableIndexes = new BindableCollection<string>(x => x); SpatialQuery = new SpatialQueryModel {IndexName = indexName}; }
protected ProjectionEditorViewModel(IEditorDocument document, ITextDocumentFactoryService textDocumentFactoryService) : base(document, CreateViewBuffer(document.TextBuffer(), textDocumentFactoryService)) { }