Ejemplo n.º 1
0
        private void listViewCategories_Dropped(object sender, OlvDropEventArgs e)
        {
            if (e.DropTargetIndex == -1)
            {
                return;
            }

            var data          = (OLVDataObject)e.DataObject;
            var draggedObject = data.ModelObjects[0];

            // Change category position
            if (draggedObject is Category)
            {
                // Set categories using listview order
                categories = listViewCategories.Objects.Cast <Category>().ToList();
                needUpdate = true;
            }

            // Change item's category
            else
            {
                var item        = draggedObject as Item;
                var newCategory = e.DropTargetItem.RowObject as Category;

                if (item.Category == newCategory)
                {
                    return;
                }

                item.Category.Items.Remove(item);
                newCategory.Items.Add(item);

                ShowItemList(categories.IndexOf(newCategory));
            }
        }
Ejemplo n.º 2
0
 void rearrangingDropSink_Dropped(object sender, OlvDropEventArgs e)
 {
     if (GroupingChanged != null)
     {
         GroupingChanged(this, EventArgs.Empty);
     }
 }
Ejemplo n.º 3
0
        private void HandleCanDrop(object sender, OlvDropEventArgs e)
        {
            // This will only be triggered if HandleModelCanDrop doesn't set Handled to true.
            // In practice, this will only be called when the source of the drag is not an ObjectListView

            IDataObject data = e.DataObject as IDataObject;

            if (data == null || !data.GetDataPresent(DataFormats.UnicodeText))
            {
                return;
            }

            string str = data.GetData(DataFormats.UnicodeText) as string;

            e.Effect = String.IsNullOrEmpty(str) ? DragDropEffects.None : DragDropEffects.Copy;

            switch (e.DropTargetLocation)
            {
            case DropTargetLocation.AboveItem:
            case DropTargetLocation.BelowItem:
                e.InfoMessage = "Cannot drop between items -- because I haven't written the logic :)";
                break;

            case DropTargetLocation.Background:
                e.InfoMessage = "Drop here to create a new root item called '" + str + "'";
                break;

            case DropTargetLocation.Item:
                e.InfoMessage = "Drop here to create a new child item called '" + str + "'";
                break;

            default:
                return;
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Shows when an object can and cannot be dropped in the list view
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void olvCraftList_CanDrop(object sender, OlvDropEventArgs e)
 {
     // If object is a file, allow copy
     if (e.DragEventArgs.Data.GetDataPresent(DataFormats.FileDrop, false))
     {
         e.Effect = DragDropEffects.Copy;
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Returns an array of file paths, when given an argument object recieved by the OnCanDrop and OnDropped events.
 /// </summary>
 /// <param name="args"></param>
 /// <returns></returns>
 public List <string> GetDroppedFiles(OlvDropEventArgs args)
 {
     try {
         return(((string[])args.DragEventArgs.Data.GetData(DataFormats.FileDrop)).ToList <string>());
     } catch (Exception) {
     }
     return(null);
 }
 private void DropsinkOnDropped(object sender, OlvDropEventArgs e)
 {
     if (e.DataObject is DataObject dataObject && dataObject.GetFormats().Any(f => f == "FileDrop"))
     {
         var files = (string[])dataObject.GetData(DataFormats.FileDrop);
         OnLoadFile?.Invoke(this, files);
     }
 }
 private void DropsinkOnCanDrop(object sender, OlvDropEventArgs e)
 {
     if (e.DataObject is DataObject dataObject && dataObject.GetFormats().Any(f => f == "FileDrop"))
     {
         e.Effect  = DragDropEffects.Copy;
         e.Handled = true;
     }
 }
Ejemplo n.º 8
0
 private void ObjectListView1CanDrop(object sender, OlvDropEventArgs e)
 {
     if (e.DropTargetItem.RowObject is TableBlock)
     {
         e.Effect = DragDropEffects.Move;
     }
     else
     {
         e.Effect = DragDropEffects.None;
     }
 }
Ejemplo n.º 9
0
        private void HandleDropped(object sender, OlvDropEventArgs e)
        {
            // This will only be triggered if HandleModelDropped doesn't set Handled to true.
            // In practice, this will only be called when the source of the drag is not an ObjectListView

            DataObject data = e.DataObject as DataObject;

            if (data == null || String.IsNullOrEmpty(data.GetText()))
            {
                return;
            }

            TreeListView treeListView = e.ListView as TreeListView;

            if (treeListView == null)
            {
                return;
            }

            ModelWithChildren newModel = new ModelWithChildren {
                Label           = data.GetText(),
                DataForChildren = new ArrayList {
                    "A", "B ", "C", "D", "E"
                }
            };

            switch (e.DropTargetLocation)
            {
            case DropTargetLocation.AboveItem:
                break;

            case DropTargetLocation.BelowItem:
                break;

            case DropTargetLocation.Background:
                treeListView.AddObject(newModel);
                break;

            case DropTargetLocation.Item:
                ModelWithChildren targetModel = e.DropTargetItem.RowObject as ModelWithChildren;
                if (targetModel != null)
                {
                    newModel.Parent = targetModel;
                    targetModel.Children.Add(newModel);
                    treeListView.RefreshObject(targetModel);
                }
                break;

            default:
                return;
            }
        }
Ejemplo n.º 10
0
        private void lvIcons_CanDrop(object sender, OlvDropEventArgs e)
        {
            DataObject d = (DataObject)e.DataObject;

            if (d.GetDataPresent(DataFormats.FileDrop, false) == true)
            {
                e.Effect = DragDropEffects.Move;
            }
            else
            {
                e.Effect = DragDropEffects.None;
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Handles when external files are dropped into the list view
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void olvCraftList_Dropped(object sender, OlvDropEventArgs e)
        {
            if (!e.DragEventArgs.Data.GetDataPresent(DataFormats.FileDrop, false))
            {
                return;
            }

            // File system list of paths of files dropped into the list view
            var files = ((string[])e.DragEventArgs.Data.GetData(DataFormats.FileDrop)).ToList();

            _craftFileHandler.CopyNewCraftToSave(files, cbDefaultSave.Text);
            UpdateList();
        }
Ejemplo n.º 12
0
        private void lvIcons_Dropped(object sender, OlvDropEventArgs e)
        {
            DataObject d = (DataObject)e.DataObject;

            if (d.GetDataPresent(DataFormats.FileDrop, false) == true)
            {
                try
                {
                    string[]          data  = (string[])d.GetData(DataFormats.FileDrop);
                    List <IconObject> icons = new List <IconObject>();
                    foreach (string file in data)
                    {
                        if (Path.GetFileName(file).Contains(".ico"))
                        {
                            string     name      = Path.GetFileName(file).Replace(Path.GetExtension(file), "");
                            string     extension = Path.GetExtension(file);
                            string     path      = file;
                            long       length    = new FileInfo(file).Length;
                            string     size      = length.ToFileSize();
                            string     status    = "Idle";
                            IconObject io        = new IconObject(name, extension, path, size, length.ToString(), status);
                            icons.Add(io);
                        }
                    }

                    if (icons.Count > 0)
                    {
                        lvIcons.AddObjects(icons);
                    }

                    if (lvIcons.Items.Count == 0)
                    {
                        lvIcons.View      = View.SmallIcon;
                        btnInject.Enabled = false;
                    }
                    else
                    {
                        lvIcons.View = View.Details;
                        if (txtAssemblyPath.Text == "")
                        {
                            btnInject.Enabled = false;
                        }
                        else
                        {
                            btnInject.Enabled = true;
                        }
                    }
                }
                catch { }
            }
        }
Ejemplo n.º 13
0
 private void ListView_CanDrop(object sender, OlvDropEventArgs e)
 {
     try
     {
         if (dropLocker)
         {
             e.Effect   = DragDropEffects.None;
             dropLocker = false;
         }
     }
     catch (Exception ex)
     {
         Log.ShowError(ex);
     }
 }
Ejemplo n.º 14
0
        private void ObjectListView1Dropped(object sender, OlvDropEventArgs e)
        {
            OLVDataObject o = e.DataObject as OLVDataObject;

            if (o != null)
            {
                List <TableBlock> blocks = new List <TableBlock>();
                foreach (TableBlock block in o.ModelObjects)
                {
                    blocks.Add(block);
                }

                this.MoveBlocks(blocks, e.DropTargetIndex);
            }
        }
Ejemplo n.º 15
0
        private void listViewItems_Dropped(object sender, OlvDropEventArgs e)
        {
            if (e.DropTargetIndex < 0)
            {
                return;
            }

            var data        = e.DataObject as OLVDataObject;
            var draggedItem = data.ModelObjects[0] as Item;

            var oldCategoryIndex = draggedItem.Category.Items.IndexOf(draggedItem);

            draggedItem.Category.Items.Move(oldCategoryIndex, e.DropTargetIndex);

            needUpdate = true;
        }
Ejemplo n.º 16
0
 private void ListView_Dropped(object sender, OlvDropEventArgs e)
 {
     try
     {
         Console.WriteLine(SourceObjectType.Name + " Dropped " + e.DataObject);
         bool cut = (e.Effect == DragDropEffects.Move);
         bool res = PasteSelectedObjectsFromIDataObject(e.DropTargetItem != null ? e.DropTargetItem.RowObject : null, e.DataObject as IDataObject, cut);
         if (res)
         {
             MessageBox.Show(FrwCRUDRes.Drag_Record_Successfully + (cut ? FrwCRUDRes.Drage_Moved : FrwCRUDRes.Drag_Copied));
         }
     }
     catch (Exception ex)
     {
         Log.ShowError(ex);
     }
 }
Ejemplo n.º 17
0
        void DragDropProvider_CanDrop(object sender, OlvDropEventArgs e)
        {
            var dropTargetModel = e.DropTargetItem != null ? e.DropTargetItem.RowObject :null;
            var dataObject      = e.DataObject as DataObject;

            if (dataObject == null)
            {
                return;
            }

            if (dataObject is OLVDataObject)
            {
                return; //should be handled by ModelCanDrop
            }
            var execution = GetExecutionCommandIfAnyForNonModelObjects(dataObject, dropTargetModel);

            if (execution != null)
            {
                DisplayFeedback(execution, e);
            }
        }
Ejemplo n.º 18
0
 void rearrangingDropSink_CanDrop(object sender, OlvDropEventArgs e)
 {
     if (GroupingChanging != null)
     {
         var eventArgs = new GroupingChangingEventArgs <T>()
         {
             Grouping = (e.DataObject as OLVDataObject).ModelObjects[0] as Grouping <T>,
             NewIndex = Math.Max(0, e.DropTargetIndex)
         };
         if (e.DropTargetItem != null && ReferenceEquals(eventArgs.Grouping, e.DropTargetItem.RowObject))
         {
             e.Effect = DragDropEffects.None;
         }
         else
         {
             GroupingChanging(this, eventArgs);
             if (eventArgs.Cancel)
             {
                 e.Effect = DragDropEffects.None;
             }
         }
     }
 }
Ejemplo n.º 19
0
        private void DragDropProvider_Dropped(object sender, OlvDropEventArgs e)
        {
            try
            {
                var dataObject = (DataObject)e.DataObject;

                if (dataObject is OLVDataObject)
                {
                    return;  //should be handled by ModelDropped
                }
                //is it a non model drop (in which case ModelDropped won't be called) e.g. it could be a file drop
                var execution = GetExecutionCommandIfAnyForNonModelObjects(dataObject, e.DropTargetItem.RowObject);

                if (execution != null && !execution.IsImpossible)
                {
                    execution.Execute();
                }
            }
            catch (Exception exception)
            {
                ExceptionViewer.Show(exception);
            }
        }
Ejemplo n.º 20
0
        private void DisplayFeedback(ICommandExecution execution, OlvDropEventArgs e)
        {
            //no command is even remotely possible
            if (execution == null)
            {
                e.DropSink.FeedbackColor = Color.IndianRed;
                return;
            }

            //valid combination of objects but not possible due to object states
            if (execution.IsImpossible)
            {
                e.DropSink.FeedbackColor       = Color.IndianRed;
                e.DropSink.Billboard.BackColor = Color.IndianRed;
                e.InfoMessage = execution.ReasonCommandImpossible;
                return;
            }

            e.DropSink.Billboard.BackColor = Color.GreenYellow;
            e.DropSink.FeedbackColor       = Color.GreenYellow;
            e.InfoMessage = execution.GetCommandName();
            e.Handled     = true;
            e.Effect      = DragDropEffects.Move;
        }
Ejemplo n.º 21
0
 private void tlvGroupedFiles_CanDrop(object sender, OlvDropEventArgs e)
 {
     if (e.DataObject.GetType().ToString() == "System.Windows.Forms.DataObject")
     {
         e.Effect = DragDropEffects.Move;
     }
     else if (e.DataObject is OLVDataObject && e.DropTargetItem != null &&
              (e.DropTargetItem.RowObject is tlvBranch &&
               ((e.DropTargetItem.RowObject as tlvBranch).Data is SpectrumSourceGroup ||
                (e.DropTargetItem.RowObject as tlvBranch).Data is SpectrumSource)))
     {
         var target   = e.DropTargetItem.RowObject as tlvBranch;
         var dragging = (e.DataObject as OLVDataObject).ModelObjects;
         var isValid  = true;
         foreach (var item in dragging)
         {
             if (checkIfDestGroupAChildNodeOfMe(target, item as tlvBranch))
             {
                 isValid = false;
                 break;
             }
         }
         if (isValid)
         {
             e.Effect = DragDropEffects.Move;
         }
         else
         {
             e.Effect = DragDropEffects.None;
         }
     }
     else
     {
         e.Effect = DragDropEffects.None;
     }
 }
Ejemplo n.º 22
0
        private void tlvGroupedFiles_Dropped(object sender, OlvDropEventArgs e)
        {
            var target    = (tlvBranch)e.DropTargetItem.RowObject;
            var index     = -1;
            var toRefresh = new HashSet <tlvBranch>();

            if (target.Data is SpectrumSource)
            {
                index  = target.Parent.Children.IndexOf(target);
                target = target.Parent;
            }
            if (e.DataObject.GetType().ToString() == "System.Windows.Forms.DataObject")
            {
                var sources = new List <tlvBranch>();
                foreach (ListViewItem item in lvNonGroupedFiles.SelectedItems)
                {
                    sources.Add((tlvBranch)item.Tag);
                }
                //var sources = from ListViewItem item in lvNonGroupedFiles.SelectedItems
                //              select (tlvBranch) item.Tag;

                foreach (var source in sources)
                {
                    if (index >= 0)
                    {
                        target.Children.Insert(index, source);
                    }
                    else
                    {
                        target.Children.Add(source);
                    }
                    source.Parent = target;
                }

                toRefresh.Add(target);

                var usedItems = from ListViewItem item in lvNonGroupedFiles.SelectedItems
                                select item;
                foreach (var item in usedItems)
                {
                    lvNonGroupedFiles.Items.Remove(item);
                }
            }
            else if (e.DataObject is OLVDataObject)
            {
                var dragging = e.DataObject as OLVDataObject;
                var sources  = from tlvBranch item in dragging.ModelObjects
                               where item.Data is SpectrumSource
                               select item;
                var groups = from tlvBranch item in dragging.ModelObjects
                             where (item.Data is SpectrumSourceGroup &&
                                    (item.Data as SpectrumSourceGroup).Name != "\\")
                             select item;
                var sourcesToIgnore = new List <tlvBranch>();

                foreach (var group in groups)
                {
                    //find and ignore spectra in group
                    getListOfSprectrumSourcesRecursively(group, ref sourcesToIgnore);

                    group.Parent.Children.Remove(group);
                    toRefresh.Add(group.Parent);
                    group.Parent = target;
                    if (target.Children.Any())
                    {
                        target.Children.Insert(0, group);
                    }
                    else
                    {
                        target.Children.Add(group);
                    }
                }

                sources = from tlvBranch s in sources where !sourcesToIgnore.Contains(s) select s;
                foreach (var source in sources)
                {
                    source.Parent.Children.Remove(source);
                    toRefresh.Add(source.Parent);
                    source.Parent = target;
                    if (index >= 0)
                    {
                        target.Children.Insert(index, source);
                    }
                    else
                    {
                        target.Children.Add(source);
                    }
                }

                toRefresh.Add(target);
                tlvGroupedFiles.Expand(target);
            }
            foreach (var item in toRefresh)
            {
                tlvGroupedFiles.RefreshObject(item);
            }
            OrganizeNode(target);
        }
Ejemplo n.º 23
0
 private void olvFiles_CanDrop(object sender, OlvDropEventArgs e)
 {
     e.Effect = DragDropEffects.Copy;
 }
Ejemplo n.º 24
0
 protected override void OnCanDrop(OlvDropEventArgs args)
 {
     base.OnCanDrop(args);
     CurrentEffect = args.Effect;
 }
Ejemplo n.º 25
0
 private void treeListFiles_Dropped(object sender, OlvDropEventArgs e)
 {
 }
Ejemplo n.º 26
0
 private new void DragDrop(object sender, OlvDropEventArgs e)
 {
     unsavedChanges = true;
     RenumberOrder();
 }
Ejemplo n.º 27
0
 private void treeListFiles_CanDrop(object sender, OlvDropEventArgs e)
 {
 }