コード例 #1
0
        /// <summary>
        /// 增加Tab;
        /// </summary>
        /// <param name="doc"></param>
        public void AddDocument(IDocumentBase doc)
        {
            if (doc == null)
            {
                throw new ArgumentNullException(nameof(doc));
            }

            if (!(doc is DocumentBase document))
            {
                throw new InvalidOperationException($"{doc.GetType()} is not a valid type,please user ${nameof(IDocumentService.CreateNewDocument)} instead.");
            }

            if (VM.Documents.FirstOrDefault(p => p == doc) != null)
            {
                SelectedDocument = doc;
                return;
            }

            CommonEventHelper.GetEvent <DocumentAddingEvent>().Publish((doc, this));

            document.CloseRequest += Document_CloseRequest;

            VM.Documents.Add(document);

            CommonEventHelper.PublishEventToHandlers((doc, this as IDocumentService), _documentAddedEventHandlers);
            CommonEventHelper.GetEvent <DocumentAddedEvent>().Publish((doc, this));

            SelectedDocument = document;
        }
コード例 #2
0
        /// <summary>
        /// 移除Tab;
        /// </summary>
        /// <param name="doc"></param>
        public void RemoveDocument(IDocumentBase doc)
        {
            if (doc == null)
            {
                throw new ArgumentNullException(nameof(doc));
            }

            if (!(doc is DocumentBase document))
            {
                throw new InvalidOperationException($"{doc.GetType()} is not a valid type,please user ${nameof(IDocumentService.CreateNewDocument)} instead.");
            }

            var cEvg = new CancelEventArgs();

            CommonEventHelper.GetEvent <DocumentClosingEvent>().Publish((doc, cEvg, this));
            if (cEvg.Cancel)
            {
                return;
            }

            VM.Documents.Remove(document);

            CommonEventHelper.PublishEventToHandlers((doc as IDocumentBase, this as IDocumentService), _documentClosedEventHandlers);
            CommonEventHelper.GetEvent <DocumentClosedEvent>().Publish((doc, this));

            document.CloseRequest -= Document_CloseRequest;

            if (VM.Documents.Count == 0)
            {
                SelectedDocument = null;
                CommonEventHelper.GetEvent <DocumentsCleared>().Publish(this);
            }

#if DEBUG
            for (int i = 0; i < 2; i++)
            {
                System.GC.Collect();
                System.GC.WaitForPendingFinalizers();
            }
#endif
        }