Professional Web Applications Themes

Allow openPanel to choose folders in Cocoa doent-based application? - Mac Programming

I am trying to figure out the best way to force the open panel of a Cocoa doent-based application to allow selection of folders. In some situations the doent model I use can be constructed from the contents of a Folder, and I would like to allow users to select a folder. Validation of the contents (to see if they in fact form a doent) would be done in an NSDoent subclass method. I realize I could subclass NSDoentController, and implement my own version of openDoent, but am wondering if this is the best way (seems a lot to subclass ...

  1. #1

    Default Allow openPanel to choose folders in Cocoa doent-based application?

    I am trying to figure out the best way to force the open panel of a
    Cocoa doent-based application to allow selection of folders. In some
    situations the doent model I use can be constructed from the contents
    of a Folder, and I would like to allow users to select a folder.
    Validation of the contents (to see if they in fact form a doent)
    would be done in an NSDoent subclass method.

    I realize I could subclass NSDoentController, and implement my own
    version of openDoent, but am wondering if this is the best way (seems
    a lot to subclass a major class just to override one GUI default).

    Thanks for any suggestions,

    ER
    Eric Raas Guest

  2. #2

    Default Re: Allow openPanel to choose folders in Cocoa doent-based application?

    Eric Raas <foobar.net> wrote in message news:<20030918141918883-0400nntp.mgh.harvard.edu>...
    > I am trying to figure out the best way to force the open panel of a
    > Cocoa doent-based application to allow selection of folders. In some
    > situations the doent model I use can be constructed from the contents
    > of a Folder, and I would like to allow users to select a folder.
    > Validation of the contents (to see if they in fact form a doent)
    > would be done in an NSDoent subclass method.
    [openPanel setCanChooseDirectories:YES];

    assuming that openPanel is your openPanel.
    Eric Pepke Guest

  3. #3

    Default Re: Allow openPanel to choose folders in Cocoa doent-basedapplication?

    In <ef37f531.0309201842.1de8450posting.google.com> Eric Pepke wrote:
    > Eric Raas <foobar.net> wrote in message news:<20030918141918883-0400
    > nntp.mgh.harvard.edu>...
    >> I am trying to figure out the best way to force the open panel of a
    >> Cocoa doent-based application to allow selection of folders. In
    >> some situations the doent model I use can be constructed from the
    >> contents of a Folder, and I would like to allow users to select a
    >> folder. Validation of the contents (to see if they in fact form a
    >> doent) would be done in an NSDoent subclass method.
    >
    > [openPanel setCanChooseDirectories:YES];
    >
    > assuming that openPanel is your openPanel.
    >
    Thanks - I have used setCanChooseDirectories:YES in the past when I have
    launched an openPanel outside of the Cocoa doent framework. What I
    am wondering is where this operation should go in a Doent-based app (
    in an NSDoent method? in an override of NSDoentController?)

    ER
    Eric Raas Guest

  4. #4

    Default Re: Allow openPanel to choose folders in Cocoa doent-based application?

    Eric Raas <foobar.net> wrote in message news:<20030921104429426-0400news.verizon.net>...
    > Thanks - I have used setCanChooseDirectories:YES in the past when I have
    > launched an openPanel outside of the Cocoa doent framework. What I
    > am wondering is where this operation should go in a Doent-based app (
    > in an NSDoent method? in an override of NSDoentController?)
    TIMTOWTDI, but I put it in a custom subclass NSDoentController,
    which I just put in the main nib file. The system seems magically
    to know to use that one.
    Eric Pepke Guest

  5. #5

    Default Re: Allow openPanel to choose folders in Cocoa doent-based application?

    In article <ef37f531.0309221906.7f987624posting.google.com >,
    [email]epepkeacm.org[/email] (Eric Pepke) wrote:
    > Eric Raas <foobar.net> wrote in message
    > news:<20030921104429426-0400news.verizon.net>...
    > > Thanks - I have used setCanChooseDirectories:YES in the past when I have
    > > launched an openPanel outside of the Cocoa doent framework. What I
    > > am wondering is where this operation should go in a Doent-based app (
    > > in an NSDoent method? in an override of NSDoentController?)
    >
    > TIMTOWTDI, but I put it in a custom subclass NSDoentController,
    > which I just put in the main nib file. The system seems magically
    > to know to use that one.
    What does "TIMTOWTDI" mean? I've seen a lot of this kind of
    abbreviation, but this one's new on me.

    --
    Tom "Tom" Harrington
    Macaroni, Automated System Maintenance for Mac OS X.
    Version 1.4: Best cleanup yet, gets files other tools miss.
    See [url]http://www.atomicbird.com/[/url]
    Tom Harrington Guest

  6. #6

    Default Re: Allow openPanel to choose folders in Cocoa doent-based application?

    Tom Harrington <tphpcisys.no.spam.dammit.net> wrote:
    > What does "TIMTOWTDI" mean? I've seen a lot of this kind of
    > abbreviation, but this one's new on me
    You could easily learn what this abbreviation means just by typing it
    into Google. Not that you'd have to use Google particularly; there is
    more than one way to do it, I'm certain. Heck, just reading this note
    carefully might tell you the answer. One way or another, though, wasting
    bandwidth here is just utterly needless. m.

    --
    matt neuburg, phd = [email]matttidbits.com[/email], [url]http://www.tidbits.com/matt/[/url]
    Read TidBITS! It's free and smart. [url]http://www.tidbits.com[/url]
    matt neuburg Guest

  7. #7

    Default Re: Allow openPanel to choose folders in Cocoa doent-based application?

    > > Thanks - I have used setCanChooseDirectories:YES in the past when I have 
    >
    > TIMTOWTDI, but I put it in a custom subclass NSDoentController,
    > which I just put in the main nib file. The system seems magically
    > to know to use that one.[/ref]

    I finally got round to playing with this, and found that it got tricky
    to retain the correct doent type restrictions with my custom
    openPanel. This is because I use separate subclasses of my main
    NSDoent subclass to handle file-format-specific tasks. For this
    reason, running the open panel like this:

    int result = [myOpenPanel runModalForDirectory:nil file:nil
    types:[MyDoent readableTypes]];

    does not recognize my types because MyDoent itself does not have
    any doent types associated with it. It now becomes necessary to
    dig out the classes and find the types - which seems possible using

    [[NSBundle mainBundle]
    objectForInfoDictionaryKey:"CFBundleDoentTypes "]

    However this turns into a bunch of work just to get the Open button to
    light up when you've selected a folder... NSDoent does a lot for
    you! Does anyone know exactly what is done in the NSDoent
    implementation of openDoent? Is the source of this available?
    Eric Guest

  8. #8

    Default Re: Allow openPanel to choose folders in Cocoa doent-based application?

    > I finally got round to playing with this, and found that it got tricky 

    Here is code that seems to generate an NSArray of file extensions that
    will work with [openPanel runModalForDirectory:file:types:]

    // Returns list of doent extensions that we can handle
    -(NSArray*)getDoentTypes {

    // Get list of types
    NSArray *theTypes = [[NSBundle mainBundle]
    objectForInfoDictionaryKey:"CFBundleDoentTypes "];

    // Loop over types, adding to list
    NSEnumerator *en = [theTypes objectEnumerator];
    id nextType;

    // The list
    NSMutableArray *typeNames = [NSMutableArray array];

    while (nextType = [en nextObject]) {
    [typeNames addObjectsFromArray:[nextType
    objectForKey:"CFBundleTypeExtensions"]];
    }

    return (NSArrray*)typeNames;

    }
    Eric Guest

  9. #9

    Default Shift-drag breaks in Cocoa app under Panther


    In today's experimentation with Panther I noticed that in a Cocoa app
    I've been writing a shift-drag functionality I'd implemented no longer
    works. I used modifier keys like Shift and Option to change the
    behaviour of clicking and dragging operations.

    This was done using the following sort of approach:

    -(void)mouseDown:(NSEvent *)theEvent {

    if ([theEvent modifierFlags] == NSShiftKeyMask) {
    // Do one thing...
    else if ([theEvent modifierFlags] == NSCommandKeyMask) {
    // Do another...
    } } else {
    // Do something else
    } }

    Anyone have an idea why this would stop working? Maybe there are new
    keyboard shortcuts that interact?? Other than this all seems great...

    Will probably spend the weekend figuring out Xcode... need to find some
    good docs on migrating from PB



    Eric Guest

  10. #10

    Default Re: Shift-drag breaks in Cocoa app under Panther

    In article <verizon.net>,
    Eric Raas <net> wrote:
     

    This is covered in the release notes for Cocoa, I believe. Your method
    for checking for the shift key is incorrect, since it fails if there are
    other flags set. Under Panther, NSEvent has the possibility of setting
    certain device-specific flags. So change your code to look something
    like this:

    if([theEvent modifierFlags] & NSShiftKeyMask) { ... }

    This will however catch any event with the shift key held down, even if
    other modifiers are held down as well. Another strategy could be:

    int modifiers = [theEvent modifierFlags] & (NSShiftKeyMask |
    NSCommandKeyMask | NSAlternateKeyMask | ...put others here...);

    Then check modifiers as you do above; you'll miss the device-specific
    flags this way.

    Open the Cocoa release notes and search for "modifierFlags" to get the
    info about this change.
    Michael Guest

  11. #11

    Default Re: Shift-drag breaks in Cocoa app under Panther

    >> 
    >
    > This is covered in the release notes for Cocoa, I believe. Your method
    > for checking for the shift key is incorrect, since it fails if there
    > are other flags set. Under Panther, NSEvent has the possibility of
    > setting certain device-specific flags. So change your code to look
    > something like this:
    >
    > if([theEvent modifierFlags] & NSShiftKeyMask) { ... }
    >
    > This will however catch any event with the shift key held down, even
    > if other modifiers are held down as well. Another strategy could be:
    >
    > int modifiers = [theEvent modifierFlags] & (NSShiftKeyMask |
    > NSCommandKeyMask | NSAlternateKeyMask | ...put others here...);[/ref]

    Thanks! This of course cleaned it up right away...
    Eric Guest

Similar Threads

  1. Accessing files/folders inside other application folders
    By jeffreyabe in forum Macromedia Flash Flashcom
    Replies: 0
    Last Post: March 19th, 01:57 AM
  2. web-based application question
    By Pd Schloss in forum PERL Beginners
    Replies: 7
    Last Post: October 15th, 04:13 PM
  3. beginner question doent based application
    By Paul Forgey in forum Mac Programming
    Replies: 2
    Last Post: September 15th, 09:28 PM
  4. Replies: 1
    Last Post: August 5th, 10:41 PM
  5. multiple doent and window types in cocoa
    By matt neuburg in forum Mac Programming
    Replies: 0
    Last Post: July 21st, 02:35 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139