void IInternalDocumentManager.OnDocumentCreated(Document document)
        {
            this.documentList.Add(document);

            var handler = this.DocumentCreated;

            if (handler != null)
            {
                handler(this, new DocumentCreatedEventArgs(document));
            }
        }
 public DocumentCreatedEventArgs(Document document)
 {
     this.Document = document;
 }
 void IInternalDocumentManager.OnDocumentClosed(Document document)
 {
     this.documentList.Remove(document);
 }
 void ObserveDocument(Document document)
 {
     document.Closed += OnDocumentClosed;
     document.PropertyChanged += OnDocumentPropertyChanged;
     UpdateList(document);
 }
        void UpdateList(Document document)
        {
            if (document.Identity == null || !document.AddToRecentDocuments)
            {
                return;
            }

            var existing = this.documentList.FirstOrDefault(d => d.Equals(document.Identity));

            if (existing == null)
            {
                this.documentList.Insert(0, document.Identity);
                if (this.documentList.Count > MaxRecentDocuments)
                {
                    this.documentList.RemoveAt(this.documentList.Count - 1);
                }
            }
            else
            {
                this.documentList.Remove(existing);
                this.documentList.Insert(0, existing);
            }

            var factory = this.DocumentManager.LookupDocumentFactory(document.Identity.FactoryName);
            string fileName;

            if (factory != null && factory.TryGetFileName(document.Identity, out fileName))
            {
                UpdateRecentFoldersList(fileName, true);
            }
        }
            public void ActivateDocument(Document document)
            {
                if (this.mainWindowDocumentTracker != null)
                {
                    // This is a secondary window.  If we're setting the active document to a specific document,
                    // that means we no longer track the main window's active document.  Conversely, if we're setting
                    // it to null, it means we revert to tracking the main window's active document.
                    if (document == null)
                    {
                        this.ActiveDocument = this.mainWindowDocumentTracker.ActiveDocument;
                        this.selectedDocument = this.activeDocumentCookie;
                        this.IsTrackingMainWindow = true;
                    }
                    else
                    {
                        this.ActiveDocument = document;
                        this.selectedDocument = FindWrapperForDocument(document);
                        this.IsTrackingMainWindow = false;
                    }
                }
                else
                {
                    this.ActiveDocument = document;
                    this.selectedDocument = FindWrapperForDocument(document);
                }

                // Note that we don't use the SelectedDocument property setter -- it is called by the XAML code
                // in response to the combo box selection, and results in calls to this method.
                Notify("SelectedDocument");
            }
 DocumentWrapper FindWrapperForDocument(Document doc)
 {
     return this.documentList.FirstOrDefault(w => (!(w is ActiveDocumentCookie)) && (w.WrappedDocument == doc));
 }
            public WindowDocumentTracker(ToolsUIWindow window, IServiceProvider serviceProvider)
                : base(serviceProvider)
            {
                this.thisWindow = window;
                this.mainWindow = ToolsUIApplication.Instance.MainToolsUIWindow ?? window;      // If MainToolsUIWindow is null, the window is (about to be) the main window
                this.documentList = new ObservableCollection<DocumentWrapper>();

                if (this.thisWindow != this.mainWindow)
                {
                    // This is not the main window.  All secondary windows are born tracking the main window's
                    // active document.
                    this.mainWindowDocumentTracker = this.mainWindow.ServiceProvider.GetService(typeof(IActiveDocumentTracker)) as IActiveDocumentTracker;

                    if (this.mainWindowDocumentTracker != null)
                    {
                        this.mainWindowDocumentTracker.ActiveDocumentChanged += OnMainWindowActiveDocumentChanged;
                        this.activeDocumentCookie = new ActiveDocumentCookie(this.thisWindow);
                        this.activeDocument = this.mainWindowDocumentTracker.ActiveDocument;
                        this.activeDocumentCookie.WrappedDocument = this.mainWindowDocumentTracker.ActiveDocument;
                        this.isTrackingMainWindow = true;
                        this.mainWindow.Closed += OnMainWindowClosed;
                    }
                }

                this.documentListAsINCC = this.DocumentManager.Documents as INotifyCollectionChanged;

                if (this.documentListAsINCC != null)
                {
                    this.documentListAsINCC.CollectionChanged += OnDocumentListChanged;
                }

                InitializeDocumentList();
                this.selectedDocument = this.activeDocumentCookie ?? this.documentList.FirstOrDefault(d => d.WrappedDocument == this.activeDocument);
            }