How do I load a directory into a document-based app?

  • I'm trying to write a text editor and it all works except the saving.
    I want to load a directory the way TextMate does. It puts all of the
    files of the directory in an outline view and you can edit the files
    indivisually. I've achieved that.

    I have put an entry in Info.plist as follows:

    <dict>
      <key>CFBundleTypeExtensions</key>
      <array>
        <string></string>
      </array>
      <key>CFBundleTypeName</key>
      <string>Folder</string>
      <key>CFBundleTypeOSTypes</key>
      <array>
        <string>****</string>
      </array>
      <key>CFBundleTypeRole</key>
      <string>Editor</string>
      <key>LSTypeIsPackage</key>
      <false/>
      <key>NSDocumentClass</key>
      <string>FileEditor</string>
      </dict>

    I can use that to drop a folder onto the app's icon in the dock and it
    loads. No problem. I do have problems however when I try to save the
    files. Currently I have it save the selected file in the outline view.
    No matter how I try to save, somehow the original folder disappears
    from my hard disk! Here is my saving code:

    - (BOOL)writeToURL:(NSURL *)absoluteURL ofType:(NSString *)typeName
    error:(NSError **)outError
    {
    if (saveAll == NO)
    {
      if ([outline selectedRow] != -1)
      {
      AOTree *item = [outline itemAtRow: [outline selectedRow]];

      NSString *name = [item displayName];// stringByDeletingPathExtension];
      //name = [name stringByAppendingString: typeName];

      if ([[files objectForKey: [item path]] writeToFile: [item path]
    atomically: YES encoding: NSUTF8StringEncoding error: outError])
      {
        unsavedFileCount--;
      }
      }
    }


    if (unsavedFileCount <= 0)
    {
      [self updateChangeCount: NSChangeCleared];
    }
    else
    {
      [self updateChangeCount: NSChangeDone];
    }

    return YES;
    }

    It is not very functional, and not complete, but should save the file.
    It doesn't.

    So, how do I change the Info.plist file so that I can load directories
    but prevent them from appearing as a format in the save dialogs? My
    hope is that the only problem is the Info.plist file and that a proper
    fix will cause my troubles to cease.

    Many thanks, Alan

    --
    // Quotes from yours truly -------------------------
    "You don't forget, you just don't remember."
    "Maturity resides in the mind."
    "Silence is the Universe's greatest gift."
    "When the World realizes that religion really is unimportant, then it
    shall evolve."
  • Thanks to Uli Kusterer this specific problem has been fixed. I simply
    changed **** to fold and it works. I also found out why the folder
    kept disappearing, thanks to Uli. NSDocument deletes it because it
    thinks you're going to replace that file. It doesn't know that I want
    to save *in* that folder. It assumes that it is a file and not a
    folder. Since the folder is gone than my program can't save into it.

    I'll move this to a new thread, Alan

    --
    // Quotes from yours truly -------------------------
    "You don't forget, you just don't remember."
    "Maturity resides in the mind."
    "Silence is the Universe's greatest gift."
    "When the World realizes that religion really is unimportant, then it
    shall evolve."
previous month october 2006 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today