Skip to content

Commit

Permalink
Fix an issue where the contents of a duplicated query favorite would …
Browse files Browse the repository at this point in the history
…be overwritten if the selection was changed bevore saving (#2938)
  • Loading branch information
dmoagx committed Jan 5, 2018
1 parent 2f0099e commit b6e085e
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions Source/SPQueryFavoriteManager.m
Expand Up @@ -201,11 +201,19 @@ - (IBAction)addQueryFavorite:(id)sender
[[self window] makeFirstResponder:favoriteNameTextField];

// Duplicate a selected favorite if sender == self
if (sender == self)
favorite = [NSMutableDictionary dictionaryWithObjects:[NSArray arrayWithObjects:[[favoriteNameTextField stringValue] stringByAppendingFormat:@" Copy"], [favoriteQueryTextView string], nil] forKeys:[NSArray arrayWithObjects:@"name", @"query", nil]];
if (sender == self) {
favorite = [NSMutableDictionary dictionaryWithDictionary:@{
@"name": [NSString stringWithFormat:NSLocalizedString(@"%@ Copy", @"query favorite manager : duplicate favorite : new favorite name"),[favoriteNameTextField stringValue]],
@"query": [NSString stringWithString:[favoriteQueryTextView string]] // #2938 - without copying the string we would store the live NS*MutableString object that backs the text view and changes its contents when selection changes!
}];
}
// Add a new favorite
else
favorite = [NSMutableDictionary dictionaryWithObjects:@[@"New Favorite", @""] forKeys:@[@"name", @"query"]];
else {
favorite = [NSMutableDictionary dictionaryWithDictionary:@{
@"name": NSLocalizedString(@"New Favorite",@"query favorite manager : new favorite : name"),
@"query": @""
}];
}

// If a favourite is currently selected, add the new favourite next to it
if ([favoritesTableView numberOfSelectedRows] > 0) {
Expand Down

0 comments on commit b6e085e

Please sign in to comment.