Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add catalog action #1276

Merged
merged 10 commits into from Jan 17, 2013
4 changes: 4 additions & 0 deletions Quicksilver/Code-App/QSCatalogPrefPane.h
Expand Up @@ -55,6 +55,8 @@
IBOutlet NSView *sidebar;
}

+ (id)sharedInstance;

- (IBAction)addSource:(id)sender;
//- (IBAction)addSourcePreset:(id)sender;
//- (IBAction)removeItem:(id)sender;
Expand Down Expand Up @@ -103,4 +105,6 @@
- (void)selectEntry:(QSCatalogEntry *)entry;
- (QSCatalogEntry *)entryForCatFile:(NSString *)path;
- (id)preferencesSplitView;

- (void)showOptionsDrawer;
@end
15 changes: 11 additions & 4 deletions Quicksilver/Code-App/QSCatalogPrefPane.m
Expand Up @@ -270,8 +270,7 @@ - (IBAction)addSource:(id)sender {

QSCatalogEntry *childEntry = [QSCatalogEntry entryWithDictionary:childDict];
[[parentEntry children] addObject:childEntry];
[treeController rearrangeObjects];
[itemTable reloadData];
[self reloadData];
[self selectEntry:childEntry];

if ([sourceString isEqualToString:@"QSFileSystemObjectSource"]) {
Expand Down Expand Up @@ -507,12 +506,20 @@ - (IBAction)copyPreset:(id)sender {
QSCatalogEntry *newItem = [currentItem uniqueCopy];
[[[[QSLibrarian sharedInstance] catalogCustom] children] addObject:newItem];
[currentItem setEnabled:NO];
[itemTable reloadData];
[treeController rearrangeObjects];
[self reloadData];
[self selectEntry:newItem];
[[NSNotificationCenter defaultCenter] postNotificationName:QSCatalogStructureChanged object:nil];
}

-(void)reloadData {
[treeController rearrangeObjects];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
dispatch_async(dispatch_get_main_queue(), ^{
[itemTable reloadData];
});
});
}

- (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard {
draggedIndexPaths = [items valueForKey:@"indexPath"];
items = ([items count] && [[items lastObject] respondsToSelector:@selector(representedObject)])?[items valueForKey:@"representedObject"] : [items valueForKey:@"observedObject"];
Expand Down
16 changes: 11 additions & 5 deletions Quicksilver/Code-QuickStepCore/QSLibrarian.m
Expand Up @@ -356,11 +356,17 @@ - (QSCatalogEntry *)entryForID:(NSString *)theID {
}
- (QSCatalogEntry *)firstEntryContainingObject:(QSObject *)object {
NSArray *entries = [catalog deepChildrenWithGroups:NO leaves:YES disabled:NO];
for(QSCatalogEntry * entry in entries) {
//NSString *ID = [entry identifier];
if ([[entry _contents] containsObject:object])
return entry;
}
NSIndexSet *matchedIndexes = [entries indexesOfObjectsWithOptions:NSEnumerationConcurrent passingTest:^BOOL(QSCatalogEntry *entry, NSUInteger idx, BOOL *stop) {
return [[entry _contents] containsObject:object];
}];
if ([matchedIndexes count]) {
NSArray *matchedCatalogEntries = [entries objectsAtIndexes:matchedIndexes];
for (QSCatalogEntry *matchedEntry in matchedCatalogEntries) {
if (![[matchedEntry identifier] isEqualToString:@"QSPresetObjectHistory"] || matchedEntry == [matchedCatalogEntries lastObject]) {
return matchedEntry;
}
}
}
return nil;
}

Expand Down
51 changes: 48 additions & 3 deletions Quicksilver/PlugIns-Main/QSCorePlugIn/Code/QSCatalogEntrySource.m
Expand Up @@ -17,6 +17,7 @@

#define kQSCatalogEntryShowAction @"QSCatalogEntryShowAction"
#define kQSCatalogEntryRescanAction @"QSCatalogEntryRescanAction"
#define kQSCatalogAddEntryAction @"QSCatalogAddEntryAction"

static BOOL firstCheck = NO;
static NSImage *prefsCatalogImage = nil;
Expand Down Expand Up @@ -124,15 +125,59 @@ - (NSArray *)actions {
[action2 setIcon:[QSResourceManager imageNamed:@"prefsCatalog"]];
[action2 setProvider:self];
[action2 setAction:@selector(rescan:)];
return [NSArray arrayWithObjects:action, action2, nil];
QSAction *action3 = [QSAction actionWithIdentifier:kQSCatalogAddEntryAction];
[action3 setIcon:[QSResourceManager imageNamed:@"prefsCatalog"]];
[action3 setProvider:self];
[action3 setAction:@selector(addCatalogEntry:)];
return [NSArray arrayWithObjects:action, action2, action3, nil];
}

- (NSArray *)validActionsForDirectObject:(QSObject *)dObject indirectObject:(QSObject *)iObject {
return [NSArray arrayWithObjects:kQSCatalogEntryShowAction, kQSCatalogEntryRescanAction, nil];
if ([dObject count] == 1) {
return [NSArray arrayWithObjects:kQSCatalogEntryShowAction, kQSCatalogEntryRescanAction, kQSCatalogAddEntryAction, nil];
}
return nil;
}

- (QSObject *)show:(QSObject *)dObject {
[NSClassFromString(@"QSCatalogPrefPane") performSelectorOnMainThread:@selector(showEntryInCatalog:) withObject:[[QSLibrarian sharedInstance] entryForID:[dObject objectForType:QSCatalogEntryPboardType]] waitUntilDone:NO];

dispatch_sync(dispatch_get_main_queue(), ^{
id catalogPrefsClass = NSClassFromString(@"QSCatalogPrefPane");
[catalogPrefsClass showEntryInCatalog:[QSLib entryForID:[dObject objectForType:QSCatalogEntryPboardType]]];
[[catalogPrefsClass sharedInstance] reloadData];
[[catalogPrefsClass sharedInstance] selectEntry:[QSLib entryForID:[dObject objectForType:QSCatalogEntryPboardType]]];
[[catalogPrefsClass sharedInstance] showOptionsDrawer];
});
return nil;
}

- (QSObject *)addCatalogEntry:(QSObject *)dObject {
QSCatalogEntry *parentEntry = [[QSLibrarian sharedInstance] catalogCustom];

NSString *file = [[dObject objectForType:NSFilenamesPboardType] stringByStandardizingPath];
NSString *uniqueString = [NSString uniqueString];

NSMutableDictionary *childDict = [NSMutableDictionary dictionary];
[childDict setObject:uniqueString forKey:kItemID];
[childDict setObject:[NSNumber numberWithBool:YES] forKey:kItemEnabled];

[childDict setObject:[file lastPathComponent] forKey:kItemName];
[childDict setObject:@"QSFileSystemObjectSource" forKey:kItemSource];

[childDict setObject:[dObject arrayForType:NSFilenamesPboardType] forKey:kItemPath];
[childDict setObject:[NSNumber numberWithFloat:[NSDate timeIntervalSinceReferenceDate]] forKey:kItemModificationDate];

QSCatalogEntry *childEntry = [QSCatalogEntry entryWithDictionary:childDict];

[[parentEntry children] addObject:childEntry];
[[childEntry info] setObject:[NSMutableDictionary dictionaryWithObject:file forKey:kItemPath] forKey:kItemSettings];
[[childEntry info] setObject:[NSNumber numberWithDouble:[NSDate timeIntervalSinceReferenceDate]] forKey:kItemModificationDate];
[childEntry scanForced:YES];
[[NSNotificationCenter defaultCenter] postNotificationName:QSCatalogStructureChanged object:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:QSCatalogEntryChanged object:childEntry];
[dObject setObject:uniqueString forType:QSCatalogEntryPboardType];

[self show:dObject];
return nil;
}

Expand Down
17 changes: 17 additions & 0 deletions Quicksilver/PlugIns-Main/QSCorePlugIn/QSCorePlugIn-Info.plist
Expand Up @@ -1313,6 +1313,23 @@
<key>feature</key>
<integer>1</integer>
</dict>
<key>QSCatalogAddEntryAction</key>
<dict>
<key>actionClass</key>
<string>QSCatalogEntrySource</string>
<key>directTypes</key>
<array>
<string>NSFilenamesPboardType</string>
</array>
<key>precedence</key>
<real>-0.05</real>
<key>enabled</key>
<string>NO</string>
<key>actionSelector</key>
<string>addCatalogEntry:</string>
<key>icon</key>
<string>Catalog</string>
</dict>
<key>QSCatalogEntryShowAction</key>
<dict>
<key>actionClass</key>
Expand Down
Expand Up @@ -13,7 +13,7 @@
<key>AppShowHideAction</key>
<string>Toggle Visibility of %@</string>
<key>FileAlwaysOpenTypeWithAction</key>
<string>Always Open %@'s Filetype With %@</string>
<string>Always Open %@&apos;s Filetype With %@</string>
<key>QSCommandSaveAction</key>
<string>Save %@ to File</string>
<key>PasteboardPasteActionAsPlainText</key>
Expand Down Expand Up @@ -53,7 +53,7 @@
<key>AppleScriptRunAction</key>
<string>Run Script: %@</string>
<key>AppleScriptRunTextAction</key>
<string>Run '%@'</string>
<string>Run &apos;%@&apos;</string>
<key>DiskEjectAction</key>
<string>Eject %@</string>
<key>DiskForceEjectAction</key>
Expand All @@ -76,6 +76,8 @@
<string>Get absolute path of %@</string>
<key>FileGetURLAction</key>
<string>Get file:// URL of %@</string>
<key>New item</key>
<string></string>
<key>FileMakeAliasInAction</key>
<string>Make alias of %@ in %#</string>
<key>FileMakeHardLinkInAction</key>
Expand Down Expand Up @@ -112,6 +114,8 @@
<string>Resume %@</string>
<key>ProcessSuspendAction</key>
<string>Suspend %@</string>
<key>QSCatalogAddEntryAction</key>
<string>Add %@ to the Catalog</string>
<key>QSCatalogEntryRescanAction</key>
<string>Rescan %@</string>
<key>QSCatalogEntryShowAction</key>
Expand All @@ -121,7 +125,7 @@
<key>QSEditAction</key>
<string>Edit %@</string>
<key>QSLargeTypeAction</key>
<string>Show "%@" in large type</string>
<string>Show &quot;%@&quot; in large type</string>
<key>QSLoginItemAddAction</key>
<string>Add %@ to login items</string>
<key>QSLoginItemRemoveAction</key>
Expand Down Expand Up @@ -161,11 +165,11 @@
<key>QSTextDiffAction</key>
<string>Diff %@ and %#</string>
<key>QSTextShowDialogAction</key>
<string>Show dialog: \"%@\"</string>
<string>Show dialog: \&quot;%@\&quot;</string>
<key>QSTextSpeakAction</key>
<string>Say \"%@\"</string>
<string>Say \&quot;%@\&quot;</string>
<key>QSTextTypeAction</key>
<string>Type \"%@\"</string>
<string>Type \&quot;%@\&quot;</string>
<key>ShellScriptRunAction</key>
<string>Run script: %@</string>
<key>URLEmailAction</key>
Expand Down
Expand Up @@ -136,6 +136,8 @@
<string>Go To Directory in Terminal</string>
<key>QSCLTermShowManPageAction</key>
<string>Show Man Page</string>
<key>QSCatalogAddEntryAction</key>
<string>Add To Catalog</string>
<key>QSCatalogEntryRescanAction</key>
<string>Rescan Catalog Entry</string>
<key>QSCatalogEntryShowAction</key>
Expand Down