setting preselected file for nsopenpanel

  • Hi,

    Been through numerous posts on stack overflow without a solution so here goes:

    runModalForDirectory:file:types: was deprecated but in the docs it doesn't give the replacement for the file argument.  How can we have a file preselected when running an open panel?

    Thanks,

    rc
  • Well, NSOpenPanel inherits from NSSavePanel, so setNameFieldStringValue: might work. I haven't tried this, and I don't know whether there would be sandboxing issues.

    On 2012-06-11, at 7:08 AM, Rick C. wrote:

    > Hi,
    >
    > Been through numerous posts on stack overflow without a solution so here goes:
    >
    > runModalForDirectory:file:types: was deprecated but in the docs it doesn't give the replacement for the file argument.  How can we have a file preselected when running an open panel?
    >
    > Thanks,
    >
    > rc
  • Nope. I filed a bug (10522782), it got marked as a duplicate of bug 8106339

    Mine was:
    NSOpenPanel beginForDirectory:file:types:modelessDelegate:didEndSelector:contextInfo:
    let you provide an initial selection. The replacement method doesn't.

    In addition to having an initial selection, it would be nice to have a way to set selection while the panel is up; for instance, a "Recent Items" in an accessoryView would want to change the selection.

    Since it's possible to set the selection with drag and drop, it ought to be possible to do it programmatically.

    ----- Original Message -----
    From: "Dave Fernandes" <dave.fernandes...>
    To: "Rick C." <rickcorteza...>
    Cc: "Cocoa-Dev List" <cocoa-dev...>
    Sent: Monday, June 11, 2012 8:00:25 AM
    Subject: Re: setting preselected file for nsopenpanel

    Well, NSOpenPanel inherits from NSSavePanel, so setNameFieldStringValue: might work. I haven't tried this, and I don't know whether there would be sandboxing issues.

    On 2012-06-11, at 7:08 AM, Rick C. wrote:

    > Hi,
    >
    > Been through numerous posts on stack overflow without a solution so here goes:
    >
    > runModalForDirectory:file:types: was deprecated but in the docs it doesn't give the replacement for the file argument.  How can we have a file preselected when running an open panel?
    >
    > Thanks,
    >
    > rc
  • This is a known limitation, as Lee Ann Rucker reported in the prior message.

    One work around is to use setDirectoryURL: and pass it the actual file (not the folder). I believe that will pre-select it (sort of by accident).

    corbin

    On Jun 11, 2012, at 4:08 AM, Rick C. <rickcorteza...> wrote:

    > Hi,
    >
    > Been through numerous posts on stack overflow without a solution so here goes:
    >
    > runModalForDirectory:file:types: was deprecated but in the docs it doesn't give the replacement for the file argument.  How can we have a file preselected when running an open panel?
    >
    > Thanks,
    >
    > rc
  • Thanks all for the replies.  I know setNameFieldStringValue: doesn't work I tried it.  I also tried (I thought) the suggestion by corbin but I will go back and try it again to make sure I did it right.  I'll post back my results thanks!

    rc

    On Jun 12, 2012, at 5:11 AM, Corbin Dunn wrote:

    > This is a known limitation, as Lee Ann Rucker reported in the prior message.
    >
    > One work around is to use setDirectoryURL: and pass it the actual file (not the folder). I believe that will pre-select it (sort of by accident).
    >
    > corbin
    >
    > On Jun 11, 2012, at 4:08 AM, Rick C. <rickcorteza...> wrote:
    >
    >> Hi,
    >>
    >> Been through numerous posts on stack overflow without a solution so here goes:
    >>
    >> runModalForDirectory:file:types: was deprecated but in the docs it doesn't give the replacement for the file argument.  How can we have a file preselected when running an open panel?
    >>
    >> Thanks,
    >>
    >> rc
    >
  • Ok with this unfortunately what happens is the actual file is treated as a directory and it appears in the dropdown bar at the top.  So if I pass ~/Downloads/test.pdf for setDirectoryURL: it thinks test.pdf is a directory and wants me to choose a file from the test.pdf directory.  Any other ideas? :-)

    rc

    On Jun 12, 2012, at 5:11 AM, Corbin Dunn wrote:

    > This is a known limitation, as Lee Ann Rucker reported in the prior message.
    >
    > One work around is to use setDirectoryURL: and pass it the actual file (not the folder). I believe that will pre-select it (sort of by accident).
    >
    > corbin
    >
    > On Jun 11, 2012, at 4:08 AM, Rick C. <rickcorteza...> wrote:
    >
    >> Hi,
    >>
    >> Been through numerous posts on stack overflow without a solution so here goes:
    >>
    >> runModalForDirectory:file:types: was deprecated but in the docs it doesn't give the replacement for the file argument.  How can we have a file preselected when running an open panel?
    >>
    >> Thanks,
    >>
    >> rc
    >
previous month june 2012 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  
Go to today