コード例 #1
0
        public AddParticleDlgViewModel(IParticlesManager particleManager, Type targetType, IBlockManager blockManager)
        {
            _particleManager = particleManager;
            _blockManager = blockManager;
            AddParticleVm = new AddParticleViewViewModel(_particleManager, Visibility.Collapsed);
            OkCommand = new DelegateCommand<Window>((wnd) =>
            {
                if (AddParticleVm.UseNewParticle)
                {
                    var particle = _particleManager.CreateParticle(AddParticleVm.NewParticle.Material,
                        AddParticleVm.NewParticle.Begin, AddParticleVm.NewParticle.End);
                    _blockManager.AddParticleToBlock(_block, particle);
                }
                else if (AddParticleVm.UseExistParticle && AddParticleVm.ExistParticle.HasValue)
                {
                    var particle = _particleManager.GetParticleById(AddParticleVm.ExistParticle.Value);
                    _blockManager.AddParticleToBlock(_block, particle);
                }

                wnd.DialogResult = true;
                wnd.Close();
            }, wnd => _block != null && (AddParticleVm.UseNewParticle || AddParticleVm.UseExistParticle));

            SelectIdeaCommand = new DelegateCommand(() =>
            {
                var dlg = new SelectTagDlg(targetType);
                var res = dlg.ShowDialog();
                if (res.HasValue && res.Value && dlg.Id.HasValue)
                {
                    _block = _blockManager.GetBlockById(dlg.Id.Value);
                    BlockCaption = _block.Caption;
                    OkCommand.RaiseCanExecuteChanged();
                }
            });
        }
コード例 #2
0
        public CreateCommentDlgViewModel(IParticlesManager particlesManager, IBlockManager blockManager,
            ICommentManager commentManager, IEventAggregator eventAggregator)
        {
            _particlesManager = particlesManager;
            _blockManager = blockManager;
            _commentManager = commentManager;
            _eventAggregator = eventAggregator;
            AddParticleVm = new AddParticleViewViewModel(particlesManager);

            SelectBlockCommand = new DelegateCommand(() =>
            {
                var dlg = new SelectTagDlg(typeof (Guidable));
                var res = dlg.ShowDialog();
                if (res.HasValue && res.Value && dlg.Id.HasValue)
                {
                    _myGuidable = _blockManager.GetGuidableById(dlg.Id.Value);
                    OkCommand.RaiseCanExecuteChanged();
                    if (_myGuidable is Material)
                        GuidableCaption = (_myGuidable as Material).Name;
                    else if (_myGuidable is Block)
                        GuidableCaption = (_myGuidable as Block).Caption;
                }
            });

            OkCommand = new DelegateCommand<Window>((wnd) =>
            {
                var comment = _commentManager.CreateComment(Caption, _myGuidable);

                if (AddParticleVm.AddParticle)
                    if (AddParticleVm.UseNewParticle)
                    {
                        var particle = _particlesManager.CreateParticle(AddParticleVm.NewParticle.Material,
                            AddParticleVm.NewParticle.Begin, AddParticleVm.NewParticle.End);
                        _blockManager.AddParticleToBlock(comment, particle);
                    }
                    else if (AddParticleVm.UseExistParticle && AddParticleVm.ExistParticle.HasValue)
                    {
                        var particle = _particlesManager.GetParticleById(AddParticleVm.ExistParticle.Value);
                        _blockManager.AddParticleToBlock(comment, particle);
                    }

                _eventAggregator.GetEvent<BlockAddedEvent>().Publish(comment.Id);
                wnd.DialogResult = true;
                wnd.Close();
            }, wnd => !String.IsNullOrWhiteSpace(Caption) && _myGuidable != null);
        }
コード例 #3
0
        public CreateIdeaDlgViewModel(ITagsManager tagsManager, IParticlesManager particleManager,
            IIdeaManager ideaManager, IBlockManager blockManager, IEventAggregator eventAggregator)
        {
            _tagsManager = tagsManager;
            _particleManager = particleManager;
            _ideaManager = ideaManager;
            _blockManager = blockManager;
            _eventAggregator = eventAggregator;
            AddParticleVm = new AddParticleViewViewModel(_particleManager);
            OkCommand = new DelegateCommand<Window>((wnd) =>
            {
                var idea = _ideaManager.CreateIdea(Caption);
                if (_parentTag != null)
                    _ideaManager.AddTagToIdea(idea, _parentTag);

                if (AddParticleVm.AddParticle)
                    if (AddParticleVm.UseNewParticle)
                    {
                        var particle = _particleManager.CreateParticle(AddParticleVm.NewParticle.Material,
                            AddParticleVm.NewParticle.Begin, AddParticleVm.NewParticle.End);
                        _blockManager.AddParticleToBlock(idea, particle);
                    }
                    else if (AddParticleVm.UseExistParticle && AddParticleVm.ExistParticle.HasValue)
                    {
                        var particle = _particleManager.GetParticleById(AddParticleVm.ExistParticle.Value);
                        _blockManager.AddParticleToBlock(idea, particle);
                    }

                _eventAggregator.GetEvent<BlockAddedEvent>().Publish(idea.Id);
                wnd.DialogResult = true;
                wnd.Close();
            }, wnd => !String.IsNullOrWhiteSpace(Caption));

            SelectTagCommand = new DelegateCommand(() =>
            {
                var dlg = new SelectTagDlg(typeof (Tag));
                var res = dlg.ShowDialog();
                if (res.HasValue && res.Value && dlg.Id.HasValue)
                {
                    _parentTag = _tagsManager.GetTagById(dlg.Id.Value);
                    TagCaption = _parentTag.Caption;
                    AddToTag = true;
                }
            });
        }
コード例 #4
0
        private void SetParticleIfExist(AddParticleViewViewModel model)
        {
            if (!String.IsNullOrEmpty(SelectedBookmark))
                model.ExistParticle = StringToGuid(SelectedBookmark);

            if (SelectionRange.HasValue && SelectionRange.Value.Length > 0 && !IsIntersect(SelectionRange.Value))
                model.NewParticle = new ParticleDto()
                {
                    Material = MyMaterial.Id,
                    Begin = SelectionRange.Value.Start,
                    End = SelectionRange.Value.Start + SelectionRange.Value.Length,
                    Text = SelectionRange.Value.GetText(MyDocument)
                };
        }
コード例 #5
0
        public CreateRelationDlgViewModel(IParticlesManager particlesManager, IIdeaManager ideaManager,
            IRelationManager relationManager, IBlockManager blockManager, IEventAggregator eventAggregator)
        {
            _particlesManager = particlesManager;
            _ideaManager = ideaManager;
            _relationManager = relationManager;
            _blockManager = blockManager;
            _eventAggregator = eventAggregator;
            AddParticleVm = new AddParticleViewViewModel(_particlesManager);

            SelectIdea1Command = new DelegateCommand(() =>
            {
                var dlg = new SelectTagDlg(typeof (Idea));
                var res = dlg.ShowDialog();
                if (res.HasValue && res.Value && dlg.Id.HasValue)
                {
                    _idea1 = _ideaManager.GetIdeaById(dlg.Id.Value);
                    Idea1Caption = _idea1.Caption;
                    OnPropertyChanged("Idea1Caption");
                }
                OkCommand.RaiseCanExecuteChanged();
            });

            SelectIdea2Command = new DelegateCommand(() =>
            {
                var dlg = new SelectTagDlg(typeof (Idea));
                var res = dlg.ShowDialog();
                if (res.HasValue && res.Value && dlg.Id.HasValue)
                {
                    _idea2 = _ideaManager.GetIdeaById(dlg.Id.Value);
                    Idea2Caption = _idea2.Caption;
                    OnPropertyChanged("Idea2Caption");
                }
                OkCommand.RaiseCanExecuteChanged();
            });

            AddRelationTypeCommand = new DelegateCommand<RoutedEventArgs>(e =>
            {
                var text = ((ButtonEdit) e.Source).Text;
                var rt = _relationManager.AddRelationType(text);
                var relationDto = new RelationTypeDto() {Id = rt.Id, Name = text};
                Relations.Add(relationDto);
                Relation = relationDto;
            });

            OkCommand = new DelegateCommand<Window>(wnd =>
            {
                var relation = _relationManager.CreateRelation(Relation.Id, _idea1.Id, _idea2.Id);

                if (AddParticleVm.AddParticle)
                    if (AddParticleVm.UseNewParticle)
                    {
                        var particle = _particlesManager.CreateParticle(AddParticleVm.NewParticle.Material,
                            AddParticleVm.NewParticle.Begin, AddParticleVm.NewParticle.End);
                        _blockManager.AddParticleToBlock(relation, particle);
                    }
                    else if (AddParticleVm.UseExistParticle && AddParticleVm.ExistParticle.HasValue)
                    {
                        var particle = _particlesManager.GetParticleById(AddParticleVm.ExistParticle.Value);
                        _blockManager.AddParticleToBlock(relation, particle);
                    }

                _eventAggregator.GetEvent<BlockAddedEvent>().Publish(relation.Id);
                wnd.DialogResult = true;
                wnd.Close();
            }, wnd => Relation != null && _idea1 != null && _idea2 != null);

            Relations =
                new ObservableCollection<RelationTypeDto>(
                    _relationManager.GetRelationTypes()
                        .Select(rt => new RelationTypeDto() {Id = rt.Id, Name = rt.Caption}));
        }