validateMenuItem Not Called for Undo: Menu Item?

2011-08-25 Thread Vik Rubenfeld
My validateMenuItem method is never being called for my undo: and redo: menu 
items, leaving them permanently disabled. 

From Apple's doc, "Enabling Menu Items": 
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MenuList/Articles/EnablingMenuItems.html#//apple_ref/doc/uid/2261-BAJBFGED

> If the menu item’s target is not set (that is, if it is nil—typically if the 
> menu item is connected to First Responder) and the NSMenu object is not a 
> contextual menu, then NSMenu uses the responder chain (described in About the 
> Responder Chain) to determine the target. If there is no object in the 
> responder chain that implements the item’s action, the item is disabled.
> 
> If there is an object in the responder chain that implements the item’s 
> action, NSMenu then checks to see if that object implements the 
> validateMenuItem: or validateUserInterfaceItem: method. If it does not, then 
> the menu item is enabled. If it does, then the enabled status of the menu 
> item is determined by the return value of the method.

Going through these requirements, it appears my app is fulfulling all of them. 
My undo menu item has its Sent Action set to undo: in First Responder.  First 
Responder at the time of the anomaly is an NSDocument called 
myQuestionnaireEditor. This can be verified because the Cut and Paste menu 
items also have their Sent Actions set to First Responder, and validateMenuItem 
method in myQuestionnaireEditor is called for them as expected.

myQuestionnaireEditor does have a method for implementing undo:

-(IBAction)undo:(id) sender {
[[self undoManager] undo];
}

myQuestionnaireEditor does implement validateMenuItem:

- (BOOL)validateMenuItem:(NSMenuItem *)menuItem {

NSLog(@"validateMenuItem - %@", [menuItem title]);
BOOL returnValue = NO;

if ([menuItem action] == @selector(undo:)) {
return [[self undoManager] canUndo];
}

{..}
return [super validateMenuItem:menuItem];
}

The NSLog output shows that validateMenuItem **is never called** for the undo: 
menu item.

Yet is *is called* for copy:, cut:, paste:, etc.

How can I fix this?

Thanks very much in advance to all for any info.

___

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 arch...@mail-archive.com


Re: validateMenuItem Not Called for Undo: Menu Item?

2011-08-25 Thread Vik Rubenfeld
Thank you very much, Quincey. That fixed it.


On Aug 25, 2011, at 7:00 PM, Quincey Morris wrote:

> Configuring the Undo menu item with action 'undo:' tells the frameworks that 
> this is *the* undo menu item, so it becomes one element of a standard undo UI 
> mechanism implemented in NSWindow. Under these circumstances, the menu item 
> (and especially its validation) isn't yours to mess with. The proper way to 
> provide an undo manager object to this mechanism is to use the 
> 'windowWillReturnUndoManager:' window delegate method.

___

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 arch...@mail-archive.com


Re: Best Practices for Associating a File Extension With a File in XCode 4?

2011-09-03 Thread Vik Rubenfeld
Thanks very much for your advice. 

After receiving your email I set the filetype in the object's init method:

[self setFileType:FILEEXTENSION_QUICKLOOK]; //#define 
FILEEXTENSION_QUICKLOOK @"CAQuickLook"

However, saving the file as before, still does not append a file extension. 

On the call to:

[self saveDocumentWithDelegate:self 
didSaveSelector:@selector(didSaveDocument:didSave:contextInfo:) 
contextInfo:nil];

...I get this message from XCode:

2011-09-03 15:15:01.954 CATab[12618:903] -[NSDocumentController 
fileExtensionsFromType:] is deprecated, and does not work when passed a uniform 
type identifier (UTI). If the application didn't invoke it directly then the 
problem is probably that some other NSDocument or NSDocumentController method 
is getting confused by a UTI that's not actually declared anywhere. Maybe it 
should be declared in the UTExportedTypeDeclarations section of this app's 
Info.plist but is not. The alleged UTI in question is "CAQuickLook".

I went to the XCode App Properties panel and added an Exported UTI with file 
extension of "CAQuickLook". However, saving the document, still does not append 
a file extension to the file name. 

What am I missing?



On Sep 3, 2011, at 2:12 PM, Lee Ann Rucker wrote:

> Have you set [NSDocument fileType]?
> You can get the extension from [NSString pathExtension]
> 
> 
> - Original Message -
> From: "Vik Rubenfeld" 
> To: cocoa-dev@lists.apple.com
> Sent: Saturday, September 3, 2011 12:33:13 PM
> Subject: Best Practices for Associating a File Extension With a File in   
> XCode 4?
> 
> I see that NSDocument has lots of great support for saving files, including:
> 
>[self saveDocumentWithDelegate:self 
> didSaveSelector:@selector(didSaveDocument:didSave:contextInfo:) 
> contextInfo:nil];
> 
> NSDocument supports several methods for providing info on the document to be 
> saved, including:
> 
>   - (NSURL *)fileURL //document's location
>   - (NSData *)dataOfType: (NSString *)type error:(NSError **)error 
> //document's data
>   ...etc.
> 
> But I don't yet see a method that returns the file extension for the file.
> 
> Going to the app project settings, I filled in a document type as shown in 
> this image:
> 
> http://tinyurl.com/3v6hezq
> 
> As shown in the image, I filled in a file extension for documents of the 
> document type, "QuickLookOutputDocument," which is one of my app's objects, a 
> subclass of NSDocument. I thought that perhaps this file extension would be 
> used when the document was saved. However, although the data of the document 
> is saved correctly, using:
> 
>[self saveDocumentWithDelegate:self 
> didSaveSelector:@selector(didSaveDocument:didSave:contextInfo:) 
> contextInfo:nil];
> 
> ...no file extension was used.
> 
> What am I missing?
> 
> Thanks very much in advance to all for any 
> info.___
> 
> 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/lrucker%40vmware.com
> 
> This email sent to lruc...@vmware.com

___

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 arch...@mail-archive.com


Re: Best Practices for Associating a File Extension With a File in XCode 4?

2011-09-03 Thread Vik Rubenfeld
Thanks very much for this info. I've been coding in Cocoa all year, but I'm 
still a newbie to plenty of stuff, including this.

I have developed code that does permit me to append the file extension to the 
filename:

- (IBAction) saveDocumentAs:(id)sender
{
NSSavePanel* theSavePanel = [[NSSavePanel alloc]init];
[theSavePanel setDirectory:[path stringByExpandingTildeInPath]];
[theSavePanel setPrompt:NSLocalizedString(@"Save",nil)];
[theSavePanel setRequiredFileType:DESIREDFILEEXTENSION];

 //adapted in part from code in an Apple demo app
 void (^theSavePanelHandler)(NSInteger) = ^( NSInteger result )
 {
  NSURL *theDirectoryURL = [theSavePanel directoryURL];
NSString *theDirectoryPath = [theSavePanel directory];
NSString* theFilename = [theSavePanel filename];
  
  if( theDirectoryURL )
  {
   if( theDirectoryPath )
   {
fileName =  theFilename; 

NSMutableArray* items = [NSMutableArray array];
//Here's where your app stores its data - of a type for which 
encodeWithCoder has been implemented - 
//in an NSMutableArray or other data structure accepted by 
NSKeyedArchiver
[NSKeyedArchiver archiveRootObject: items toFile: theFilename];
   } // if
  } // if
 };
 
 [theSavePanel beginSheetModalForWindow: editorWindow
 completionHandler:theSavePanelHandler];
} 

That seems to work quite well.  After developing that code, I learned about the 
NSDocument method:

[self saveDocumentWithDelegate:self 
didSaveSelector:@selector(didSaveDocument:didSave:contextInfo:) 
contextInfo:nil];

If I'm using saveDocumentWithDelegate:didSaveSelector:contextInfo, what is the 
correct way for me to communicate the list of suitable extensions to the Save 
panel?




On Sep 3, 2011, at 3:33 PM, Quincey Morris wrote:

> On Sep 3, 2011, at 15:21 , Vik Rubenfeld wrote:
> 
>> I went to the XCode App Properties panel and added an Exported UTI with file 
>> extension of "CAQuickLook". However, saving the document, still does not 
>> append a file extension to the file name. 
>> 
>> What am I missing?
> 
> You're not missing anything. Saving a document does not append a file 
> extension to the file name.
> 
> You must provide the full file name, which includes the extension. Typically, 
> it gets the correct extension because the user is presented with a Save 
> panel, and *that* returns a file name to you with a suitable extension in 
> place already.
> 
> The Save panel gets the list of suitable extensions (and the default 
> extension within that list) from the document types that you've set up for 
> the app in Xcode.
> 
> 

___

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 arch...@mail-archive.com


Re: Best Practices for Associating a File Extension With a File in XCode 4?

2011-09-04 Thread Vik Rubenfeld
I'm sure I'm missing something - it's probably one of those things that when 
you see it, you wonder how you missed it.

writableTypesForSaveOperation: seems to be about file type, e.g. RTF, XML, 
etc., rather than file extensions. From the Apple docs:

> You can override this method to limit the set of writable types when the 
> document currently contains data that is not representable in all types. For 
> example, you can disallow saving to RTF files when the document contains an 
> attachment and can only be saved properly to RTFD files.

The Apple docs don't seem to provide a demo app that calls this, but, from 
FunHouseDocument.m:

> + (NSArray *)writableTypes
> {
>   return [NSArray arrayWithObjects:@"Fun House Preset", @"JPEG File", 
> @"TIFF File", nil];
> }


Also from FunHouseDocument.m:

> + (BOOL)isNativeType:(NSString *)aType
> {
>   return [[[self class] writableTypes] containsObject:aType];
> }

So I still haven't discovered how to tell NSSavePanel what file type my 
document should be, when calling 
saveDocumentWithDelegate:didSaveSelector:contextInfo.

I'm sure it's right in front of me. What am I not seeing yet?




On Sep 3, 2011, at 5:23 PM, Kyle Sluder wrote:

> On Sat, Sep 3, 2011 at 5:14 PM, Vik Rubenfeld  wrote:
>> If I'm using saveDocumentWithDelegate:didSaveSelector:contextInfo, what is 
>> the correct way for me to communicate the list of suitable extensions to the 
>> Save panel?
> 
> NSDocument ascertains this information from calling
> -writableTypesForSaveOperation: and +isNativeType: on your NSDocument
> subclass.
> 
> --Kyle Sluder

___

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 arch...@mail-archive.com


Re: Best Practices for Associating a File Extension With a File in XCode 4?

2011-09-04 Thread Vik Rubenfeld
[exact same post, with "file type" changed to "file extension" in 2nd to last 
paragraph]

I'm sure I'm missing something - it's probably one of those things that when 
you see it, you wonder how you missed it.

writableTypesForSaveOperation: seems to be about file type, e.g. RTF, XML, 
etc., rather than file extensions. From the Apple docs:

> You can override this method to limit the set of writable types when the 
> document currently contains data that is not representable in all types. For 
> example, you can disallow saving to RTF files when the document contains an 
> attachment and can only be saved properly to RTFD files.

The Apple docs don't seem to provide a demo app that calls this, but, from 
FunHouseDocument.m:

> + (NSArray *)writableTypes
> {
>   return [NSArray arrayWithObjects:@"Fun House Preset", @"JPEG File", 
> @"TIFF File", nil];
> }


Also from FunHouseDocument.m:

> + (BOOL)isNativeType:(NSString *)aType
> {
>   return [[[self class] writableTypes] containsObject:aType];
> }

So I still haven't discovered how to tell NSSavePanel what file extension my 
document should be, when calling 
saveDocumentWithDelegate:didSaveSelector:contextInfo.

I'm sure it's right in front of me. What am I not seeing yet?




On Sep 3, 2011, at 5:23 PM, Kyle Sluder wrote:

> On Sat, Sep 3, 2011 at 5:14 PM, Vik Rubenfeld  wrote:
>> If I'm using saveDocumentWithDelegate:didSaveSelector:contextInfo, what is 
>> the correct way for me to communicate the list of suitable extensions to the 
>> Save panel?
> 
> NSDocument ascertains this information from calling
> -writableTypesForSaveOperation: and +isNativeType: on your NSDocument
> subclass.
> 
> --Kyle Sluder

___

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 arch...@mail-archive.com


Re: Best Practices for Associating a File Extension With a File in XCode 4?

2011-09-04 Thread Vik Rubenfeld
I'm saving via this call:

[self saveDocumentWithDelegate:self 
didSaveSelector:@selector(didSaveDocument:didSave:contextInfo:) 
contextInfo:nil];

This brings up a Save As dialogue box. 

On Sep 4, 2011, at 12:33 PM, Jens Alfke wrote:

> 
> On Sep 4, 2011, at 9:06 AM, Vik Rubenfeld wrote:
> 
>> Still no file extension is appended to the document when I save it.
> 
> How are you saving it, in particular how are you getting the filename to save 
> as?
> 
> —Jens

___

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 arch...@mail-archive.com


NSTextFieldCell Action Method Not Reaching Delegate?

2011-07-11 Thread Vik Rubenfeld
I have an NSOutlineView with five columns.  I need to know which column 
contains the NSTextFieldCell which is currently being edited.  To do that, I 
thought I would connect the action method of the NSTextFieldCell to a method in 
the NSOutlineView's delegate, which could check the Tag of the NSTextField, to 
determine what column that field was in.  However, the action method I set up 
in the delegate, is never called. 

Question 1) Is there a better way to do this?
Question 2) If not, how can I get the action method to be called?

Thanks very much in advance to all for any info.


___

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 arch...@mail-archive.com