protected override void OnItemDragStarting(ItemDragEventArgs eventArgs)
        {
            SelectionCollection selectionCollection = eventArgs.Data as SelectionCollection;
            foreach (Selection selection in selectionCollection)
            {

                if (selection.Item.GetType().Equals(typeof(Block)))
                {
                    if (((Block)selection.Item).flag_isPackage)
                    {
                        eventArgs.Cancel = true;
                        eventArgs.Handled = true;
                    }
                    else
                    {
                        base.OnItemDragStarting(eventArgs);
                        ListBox listBox = eventArgs.DragSource as ListBox;
                        var testingList = listBox.ItemsSource;
                        if (testingList.GetType().Equals(typeof(ObservableCollection<Block>)))
                        {
                            ObservableCollection<Block> list = testingList as ObservableCollection<Block>;
                            listBox.ItemsSource = null;
                            var itemsToRemove = list.Where(item => !item.flag_isPackage).ToArray();
                            foreach (var item in itemsToRemove)
                            {
                                list.Remove(item);
                            }
                            listBox.ItemsSource = list;

                            listBox.ScrollIntoView(listBox.Items.ElementAt(0));
                        }
                    }
                }
            }
        }
        protected override void OnItemDroppedOnTarget(ItemDragEventArgs args)
        {
            //Debug.WriteLine("Editor On Item drop");
            ListBox listBox = args.DragSource as ListBox;
            SelectionCollection selectionCollection = args.Data as SelectionCollection;
            foreach (Selection selection in selectionCollection)
            {
                if (selection.Item.GetType().Equals(typeof(Block)))
                {
                    move = false;
                    if (MainPage.communicate.trash)
                    {
                        MainPage.communicate.trash = false;
                        listBox.ItemsSource = tree.Delete(((Block)selection.Item).index);
                    }
                }
            }
            try
            {
                base.OnItemDroppedOnTarget(args);
                listBox.ItemsSource = tree.ListRefresh();
                Refresh(listBox);
            }
            catch (Exception exe)
            {
            }

        }
        protected override void OnItemDragStarting(ItemDragEventArgs eventArgs)
        {
            //Debug.WriteLine("Editor drag start");
            SelectionCollection selectionCollection = eventArgs.Data as SelectionCollection;
            foreach (Selection selection in selectionCollection)
            {

                if (selection.Item.GetType().Equals(typeof(Block)))
                {
                    if (((Block)selection.Item).Text.Contains("END"))
                    {
                        eventArgs.Cancel = true;
                        eventArgs.Handled = true; 
                    }
                    else
                    {
                        if (!MainPage.communicate.socket) //check to see that you are not moving a socket
                        {
                            move = true;
                            fromIndex = ((Block)selection.Item).index;
                        }
                        base.OnItemDragStarting(eventArgs);
                    }
                }
            }
        }
        /*
         * Event method that is called when a socket item is dropped on destination.
         * Preforms functions based on the communication class.
         * Set the communication flag for socket to false (handled).
         * Calls parent method
         */
        protected override void OnItemDroppedOnTarget(ItemDragEventArgs args)
        {
            Debug.WriteLine("socket on item drop");
            ListBox listBox = args.DragSource as ListBox;

            SelectionCollection selectionCollection = args.Data as SelectionCollection;
            foreach (Selection selection in selectionCollection)
            {
                if (selection.Item.GetType().Equals(typeof(Block)))
                {
                    //create the block based on selection block
                    Block copyBlock = MainPage.createProgramStructureBlock(((Block)selection.Item).typeID);
                    if (copyBlock == null)
                    {
                        if (!((Block)selection.Item).Text.Contains("END"))
                            copyBlock = ((Block)selection.Item).cloneSelf(true);
                        else
                            copyBlock = MainPage.createReservedBlock(((Block)selection.Item).Text);
                    }

                    if (MainPage.communicate.trash) //socket moved to trash
                    {
                        MainPage.communicate.trash = false; //let trash know that socket finished move
                        listBox.Background.Opacity = 1; //show empty socket
                        listBox.BorderBrush.Opacity = 1; //show empty socket
                    }
                    else if (MainPage.communicate.editor) //socket moved to editor (removed communicate.socket to see if communication error is fixed)
                    {
                        //copyBlock goes here
                        if (listBox.Items.Count == 0)
                        {
                            Debigulate(listBox);
                            if (socketType.Contains(copyBlock.Text))
                                ResizeAndAdd(listBox, copyBlock);
                            else if (isConstant && copyBlock.flag_isConstant)
                                ResizeAndAdd(listBox, copyBlock);
                            else if (isCondition && copyBlock.flag_isCondition)
                                ResizeAndAdd(listBox, copyBlock);
                        }

                        MainPage.communicate.editor = false; //let editor know that that socket was added and move finished
                    }
                    else //socket moved else where...need to have a check to see if it was added
                    {
                        if (listBox.Items.Count == 0)
                        {
                            listBox.Background.Opacity = 1; //show empty socket
                            listBox.BorderBrush.Opacity = 1; //show empty socket
                        }
                    }
                }
            }
            base.OnItemDroppedOnTarget(args);
            MainPage.communicate.socket = false; //save that moveing socket is finished

            //returning the block to normal size, if neccessary
            Debigulate(listBox);
        }
 /// <summary>
 /// Initializes a new instance of the ItemDragEventArgs class using an
 /// existing instance.
 /// </summary>
 /// <param name="args">The instance to use as the template when creating
 /// the new instance.</param>
 internal ItemDragEventArgs(ItemDragEventArgs args)
 {
     this.AllowedEffects = args.AllowedEffects;
     this.Effects = args.Effects;
     this.Data = args.Data;
     this.DragSource = args.DragSource;
     this.KeyStates = args.KeyStates;
     this.OriginalSource = args.OriginalSource;
     this.DragDecoratorContent = args.DragDecoratorContent;
     this.DragDecoratorContentMouseOffset = args.DragDecoratorContentMouseOffset;
 }
        //private ListBox listBox = new ListBox();

        protected override void OnItemDragCompleted(ItemDragEventArgs args)
        {
            base.OnItemDragCompleted(args);

            ListBox listBox = args.DragSource as ListBox;
            var testingList = listBox.ItemsSource;
   
            if (testingList.GetType().Equals(typeof(ObservableCollection<Block>)))
            {
                ObservableCollection<Block> blockList = testingList as ObservableCollection<Block>;
                if (listBox != null)
                {
                    listBox.ItemsSource = null;
                    blockList.Clear();
                    foreach (Block b in list)
                    {
                        blockList.Add(b);
                    }
                    listBox.ItemsSource = blockList;
                }
            }   
        }
 protected override void OnItemDragStarting(ItemDragEventArgs eventArgs)
 {
     SelectionCollection selectionCollection = eventArgs.Data as SelectionCollection;
     
     foreach (Selection selection in selectionCollection)
     {
         if (selection.Item.GetType().Equals(typeof(Block)))
         {
             ListBox listBox = eventArgs.DragSource as ListBox;
             var testingList = listBox.ItemsSource;
             if (testingList.GetType().Equals(typeof(ObservableCollection<Block>)))
             {
                 ObservableCollection<Block> blockList = testingList as ObservableCollection<Block>;
                 list = new ObservableCollection<Block>();
                 foreach (Block b in blockList)
                 {
                     list.Add(b);
                 }
             }
             base.OnItemDragStarting(eventArgs);     
         }
     }
 }
Ejemplo n.º 8
0
        protected override void OnItemDragStarting(ItemDragEventArgs cEventArgs)
        {
            if (!_bMouseDown)
            {
                cEventArgs.Handled = true;
                return;
            }

			lock (_cSyncRoot)
            {
                if (_cTimerDragDropDelay == null)
                {
                    _cTimerDragDropDelay = new Timer
                    (
                        callback =>
                        {
							lock (_cSyncRoot)
                            {
                                if (!DragDrop.IsDragInProgress)
                                {
                                    Dispatcher.BeginInvoke(() =>
                                    {
                                        lock (_cSyncRoot)
                                        {
                                            base.OnItemDragStarting(cEventArgs);
                                        }
                                    });
                                }
                            }
                        },
                        null,
						nDelay,
                        Timeout.Infinite
                    );
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the ItemDragEventArgs class using an
 /// existing instance.
 /// </summary>
 /// <param name="args">The instance to use as the template when creating
 /// the new instance.</param>
 internal ItemDragEventArgs(ItemDragEventArgs args)
 {
     this.AllowedEffects = args.AllowedEffects;
     this.Effects = args.Effects;
     this.Data = args.Data;
     this.DragSource = args.DragSource;
     this.KeyStates = args.KeyStates;
     this.DragDecoratorContent = args.DragDecoratorContent;
     this.DragDecoratorContentMouseOffset = args.DragDecoratorContentMouseOffset;
     this.RemoveDataFromDragSourceAction = args.RemoveDataFromDragSourceAction;
     this.DataRemovedFromDragSource = args.DataRemovedFromDragSource;
 }
Ejemplo n.º 10
0
 protected override void OnItemDragStarting(ItemDragEventArgs eventArgs) 
 { 
     eventArgs.Cancel = true; 
     eventArgs.Handled = true; 
 }
Ejemplo n.º 11
0
        //method to prevent a block from going into one of its own sockets
        private ListBox preventOuroboros(ItemDragEventArgs itemDragEventArgs, ListBox dropTarget, Block immigrant, Block destination)
        {
            //testing dragging into self and catching it if it happens
            List<int> socks = SocketReader.socketFinder(destination);
            ListBox test;
            ListBox sourceBox = itemDragEventArgs.DragSource as ListBox;

            //handling constants
            if (immigrant.flag_isConstant || immigrant.flag_isRobotConstant)
            {
                //checking constants, accounting for their 1 lvl lower problem
                try
                {
                    Block source = SocketReader.getParentBlock(sourceBox);
                    Block dst = SocketReader.getParentBlock(dropTarget);
                    List<int> socketLocs = SocketReader.socketFinder(dst);
                    foreach (int loc in socketLocs)
                    {
                        ListBox targ = SocketReader.socketMole(dst, loc);
                        if (targ.Items.Count > 0)
                        {
                            //checking if the target is the current block's location
                             if (((Block)dropTarget.Items.ElementAt(0)) == source)
                            {
                                isConstant = immigrant.flag_isConstant;//for some reason this gets reset during the process, so setting it back
                                dropTarget = sourceBox;//changing the target to the block's current position, dropping it back in place
                            }
                        }
                    }
                }
                catch (Exception) { }
                
                //clearing the target so the block can be added
                if (dropTarget.Items.Count > 0)
                {
                    if(((Block)dropTarget.Items.ElementAt(0)) == immigrant)
                    dropTarget.Items.Clear();
                }
            }
            //checking the block's socket to ensure that it isn't being added to itself
            foreach (int loc in socks)
            {
                test = SocketReader.socketMole(destination, loc);
                //resetting the drop zone if true and shrinking the block down
                if (test == dropTarget)
                {
                    dropTarget = sourceBox;
                    Debigulate(dropTarget);
                    isCondition = immigrant.flag_isCondition;
                }
                //recursively calling, to ensure that the block isn't being added to a socket in a block within its own socket
                if (test.Items.Count > 0)
                {
                    dropTarget = preventOuroboros(itemDragEventArgs, dropTarget, immigrant, (Block)test.Items.ElementAt(0));
                }
            }
            return dropTarget;
        }
Ejemplo n.º 12
0
        public bool isCondition { get; set; }       //define if condition is allowed in socket
        #endregion

        #region Overwritten Methods
        /*
         * Event method that is called when a socket item starts to move.
         * Sets the socket communication to true, which allows other DDT's to know socket is being moved
         * Calls parent method
         */
        protected override void OnItemDragStarting(ItemDragEventArgs eventArgs)
        {
            Debug.WriteLine("socket on item drag start");
            MainPage.communicate.socket = true;
            base.OnItemDragStarting(eventArgs);
        }
Ejemplo n.º 13
0
		protected override void OnItemDragCompleted(ItemDragEventArgs args)
		{
 			 base.OnItemDragCompleted(args);
		}
Ejemplo n.º 14
0
		protected override void OnItemDroppedOnTarget(ItemDragEventArgs args)
		{
			base.OnItemDroppedOnTarget(args);
		}
        /// <summary>
        /// Adds all selected items when drag operation begins.
        /// </summary>
        /// <param name="eventArgs">Information about the event.</param>
        protected override void OnItemDragStarting(ItemDragEventArgs eventArgs)
        {
            SelectionCollection selectionCollection = new SelectionCollection();

            // If panel is virtualized there is no way of knowing the precise
            // index of each selected item.
            Panel itemsHost = this.ListBox.GetItemsHost();

            if (itemsHost is VirtualizingPanel)
            {
                foreach (object item in this.ListBox.SelectedItems)
                {
                    selectionCollection.Add(new Selection(item));
                }

                // Adding the item dragged even if it isn't selected
                SelectionCollection defaultSelectionCollection = SelectionCollection.ToSelectionCollection(eventArgs.Data);

                if (defaultSelectionCollection.Count == 1 && !selectionCollection.Any(selection => object.Equals(selection.Item, defaultSelectionCollection[0].Item)))
                {
                    selectionCollection.Add(defaultSelectionCollection[0]);
                }
            }
            else
            {
                for (int cnt = 0; cnt < this.ListBox.Items.Count; cnt++)
                {
                    ListBoxItem listBoxItem = this.ListBox.ItemContainerGenerator.ContainerFromIndex(cnt) as ListBoxItem;
                    if (listBoxItem.IsSelected)
                    {
                        selectionCollection.Add(new Selection(cnt, this.ListBox.Items[cnt]));
                    }
                }

                // Adding the item dragged even if it isn't selected
                SelectionCollection defaultSelectionCollection = GetSelectionCollection(eventArgs.Data);
                if (defaultSelectionCollection.Count == 1)
                {
                    if (selectionCollection.All(selection => selection.Index != defaultSelectionCollection[0].Index))
                    {
                        selectionCollection.Add(defaultSelectionCollection[0]);
                    }
                }
            }

            eventArgs.Data = selectionCollection;

            CardPanel cardPanel = new CardPanel();
            IEnumerable <UIElement> itemContainers =
                selectionCollection.SelectedItems
                .Select(item => this.ListBox.ItemContainerGenerator.ContainerFromItem(item))
                .Where(item => item != null)
                .OfType <UIElement>();

            foreach (ListBoxItem row in itemContainers)
            {
                cardPanel.Children.Add(new Image {
                    Source = new WriteableBitmap(row, new TranslateTransform())
                });
            }

            eventArgs.DragDecoratorContent = cardPanel;

            eventArgs.Handled = true;
            base.OnItemDragStarting(eventArgs);
        }