Results 1 to 3 of 3

Thread: File system: Implementing Cut and Paste

  1. #1
    Join Date
    Jun 2008
    Posts
    88
    Thanks
    4
    Thanked 4 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11
    Wiki edits
    1

    Default File system: Implementing Cut and Paste

    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?

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: File system: Implementing Cut and Paste

    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
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Jun 2008
    Posts
    88
    Thanks
    4
    Thanked 4 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11
    Wiki edits
    1

    Default Re: File system: Implementing Cut and Paste

    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.

    Qt Code:
    1. data << "cut" << "\n" << pathlist;
    2. mimdata.setData("x-special/gnome-copied-files", data);
    To copy to clipboard, switch view to plain text mode 

    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

    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).

Similar Threads

  1. System File Association
    By johnmauer in forum Qt Programming
    Replies: 5
    Last Post: 10th November 2010, 22:35
  2. Replies: 0
    Last Post: 12th April 2010, 07:05
  3. How to get system associated icon for any file
    By rittchat in forum Qt Programming
    Replies: 0
    Last Post: 15th December 2009, 04:16
  4. Creating a form.ui by a Designer + implementing to .cpp file
    By thewooferbbk in forum Qt Programming
    Replies: 1
    Last Post: 25th March 2009, 08:25
  5. copy and run a .exe file in another system
    By sabeesh in forum Installation and Deployment
    Replies: 3
    Last Post: 22nd August 2007, 10:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.