示例#1
0
        public void CloseDocument(Document document)
        {
            int index = OpenDocuments.IndexOf(document);

            OpenDocuments.Remove(document);

            if (index == active_document_index)
            {
                // If there's other documents open, switch to one of them
                if (HasOpenDocuments)
                {
                    if (index > 0)
                    {
                        SetActiveDocument(index - 1);
                    }
                    else
                    {
                        SetActiveDocument(index);
                    }
                }
                else
                {
                    active_document_index = -1;
                    OnActiveDocumentChanged(EventArgs.Empty);
                }
            }

            document.Close();

            OnDocumentClosed(new DocumentEventArgs(document));
        }
示例#2
0
        public async Task CloseDocument(OpenDocumentViewModel document)
        {
            if (document == null)
            {
                return;
            }

            var result = await document.Save(promptSave : true).ConfigureAwait(true);

            if (result == SaveResult.Cancel)
            {
                return;
            }

            // ReSharper disable once PossibleNullReferenceException
            var autoSavePath = document.Document?.GetAutoSavePath();

            if (autoSavePath != null && File.Exists(autoSavePath))
            {
                File.Delete(autoSavePath);
            }

            RoslynHost.CloseDocument(document.DocumentId);
            OpenDocuments.Remove(document);
            document.Close();
        }
        public void ProjectDoubleClick()
        {
            if (SelectedSolutionItem == null || !SelectedSolutionItem.HasPreview)
            {
                return;
            }

            var alreadyOpenDocument = OpenDocuments.FirstOrDefault(d => d.AssociatedModel == SelectedSolutionItem);

            if (alreadyOpenDocument?.IsTemporary == true)
            {
                OpenDocuments.Remove(alreadyOpenDocument);
                alreadyOpenDocument = null;
            }

            if (alreadyOpenDocument != null)
            {
                ActiveDocument = alreadyOpenDocument;
            }
            else
            {
                var document = OpenDocument(SelectedSolutionItem);

                OpenDocuments.Add(document);
                ActiveDocument = document;
            }
        }
示例#4
0
        /// <summary>
        /// Closes a document in the document viewer.
        /// </summary>
        /// <param name="filePath">Path of the document, which should be closed.</param>
        public void CloseDocument(string filePath)
        {
            try
            {
                System.Windows.Input.Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;

                DocumentViewModel documentToRemove = null;
                foreach (var openDocument in OpenDocuments)
                {
                    if (openDocument.FilePath.Equals(filePath, StringComparison.OrdinalIgnoreCase))
                    {
                        documentToRemove = openDocument;
                        break;
                    }
                }
                if (documentToRemove != null)
                {
                    OpenDocuments.Remove(documentToRemove);
                }
            }
            finally
            {
                System.Windows.Input.Mouse.OverrideCursor = null;
            }
        }
示例#5
0
        public void CloseDocument(DocumentViewModel document)
        {
            // TODO: Check if not saved
            OpenDocuments.Remove(document);

            if (document.Token != null)
            {
                SaveFileTokensAsync();
            }
        }
示例#6
0
        public async Task CloseDocument(OpenDocumentViewModel document)
        {
            var result = await document.Save(promptSave : true).ConfigureAwait(true);

            if (result == SaveResult.Cancel)
            {
                return;
            }
            if (document.Document?.IsAutoSave == true)
            {
                File.Delete(document.Document.Path);
            }
            RoslynHost.CloseDocument(document.DocumentId);
            OpenDocuments.Remove(document);
            document.Close();
        }