Storing info with text file

Discussion in 'Mac Programming' started by titaniumdecoy, Nov 17, 2007.

  1. macrumors member

    Joined:
    Oct 13, 2005
    #1
    Hi all,

    I am writing a text editor in Cocoa. I plan to implement code folding and line bookmarking. However, I cannot figure out how to store this information so that it will be available the next time the text file is opened. When using TextMate, for instance, your code folding and line bookmarks are restored when you reopen a text file even if it has been moved or renamed. How is this possible?

    Thanks.
     
  2. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Without seeing the TextMate source code I couldn't say for sure but I'd suggest they use HFS+ Extended Attributes to store the data...
     
  3. macrumors 68030

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #3
    Wow, kudos to the TextMate developer. That's pretty slick :)
     
  4. thread starter macrumors member

    Joined:
    Oct 13, 2005
    #4
    Using HFS+ attributes is a possibility, I suppose, but I have been hearing a lot about ZFS and I would rather use a more portable approach, if possible. Even so, can anyone point me to example code for manipulating HFS+ attributes? I can't seem to find anything.

    Someone suggested storing aliases as data in a file. (As I understand it, aliases can only be used with Carbon code; perhaps this has changed in 10.5?) However, this is once again beyond me and I would appreciate any pointers on how to go about implementing this. On the other hand, if I used this approach I assume I would have to iterate through each alias and compare it to the file being opened, which could take a long time.

    What is my best option?
     
  5. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #5
    There is no built in Cocoa API for this. I you end up in Carbon or worse to do it. I was trying to find the API last night but gave up.

    I can, however, confirm that text mates uses Extended Attributes for something:

    MacBook-Pro:java robbie$ xattr -l PairMatcher.java
    com.macromates.caret: {column = 49; line = 8; }

    PairMatcher.java has been edited by TextMate and as you can see has an extended attribute which matches their domain. This only appears to hold the caret position, not the folding status.

    I can't find any API other than the BSD level setxattr and getxattr.

    Note there is no issue in using these from Cocoa.
     

Share This Page