Permalink
Browse files

Fix an issue where the contents of a duplicated query favorite would …

…be overwritten if the selection was changed bevore saving (#2938)
  • Loading branch information...
dmoagx committed Jan 5, 2018
1 parent 2f0099e commit b6e085eb89bcea1079b7892c6a67176771a25adb
Showing with 12 additions and 4 deletions.
  1. +12 −4 Source/SPQueryFavoriteManager.m
@@ -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) {

0 comments on commit b6e085e

Please sign in to comment.