aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2009-11-13 12:05:30 +0000
committerstuconnolly <stuart02@gmail.com>2009-11-13 12:05:30 +0000
commit53b268eece1c040b71a58bb7652e360263f4d3f0 (patch)
treec4cab737ae6fa9fc585295dbe9262db74d1a3c7a /Source
parentde3b515a6988354a36fe6e6c62e050f9fa0d2444 (diff)
downloadsequelpro-53b268eece1c040b71a58bb7652e360263f4d3f0.tar.gz
sequelpro-53b268eece1c040b71a58bb7652e360263f4d3f0.tar.bz2
sequelpro-53b268eece1c040b71a58bb7652e360263f4d3f0.zip
In an aid to split up the functionality of the TableDocument class as well as reducing the overall size of DBView, split out the server variables sheet into it's own controller and XIB in the same way as the new server processes sheet is implemented.
Diffstat (limited to 'Source')
-rw-r--r--Source/SPProcessListController.m7
-rw-r--r--Source/SPServerVariablesController.h53
-rw-r--r--Source/SPServerVariablesController.m373
-rw-r--r--Source/TableDocument.h22
-rw-r--r--Source/TableDocument.m265
5 files changed, 470 insertions, 250 deletions
diff --git a/Source/SPProcessListController.m b/Source/SPProcessListController.m
index c1f52d3c..af160177 100644
--- a/Source/SPProcessListController.m
+++ b/Source/SPProcessListController.m
@@ -26,8 +26,9 @@
#import <MCPKit/MCPKit.h>
#import "SPProcessListController.h"
-#import "SPConstants.h"
#import "SPArrayAdditions.h"
+#import "TableDocument.h"
+#import "SPConstants.h"
@interface SPProcessListController (PrivateAPI)
@@ -277,9 +278,9 @@
*/
- (void)savePanelDidEnd:(NSSavePanel *)panel returnCode:(NSInteger)returnCode contextInfo:(NSString *)contextInfo
{
- if (returnCode == NSAlertDefaultReturn) {
+ if (returnCode == NSOKButton) {
if ([processesFiltered count] > 0) {
- NSMutableString *processesString = [NSMutableString string];
+ NSMutableString *processesString = [NSMutableString stringWithFormat:@"# MySQL server proceese for %@\n\n", [(TableDocument *)[[NSApp mainWindow] delegate] host]];
for (NSDictionary *process in processesFiltered)
{
diff --git a/Source/SPServerVariablesController.h b/Source/SPServerVariablesController.h
new file mode 100644
index 00000000..3b90ae83
--- /dev/null
+++ b/Source/SPServerVariablesController.h
@@ -0,0 +1,53 @@
+//
+// $Id$
+//
+// SPServerVariablesController.h
+// sequel-pro
+//
+// Created by Stuart Connolly (stuconnolly.com) on November 13, 2009
+// Copyright (c) 2009 Stuart Connolly. All rights reserved.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// More info at <http://code.google.com/p/sequel-pro/>
+
+#import <Cocoa/Cocoa.h>
+
+@class MCPConnection;
+
+@interface SPServerVariablesController : NSWindowController
+{
+ MCPConnection *connection;
+
+ NSMutableArray *variables, *variablesFiltered;
+
+ IBOutlet NSTableView *variablesTableView;
+ IBOutlet NSButton *saveVariablesButton;
+ IBOutlet NSTextField *variablesCountTextField;
+ IBOutlet NSSearchField *filterVariablesSearchField;
+}
+
+@property (readwrite, assign) MCPConnection *connection;
+
+- (IBAction)copy:(id)sender;
+- (IBAction)copyServerVariableName:(id)sender;
+- (IBAction)copyServerVariableValue:(id)sender;
+
+- (IBAction)closeSheet:(id)sender;
+- (IBAction)saveServerVariables:(id)sender;
+
+- (void)displayServerVariablesSheetAttachedToWindow:(NSWindow *)window;
+
+@end
diff --git a/Source/SPServerVariablesController.m b/Source/SPServerVariablesController.m
new file mode 100644
index 00000000..ca4f53b1
--- /dev/null
+++ b/Source/SPServerVariablesController.m
@@ -0,0 +1,373 @@
+//
+// $Id$
+//
+// SPServerVariablesController.m
+// sequel-pro
+//
+// Created by Stuart Connolly (stuconnolly.com) on November 13, 2009
+// Copyright (c) 2009 Stuart Connolly. All rights reserved.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// More info at <http://code.google.com/p/sequel-pro/>
+
+#import <MCPKit/MCPKit.h>
+
+#import "SPServerVariablesController.h"
+#import "SPArrayAdditions.h"
+#import "TableDocument.h"
+#import "SPConstants.h"
+
+@interface SPServerVariablesController (PrivateAPI)
+
+- (void)_getDatabaseServerVariables;
+- (void)_updateServerVariablesFilterForFilterString:(NSString *)filterString;
+- (void)_copyServerVariablesToPasteboardIncludingName:(BOOL)name andValue:(BOOL)value;
+
+@end
+
+@implementation SPServerVariablesController
+
+@synthesize connection;
+
+/**
+ * Initialisation
+ */
+- (id)init
+{
+ if ((self = [super initWithWindowNibName:@"DatabaseServerVariables"])) {
+ variables = [[NSMutableArray alloc] init];
+ }
+
+ return self;
+}
+
+/**
+ * Interface initialisation
+ */
+- (void)awakeFromNib
+{
+ // Set the process table view's vertical gridlines if required
+ [variablesTableView setGridStyleMask:([[NSUserDefaults standardUserDefaults] boolForKey:SPDisplayTableViewVerticalGridlines]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone];
+}
+
+#pragma mark -
+#pragma mark IBAction methods
+
+/**
+ * Copy implementation for server variables table view.
+ */
+- (IBAction)copy:(id)sender
+{
+ [self _copyServerVariablesToPasteboardIncludingName:YES andValue:YES];
+}
+
+/**
+ * Copies the name(s) of the selected server variables.
+ */
+- (IBAction)copyServerVariableName:(id)sender
+{
+ [self _copyServerVariablesToPasteboardIncludingName:YES andValue:NO];
+}
+
+/**
+ * Copies the value(s) of the selected server variables.
+ */
+- (IBAction)copyServerVariableValue:(id)sender
+{
+ [self _copyServerVariablesToPasteboardIncludingName:NO andValue:YES];
+}
+
+/**
+ * Close the server variables sheet.
+ */
+- (IBAction)closeSheet:(id)sender
+{
+ [NSApp endSheet:[self window] returnCode:[sender tag]];
+ [[self window] orderOut:self];
+
+ // If the filtered array is allocated and it's not a reference to the processes array get rid of it
+ if ((variablesFiltered) && (variablesFiltered != variables)) {
+ [variablesFiltered release], variablesFiltered = nil;
+ }
+}
+
+/**
+ * Saves the server variables to the selected file.
+ */
+- (IBAction)saveServerVariables:(id)sender
+{
+ NSSavePanel *panel = [NSSavePanel savePanel];
+
+ [panel setRequiredFileType:@"cnf"];
+
+ [panel setExtensionHidden:NO];
+ [panel setAllowsOtherFileTypes:YES];
+ [panel setCanSelectHiddenExtension:YES];
+
+ [panel beginSheetForDirectory:nil file:@"ServerVariables" modalForWindow:[self window] modalDelegate:self didEndSelector:@selector(savePanelDidEnd:returnCode:contextInfo:) contextInfo:nil];
+}
+
+
+#pragma mark -
+#pragma mark Other methods
+
+/**
+ * Displays the process list sheet attached to the supplied window.
+ */
+- (void)displayServerVariablesSheetAttachedToWindow:(NSWindow *)window
+{
+ // Weak reference
+ variablesFiltered = variables;
+
+ // Get the variables
+ [self _getDatabaseServerVariables];
+
+ // Reload the tableview
+ [variablesTableView reloadData];
+
+ // If the search field already has value from when the panel was previously open, apply the filter.
+ if ([[filterVariablesSearchField stringValue] length] > 0) {
+ [self _updateServerVariablesFilterForFilterString:[filterVariablesSearchField stringValue]];
+ }
+
+ // Open the sheet
+ [NSApp beginSheet:[self window] modalForWindow:window modalDelegate:self didEndSelector:nil contextInfo:nil];
+}
+
+/**
+ * Invoked when the save panel is dismissed.
+ */
+- (void)savePanelDidEnd:(NSSavePanel *)panel returnCode:(NSInteger)returnCode contextInfo:(NSString *)contextInfo
+{
+ if (returnCode == NSOKButton) {
+ if ([variablesFiltered count] > 0) {
+ NSMutableString *variablesString = [NSMutableString stringWithFormat:@"# MySQL server variables for %@\n\n", [(TableDocument *)[[NSApp mainWindow] delegate] host]];
+
+ for (NSDictionary *variable in variablesFiltered)
+ {
+ [variablesString appendString:[NSString stringWithFormat:@"%@ = %@\n", [variable objectForKey:@"Variable_name"], [variable objectForKey:@"Value"]]];
+ }
+
+ [variablesString writeToFile:[panel filename] atomically:YES encoding:NSUTF8StringEncoding error:NULL];
+ }
+ }
+}
+
+/**
+ * Menu item validation.
+ */
+- (BOOL)validateMenuItem:(NSMenuItem *)menuItem
+{
+ SEL action = [menuItem action];
+
+ if (action == @selector(copy:)) {
+ return ([variablesTableView numberOfSelectedRows] > 0);
+ }
+
+ // Copy selected server variable name(s)
+ if ([menuItem action] == @selector(copyServerVariableName:)) {
+ [menuItem setTitle:([variablesTableView numberOfSelectedRows] > 1) ? NSLocalizedString(@"Copy Variable Names", @"copy server variable names menu item") : NSLocalizedString(@"Copy Variable Name", @"copy server variable name menu item")];
+
+ return ([variablesTableView numberOfSelectedRows] > 0);
+ }
+
+ // Copy selected server variable value(s)
+ if ([menuItem action] == @selector(copyServerVariableValue:)) {
+ [menuItem setTitle:([variablesTableView numberOfSelectedRows] > 1) ? NSLocalizedString(@"Copy Variable Values", @"copy server variable values menu item") : NSLocalizedString(@"Copy Variable Value", @"copy server variable value menu item")];
+
+ return ([variablesTableView numberOfSelectedRows] > 0);
+ }
+
+ return YES;
+}
+
+/**
+ * This method is called as part of Key Value Observing which is used to watch for prefernce changes which effect the interface.
+ */
+- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
+{
+ if ([keyPath isEqualToString:SPDisplayTableViewVerticalGridlines]) {
+ [variablesTableView setGridStyleMask:([[change objectForKey:NSKeyValueChangeNewKey] boolValue]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone];
+ }
+}
+
+#pragma mark -
+#pragma mark Tableview delegate methods
+
+/**
+ * Table view delegate method. Returns the number of rows in the table veiw.
+ */
+- (int)numberOfRowsInTableView:(NSTableView *)tableView
+{
+ return [variablesFiltered count];
+}
+
+/**
+ * Table view delegate method. Returns the specific object for the request column and row.
+ */
+- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
+{
+ return [[variablesFiltered objectAtIndex:row] valueForKey:[tableColumn identifier]];
+}
+
+#pragma mark -
+#pragma mark Text field delegate methods
+
+/**
+ * Apply the filter string to the current process list.
+ */
+- (void)controlTextDidChange:(NSNotification *)notification
+{
+ id object = [notification object];
+
+ if (object == filterVariablesSearchField) {
+ [self _updateServerVariablesFilterForFilterString:[object stringValue]];
+ }
+}
+
+#pragma mark -
+
+/**
+ * Dealloc
+ */
+- (void)dealloc
+{
+ [variables release], variables = nil;
+
+ [super dealloc];
+}
+
+@end
+
+@implementation SPServerVariablesController (PrivateAPI)
+
+/**
+ * Gets the database's current server variables.
+ */
+- (void)_getDatabaseServerVariables
+{
+ NSUInteger i = 0;
+
+ // Get processes
+ MCPResult *serverVariables = [connection queryString:@"SHOW VARIABLES"];
+
+ if ([serverVariables numOfRows]) [serverVariables dataSeek:0];
+
+ [variables removeAllObjects];
+
+ for (i = 0; i < [serverVariables numOfRows]; i++)
+ {
+ [variables addObject:[serverVariables fetchRowAsDictionary]];
+ }
+}
+
+/**
+ * Filter the displayed server variables by matching the variable name and value against the
+ * filter string.
+ */
+- (void)_updateServerVariablesFilterForFilterString:(NSString *)filterString
+{
+ [saveVariablesButton setEnabled:NO];
+
+ filterString = [[filterString lowercaseString] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
+
+ // If the filtered array is allocated and its not a reference to the variables array
+ // relase it to prevent memory leaks upon the next allocation.
+ if ((variablesFiltered) && (variablesFiltered != variables)) {
+ [variablesFiltered release], variablesFiltered = nil;
+ }
+
+ variablesFiltered = [[NSMutableArray alloc] init];
+
+ if ([filterString length] == 0) {
+ [variablesFiltered release];
+ variablesFiltered = variables;
+
+ [saveVariablesButton setEnabled:YES];
+ [saveVariablesButton setTitle:@"Save As..."];
+ [variablesCountTextField setStringValue:@""];
+
+ [variablesTableView reloadData];
+
+ return;
+ }
+
+ for (NSDictionary *variable in variables)
+ {
+ if (([[variable objectForKey:@"Variable_name"] rangeOfString:filterString options:NSCaseInsensitiveSearch].location != NSNotFound) ||
+ ([[variable objectForKey:@"Value"] rangeOfString:filterString options:NSCaseInsensitiveSearch].location != NSNotFound))
+ {
+ [variablesFiltered addObject:variable];
+ }
+ }
+
+ [variablesTableView reloadData];
+
+ [variablesCountTextField setHidden:NO];
+ [variablesCountTextField setStringValue:[NSString stringWithFormat:NSLocalizedString(@"%d of %d", "filtered server variables count"), [variablesFiltered count], [variables count]]];
+
+ if ([variablesFiltered count] == 0) return;
+
+ [saveVariablesButton setEnabled:YES];
+ [saveVariablesButton setTitle:@"Save View As..."];
+}
+
+/**
+ * Copies either the name or value or both (as name = value pairs) of the currently selected server variables.
+ */
+- (void)_copyServerVariablesToPasteboardIncludingName:(BOOL)name andValue:(BOOL)value
+{
+ // At least one of either name or value must be true
+ if ((!name) && (!value)) return;
+
+ NSResponder *firstResponder = [[self window] firstResponder];
+
+ if ((firstResponder == variablesTableView) && ([variablesTableView numberOfSelectedRows] > 0)) {
+
+ NSString *string = @"";
+ NSIndexSet *rows = [variablesTableView selectedRowIndexes];
+
+ NSUInteger i = [rows firstIndex];
+
+ while (i != NSNotFound)
+ {
+ if (i < [variablesFiltered count]) {
+ NSDictionary *variable = NSArrayObjectAtIndex(variablesFiltered, i);
+
+ NSString *variableName = [variable objectForKey:@"Variable_name"];
+ NSString *variableValue = [variable objectForKey:@"Value"];
+
+ // Decide what to include in the string
+ if (name && value) {
+ string = [string stringByAppendingFormat:@"%@ = %@\n", variableName, variableValue];
+ }
+ else {
+ string = [string stringByAppendingFormat:@"%@\n", (name) ? variableName : variableValue];
+ }
+ }
+
+ i = [rows indexGreaterThanIndex:i];
+ }
+
+ NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];
+
+ // Copy the string to the pasteboard
+ [pasteBoard declareTypes:[NSArray arrayWithObjects:NSStringPboardType, nil] owner:nil];
+ [pasteBoard setString:string forType:NSStringPboardType];
+ }
+}
+
+@end
diff --git a/Source/TableDocument.h b/Source/TableDocument.h
index ab36ffb3..a577a6c4 100644
--- a/Source/TableDocument.h
+++ b/Source/TableDocument.h
@@ -29,7 +29,7 @@
#import <MCPKit/MCPKit.h>
#import <WebKit/WebKit.h>
-@class SPConnectionController, SPProcessListController, SPUserManager;
+@class SPConnectionController, SPProcessListController, SPServerVariablesController, SPUserManager;
enum sp_current_query_mode
{
@@ -55,8 +55,9 @@ enum sp_current_query_mode
IBOutlet id databaseDataInstance;
IBOutlet id spHistoryControllerInstance;
IBOutlet id exportControllerInstance;
+
IBOutlet SPUserManager *userManagerInstance;
-
+
IBOutlet NSSearchField *listFilterField;
IBOutlet id tableWindow;
@@ -66,7 +67,6 @@ enum sp_current_query_mode
IBOutlet id titleStringView;
IBOutlet id databaseSheet;
- IBOutlet id variablesSheet;
IBOutlet id queryProgressBar;
IBOutlet NSBox *taskProgressLayer;
@@ -81,11 +81,7 @@ enum sp_current_query_mode
IBOutlet id addDatabaseButton;
IBOutlet id chooseDatabaseButton;
IBOutlet id historyControl;
- IBOutlet id variablesTableView;
IBOutlet NSTabView *tableTabView;
- IBOutlet NSButton *saveVariablesButton;
- IBOutlet NSSearchField *variablesSearchField;
- IBOutlet NSTextField *variablesCountTextField;
IBOutlet NSTableView *tableInfoTable;
IBOutlet NSButton *tableInfoCollapseButton;
@@ -118,9 +114,11 @@ enum sp_current_query_mode
IBOutlet id inputTextWindowMessage;
IBOutlet id inputTextWindowSecureTextField;
int passwordSheetReturnCode;
-
+
+ // Controllers
SPConnectionController *connectionController;
SPProcessListController *processListController;
+ SPServerVariablesController *serverVariablesController;
MCPConnection *mySQLConnection;
@@ -183,8 +181,8 @@ enum sp_current_query_mode
- (IBAction)addDatabase:(id)sender;
- (IBAction)removeDatabase:(id)sender;
- (IBAction)showMySQLHelp:(id)sender;
-- (IBAction)saveServerVariables:(id)sender;
-- (IBAction)showDatabaseProcessList:(id)sender;
+- (IBAction)showServerVariables:(id)sender;
+- (IBAction)showServerProcesses:(id)sender;
- (IBAction)openCurrentConnectionInNewWindow:(id)sender;
- (NSArray *)allDatabaseNames;
@@ -230,7 +228,6 @@ enum sp_current_query_mode
- (void)doPerformQueryService:(NSString *)query;
- (void)doPerformLoadQueryService:(NSString *)query;
- (void)flushPrivileges:(id)sender;
-- (void)showVariables:(id)sender;
- (void)closeConnection;
- (NSWindow *)getCreateTableSyntaxWindow;
- (void)refreshCurrentDatabase;
@@ -239,9 +236,6 @@ enum sp_current_query_mode
- (BOOL)saveDocumentWithFilePath:(NSString *)fileName inBackground:(BOOL)saveInBackground onlyPreferences:(BOOL)saveOnlyPreferences;
- (IBAction)closePasswordSheet:(id)sender;
- (IBAction)backForwardInHistory:(id)sender;
-- (IBAction)copy:(id)sender;
-- (IBAction)copyServerVariableName:(id)sender;
-- (IBAction)copyServerVariableValue:(id)sender;
- (IBAction)showUserManager:(id)sender;
// Getter methods
diff --git a/Source/TableDocument.m b/Source/TableDocument.m
index 683d6237..6e3c91ca 100644
--- a/Source/TableDocument.m
+++ b/Source/TableDocument.m
@@ -53,6 +53,7 @@
#import "SPConstants.h"
#import "YRKSpinningProgressIndicator.h"
#import "SPProcessListController.h"
+#import "SPServerVariablesController.h"
// Printing
#import "MGTemplateEngine.h"
@@ -62,8 +63,6 @@
- (void)_addDatabase;
- (void)_removeDatabase;
-- (void)_updateServerVariablesFilterForFilterString:(NSString *)filterString;
-- (void)_copyServerVariablesToPasteboardIncludingName:(BOOL)name andValue:(BOOL)value;
@end
@@ -106,7 +105,6 @@
taskFadeAnimator = nil;
keyChainID = nil;
-
}
return self;
@@ -168,9 +166,6 @@
// Set the connection controller's delegate
[connectionController setDelegate:self];
- // Set the server variables table view's vertical gridlines if required
- [variablesTableView setGridStyleMask:([[NSUserDefaults standardUserDefaults] boolForKey:SPDisplayTableViewVerticalGridlines]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone];
-
// Register observers for when the DisplayTableViewVerticalGridlines preference changes
[prefs addObserver:self forKeyPath:SPDisplayTableViewVerticalGridlines options:NSKeyValueObservingOptionNew context:NULL];
[prefs addObserver:tableSourceInstance forKeyPath:SPDisplayTableViewVerticalGridlines options:NSKeyValueObservingOptionNew context:NULL];
@@ -1051,9 +1046,26 @@
}
/**
+ * Displays the database server variables sheet.
+ */
+- (IBAction)showServerVariables:(id)sender
+{
+ if (!serverVariablesController) {
+ serverVariablesController = [[SPServerVariablesController alloc] init];
+
+ [serverVariablesController setConnection:mySQLConnection];
+
+ // Register to obeserve table view vertical grid line pref changes
+ [prefs addObserver:serverVariablesController forKeyPath:SPDisplayTableViewVerticalGridlines options:NSKeyValueObservingOptionNew context:NULL];
+ }
+
+ [serverVariablesController displayServerVariablesSheetAttachedToWindow:tableWindow];
+}
+
+/**
* Displays the database process list sheet.
*/
-- (IBAction)showDatabaseProcessList:(id)sender
+- (IBAction)showServerProcesses:(id)sender
{
if (!processListController) {
processListController = [[SPProcessListController alloc] init];
@@ -2033,41 +2045,6 @@
{
[NSApp endSheet:[sender window] returnCode:[sender tag]];
[[sender window] orderOut:self];
-
- // If it was the server variables sheet that was closed release the relevant arrays if necessary
- if ([sender window] == variablesSheet) {
-
- // If the filtered array is allocated and it's not a reference to the variables array get rid of it
- if ((variablesFiltered) && (variablesFiltered != variables)) {
- [variablesFiltered release], variablesFiltered = nil;
- }
-
- if (variables) [variables release], variables = nil;
- }
-}
-
-/**
- * Copy implementation for server variables table view.
- */
-- (IBAction)copy:(id)sender
-{
- [self _copyServerVariablesToPasteboardIncludingName:YES andValue:YES];
-}
-
-/**
- * Copies the name(s) of the selected server variables.
- */
-- (IBAction)copyServerVariableName:(id)sender
-{
- [self _copyServerVariablesToPasteboardIncludingName:YES andValue:NO];
-}
-
-/**
- * Copies the value(s) of the selected server variables.
- */
-- (IBAction)copyServerVariableValue:(id)sender
-{
- [self _copyServerVariablesToPasteboardIncludingName:NO andValue:YES];
}
/**
@@ -2117,46 +2094,6 @@
}
}
-/**
- * Shows the MySQL server variables
- */
-- (void)showVariables:(id)sender
-{
- int i;
-
- [variablesCountTextField setStringValue:@""];
-
- if (variables) [variables release], variables = nil;
-
- // Get variables
- MCPResult *theResult = [mySQLConnection queryString:@"SHOW VARIABLES"];
-
- if ([theResult numOfRows]) [theResult dataSeek:0];
-
- variables = [[NSMutableArray alloc] init];
-
- for ( i = 0 ; i < [theResult numOfRows] ; i++ ) {
- [variables addObject:[theResult fetchRowAsDictionary]];
- }
-
- // Weak reference
- variablesFiltered = variables;
-
- [variablesTableView reloadData];
-
- // If the search field already has value from when the panel was previously open, apply the filter.
- if ([[variablesSearchField stringValue] length] > 0) {
- [self _updateServerVariablesFilterForFilterString:[variablesSearchField stringValue]];
- }
-
- // Show variables sheet
- [NSApp beginSheet:variablesSheet
- modalForWindow:tableWindow
- modalDelegate:self
- didEndSelector:nil
- contextInfo:nil];
-}
-
- (IBAction)openCurrentConnectionInNewWindow:(id)sender
{
TableDocument *newTableDocument;
@@ -2190,9 +2127,6 @@
if ([keyPath isEqualToString:SPConsoleEnableLogging]) {
[mySQLConnection setDelegateQueryLogging:[[change objectForKey:NSKeyValueChangeNewKey] boolValue]];
}
- else if ([keyPath isEqualToString:SPDisplayTableViewVerticalGridlines]) {
- [variablesTableView setGridStyleMask:([[change objectForKey:NSKeyValueChangeNewKey] boolValue]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone];
- }
}
/*
@@ -2811,22 +2745,6 @@
}
/**
- * Saves the server variables to the selected file.
- */
-- (IBAction)saveServerVariables:(id)sender
-{
- NSSavePanel *panel = [NSSavePanel savePanel];
-
- [panel setRequiredFileType:@"cnf"];
-
- [panel setExtensionHidden:NO];
- [panel setAllowsOtherFileTypes:YES];
- [panel setCanSelectHiddenExtension:YES];
-
- [panel beginSheetForDirectory:nil file:@"ServerVariables" modalForWindow:variablesSheet modalDelegate:self didEndSelector:@selector(savePanelDidEnd:returnCode:contextInfo:) contextInfo:@"ServerVariables"];
-}
-
-/**
* Menu item validation.
*/
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem
@@ -2911,25 +2829,6 @@
if (([menuItem action] == @selector(backForwardInHistory:)) && ([menuItem tag] == 1)) {
return (([[spHistoryControllerInstance history] count]) && (([spHistoryControllerInstance historyPosition] + 1) < [[spHistoryControllerInstance history] count]));
}
-
- // Copy selected server variable(s)
- if ([menuItem action] == @selector(copy:)) {
- return ([variablesTableView numberOfSelectedRows] > 0);
- }
-
- // Copy selected server variable name(s)
- if ([menuItem action] == @selector(copyServerVariableName:)) {
- [menuItem setTitle:([variablesTableView numberOfSelectedRows] > 1) ? NSLocalizedString(@"Copy Variable Names", @"copy server variable names menu item") : NSLocalizedString(@"Copy Variable Name", @"copy server variable name menu item")];
-
- return ([variablesTableView numberOfSelectedRows] > 0);
- }
-
- // Copy selected server variable value(s)
- if ([menuItem action] == @selector(copyServerVariableValue:)) {
- [menuItem setTitle:([variablesTableView numberOfSelectedRows] > 1) ? NSLocalizedString(@"Copy Variable Values", @"copy server variable values menu item") : NSLocalizedString(@"Copy Variable Value", @"copy server variable value menu item")];
-
- return ([variablesTableView numberOfSelectedRows] > 0);
- }
// Show/hide console
if ([menuItem action] == @selector(toggleConsole:)) {
@@ -3134,10 +3033,6 @@
[titleImageView setImage:nil];
}
-
-
-
-
#pragma mark -
#pragma mark Toolbar Methods
@@ -3396,13 +3291,13 @@
* Code that need to be executed once the windowController has loaded the document's window
* sets upt the interface (small fonts).
*/
-- (void)windowControllerDidLoadNib:(NSWindowController *) aController
+- (void)windowControllerDidLoadNib:(NSWindowController *)aController
{
[aController setShouldCascadeWindows:YES];
[super windowControllerDidLoadNib:aController];
- NSEnumerator *theCols = [[variablesTableView tableColumns] objectEnumerator];
- NSTableColumn *theCol;
+ //NSEnumerator *theCols = [[variablesTableView tableColumns] objectEnumerator];
+ //NSTableColumn *theCol;
//register for notifications
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willPerformQuery:)
@@ -3413,7 +3308,7 @@
name:@"NSApplicationWillTerminateNotification" object:nil];
//set up interface
- if ( [prefs boolForKey:SPUseMonospacedFonts] ) {
+ /*if ( [prefs boolForKey:SPUseMonospacedFonts] ) {
[[SPQueryController sharedQueryController] setConsoleFont:[NSFont fontWithName:@"Monaco" size:[NSFont smallSystemFontSize]]];
while ( (theCol = [theCols nextObject]) ) {
@@ -3425,7 +3320,7 @@
while ( (theCol = [theCols nextObject]) ) {
[[theCol dataCell] setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
}
- }
+ }*/
}
// NSWindow delegate methods
@@ -3657,11 +3552,6 @@
if (object == databaseNameField) {
[addDatabaseButton setEnabled:([[databaseNameField stringValue] length] > 0)];
}
-
- else if (object == variablesSearchField) {
- [self _updateServerVariablesFilterForFilterString:[object stringValue]];
- }
-
else if (object == saveConnectionEncryptString) {
[saveConnectionEncryptString setStringValue:[saveConnectionEncryptString stringValue]];
}
@@ -3748,21 +3638,24 @@
- (void)dealloc
{
[_encoding release];
+ [allDatabases release];
[printWebView release];
+
if (connectionController) [connectionController release];
if (processListController) [processListController release];
+ if (serverVariablesController) [serverVariablesController release];
if (mySQLConnection) [mySQLConnection release];
if (variables) [variables release];
if (selectedDatabase) [selectedDatabase release];
if (mySQLVersion) [mySQLVersion release];
- [allDatabases release];
if (taskDrawTimer) [taskDrawTimer release];
if (taskFadeAnimator) [taskFadeAnimator release];
- if(queryEditorInitString) [queryEditorInitString release];
- if(spfSession) [spfSession release];
- if(spfDocData) [spfDocData release];
- if(keyChainID) [keyChainID release];
+ if (queryEditorInitString) [queryEditorInitString release];
+ if (spfSession) [spfSession release];
+ if (spfDocData) [spfDocData release];
+ if (keyChainID) [keyChainID release];
if (taskProgressWindow) [taskProgressWindow release];
+
[super dealloc];
}
@@ -3852,98 +3745,4 @@
[tableWindow setTitle:[self displaySPName]];
}
-/**
- * Filter the displayed server variables by matching the variable name and value against the
- * filter string.
- */
-- (void)_updateServerVariablesFilterForFilterString:(NSString *)filterString
-{
- [saveVariablesButton setEnabled:NO];
-
- filterString = [[filterString lowercaseString] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
-
- // If the filtered array is allocated and its not a reference to the variables array
- // relase it to prevent memory leaks upon the next allocation.
- if ((variablesFiltered) && (variablesFiltered != variables)) {
- [variablesFiltered release], variablesFiltered = nil;
- }
-
- variablesFiltered = [[NSMutableArray alloc] init];
-
- if ([filterString length] == 0) {
- [variablesFiltered release];
- variablesFiltered = variables;
-
- [saveVariablesButton setEnabled:YES];
- [saveVariablesButton setTitle:@"Save As..."];
- [variablesCountTextField setStringValue:@""];
-
- [variablesTableView reloadData];
-
- return;
- }
-
- for (NSDictionary *variable in variables)
- {
- if (([[variable objectForKey:@"Variable_name"] rangeOfString:filterString options:NSCaseInsensitiveSearch].location != NSNotFound) ||
- ([[variable objectForKey:@"Value"] rangeOfString:filterString options:NSCaseInsensitiveSearch].location != NSNotFound))
- {
- [variablesFiltered addObject:variable];
- }
- }
-
- [variablesTableView reloadData];
- [variablesCountTextField setStringValue:[NSString stringWithFormat:NSLocalizedString(@"%d of %d", "filtered server variables count"), [variablesFiltered count], [variables count]]];
-
- if ([variablesFiltered count] == 0) return;
-
- [saveVariablesButton setEnabled:YES];
- [saveVariablesButton setTitle:@"Save View As..."];
-}
-
-/**
- * Copies either the name or value or both (as name = value pairs) of the currently selected server variables.
- */
-- (void)_copyServerVariablesToPasteboardIncludingName:(BOOL)name andValue:(BOOL)value
-{
- // At least one of either name or value must be true
- if ((!name) && (!value)) return;
-
- NSResponder *firstResponder = [variablesSheet firstResponder];
-
- if ((firstResponder == variablesTableView) && ([variablesTableView numberOfSelectedRows] > 0)) {
-
- NSString *string = @"";
- NSIndexSet *rows = [variablesTableView selectedRowIndexes];
-
- NSUInteger i = [rows firstIndex];
-
- while (i != NSNotFound)
- {
- if (i < [variablesFiltered count]) {
- NSDictionary *variable = NSArrayObjectAtIndex(variablesFiltered, i);
-
- NSString *variableName = [variable objectForKey:@"Variable_name"];
- NSString *variableValue = [variable objectForKey:@"Value"];
-
- // Decide what to include in the string
- if (name && value) {
- string = [string stringByAppendingFormat:@"%@ = %@\n", variableName, variableValue];
- }
- else {
- string = [string stringByAppendingFormat:@"%@\n", (name) ? variableName : variableValue];
- }
- }
-
- i = [rows indexGreaterThanIndex:i];
- }
-
- NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];
-
- // Copy the string to the pasteboard
- [pasteBoard declareTypes:[NSArray arrayWithObjects:NSStringPboardType, nil] owner:nil];
- [pasteBoard setString:string forType:NSStringPboardType];
- }
-}
-
@end