예제 #1
0
 private void DragDropTarget_Drop(object sender, Microsoft.Windows.DragEventArgs e)
 {
     try
     {
         if (e.Data.GetDataPresent(typeof(ItemDragEventArgs)))
         {
             ItemDragEventArgs   cItemDragEventArgs   = (ItemDragEventArgs)e.Data.GetData(typeof(ItemDragEventArgs));
             SelectionCollection aSelectionCollection = (SelectionCollection)cItemDragEventArgs.Data;
             object oItemSelected = aSelectionCollection.Select(o => o.Item).FirstOrDefault();
             if (null != oItemSelected && Microsoft.Windows.DragDropEffects.Move == cItemDragEventArgs.Effects)
             {
                 if (_ui_lbLeft == cItemDragEventArgs.DragSource && _ui_dlbRight == sender)
                 {
                     SelectionChange(oItemSelected, true);
                 }
                 else if (_ui_tvLeft == cItemDragEventArgs.DragSource && _ui_dtvRight == sender)
                 {
                     SelectionChange(oItemSelected, true);
                 }
                 else if (_ui_lbRight == cItemDragEventArgs.DragSource && _ui_dlbLeft == sender)
                 {
                     SelectionChange(oItemSelected, false);
                 }
                 else if (_ui_tvRight == cItemDragEventArgs.DragSource && _ui_dtvLeft == sender)
                 {
                     SelectionChange(oItemSelected, false);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         (new controls.childs.sl.MsgBox()).ShowError(ex);
     }
 }
        private void AssociatedObject_Drop(object sender, DragEventArgs e)
        {
            // You can only get here when (e.AllowedEffects & DragDropEffects.Scroll) == DragDropEffects.Scroll
            if (DropDataSource != null && CastMethodSource != null && CastMethodName != null)
            {
                // Retrieve the dropped data in the first available format.
                var data = e.Data.GetData(e.Data.GetFormats()[0]);

                var dragEventArgs = data as ItemDragEventArgs;
                if (dragEventArgs != null)
                {
                    var selectionCollection = dragEventArgs.Data as SelectionCollection;
                    if (selectionCollection != null)
                    {
                        var dtos =
                            selectionCollection.Select(selection => selection.Item).OfType <object> ();
                        var methodInfo = CastMethodSource.GetType().GetMethod(CastMethodName);

                        if (dtos.Any() && methodInfo != null)
                        {
                            foreach (var dto in dtos)
                            {
                                var targetDto = methodInfo.Invoke(CastMethodSource, new[] { dto });
                                if (targetDto != null)
                                {
                                    DropDataSource.Add(targetDto);
                                }
                            }
                            e.Handled = true;
                        }
                    }
                }
            }
        }
예제 #3
0
        private void treeViewDDTarget_DragOver(object sender, Microsoft.Windows.DragEventArgs e)
        {
            var elements = VisualTreeHelper.FindElementsInHostCoordinates(e.GetPosition(treeView), treeView).Where(element => element is TreeViewItem).Cast <TreeViewItem>();

            if (elements.Any())
            {
                UIManager.Instance.SelectedGraphicInstance = elements.First().DataContext as GraphicInstance;
            }
        }
        private void DataGridDragDropTarget_Drop_2(object sender, Microsoft.Windows.DragEventArgs e)
        {
            //var data = (List<CsClient>)e.GetData<CsClient>();

            //foreach (var item in data)
            //{
            //    ListeClientEligibleSellection.Add(item);
            //}
            //e.Handled = true;
        }
예제 #5
0
        private void CreateItem(DragEventArgs args, Type type, LogicalInstance logicalInstance)
        {
            GraphicInstance graphicInstance = null;

            if (InstancesManager.Instance.CanvasRootElement == null)
            {
                graphicInstance = new RootInstance {
                    LogicalInstance = logicalInstance
                };
            }
            else
            {
                graphicInstance = CreateGraphicVisualizedInstance(type, logicalInstance, args);
            }
            InstancesManager.Instance.InstancesContext.GraphicInstances.Add(graphicInstance);
            InstancesManager.Instance.AddInstance(graphicInstance);
            InstancesManager.Instance.InstancesContext.SubmitChanges();
        }
예제 #6
0
        private void PerfilxPermisoTarget_Drop(object sender, Microsoft.Windows.DragEventArgs e)
        {
            object              data                = e.Data.GetData(e.Data.GetFormats()[0]);
            ItemDragEventArgs   dragEventArgs       = data as ItemDragEventArgs;
            SelectionCollection selectionCollection = dragEventArgs.Data as SelectionCollection;

            if (selectionCollection != null)
            {
                IEnumerable <T_Permiso> permisos = selectionCollection.Select(selection => selection.Item).OfType <T_Permiso>();
                if (permisos.Any())
                {
                    foreach (T_Permiso per in permisos)
                    {
                        vm.ListPermiso.Add(per);
                    }
                }
            }
        }
예제 #7
0
        protected override void OnDropOverride(Microsoft.Windows.DragEventArgs args)
        {
            ItemDragEventArgs rawObject = args.Data.GetData(args.Data.GetFormats()[0]) as ItemDragEventArgs;
            Type type = (rawObject.Data as System.Collections.ObjectModel.SelectionCollection).First().Item as Type;

            if (CanAddItem(null, type))
            {
                LogicalInstance logicalInstance = new LogicalInstance
                {
                    Name = "anonymous " + (Activator.CreateInstance(type) as ObjectType).TypeName,
                    Type = type.FullName
                };
                InstancesManager.Instance.InstancesContext.LogicalInstances.Add(logicalInstance);
                GraphicInstance graphicInstance = new RootInstance {
                    LogicalInstance = logicalInstance
                };
                InstancesManager.Instance.InstancesContext.GraphicInstances.Add(graphicInstance);
                InstancesManager.Instance.AddInstance(graphicInstance);
                InstancesManager.Instance.InstancesContext.SubmitChanges();
            }
        }
 private void SeriesListTarget_Drop(object sender, Microsoft.Windows.DragEventArgs e)
 {
 }
예제 #9
0
        /*
         * Event method that is called when an item is dropped into socket.
         * Checks to see if block can be added to socket and prefroms functions based on those checks.
         * Set the communication flag for socket to false (handled).
         */
        protected override void OnDropOverride(Microsoft.Windows.DragEventArgs args)
        {
            Debug.WriteLine("socket drop");
            if ((args.AllowedEffects & Microsoft.Windows.DragDropEffects.Link) == Microsoft.Windows.DragDropEffects.Link ||
                (args.AllowedEffects & Microsoft.Windows.DragDropEffects.Move) == Microsoft.Windows.DragDropEffects.Move)
            {
                //changed
                //gets the data format which is a ItemDragEventArgs
                object data = args.Data.GetData(args.Data.GetFormats()[0]);

                //changed
                //cast from generic object to ItemDragEventArgs and add to SelectionCollection
                ItemDragEventArgs   itemDragEventArgs   = data as ItemDragEventArgs;
                SelectionCollection selectionCollection = itemDragEventArgs.Data as SelectionCollection;
                //changed
                //get the target & source listbox from DragEventArgs
                ListBox dropTarget = GetDropTarget(args);

                //Copy from parent method
                if (dropTarget != null && selectionCollection.All(selection => CanAddItem(dropTarget, selection.Item)))
                {
                    if ((args.Effects & Microsoft.Windows.DragDropEffects.Move) == Microsoft.Windows.DragDropEffects.Move)
                    {
                        args.Effects = Microsoft.Windows.DragDropEffects.Move;
                    }
                    else
                    {
                        args.Effects = Microsoft.Windows.DragDropEffects.Link;
                    }

                    int?index = GetDropTargetInsertionIndex(dropTarget, args);

                    if (index != null)
                    {
                        if (args.Effects == Microsoft.Windows.DragDropEffects.Move && itemDragEventArgs != null && !itemDragEventArgs.DataRemovedFromDragSource)
                        {
                            itemDragEventArgs.RemoveDataFromDragSource();
                        }

                        //major change place at top of the listbox to act as a stack for undo
                        //needs to have its own method

                        foreach (Selection selection in selectionCollection)
                        {
                            if (selection.Item.GetType().Equals(typeof(Block)))
                            {
                                //creat copy block of the selection item
                                Block copyBlock = MainPage.createProgramStructureBlock(((Block)selection.Item).typeID);
                                if (copyBlock == null || (copyBlock != null && !copyBlock.type.Equals("STATEMENT"))) //check to make sure that you are not adding a STATEMENT to SOCKET
                                {
                                    Block selected = (Block)selection.Item;
                                    //check to make sure that you are not dragging into self
                                    dropTarget = preventOuroboros(itemDragEventArgs, dropTarget, selected, selected);

                                    if (copyBlock == null)
                                    {
                                        if (!((Block)selection.Item).Text.Equals("END"))
                                        {
                                            copyBlock = (selected).cloneSelf(true);
                                        }
                                        else
                                        {
                                            copyBlock = MainPage.createReservedBlock(selected.Text);
                                        }
                                    }

                                    //check to make sure that if there are more than 1 socket that they match
                                    if (SocketReader.socketCompatable(dropTarget, copyBlock))
                                    {
                                        //alter comboboxes if needed
                                        if (checkRestrictions(dropTarget, copyBlock))
                                        {
                                            if (copyBlock.ToString().Equals("DIRECTION"))
                                            {
                                                directionalCombos(dropTarget, copyBlock);
                                            }

                                            //flag to check if an element did move
                                            //used for cloneSockets check
                                            bool flag_DidAdd = false;

                                            //Add item to socket if allowed
                                            if (socketType.Contains(copyBlock.Text) || (copyBlock.returnType != null && socketType.Contains(copyBlock.returnType)))
                                            {
                                                ResizeAndAdd(dropTarget, copyBlock);
                                                flag_DidAdd = true;
                                            }
                                            else if (isConstant && copyBlock.flag_isConstant)
                                            {
                                                ResizeAndAdd(dropTarget, copyBlock);
                                                flag_DidAdd = true;
                                            }
                                            else if (isCondition && copyBlock.flag_isCondition)
                                            {
                                                ResizeAndAdd(dropTarget, copyBlock);
                                                flag_DidAdd = true;
                                            }

                                            //clone sockets if item was added
                                            if (copyBlock.flag_hasSocks && flag_DidAdd)
                                            {
                                                copyBlock = cloneSockets(selected, copyBlock);
                                            }
                                            if (!flag_DidAdd)
                                            {
                                                ErrorMessage(1);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        ErrorMessage(2);
                                    }
                                }
                                else
                                {
                                    ErrorMessage(3);
                                }
                            }
                        }
                        //socket is no longer dragging
                        MainPage.communicate.socket = false; //try to fix half of the communication error
                    }
                }
                else
                {
                    args.Effects = Microsoft.Windows.DragDropEffects.None;
                }

                if (args.Effects != args.AllowedEffects)
                {
                    args.Handled = true;
                }
            }
        }
예제 #10
0
 public ItemsControl GetRealDropTarget(Microsoft.Windows.DragEventArgs args)
 {
     return(base.GetDropTarget(args));
 }
예제 #11
0
        private GraphicInstance CreateGraphicVisualizedInstance(Type type, LogicalInstance logicalInstance, DragEventArgs args)
        {
            Point           position        = args.GetPosition(this);
            double          width           = (double)type.GetProperty("Width").GetValue(Activator.CreateInstance(type), null);
            double          height          = (double)type.GetProperty("Height").GetValue(Activator.CreateInstance(type), null);
            GraphicInstance graphicInstance = null;

            if (type.IsSubclassOf(typeof(NodeType)))
            {
                ParentableInstance parent = (this.Content as CanvasItemsControl).FindParent(position, graphicInstance);
                graphicInstance = new NodeInstance
                {
                    X               = position.X,
                    Y               = position.Y,
                    Width           = (width != 0 && !double.IsNaN(width)) ? width : 200,
                    Height          = (height != 0 && !double.IsNaN(height)) ? height : 200,
                    LogicalInstance = logicalInstance,
                    Parent          = parent
                };
            }
            else
            {
                graphicInstance = new EdgeInstance
                {
                    X               = position.X,
                    Y               = position.Y,
                    Width           = (width != 0 && !double.IsNaN(width)) ? width : 200,
                    Height          = (height != 0 && !double.IsNaN(height)) ? height : 200,
                    LogicalInstance = logicalInstance,
                    Parent          = InstancesManager.Instance.CanvasRootElement
                };
            }
            return(graphicInstance);
        }
 private void CategoryBorder_Drop(object sender, Microsoft.Windows.DragEventArgs e)
 {
 }
 private void SeriesListTarget_ItemDroppedOnSource(object sender, Microsoft.Windows.DragEventArgs e)
 {
 }
 private void ListBoxDragDropTargetExtend_ItemDroppedOnSource(object sender, Microsoft.Windows.DragEventArgs e)
 {
 }
 private void ListBoxDragDropTargetExtend_Drop(object sender, Microsoft.Windows.DragEventArgs e)
 {
 }
 private void TreeViewDragDropTarget_ItemDroppedOnSource(object sender, Microsoft.Windows.DragEventArgs e)
 {
 }
예제 #17
0
        protected override void OnDropOverride(Microsoft.Windows.DragEventArgs args)
        {
            //Debug.WriteLine("AllowAdd: " + AllowAdd);
            //Debug.WriteLine("trash");
            MainPage.communicate.trash = true;
            if (AllowAdd)
            {
                if ((args.AllowedEffects & Microsoft.Windows.DragDropEffects.Link) == Microsoft.Windows.DragDropEffects.Link ||
                    (args.AllowedEffects & Microsoft.Windows.DragDropEffects.Move) == Microsoft.Windows.DragDropEffects.Move)
                {
                    //changed
                    //gets the data format which is a ItemDragEventArgs
                    object data = args.Data.GetData(args.Data.GetFormats()[0]);

                    //changed
                    //cast from generic object to ItemDragEventArgs and add to SelectionCollection
                    ItemDragEventArgs   itemDragEventArgs   = data as ItemDragEventArgs;
                    SelectionCollection selectionCollection = itemDragEventArgs.Data as SelectionCollection;

                    //changed
                    //get the target listbox from DragEventArgs
                    ListBox dropTarget = GetDropTarget(args);

                    if (dropTarget != null && selectionCollection.All(selection => CanAddItem(dropTarget, selection.Item)))
                    {
                        if ((args.Effects & Microsoft.Windows.DragDropEffects.Move) == Microsoft.Windows.DragDropEffects.Move)
                        {
                            args.Effects = Microsoft.Windows.DragDropEffects.Move;
                        }
                        else
                        {
                            args.Effects = Microsoft.Windows.DragDropEffects.Link;
                        }

                        int?index = GetDropTargetInsertionIndex(dropTarget, args);
                        //Debug.WriteLine("?index: " + index.Value);
                        if (index != null)
                        {
                            if (args.Effects == Microsoft.Windows.DragDropEffects.Move && itemDragEventArgs != null && !itemDragEventArgs.DataRemovedFromDragSource)
                            {
                                itemDragEventArgs.RemoveDataFromDragSource();
                            }

                            //major change place at top of the listbox to act as a stack for undo
                            foreach (Selection selection in selectionCollection)
                            {
                                InsertItem(dropTarget, 0, selection.Item);
                            }
                        }
                    }
                    else
                    {
                        args.Effects = Microsoft.Windows.DragDropEffects.None;
                    }

                    if (args.Effects != args.AllowedEffects)
                    {
                        args.Handled = true;
                    }
                }
                AllowAdd = false;
            }
        }
        protected override void OnDropOverride(Microsoft.Windows.DragEventArgs args)
        {
            //Debug.WriteLine("Editor Drop");
            if ((args.AllowedEffects & Microsoft.Windows.DragDropEffects.Link) == Microsoft.Windows.DragDropEffects.Link ||
                (args.AllowedEffects & Microsoft.Windows.DragDropEffects.Move) == Microsoft.Windows.DragDropEffects.Move)
            {
                //changed
                //gets the data format which is a ItemDragEventArgs
                object data = args.Data.GetData(args.Data.GetFormats()[0]);

                //changed
                //cast from generic object to ItemDragEventArgs and add to SelectionCollection
                ItemDragEventArgs   itemDragEventArgs   = data as ItemDragEventArgs;
                SelectionCollection selectionCollection = itemDragEventArgs.Data as SelectionCollection;

                //changed
                //get the target & source listbox from DragEventArgs
                ListBox dropTarget = GetDropTarget(args);
                //ListBox src = (ListBox)itemDragEventArgs.DragSource;

                if (dropTarget != null && selectionCollection.All(selection => CanAddItem(dropTarget, selection.Item)))
                {
                    if ((args.Effects & Microsoft.Windows.DragDropEffects.Move) == Microsoft.Windows.DragDropEffects.Move)
                    {
                        args.Effects = Microsoft.Windows.DragDropEffects.Move;
                    }
                    else
                    {
                        args.Effects = Microsoft.Windows.DragDropEffects.Link;
                    }

                    int?index = GetDropTargetInsertionIndex(dropTarget, args);

                    if (index != null)
                    {
                        if (args.Effects == Microsoft.Windows.DragDropEffects.Move && itemDragEventArgs != null && !itemDragEventArgs.DataRemovedFromDragSource)
                        {
                            itemDragEventArgs.RemoveDataFromDragSource();
                        }

                        //major change place at top of the listbox to act as a stack for undo
                        //needs to have its own method
                        foreach (Selection selection in selectionCollection)
                        {
                            if (selection.Item.GetType().Equals(typeof(Block)))
                            {
                                //socket was added to the editor
                                if (MainPage.communicate.socket)
                                {
                                    MainPage.communicate.editor = true;  //let the socket know that it will need to be replaced
                                    MainPage.communicate.socket = false; //trying to fix the error

                                    //catching constant into constant in a first level block
                                    Block selected = selection.Item as Block;
                                    if (selected.flag_isConstant || selected.flag_isRobotConstant)
                                    {
                                        dropTarget = itemDragEventArgs.DragSource as ListBox;
                                        dropTarget.Items.Add(selected);
                                    }
                                }
                                else if (move) //moving in the editor window
                                {
                                    move = false;
                                    //Debug.WriteLine("move from " + fromIndex + " to " + index.Value);
                                    if (index.Value < dropTarget.Items.Count && (((Block)dropTarget.Items[index.Value]).Text.Equals("ELSE") || ((Block)dropTarget.Items[index.Value]).Text.Equals("ELSEIF")))
                                    {
                                        dropTarget.ItemsSource = tree.Move(fromIndex, fromIndex);
                                    }
                                    else
                                    {
                                        dropTarget.ItemsSource = tree.Move(fromIndex, index.Value);
                                    }
                                }
                                else
                                {
                                    Debug.WriteLine(((Block)selection.Item).typeID);
                                    Block copyBlock = MainPage.createProgramStructureBlock(((Block)selection.Item).typeID);

                                    if (copyBlock == null)
                                    {
                                        if (!((Block)selection.Item).Text.Equals("END"))
                                        {
                                            copyBlock = ((Block)selection.Item).cloneSelf(true);
                                        }
                                        //else if (((Block)selection.Item).Text.Equals("METHOD"))
                                        //    copyBlock = ((Block)selection.Item).cloneSelf();
                                        else
                                        {
                                            copyBlock = MainPage.createReservedBlock(((Block)selection.Item).Text);
                                        }
                                    }
                                    if (copyBlock.checkType("STATEMENT"))
                                    {
                                        if (copyBlock.flag_requiresEndIf)
                                        {
                                            //check if it is an else or else if and make sure that count and index are not 0 or null to preform operatoins

                                            if (copyBlock.flag_followsIfOnly && dropTarget.Items.Count > 0 && index.Value > 0)
                                            {
                                                //check previous index for end if block
                                                //add if it exist
                                                if (((Block)dropTarget.Items[index.Value - 1]).Text.Equals("ENDIF"))
                                                {
                                                    if (copyBlock.Text.Equals("ELSE"))
                                                    {
                                                        //check to see if there is already an else
                                                        if (index.Value < dropTarget.Items.Count && (((Block)dropTarget.Items[index.Value]).Text.Equals("ELSE") || ((Block)dropTarget.Items[index.Value]).Text.Equals("ELSEIF")))
                                                        {
                                                        }
                                                        else
                                                        {
                                                            Block endBlock = MainPage.createReservedBlock("ENDELSE");//.cloneSelf();
                                                            dropTarget.ItemsSource = tree.AddWithChild(copyBlock, endBlock, index.Value);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        Block endBlock = MainPage.createReservedBlock("ENDIF");//.cloneSelf();
                                                        dropTarget.ItemsSource = tree.AddWithChild(copyBlock, endBlock, index.Value);
                                                    }
                                                }
                                            }
                                            else if (!copyBlock.flag_followsIfOnly)
                                            {
                                                //doesn't allow if to be placed inbetween an if and else-if or else
                                                if (index.Value < dropTarget.Items.Count && (((Block)dropTarget.Items[index.Value]).Text.Equals("ELSEIF") || ((Block)dropTarget.Items[index.Value]).Text.Equals("ELSE")))
                                                {
                                                }
                                                else
                                                {
                                                    Block endBlock = MainPage.createReservedBlock("ENDIF");//.cloneSelf();
                                                    dropTarget.ItemsSource = tree.AddWithChild(copyBlock, endBlock, index.Value);
                                                }
                                            }
                                        }
                                        else if (index.Value < dropTarget.Items.Count && (((Block)dropTarget.Items[index.Value]).Text.Equals("ELSE") || ((Block)dropTarget.Items[index.Value]).Text.Equals("ELSEIF")))
                                        {
                                        }
                                        else if (copyBlock.flag_requiresEndLoop)
                                        {
                                            Block endBlock = MainPage.createReservedBlock("ENDLOOP");//.cloneSelf();
                                            dropTarget.ItemsSource = tree.AddWithChild(copyBlock, endBlock, index.Value);
                                        }
                                        else
                                        {
                                            dropTarget.ItemsSource = tree.Add(copyBlock, index.Value);
                                        }
                                    }
                                }
                            }
                        }
                        Refresh(dropTarget);
                    }
                }
                else
                {
                    args.Effects = Microsoft.Windows.DragDropEffects.None;
                }

                if (args.Effects != args.AllowedEffects)
                {
                    args.Handled = true;
                }
            }
        }