Copy,Cut,Paste

Developer
May 8, 2013 at 5:42 AM
I am trying to work with the editing commands (Copy,Cut and Paste) Bust I don`t know how can I do?

Any help would be appreciated.
Developer
May 26, 2013 at 12:18 PM
Hi Every body

I find out how should I do:
     public virtual Controller Controller
        {
            get
            {
                return _controller;
            }
            set
            {
                if (value == null) throw new ArgumentNullException();

                _controller = value;
                _controller.Model = this.Model;
                _controller.AllowRedo = _controller.AllowUndo = true;
            }
        }
   public virtual ClipboardCommand ClipboardCommand
        {
            get { return _clipboardCommand; }
            set
            {
                if (value == null) throw new ArgumentException();
                _clipboardCommand = value;
            }
        }
  
  public bool Copy()
        {
            ClipboardCommand.CommandText = "copy";
            Controller.Model.Elements.SetModifiable(true);
            ClipboardCommand.Shapes = Controller.Model.SelectedShapes();
            ClipboardCommand.Lines = Controller.Model.SelectedLines();
            ClipboardCommand.Execute();
            return true;
        }

        public bool Paste()
        {
            ClipboardCommand.CommandText = "paste";
            Controller.Model.Elements.SetModifiable(true);
            ClipboardCommand.Shapes = Controller.Model.SelectedShapes();
            ClipboardCommand.Lines = Controller.Model.SelectedLines();
            ClipboardCommand.Location = _currentLocation;
            ClipboardCommand.Execute();
            return true;
        }

        public bool Delete()
        {
            ClipboardCommand.CommandText = "delete";
            Controller.Model.Elements.SetModifiable(true);
            ClipboardCommand.Shapes = Controller.Model.SelectedShapes();
            ClipboardCommand.Lines = Controller.Model.SelectedLines();
            ClipboardCommand.Execute();
            return true;
        }

        public bool Cut()
        {
            ClipboardCommand.CommandText = "cut";
            Controller.Model.Elements.SetModifiable(true);
            ClipboardCommand.Shapes = Controller.Model.SelectedShapes();
            ClipboardCommand.Lines = Controller.Model.SelectedLines();
            ClipboardCommand.Execute();
            return true;    
        }
Best Regards.
Aug 16, 2013 at 10:49 PM
I'm trying to delete a shape just after selecting it, so after getting the selected shape
i try to delete it just with that way but i get some error in the ModelMomento's class
here is my code thank you for giving a hand ^^

Shapes shapes = diagram1.Model.SelectedShapes();
ClipboardCommand command = new ClipboardCommand(diagram1.Controller);
command.CommandText = "delete";
diagram1.Controller.Model.Elements.SetModifiable(true);
command.Shapes = diagram1.Controller.Model.SelectedShapes();
command.Lines = diagram1.Controller.Model.SelectedLines();
command.Execute();
Developer
Aug 19, 2013 at 7:17 AM
could you tell me how should I guess some error !!!!!!!!

please tell me what is error exactly. additional check this code :
      public bool Copy()
        {
            if (Controller.Model.SelectedShapes().Count > 0 || Controller.Model.SelectedLines().Count > 0)
            {
                ClipboardCommand.CommandText = "copy";
                Controller.Model.Elements.SetModifiable(true);
                ClipboardCommand.Shapes = Controller.Model.SelectedShapes();
                ClipboardCommand.Lines = Controller.Model.SelectedLines();
                ClipboardCommand.Execute();
                return true;
            }
            return false;
        }

        public bool Paste()
        {
            if (Controller.Model.SelectedShapes().Count > 0 || Controller.Model.SelectedLines().Count > 0)
            {
                ClipboardCommand.CommandText = "paste";
                Controller.Model.Elements.SetModifiable(true);
                ClipboardCommand.Shapes = Controller.Model.SelectedShapes();
                ClipboardCommand.Lines = Controller.Model.SelectedLines();
                ClipboardCommand.Location = _currentLocation;
                ClipboardCommand.Execute();
                return true;
            }
            return false;
        }
Aug 19, 2013 at 9:14 AM
Thank you for replying
the error is in creating the ClipboardCommand's instance
ClipboardCommand command = new ClipboardCommand(diagram1.Controller); 
it returns a NullReferenceException in the void WriteItem(Model item) method
while the instruction item.SetSize(_newModel.Size);
because the _newModel is not instantiated.

This is my first project with MVC, but it would be very kind of you if you can give me a full example about using the ClipboardCommand

Cheers