예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="selectedItem"></param>
        public void RemoveSet(ITreeViewItemViewModel selectedItem)
        {
            if (selectedItem == null)
            {
                //imply selection
                selectedItem = this.treeviewCardSets.SelectedValue as ITreeViewItemViewModel;
                if (selectedItem != null)
                {
                    CardSetModelView setModel;
                    if (!selectedItem.IsLeaf)
                    {
                        setModel = selectedItem as CardSetModelView;
                    }
                    else
                    {
                        return;
                    }

                    CardSets.Remove(setModel);
                    NotifyPropertyChanged("CardSets");
                    NotifyPropertyChanged("ObservableCardSets");
                }
            }
            else
            {
                CardSetModelView set = selectedItem as CardSetModelView;
                if (set != null && CardSets.Contains(set))
                {
                    CardSets.Remove(set);
                    NotifyPropertyChanged("CardSets");
                    NotifyPropertyChanged("ObservableCardSets");
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Moves a card from the old set to this one
        /// and notifies of property changes.
        /// </summary>
        /// <param name="old"></param>
        public void TransferCard(CardModelView card)
        {
            if (card == null)
            {
                return;
            }
            CardSetModelView old = card.Parent as CardSetModelView;

            if (old == null)
            {
                return;
            }
            if (old == this)
            {
                //MessageBox.Show("Whoa!");
                return;
            }

            _Cards.Add(card);
            old._Cards.Remove(card);
            card.TransferOwnership(this);

            NotifyPropertyChanged("Cards");
            NotifyPropertyChanged("Children");
            old.NotifyPropertyChanged("Cards");
            old.NotifyPropertyChanged("Children");
        }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        public void AddSet()
        {
            CardSetModelView newSet = new CardSetModelView();

            newSet.ResetToDefaultSet();
            CardSets.Add(newSet);
            NotifyPropertyChanged("CardSets");
            NotifyPropertyChanged("ObservableCardSets");
        }
예제 #4
0
        private void treeview_MouseMove(object sender, MouseEventArgs e)
        {
            if (!Dragging)
            {
                return;
            }
            try
            {
                if (e.LeftButton == MouseButtonState.Pressed)
                {
                    Point currentMousePos = e.GetPosition(this.treeviewCardSets);
                    if (Math.Abs(currentMousePos.X - StartDragPos.X) > SystemParameters.MinimumHorizontalDragDistance ||
                        Math.Abs(currentMousePos.Y - StartDragPos.Y) > SystemParameters.MinimumVerticalDragDistance)
                    {
                        DraggedItem = this.treeviewCardSets.SelectedItem as ITreeViewItemViewModel;
                        if (DraggedItem != null)
                        {
                            DragDropEffects finalDropEffect = DragDrop.DoDragDrop(this.treeviewCardSets,
                                                                                  this.treeviewCardSets.SelectedValue,
                                                                                  DragDropEffects.Move);

                            //ensure target is not null and item is dragging
                            if (finalDropEffect == DragDropEffects.Move && DropTarget != null)
                            {
                                if (DropTarget.IsLeaf)
                                {
                                    CardSetModelView set = DropTarget.Parent as CardSetModelView;
                                    set.TransferCard(DraggedItem as CardModelView);
                                    DropTarget  = null;
                                    DraggedItem = null;
                                }
                                else
                                {
                                    //copy card to target set
                                    //then remove references
                                    CardSetModelView set = DropTarget as CardSetModelView;
                                    set.TransferCard(DraggedItem as CardModelView);
                                    DropTarget  = null;
                                    DraggedItem = null;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
            return;
        }
예제 #5
0
        public void ImportSet(string fileName)
        {
            if (fileName != null && fileName.Length > 0)
            {
                //imply selection
                ITreeViewItemViewModel selectedItem = this.treeviewCardSets.SelectedValue as ITreeViewItemViewModel;

                if (selectedItem != null)
                {
                    //CardSetModelView cardSet;
                    //if (selectedItem.IsLeaf) cardSet = selectedItem.Parent as CardSetModelView;
                    //else cardSet = selectedItem as CardSetModelView;

                    //serialize that card
                    IFormatter       formatter = new BinaryFormatter();
                    Stream           stream    = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
                    CardSetModelView cardSet   = (CardSetModelView)formatter.Deserialize(stream);
                    stream.Close();

                    if (cardSet == null)
                    {
                        MessageBox.Show("The card set did not load properly. " + fileName);
                        return;
                    }
                    //cardSet.AddCardToSet(cardSet);
                    this.CardSets.Add(cardSet);
                    NotifyPropertyChanged("CardSets");
                    NotifyPropertyChanged("ObservableCardSets");
                    cardSet.IsExpanded = true;
                    ActiveCard         = cardSet.Cards[0] as CardModelView;
                }
                else
                {
                    MessageBox.Show("There was an error loading the card. " + fileName);
                }
            }
        }
예제 #6
0
        public void RenameSet()
        {
            //imply selection
            ITreeViewItemViewModel selectedItem = this.treeviewCardSets.SelectedValue as ITreeViewItemViewModel;

            if (selectedItem != null)
            {
                CardSetModelView setModel;
                if (!selectedItem.IsLeaf)
                {
                    setModel = selectedItem as CardSetModelView;
                }
                else
                {
                    return;
                }

                TreeViewItem item = this.treeviewCardSets.ItemContainerGenerator.ContainerFromItem(this.treeviewCardSets.SelectedItem) as TreeViewItem;
                //myTree.ItemContainerGenerator.ContainerFromItem(SelectedItem) as TreeViewItem
                if (item == null)
                {
                    MessageBox.Show("Oh no");
                    return;
                }
                GeneralTransform myTransform = item.TransformToAncestor(treeviewCardSets);
                Point            myOffset    = myTransform.Transform(new Point(0, 0));
                // myOffset.Y contains your distance from the top of the treeview now
                textboxRenamer.Margin = new Thickness(10.0, myOffset.Y + 32.0, 0, 0);
                SelectedSet           = setModel;

                this.textboxRenamer.Visibility = System.Windows.Visibility.Visible;
                this.textboxRenamer.IsEnabled  = true;
                this.textboxRenamer.Text       = setModel.Name;
                this.textboxRenamer.Focus();
            }
        }
예제 #7
0
 public void SetOwner(CardSetModelView set)
 {
     this._OwningSet = set;
 }
예제 #8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="newSet"></param>
 public void TransferOwnership(CardSetModelView newSet)
 {
     this._OwningSet = newSet;
 }
예제 #9
0
 /// <summary>
 /// Required public default constructor for data binding.
 /// </summary>
 public CardModelView(CardSetModelView owningSet)
 {
     _OwningSet = owningSet;
 }