help with menuCommandFor:

Any trouble you encounter with the Pedias, here's the place to ask for help.
Post Reply
raf
Contributor
Contributor
Posts: 6
Joined: Sun Oct 04, 2009 10:59 am

help with menuCommandFor:

Post by raf »

HI,

I am new to plugin development w/DVDPedia (not to Cocoa dev) and am trying to understand how things work. I am using the beta version of DVDPedia mentioned in this forum, although the same problem occurs with the current release version.

I am trying to change just one field in (for now) a single selected entry. Here is my code:

Code: Select all

- (NSArray *)menuCommandFor:(NSMutableArray *)entries {
	NSLog(@"[[entries objectAtIndex:0] valueForKey:@\"custom1\"] is: %@ (%@)", [[entries objectAtIndex:0] valueForKey:@"custom1"], [[[entries objectAtIndex:0] valueForKey:@"custom1"] class]);

	[[entries objectAtIndex:0] setValue:@"99.3" forKey:@"custom1"];
	return [NSArray arrayWithObject:[NSNumber numberWithBool:YES]];
}
When I select the menuItem for my plugin (with a single dvd selected), DVDPedia this throws an exception. It also opens a blank edit window. Here is the output from the console log:

Code: Select all

10/9/09 8:46:55 AM DVDpedia[1621] [[entries objectAtIndex:0] valueForKey:@"custom1"] is: 99.5 (NSCFString) 
10/9/09 8:46:55 AM DVDpedia[1621] [<NSCFBoolean 0xa02f2400> valueForUndefinedKey:]: this class is not key value coding-compliant for the key title. 
10/9/09 8:46:56 AM [0x0-0x89089].com.bruji.dvdpedia[1621] NSExceptionHandlerExceptionRaiser (in ExceptionHandling) + 185 
10/9/09 8:46:56 AM [0x0-0x89089].com.bruji.dvdpedia[1621] objc_exception_throw (in libobjc.A.dylib) + 40 
10/9/09 8:46:56 AM [0x0-0x89089].com.bruji.dvdpedia[1621] -[NSException raise] (in CoreFoundation) + 17 
10/9/09 8:46:56 AM [0x0-0x89089].com.bruji.dvdpedia[1621] -[NSObject(NSKeyValueCoding) valueForUndefinedKey:] (in Foundation) + 259 
10/9/09 8:46:56 AM [0x0-0x89089].com.bruji.dvdpedia[1621] _NSGetUsingKeyValueGetter (in Foundation) + 123 
10/9/09 8:46:56 AM [0x0-0x89089].com.bruji.dvdpedia[1621] -[NSObject(NSKeyValueCoding) valueForKey:] (in Foundation) + 250 
10/9/09 8:46:56 AM [0x0-0x89089].com.bruji.dvdpedia[1621] -[MyPanel setFromDictionary:] (in Pediabase) + 49 
10/9/09 8:46:56 AM [0x0-0x89089].com.bruji.dvdpedia[1621] -[MyControllerShared addEntriesToPanel:] (in Pediabase) + 63 
10/9/09 8:46:56 AM [0x0-0x89089].com.bruji.dvdpedia[1621] -[NSApplication sendAction:to:from:] (in AppKit) + 112 
10/9/09 8:46:56 AM [0x0-0x89089].com.bruji.dvdpedia[1621] -[NSMenu performActionForItemAtIndex:] (in AppKit) + 493 
10/9/09 8:46:56 AM [0x0-0x89089].com.bruji.dvdpedia[1621] -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] (in AppKit) + 220 
10/9/09 8:46:56 AM [0x0-0x89089].com.bruji.dvdpedia[1621] AppKitMenuEventHandler (in AppKit) + 6608 
10/9/09 8:46:56 AM [0x0-0x89089].com.bruji.dvdpedia[1621] DispatchEventToHandlers(EventTargetRec*, OpaqueEventRef*, HandlerCallRec*) (in HIToolbox) + 1181 
10/9/09 8:46:56 AM [0x0-0x89089].com.bruji.dvdpedia[1621] SendEventToEventTargetInternal(OpaqueEventRef*, OpaqueEventTargetRef*, HandlerCallRec*) (in HIToolbox) + 405 
10/9/09 8:46:56 AM [0x0-0x89089].com.bruji.dvdpedia[1621] SendEventToEventTarget (in HIToolbox) + 52 
10/9/09 8:46:56 AM [0x0-0x89089].com.bruji.dvdpedia[1621] SendHICommandEvent(unsigned long, HICommand const*, unsigned long, unsigned long, unsigned char, OpaqueEventTargetRef*, OpaqueEventTargetRef*, OpaqueEventRef**) (in HIToolbox) + 411 
10/9/09 8:46:56 AM [0x0-0x89089].com.bruji.dvdpedia[1621] SendMenuCommandWithContextAndModifiers (in HIToolbox) + 59 
10/9/09 8:46:56 AM [0x0-0x89089].com.bruji.dvdpedia[1621] SendMenuItemSelectedEvent (in HIToolbox) + 134 
10/9/09 8:46:56 AM [0x0-0x89089].com.bruji.dvdpedia[1621] FinishMenuSelection(MenuData*, MenuData*, MenuResult*, MenuResult*, unsigned long, unsigned long, unsigned long, unsigned char) (in HIToolbox) + 162 
10/9/09 8:46:56 AM [0x0-0x89089].com.bruji.dvdpedia[1621] MenuSelectCore(MenuData*, Point, double, unsigned long, OpaqueMenuRef**, unsigned short*) (in HIToolbox) + 640 
10/9/09 8:46:56 AM [0x0-0x89089].com.bruji.dvdpedia[1621] _HandleMenuSelection2 (in HIToolbox) + 383 
10/9/09 8:46:56 AM [0x0-0x89089].com.bruji.dvdpedia[1621] _HandleMenuSelection (in HIToolbox) + 53 
10/9/09 8:46:56 AM [0x0-0x89089].com.bruji.dvdpedia[1621] _NSHandleCarbonMenuEvent (in AppKit) + 244 
10/9/09 8:46:56 AM [0x0-0x89089].com.bruji.dvdpedia[1621] _DPSNextEvent (in AppKit) + 1918 
10/9/09 8:46:56 AM [0x0-0x89089].com.bruji.dvdpedia[1621] -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] (in AppKit) + 128 
10/9/09 8:46:56 AM [0x0-0x89089].com.bruji.dvdpedia[1621] -[NSApplication run] (in AppKit) + 795 
10/9/09 8:46:56 AM [0x0-0x89089].com.bruji.dvdpedia[1621] NSApplicationMain (in AppKit) + 574 
10/9/09 8:46:56 AM [0x0-0x89089].com.bruji.dvdpedia[1621] _start (in DVDpedia) + 209 
10/9/09 8:46:56 AM [0x0-0x89089].com.bruji.dvdpedia[1621] start (in DVDpedia) + 41 
10/9/09 8:46:56 AM [0x0-0x89089].com.bruji.dvdpedia[1621] 0x2 

Can anyone help me to understand why I am tickling the exception?

Thanks,
Martin
User avatar
Conor
Top Dog
Posts: 5346
Joined: Sat Jul 03, 2004 12:58 pm
Contact:

Re: help with menuCommandFor:

Post by Conor »

That was my fault, thank you for the bug report. I had to update the documentation, just return nil instead of the NSArray.

I also updated the documentation to reflect the new covers location technique. So if you are interested in the cover use:

Code: Select all

MOEntry *aDVD = [entries objectAtIndex:0];
NSString *pathToCover = [aDVD coverImagePath];
But for the last thing you need the new beta and the new sample plugin that has the following in the header file (which you can also copy paste instead of downloading a new sample plugin):

Code: Select all

@interface MOEntry : NSManagedObject 
- (NSString *)coverImagePath;
@end
raf
Contributor
Contributor
Posts: 6
Joined: Sun Oct 04, 2009 10:59 am

Re: help with menuCommandFor:

Post by raf »

Thanks for the info.

However, I am still having a problem. When I return nil the display is not refreshed. The entry is actually updated which I can verify by clicking Edit and inspecting the field I changed in the plugin. When I close the edit window the entry in the main window is updated with the new value.

Is there some way to force a refresh?

Thanks,
Martin

PS - I think the link to the new sample plugin is pointing to the old one.
User avatar
Conor
Top Dog
Posts: 5346
Joined: Sat Jul 03, 2004 12:58 pm
Contact:

Re: help with menuCommandFor:

Post by Conor »

I forgot to upload the new source code. Thank you. The refreshing should be taken happen automatically by OS X, but the new beta now up will force the refresh when you return nil.
raf
Contributor
Contributor
Posts: 6
Joined: Sun Oct 04, 2009 10:59 am

Re: help with menuCommandFor:

Post by raf »

I downloaded the beta (I can't tell if it is the same as the one I downloaded yesterday) but it exhibits the same behavior. I have now tried with 2 different fields: custom1 and Genre.

Any idea what could be going on?

Thanks,
Martin
User avatar
Conor
Top Dog
Posts: 5346
Joined: Sat Jul 03, 2004 12:58 pm
Contact:

Re: help with menuCommandFor:

Post by Conor »

Hi Martin,

Please try a new beta (I haven't gotten around to automatic the labeling of beta builds, this one will have a modified date of today).
raf
Contributor
Contributor
Posts: 6
Joined: Sun Oct 04, 2009 10:59 am

Re: help with menuCommandFor:

Post by raf »

Hi,

I don't think I'm actually getting the updated beta. Here is what I just downloaded from your inline link:

The beta.zip file has a mod date of:
Oct 9, 2009 @ 10:11 PM
and DVDPedia Beta.app has a mod date of:
Oct 9, 2009 @ 10:09 PM

This beta appears to be an older one and of course has the same behavior: does not refresh in place.

Could this be a caching issue somewhere?

Thanks,
Martin
User avatar
Conor
Top Dog
Posts: 5346
Joined: Sat Jul 03, 2004 12:58 pm
Contact:

Re: help with menuCommandFor:

Post by Conor »

Does seem to be getting cached somewhere between our server and you, here is a [url=htttp://www.bruji.com/temp/dvdpediabetaraf.zip]new link[/url] that should avoid that.
raf
Contributor
Contributor
Posts: 6
Joined: Sun Oct 04, 2009 10:59 am

Re: help with menuCommandFor:

Post by raf »

Okay, finally got the newest beta, thanks.

But I am sorry to report that there is no visible change in behavior. When the menu plugin is called, menuCommandFor: does the following:
  • 1. logs existing values of 2 fields of the selected dvd entry
    2. modifies these two fields
    3. logs values of 2 fields of the selected dvd entry (to see if change was effective)
    4. returns nil
The UI does not reflect these changes until I force a refresh by, for example, clicking on another entry and then back to the original one.

Here is the complete source for menuCommandFor:

Code: Select all

- (NSArray *)menuCommandFor:(NSMutableArray *)entries {
	NSLog(@"[[entries objectAtIndex:0] valueForKey:@\"custom1\"] is: %@ (%@)", [[entries objectAtIndex:0] valueForKey:@"custom1"], [[[entries objectAtIndex:0] valueForKey:@"custom1"] class]);
	NSLog(@"[[entries objectAtIndex:0] valueForKey:@\"Genre\"] is: %@ (%@)", [[entries objectAtIndex:0] valueForKey:@"Genre"], [[[entries objectAtIndex:0] valueForKey:@"Genre"] class]);	
	
	[[entries objectAtIndex:0] setValue:@"98.4" forKey:@"custom1"];
	[[entries objectAtIndex:0] setValue:@"DDD" forKey:@"Genre"];

	NSLog(@"[[entries objectAtIndex:0] valueForKey:@\"custom1\"] is: %@ (%@)", [[entries objectAtIndex:0] valueForKey:@"custom1"], [[[entries objectAtIndex:0] valueForKey:@"custom1"] class]);
	NSLog(@"[[entries objectAtIndex:0] valueForKey:@\"Genre\"] is: %@ (%@)", [[entries objectAtIndex:0] valueForKey:@"Genre"], [[[entries objectAtIndex:0] valueForKey:@"Genre"] class]);

	return nil;
}
And here is the console output:

Code: Select all

10/12/09 5:17:26 PM DVDpedia[14773] [[entries objectAtIndex:0] valueForKey:@"custom1"] is: 98.5 (NSCFString) 
10/12/09 5:17:26 PM DVDpedia[14773] [[entries objectAtIndex:0] valueForKey:@"Genre"] is: CCC (NSCFString) 
10/12/09 5:17:26 PM DVDpedia[14773] [[entries objectAtIndex:0] valueForKey:@"custom1"] is: 98.4 (NSCFString) 
10/12/09 5:17:26 PM DVDpedia[14773] [[entries objectAtIndex:0] valueForKey:@"Genre"] is: DDD (NSCFString) 
Thanks for any assistance.

Martin
User avatar
Conor
Top Dog
Posts: 5346
Joined: Sat Jul 03, 2004 12:58 pm
Contact:

Re: help with menuCommandFor:

Post by Conor »

Hi Martin,

What OS X are you running? I have tested your code on both Snow Leopard and Leopard and it works. A small fix is that "Genre" should be lowercase; DVDpedia fixes it on the fly and this is why it still works, but Core Data requires lowercase keys. When running into issues I always separate the method calls to help debug and follow the flow, in this case it did not help as I was never able to get the buggy behavior.

Code: Select all

	NSManagedObject *aDVD = [entries objectAtIndex:0];
	
	NSString *customOne = [aDVD valueForKey:@"custom1"];
	NSString *genre = [aDVD valueForKey:@"genre"];
	NSLog(@"[aDVD valueForKey:@\"custom1\"] is: %@ (%@)", customOne, [customOne class]);
	NSLog(@"[aDVD valueForKey:@\"Genre\"] is: %@ (%@)", genre, [genre class]);   
	
	[aDVD setValue:@"98.4" forKey:@"custom1"];
	[aDVD setValue:@"DDD" forKey:@"genre"];
	
	customOne = [aDVD valueForKey:@"custom1"];
	genre = [aDVD valueForKey:@"genre"];
	NSLog(@"[aDVD valueForKey:@\"custom1\"] is: %@ (%@)", customOne, [customOne class]);
	NSLog(@"[aDVD valueForKey:@\"Genre\"] is: %@ (%@)", genre, [genre class]);
	
	return nil;
Not sure what it could be that is stopping the update on your system. The truth is that it should have done it from the beginning without having the explicit call to the method reloadData that the beta now has, as the table is linked via bindings directly into the core data and is watching for changes via KVO.
raf
Contributor
Contributor
Posts: 6
Joined: Sun Oct 04, 2009 10:59 am

Re: help with menuCommandFor:

Post by raf »

I understand and agree with your analysis. (I am presently coding an application using core data and bindings).

I'm running 10.5.8

One interesting thing I can add (but cannot explain) is that I am getting a extra line being output to the console log. I'm now running the code you posted but have added "before:" and "after:" to the NSLog statements. I also changed the new value to the current date so I could more easily keep track of the runs.

Code: Select all

- (NSArray *)menuCommandFor:(NSMutableArray *)entries {
	NSManagedObject *aDVD = [entries objectAtIndex:0];
	
	NSString *customOne = [aDVD valueForKey:@"custom1"];
	NSString *genre = [aDVD valueForKey:@"genre"];
	NSLog(@"before: [aDVD valueForKey:@\"custom1\"] is: %@ (%@)", customOne, [customOne class]);
	NSLog(@"before: [aDVD valueForKey:@\"genre\"] is: %@ (%@)", genre, [genre class]);   
	
	[aDVD setValue:[NSString stringWithFormat:@"%@", [NSDate date]] forKey:@"custom1"];
	[aDVD setValue:[NSString stringWithFormat:@"%@", [NSDate date]] forKey:@"genre"];

	customOne = [aDVD valueForKey:@"custom1"];
	genre = [aDVD valueForKey:@"genre"];
	NSLog(@"after: [aDVD valueForKey:@\"custom1\"] is: %@ (%@)", customOne, [customOne class]);
	NSLog(@"after: [aDVD valueForKey:@\"genre\"] is: %@ (%@)", genre, [genre class]);
	
	return nil;
}
This is the console log

Code: Select all

10/13/09 5:17:40 PM com.apple.launchd[111] ([0x0-0x40a40a].com.bruji.dvdpedia[22618]) Exited: Terminated 
10/13/09 5:18:19 PM DVDpedia[22629] before: [aDVD valueForKey:@"custom1"] is: 2009-10-13 17:17:08 -0400 (NSCFString) 
10/13/09 5:18:19 PM DVDpedia[22629] before: [aDVD valueForKey:@"genre"] is: 2009-10-13 17:17:08 -0400 (NSCFString) 
10/13/09 5:18:19 PM DVDpedia[22629] after: [aDVD valueForKey:@"custom1"] is: 2009-10-13 17:18:19 -0400 (NSCFString) 
10/13/09 5:18:19 PM DVDpedia[22629] after: [aDVD valueForKey:@"genre"] is: 2009-10-13 17:18:19 -0400 (NSCFString) 
10/13/09 5:18:19 PM DVDpedia[22629] after: [aDVD valueForKey:@"genre"] is: 2009-10-13 17:18:19 -0400 (NSCFString) 
Note the last line of output. This should not be happening. It does not appear immediately like the other 4 lines even though it has the same NSLog date string at the beginning of the line: it is output a minute or so later.

Any ideas? Could it be something to do with my development environment or my build settings?

Martin

PS - I tried bracketing the setValue: calls with willChangeValueForKey:/didChangeValueForKey: This had no effect.

[edited to include complete method]
User avatar
Conor
Top Dog
Posts: 5346
Joined: Sat Jul 03, 2004 12:58 pm
Contact:

Re: help with menuCommandFor:

Post by Conor »

That is really strange. If you don't mind could you please zip up your entire plugin project folder and email it to me. This way I will get the project settings and other variables and try to reproduce your results here.
Post Reply