Re: problems in runModal in NSOpenPanel used with defaults

2008-09-30 Thread Corbin Dunn


On Sep 29, 2008, at 11:20 PM, spartan g wrote:


Oh Yes...

Thanks Mike. I got your point corbin. I was thinking that I am  
messing somewhere in using the panel properties!!! In fact that  
behavior, now, seems very helpful to get the last opened directory..


I should also mention that you should not rely on the properties that  
are written out by the NSSavePanel, as they may change in the future.  
Any defaults that start with "NS" are considered owned by AppKit.


If you want to save/restore the last directory shown, I'd recommend  
accessing the -directory property and saving/restoring that as required.


-corbin



Very much Helpful...

Once again Thanks Mike, Thanks Corbin

Best Regards,
Spartan...


On Mon, Sep 29, 2008 at 9:17 PM, Corbin Dunn <[EMAIL PROTECTED]>  
wrote:


On Sep 26, 2008, at 10:34 PM, spartan g wrote:


Thanks Corbin,

I have used your tips in the updated code.
Besides, my aim is to save the filename selected through the panel  
to a pList file timely whenever it is changed, so I am using  
synchronization of defaults. I checked and found that there is no  
resetStandardUserDefaults used anywhere in the entire project.
I tried implementing dictionary insted of defaults and updating the  
pList contents accordingly.
But to my surprise, in either cases(dictionary/defaults), whenever  
I click browse and click cancel/open the junk values are appended  
automatically in the pList file!!! For the time being I am deleting  
and recreating the file, but it doesn't seem a good alternative!!!

How can a 'Panel runModal' add such junk in the pList!!!



Michael already clarified a bit, but it sounds like your definition  
of junk isn't what I had expected. I assumed you were reading in bad  
(unexpected) values, ie: junk. But I think you are referring to the  
other values the save panel places there. As michael said, this is  
just the way it works. Consider using NSDictionary and  
writeToFile:... instead


corbin





Sparta...


On Fri, Sep 26, 2008 at 10:48 PM, Corbin Dunn <[EMAIL PROTECTED]>  
wrote:

Howdy spartan,

Oh! A few little tips:


On Sep 26, 2008, at 3:11 AM, spartan g wrote:

Hi,
I am writing an utility which needs to open a panel to browse files  
and

select one.


- (IBAction)browseClicked:(id)sender

{

NSOpenPanel *panel = [NSOpenPanel openPanel];

if ([panel runModal]) {

  NSArray *filenames = [panel filenames];

   NSString *filename = [filenames objectAtIndex:0];

Always check the array length first, or just use [panel filename];




   if (filename){

printf("\n browseClicked: filename = %s \n", [filename cString]);

Just a side note: most cocoa people move to NSLog, but printf still  
works. Try:

NSLog(@"%@", filename); -- much easier!



if ([appToOpenText stringValue] != NULL ){

nil is preferred to NULL.




  [appToOpenText setStringValue: filename];

}

else  printf("\n browseClicked: appToOpenText has NULL value \n");

  }

   else printf ("\n *** browseClicked: Filename is NULL *** \n");

}

}
The filename chosen is assigned to the textfield. I have used  
defaults to

synchronize this filename and storing it in a pList file.
[_defaults setObject: [appToOpenText stringValue] forKey:  
@"AppToOpen" ];


It seems strange to use the user defaults as your model to store  
objects, but i'm sure there is a reason you do this.




[_defaults synchronize];

You probably don't want to hold onto the userdefaults instance as  
an ivar, and instead always query it with [NSUserDefaults  
standardUserDefaults]. It may be possible that something is calling  
resetStandardUserDefaults, and blowing away the old instance.


corbin







___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: problems in runModal in NSOpenPanel used with defaults

2008-09-29 Thread spartan g
Oh Yes...
Thanks Mike. I got your point corbin. I was thinking that I am messing
somewhere in using the panel properties!!! In fact that behavior, now, seems
very helpful to get the last opened directory..
Very much Helpful...

Once again Thanks Mike, Thanks Corbin

Best Regards,
Spartan...


On Mon, Sep 29, 2008 at 9:17 PM, Corbin Dunn <[EMAIL PROTECTED]> wrote:

>
> On Sep 26, 2008, at 10:34 PM, spartan g wrote:
>
> Thanks Corbin,
> I have used your tips in the updated code.
> Besides, my aim is to save the filename selected through the panel to a
> pList file timely whenever it is changed, so I am using synchronization of
> defaults. I checked and found that there is no resetStandardUserDefaults
> used anywhere in the entire project.
> I tried implementing dictionary insted of defaults and updating the pList
> contents accordingly.
> But to my surprise, in either cases(dictionary/defaults), whenever I click
> browse and click cancel/open the junk values are appended automatically in
> the pList file!!! For the time being I am deleting and recreating the file,
> but it doesn't seem a good alternative!!!
> How can a 'Panel runModal' add such junk in the pList!!!
>
>
> Michael already clarified a bit, but it sounds like your definition of junk
> isn't what I had expected. I assumed you were reading in bad (unexpected)
> values, ie: junk. But I think you are referring to the other values the save
> panel places there. As michael said, this is just the way it works. Consider
> using NSDictionary and writeToFile:... instead
>
> corbin
>
>
>
>
> Sparta...
>
>
> On Fri, Sep 26, 2008 at 10:48 PM, Corbin Dunn <[EMAIL PROTECTED]> wrote:
>
>> Howdy spartan,
>>
>> Oh! A few little tips:
>>
>> On Sep 26, 2008, at 3:11 AM, spartan g wrote:
>>
>>  Hi,
>>> I am writing an utility which needs to open a panel to browse files and
>>> select one.
>>>
>>>
>>> - (IBAction)browseClicked:(id)sender
>>>
>>> {
>>>
>>> NSOpenPanel *panel = [NSOpenPanel openPanel];
>>>
>>> if ([panel runModal]) {
>>>
>>>   NSArray *filenames = [panel filenames];
>>>
>>>NSString *filename = [filenames objectAtIndex:0];
>>>
>>
>> Always check the array length first, or just use [panel filename];
>>
>>
>>>
>>>if (filename){
>>>
>>> printf("\n browseClicked: filename = %s \n", [filename cString]);
>>>
>>
>> Just a side note: most cocoa people move to NSLog, but printf still works.
>> Try:
>> NSLog(@"%@", filename); -- much easier!
>>
>>
>>>
>>> if ([appToOpenText stringValue] != NULL ){
>>>
>>
>> nil is preferred to NULL.
>>
>>
>>>
>>>   [appToOpenText setStringValue: filename];
>>>
>>> }
>>>
>>> else  printf("\n browseClicked: appToOpenText has NULL value \n");
>>>
>>>   }
>>>
>>>else printf ("\n *** browseClicked: Filename is NULL *** \n");
>>>
>>> }
>>>
>>> }
>>> The filename chosen is assigned to the textfield. I have used defaults to
>>> synchronize this filename and storing it in a pList file.
>>> [_defaults setObject: [appToOpenText stringValue] forKey: @"AppToOpen" ];
>>>
>>
>> It seems strange to use the user defaults as your model to store objects,
>> but i'm sure there is a reason you do this.
>>
>>
>>>
>>> [_defaults synchronize];
>>>
>>
>> You probably don't want to hold onto the userdefaults instance as an ivar,
>> and instead always query it with [NSUserDefaults standardUserDefaults]. It
>> may be possible that something is calling resetStandardUserDefaults, and
>> blowing away the old instance.
>>
>> corbin
>>
>>
>
>
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: problems in runModal in NSOpenPanel used with defaults

2008-09-29 Thread Corbin Dunn


On Sep 26, 2008, at 10:34 PM, spartan g wrote:


Thanks Corbin,

I have used your tips in the updated code.
Besides, my aim is to save the filename selected through the panel  
to a pList file timely whenever it is changed, so I am using  
synchronization of defaults. I checked and found that there is no  
resetStandardUserDefaults used anywhere in the entire project.
I tried implementing dictionary insted of defaults and updating the  
pList contents accordingly.
But to my surprise, in either cases(dictionary/defaults), whenever I  
click browse and click cancel/open the junk values are appended  
automatically in the pList file!!! For the time being I am deleting  
and recreating the file, but it doesn't seem a good alternative!!!

How can a 'Panel runModal' add such junk in the pList!!!



Michael already clarified a bit, but it sounds like your definition of  
junk isn't what I had expected. I assumed you were reading in bad  
(unexpected) values, ie: junk. But I think you are referring to the  
other values the save panel places there. As michael said, this is  
just the way it works. Consider using NSDictionary and writeToFile:...  
instead


corbin





Sparta...


On Fri, Sep 26, 2008 at 10:48 PM, Corbin Dunn <[EMAIL PROTECTED]>  
wrote:

Howdy spartan,

Oh! A few little tips:


On Sep 26, 2008, at 3:11 AM, spartan g wrote:

Hi,
I am writing an utility which needs to open a panel to browse files  
and

select one.


- (IBAction)browseClicked:(id)sender

{

NSOpenPanel *panel = [NSOpenPanel openPanel];

if ([panel runModal]) {

  NSArray *filenames = [panel filenames];

   NSString *filename = [filenames objectAtIndex:0];

Always check the array length first, or just use [panel filename];




   if (filename){

printf("\n browseClicked: filename = %s \n", [filename cString]);

Just a side note: most cocoa people move to NSLog, but printf still  
works. Try:

NSLog(@"%@", filename); -- much easier!



if ([appToOpenText stringValue] != NULL ){

nil is preferred to NULL.




  [appToOpenText setStringValue: filename];

}

else  printf("\n browseClicked: appToOpenText has NULL value \n");

  }

   else printf ("\n *** browseClicked: Filename is NULL *** \n");

}

}
The filename chosen is assigned to the textfield. I have used  
defaults to

synchronize this filename and storing it in a pList file.
[_defaults setObject: [appToOpenText stringValue] forKey:  
@"AppToOpen" ];


It seems strange to use the user defaults as your model to store  
objects, but i'm sure there is a reason you do this.




[_defaults synchronize];

You probably don't want to hold onto the userdefaults instance as an  
ivar, and instead always query it with [NSUserDefaults  
standardUserDefaults]. It may be possible that something is calling  
resetStandardUserDefaults, and blowing away the old instance.


corbin




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: problems in runModal in NSOpenPanel used with defaults

2008-09-27 Thread Michael Ash
On Sat, Sep 27, 2008 at 1:34 AM, spartan g <[EMAIL PROTECTED]> wrote:
> Thanks Corbin,
> I have used your tips in the updated code.
> Besides, my aim is to save the filename selected through the panel to a
> pList file timely whenever it is changed, so I am using synchronization of
> defaults. I checked and found that there is no resetStandardUserDefaults
> used anywhere in the entire project.
> I tried implementing dictionary insted of defaults and updating the pList
> contents accordingly.
> But to my surprise, in either cases(dictionary/defaults), whenever I click
> browse and click cancel/open the junk values are appended automatically in
> the pList file!!! For the time being I am deleting and recreating the file,
> but it doesn't seem a good alternative!!!
> How can a 'Panel runModal' add such junk in the pList!!!

I believe you attempted to show the junk values you were getting in
your first e-mail, however they did not appear to me. So this is just
a guess

I suspect that you're seeing entirely normal autosave information
being generated by NSOpenPanel. That plist is not exclusively yours.
It holds all user defaults for your program. Any library in your
program, such as AppKit, is free to use that plist to store its own
values as well. This is normal, harmless, and expected. NSOpenPanel
will store values in user defaults to remember its position, size,
selection, and other such values.

Mike
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: problems in runModal in NSOpenPanel used with defaults

2008-09-26 Thread spartan g
Thanks Corbin,
I have used your tips in the updated code.
Besides, my aim is to save the filename selected through the panel to a
pList file timely whenever it is changed, so I am using synchronization of
defaults. I checked and found that there is no resetStandardUserDefaults
used anywhere in the entire project.
I tried implementing dictionary insted of defaults and updating the pList
contents accordingly.
But to my surprise, in either cases(dictionary/defaults), whenever I click
browse and click cancel/open the junk values are appended automatically in
the pList file!!! For the time being I am deleting and recreating the file,
but it doesn't seem a good alternative!!!
How can a 'Panel runModal' add such junk in the pList!!!

Sparta...


On Fri, Sep 26, 2008 at 10:48 PM, Corbin Dunn <[EMAIL PROTECTED]> wrote:

> Howdy spartan,
>
> Oh! A few little tips:
>
> On Sep 26, 2008, at 3:11 AM, spartan g wrote:
>
>  Hi,
>> I am writing an utility which needs to open a panel to browse files and
>> select one.
>>
>>
>> - (IBAction)browseClicked:(id)sender
>>
>> {
>>
>> NSOpenPanel *panel = [NSOpenPanel openPanel];
>>
>> if ([panel runModal]) {
>>
>>   NSArray *filenames = [panel filenames];
>>
>>NSString *filename = [filenames objectAtIndex:0];
>>
>
> Always check the array length first, or just use [panel filename];
>
>
>>
>>if (filename){
>>
>> printf("\n browseClicked: filename = %s \n", [filename cString]);
>>
>
> Just a side note: most cocoa people move to NSLog, but printf still works.
> Try:
> NSLog(@"%@", filename); -- much easier!
>
>
>>
>> if ([appToOpenText stringValue] != NULL ){
>>
>
> nil is preferred to NULL.
>
>
>>
>>   [appToOpenText setStringValue: filename];
>>
>> }
>>
>> else  printf("\n browseClicked: appToOpenText has NULL value \n");
>>
>>   }
>>
>>else printf ("\n *** browseClicked: Filename is NULL *** \n");
>>
>> }
>>
>> }
>> The filename chosen is assigned to the textfield. I have used defaults to
>> synchronize this filename and storing it in a pList file.
>> [_defaults setObject: [appToOpenText stringValue] forKey: @"AppToOpen" ];
>>
>
> It seems strange to use the user defaults as your model to store objects,
> but i'm sure there is a reason you do this.
>
>
>>
>> [_defaults synchronize];
>>
>
> You probably don't want to hold onto the userdefaults instance as an ivar,
> and instead always query it with [NSUserDefaults standardUserDefaults]. It
> may be possible that something is calling resetStandardUserDefaults, and
> blowing away the old instance.
>
> corbin
>
>
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: problems in runModal in NSOpenPanel used with defaults

2008-09-26 Thread Corbin Dunn

Howdy spartan,

Oh! A few little tips:

On Sep 26, 2008, at 3:11 AM, spartan g wrote:


Hi,
I am writing an utility which needs to open a panel to browse files  
and

select one.


- (IBAction)browseClicked:(id)sender

{

NSOpenPanel *panel = [NSOpenPanel openPanel];

if ([panel runModal]) {

   NSArray *filenames = [panel filenames];

NSString *filename = [filenames objectAtIndex:0];


Always check the array length first, or just use [panel filename];




if (filename){

printf("\n browseClicked: filename = %s \n", [filename cString]);


Just a side note: most cocoa people move to NSLog, but printf still  
works. Try:

NSLog(@"%@", filename); -- much easier!




if ([appToOpenText stringValue] != NULL ){


nil is preferred to NULL.




   [appToOpenText setStringValue: filename];

}

else  printf("\n browseClicked: appToOpenText has NULL value \n");

   }

else printf ("\n *** browseClicked: Filename is NULL *** \n");

}

}
The filename chosen is assigned to the textfield. I have used  
defaults to

synchronize this filename and storing it in a pList file.
[_defaults setObject: [appToOpenText stringValue] forKey:  
@"AppToOpen" ];


It seems strange to use the user defaults as your model to store  
objects, but i'm sure there is a reason you do this.





[_defaults synchronize];


You probably don't want to hold onto the userdefaults instance as an  
ivar, and instead always query it with [NSUserDefaults  
standardUserDefaults]. It may be possible that something is calling  
resetStandardUserDefaults, and blowing away the old instance.


corbin

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]