Example #1
0
        /// <summary>Node has been dragged over another node. Allow a drop here?</summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event data.</param>
        private void OnDragOver(object sender, DragMotionArgs e)
        {
            try
            {
                // e.Effect = DragDropEffects.None;
                e.RetVal = false;
                Gdk.Drag.Status(e.Context, 0, e.Time); // Default to no drop

                Gdk.Atom target = Drag.DestFindTarget(treeview1, e.Context, null);
                // Get the drop location
                TreePath path;
                TreeIter dest;
                if (treeview1.GetPathAtPos(e.X, e.Y, out path) && treemodel.GetIter(out dest, path) &&
                    target != Gdk.Atom.Intern("GDK_NONE", false))
                {
                    AllowDropArgs args = new AllowDropArgs();
                    args.NodePath = GetFullPath(path);
                    Drag.GetData(treeview1, e.Context, target, e.Time);
                    if (dragDropData != null)
                    {
                        args.DragObject = dragDropData;
                        if (AllowDrop != null)
                        {
                            AllowDrop(this, args);
                            if (args.Allow)
                            {
                                e.RetVal = true;
                                string sourceParent = null;
                                if (sourcePathOfItemBeingDragged != null)
                                {
                                    sourceParent = StringUtilities.ParentName(sourcePathOfItemBeingDragged);
                                }

                                // Now determine the effect. If the drag originated from a different view
                                // (e.g. a toolbox or another file) then only copy is supported.
                                if (sourcePathOfItemBeingDragged == null)
                                {
                                    Gdk.Drag.Status(e.Context, Gdk.DragAction.Copy, e.Time);
                                }
                                else if (sourceParent == args.NodePath)
                                {
                                    Gdk.Drag.Status(e.Context, Gdk.DragAction.Copy, e.Time);
                                }
                                else
                                {
                                    // The "SuggestedAction" will normally be Copy, but will be Move
                                    // if shift is pressed, and Link if Ctrl-Shift is pressed
                                    Gdk.Drag.Status(e.Context, e.Context.SuggestedAction, e.Time);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception err)
            {
                ShowError(err);
            }
        }
Example #2
0
        /// <summary>Node has been dragged over another node. Allow a drop here?</summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event data.</param>
        private void OnDragOver(object sender, DragMotionArgs e)
        {
            // e.Effect = DragDropEffects.None;
            e.RetVal = false;

            // Get the drop location
            TreePath path;
            TreeIter dest;

            if (treeview1.GetPathAtPos(e.X, e.Y, out path) && treemodel.GetIter(out dest, path))
            {
                AllowDropArgs Args = new AllowDropArgs();
                Args.NodePath = FullPath(path);
                Drag.GetData(treeview1, e.Context, e.Context.Targets[0], e.Time);
                if (DragDropData != null)
                {
                    Args.DragObject = DragDropData;
                    if (AllowDrop != null)
                    {
                        AllowDrop(this, Args);
                        if (Args.Allow)
                        {
                            e.RetVal = true;
                            string SourceParent = null;
                            if (sourcePathOfItemBeingDragged != null)
                            {
                                SourceParent = StringUtilities.ParentName(sourcePathOfItemBeingDragged);
                            }

                            // Now determine the effect. If the drag originated from a different view
                            // (e.g. a toolbox or another file) then only copy is supported.
                            if (sourcePathOfItemBeingDragged == null)
                            {
                                Gdk.Drag.Status(e.Context, Gdk.DragAction.Copy, e.Time);
                            }
                            else if (SourceParent == Args.NodePath)
                            {
                                Gdk.Drag.Status(e.Context, Gdk.DragAction.Copy, e.Time);
                            }
                            else
                            {
                                // The "SuggestedAction" will normally be Copy, but will be Move
                                // if shift is pressed, and Link if Ctrl-Shift is pressed
                                Gdk.Drag.Status(e.Context, e.Context.SuggestedAction, e.Time);
                            }
                        }
                        else
                        {
                            Gdk.Drag.Status(e.Context, 0, e.Time);
                        }
                    }
                }
            }
        }
Example #3
0
    private static void HandleTargetDragDrop(object sender, DragDropArgs args)
    {
        Console.WriteLine("drop");
        have_drag = false;
        (sender as Gtk.Image).Pixbuf = trashcan_closed_pixbuf;

#if BROKEN                      // Context.Targets is not defined in the bindings
        if (Context.Targets.Length != 0)
        {
            Drag.GetData(sender, context, Context.Targets.Data as Gdk.Atom, args.Time);
            args.RetVal = true;
        }
#endif

        args.RetVal = false;
    }
Example #4
0
        /// <summary>Node has been dropped. Send to presenter.</summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event data.</param>
        private void OnDragDrop(object sender, DragDropArgs e)
        {
            try
            {
                Gdk.Atom target = Drag.DestFindTarget(treeview1, e.Context, null);
                // Get the drop location
                TreePath path;
                TreeIter dest;
                bool     success = false;
                if (treeview1.GetPathAtPos(e.X, e.Y, out path) && treemodel.GetIter(out dest, path) &&
                    target != Gdk.Atom.Intern("GDK_NONE", false))
                {
                    AllowDropArgs args = new AllowDropArgs();
                    args.NodePath = GetFullPath(path);

                    Drag.GetData(treeview1, e.Context, target, e.Time);
                    if (dragDropData != null)
                    {
                        DropArgs dropArgs = new DropArgs();
                        dropArgs.NodePath = GetFullPath(path);

                        dropArgs.DragObject = dragDropData;
                        Gdk.DragAction action = e.Context.SelectedAction;
                        if ((action & Gdk.DragAction.Move) == Gdk.DragAction.Move)
                        {
                            dropArgs.Moved = true;
                        }
                        else if ((action & Gdk.DragAction.Copy) == Gdk.DragAction.Copy)
                        {
                            dropArgs.Copied = true;
                        }
                        else
                        {
                            dropArgs.Linked = true;
                        }
                        Droped(this, dropArgs);
                        success = true;
                    }
                }
                Gtk.Drag.Finish(e.Context, success, e.Context.SelectedAction == Gdk.DragAction.Move, e.Time);
                e.RetVal = success;
            }
            catch (Exception err)
            {
                ShowError(err);
            }
        }
Example #5
0
        /// <summary>Node has been dropped. Send to presenter.</summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event data.</param>
        private void OnDragDrop(object sender, DragDropArgs e)
        {
            Gdk.Atom target = Drag.DestFindTarget(treeview1, e.Context, null);
            // Get the drop location
            TreePath path;
            TreeIter dest;
            bool     success = false;

            if (treeview1.GetPathAtPos(e.X, e.Y, out path) && treemodel.GetIter(out dest, path) &&
                target != Gdk.Atom.Intern("GDK_NONE", false))
            {
                AllowDropArgs Args = new AllowDropArgs();
                Args.NodePath = FullPath(path);

                Drag.GetData(treeview1, e.Context, target, e.Time);
                if (DragDropData != null)
                {
                    DropArgs args = new DropArgs();
                    args.NodePath = FullPath(path);

                    args.DragObject = DragDropData;
                    if (e.Context.Action == Gdk.DragAction.Copy)
                    {
                        args.Copied = true;
                    }
                    else if (e.Context.Action == Gdk.DragAction.Move)
                    {
                        args.Moved = true;
                    }
                    else
                    {
                        args.Linked = true;
                    }
                    Droped(this, args);
                    success = true;
                }
            }
            Gtk.Drag.Finish(e.Context, success, e.Context.Action == Gdk.DragAction.Move, e.Time);
            e.RetVal = success;
        }
Example #6
0
        void Treeview1_DragDrop(object o, DragDropArgs args)
        {
            args.RetVal = true;

            #if GTK3
            if (args.Context.ListTargets().Length > 0)
            {
                Drag.GetData((Widget)o, args.Context, args.Context.ListTargets()[0], args.Time);
            }
            #else
            if (args.Context.Targets.Length > 0)
            {
                Drag.GetData((Widget)o, args.Context, args.Context.Targets[0], args.Time);
            }
            #endif

            var siters = this.siters;
            this.siters = new List <TreeIter>();

            if (siters.Count == 0)
            {
                return;
            }

            TreeViewDropPosition pos;
            TreePath             path;
            TreeIter             iter;

            if (treeview1.GetDestRowAtPos(args.X, args.Y, out path, out pos))
            {
                if (!listStore.GetIter(out iter, path))
                {
                    return;
                }
            }
            else
            {
                iter = GetBaseIter();
                pos  = TreeViewDropPosition.IntoOrAfter;
            }

            if (treeview1.Model.GetValue(iter, 2).ToString() == ID_FILE)
            {
                if (pos == TreeViewDropPosition.IntoOrBefore || pos == TreeViewDropPosition.Before)
                {
                    pos = TreeViewDropPosition.Before;
                }
                else
                {
                    pos = TreeViewDropPosition.After;
                }
            }

            if (pos == TreeViewDropPosition.After || pos == TreeViewDropPosition.Before)
            {
                if (!treeview1.Model.IterParent(out iter, iter))
                {
                    return;
                }
            }

            string dest_folder = (iter.Equals(GetBaseIter())) ? "" : GetPathFromIter(iter) + "/";

            List <string>   sourcedata = new List <string>();
            List <string>   destdata   = new List <string>();
            List <FileType> types      = new List <FileType>();

            foreach (var si in siters)
            {
                string spath = GetPathFromIter(si);
                string dpath = dest_folder + System.IO.Path.GetFileName(spath);

                sourcedata.Add(spath);
                destdata.Add(dpath);

                types.Add((treeview1.Model.GetValue(si, 2).ToString() == ID_FILE) ? FileType.File : FileType.Folder);
            }

            window._controller.Move(sourcedata.ToArray(), destdata.ToArray(), types.ToArray());
            window.UpdateMenus();
        }