PDA

View Full Version : File system: Implementing Cut and Paste



chezifresh
22nd October 2011, 00:52
I'm creating a directory browser for browsing the file system. I'd like it to act much like other directory browsers you've used. However, I ran into a interesting problem.

How do you implement Cut?

Seems simple enough right? Copy the path to the clipboard, but what happens when the user pastes it to their desktop? Do I watch the QClipboard for changes and delete the file if I detect it was pasted? Will the desktop environment take care of it for me and all I have to do is watch for the file to disappear from the directory? That seems the most likely, but how do I tell the desktop environment that its a cut and not a copy?

Similarly, I'm curious how paste would work if the user 'Cut' a file on their desktop and pasted it into my widget. Any ideas?

amleto
22nd October 2011, 22:15
You need to specify your expected behaviour. I think I understand that you want a user to be able to 'cut' from your browser, and select some O/S window and then paste. At which point your program must implement the file/folder move. Is this right?

What do you expect to happen when a user cuts from O/S and pastes to your widget?

First, you must tell us what you want, before we can help with how

chezifresh
28th October 2011, 19:00
I'd expect it to work like a normal file browser. If you cut from my widget, and paste on the desktop, the item should disappear from my widget and appear on the desktop and vice versa. I found out how to do this in Gnome by setting a special mimetype on my QMimeData.


QByteArray data;
data << "cut" << "\n" << pathlist;
mimdata.setData("x-special/gnome-copied-files", data);

I found this in the Qt documentation with a myriad of other caveats http://doc.qt.nokia.com/latest/qclipboard.html#notes-for-x11-users
(http://doc.qt.nokia.com/latest/qclipboard.html#notes-for-x11-users)
It could be that the QClipboard is completely inadequate to handle this. The detailed description says
The clipboard offers a simple mechanism to copy and paste data between applications. No mention of cut.

Using the gnome specific implementation, you can simply setup a QFileSystemWatcher on the cut file, once it changes/moves you remove it from your view, but its up to the desktop environment to do the move. Likewise on gnome, my widget would have to watch the clipboard for the same mimetype and I would have to handle the move. The desktop environment would then be responsible for watching when the file moved.

Now that I pieced that together, I need to figure out the other platform specific ways of handling CUT and PASTE. So, I'm not sure how to accomplish this on OSX (or for that matter, Windows, but I'm not targeting Windows).