private void treeViewCrowd_PreviewDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(Constants.CROWD_MEMBER_DRAG_FROM_CHAR_XPLORER_KEY))
            {
                FindDropTarget((TreeView)sender, out currentDropItemNode, e);

                if (currentDropItemNode != null)
                {
                    var        dropMember  = (currentDropItemNode != null && currentDropItemNode.IsVisible ? currentDropItemNode.DataContext : null);
                    var        dragMember  = e.Data.GetData(Constants.CROWD_MEMBER_DRAG_FROM_CHAR_XPLORER_KEY);
                    CrowdModel targetCrowd = null;
                    if (dropMember is CrowdModel)
                    {
                        targetCrowd = dropMember as CrowdModel;
                        currentDropItemNodeParent = currentDropItemNode;
                    }
                    else
                    {
                        currentDropItemNodeParent = GetImmediateTreeViewItemParent(currentDropItemNode);
                        targetCrowd = currentDropItemNodeParent != null ? currentDropItemNodeParent.DataContext as CrowdModel : null;
                    }

                    this.viewModel.DragDropSelectedCrowdMember(targetCrowd);
                }
            }
        }
        private void treeViewCrowd_PreviewKeyUp(object sender, KeyEventArgs e)
        {
            TreeViewItem treeViewItem = VisualUpwardSearch(e.OriginalSource as DependencyObject);

            if (treeViewItem != null)
            {
                TreeViewItem item = GetRootTreeViewItemParent(treeViewItem);
                if (item != null)
                {
                    this.selectedCrowdRoot = item.DataContext as CrowdModel;
                }
                else
                {
                    this.selectedCrowdRoot = null;
                }
                if (treeViewItem.DataContext is CrowdModel)
                {
                    treeViewItem = GetImmediateTreeViewItemParent(treeViewItem);
                    if (treeViewItem != null)
                    {
                        this.viewModel.SelectedCrowdParent = treeViewItem.DataContext as CrowdModel;
                    }
                    else
                    {
                        this.viewModel.SelectedCrowdParent = null;
                    }
                }
                else
                {
                    this.viewModel.SelectedCrowdParent = null;
                }
            }
        }
 /// <summary>
 /// This will recursively expand a matched item and its matched children
 /// </summary>
 /// <param name="tvi"></param>
 private void ExpandMatchedItems(TreeViewItem tvi)
 {
     if (tvi != null)
     {
         tvi.UpdateLayout();
         if (tvi.Items != null && tvi.Items.Count > 0)
         {
             for (int i = 0; i < tvi.Items.Count; i++)
             {
                 TreeViewItem item = tvi.ItemContainerGenerator.ContainerFromItem(tvi.Items[i]) as TreeViewItem;
                 if (item != null)
                 {
                     CrowdModel model = item.DataContext as CrowdModel;
                     if (model != null && model.IsMatched)
                     {
                         item.IsExpanded = true;
                         ExpandMatchedItems(item);
                     }
                     else
                     {
                         item.IsExpanded = false;
                     }
                 }
             }
         }
     }
 }
        private void viewModel_ExpansionUpdateNeeded(object sender, CustomEventArgs <ExpansionUpdateEvent> e)
        {
            CrowdModel           crowdModel  = sender as CrowdModel;
            DependencyObject     dObject     = null;
            ExpansionUpdateEvent updateEvent = e.Value;

            if (updateEvent == ExpansionUpdateEvent.Filter)
            {
                ExpandMatchedNode(sender);
            }
            else if (updateEvent == ExpansionUpdateEvent.DragDrop)
            {
                if (this.currentDropItemNode != null)
                {
                    this.currentDropItemNode.IsExpanded = true;
                }
            }
            else
            {
                if (this.selectedCrowdRoot != null && crowdModel != null)
                {
                    TreeViewItem item = treeViewCrowd.ItemContainerGenerator.ContainerFromItem(this.selectedCrowdRoot) as TreeViewItem;
                    dObject = FindTreeViewItemUnderTreeViewItemByModelName(item, crowdModel.Name);
                    if (dObject == null)
                    {
                        dObject = treeViewCrowd.GetItemFromSelectedObject(crowdModel);
                    }
                }
                else
                {
                    dObject = treeViewCrowd.GetItemFromSelectedObject(crowdModel);
                }
                TreeViewItem tvi = dObject as TreeViewItem;
                if (tvi != null)
                {
                    ICrowdMemberModel model = tvi.DataContext as ICrowdMemberModel;
                    if (tvi.Items != null && tvi.Items.Count > 0)
                    {
                        if (updateEvent != ExpansionUpdateEvent.Delete)
                        {
                            tvi.IsExpanded = true;
                        }
                        else
                        {
                            UpdateExpansions(tvi);
                        }
                    }
                    else
                    {
                        tvi.IsExpanded = false;
                    }
                }
            }
        }
コード例 #5
0
        public override ICrowdMember Clone()
        {
            CrowdModel clonedCrowdModel = new CrowdModel(this.Name);

            foreach (var member in this.crowdMemberCollection)
            {
                clonedCrowdModel.Add(member.Clone() as ICrowdMemberModel);
            }
            clonedCrowdModel.crowdMemberCollection = new HashedObservableCollection <ICrowdMemberModel, string>(clonedCrowdModel.CrowdMemberCollection, x => x.Name, x => x.Order, x => x.Name);
            clonedCrowdModel.CrowdMemberCollection = new ReadOnlyHashedObservableCollection <ICrowdMemberModel, string>(clonedCrowdModel.crowdMemberCollection);
            return(clonedCrowdModel);
        }
コード例 #6
0
        public CrowdFromModelsViewModel(IBusyService busyService, IUnityContainer container, IMessageBoxService messageBoxService, IDesktopKeyEventHandler keyEventHandler, EventAggregator eventAggregator)
            : base(busyService, container)
        {
            this.eventAggregator        = eventAggregator;
            this.messageBoxService      = messageBoxService;
            this.desktopKeyEventHandler = keyEventHandler;
            InitializeCommands();
            CreateModelsViewSource();
            charExpVM = this.Container.Resolve <CharacterExplorerViewModel>();
            this.eventAggregator.GetEvent <CreateCrowdFromModelsEvent>().Subscribe(this.LoadCrowd);
            tmpCrowd = new CrowdModel();

            InitializeDesktopKeyEventHandlers();
        }
        /// <summary>
        /// This will expand a matched item and its matched children
        /// </summary>
        /// <param name="sender"></param>
        private void ExpandMatchedNode(object sender)
        {
            CrowdModel crowdModel = sender as CrowdModel;

            if (crowdModel.IsMatched)
            {
                DependencyObject dObject = treeViewCrowd.GetItemFromSelectedObject(crowdModel);
                TreeViewItem     tvi     = dObject as TreeViewItem;
                if (tvi != null)
                {
                    tvi.IsExpanded = true;
                    ExpandMatchedItems(tvi);
                }
            }
        }
        private void treeViewCrowd_OnPreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            startPoint = e.GetPosition(null);

            TreeViewItem treeViewItem = VisualUpwardSearch(e.OriginalSource as DependencyObject);

            if (treeViewItem != null)
            {
                treeViewItem.Focus();
                TreeViewItem item = GetRootTreeViewItemParent(treeViewItem);
                if (item != null)
                {
                    this.selectedCrowdRoot = item.DataContext as CrowdModel;
                }
                else
                {
                    this.selectedCrowdRoot = null;
                }
                if (treeViewItem.DataContext is CrowdModel)
                {
                    treeViewItem = GetImmediateTreeViewItemParent(treeViewItem);
                    if (treeViewItem != null)
                    {
                        this.viewModel.SelectedCrowdParent = treeViewItem.DataContext as CrowdModel;
                    }
                    else
                    {
                        this.viewModel.SelectedCrowdParent = null;
                    }
                }
                else
                {
                    this.viewModel.SelectedCrowdParent = null;
                }
            }
        }
        private void viewModel_EditNeeded(object sender, CustomEventArgs <string> e)
        {
            ICrowdMemberModel modelToSelect = sender as ICrowdMemberModel;

            if (sender == null) // need to unselect
            {
                DependencyObject dObject = treeViewCrowd.GetItemFromSelectedObject(treeViewCrowd.SelectedItem);
                TreeViewItem     tvi     = dObject as TreeViewItem; // got the selected treeviewitem
                if (tvi != null)
                {
                    tvi.IsSelected         = false;
                    this.selectedCrowdRoot = null;
                }
            }
            else
            {
                bool    itemFound = false;
                TextBox txtBox    = null;
                treeViewCrowd.UpdateLayout();
                if (this.viewModel.SelectedCrowdModel == null)
                {
                    var allCharsCrowd = this.viewModel.CrowdCollection[Constants.ALL_CHARACTER_CROWD_NAME];
                    if (allCharsCrowd != null)
                    {
                        TreeViewItem firstItem = treeViewCrowd.ItemContainerGenerator.ContainerFromItem(allCharsCrowd) as TreeViewItem;
                        if (firstItem != null)
                        {
                            firstItem.IsSelected = true;
                            this.viewModel.SelectedCrowdModel = firstItem.DataContext as CrowdModel;
                        }
                    }
                }
                if (sender is CrowdModel)
                {
                    if (this.viewModel.SelectedCrowdModel == null || this.viewModel.SelectedCrowdModel.Name == Constants.ALL_CHARACTER_CROWD_NAME) // A new crowd has been added to the collection
                    {
                        for (int i = 0; i < treeViewCrowd.Items.Count; i++)
                        {
                            TreeViewItem item = treeViewCrowd.ItemContainerGenerator.ContainerFromItem(treeViewCrowd.Items[i]) as TreeViewItem;
                            if (item != null)
                            {
                                var model = item.DataContext as ICrowdMemberModel;
                                if (model.Name == modelToSelect.Name)
                                {
                                    item.IsSelected = true;
                                    itemFound       = true;
                                    txtBox          = FindTextBoxInTemplate(item);
                                    this.viewModel.SelectedCrowdModel = model as CrowdModel;
                                    break;
                                }
                            }
                        }
                    }
                }
                if (!itemFound)
                {
                    DependencyObject dObject = null;
                    if (e != null) // Something sent as event args
                    {
                        if (e.Value == "EditAfterDragDrop" && this.currentDropItemNodeParent != null)
                        {
                            dObject = currentDropItemNodeParent;
                        }
                    }
                    else
                    {
                        if (this.selectedCrowdRoot != null && this.viewModel.SelectedCrowdModel != null)
                        {
                            TreeViewItem item = treeViewCrowd.ItemContainerGenerator.ContainerFromItem(this.selectedCrowdRoot) as TreeViewItem;
                            dObject = FindTreeViewItemUnderTreeViewItemByModelName(item, this.viewModel.SelectedCrowdModel.Name);
                        }
                        else
                        {
                            dObject = treeViewCrowd.GetItemFromSelectedObject(this.viewModel.SelectedCrowdModel);
                        }
                    }
                    TreeViewItem tvi = dObject as TreeViewItem; // got the selected treeviewitem
                    if (tvi != null)
                    {
                        ICrowdMemberModel model = tvi.DataContext as ICrowdMemberModel;
                        if (tvi.Items != null)
                        {
                            tvi.IsExpanded = true;
                            tvi.UpdateLayout();
                            for (int i = 0; i < tvi.Items.Count; i++)
                            {
                                TreeViewItem item = tvi.ItemContainerGenerator.ContainerFromItem(tvi.Items[i]) as TreeViewItem;
                                if (item != null)
                                {
                                    model = item.DataContext as ICrowdMemberModel;
                                    if (model.Name == modelToSelect.Name)
                                    {
                                        item.IsSelected = true;
                                        itemFound       = true;
                                        item.UpdateLayout();
                                        txtBox = FindTextBoxInTemplate(item);
                                        if (model is CrowdModel)
                                        {
                                            this.viewModel.SelectedCrowdModel  = model as CrowdModel;
                                            this.viewModel.SelectedCrowdParent = tvi.DataContext as CrowdModel;
                                        }
                                        else
                                        {
                                            this.viewModel.SelectedCrowdMemberModel = model as CrowdMemberModel;
                                            this.viewModel.SelectedCrowdModel       = tvi.DataContext as CrowdModel;
                                        }
                                        if (this.selectedCrowdRoot == null)
                                        {
                                            this.selectedCrowdRoot = tvi.DataContext as CrowdModel;
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                if (txtBox != null)
                {
                    this.viewModel.EnterEditModeCommand.Execute(txtBox);
                }
            }
        }
コード例 #10
0
 private void LoadCrowd(CrowdModel crowd)
 {
     Filter           = null;
     this.EditedCrowd = crowd;
     this.Visibility  = Visibility.Visible;
 }