Ejemplo n.º 1
0
        /// <summary>A node has been dropped.</summary>
        /// <param name="sender">Sending object</param>
        /// <param name="e">Drop arguments</param>
        private void OnDrop(object sender, DropArgs e)
        {
            string toParentPath = e.NodePath;
            Model  toParent     = Apsim.Get(this.ApsimXFile, toParentPath) as Model;

            DragObject dragObject = e.DragObject as DragObject;

            if (dragObject != null && toParent != null)
            {
                string fromModelXml   = dragObject.Xml;
                string fromParentPath = StringUtilities.ParentName(dragObject.NodePath);

                ICommand cmd = null;
                if (e.Copied)
                {
                    this.Add(fromModelXml, toParentPath);
                }
                else if (e.Moved)
                {
                    if (fromParentPath != toParentPath)
                    {
                        Model fromModel = Apsim.Get(this.ApsimXFile, dragObject.NodePath) as Model;
                        if (fromModel != null)
                        {
                            cmd = new MoveModelCommand(fromModel, toParent, this.GetNodeDescription(fromModel), this.view);
                            CommandHistory.Add(cmd);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public bool TryGetData(IDataObject dataObject, out DropArgs output)
        {
            var data = dataObject.GetData("FileDrop") as string[];

            if (data != null)
            {
                output          = new DropArgs();
                output.FileList = data.ToList();
                return(true);
            }

            output = null;
            return(false);
        }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
0
        /// <summary>A node has been dropped.</summary>
        /// <param name="sender">Sending object</param>
        /// <param name="e">Drop arguments</param>
        private void OnDrop(object sender, DropArgs e)
        {
            try
            {
                string toParentPath = e.NodePath;
                Model  toParent     = this.ApsimXFile.FindByPath(toParentPath)?.Value as Model;

                DragObject dragObject = e.DragObject as DragObject;
                if (dragObject != null && toParent != null)
                {
                    string modelString    = dragObject.ModelString;
                    string fromParentPath = StringUtilities.ParentName(dragObject.NodePath);

                    ICommand cmd = null;
                    if (e.Moved)
                    {
                        if (fromParentPath != toParentPath)
                        {
                            Model fromModel = this.ApsimXFile.FindByPath(dragObject.NodePath)?.Value as Model;
                            if (fromModel != null)
                            {
                                cmd = new MoveModelCommand(fromModel, toParent, GetNodeDescription);
                                CommandHistory.Add(cmd);
                            }
                        }
                    }
                    else if (e.Copied)
                    {
                        var command = new AddModelCommand(toParent, modelString, GetNodeDescription);
                        CommandHistory.Add(command, true);
                    }
                    else if (e.Linked)
                    {
                        // tbi
                        MainPresenter.ShowMessage("Linked models TBI", Simulation.MessageType.Information);
                    }
                    view.Tree.ExpandChildren(toParent.FullPath, false);
                }
            }
            catch (Exception err)
            {
                MainPresenter.ShowError(err);
            }
        }
Ejemplo n.º 5
0
        public bool TryGetData(IDataObject dataObject, out DropArgs output)
        {
            var data = dataObject.GetData("Text") as string;

            if (data != null)
            {
                using (var client = new WebClient())
                {
                    var bytes = client.DownloadData(data);
                    output = new DropArgs()
                    {
                        Data         = bytes,
                        OriginalPath = data
                    };
                    return(true);
                }
            }
            output = null;
            return(false);
        }
Ejemplo n.º 6
0
        /// <summary>A node has been dropped.</summary>
        /// <param name="sender">Sending object</param>
        /// <param name="e">Drop arguments</param>
        private void OnDrop(object sender, DropArgs e)
        {
            try
            {
                string toParentPath = e.NodePath;
                Model  toParent     = Apsim.Get(this.ApsimXFile, toParentPath) as Model;

                DragObject dragObject = e.DragObject as DragObject;
                if (dragObject != null && toParent != null)
                {
                    string modelString    = dragObject.ModelString;
                    string fromParentPath = StringUtilities.ParentName(dragObject.NodePath);

                    ICommand cmd = null;
                    if (e.Copied)
                    {
                        var command = new AddModelCommand(toParentPath,
                                                          modelString,
                                                          this);
                        CommandHistory.Add(command, true);
                    }
                    else if (e.Moved)
                    {
                        if (fromParentPath != toParentPath)
                        {
                            Model fromModel = Apsim.Get(this.ApsimXFile, dragObject.NodePath) as Model;
                            if (fromModel != null)
                            {
                                cmd = new MoveModelCommand(fromModel, toParent, this.GetNodeDescription(fromModel), this);
                                CommandHistory.Add(cmd);
                            }
                        }
                    }
                }
            }
            catch (Exception err)
            {
                MainPresenter.ShowError(err);
            }
        }
Ejemplo n.º 7
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;
        }
Ejemplo n.º 8
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, DragEventArgs e)
        {
            TreeNode destinationNode = TreeView.GetNodeAt(TreeView.PointToClient(new Point(e.X, e.Y)));

            if (destinationNode != null && Droped != null)
            {
                DropArgs args = new DropArgs();
                args.NodePath = FullPath(destinationNode);

                string[] formats = e.Data.GetFormats();
                if (formats.Length > 0)
                {
                    args.DragObject = e.Data.GetData(formats[0]) as ISerializable;
                    if (e.Effect == DragDropEffects.Copy)
                    {
                        args.Copied = true;
                    }
                    else if (e.Effect == DragDropEffects.Move)
                    {
                        args.Moved = true;
                    }
                    else
                    {
                        args.Linked = true;
                    }
                    Droped(this, args);

                    // Under MONO / LINUX seem to need to deselect and reselect the node otherwise no
                    // node is selected after the drop and this causes problems later in OnTreeViewBeforeSelect
                    TreeView.SelectedNode = null;
                    TreeView.SelectedNode = destinationNode;
                }
            }

            sourcePathOfItemBeingDragged = null;
        }
Ejemplo n.º 9
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)
        {
            // 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))
            {
                AllowDropArgs Args = new AllowDropArgs();
                Args.NodePath = FullPath(path);

                Drag.GetData(treeview1, e.Context, e.Context.Targets[0], 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;
        }
Ejemplo n.º 10
0
        /// <summary>A node has been dropped.</summary>
        /// <param name="sender">Sending object</param>
        /// <param name="e">Drop arguments</param>
        private void OnDrop(object sender, DropArgs e)
        {
            string toParentPath = e.NodePath;
            Model toParent = Apsim.Get(this.ApsimXFile, toParentPath) as Model;

            DragObject dragObject = e.DragObject as DragObject;
            if (dragObject != null && toParent != null)
            {
                string fromModelXml = dragObject.Xml;
                string fromParentPath = StringUtilities.ParentName(dragObject.NodePath);

                ICommand cmd = null;
                if (e.Copied)
                    Add(fromModelXml, toParentPath);
                else if (e.Moved)
                {
                    if (fromParentPath != toParentPath)
                    {
                        Model fromModel = Apsim.Get(this.ApsimXFile, dragObject.NodePath) as Model;
                        if (fromModel != null)
                        {
                            cmd = new MoveModelCommand(fromModel, toParent);
                        }
                    }
                }

                if (cmd != null)
                {
                    CommandHistory.Add(cmd);
                }
            }
        }
Ejemplo n.º 11
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, DragEventArgs e)
        {
            TreeNode destinationNode = TreeView.GetNodeAt(TreeView.PointToClient(new Point(e.X, e.Y)));
            if (destinationNode != null && Droped != null)
            {
                DropArgs args = new DropArgs();
                args.NodePath = FullPath(destinationNode);

                string[] formats = e.Data.GetFormats();
                if (formats.Length > 0)
                {
                    args.DragObject = e.Data.GetData(formats[0]) as ISerializable;
                    if (e.Effect == DragDropEffects.Copy)
                        args.Copied = true;
                    else if (e.Effect == DragDropEffects.Move)
                        args.Moved = true;
                    else
                        args.Linked = true;
                    Droped(this, args);

                    // Under MONO / LINUX seem to need to deselect and reselect the node otherwise no
                    // node is selected after the drop and this causes problems later in OnTreeViewBeforeSelect
                    TreeView.SelectedNode = null;
                    TreeView.SelectedNode = destinationNode;
                }
            }

            sourcePathOfItemBeingDragged = null;
        }