License file in Document Architecture

  • I have a program that uses the document architecture to manage
    multiple NSDocument subclasses (DQDocument). I just added the ability
    for it to read a license file (double-click support from the Finder)
    by adding another subclass (DQLicense) but I've had to use some
    workarounds to keep this method happy. I had to subclass
    NSDocumentController to keep the license file out of the recent file
    list and I've had to add a nib to quiet a warning. Now I'm finding
    that it sees this document as open still and I'll have to add one
    more workaround.

    Is this the best way to handle opening a file that is not actually
    used in the program as a primary NSDocument?

    Peace,
    Kevin Hoctor
    No Thirst Software
    http://nothirst.com
  • Is there some specific reason you need to open your license file
    as a document, using the Cocoa document architecture? If not, then
    avoid the hassle of short-circuiting time-tested Cocoa mechanisms and
    load your license information as part of your preferences or in your
    app delegate when your app launches (say, in the -
    applicationDidFinishLaunching: delegate method).

      You can accomplish this with NSData and NSString (whichever is
    appropriate for the format of your license file). Use NSString's
    +stringWithContentsOfFile: or NSData's +dataWithContentsOfFile: to
    read in the file's contents and manipulate it as necessary.

      The details for all the classes and their methods are easily found
    in the docs and I thin you'll find this approach a *lot* easier .

    --
    I.S.

    On Oct 26, 2006, at 10:28 AM, Kevin Hoctor wrote:

    > I have a program that uses the document architecture to manage
    > multiple NSDocument subclasses (DQDocument). I just added the
    > ability for it to read a license file (double-click support from
    > the Finder) by adding another subclass (DQLicense) but I've had to
    > use some workarounds to keep this method happy. I had to subclass
    > NSDocumentController to keep the license file out of the recent
    > file list and I've had to add a nib to quiet a warning. Now I'm
    > finding that it sees this document as open still and I'll have to
    > add one more workaround.
    >
    > Is this the best way to handle opening a file that is not actually
    > used in the program as a primary NSDocument?
    >
    > Peace,
    > Kevin Hoctor
    > No Thirst Software
    > http://nothirst.com
    >
    >
    >
    > _______________________________________________
    > Do not post admin requests to the list. They will be ignored.
    > Cocoa-dev mailing list      (<Cocoa-dev...>)
    > Help/Unsubscribe/Update your Subscription:
    > http://lists.apple.com/mailman/options/cocoa-dev/idiotsavant2005%
    > 40gmail.com
    >
    > This email sent to <idiotsavant2005...>
  • On Oct 26, 2006, at 10:41 AM, I. Savant wrote:

    > Is there some specific reason you need to open your license file
    > as a document, using the Cocoa document architecture?

    Yes, I want the user to be able to open the license file from the e-
    mail or from the finder and have it associated with my application.
    The only way I could figure out to handle this is to set the
    CFBundleTypeExtensions in my Info.plist and handle this document with
    another subclass. It works and it's not that much work, but if there
    is a more "proper" way, I'd like to learn it.

    I do store the license data in the preferences after this initial
    action and load it from there. It's only the initial loading of the
    license file that is handled via the document architecture.

    Kevin Hoctor
    No Thirst Software
    http://nothirst.com
  • The trick is to add something like this method to your app delegate:

    - (BOOL)application:(NSApplication *)theApplication openFile:(NSString
    *)filename
    {
    if ([[filename pathExtension] isEqualToString: LICENSE_EXTENSION])
    {
      [self installLicense:filename];
    }
    else
    {
      [[NSDocumentController sharedDocumentController]
    openDocumentWithContentsOfFile:pathName display:YES];
    }
    return YES;
    }

    On 10/26/06, Kevin Hoctor <kevin...> wrote:
    > On Oct 26, 2006, at 10:41 AM, I. Savant wrote:
    >
    >> Is there some specific reason you need to open your license file
    >> as a document, using the Cocoa document architecture?
    >
    > Yes, I want the user to be able to open the license file from the e-
    > mail or from the finder and have it associated with my application.
    > The only way I could figure out to handle this is to set the
    > CFBundleTypeExtensions in my Info.plist and handle this document with
    > another subclass. It works and it's not that much work, but if there
    > is a more "proper" way, I'd like to learn it.
    >
    > I do store the license data in the preferences after this initial
    > action and load it from there. It's only the initial loading of the
    > license file that is handled via the document architecture.
    >
    > Kevin Hoctor
    > No Thirst Software
    > http://nothirst.com
    >
    --
    Mark Munz
    unmarked software
    http://www.unmarked.com/
  • On Oct 26, 2006, at 11:18 AM, Mark Munz wrote:

    > - (BOOL)application:(NSApplication *)theApplication openFile:
    > (NSString *)filename

    Mark, isn't this call for my application to send a file to the Finder
    for opening by the default application? I want the opposite. When a
    user double-clicks on a Debt Quencher License file (.dqlic), it
    should trigger my app to read the file (which it does now
    successfully via a DQLicense subclass of NSDocument).

    Kevin Hoctor
    No Thirst Software
    http://nothirst.com
  • No, This is a delegate method that gets called when your app should open a file.

    > From Apple docs:

    Tells the delegate to open a single file.

    - (BOOL)application:(NSApplication *)theApplication openFile:(NSString
    *)filename

    Sent directly by theApplication to the delegate. The method should
    open the file filename, returning YES if the file is successfully
    opened, and NO otherwise.

    I believe that if you don't intercept this, the NSDocumentController
    is called to open the file.

    On 10/26/06, Kevin Hoctor <kevin...> wrote:
    >
    > On Oct 26, 2006, at 11:18 AM, Mark Munz wrote:
    >
    >> - (BOOL)application:(NSApplication *)theApplication openFile:
    >> (NSString *)filename
    >
    > Mark, isn't this call for my application to send a file to the Finder
    > for opening by the default application? I want the opposite. When a
    > user double-clicks on a Debt Quencher License file (.dqlic), it
    > should trigger my app to read the file (which it does now
    > successfully via a DQLicense subclass of NSDocument).
    >
    > Kevin Hoctor
    > No Thirst Software
    > http://nothirst.com
    >
    >
    >
    >

    --
    Mark Munz
    unmarked software
    http://www.unmarked.com/
  • On Oct 26, 2006, at 11:34 AM, Mark Munz wrote:

    > From Apple docs:
    >
    > Tells the delegate to open a single file.

    Ah... I was looking at the NSWorkspace version of this call. I'll try
    your method and see if that cleans up my app a bit. Thanks!

    Kevin Hoctor
    No Thirst Software
    http://nothirst.com
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