From 02cc3edfc5a0c64de768812220e78aba26aab81f Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Thu, 16 Apr 2009 13:55:04 +0000 Subject: - The connection sheet Edit button now opens the favourites list in preferences and selects appropriately; this resolves the initially planned changes for Issue #232. - Move updateDefaultFavoritePopup in SPPreferenceController to a public method and set TableDocument to update it when adding favorites --- Source/MainController.h | 3 ++ Source/MainController.m | 12 ++++++ Source/SPPreferenceController.h | 4 ++ Source/SPPreferenceController.m | 88 ++++++++++++++++++++++------------------- Source/TableDocument.m | 9 ++++- 5 files changed, 75 insertions(+), 41 deletions(-) diff --git a/Source/MainController.h b/Source/MainController.h index 962329e7..a153964d 100644 --- a/Source/MainController.h +++ b/Source/MainController.h @@ -44,6 +44,9 @@ - (IBAction)visitWebsite:(id)sender; - (IBAction)visitHelpWebsite:(id)sender; +// Getters +- (SPPreferenceController *)preferenceController; + // Other - (id)handleQuitScriptCommand:(NSScriptCommand *)command; diff --git a/Source/MainController.m b/Source/MainController.m index d59d2725..ad90531e 100644 --- a/Source/MainController.m +++ b/Source/MainController.m @@ -69,6 +69,18 @@ [prefsController showWindow:self]; } +#pragma mark - +#pragma mark Getters + +/** + * Provide a method to retrieve the prefs controller + */ +- (SPPreferenceController *)preferenceController +{ + return prefsController; +} + + #pragma mark - #pragma mark Services menu methods diff --git a/Source/SPPreferenceController.h b/Source/SPPreferenceController.h index 73819cfd..cb12cde1 100644 --- a/Source/SPPreferenceController.h +++ b/Source/SPPreferenceController.h @@ -77,4 +77,8 @@ - (IBAction)displayAutoUpdatePreferences:(id)sender; - (IBAction)displayNetworkPreferences:(id)sender; +// Other +- (void)updateDefaultFavoritePopup; +- (void)selectFavorites:(NSArray *)favorite; + @end diff --git a/Source/SPPreferenceController.m b/Source/SPPreferenceController.m index dc4b98c7..80f32e36 100644 --- a/Source/SPPreferenceController.m +++ b/Source/SPPreferenceController.m @@ -41,7 +41,6 @@ - (void)_setupToolbar; - (void)_resizeWindowForContentView:(NSView *)view; -- (void)_updateDefaultFavoritePopup; @end @@ -82,7 +81,7 @@ [favoritesTableView selectRowIndexes:[NSIndexSet indexSetWithIndex:0] byExtendingSelection:NO]; [favoritesTableView reloadData]; - [self _updateDefaultFavoritePopup]; + [self updateDefaultFavoritePopup]; } #pragma mark - @@ -236,7 +235,7 @@ [favoritesController addObject:favorite]; [favoritesTableView reloadData]; - [self _updateDefaultFavoritePopup]; + [self updateDefaultFavoritePopup]; } // ------------------------------------------------------------------------------- @@ -272,7 +271,7 @@ [favoritesController removeObjectAtArrangedObjectIndex:[favoritesTableView selectedRow]]; [favoritesTableView reloadData]; - [self _updateDefaultFavoritePopup]; + [self updateDefaultFavoritePopup]; } } @@ -308,7 +307,7 @@ [favoritesController addObject:favorite]; [favoritesTableView reloadData]; - [self _updateDefaultFavoritePopup]; + [self updateDefaultFavoritePopup]; } } @@ -501,7 +500,7 @@ if ([prefs integerForKey:@"DefaultFavorite"] == originalRow) { [prefs setInteger:destinationRow forKey:@"DefaultFavorite"]; } - [self _updateDefaultFavoritePopup]; + [self updateDefaultFavoritePopup]; return YES; } @@ -685,6 +684,49 @@ } +#pragma mark - +#pragma mark Other + + +// ------------------------------------------------------------------------------- +// updateDefaultFavoritePopup: +// +// Build the default favorite popup button +// ------------------------------------------------------------------------------- +- (void)updateDefaultFavoritePopup; +{ + [defaultFavoritePopup removeAllItems]; + + // Use the last used favorite + [defaultFavoritePopup addItemWithTitle:@"Last Used"]; + [[defaultFavoritePopup menu] addItem:[NSMenuItem separatorItem]]; + + // Load in current favorites + [defaultFavoritePopup addItemsWithTitles:[[favoritesController arrangedObjects] valueForKeyPath:@"name"]]; + + // Add item to switch to edit favorites pane + [[defaultFavoritePopup menu] addItem:[NSMenuItem separatorItem]]; + [defaultFavoritePopup addItemWithTitle:@"Edit Favorites…"]; + [[[defaultFavoritePopup menu] itemWithTitle:@"Edit Favorites…"] setAction:@selector(displayFavoritePreferences:)]; + [[[defaultFavoritePopup menu] itemWithTitle:@"Edit Favorites…"] setTarget:self]; + + // Select the default favorite from prefs + if (![prefs boolForKey:@"SelectLastFavoriteUsed"]) { + [defaultFavoritePopup selectItemAtIndex:[prefs integerForKey:@"DefaultFavorite"] + 2]; + } else { + [defaultFavoritePopup selectItemAtIndex:0]; + } +} + +// ------------------------------------------------------------------------------- +// selectFavorite: +// +// Selects the specified favorite(s) in the favorites list +// ------------------------------------------------------------------------------- +- (void)selectFavorites:(NSArray *)favorites +{ + [favoritesController setSelectedObjects:favorites]; +} @end @@ -783,38 +825,4 @@ [view setFrameOrigin:NSMakePoint(0, 0)]; } - - -// ------------------------------------------------------------------------------- -// _updateDefaultFavoritePopup: -// -// Build the default favorite popup button -// ------------------------------------------------------------------------------- -- (void)_updateDefaultFavoritePopup; -{ - [defaultFavoritePopup removeAllItems]; - - // Use the last used favorite - [defaultFavoritePopup addItemWithTitle:@"Last Used"]; - [[defaultFavoritePopup menu] addItem:[NSMenuItem separatorItem]]; - - // Load in current favorites - [defaultFavoritePopup addItemsWithTitles:[[favoritesController arrangedObjects] valueForKeyPath:@"name"]]; - - // Add item to switch to edit favorites pane - [[defaultFavoritePopup menu] addItem:[NSMenuItem separatorItem]]; - [defaultFavoritePopup addItemWithTitle:@"Edit Favorites…"]; - [[[defaultFavoritePopup menu] itemWithTitle:@"Edit Favorites…"] setAction:@selector(displayFavoritePreferences:)]; - [[[defaultFavoritePopup menu] itemWithTitle:@"Edit Favorites…"] setTarget:self]; - - // Select the default favorite from prefs - if (![prefs boolForKey:@"SelectLastFavoriteUsed"]) { - [defaultFavoritePopup selectItemAtIndex:[prefs integerForKey:@"DefaultFavorite"] + 2]; - } else { - [defaultFavoritePopup selectItemAtIndex:0]; - } -} - - - @end diff --git a/Source/TableDocument.m b/Source/TableDocument.m index f58b9b29..850ee443 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -41,6 +41,8 @@ #import "SPQueryConsole.h" #import "CMMCPConnection.h" #import "CMMCPResult.h" +#import "MainController.h" +#import "SPPreferenceController.h" //used for printing #import "MGTemplateEngine.h" @@ -409,7 +411,11 @@ NSString *TableDocumentFavoritesControllerSelectionIndexDidChange = @"TableDocum */ - (IBAction)editFavorites:(id)sender { - + SPPreferenceController *prefsController = [[NSApp delegate] preferenceController]; + + [prefsController showWindow:self]; + [prefsController displayFavoritePreferences:self]; + [prefsController selectFavorites:[favoritesController selectedObjects]]; } /** @@ -481,6 +487,7 @@ NSString *TableDocumentFavoritesControllerSelectionIndexDidChange = @"TableDocum [favoritesController addObject:newFavorite]; [favoritesController setSelectedObjects:[NSArray arrayWithObject:newFavorite]]; + [[[NSApp delegate] preferenceController] updateDefaultFavoritePopup]; } /** -- cgit v1.2.3