aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPServerVariablesController.m
diff options
context:
space:
mode:
authorAbhi Beckert <abhi@abhibeckert.com>2017-04-15 08:14:41 +1000
committerAbhi Beckert <abhi@abhibeckert.com>2017-04-15 08:14:41 +1000
commitd20ad5fecb5d68f7dbee83aa56bdd1d262698bc7 (patch)
tree49bbde8fe38cb95cd2dce758b998ce08df35841b /Source/SPServerVariablesController.m
parent1d12c0e41319ffd2a1f1ab62305bd2688910f151 (diff)
parent4daa0e1419ac63abcfb87b9ba7e9f3db5861a95a (diff)
downloadsequelpro-d20ad5fecb5d68f7dbee83aa56bdd1d262698bc7.tar.gz
sequelpro-d20ad5fecb5d68f7dbee83aa56bdd1d262698bc7.tar.bz2
sequelpro-d20ad5fecb5d68f7dbee83aa56bdd1d262698bc7.zip
Merge remote-tracking branch 'sequelpro/master'
Diffstat (limited to 'Source/SPServerVariablesController.m')
-rw-r--r--Source/SPServerVariablesController.m46
1 files changed, 31 insertions, 15 deletions
diff --git a/Source/SPServerVariablesController.m b/Source/SPServerVariablesController.m
index dade0687..86bce928 100644
--- a/Source/SPServerVariablesController.m
+++ b/Source/SPServerVariablesController.m
@@ -53,6 +53,8 @@
{
if ((self = [super initWithWindowNibName:@"DatabaseServerVariables"])) {
variables = [[NSMutableArray alloc] init];
+
+ prefs = [NSUserDefaults standardUserDefaults];
}
return self;
@@ -60,8 +62,6 @@
- (void)awakeFromNib
{
- prefs = [NSUserDefaults standardUserDefaults];
-
// Set the process table view's vertical gridlines if required
[variablesTableView setGridStyleMask:([prefs boolForKey:SPDisplayTableViewVerticalGridlines]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone];
@@ -74,8 +74,7 @@
[[column dataCell] setFont:useMonospacedFont ? [NSFont fontWithName:SPDefaultMonospacedFontName size:monospacedFontSize] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
}
- // Register as an observer for the when the UseMonospacedFonts preference changes
- [prefs addObserver:self forKeyPath:SPUseMonospacedFonts options:NSKeyValueObservingOptionNew context:NULL];
+ [self _addPreferenceObservers];
}
#pragma mark -
@@ -342,13 +341,10 @@
if ((firstResponder == variablesTableView) && ([variablesTableView numberOfSelectedRows] > 0)) {
- NSString *string = @"";
+ NSMutableString *string = [[NSMutableString alloc] init];
NSIndexSet *rows = [variablesTableView selectedRowIndexes];
- NSUInteger i = [rows firstIndex];
-
- while (i != NSNotFound)
- {
+ [rows enumerateIndexesUsingBlock:^(NSUInteger i, BOOL * _Nonnull stop) {
if (i < [variablesFiltered count]) {
NSDictionary *variable = NSArrayObjectAtIndex(variablesFiltered, i);
@@ -357,29 +353,49 @@
// Decide what to include in the string
if (name && value) {
- string = [string stringByAppendingFormat:@"%@ = %@\n", variableName, variableValue];
+ [string appendFormat:@"%@ = %@\n", variableName, variableValue];
}
else {
- string = [string stringByAppendingFormat:@"%@\n", (name) ? variableName : variableValue];
+ [string appendFormat:@"%@\n", (name) ? variableName : variableValue];
}
}
-
- i = [rows indexGreaterThanIndex:i];
- }
+ }];
NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];
// Copy the string to the pasteboard
[pasteBoard declareTypes:@[NSStringPboardType] owner:nil];
[pasteBoard setString:string forType:NSStringPboardType];
+ [string release];
}
}
+/**
+ * Add any necessary preference observers to allow live updating on changes.
+ */
+- (void)_addPreferenceObservers
+{
+ // Register as an observer for the when the UseMonospacedFonts preference changes
+ [prefs addObserver:self forKeyPath:SPUseMonospacedFonts options:NSKeyValueObservingOptionNew context:NULL];
+
+ // Register to obeserve table view vertical grid line pref changes
+ [prefs addObserver:self forKeyPath:SPDisplayTableViewVerticalGridlines options:NSKeyValueObservingOptionNew context:NULL];
+}
+
+/**
+ * Remove any previously added preference observers.
+ */
+- (void)_removePreferenceObservers
+{
+ [prefs removeObserver:self forKeyPath:SPUseMonospacedFonts];
+ [prefs removeObserver:self forKeyPath:SPDisplayTableViewVerticalGridlines];
+}
+
#pragma mark -
- (void)dealloc
{
- [prefs removeObserver:self forKeyPath:SPUseMonospacedFonts];
+ [self _removePreferenceObservers];
SPClear(variables);