コード例 #1
0
 /// <summary>
 /// Unchecks the given item.
 /// </summary>
 /// <param name="pItem">The item to uncheck.</param>
 public void Uncheck(IHierarchicalItemViewModel pItem)
 {
     if (this.InnerListView != null)
     {
         this.InnerListView.CheckModel.Uncheck(pItem, false);
     }
 }
コード例 #2
0
ファイル: ExpandModel.cs プロジェクト: mastertnt/XRay
        /// <summary>
        /// This method expands a node.
        /// </summary>
        /// <param name="pItem">The target node.</param>
        /// <param name="pValue">True to set the node as expanded.</param>
        public void SetIsExpanded(IHierarchicalItemViewModel pItem, bool pValue)
        {
            if (this.BeginProcessingExpand())
            {
                if (pItem.HasChildren)
                {
                    if (pValue)
                    {
                        pItem.IsExpanded = pValue;
                        this.mParent.LoadsChildrenItems(pItem);
                    }
                    else
                    {
                        // When collapsed, if any child is selected, then all the item are unselected and the collapsed item is selected.
                        if (this.mParent.SelectionModel.SelectedItemsViewModel.Any(lSelectedItem => pItem.AllVisibleChildren.Contains(lSelectedItem)))
                        {
                            this.mParent.SelectionModel.Select(pItem);
                        }

                        this.mParent.DropChildrenItems(pItem, false);
                        pItem.IsExpanded = pValue;
                    }
                }

                this.EndProcessingExpand();
            }
        }
コード例 #3
0
 /// <summary>
 /// Expands the given item.
 /// </summary>
 /// <param name="pItem">The item to expand.</param>
 public void Expand(IHierarchicalItemViewModel pItem)
 {
     if (this.InnerListView != null)
     {
         this.InnerListView.ExpandModel.SetIsExpanded(pItem, true);
     }
 }
コード例 #4
0
        /// <summary>
        /// This method expands a node.
        /// </summary>
        /// <param name="pItem">The target node.</param>
        /// <param name="pValue">True to set the node as expanded.</param>
        public void SetIsExpanded(IHierarchicalItemViewModel pItem, bool pValue)
        {
            if (this.BeginProcessingExpand())
            {
                if (pItem.HasChildren)
                {
                    if (pValue)
                    {
                        pItem.IsExpanded = pValue;
                        this.mParent.LoadsChildrenItems(pItem);
                    }
                    else
                    {
                        // When collapsed, if any child is selected, then all the item are unselected and the collapsed item is selected.
                        if (this.mParent.SelectionModel.SelectedViewModels.Any(lSelectedItem => pItem.AllVisibleChildren.Contains(lSelectedItem)))
                        {
                            this.mParent.SelectionModel.Select(pItem);
                        }

                        this.mParent.DropChildrenItems(pItem, false);
                        pItem.IsExpanded = pValue;
                    }
                }

                this.EndProcessingExpand();
            }
        }
コード例 #5
0
 /// <summary>
 /// Collapses the given item.
 /// </summary>
 /// <param name="pItem">The item to expand.</param>
 public void Collapse(IHierarchicalItemViewModel pItem)
 {
     if (this.InnerListView != null)
     {
         this.InnerListView.ExpandModel.SetIsExpanded(pItem, false);
     }
 }
コード例 #6
0
 /// <summary>
 /// This method forces the item to be visible in the viewport.
 /// </summary>
 /// <param name="pItem">The item to make visible into the viewport.</param>
 public void ScrollToItem(IHierarchicalItemViewModel pItem)
 {
     if (this.InnerListView != null)
     {
         this.InnerListView.ScrollIntoView(pItem, true);
     }
 }
コード例 #7
0
        /// <summary>
        /// Adds the given to the selection.
        /// </summary>
        /// <param name="pItem">The item to add to the selection.</param>
        /// <param name="pUpdatePivot">Flag to know if the pivot must be updated.</param>
        /// <param name="pNotify">Flag defining if the notification must be done.</param>
        private void InternalAddToSelection(IHierarchicalItemViewModel pItem, bool pUpdatePivot, bool pNotify)
        {
            if (pItem.CanBeSelected && pItem.IsSelected == false)
            {
                // Updating view model.
                pItem.IsSelected = true;

                // Updating the selected items list.
                this.mSelectedViewModels.Add(pItem);

                // Setting the pivot.
                if (pUpdatePivot)
                {
                    this.Anchor = pItem;
                }

                // Updating native selection handling.
                if (this.SelectionMode == TreeSelectionMode.SingleSelection)
                {
                    this.mParent.SelectedItem = pItem;
                }
                else
                {
                    this.mParent.SelectedItems.Add(pItem);
                }

                // Notification.
                if (pNotify)
                {
                    this.NotifySelectionChanged(new IHierarchicalItemViewModel[] { }, new IHierarchicalItemViewModel[] { pItem });
                }
            }
        }
コード例 #8
0
 /// <summary>
 /// This method unselects an item.
 /// </summary>
 /// <param name="pItem">The item to unselect.</param>
 public void Unselect(IHierarchicalItemViewModel pItem)
 {
     if (this.InnerListView != null)
     {
         this.InnerListView.SelectionModel.Unselect(pItem, false);
     }
 }
コード例 #9
0
 /// <summary>
 /// Selects a range of items.
 /// </summary>
 /// <param name="pFrom">The range start view model.</param>
 /// <param name="pTo">The range stop view model.</param>
 public void SelectRange(IHierarchicalItemViewModel pFrom, IHierarchicalItemViewModel pTo)
 {
     if (this.SelectionMode != TreeSelectionMode.NoSelection)
     {
         this.InternalSelectRange(pFrom, pTo, true);
     }
 }
コード例 #10
0
        /// <summary>
        /// Uncheck the item.
        /// </summary>
        /// <param name="pItem">The item to uncheck.</param>
        /// <param name="pUncheckChildren">Flag defining if the children have to be unchecked as well.</param>
        public void Uncheck(IHierarchicalItemViewModel pItem, bool pUncheckChildren)
        {
            if ((pItem.IsChecked && pItem.IsCheckable && pItem.IsCheckingEnabled) ||
                (pUncheckChildren)
                )
            {
                // Update.
                IHierarchicalItemViewModel[] lUncheckedItems;
                if (pUncheckChildren)
                {
                    lUncheckedItems = pItem.UncheckAll();
                }
                else
                {
                    pItem.IsChecked = false;
                    lUncheckedItems = new IHierarchicalItemViewModel[] { pItem };
                }

                if (lUncheckedItems.Any())
                {
                    foreach (IHierarchicalItemViewModel lItem in lUncheckedItems)
                    {
                        this.mCheckedItemsViewModel.Remove(lItem);
                    }

                    // Notification.
                    this.NotifyItemsToggled(lUncheckedItems);
                }
            }
        }
コード例 #11
0
 /// <summary>
 /// Adds the given to the selection.
 /// </summary>
 /// <param name="pItem">The item to add to the selection.</param>
 public void AddToSelection(IHierarchicalItemViewModel pItem)
 {
     if (this.SelectionMode != TreeSelectionMode.NoSelection)
     {
         this.InternalAddToSelection(pItem, true, true);
     }
 }
コード例 #12
0
 /// <summary>
 /// Notifies a check modification.
 /// </summary>
 /// <param name="pToggledItem">The toogled item.</param>
 private void NotifyItemToggled(IHierarchicalItemViewModel pToggledItem)
 {
     if (this.ItemsViewModelToggled != null)
     {
         this.ItemsViewModelToggled(this, new IHierarchicalItemViewModel[] { pToggledItem });
     }
 }
コード例 #13
0
        /// <summary>
        /// Check the item.
        /// </summary>
        /// <param name="pItem">The item to check.</param>
        /// <param name="pCheckChildren">Flag defining if the children have to be checked as well.</param>
        public void Check(IHierarchicalItemViewModel pItem, bool pCheckChildren)
        {
            if ((pItem.IsChecked == false && pItem.IsCheckable && pItem.IsCheckingEnabled) ||
                (pCheckChildren)
                )
            {
                // Update.
                IHierarchicalItemViewModel[] lCheckedItems;
                if (pCheckChildren)
                {
                    lCheckedItems = pItem.CheckAll();
                }
                else
                {
                    pItem.IsChecked = true;
                    lCheckedItems   = new IHierarchicalItemViewModel[] { pItem };
                }

                if (lCheckedItems.Any())
                {
                    this.mCheckedItemsViewModel.AddRange(lCheckedItems);

                    // Notification.
                    this.NotifyItemsToggled(lCheckedItems);
                }
            }
        }
コード例 #14
0
        /// <summary>
        /// Selects a range of items.
        /// </summary>
        /// <param name="pFrom">The range start view model.</param>
        /// <param name="pTo">The range stop view model.</param>
        /// <param name="pNotify">Flag defining if the notification must be done.</param>
        private void InternalSelectRange(IHierarchicalItemViewModel pFrom, IHierarchicalItemViewModel pTo, bool pNotify)
        {
            if (this.SelectionMode != TreeSelectionMode.SingleSelection)
            {
                // Getting the indexes of the selection range.
                int lFromIndex = this.mParent.Rows.IndexOf(pFrom);
                int lToIndex   = this.mParent.Rows.IndexOf(pTo);
                if (lFromIndex > lToIndex)
                {
                    // Swap values.
                    int lTemp = lFromIndex;
                    lFromIndex = lToIndex;
                    lToIndex   = lTemp;
                }

                // Building the list of items to select.
                List <IHierarchicalItemViewModel> lItemsToSelect = new List <IHierarchicalItemViewModel>();
                for (int lIndex = lFromIndex; lIndex <= lToIndex; lIndex++)
                {
                    IHierarchicalItemViewModel lItem = this.mParent.Rows.ElementAtOrDefault(lIndex);
                    if (lItem != null)
                    {
                        lItemsToSelect.Add(lItem);
                    }
                }

                if (lItemsToSelect.Any())
                {
                    // Update.
                    this.InternalSelect(lItemsToSelect, false, pNotify);
                }
            }
        }
コード例 #15
0
        /// <summary>
        /// Removes the children from the rows.
        /// </summary>
        /// <param name="pViewModel">The view model containing the rows.</param>
        /// <param name="pIncludeParent">Flag indicating if the parent must be droped has well.</param>
        internal void DropChildrenItems(IHierarchicalItemViewModel pViewModel, bool pIncludeParent)
        {
            if (pViewModel.ChildrenAreLoaded)
            {
                int lStartIndex = this.Rows.IndexOf(pViewModel);
                int lCount      = pViewModel.AllVisibleChildren.Count();

                if (pIncludeParent == false)
                {
                    lStartIndex++;
                }
                else
                {
                    lCount++;
                }

                // The item must be in the children list.
                if (lStartIndex != -1)
                {
                    this.Rows.RemoveRange(lStartIndex, lCount);
                }

                pViewModel.ChildrenAreLoaded = false;
                pViewModel.AllVisibleChildren.Where(lItem => lItem.IsExpanded).ForEach(lItem => lItem.ChildrenAreLoaded = false);
            }
        }
コード例 #16
0
        /// <summary>
        /// Delegate called when items are removed from the view model.
        /// </summary>
        /// <param name="pSender">The modified root view model.</param>
        /// <param name="pItem">The removed item.</param>
        /// <param name="pOldIndex">The old index of the item.</param>
        /// <param name="pNewIndex">THe new index of the item.</param>
        private void OnItemViewModelMoved(object pSender, IHierarchicalItemViewModel pItem, int pOldIndex, int pNewIndex)
        {
            if (pItem != null)
            {
                // Computing the row indexes.
                int lOldRowIndex = pOldIndex;
                int lNewRowIndex = pNewIndex;
                if (pItem.Parent != null && pItem.Parent is IRootHierarchicalItemViewModel == false)
                {
                    int lParentRowIndex = this.Rows.IndexOf(pItem.Parent);
                    lOldRowIndex = lParentRowIndex + pOldIndex + 1;
                    lNewRowIndex = lParentRowIndex + pNewIndex + 1;
                }

                // Removing the items from the tree view if they are displayed.
                if (pItem.IsExpanded)
                {
                    this.DropChildrenItems(pItem, true);
                }
                else
                {
                    this.Rows.Remove(pItem);
                }

                // Adding the item in the rows.
                if (lNewRowIndex >= this.Rows.Count)
                {
                    this.Rows.Add(pItem);
                }
                else
                {
                    this.Rows.Insert(lNewRowIndex, pItem);
                }
            }
        }
コード例 #17
0
        /// <summary>
        /// Converts the tree configuration to the item group state.
        /// </summary>
        /// <param name="pValues">The values defining the tree configuration.</param>
        /// <param name="pTargetType">The target type.</param>
        /// <param name="pParameter">The additional parameters.</param>
        /// <param name="pCulture">The culture to use during the conversion.</param>
        /// <returns>The returned item group state.</returns>
        public object Convert(object[] pValues, Type pTargetType, object pParameter, CultureInfo pCulture)
        {
            Debug.Assert(pValues.Count() == 2);

            try
            {
#pragma warning disable 1587
                /// To be a group, an item must have the root as its parent view model, and the FirstLevelItemAsGroup property to true.
                /// First parameter is the view model, second is the FirstLevelItemAsGroup property.
#pragma warning restore 1587
                IHierarchicalItemViewModel lViewModel = pValues[0] as IHierarchicalItemViewModel;
                bool lFirstLevelItemAsGroup           = System.Convert.ToBoolean(pValues[1]);
                if
                ((lViewModel != null) &&
                 (lViewModel.Parent is IRootHierarchicalItemViewModel) &&
                 (lFirstLevelItemAsGroup)
                )
                {
                    return(true);
                }

                return(false);
            }
            catch
            {
                return(Binding.DoNothing);
            }
        }
コード例 #18
0
ファイル: CheckModel.cs プロジェクト: mastertnt/XRay
        /// <summary>
        /// Check the item.
        /// </summary>
        /// <param name="pItem">The item to check.</param>
        /// <param name="pCheckChildren">Flag defining if the children have to be checked as well.</param>
        public void Check(IHierarchicalItemViewModel pItem, bool pCheckChildren)
        {
            if  (   (pItem.IsChecked == false && pItem.IsCheckable && pItem.IsCheckingEnabled)
                ||  (pCheckChildren)
                )
            {
                // Update.
                IHierarchicalItemViewModel[] lCheckedItems;
                if (pCheckChildren)
                {
                    lCheckedItems = pItem.CheckAll();
                }
                else
                {
                    pItem.IsChecked = true;
                    lCheckedItems = new IHierarchicalItemViewModel[] { pItem };
                }

                if (lCheckedItems.Any())
                {
                    this.mCheckedItemsViewModel.AddRange(lCheckedItems);

                    // Notification.
                    this.NotifyItemsToggled(lCheckedItems);
                }
            }
        }
コード例 #19
0
 /// <summary>
 /// Method to call when children are removed from this view model.
 /// </summary>
 /// <param name="pChild">The child added to the children list.</param>
 protected sealed override void NotifyChildRemoved(IHierarchicalItemViewModel pChild)
 {
     if (this.ItemViewModelsRemoved != null)
     {
         this.ItemViewModelsRemoved(this, new IHierarchicalItemViewModel[] { pChild });
     }
 }
コード例 #20
0
 /// <summary>
 /// Method to call when children are removed from this view model.
 /// </summary>
 /// <param name="pChild">The child added to the children list.</param>
 /// <param name="pOldIndex">The old index of the item.</param>
 /// <param name="pNewIndex">THe new index of the item.</param>
 protected sealed override void NotifyChildMoved(IHierarchicalItemViewModel pChild, int pOldIndex, int pNewIndex)
 {
     if (this.ItemViewModelMoved != null)
     {
         this.ItemViewModelMoved(this, pChild, pOldIndex, pNewIndex);
     }
 }
コード例 #21
0
        /// <summary>
        /// Unselect the given item.
        /// </summary>
        /// <param name="pItem">The item to unselect.</param>
        /// <param name="pNotify">Flag defining if the notification must be done.</param>
        private void InternalUnselect(IHierarchicalItemViewModel pItem, bool pNotify)
        {
            if (pItem.IsSelected)
            {
                // Updating view model.
                pItem.IsSelected = false;

                // Updating the selected items list.
                this.mSelectedViewModels.Remove(pItem);

                // Updating the pivot.
                if (this.Anchor == pItem)
                {
                    this.Anchor = null;
                }

                // Updating native selection handling.
                if (this.SelectionMode == TreeSelectionMode.SingleSelection)
                {
                    this.mParent.SelectedItem = null;
                }
                else
                {
                    this.mParent.SelectedItems.Remove(pItem);
                }

                // Notification.
                if (pNotify)
                {
                    this.NotifySelectionChanged(new IHierarchicalItemViewModel[] { pItem }, new IHierarchicalItemViewModel[] { });
                }
            }
        }
コード例 #22
0
 /// <summary>
 /// Delegate called when the mouse clicked on this item.
 /// </summary>
 /// <param name="pItem">The clicked item.</param>
 /// <param name="pEventArgs">The event arguments.</param>
 internal void OnItemMouseClicked(IHierarchicalItemViewModel pItem, System.Windows.Input.MouseButtonEventArgs pEventArgs)
 {
     // Notification.
     if (this.ItemViewModelClicked != null)
     {
         this.ItemViewModelClicked(this, new IHierarchicalItemViewModel[] { pItem });
     }
 }
コード例 #23
0
ファイル: SelectionBehavior.cs プロジェクト: mastertnt/XRay
 /// <summary>
 /// Delegate called when the mouse left button is down on an item.
 /// </summary>
 /// <param name="pItem">The clicked item.</param>
 /// <param name="pEventArgs">The event arguments.</param>
 public void OnItemMouseLeftButtonDown(IHierarchicalItemViewModel pItem, System.Windows.Input.MouseButtonEventArgs pEventArgs)
 {
     if (System.Windows.Input.Keyboard.IsKeyDown(Key.LeftCtrl) || System.Windows.Input.Keyboard.IsKeyDown(Key.RightCtrl))
     {
         if (this.mParent.SelectionModel.SelectionMode == TreeSelectionMode.MultiSelection)
         {
             if (pItem.CanBeSelected)
             {
                 if (pItem.IsSelected == false)
                 {
                     this.mParent.SelectionModel.AddToSelection(pItem);
                 }
                 else
                 {
                     this.mParent.SelectionModel.Unselect(pItem, false);
                 }
             }
         }
     }
     else if (System.Windows.Input.Keyboard.IsKeyDown(Key.LeftShift) || System.Windows.Input.Keyboard.IsKeyDown(Key.RightShift))
     {
         if (this.mParent.SelectionModel.SelectionMode == TreeSelectionMode.MultiSelection)
         {
             if (pItem.CanBeSelected)
             {
                 if (this.mParent.SelectionModel.Anchor == null)
                 {
                     this.mParent.SelectionModel.Select(pItem);
                 }
                 else
                 {
                     this.mParent.SelectionModel.SelectRange(this.mParent.SelectionModel.Anchor, pItem);
                 }
             }
         }
     }
     else
     {
         // Default behavior.
         if (this.mParent.SelectionModel.SelectionMode == TreeSelectionMode.SingleSelection)
         {
             if (pItem.CanBeSelected)
             {
                 this.mParent.SelectionModel.Select(pItem);
             }
         }
         else if (this.mParent.SelectionModel.SelectionMode == TreeSelectionMode.MultiSelection)
         {
             if (pItem.CanBeSelected)
             {
                 this.mParent.SelectionModel.Select(pItem);
             }
         }
     }
 }
コード例 #24
0
ファイル: SelectionBehavior.cs プロジェクト: mastertnt/XRay
 /// <summary>
 /// Delegate called when the mouse left button is up on an item.
 /// </summary>
 /// <param name="pItem">The clicked item.</param>
 /// <param name="pEventArgs">The event arguments.</param>
 public void OnItemMouseLeftButtonUp(IHierarchicalItemViewModel pItem, System.Windows.Input.MouseButtonEventArgs pEventArgs)
 {
     if (System.Windows.Input.Keyboard.Modifiers == System.Windows.Input.ModifierKeys.None &&
         pItem.CanBeSelected)
     {
         if (pItem.IsSelected && this.mParent.SelectionModel.SelectedViewModels.Count() > 1)
         {
             this.mParent.SelectionModel.Select(pItem);
         }
     }
 }
コード例 #25
0
 /// <summary>
 /// Unselect the given item.
 /// </summary>
 /// <param name="pItem">The item to unselect.</param>
 /// <param name="pUnselectChildren">Unselect the children as well.</param>
 public void Unselect(IHierarchicalItemViewModel pItem, bool pUnselectChildren)
 {
     if (pUnselectChildren)
     {
         this.InternalUnselectAndChildren(pItem, true);
     }
     else
     {
         this.InternalUnselect(pItem, true);
     }
 }
コード例 #26
0
        /// <summary>
        /// Delegate called when the mouse double clicked on this item.
        /// </summary>
        /// <param name="pItem">The double clicked item.</param>
        /// <param name="pEventArgs">The event arguments.</param>
        internal void OnItemMouseDoubleClicked(IHierarchicalItemViewModel pItem, System.Windows.Input.MouseButtonEventArgs pEventArgs)
        {
            // Handling the expand.
            this.mExpandBehavior.OnItemMouseDoubleClicked(pItem, pEventArgs);

            // Notification.
            if (this.ItemViewModelDoubleClicked != null)
            {
                this.ItemViewModelDoubleClicked(this, new IHierarchicalItemViewModel[] { pItem });
            }
        }
コード例 #27
0
        /// <summary>
        /// Loads the children of this item in the control.
        /// </summary>
        /// <param name="pViewModel">The view model containing the children.</param>
        internal void LoadsChildrenItems(IHierarchicalItemViewModel pViewModel)
        {
            if (pViewModel.ChildrenAreLoaded == false)
            {
                int lStartIndex = this.Rows.IndexOf(pViewModel);
                this.Rows.InsertRange(lStartIndex + 1, pViewModel.AllVisibleChildren.ToArray());

                pViewModel.ChildrenAreLoaded = true;
                pViewModel.AllVisibleChildren.Where(lItem => lItem.IsExpanded).ForEach(lItem => lItem.ChildrenAreLoaded = true);
            }
        }
コード例 #28
0
 /// <summary>
 /// Toggles the expand state of the given item.
 /// </summary>
 /// <param name="pItem">The item to toggle expand.</param>
 public void ToggleExpand(IHierarchicalItemViewModel pItem)
 {
     if (pItem.HasChildren)
     {
         if (pItem.IsExpanded == false)
         {
             this.SetIsExpanded(pItem, true);
         }
         else
         {
             this.SetIsExpanded(pItem, false);
         }
     }
 }
コード例 #29
0
ファイル: SelectionBehavior.cs プロジェクト: mastertnt/XRay
 /// <summary>
 /// Delegate called when the mouse right button is down on an item.
 /// </summary>
 /// <param name="pItem">The clicked item.</param>
 /// <param name="pEventArgs">The event arguments.</param>
 public void OnItemMouseRightButtonDown(IHierarchicalItemViewModel pItem, System.Windows.Input.MouseButtonEventArgs pEventArgs)
 {
     if (pItem.CanBeSelected)
     {
         if (pItem.IsSelected == false)
         {
             this.mParent.SelectionModel.Select(pItem);
         }
     }
     else
     {
         this.mParent.SelectionModel.UnselectAll();
     }
 }
コード例 #30
0
ファイル: ExpandModel.cs プロジェクト: mastertnt/XRay
 /// <summary>
 /// Toggles the expand state of the given item.
 /// </summary>
 /// <param name="pItem">The item to toggle expand.</param>
 public void ToggleExpand(IHierarchicalItemViewModel pItem)
 {
     if (pItem.HasChildren)
     {
         if (pItem.IsExpanded == false)
         {
             this.SetIsExpanded(pItem, true);
         }
         else
         {
             this.SetIsExpanded(pItem, false);
         }
     }
 }
コード例 #31
0
        /// <summary>
        /// Select the given item.
        /// </summary>
        /// <param name="pItem">The selected item.</param>
        /// <param name="pNotify">Flag defining if the notification must be done.</param>
        private void InternalSelect(IHierarchicalItemViewModel pItem, bool pNotify)
        {
            if (pItem.CanBeSelected && (pItem.IsSelected == false || this.mSelectedViewModels.Count > 1))
            {
                // Update.
                IHierarchicalItemViewModel[] lOldSelection = this.SelectedViewModels.ToArray();
                this.InternalUnselectAll(true, false);
                this.InternalAddToSelection(pItem, true, false);

                // Notification.
                if (pNotify)
                {
                    this.NotifySelectionChanged(lOldSelection, new IHierarchicalItemViewModel[] { pItem });
                }
            }
        }
コード例 #32
0
        /// <summary>
        /// Unselect the given item and all its children.
        /// </summary>
        /// <param name="pItem">The item to unselect.</param>
        /// <param name="pNotify">Flag defining if the notification must be done.</param>
        private void InternalUnselectAndChildren(IHierarchicalItemViewModel pItem, bool pNotify)
        {
            if (pItem.IsSelected)
            {
                IHierarchicalItemViewModel[]      lOldSelection = this.SelectedViewModels.ToArray();
                List <IHierarchicalItemViewModel> lRemovedItems = new List <IHierarchicalItemViewModel>();
                lRemovedItems.AddRange(pItem.UnSelectAll());

                if (lRemovedItems.Any())
                {
                    // Updating the selected items list.
                    foreach (IHierarchicalItemViewModel lItem in lRemovedItems)
                    {
                        this.mSelectedViewModels.Remove(lItem);
                    }

                    // Updating the pivot.
                    if (lRemovedItems.Contains(this.Anchor))
                    {
                        this.Anchor = null;
                    }

                    // Updating native selection handling.
                    if (this.SelectionMode == TreeSelectionMode.SingleSelection)
                    {
                        this.mParent.SelectedItem = null;
                    }
                    else
                    {
                        foreach (IHierarchicalItemViewModel lItem in lRemovedItems)
                        {
                            this.mParent.SelectedItems.Remove(lItem);
                        }
                    }

                    // Notification.
                    if (pNotify)
                    {
                        this.NotifySelectionChanged(lRemovedItems.ToArray(), new IHierarchicalItemViewModel[] { });
                    }
                }
            }
        }
コード例 #33
0
        /// <summary>
        /// Convert from Level to Tickness.
        /// </summary>
        /// <param name="pValue">The value to convert.</param>
        /// <param name="pTargetType">The target type.</param>
        /// <param name="pExtraParameter">The extra parameter to use (not used by the lConverter).</param>
        /// <param name="pCulture">The culture to use (not used by the lConverter).</param>
        /// <returns>The value converted.</returns>
        public object Convert(object pValue, Type pTargetType, object pExtraParameter, CultureInfo pCulture)
        {
            int lLevel = 0;
            IHierarchicalItemViewModel lItemToIndent = pValue as IHierarchicalItemViewModel;

            if
            (lItemToIndent != null)
            {
                IHierarchicalItemViewModel lCurrentItem = lItemToIndent;
                while
                (lCurrentItem.Parent != null)
                {
                    lCurrentItem = lCurrentItem.Parent;
                    lLevel++;
                }
            }

            return(new Thickness(lLevel * LevelToIndentConverter.IndentSize, 0, 0, 0));
        }
コード例 #34
0
ファイル: SelectionBehavior.cs プロジェクト: mastertnt/XRay
 /// <summary>
 /// Delegate called when the mouse left button is down on an item.
 /// </summary>
 /// <param name="pItem">The clicked item.</param>
 /// <param name="pEventArgs">The event arguments.</param>
 public void OnItemMouseLeftButtonDown(IHierarchicalItemViewModel pItem, System.Windows.Input.MouseButtonEventArgs pEventArgs)
 {
     if (System.Windows.Input.Keyboard.Modifiers == System.Windows.Input.ModifierKeys.None)
     {
         if (this.mParent.SelectionModel.SelectionOption == TreeSelectionOptions.SingleSelection)
         {
             this.mParent.SelectionModel.Select(pItem);
         }
         else if (this.mParent.SelectionModel.SelectionOption == TreeSelectionOptions.MultiSelection)
         {
             this.mParent.SelectionModel.Select(pItem);
         }
     }
     else if (System.Windows.Input.Keyboard.Modifiers == System.Windows.Input.ModifierKeys.Control)
     {
         if (this.mParent.SelectionModel.SelectionOption == TreeSelectionOptions.MultiSelection)
         {
             this.mParent.SelectionModel.AddToSelection(pItem);
         }
     }
 }
コード例 #35
0
ファイル: ExpandBehavior.cs プロジェクト: mastertnt/XRay
 /// <summary>
 /// Delegate called when the mouse double clicked on this item.
 /// </summary>
 /// <param name="pItem">The double clicked item.</param>
 /// <param name="pEventArgs">The event arguments.</param>
 public void OnItemMouseDoubleClicked(IHierarchicalItemViewModel pItem, System.Windows.Input.MouseButtonEventArgs pEventArgs)
 {
     this.mParent.ExpandModel.ToggleExpand(pItem);
 }
コード例 #36
0
ファイル: SelectionModel.cs プロジェクト: mastertnt/XRay
 /// <summary>
 /// Notifies a selection modification.
 /// </summary>
 /// <param name="pRemovedItems">The items removed from the selection.</param>
 /// <param name="pAddedItems">The items added to the selection.</param>
 private void NotifySelectionChanged(IHierarchicalItemViewModel[] pRemovedItems, IHierarchicalItemViewModel[] pAddedItems)
 {
     if (this.SelectionChanged != null)
     {
         SelectionChangedEventArgs lArgs = new SelectionChangedEventArgs(pRemovedItems, pAddedItems);
         this.SelectionChanged(this, lArgs);
     }
 }
コード例 #37
0
ファイル: SelectionModel.cs プロジェクト: mastertnt/XRay
        /// <summary>
        /// Unselect the given item and all its children.
        /// </summary>
        /// <param name="pItem">The item to unselect.</param>
        /// <param name="pNotify">Flag defining if the notification must be done.</param>
        private void InternalUnselectAndChildren(IHierarchicalItemViewModel pItem, bool pNotify)
        {
            if (pItem.IsSelected)
            {
                IHierarchicalItemViewModel[] lOldSelection = this.SelectedItemsViewModel.ToArray();
                List<IHierarchicalItemViewModel> lRemovedItems = new List<IHierarchicalItemViewModel>();
                lRemovedItems.AddRange(pItem.UnSelectAll());

                if (lRemovedItems.Any())
                {
                    // Updating the selected items list.
                    foreach (IHierarchicalItemViewModel lItem in lRemovedItems)
                    {
                        this.mSelectedItemsViewModel.Remove(lItem);
                    }

                    // Updating native selection handling.
                    if (this.mParent.SelectionMode == System.Windows.Controls.SelectionMode.Single)
                    {
                        this.mParent.SelectedItem = null;
                    }
                    else
                    {
                        foreach (IHierarchicalItemViewModel lItem in lRemovedItems)
                        {
                            this.mParent.SelectedItems.Remove(lItem);
                        }
                    }

                    // Notification.
                    if (pNotify)
                    {
                        this.NotifySelectionChanged(lRemovedItems.ToArray(), new IHierarchicalItemViewModel[] { });
                    }
                }
            }
        }
コード例 #38
0
ファイル: TreeListView.cs プロジェクト: mastertnt/XRay
 /// <summary>
 /// This method unselects an item.
 /// </summary>
 /// <param name="pItem">The item to unselect.</param>
 public void Unselect(IHierarchicalItemViewModel pItem)
 {
     if (this.InnerListView != null)
     {
         this.InnerListView.SelectionModel.Unselect(pItem, false);
     }
 }
コード例 #39
0
ファイル: ExtendedListView.cs プロジェクト: mastertnt/XRay
 /// <summary>
 /// Delegate called when the mouse right button is down on an item.
 /// </summary>
 /// <param name="pItem">The clicked item.</param>
 /// <param name="pEventArgs">The event arguments.</param>
 internal void OnItemMouseRightButtonDown(IHierarchicalItemViewModel pItem, System.Windows.Input.MouseButtonEventArgs pEventArgs)
 {
     // Handling the selection.
     this.mSelectionBehavior.OnItemMouseRightButtonDown(pItem, pEventArgs);
 }
コード例 #40
0
ファイル: TreeListView.cs プロジェクト: mastertnt/XRay
 /// <summary>
 /// This method forces the item to be visible in the viewport.
 /// </summary>
 /// <param name="pItem">The item to make visible into the viewport.</param>
 public void ScrollToItem(IHierarchicalItemViewModel pItem)
 {
     if (this.InnerListView != null)
     {
         this.InnerListView.ScrollIntoView(pItem, true);
     }
 }
コード例 #41
0
ファイル: SelectionModel.cs プロジェクト: mastertnt/XRay
 /// <summary>
 /// Select the given item.
 /// </summary>
 /// <param name="pItem">The selected item.</param>
 public void Select(IHierarchicalItemViewModel pItem)
 {
     if (this.SelectionOption != TreeSelectionOptions.NoSelection)
     {
         this.InternalSelect(pItem, true);
     }
 }
コード例 #42
0
ファイル: TreeListView.cs プロジェクト: mastertnt/XRay
 /// <summary>
 /// Unchecks the given item.
 /// </summary>
 /// <param name="pItem">The item to uncheck.</param>
 public void Uncheck(IHierarchicalItemViewModel pItem)
 {
     if (this.InnerListView != null)
     {
         this.InnerListView.CheckModel.Uncheck(pItem, false);
     }
 }
コード例 #43
0
ファイル: CheckModel.cs プロジェクト: mastertnt/XRay
 /// <summary>
 /// Notifies a check modification.
 /// </summary>
 /// <param name="pToggledItem">The toogled item.</param>
 private void NotifyItemToggled(IHierarchicalItemViewModel pToggledItem)
 {
     if (this.ItemsViewModelToggled != null)
     {
         this.ItemsViewModelToggled(this, new IHierarchicalItemViewModel[] { pToggledItem });
     }
 }
コード例 #44
0
ファイル: CheckModel.cs プロジェクト: mastertnt/XRay
 /// <summary>
 /// Notifies a check modification.
 /// </summary>
 /// <param name="pToggledItem">The toogled item.</param>
 private void NotifyItemsToggled(IHierarchicalItemViewModel[] pToggledItem)
 {
     if (this.ItemsViewModelToggled != null)
     {
         this.ItemsViewModelToggled(this, pToggledItem);
     }
 }
コード例 #45
0
ファイル: CheckModel.cs プロジェクト: mastertnt/XRay
        /// <summary>
        /// Uncheck the item.
        /// </summary>
        /// <param name="pItem">The item to uncheck.</param>
        /// <param name="pUncheckChildren">Flag defining if the children have to be unchecked as well.</param>
        public void Uncheck(IHierarchicalItemViewModel pItem, bool pUncheckChildren)
        {
            if  (   (pItem.IsChecked && pItem.IsCheckable && pItem.IsCheckingEnabled)
                ||  (pUncheckChildren)
                )
            {
                // Update.
                IHierarchicalItemViewModel[] lUncheckedItems;
                if (pUncheckChildren)
                {
                    lUncheckedItems = pItem.UncheckAll();
                }
                else
                {
                    pItem.IsChecked = false;
                    lUncheckedItems = new IHierarchicalItemViewModel[] { pItem };
                }

                if (lUncheckedItems.Any())
                {
                    foreach (IHierarchicalItemViewModel lItem in lUncheckedItems)
                    {
                        this.mCheckedItemsViewModel.Remove(lItem);
                    }

                    // Notification.
                    this.NotifyItemsToggled(lUncheckedItems);
                }
            }
        }
コード例 #46
0
ファイル: ExpandBehavior.cs プロジェクト: mastertnt/XRay
 /// <summary>
 /// Delegate called when the item expander gets unchecked.
 /// </summary>
 /// <param name="pItem">The unchecked item.</param>
 public void OnItemExpanderUnchecked(IHierarchicalItemViewModel pItem)
 {
     this.mParent.ExpandModel.SetIsExpanded(pItem, false);
 }
コード例 #47
0
ファイル: ExpandBehavior.cs プロジェクト: mastertnt/XRay
        /// <summary>
        /// Delegate called when a key is pressed when the item get the focus.
        /// </summary>
        /// <param name="pItem">The key up item.</param>
        /// <param name="pEventArgs">The event arguments.</param>
        public void OnItemKeyUp(IHierarchicalItemViewModel pItem, System.Windows.Input.KeyEventArgs pEventArgs)
        {
            if (pEventArgs.KeyboardDevice.Modifiers == System.Windows.Input.ModifierKeys.None)
            {
                // Handling the selection when right arrow key is pressed.
                if (pEventArgs.Key == System.Windows.Input.Key.Right)
                {
                    if (pItem != null)
                    {
                        if (pItem.HasChildren)
                        {
                            if (pItem.IsExpanded)
                            {
                                // If not expanded, just expand it.
                                this.mParent.ExpandModel.SetIsExpanded(pItem, true);
                            }
                            else
                            {
                                // Otherwise, selecting the first child if any.
                                IHierarchicalItemViewModel lFirstChild = pItem.Children.FirstOrDefault();
                                if (lFirstChild != null)
                                {
                                    this.mParent.ScrollIntoView(lFirstChild, true);
                                }
                            }
                        }
                    }
                }

                // Handling the selection when left arrow key is pressed.
                if (pEventArgs.Key == System.Windows.Input.Key.Left)
                {
                    if (this.mParent.SelectionModel.SelectedItemsViewModel.Count() > 1)
                    {
                        // Selecting the first element with no selected parent.
                        IHierarchicalItemViewModel lFoundItem = this.mParent.SelectionModel.SelectedItemsViewModel.FirstOrDefault(lItem => (lItem.Parent == null) || (lItem.Parent.IsSelected == false));
                        if (lFoundItem != null)
                        {
                            this.mParent.ScrollIntoView(lFoundItem, true);
                        }
                    }
                    else
                    {
                        if (pItem != null)
                        {
                            // This item is the only one selected.
                            if (pItem.IsExpanded)
                            {
                                this.mParent.ExpandModel.SetIsExpanded(pItem, false);
                            }
                            else if
                                (   (pItem.Parent != null)
                                &&  (pItem.Parent is IRootHierarchicalItemViewModel) == false
                                )
                            {
                                this.mParent.ScrollIntoView(pItem.Parent, true);
                            }
                        }
                    }
                }
            }
        }
コード例 #48
0
ファイル: SelectionModel.cs プロジェクト: mastertnt/XRay
 /// <summary>
 /// Unselect the given item.
 /// </summary>
 /// <param name="pItem">The item to unselect.</param>
 /// <param name="pUnselectChildren">Unselect the children as well.</param>
 public void Unselect(IHierarchicalItemViewModel pItem, bool pUnselectChildren)
 {
     if (pUnselectChildren)
     {
         this.InternalUnselectAndChildren(pItem, true);
     }
     else
     {
         this.InternalUnselect(pItem, true);
     }
 }
コード例 #49
0
ファイル: TreeListView.cs プロジェクト: mastertnt/XRay
 /// <summary>
 /// Expands the given item.
 /// </summary>
 /// <param name="pItem">The item to expand.</param>
 public void Expand(IHierarchicalItemViewModel pItem)
 {
     if (this.InnerListView != null)
     {
         this.InnerListView.ExpandModel.SetIsExpanded(pItem, true);
     }
 }
コード例 #50
0
ファイル: SelectionModel.cs プロジェクト: mastertnt/XRay
        /// <summary>
        /// Select the given item.
        /// </summary>
        /// <param name="pItem">The selected item.</param>
        /// <param name="pNotify">Flag defining if the notification must be done.</param>
        private void InternalSelect(IHierarchicalItemViewModel pItem, bool pNotify)
        {
            if (pItem.CanBeSelected && (pItem.IsSelected == false || this.mSelectedItemsViewModel.Count > 1))
            {
                // Update.
                IHierarchicalItemViewModel[] lOldSelection = this.SelectedItemsViewModel.ToArray();
                this.InternalUnselectAll(false);
                this.InternalAddToSelection(pItem, false);

                // Notification.
                if (pNotify)
                {
                    this.NotifySelectionChanged(lOldSelection, new IHierarchicalItemViewModel[] { pItem });
                }
            }
        }
コード例 #51
0
ファイル: TreeListView.cs プロジェクト: mastertnt/XRay
 /// <summary>
 /// Collapses the given item.
 /// </summary>
 /// <param name="pItem">The item to expand.</param>
 public void Collapse(IHierarchicalItemViewModel pItem)
 {
     if (this.InnerListView != null)
     {
         this.InnerListView.ExpandModel.SetIsExpanded(pItem, false);
     }
 }
コード例 #52
0
ファイル: SelectionModel.cs プロジェクト: mastertnt/XRay
        /// <summary>
        /// Unselect the given item.
        /// </summary>
        /// <param name="pItem">The item to unselect.</param>
        /// <param name="pNotify">Flag defining if the notification must be done.</param>
        private void InternalUnselect(IHierarchicalItemViewModel pItem, bool pNotify)
        {
            if (pItem.IsSelected)
            {
                // Updating view model.
                pItem.IsSelected = false;

                // Updating the selected items list.
                this.mSelectedItemsViewModel.Remove(pItem);

                // Updating native selection handling.
                if (this.mParent.SelectionMode == System.Windows.Controls.SelectionMode.Single)
                {
                    this.mParent.SelectedItem = null;
                }
                else
                {
                    this.mParent.SelectedItems.Remove(pItem);
                }

                // Notification.
                if (pNotify)
                {
                    this.NotifySelectionChanged(new IHierarchicalItemViewModel[] { pItem }, new IHierarchicalItemViewModel[] { });
                }
            }
        }
コード例 #53
0
ファイル: SelectionModel.cs プロジェクト: mastertnt/XRay
        /// <summary>
        /// Adds the given to the selection.
        /// </summary>
        /// <param name="pItem">The item to add to the selection.</param>
        /// <param name="pNotify">Flag defining if the notification must be done.</param>
        private void InternalAddToSelection(IHierarchicalItemViewModel pItem, bool pNotify)
        {
            if (pItem.CanBeSelected && pItem.IsSelected == false)
            {
                // Updating view model.
                pItem.IsSelected = true;

                // Updating the selected items list.
                this.mSelectedItemsViewModel.Add(pItem);

                // Updating native selection handling.
                if (this.mParent.SelectionMode == System.Windows.Controls.SelectionMode.Single)
                {
                    this.mParent.SelectedItem = pItem;
                }
                else
                {
                    this.mParent.SelectedItems.Add(pItem);
                }

                // Notification.
                if (pNotify)
                {
                    this.NotifySelectionChanged(new IHierarchicalItemViewModel[] { }, new IHierarchicalItemViewModel[] { pItem });
                }
            }
        }
コード例 #54
0
ファイル: ExtendedListView.cs プロジェクト: mastertnt/XRay
        /// <summary>
        /// Delegate called when the mouse double clicked on this item.
        /// </summary>
        /// <param name="pItem">The double clicked item.</param>
        /// <param name="pEventArgs">The event arguments.</param>
        internal void OnItemMouseDoubleClicked(IHierarchicalItemViewModel pItem, System.Windows.Input.MouseButtonEventArgs pEventArgs)
        {
            // Handling the expand.
            this.mExpandBehavior.OnItemMouseDoubleClicked(pItem, pEventArgs);

            // Notification.
            if (this.ItemViewModelDoubleClicked != null)
            {
                this.ItemViewModelDoubleClicked(this, new IHierarchicalItemViewModel[] { pItem });
            }
        }
コード例 #55
0
ファイル: ExtendedListView.cs プロジェクト: mastertnt/XRay
 /// <summary>
 /// Delegate called when the expander gets unchecked on the given item.
 /// </summary>
 /// <param name="pItem">The unchecked item.</param>
 internal void OnItemExpanderUnchecked(IHierarchicalItemViewModel pItem)
 {
     // Handling the expand.
     this.mExpandBehavior.OnItemExpanderUnchecked(pItem);
 }
コード例 #56
0
ファイル: ExtendedListView.cs プロジェクト: mastertnt/XRay
 /// <summary>
 /// Delegate called when a key is pressed when the item get the focus.
 /// </summary>
 /// <param name="pItem">The clicked item.</param>
 /// <param name="pEventArgs">The event arguments.</param>
 internal void OnItemKeyUp(IHierarchicalItemViewModel pItem, System.Windows.Input.KeyEventArgs pEventArgs)
 {
     // Handling the expand.
     this.mExpandBehavior.OnItemKeyUp(null, pEventArgs);
 }
コード例 #57
0
ファイル: ExtendedListView.cs プロジェクト: mastertnt/XRay
        /// <summary>
        /// Removes the children from the rows.
        /// </summary>
        /// <param name="pViewModel">The view model containing the rows.</param>
        /// <param name="pIncludeParent">Flag indicating if the parent must be droped has well.</param>
        internal void DropChildrenItems(IHierarchicalItemViewModel pViewModel, bool pIncludeParent)
        {
            if (pViewModel.ChildrenAreLoaded)
            {
                int lStartIndex = this.Rows.IndexOf(pViewModel);
                int lCount = pViewModel.AllVisibleChildren.Count();

                if (pIncludeParent == false)
                {
                    lStartIndex++;
                }
                else
                {
                    lCount++;
                }

                // The item must be in the children list.
                if (lStartIndex != -1)
                {
                    this.Rows.RemoveRange(lStartIndex, lCount);
                }

                pViewModel.ChildrenAreLoaded = false;
            }
        }
コード例 #58
0
ファイル: ExtendedListView.cs プロジェクト: mastertnt/XRay
        /// <summary>
        /// Loads the children of this item in the control.
        /// </summary>
        /// <param name="pViewModel">The view model containing the children.</param>
        internal void LoadsChildrenItems(IHierarchicalItemViewModel pViewModel)
        {
            if (pViewModel.ChildrenAreLoaded == false)
            {
                int lStartIndex = this.Rows.IndexOf(pViewModel);
                this.Rows.InsertRange(lStartIndex + 1, pViewModel.AllVisibleChildren.ToArray());

                pViewModel.ChildrenAreLoaded = true;
                pViewModel.AllVisibleChildren.Where(lItem => lItem.IsExpanded).ForEach(lItem => lItem.ChildrenAreLoaded = true);
            }
        }
コード例 #59
0
ファイル: SelectionBehavior.cs プロジェクト: mastertnt/XRay
 /// <summary>
 /// Delegate called when the mouse right button is down on an item.
 /// </summary>
 /// <param name="pItem">The clicked item.</param>
 /// <param name="pEventArgs">The event arguments.</param>
 public void OnItemMouseRightButtonDown(IHierarchicalItemViewModel pItem, System.Windows.Input.MouseButtonEventArgs pEventArgs)
 {
     this.mParent.SelectionModel.Select(pItem);
 }
コード例 #60
0
ファイル: ExtendedListView.cs プロジェクト: mastertnt/XRay
        /// <summary>
        /// Scrolls the view to show the wanted item to the user.
        /// </summary>
        /// <param name="pItem">The item to bring.</param>
        /// <param name="pSelect">Flag indicating if the selected item must be selected.</param>
        /// <returns>True if the item is loaded, false otherwise.</returns>
        public bool ScrollIntoView(IHierarchicalItemViewModel pItem, bool pSelect)
        {
            if  (   (pItem != null)
                &&  (pItem.Parent != null)
                )
            {
                // Expand its parent to make pItem visible.
                pItem.Parent.IsExpanded = true;

                // Showing the added item.
                this.ScrollIntoView(pItem);

                // Selecting the item if asked.
                if (pSelect)
                {
                    this.SelectionModel.Select(pItem);
                }

                return true;
            }

            return false;
        }