Skip to content

Commit

Permalink
Merge pull request #1532 from quicksilver/cmdHistory
Browse files Browse the repository at this point in the history
Remove duplicate commands from the command history
  • Loading branch information
skurfer committed Jul 12, 2013
2 parents 490298b + 2a3f8b8 commit 50c25fd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
10 changes: 10 additions & 0 deletions Quicksilver/Code-QuickStepCore/QSCommand.m
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,16 @@ - (QSObject *)executeIgnoringModifiers {
return [self execute];
}

- (BOOL)isEqual:(id)anObject {
if (![anObject isKindOfClass:[QSCommand class]]) {
return NO;
}
if ([anObject dObject] == [self dObject] && [anObject aObject] == [self aObject] && [anObject iObject] == [self iObject]) {
return YES;
}
return NO;
}

- (QSObject *)execute {
QSAction *actionObject = [self aObject];
QSObject *directObject = [self dObject];
Expand Down
23 changes: 17 additions & 6 deletions Quicksilver/Code-QuickStepCore/QSHistoryController.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,26 @@ - (void)addAction:(id)action {
[actionHistory removeLastObject];
}
- (void)addCommand:(QSCommand *)command {
if ([[[command dObject] identifier] isEqualToString:@"QSLastCommandProxy"]) {
if ([[[command dObject] identifier] isEqualToString:@"QSLastCommandProxy"] || !command) {
// If we're re-running the last command, don't change anything
return;
}
if (command)
[commandHistory insertObject:command atIndex:0];
while ([commandHistory count] > MAXHIST)
[commandHistory removeLastObject];
[[NSNotificationCenter defaultCenter] postNotificationName:QSCatalogEntryInvalidated object:@"QSPresetCommandHistory"];

NSUInteger existingCommandIndex = [commandHistory indexOfObject:command];
if (existingCommandIndex != NSNotFound) {
if (existingCommandIndex == 0) {
// command is already the first item in the history, no need to remove and re-add it
return;
}
[commandHistory removeObjectAtIndex:existingCommandIndex];
}
[commandHistory insertObject:command atIndex:0];
if (existingCommandIndex == NSNotFound) {
while ([commandHistory count] > MAXHIST) {
[commandHistory removeLastObject];
}
}
[[NSNotificationCenter defaultCenter] postNotificationName:QSCatalogEntryInvalidated object:@"QSPresetCommandHistory"];
}

- (void)addObject:(id)object {
Expand Down

0 comments on commit 50c25fd

Please sign in to comment.