示例#1
0
        protected void OnDocumentOpened(Document document)
        {
            CheckDocumentIsClosed(document.Id);

            using (_serializationLock.DisposableWait())
            {
                var oldDocuments = this.CurrentDocuments;
                var oldDocument  = oldDocuments.GetDocument(document.Id);

                // TODO: If document exists but is not opened (i.e. a previously closed #include'd file), then re-use it.

                AddToOpenDocumentMap(document.Id);

                var currentDocuments = oldDocument != null
                    ? oldDocuments.WithDocumentText(document.Id, document.SourceText)
                    : oldDocuments.AddDocument(document);

                var newSolution = this.SetCurrentDocuments(currentDocuments);
                SignupForTextChanges(document.Id, document.SourceText.Container, (w, id, text) => w.OnDocumentTextChanged(id, text));

                var newDoc = newSolution.GetDocument(document.Id);
                this.OnDocumentTextChanged(newDoc);

                DocumentOpened?.Invoke(this, new DocumentEventArgs(newDoc));
            }

            RegisterText(document.SourceText.Container);
        }
示例#2
0
        /// <inheritdoc/>
        public sealed override async Task <bool> Initialize()
        {
            var projectWatcher = await StrideAssetsViewModel.Instance.Code.ProjectWatcher;

            RoslynHost = await projectWatcher.RoslynHost;
            Workspace  = await StrideAssetsViewModel.Instance.Code.Workspace;

            Workspace.HostDocumentClosed += WorkspaceHostDocumentClosed;

            if (Asset.DocumentId == null)
            {
                return(false);
            }

            // Open document
            DocumentId = Workspace.OpenDocument(SourceTextContainer, await Asset.DocumentId,
                                                a => Dispatcher.Invoke(() => ProcessDiagnostics?.Invoke(this, a)));
            //Workspace.TrackDocument(await Asset.DocumentId, OnTextUpdated);

            // Failed? let's close editor right away
            if (DocumentId == null)
            {
                return(false);
            }

            DocumentOpened?.Invoke(this, EventArgs.Empty);

            return(true);
        }
示例#3
0
        public void OpenProgram(string fullpath)
        {
            var openedProgram = OpenedDocuments.FirstOrDefault(op => op.ProgramFullPath == fullpath);

            if (openedProgram != null)
            {
                DocumentOpened?.Invoke(this, new DocumentOpenEventArgs(openedProgram));
                return;
            }

            var programforOpening =
                RecentPrograms.FirstOrDefault(p => p.ProgramFullPath == fullpath);

            if (programforOpening == null)
            {
                programforOpening = ProgramViewModel.Create(fullpath, this, TvcStudioSettings);
                RecentPrograms.Add(programforOpening);
            }

            if (programforOpening.ProgramState == ProgramState.NotFound)
            {
                TraceEngine.TraceError($"{programforOpening.ProgramFullPath} beolvasása sikertelen, a file nem található!");
                return;
            }

            openedProgram = programforOpening.GetDocumentViewModel();
            openedProgram.DocumentClosedEvent += OnDocumentClose;
            OpenedDocuments.Add(openedProgram);
            programforOpening.ProgramState = ProgramState.Opened;
            DocumentOpened?.Invoke(this, new DocumentOpenEventArgs(openedProgram));
        }
        // fired when a document is about to be shown on screen for various
        // reasons
        //
        public override int OnBeforeDocumentWindowShow(
            uint itemCookie, int first, IVsWindowFrame wf)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            // this may be called any time after the solution is loaded since
            // window frames are lazily created when a tab is clicked for the
            // first time

            if (first == 0)
            {
                // only handle the first time a document is shown
                return(VSConstants.S_OK);
            }

            Trace(
                "OnBeforeDocumentWindowShow: {0}",
                VSDocument.DebugWindowFrameName(wf));

            var d = VSDocument.DocumentFromWindowFrame(wf);

            if (d == null)
            {
                Error("OnBeforeDocumentWindowShow: frame has no document");
                return(VSConstants.S_OK);
            }

            DocumentOpened?.Invoke(new VSDocument(d, wf));

            return(VSConstants.S_OK);
        }
示例#5
0
 private void OnDocumentOpen(EventArgs e)
 {
     if (DocumentOpened != null)
     {
         DocumentOpened.Invoke(this, e);
     }
 }
示例#6
0
 void OnDocumentOpened(DocumentEventArgs e)
 {
     try {
         DocumentOpened?.Invoke(this, e);
     } catch (Exception ex) {
         LoggingService.LogError("Exception while opening documents", ex);
     }
 }
示例#7
0
        private void _HandleTextDocumentOpened(object sender, DidOpenTextDocumentParams e)
        {
            WorkspaceDocument document = new WorkspaceDocument(e.TextDocument.LanguageId, e.TextDocument.Text, e.TextDocument.Uri, e.TextDocument.Version);

            _documents.Add(document);

            DocumentOpened?.Invoke(this, document);
        }
示例#8
0
        public void OpenReadonlyDocument(string fullPath)
        {
            var openedProgram = OpenedDocuments.FirstOrDefault(op => op.ProgramFullPath == fullPath);

            if (openedProgram != null)
            {
                DocumentOpened?.Invoke(this, new DocumentOpenEventArgs(openedProgram));
                return;
            }

            openedProgram = new ReadOnlyDocumentViewModel(fullPath, TvcStudioSettings);
            openedProgram.DocumentClosedEvent += OnDocumentClose;
            OpenedDocuments.Add(openedProgram);
            DocumentOpened?.Invoke(this, new DocumentOpenEventArgs(openedProgram));
        }
示例#9
0
        // 'Safe' in the sense that all exceptions are caught (and reported via OnOpenException).
        private IDocument SafeOpen(IDocumentClient client, Uri uri)
        {
            IDocument document = null;

            try
            {
                if (client.CanOpen(uri))
                {
                    if (OnDocumentOpening(uri))
                    {
                        document = client.Open(uri);
                        if (document != null)
                        {
                            OnDocumentOpened(document);
                            DocumentOpened.Raise(this, new DocumentEventArgs(document, DocumentEventType.Opened));

                            DocumentRegistry.ActiveDocument = document;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // DAN: Added this - if an exception occurs during line:
                // DocumentRegistry.ActiveDocument = document;
                // then we need to remove it
                if (DocumentRegistry.ActiveDocument == document)
                {
                    DocumentRegistry.Remove(document);
                }

                document = null;

                // Let's share the exception directly. We used to wrap it in another Exception
                //  object but this hides the actual exception in the error dialog.
                OnOpenException(ex);
            }

            return(document);
        }
示例#10
0
 protected virtual void OnDocumentOpened(VsDocumentEventArgs e)
 {
     DocumentOpened?.Invoke(this, e);
 }
示例#11
0
 void OnDocumentOpened(DocumentEventArgs e)
 {
     DocumentOpened?.SafeInvoke(this, e);
 }
 private void DocumentEventsOnDocumentOpened(Document document)
 {
     _logger.LogVerbose($"{document.FullName}, {document.Type}");
     DocumentOpened?.Invoke(document);
 }