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

Re: plugin menuCommandFor issue

Post by bobino »

hi Conor,

it works very well i just added a declaration for MOCollection :

Code: Select all

@interface MOCollection : NSObject
@end
i suppose there is a method to add a new collection ?

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

Re: plugin menuCommandFor issue

Post by Conor »

Code: Select all

- (MOCollection *)createCollectionNamed:(NSString *)name withEntries:(NSSet *)aSet
You can pass in an empty set, if you want an empty collection. Which I would recommend as otherwise you have to pass MOEntry objects and those are much harder to create. So create an empty collection (this method will already select the collection) and you can return an array of new NSDictionaries with the entries you want to add.
bobino
Addicted to Bruji
Addicted to Bruji
Posts: 47
Joined: Tue May 26, 2009 4:23 pm

Re: plugin menuCommandFor issue

Post by bobino »

nice.

would it be possible to create a smart list ?
User avatar
Conor
Top Dog
Posts: 5346
Joined: Sat Jul 03, 2004 12:58 pm
Contact:

Re: plugin menuCommandFor issue

Post by Conor »

Would it be possible to create a smart list
No, the smart lists have to many variables and intricacies to be able to create programmatically, it's linked directly to the interface.
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 Conor,

i try to modify programmatically links for an entry. it seems that Link is a MOLink class.
could you provide the definition of the MOLink class in order to be able to modified links ?

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

Re: plugin menuCommandFor issue

Post by Conor »

It's a subclass of NSManagedObject, so it can be treat as one. Call "setValue:forKey:" with "url", "type", "name" as the possible keys to modify.
bobino
Addicted to Bruji
Addicted to Bruji
Posts: 47
Joined: Tue May 26, 2009 4:23 pm

Re: plugin menuCommandFor issue

Post by bobino »

Yes,
if i want to add a link, i need to create an MOlink object.
I can't do it without MOLink definition? Am i wrong ?
User avatar
Conor
Top Dog
Posts: 5346
Joined: Sat Jul 03, 2004 12:58 pm
Contact:

Re: plugin menuCommandFor issue

Post by Conor »

It's not possible to add a new link to an existing entry only to a new entry as you pass those as dictionaries and then get validated and the objects get created in the database. Creating an MOLink object is not enough, you would need to initialize it and add it to the NSManagedObjectContext.

I have added a convenience method for you in the beta, so download it again and add the following method to the MOEntry @interface in the MyControllerForPlugins.h file.

Code: Select all

- (void)addLinkWithAttributtes:(NSDictionary *)attributes;
You can then add new links with:

Code: Select all

	NSDictionary *aLink = [NSDictionary dictionaryWithObjectsAndKeys:@"http://www.bruji.com", @"url", @"A Mac's Best Friend", @"name", @"Web Page", @"type", nil];
	[aDVD addLinkWithAttributtes:aLink];
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 ,

when i try to remove a link, it seems ok, it doesn't appear any more. But if i close Bookpedia and relaunch it, links i've juste removed are present.

Code: Select all

NSMutableSet *linkSet = [entryTobeModified valueForKey:@"linksSet"];
[linkSet removeObject:linksToBeRemove];
it is like modifications are not apply on database before closing Bookpedia.

Ps : the method to add a link is ok :D
User avatar
Conor
Top Dog
Posts: 5346
Joined: Sat Jul 03, 2004 12:58 pm
Contact:

Re: plugin menuCommandFor issue

Post by Conor »

You have to get the mutable version of the linkSet (mutableSetValueForKey:). That alone will then give you and error when you try to quit DVDpedia as you left a link orphaned and this is against the Bookpedia rules. To delete the link as well download the beta again and you will be able to use the following new deleteObject: method.

Code: Select all


NSMutableSet *linkSet = [entryTobeModified mutableSetValueForKey::@"linksSet"];
MOLink *linkToBeRemove = [[linkSet allObjects] lastObject];
[linkSet removeObject:linkToBeRemove];

[linkToBeRemove deleteObject];

You will need to declare the deleteObject method in the MyControllerForPlugins.h.

Code: Select all

@interface MOLink : NSManagedObject
- (void)deleteObject;
@end
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 Conor,

Regarding collections, i'm trying the method to create a collection.
The created collection is an excluded collection, is it possible to add an included collection ?
I would like to be able to add an entry of the Library to a collection, could you provide a method to do that ?
i can do it only when i create a collection for example :

Code: Select all

		
[myCollections createCollectionNamed:@"superTest" withEntries:[NSSet setWithArray:[manager arrangedEntries]]];
User avatar
Conor
Top Dog
Posts: 5346
Joined: Sat Jul 03, 2004 12:58 pm
Contact:

Re: plugin menuCommandFor issue

Post by Conor »

Download the beta again and I have exposed the following two method:

Code: Select all

@interface MyCollectionTableView : NSObject
- (MOCollection *)createCollectionWithName:(NSString *)aName;
@end

@interface MyControllerForPlugins : NSObject
- (BOOL)addEntry:(MOEntry *)anEntry toCollection:(MOCollection *)aCollection;
@end
You would use them in conjunction:

Code: Select all

MOCollection *newCollection = [myCollections createCollectionWithName:@"superTest"]];
MOEntry *aDVD = [[manager arrangedEntries] lastObject]; // You will have to loop the next method to add more than one 
[manager addEntry:anEntry toCollection:newCollection];
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 wrote:
Would it be possible to create a smart list
No, the smart lists have to many variables and intricacies to be able to create programmatically, it's linked directly to the interface.
even i wan't to create a smartlist on only one condition : field "x" = string "y" ?
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 Conor,

how can I create, add and retrieve a folder in the collection list ?

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

Re: plugin menuCommandFor issue

Post by Conor »

The folders are part of the collection returned by "allCollections" method. Loop through the results from that method and look for the name of the folder you wish to locate. You can also tell at that a collection is a folder if the "type" value is 30.

Code: Select all

MOCollection *newFolder = [myCollections createCollectionWithName:@"superTest"]];
if ([[aCollection valueForKey:@"type"] intValue] == 30)
      NSLog(@"A Folder named: %@", [aCollection valueForKey:@"name"]);
You can create a folder with the same new collection method and then setting the folder type flag. If you then create regular collections after creating a folder or selecting a folder, they will be added to the folder; however, you can't add existing collections to a folder, that can only be done via the drag and drop UI. The type value is also an internal implementation, so I can't promise it will always work, but I can't foresee a reason for changing it.

Code: Select all

MOCollection *newFolder = [myCollections createCollectionWithName:@"superTest"]];
[newFolder setValue:[NSNumber numberWithInt:30] forKey:@"type"];
Post Reply