• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Core Data and Document Packages
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Core Data and Document Packages


  • Subject: Re: Core Data and Document Packages
  • From: sergio <email@hidden>
  • Date: Fri, 13 Jul 2007 14:45:05 +0200

Hi Tim,

> I found the problem in my code, so now it saves, save as etc etc and  
> re-opens :)

very good! :-)

> I followed your example but in my recent menu items i still see  
> "data.xml" - im guessing I need to write some code to strip off the "/
> data.xml" part of the url string in  
> NSDocumentController::packageURLFromDataStoreURL(url) ?
>
> Are you just using some kind of string manipulation to do that?

in ruby string manipulation is the most straightforward way to
accomplish what is needed.

class MyDocumentController < OSX::NSDocumentController

  def init
    super_init
  end

  def packageURLFromDataStoreURL(url)
    OSX::NSURL.fileURLWithPath(url.relativePath.gsub(/data.xml$/, ''))
  end

  def noteNewRecentDocumentURL(url)
    super_noteNewRecentDocumentURL(packageURLFromDataStoreURL(url))
  end

end

you'll also need to fix the window title (or else it will always show
"data.xml"). there are several ways to do that. I think that the correct
one is subclassing NSWindowController, but overriding
NSDocument#displayName will do as well. here the second approach is
shown.

class MyDocument < OSX::NSPersistentDocument

...

  def displayName
    if (fileURL)
      documentNameFromDataStoreURL(fileURL)
    else
      'Untitled'  #-- never executed, but just to be safe...
    end
  end

  def documentNameFromDataStoreURL(url)
    /([^\/]+)\/?$/ =~ url.relativePath.gsub(/data.xml$/, '')
    $1 + " - Table View"
  end

  def dataStoreURLFromPackageURL(url)
      OSX::NSURL.fileURLWithPath(url.relativePath.stringByAppendingPathComponent('data.xml'))
  end

...

end


sergio

--
GMX FreeMail: 1 GB Postfach, 5 E-Mail-Adressen, 10 Free SMS.
Alle Infos und kostenlose Anmeldung: http://www.gmx.net/de/go/freemail
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Core Data and Document Packages
      • From: Tim Perrett <email@hidden>
  • Prev by Date: Re: Quirks when using drag and drop to Apple Mail
  • Next by Date: Re: iCal Sync Schema Recurrence Implementation
  • Previous by thread: Re: Core Data and Document Packages
  • Next by thread: Re: Core Data and Document Packages
  • Index(es):
    • Date
    • Thread