Package-based document trouble

Discussion in 'Mac Programming' started by Starfox, Jun 6, 2012.

  1. Starfox macrumors 6502


    Apr 7, 2011
    I'm trying my hand at making a package-based document app, and I'm struggling with some things. I'm using a file wrapper, and one of the things I want to do is enable the user to edit other documents that they drag into my document - allow me to explain.

    Imagine a word editing kind of app where the user drags an image into the document - in my case whenever the user drags a file that be embedded in my document, I create a new file wrapper for it. Now I want to enable the user to, say, open that image they dragged in Pixelmator or Photoshop, edit it a little, then save it with the changes immediately reflected in my document. How do I do that?

    In case that matters, the actual use case has my user dragging some Collada, Blender and Lua scripting files that I want them to be able to open in preferred editor then save with changes reflected immediately in the document in my app.

    Any pointers / ideas on the right way to do this? I'm familiar with C/C++ but I'm new to Mac programming so I might be missing some obvious way to do this.
  2. robbieduncan Moderator emeritus


    Jul 24, 2002
    Opening the documents in external editors should not be too bad. You have two (at least) choices here:

    1) Get the external editor to open file to be edited by opening the file inside your file wrapper

    2) Copy the file to temp and then open it there

    Personally I'd go with 2). In the case of 1) if the external editor corrupts the file you loose the copy in your file wrapper.

    As for detecting saves you can use the FSEvent API to monitor the folder the file is in for changes. Maintain an internal state of last modified time for each file in there and you can quickly check which has changed and reload it.

Share This Page