示例#1
0
        bool IsViewAffinitized(IViewCreationCommand viewCommand, DocumentCategory category)
        {
            if (viewCommand.IsInternalOnly && !this.ShowInternalViews)
            {
                // No internal views...
                return(false);
            }

            if (viewCommand.DocumentFactoryAffinities.Count() == 0)
            {
                // This view has no declared affinity, so it can go anywhere
                return(true);
            }

            if ((category == null) || (category.DocumentFactoryName == null))
            {
                // This view has declared affinity(ies), so it can't go in the 'Any' layouts
                return(false);
            }

            // This view is affinitized if it has declared affinity with the active document factory
            return(viewCommand.DocumentFactoryAffinities.Contains(category.DocumentFactoryName));
        }
        void Initialize()
        {
            ComputeStateStorageDirectory(this.AppName, this.AppVersion);

            this.ExtensionManager = new ExtensionManager(this.StateStorageDirectory);
            this.ExtensionManager.LoadState(this.ExtensionAssemblies);

            this.RootServiceProvider = new RootServiceProvider(this.ExtensionManager);
            this.RootServiceProvider.AddService(typeof(IUserNotificationService), new SimpleNotificationService(this.AppTitle));
            this.RootServiceProvider.AddService(typeof(ToolsUIApplication), this);
            this.RootServiceProvider.AddService(this.GetType(), this);
            this.RootServiceProvider.AddService(typeof(Dispatcher), Dispatcher.CurrentDispatcher);

            this.sessionStateService = new SessionStateService();
            this.RootServiceProvider.AddService(typeof(ISessionStateService), this.sessionStateService);

            this.windowStateFileName = Path.Combine(this.StateStorageDirectory, "WindowState.xml");
            this.sessionStateFileName = Path.Combine(this.StateStorageDirectory, "SessionState.xml");
            if (File.Exists(this.sessionStateFileName))
            {
                try
                {
                    XElement sessionState = XElement.Load(this.sessionStateFileName);
                    this.sessionStateService.SetFullSessionState(sessionState);
                }
                catch (Exception)
                {
                }
            }

            this.sessionStateService.StateSaveRequested += OnSessionStateSaveRequested;
            InitializeTheme();

            this.viewCreators = this.ExtensionManager.BuildViewCreatorDictionary();

            this.RecentDocumentService = this.RootServiceProvider.GetService(typeof(RecentDocumentService)) as RecentDocumentService;
            if (this.RecentDocumentService != null)
            {
                ((INotifyCollectionChanged)this.RecentDocumentService.DocumentIdentities).CollectionChanged += OnRecentDocumentIdentitiesCollectionChanged;
                OnRecentDocumentIdentitiesCollectionChanged(null, null);
            }

            this.FoldersSource.GroupDescriptions.Add(new PropertyGroupDescription { PropertyName = "Category" });

            if (this.RecentDocumentService != null)
            {
                NotifyCollectionChangedEventHandler handler = (s, e) =>
                {
                    this.FoldersSource.Source = new CategorizedFolder[] 
                    { 
                        new CategorizedFolder 
                        { 
                            Category = "Current Folder", 
                            DirectoryInfo = new DirectoryInfo(Directory.GetCurrentDirectory()), 
                            ShortcutKey = "C" 
                        } 
                    }.Concat(this.RecentDocumentService.RecentFolders.Select((d, i) => new CategorizedFolder
                    {
                        Category = "Recent Folders",
                        DirectoryInfo = d,
                        ShortcutKey = string.Format("D{0}", i + 1)
                    }));
                };

                ((INotifyCollectionChanged)this.RecentDocumentService.RecentFolders).CollectionChanged += handler;
                handler(null, null);
            }

            this.documentCategories = new List<DocumentCategory>();
            foreach (var factoryName in this.ExtensionManager.DocumentFactoryNames)
            {
                var factory = this.ExtensionManager.LookupDocumentFactory(factoryName);

                if (factory != null)
                {
                    var category = new DocumentCategory { DisplayName = factory.DocumentKind, DocumentFactoryName = factoryName };
                    BindingOperations.SetBinding(category, DocumentCategory.ColorProperty, Theme.CreateBinding(factory.ColorThemePropertyName));
                    this.documentCategories.Add(category);
                }
            }

            this.documentCategories.Add(new DocumentCategory { Color = Colors.Transparent, DisplayName = "Any", DocumentFactoryName = null });

            OnInitialized();
        }
        bool IsViewAffinitized(IViewCreationCommand viewCommand, DocumentCategory category)
        {
            if (viewCommand.IsInternalOnly && !this.ShowInternalViews)
            {
                // No internal views...
                return false;
            }

            if (viewCommand.DocumentFactoryAffinities.Count() == 0)
            {
                // This view has no declared affinity, so it can go anywhere
                return true;
            }

            if ((category == null) || (category.DocumentFactoryName == null))
            {
                // This view has declared affinity(ies), so it can't go in the 'Any' layouts
                return false;
            }

            // This view is affinitized if it has declared affinity with the active document factory
            return viewCommand.DocumentFactoryAffinities.Contains(category.DocumentFactoryName);
        }
示例#4
0
        void Initialize()
        {
            ComputeStateStorageDirectory(this.AppName, this.AppVersion);

            this.ExtensionManager = new ExtensionManager(this.StateStorageDirectory);
            this.ExtensionManager.LoadState(this.ExtensionAssemblies);

            this.RootServiceProvider = new RootServiceProvider(this.ExtensionManager);
            this.RootServiceProvider.AddService(typeof(IUserNotificationService), new SimpleNotificationService(this.AppTitle));
            this.RootServiceProvider.AddService(typeof(ToolsUIApplication), this);
            this.RootServiceProvider.AddService(this.GetType(), this);
            this.RootServiceProvider.AddService(typeof(Dispatcher), Dispatcher.CurrentDispatcher);

            this.sessionStateService = new SessionStateService();
            this.RootServiceProvider.AddService(typeof(ISessionStateService), this.sessionStateService);

            this.windowStateFileName  = Path.Combine(this.StateStorageDirectory, "WindowState.xml");
            this.sessionStateFileName = Path.Combine(this.StateStorageDirectory, "SessionState.xml");
            if (File.Exists(this.sessionStateFileName))
            {
                try
                {
                    XElement sessionState = XElement.Load(this.sessionStateFileName);
                    this.sessionStateService.SetFullSessionState(sessionState);
                }
                catch (Exception)
                {
                }
            }

            this.sessionStateService.StateSaveRequested += OnSessionStateSaveRequested;
            InitializeTheme();

            this.viewCreators = this.ExtensionManager.BuildViewCreatorDictionary();

            this.RecentDocumentService = this.RootServiceProvider.GetService(typeof(RecentDocumentService)) as RecentDocumentService;
            if (this.RecentDocumentService != null)
            {
                ((INotifyCollectionChanged)this.RecentDocumentService.DocumentIdentities).CollectionChanged += OnRecentDocumentIdentitiesCollectionChanged;
                OnRecentDocumentIdentitiesCollectionChanged(null, null);
            }

            this.FoldersSource.GroupDescriptions.Add(new PropertyGroupDescription {
                PropertyName = "Category"
            });

            if (this.RecentDocumentService != null)
            {
                NotifyCollectionChangedEventHandler handler = (s, e) =>
                {
                    this.FoldersSource.Source = new CategorizedFolder[]
                    {
                        new CategorizedFolder
                        {
                            Category      = "Current Folder",
                            DirectoryInfo = new DirectoryInfo(Directory.GetCurrentDirectory()),
                            ShortcutKey   = "C"
                        }
                    }.Concat(this.RecentDocumentService.RecentFolders.Select((d, i) => new CategorizedFolder
                    {
                        Category      = "Recent Folders",
                        DirectoryInfo = d,
                        ShortcutKey   = string.Format("D{0}", i + 1)
                    }));
                };

                ((INotifyCollectionChanged)this.RecentDocumentService.RecentFolders).CollectionChanged += handler;
                handler(null, null);
            }

            this.documentCategories = new List <DocumentCategory>();
            foreach (var factoryName in this.ExtensionManager.DocumentFactoryNames)
            {
                var factory = this.ExtensionManager.LookupDocumentFactory(factoryName);

                if (factory != null)
                {
                    var category = new DocumentCategory {
                        DisplayName = factory.DocumentKind, DocumentFactoryName = factoryName
                    };
                    BindingOperations.SetBinding(category, DocumentCategory.ColorProperty, Theme.CreateBinding(factory.ColorThemePropertyName));
                    this.documentCategories.Add(category);
                }
            }

            this.documentCategories.Add(new DocumentCategory {
                Color = Colors.Transparent, DisplayName = "Any", DocumentFactoryName = null
            });

            OnInitialized();
        }