/// <summary> /// Retire un fils /// </summary> /// <param name="child"></param> public void RemoveChild(IHierarchyObject child) { foreach (IHierarchyObject item in childrenListChangeHandler.Items) { if (item.GetPosition() > child.GetPosition()) { item.SetPosition(item.GetPosition() - 1); childrenListChangeHandler.AddUpdated((Attribute)item); } } child.SetPosition(-1); Attribute Child = (Attribute)child; if (Child.valueListChangeHandler.Items.Count > 0) { AttributeValue root = Child.valueListChangeHandler.Items[0].parent; for (int i = root.GetItems().Count - 1; i >= 0; i--) { AttributeValue value = root.childrenListChangeHandler.Items[i]; root.RemoveChild(value); } Child.removeDefaultValue(); } childrenListChangeHandler.AddDeleted(Child); UpdateParents(); }
/// <summary> /// Déplace un noeud vers le haut ou vers le bas /// </summary> /// <param name="item"></param> /// <param name="sens">Le sens du déplacement. 0 => UP, 1=> DOWN</param> public void MoveNode(IHierarchyObject item, int sens = 0) { if (item.GetParent() != null) { int position = item.GetPosition() + (sens == 0 ? -1 : 1); IHierarchyObject child = item.GetParent().GetChildByPosition(position); if (child != null) { child.SetPosition(item.GetPosition()); item.GetParent().UpdateChild(child); item.SetPosition(position); item.GetParent().UpdateChild(item); if (Change != null) { Change(); } SelectItem(this, item); } } }
/// <summary> /// Oublier un fils /// </summary> /// <param name="child"></param> public void ForgetChild(IHierarchyObject child) { foreach (IHierarchyObject item in childrenListChangeHandler.Items) { if (item.GetPosition() > child.GetPosition()) { item.SetPosition(item.GetPosition() - 1); } } child.SetPosition(-1); childrenListChangeHandler.forget((PresentationSlideItem)child); }
/// <summary> /// Retire un fils /// </summary> /// <param name="child"></param> public void RemoveChild(IHierarchyObject child) { foreach (IHierarchyObject item in childrenListChangeHandler.Items) { if (item.GetPosition() > child.GetPosition()) { item.SetPosition(item.GetPosition() - 1); } } child.SetPosition(-1); childrenListChangeHandler.AddDeleted((BGroup)child); }
/// <summary> /// Oublier un fils /// </summary> /// <param name="child"></param> public void ForgetChild(IHierarchyObject child) { foreach (IHierarchyObject item in childrenListChangeHandler.Items) { if (item.GetPosition() > child.GetPosition()) { item.SetPosition(item.GetPosition() - 1); } } child.SetPosition(-1); childrenListChangeHandler.forget((AttributeValue)child); }
/// <summary> /// Retire un fils /// </summary> /// <param name="child"></param> public void RemoveChild(IHierarchyObject child) { foreach (IHierarchyObject item in childrenListChangeHandler.Items) { if (item.GetPosition() > child.GetPosition()) { item.SetPosition(item.GetPosition() - 1); childrenListChangeHandler.AddUpdated((AttributeValue)item); } } child.SetPosition(-1); childrenListChangeHandler.AddDeleted((AttributeValue)child); UpdateParents(); }
/// <summary> /// Transforme un noeud en sous-noeud /// </summary> /// <param name="model">le noeud à édenté</param> public void IndentNode(IHierarchyObject item) { if (item.GetParent() != null) { int position = item.GetPosition(); IHierarchyObject child = item.GetParent().GetChildByPosition(position - 1); if (child != null) { item.GetParent().ForgetChild(item); child.AddChild(item); if (Change != null) { Change(); } SelectItem(this, item); } } }
/// <summary> /// Supprime un noeud et ses fils. /// </summary> /// <param name="model">Le noeud à supprimer</param> public void DeleteNode(IHierarchyObject item) { if (item != null && item.GetParent() != null) { MessageBoxResult result = Util.MessageDisplayer.DisplayYesNoQuestion("Delete Item", "Do you want to delete node : " + item.ToString() + "?"); if (result == MessageBoxResult.Yes) { int index = item.GetPosition(); item.GetParent().RemoveChild(item); item.GetParent().UpdateParents(); if (Change != null) { Change(); } if (this.Root.GetItems().Count > 1) { selectNodeAfterDelete(item, index); } } } }
/// <summary> /// Cette méthode permet de désactiver un menuItem dans le cas /// où l'opération associée à ce menuItem n'est pas possible pour /// le noeud courant. /// </summary> /// <param name="e"></param> protected override void OnContextMenuOpening(ContextMenuEventArgs e) { IHierarchyObject selectedItem = (IHierarchyObject)this.SelectedItem; this.NewMenuItem.IsEnabled = this.Root != null; this.EditMenuItem.IsEnabled = this.Root != null && selectedItem != null && CurrentParent != null; this.CutMenuItem.IsEnabled = this.Root != null && selectedItem != null && CurrentParent != null; this.CopyMenuItem.IsEnabled = this.Root != null && selectedItem != null && CurrentParent != null; this.PasteMenuItem.IsEnabled = this.Root != null && selectedItem != null && !Util.ClipbordUtil.IsClipBoardEmpty(); this.DeleteMenuItem.IsEnabled = this.Root != null && selectedItem != null && CurrentParent != null; this.MoveUpMenuItem.IsEnabled = this.Root != null && selectedItem != null && selectedItem.GetPosition() > 0 && CurrentParent != null; this.MoveDownMenuItem.IsEnabled = this.Root != null && selectedItem != null && selectedItem.GetPosition() < selectedItem.GetParent().GetItems().Count - 1 && CurrentParent != null; this.IndentMenuItem.IsEnabled = this.Root != null && selectedItem != null && selectedItem.GetPosition() > 0 && CurrentParent != null; this.OutdentMenuItem.IsEnabled = this.Root != null && selectedItem != null && selectedItem.GetParent() != null && selectedItem.GetParent() != Root && CurrentParent != null; }