aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2009-04-15 23:16:05 +0000
committerrowanbeentje <rowan@beent.je>2009-04-15 23:16:05 +0000
commit303910b3fe45314d98f12b3017881a02fef68459 (patch)
tree704e64e4cbfdea2c2c18e5320ed75d36a4416740
parent6c80b88f3c29b76fec560589e67920a99681723a (diff)
downloadsequelpro-303910b3fe45314d98f12b3017881a02fef68459.tar.gz
sequelpro-303910b3fe45314d98f12b3017881a02fef68459.tar.bz2
sequelpro-303910b3fe45314d98f12b3017881a02fef68459.zip
- Update the connection sheet favourites view to bind to the preferences directly to pick up updates more quickly
- Improve favouritesAlreadyExists check to respond correctly if the connection database, host or user is blank
-rw-r--r--Interfaces/English.lproj/DBView.xib54
-rw-r--r--Source/MainController.h2
-rw-r--r--Source/TableDocument.h2
-rw-r--r--Source/TableDocument.m73
4 files changed, 55 insertions, 76 deletions
diff --git a/Interfaces/English.lproj/DBView.xib b/Interfaces/English.lproj/DBView.xib
index 008470c1..6ed622de 100644
--- a/Interfaces/English.lproj/DBView.xib
+++ b/Interfaces/English.lproj/DBView.xib
@@ -2927,7 +2927,10 @@
<reference key="NSControlView" ref="363916571"/>
<int key="NSButtonFlags">-2042609409</int>
<int key="NSButtonFlags2">35</int>
- <reference key="NSNormalImage" ref="1068138296"/>
+ <object class="NSCustomResource" key="NSNormalImage">
+ <string key="NSClassName">NSImage</string>
+ <string key="NSResourceName">button_action</string>
+ </object>
<string key="NSAlternateContents"/>
<string key="NSKeyEquivalent"/>
<int key="NSPeriodicDelay">400</int>
@@ -4110,7 +4113,6 @@
</object>
<string key="NSFrame">{{1, 17}, {213, 157}}</string>
<reference key="NSSuperview" ref="112292194"/>
- <reference key="NSNextKeyView" ref="158332213"/>
<reference key="NSDocView" ref="158332213"/>
<reference key="NSBGColor" ref="1024678221"/>
<int key="NScvFlags">4</int>
@@ -4143,7 +4145,6 @@
</object>
<string key="NSFrame">{{1, 0}, {213, 17}}</string>
<reference key="NSSuperview" ref="112292194"/>
- <reference key="NSNextKeyView" ref="975843240"/>
<reference key="NSDocView" ref="975843240"/>
<reference key="NSBGColor" ref="1024678221"/>
<int key="NScvFlags">4</int>
@@ -4152,7 +4153,6 @@
</object>
<string key="NSFrame">{{12, 34}, {215, 175}}</string>
<reference key="NSSuperview" ref="781284031"/>
- <reference key="NSNextKeyView" ref="131927425"/>
<int key="NSsFlags">562</int>
<reference key="NSVScroller" ref="785468991"/>
<reference key="NSHScroller" ref="710690013"/>
@@ -4450,7 +4450,7 @@
<object class="NSTextView" id="798764405">
<reference key="NSNextResponder" ref="593223452"/>
<int key="NSvFlags">2322</int>
- <string key="NSFrameSize">{588, 72}</string>
+ <string key="NSFrameSize">{588, 0}</string>
<reference key="NSSuperview" ref="593223452"/>
<object class="NSTextContainer" key="NSTextContainer" id="623412409">
<object class="NSLayoutManager" key="NSLayoutManager">
@@ -9908,6 +9908,10 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<string key="NSClassName">NSView</string>
</object>
<object class="NSUserDefaultsController" id="461189245">
+ <object class="NSMutableArray" key="NSDeclaredKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>favorites</string>
+ </object>
<bool key="NSSharedInstance">YES</bool>
</object>
<object class="NSArrayController" id="302582105">
@@ -11319,22 +11323,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<int key="connectionID">2275</int>
</object>
<object class="IBConnectionRecord">
- <object class="IBBindingConnection" key="connection">
- <string key="label">contentArray: favorites</string>
- <reference key="source" ref="302582105"/>
- <reference key="destination" ref="427689665"/>
- <object class="NSNibBindingConnector" key="connector">
- <reference key="NSSource" ref="302582105"/>
- <reference key="NSDestination" ref="427689665"/>
- <string key="NSLabel">contentArray: favorites</string>
- <string key="NSBinding">contentArray</string>
- <string key="NSKeyPath">favorites</string>
- <int key="NSNibBindingConnectorVersion">2</int>
- </object>
- </object>
- <int key="connectionID">3149</int>
- </object>
- <object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">argumentField</string>
<reference key="source" ref="392169872"/>
@@ -12522,6 +12510,22 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
</object>
<int key="connectionID">5379</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBBindingConnection" key="connection">
+ <string key="label">contentArray: values.favorites</string>
+ <reference key="source" ref="302582105"/>
+ <reference key="destination" ref="461189245"/>
+ <object class="NSNibBindingConnector" key="connector">
+ <reference key="NSSource" ref="302582105"/>
+ <reference key="NSDestination" ref="461189245"/>
+ <string key="NSLabel">contentArray: values.favorites</string>
+ <string key="NSBinding">contentArray</string>
+ <string key="NSKeyPath">values.favorites</string>
+ <int key="NSNibBindingConnectorVersion">2</int>
+ </object>
+ </object>
+ <int key="connectionID">5388</int>
+ </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@@ -19750,8 +19754,8 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{476, 484}, {519, 335}}</string>
- <string>{{476, 484}, {519, 335}}</string>
+ <string>{{397, 484}, {519, 335}}</string>
+ <string>{{397, 484}, {519, 335}}</string>
<reference ref="9"/>
<string>{{136, 447}, {519, 335}}</string>
<reference ref="8"/>
@@ -20755,7 +20759,7 @@ Y2hhbmdlIHRoZSBvcmRlcg</string>
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">5381</int>
+ <int key="maxID">5388</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -21269,6 +21273,7 @@ Y2hhbmdlIHRoZSBvcmRlcg</string>
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSMutableArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
+ <string>addConnectionToFavorites:</string>
<string>addDatabase:</string>
<string>analyzeTable:</string>
<string>cancelConnectSheet:</string>
@@ -21334,6 +21339,7 @@ Y2hhbmdlIHRoZSBvcmRlcg</string>
<string>id</string>
<string>id</string>
<string>id</string>
+ <string>id</string>
</object>
</object>
<object class="NSMutableDictionary" key="outlets">
diff --git a/Source/MainController.h b/Source/MainController.h
index 656cf8c0..962329e7 100644
--- a/Source/MainController.h
+++ b/Source/MainController.h
@@ -30,8 +30,6 @@
{
BOOL isNewFavorite;
- NSMutableArray *favorites;
-
SPPreferenceController *prefsController;
}
diff --git a/Source/TableDocument.h b/Source/TableDocument.h
index ad66ef55..f6019e58 100644
--- a/Source/TableDocument.h
+++ b/Source/TableDocument.h
@@ -82,7 +82,6 @@
CMMCPConnection *mySQLConnection;
- NSMutableArray *favorites;
NSArray *variables;
NSString *selectedDatabase;
NSString *mySQLVersion;
@@ -120,7 +119,6 @@
sshUser:(NSString *)sshUser // no-longer in use
sshPassword:(NSString *)sshPassword // no-longer in use
sshPort:(NSString *)sshPort; // no-longer in use
-- (NSMutableArray *)favorites;
- (NSString *)getHTMLforPrint;
diff --git a/Source/TableDocument.m b/Source/TableDocument.m
index 1d8ac450..97e3ecbc 100644
--- a/Source/TableDocument.m
+++ b/Source/TableDocument.m
@@ -47,7 +47,6 @@
#import "ICUTemplateMatcher.h"
NSString *TableDocumentFavoritesControllerSelectionIndexDidChange = @"TableDocumentFavoritesControllerSelectionIndexDidChange";
-NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocumentFavoritesControllerFavoritesDidChange";
@interface TableDocument (PrivateAPI)
@@ -74,9 +73,6 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocum
// register selection did change handler for favorites controller (used in connect sheet)
[favoritesController addObserver:self forKeyPath:@"selectionIndex" options:NSKeyValueChangeInsertion context:TableDocumentFavoritesControllerSelectionIndexDidChange];
- // register value change handler for favourites, so we can save them to preferences
- [self addObserver:self forKeyPath:@"favorites" options:0 context:TableDocumentFavoritesControllerFavoritesDidChange];
-
// register double click for the favorites view (double click favorite to connect)
[connectFavoritesTableView setTarget:self];
@@ -93,12 +89,7 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocum
[self chooseFavorite:self];
return;
}
-
- if (context == TableDocumentFavoritesControllerFavoritesDidChange) {
- [prefs setObject:[self favorites] forKey:@"favorites"];
- return;
- }
-
+
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
@@ -265,10 +256,6 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocum
- (IBAction)connect:(id)sender
{
int code;
-
- // Save the favourites - commits any unsaved changes ie favourite renames
- [prefs setObject:[self favorites] forKey:@"favorites"];
- [prefs synchronize];
[connectProgressBar startAnimation:self];
[connectProgressStatusText setHidden:NO];
@@ -441,24 +428,6 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocum
}
/**
- * Return the favorites array.
- */
-- (NSMutableArray *)favorites
-{
- // if no favorites, load from user defaults
- if (!favorites) {
- favorites = [[NSMutableArray alloc] initWithArray:[[NSUserDefaults standardUserDefaults] objectForKey:@"favorites"]];
- }
-
- // if no favorites in user defaults, load empty ones
- if (!favorites) {
- favorites = [[NSMutableArray array] retain];
- }
-
- return favorites;
-}
-
-/**
* returns a KVC-compliant proxy to the currently selected favorite, or nil if nothing selected.
*
* see [NSObjectController selection]
@@ -516,20 +485,16 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocum
return;
}
- [self willChangeValueForKey:@"favorites"];
-
// write favorites and password
NSMutableDictionary *newFavorite = [NSMutableDictionary dictionaryWithObjects:[NSArray arrayWithObjects:favoriteName, host, socket, user, port, database, favoriteid, nil]
forKeys:[NSArray arrayWithObjects:@"name", @"host", @"socket", @"user", @"port", @"database", @"id", nil]];
- [favorites addObject:newFavorite];
-
if (![password isEqualToString:@""]) {
[keyChainInstance addPassword:password
forName:[NSString stringWithFormat:@"Sequel Pro : %@ (%i)", favoriteName, [favoriteid intValue]]
account:[NSString stringWithFormat:@"%@@%@/%@", user, host, database]];
}
- [self didChangeValueForKey:@"favorites"];
+ [favoritesController addObject:newFavorite];
[favoritesController setSelectedObjects:[NSArray arrayWithObject:newFavorite]];
}
@@ -1892,12 +1857,11 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocum
* When a favorite is selected, and the connection details are edited, deselect the favorite;
* this is clearer and also prevents a failed connection from being repopulated with the
* favorite's details instead of the last used details.
- * This method allows the password to be changed without altering the selection.
*/
- (void) controlTextDidChange:(NSNotification *)aNotification
{
- if ([aNotification object] == hostField || [aNotification object] == userField || [aNotification object] == databaseField
- || [aNotification object] == socketField || [aNotification object] == portField) {
+ if ([aNotification object] == hostField || [aNotification object] == userField || [aNotification object] == passwordField
+ || [aNotification object] == databaseField || [aNotification object] == socketField || [aNotification object] == portField) {
[favoritesController setSelectionIndexes:[NSIndexSet indexSet]];
}
else if ([aNotification object] == databaseNameField) {
@@ -1998,8 +1962,9 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocum
*/
- (void)tableView:(NSTableView *)tableView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)rowIndex
{
- NSDictionary *favorite = [favorites objectAtIndex:rowIndex];
-
+ NSDictionary *favorite = [[favoritesController arrangedObjects] objectAtIndex:rowIndex];
+ NSMutableDictionary *newFavorite;
+
[keyChainInstance deletePasswordForName:[NSString stringWithFormat:@"Sequel Pro : %@ (%i)", favoriteNameBeingChanged, [[favorite objectForKey:@"id"] intValue]]
account:[NSString stringWithFormat:@"%@@%@/%@", [favorite objectForKey:@"user"], [favorite objectForKey:@"host"], [favorite objectForKey:@"database"]]];
@@ -2009,6 +1974,13 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocum
account:[NSString stringWithFormat:@"%@@%@/%@", [favorite objectForKey:@"user"], [favorite objectForKey:@"host"], [favorite objectForKey:@"database"]]];
}
+ // Update the favorites array controller
+ newFavorite = [NSMutableDictionary dictionaryWithDictionary:favorite];
+ [newFavorite setObject:[NSString stringWithString:object] forKey:@"name"];
+ [favoritesController insertObject:newFavorite atArrangedObjectIndex:rowIndex];
+ [favoritesController removeObjectAtArrangedObjectIndex:(rowIndex+1)];
+ [favoritesController setSelectionIndex:rowIndex];
+
favoriteNameBeingChanged = nil;
}
@@ -2019,7 +1991,7 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocum
*/
- (BOOL)tableView:(NSTableView *)tableView shouldEditTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)rowIndex
{
- favoriteNameBeingChanged = [[favorites objectAtIndex:rowIndex] objectForKey:@"name"];
+ favoriteNameBeingChanged = [[[favoritesController arrangedObjects] objectAtIndex:rowIndex] objectForKey:@"name"];
return YES;
}
@@ -2034,7 +2006,6 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocum
{
[chooseDatabaseButton release];
[mySQLConnection release];
- [favorites release];
[variables release];
[selectedDatabase release];
[mySQLVersion release];
@@ -2051,14 +2022,20 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocum
* Checks to see if a favorite with the supplied details already exists.
*/
- (BOOL)_favoriteAlreadyExists:(NSString *)database host:(NSString *)host user:(NSString *)user
-{
+{
+ NSArray *favorites = [favoritesController arrangedObjects];
+
+ // Ensure database, host, and user match prefs format
+ if (!database) database = @"";
+ if (!host) host = @"";
+ if (!user) user = @"";
+
// Loop the favorites and check their details
- for (NSDictionary *favorite in favorites)
- {
+ for (NSDictionary *favorite in favorites)
+ {
if ([[favorite objectForKey:@"database"] isEqualToString:database] &&
[[favorite objectForKey:@"host"] isEqualToString:host] &&
[[favorite objectForKey:@"user"] isEqualToString:user]) {
-
return YES;
}
}