0

I'm working on a program in which I want to add the possibility of copy-pasting (or cut-pasting) files. I could create it so it only works within the program, but it would be nicer if I could use the system-wide clipboard. That has one huge problem though: when pasting I don't know if files are copied or cut from the system explorer, I only get the file locations.

I am using Java and the javafx clipboard. Some sample code:

Clipboard clipboard = Clipboard.getSystemClipboard();
List<File> files = clipboard.getFiles();

// destDir is a File, the target directory.
for (File oldFile : files) {
    if (oldFile.isDirectory()) {
        FileUtils.copyDirectoryToDirectory(oldFile, destDir);
    } else {
        FileUtils.copyFileToDirectory(oldFile, destDir);
    }
}

Here I simply copy the files, but how do I for example know when to use FileUtils.copyDirectoryToDirectory and when to use FileUtils.moveDirectoryToDirectory (aka copy or cut)?

Thanks,
Luca

Luca_Scorpion
  • 371
  • 4
  • 15
  • 1
    You can't. Clipboard will only give you paths or - in general - data. You could add Buttons to your Dialog for "Cut" or "Copy". You may also be interested in [Drag&Drop](http://docs.oracle.com/javafx/2/drag_drop/jfxpub-drag_drop.htm) – Fildor Dec 07 '15 at 12:29
  • Not sure if `DragBoard` yields a valid value for the TransferMode when using ctrl+c/ctrl+v etc. – Fildor Dec 07 '15 at 12:35
  • @Fildor The system clipboard unfortunately does not have a TransferMode... Drag and drop may indeed be a better option for moving files from the program to the explorer and vice versa. Thanks! – Luca_Scorpion Dec 07 '15 at 13:25

1 Answers1

0

Turns out, as pointed out by Fildor , that this is only possible when using drag and drop with the Dragboard. The Clipboard does not have such functionality.

Luca_Scorpion
  • 371
  • 4
  • 15