Esempio n. 1
0
        public ToolboxViewModel(DefaultWorkspace workspace,
                                IEventAggregator eventAggregator,
                                IToolboxToolbarService toolboxToolbarService
                                )
            : base(toolboxToolbarService)
        {
            _eventAggregator = eventAggregator;
            _workspace       = workspace;


            Name      = "Toolbox";
            Title     = "Toolbox";
            ContentId = "Toolbox";//TODO : Move to constants
            IsVisible = false;


            _view = new ToolboxUserControl(this);
            View  = _view;


            _items = new ObservableCollection <ToolboxItemViewModel>();

            var groupedItems = CollectionViewSource.GetDefaultView(_items);

            groupedItems.GroupDescriptions.Add(new PropertyGroupDescription("Category"));


            //TODO : !!!This should check specific folder to scan assemblies for toolbox items
            _toolboxItems = Assembly.GetEntryAssembly()
                            .GetTypes()
                            .Where(y => y.GetCustomAttributes <ToolboxItemAttribute>(true).Any())
                            .Select(x =>
            {
                var attribute = x.GetCustomAttributes <ToolboxItemAttribute>(true).First();
                return(new ToolboxItem
                {
                    DocumentType = attribute.DocumentType,
                    Name = attribute.Name,
                    Category = attribute.Category,
                    IconSource = (attribute.IconSource != null) ? new Uri(attribute.IconSource) : null,
                    ItemType = x,
                });
            })
                            .GroupBy(x => x.DocumentType)
                            .ToDictionary(x => x.Key.Name, x => x.AsEnumerable().ToList());

            RefreshToolboxItems();

            _eventAggregator.GetEvent <ActiveContentChangedEvent>().Subscribe(ActiveContentChanged);
        }
Esempio n. 2
0
        public void Initialize()
        {
            _eventAggregator.GetEvent <SplashScreenUpdateEvent>().Publish(new SplashScreenUpdateEvent {
                Text = "Loading Toolbox..."
            });

            _container.RegisterType <IToolboxService, ToolboxViewModel>(new ContainerControlledLifetimeManager());
            _container.RegisterType <ToolboxViewModel>(new ContainerControlledLifetimeManager());

            _container.RegisterType <IToolboxToolbarService, ToolboxToolbarService>(new ContainerControlledLifetimeManager());

            _toolboxViewModel = _container.Resolve <ToolboxViewModel>();

            _toolbarService = _container.Resolve <IToolboxToolbarService>();



            LoadCommands();
            LoadToolbar();

            _workspace.Tools.Add(_toolboxViewModel);
        }