Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows Forms
  4. How to tell "cut" from "copy" upon pasting

How to tell "cut" from "copy" upon pasting

Scheduled Pinned Locked Moved Windows Forms
questiondata-structureshelptutorial
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    michalJ
    wrote on last edited by
    #1

    I'm developing a program that acts like file manager. Obviously it has to be able to cut/copy/paste files. When i cut and later paste within my application, I can set a flag that it was a >cut< operation and the files after being copied to destination should be removed from source location. However, if I am to cut/paste between my app and some external file manager (e.g. Windows Explorer) how can I (my program) tell whether it was >cut< selected, (not a >copy< operation) in the other application ? (also, what to put into clipboard when selecting cut from menu, so that the other application that will paste, would remove files after copying them to destination) ? Currently I'm using FileDrop type with String array of paths. But how can be encoded >cut< operation ? (some additional format, marker,..?) Thanks for help, Michal

    L 1 Reply Last reply
    0
    • M michalJ

      I'm developing a program that acts like file manager. Obviously it has to be able to cut/copy/paste files. When i cut and later paste within my application, I can set a flag that it was a >cut< operation and the files after being copied to destination should be removed from source location. However, if I am to cut/paste between my app and some external file manager (e.g. Windows Explorer) how can I (my program) tell whether it was >cut< selected, (not a >copy< operation) in the other application ? (also, what to put into clipboard when selecting cut from menu, so that the other application that will paste, would remove files after copying them to destination) ? Currently I'm using FileDrop type with String array of paths. But how can be encoded >cut< operation ? (some additional format, marker,..?) Thanks for help, Michal

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Most programs work like this: Cut/Copy/Delete is what happens on the source side; the steps are: 1. if not delete: copy selection to Clipboard 2. if not copy: delete selection THEN, on the destination side, a potential Paste pastes what is on the Clipboard to the current position, replacing/deleting whatever was selected there if anything. Now Windows Explorer acts differently: Cut dims the selection but does not delete it until it has been copied somewhere in some Explorer window, and I don't know how they do that. I can come up with ways to achieve that, within a single program, however I don't know which way MS has chosen. I expect there must be a message going back from destination to source to confirm the pasting is done, so the cutting should now be finalized. :)

      Luc Pattyn


      Local announcement (Antwerp region): Lange Wapper? Neen!


      M 1 Reply Last reply
      0
      • L Luc Pattyn

        Most programs work like this: Cut/Copy/Delete is what happens on the source side; the steps are: 1. if not delete: copy selection to Clipboard 2. if not copy: delete selection THEN, on the destination side, a potential Paste pastes what is on the Clipboard to the current position, replacing/deleting whatever was selected there if anything. Now Windows Explorer acts differently: Cut dims the selection but does not delete it until it has been copied somewhere in some Explorer window, and I don't know how they do that. I can come up with ways to achieve that, within a single program, however I don't know which way MS has chosen. I expect there must be a message going back from destination to source to confirm the pasting is done, so the cutting should now be finalized. :)

        Luc Pattyn


        Local announcement (Antwerp region): Lange Wapper? Neen!


        M Offline
        M Offline
        michalJ
        wrote on last edited by
        #3

        I'm trying to achive the same thing as explorer does and I think that there must be something else placed in clipboard (upon cuting, which results in imediate dimming items) that tells how pasting application should tread source files (leave intact or delete) upon completing paste operation. Thanks, Michal

        M 1 Reply Last reply
        0
        • M michalJ

          I'm trying to achive the same thing as explorer does and I think that there must be something else placed in clipboard (upon cuting, which results in imediate dimming items) that tells how pasting application should tread source files (leave intact or delete) upon completing paste operation. Thanks, Michal

          M Offline
          M Offline
          michalJ
          wrote on last edited by
          #4

          I guess I know now. It is a memory stream that is placed in Clipboard that tell whether to cut or copy only

          const String PREFFERED_DROP_EFFECT_SHELL_CONSTANT = "Preferred DropEffect";
          private bool IsItCutOperation(IDataObject dataObject)
          {
          Object isCutOperationMS = dataObject.GetData(PREFFERED_DROP_EFFECT_SHELL_CONSTANT) as MemoryStream;
          if (isCutOperationMS == null)
          return false;

                  MemoryStream ms = isCutOperationMS as MemoryStream;
          
                  byte\[\] array = new byte\[ms.Length\];
                  ms.Read(array, 0, (int)ms.Length);
                  
                  if(array\[0\] == (byte)(2))   // 5 copy, 2 cut 
                  {
                      return true;
                  }
          
                  return false;
              }
          

          Thanks, Michal

          L 1 Reply Last reply
          0
          • M michalJ

            I guess I know now. It is a memory stream that is placed in Clipboard that tell whether to cut or copy only

            const String PREFFERED_DROP_EFFECT_SHELL_CONSTANT = "Preferred DropEffect";
            private bool IsItCutOperation(IDataObject dataObject)
            {
            Object isCutOperationMS = dataObject.GetData(PREFFERED_DROP_EFFECT_SHELL_CONSTANT) as MemoryStream;
            if (isCutOperationMS == null)
            return false;

                    MemoryStream ms = isCutOperationMS as MemoryStream;
            
                    byte\[\] array = new byte\[ms.Length\];
                    ms.Read(array, 0, (int)ms.Length);
                    
                    if(array\[0\] == (byte)(2))   // 5 copy, 2 cut 
                    {
                        return true;
                    }
            
                    return false;
                }
            

            Thanks, Michal

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            do you have any link or reference to such wisdom. You did not invent this yourself, did you? TIA

            Luc Pattyn


            Local announcement (Antwerp region): Lange Wapper? Neen!


            M 1 Reply Last reply
            0
            • L Luc Pattyn

              do you have any link or reference to such wisdom. You did not invent this yourself, did you? TIA

              Luc Pattyn


              Local announcement (Antwerp region): Lange Wapper? Neen!


              M Offline
              M Offline
              michalJ
              wrote on last edited by
              #6

              Drag and drop, cut/copy and paste files with Windows Explorer[^] I've found a code snippet in this article, and changed it a little to fit my needs. Regards, Michal

              L 1 Reply Last reply
              0
              • M michalJ

                Drag and drop, cut/copy and paste files with Windows Explorer[^] I've found a code snippet in this article, and changed it a little to fit my needs. Regards, Michal

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #7

                Thanks, :)

                Luc Pattyn


                Local announcement (Antwerp region): Lange Wapper? Neen!


                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups