plugin menuCommandFor issue

Any trouble you encounter with the Pedias, here's the place to ask for help.
bobino
Addicted to Bruji
Addicted to Bruji
Posts: 47
Joined: Tue May 26, 2009 4:23 pm

plugin menuCommandFor issue

Post by bobino »

Hi,
it's me again !
when i return an array of NSMutableDictionnary with menuCommandFor method, only the first element of the array is imported to the collection.

it is actually is big issue for my plugin !
is it a bug, or do i something wrong ?

thanks

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

Re: plugin menuCommandFor issue

Post by Conor »

Thank you for the bug report. Try out the beta, I made some changes but haven't throughly tested them in such a short time.
bobino
Addicted to Bruji
Addicted to Bruji
Posts: 47
Joined: Tue May 26, 2009 4:23 pm

Re: plugin menuCommandFor issue

Post by bobino »

thks ,

as i use bookpedia, do you have a bookpedia béta ?
how long to release this new version ?
bobino
Addicted to Bruji
Addicted to Bruji
Posts: 47
Joined: Tue May 26, 2009 4:23 pm

Re: plugin menuCommandFor issue

Post by bobino »

Hi,

i test the beta release,
when i return more than one reccord, nothing happens, and a few actions later i have an error message asking me to reload the database.
User avatar
Conor
Top Dog
Posts: 5346
Joined: Sat Jul 03, 2004 12:58 pm
Contact:

Re: plugin menuCommandFor issue

Post by Conor »

I'll take thorough look at adding multiple items and will let you know when the beta is ready or if any changes are required (in order to make it more flexible for the future). We work continuously on the Pedias but have started to stager releases about a month apart in order to minimize the update available intrusion on our users. However, if you are facing a deadline and your plug-in is really cool we can look at an early release of the next version.
bobino
Addicted to Bruji
Addicted to Bruji
Posts: 47
Joined: Tue May 26, 2009 4:23 pm

Re: plugin menuCommandFor issue

Post by bobino »

Thanks Conor,

let me do a suggestion if you are looking to improve the Plugin.

Of course i don't know your software architecture, i wonder if you could add the sender to the menucommandFor method as
- (NSArray *)menuCommandFor:(NSMutableArray *)entries sender : (id)sender{

this way i suppose we will be able to call the sender method as we do with the searchFor method (or something equivalent ):
[delegate searchReturnedNumberOfResults:[resultsData count] sender:self];

i'll be very usefull, because this way we can reuse the window for adding entries ( if there is a button to import all reccords in this window),
furthermore at this time, it's a big constraint to be oblige to return the entries to the method.
:D
User avatar
Conor
Top Dog
Posts: 5346
Joined: Sat Jul 03, 2004 12:58 pm
Contact:

Re: plugin menuCommandFor issue

Post by Conor »

The error you describe I was unable to repeat. It likely has to do with the format of the attributes your adding as their is no validation happening. Please send me your console log after you get the database error and I can tell you more. For example the following code will fail because the "theatrical" key is supposed to be a NSDate and not a NSString. Look around for that kind of error, although the console error will be explicit about which field is not in the correct format.

Code: Select all

	NSDictionary *firstItem = [NSDictionary dictionaryWithObjectsAndKeys:@"A Movie", @"title", @"A Director", @"director", nil];
	NSDictionary *secondItem = [NSDictionary dictionaryWithObjectsAndKeys:@"Another Movie", @"title", @"Another director", @"director", @"A writer", @"writer", @"2009", @"theatrical", nil];

	return [NSArray arrayWithObjects: firstItem, secondItem, nil];
Download the new beta and you will be able to use the following method to add entries at any time (even if it's only one entry pass it in an array).

Code: Select all

	MyControllerForPlugins *manager = [NSApp delegate];
	[manager addEntriesWithAttributes:[NSArray arrayWithObjects:firstItem, secondItem, nil]];
Your MyControllerForPlugins.h file needs to be updated to have the extra method declaration:

Code: Select all

// Application Controller 
@interface MyControllerForPlugins : NSObject
- (NSManagedObject *)selectedEntry;
- (NSArray *)arrangedEntries;
- (NSArray *)selectedEntries;
- (void)addEntriesWithAttributes:(NSArray *)entries;
@end
Also the new beta has a small fix that items where being added only to the library and not the currently selected collection.
bobino
Addicted to Bruji
Addicted to Bruji
Posts: 47
Joined: Tue May 26, 2009 4:23 pm

Re: plugin menuCommandFor issue

Post by bobino »

you're right !

I was sending a bad format for "releasedate" ! :lol:

i have a last issue : when i send multiple items, coverimage is not reccorded. I return the URL of image for key "imageLocation" , i don't know the album UID at this step , therefore i can't store CoverImage myself !

i test "addEntriesWithAttributes" it works very well ! thks
User avatar
Conor
Top Dog
Posts: 5346
Joined: Sat Jul 03, 2004 12:58 pm
Contact:

Re: plugin menuCommandFor issue

Post by Conor »

As you can tell you are the first to add multiple items and are debugging the method, download another beta and it will take "imageLocation" into account and store the image for the new movies.
bobino
Addicted to Bruji
Addicted to Bruji
Posts: 47
Joined: Tue May 26, 2009 4:23 pm

Re: plugin menuCommandFor issue

Post by bobino »

as your support is so quick it's a pleasure to be the first !

is the bookpedia beta also up to date ?
bobino
Addicted to Bruji
Addicted to Bruji
Posts: 47
Joined: Tue May 26, 2009 4:23 pm

Re: plugin menuCommandFor issue

Post by bobino »

i wasn't able to test you're last modification as i think you didn't update the beta for bookpedia.
Anyway i'm sure your modification is correct.

let me ask you a new question , i wan't to add some url link when i download data for the reccord, but i have a problem for key "linksSet".
When i add an array of NSDictionary nothing is reccorded :

Code: Select all

- (NSDictionary *)resultNumber:(int)number {

[...]
	 NSMutableArray *arrayURL =[NSMutableArray array];
	 NSMutableDictionary * anotherURL =[NSMutableDictionary dictionaryWithCapacity:3];

		[anotherURL setObject:[NSString stringWithFormat:@"http://www.tests/%@", data] forKey:@"URL"];
		[anotherURL setObject:@"urlName" forKey:@"Name"];
		[anotherURL setObject:@"urlType" forKey:@"Type"];
		[arrayURL addObject: anotherURL];
		[returnData setObject:arrayURL forKey:@"linksSet"];

[...]

        	return returnData;	


Furthermore, when i test to read URL for a selected entry i have an error :

Code: Select all

- (NSArray *)menuCommandFor:(NSMutableArray *)entries {
		MyControllerForPlugins *manager = [NSApp delegate];
		NSArray *selectedEntries = [manager selectedEntries];	
		NSManagedObject *entrieTobeModified = [selectedEntries objectAtIndex:0];

		NSString *test4 = [entrieTobeModified valueForKey:@"title"]; // ->correct
		NSDate *test5 = [entrieTobeModified valueForKey:@"releasedate"];// ->correct
		NSArray  *test = [entrieTobeModified valueForKey:@"linksSet"]; // ->type return for test = _NSFaultingMutableSet
		NSDictionary *test2 =[test objectAtIndex:0]; //  -> fault 

Console log:
21/07/09 21:58:35 Bookpedia[453] *** -[_NSFaultingMutableSet objectAtIndex:]: unrecognized selector sent to instance 0x16845750 

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

Re: plugin menuCommandFor issue

Post by Conor »

Sorry, I was under the impression the plug-in was for DVDpedia. I have updated all the betas so you may download Bookpedia.

For the linkSet the dictionary of attributes the keys need to start with a lowercase. The keys are: @"url", @"type" and @"name".

For reading the URLs of the links remember that Core Data relationships return a set and not an array. The set has no objectAtIndex: method. It's best to use an enumerator to go through all the links and find the URL you are looking for.

Code: Select all

      NSSet *linkSet = [entryToBeModified valueForKey:@"linksSet"];
      NSEnumerator *linksEnum = [linkSet objectEnumerator];
      NSManagedObject *nextLink;
      while (nextLink = [linksEnum nextObject]) {
	     NSLog(@"", [nextLink valueForKey:@"url"]);			
      }
However, if you really know there is only one single link then use the following to turn the set into an array and ask for the only object (lastObject saves you having to make sure the set is not empty before using objectAtIndex:).

Code: Select all

NSSet  *linkSet = [entryToBeModified valueForKey:@"linksSet"]; 
NSManagedObject *nextLink = [[linkSet allObjects] lastObject];
bobino
Addicted to Bruji
Addicted to Bruji
Posts: 47
Joined: Tue May 26, 2009 4:23 pm

Re: plugin menuCommandFor issue

Post by bobino »

i tested the beta, everything is ok.

for linksSet, i was using keys with lowercase @"url", @"type" and @"name". but nothing happend. then i did some tests with uppercase, and forgot to change that in my example.
i re-tested this evening, it doesn't work.

thks for your example about how i can read linksSet Value ! it works.
for others : there is a small mistake in the example :

NSEnumerator *linksEnum = [linkSet objectEnumerator];
User avatar
Conor
Top Dog
Posts: 5346
Joined: Sat Jul 03, 2004 12:58 pm
Contact:

Re: plugin menuCommandFor issue

Post by Conor »

Glad all is working out and thank you for pointing out that copy paste typo.
bobino
Addicted to Bruji
Addicted to Bruji
Posts: 47
Joined: Tue May 26, 2009 4:23 pm

Re: plugin menuCommandFor issue

Post by bobino »

Conor, as i said in my las post adding array of dictionnary for key "linksSet" doesn't work.. Could you have a look to this last point ?
Post Reply