aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/SPContentFilterManager.m112
-rw-r--r--Source/SPQueryController.m255
-rw-r--r--Source/SPTableContent.m52
3 files changed, 235 insertions, 184 deletions
diff --git a/Source/SPContentFilterManager.m b/Source/SPContentFilterManager.m
index f8bbbe27..767065d5 100644
--- a/Source/SPContentFilterManager.m
+++ b/Source/SPContentFilterManager.m
@@ -52,7 +52,7 @@
prefs = [NSUserDefaults standardUserDefaults];
contentFilters = [[NSMutableArray alloc] init];
-
+
if(managerDelegate == nil) {
NSBeep();
NSLog(@"ContentFilterManager was called without a delegate.");
@@ -64,7 +64,7 @@
filterType = [NSString stringWithString:compareType];
}
-
+
return self;
}
@@ -80,11 +80,11 @@
- (void)awakeFromNib
{
[contentFilterTextView setAllowsDocumentBackgroundColorChange:YES];
-
+
NSMutableDictionary *bindingOptions = [NSMutableDictionary dictionary];
-
+
[bindingOptions setObject:NSUnarchiveFromDataTransformerName forKey:@"NSValueTransformerName"];
-
+
[contentFilterTextView bind:@"backgroundColor"
toObject:[NSUserDefaultsController sharedUserDefaultsController]
withKeyPath:@"values.CustomQueryEditorBackgroundColor"
@@ -92,7 +92,7 @@
[contentFilters addObject:[NSDictionary dictionaryWithObjectsAndKeys:
- @"Global", @"MenuLabel",
+ @"Global", @"MenuLabel",
@"", @"headerOfFileURL",
@"", @"Clause",
@"", @"ConjunctionLabel",
@@ -111,8 +111,8 @@
// Build doc-based filters
[contentFilters addObject:[NSDictionary dictionaryWithObjectsAndKeys:
- [[[delegatesFileURL absoluteString] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding] lastPathComponent], @"MenuLabel",
- [delegatesFileURL absoluteString], @"headerOfFileURL",
+ [[[delegatesFileURL absoluteString] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding] lastPathComponent], @"MenuLabel",
+ [delegatesFileURL absoluteString], @"headerOfFileURL",
@"", @"Clause",
nil]];
if([[SPQueryController sharedQueryController] contentFilterForFileURL:delegatesFileURL]) {
@@ -134,7 +134,7 @@
// Register drag types
[contentFilterTableView registerForDraggedTypes:[NSArray arrayWithObject:SPContentFilterPasteboardDragType]];
-
+
[contentFilterArrayController setContent:contentFilters];
[contentFilterTableView reloadData];
@@ -144,7 +144,7 @@
// Set column header
[[[contentFilterTableView tableColumnWithIdentifier:@"MenuLabel"] headerCell] setStringValue:[NSString stringWithFormat:NSLocalizedString(@"‘%@’ Fields Content Filters", @"content filter for field type ‘%@’"), filterType]];
- // Set the button delegate
+ // Set the button delegate
[splitViewButtonBar setSplitViewDelegate:self];
}
@@ -169,7 +169,7 @@
// Look for the header specified by fileURL
while(i<[contentFilters count]) {
- if ([[contentFilters objectAtIndex:i] objectForKey:@"headerOfFileURL"]
+ if ([[contentFilters objectAtIndex:i] objectForKey:@"headerOfFileURL"]
&& [[[contentFilters objectAtIndex:i] objectForKey:@"headerOfFileURL"] isEqualToString:fileURLstring]) {
i++;
break;
@@ -250,7 +250,7 @@
[contentFilterTableView reloadData];
[contentFilterTableView selectRowIndexes:[NSIndexSet indexSetWithIndex:insertIndex] byExtendingSelection:NO];
-
+
[contentFilterTableView scrollRowToVisible:[contentFilterTableView selectedRow]];
[removeButton setEnabled:([contentFilterTableView numberOfSelectedRows] > 0)];
@@ -274,21 +274,21 @@
*/
- (IBAction)removeContentFilter:(id)sender
{
- NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Remove selected content filters?", @"remove selected content filters message")
+ NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Remove selected content filters?", @"remove selected content filters message")
defaultButton:NSLocalizedString(@"Remove", @"remove button")
alternateButton:NSLocalizedString(@"Cancel", @"cancel button")
otherButton:nil
informativeTextWithFormat:NSLocalizedString(@"Are you sure you want to remove all selected content filters? This action cannot be undone.", @"remove all selected content filters informative message")];
[alert setAlertStyle:NSCriticalAlertStyle];
-
+
NSArray *buttons = [alert buttons];
-
+
// Change the alert's cancel button to have the key equivalent of return
[[buttons objectAtIndex:0] setKeyEquivalent:@"r"];
[[buttons objectAtIndex:0] setKeyEquivalentModifierMask:NSCommandKeyMask];
[[buttons objectAtIndex:1] setKeyEquivalent:@"\r"];
-
+
[alert beginSheetModalForWindow:[self window] modalDelegate:self didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) contextInfo:@"removeSelectedFilters"];
}
@@ -303,9 +303,9 @@
- (IBAction)exportContentFilter:(id)sender
{
NSSavePanel *panel = [NSSavePanel savePanel];
-
+
[panel setRequiredFileType:SPFileExtensionDefault];
-
+
[panel setExtensionHidden:NO];
[panel setAllowsOtherFileTypes:NO];
[panel setCanSelectHiddenExtension:YES];
@@ -322,19 +322,19 @@
[panel setCanChooseDirectories:NO];
[panel setAllowsMultipleSelection:NO];
// [panel setResolvesAliases:YES];
-
- [panel beginSheetForDirectory:nil
- file:@""
- types:[NSArray arrayWithObjects:SPFileExtensionDefault, nil]
+
+ [panel beginSheetForDirectory:nil
+ file:@""
+ types:[NSArray arrayWithObjects:SPFileExtensionDefault, nil]
modalForWindow:[self window]
- modalDelegate:self
- didEndSelector:@selector(importPanelDidEnd:returnCode:contextInfo:)
+ modalDelegate:self
+ didEndSelector:@selector(importPanelDidEnd:returnCode:contextInfo:)
contextInfo:NULL];
}
- (IBAction)importFavoritesByReplacing:(id)sender
{
-
+
}
/**
@@ -370,7 +370,7 @@
[cf setObject:[self contentFilterForFileURL:nil] forKey:filterType];
[prefs setObject:cf forKey:SPContentFilters];
[cf release];
-
+
// Inform all opened documents to update the query favorites list
for(id doc in [[NSApp delegate] orderedDocuments])
if([[doc valueForKeyPath:@"tableContentInstance"] respondsToSelector:@selector(setCompareTypes:)])
@@ -421,7 +421,7 @@
return [[contentFilters objectAtIndex:rowIndex] objectForKey:[aTableColumn identifier]];
}
-/*
+/**
* Save content filter name (MenuLabel) if inline edited (suppress empty names)
*/
- (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
@@ -437,7 +437,7 @@
[contentFilterTableView reloadData];
}
-/*
+/**
* Before selecting an other filter save pending query string changes
* and make sure that no group table item can be selected
*/
@@ -453,7 +453,7 @@
return ([[contentFilters objectAtIndex:rowIndex] objectForKey:@"headerOfFileURL"]) ? NO : YES;
}
-/*
+/**
* Set indention levels for headers and filters
* (maybe in the future use an image for headers for expanding and collapsing)
*/
@@ -472,7 +472,7 @@
}
}
-/*
+/**
* A row of an header return is slighlty larger
*/
- (CGFloat)tableView:(NSTableView *)aTableView heightOfRow:(NSInteger)rowIndex
@@ -480,7 +480,7 @@
return ([[contentFilters objectAtIndex:rowIndex] objectForKey:@"headerOfFileURL"]) ? 20 : 18;
}
-/*
+/**
* Only filter name can be edited inline
*/
- (BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
@@ -493,7 +493,7 @@
}
}
-/*
+/**
* Sorting by clicking at a column header inside groups
*/
- (void)tableView:(NSTableView*)tableView didClickTableColumn:(NSTableColumn *)tableColumn
@@ -502,22 +502,22 @@
return;
}
-/*
+/**
* contentFilters holds the data if a table row is a group header or not
*/
- (BOOL)tableView:(NSTableView *)aTableView isGroupRow:(NSInteger)rowIndex
{
return ([[contentFilters objectAtIndex:rowIndex] objectForKey:@"headerOfFileURL"]) ? YES : NO;
}
-/*
+/**
* Detect if inline editing was done - then ESC to close the sheet will be activate
- */
+ */
- (void)controlTextDidEndEditing:(NSNotification *)aNotification
{
isTableCellEditing = NO;
}
-/*
+/**
* Changes in the name text field will be saved in data source directly
* to update the table view accordingly
*/
@@ -541,7 +541,7 @@
[contentFilterTextView insertText:@""];
}
-/*
+/**
* Parse clause and update labels accordingly
*/
- (void)textViewDidChangeSelection:(NSNotification *)notification
@@ -595,8 +595,8 @@
if([contentFilters count] < 2) return NO;
SEL action = [menuItem action];
-
- if ( (action == @selector(duplicateContentFilter:)))
+
+ if ( (action == @selector(duplicateContentFilter:)))
{
return ([contentFilterTableView numberOfSelectedRows] == 1);
}
@@ -605,7 +605,7 @@
{
return ([contentFilterTableView numberOfSelectedRows] > 0);
}
-
+
return YES;
}
@@ -642,9 +642,9 @@
* Validate the proposed drop of the supplied rows.
*/
- (NSDragOperation)tableView:(NSTableView *)tableView validateDrop:(id <NSDraggingInfo>)info proposedRow:(NSInteger)row proposedDropOperation:(NSTableViewDropOperation)operation
-{
+{
NSArray *pboardTypes = [[info draggingPasteboard] types];
-
+
if (([pboardTypes count] > 1) && (row != -1)) {
if (([pboardTypes containsObject:SPContentFilterPasteboardDragType]) && (operation == NSTableViewDropAbove)) {
if (row > 0) {
@@ -652,7 +652,7 @@
}
}
}
-
+
return NSDragOperationNone;
}
@@ -676,7 +676,7 @@
[draggedRows addObject:[NSNumber numberWithInteger:rowIndex]];
rowIndex = [draggedIndexes indexGreaterThanIndex: rowIndex];
}
-
+
NSInteger destinationRow = row;
NSInteger offset = 0;
@@ -770,14 +770,14 @@
if([[[filename pathExtension] lowercaseString] isEqualToString:SPFileExtensionDefault]) {
NSData *pData = [NSData dataWithContentsOfFile:filename options:NSUncachedRead error:&readError];
- spf = [[NSPropertyListSerialization propertyListFromData:pData
+ spf = [[NSPropertyListSerialization propertyListFromData:pData
mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError] retain];
if(!spf || readError != nil || [convError length] || !(format == NSPropertyListXMLFormat_v1_0 || format == NSPropertyListBinaryFormat_v1_0)) {
NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while reading data file", @"error while reading data file")]
- defaultButton:NSLocalizedString(@"OK", @"OK button")
- alternateButton:nil
- otherButton:nil
+ defaultButton:NSLocalizedString(@"OK", @"OK button")
+ alternateButton:nil
+ otherButton:nil
informativeTextWithFormat:NSLocalizedString(@"File couldn't be read.", @"error while reading data file")];
[alert setAlertStyle:NSCriticalAlertStyle];
@@ -803,9 +803,9 @@
[spf release];
} else {
NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while reading data file", @"error while reading data file")]
- defaultButton:NSLocalizedString(@"OK", @"OK button")
- alternateButton:nil
- otherButton:nil
+ defaultButton:NSLocalizedString(@"OK", @"OK button")
+ alternateButton:nil
+ otherButton:nil
informativeTextWithFormat:NSLocalizedString(@"No content filters found.", @"error that no content filters found")];
[alert setAlertStyle:NSInformationalAlertStyle];
@@ -832,7 +832,7 @@
NSMutableDictionary *cfdata = [NSMutableDictionary dictionary];
NSMutableArray *filterData = [NSMutableArray array];
-
+
[spfdata setObject:[NSNumber numberWithInteger:1] forKey:@"version"];
[spfdata setObject:@"content filters" forKey:@"format"];
[spfdata setObject:[NSNumber numberWithBool:NO] forKey:@"encrypted"];
@@ -847,7 +847,7 @@
[cfdata setObject:filterData forKey:filterType];
[spfdata setObject:cfdata forKey:SPContentFilters];
-
+
NSString *err = nil;
NSData *plist = [NSPropertyListSerialization dataFromPropertyList:spfdata
format:NSPropertyListXMLFormat_v1_0
@@ -855,9 +855,9 @@
if(err != nil) {
NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while converting content filter data", @"error while converting content filter data")]
- defaultButton:NSLocalizedString(@"OK", @"OK button")
- alternateButton:nil
- otherButton:nil
+ defaultButton:NSLocalizedString(@"OK", @"OK button")
+ alternateButton:nil
+ otherButton:nil
informativeTextWithFormat:err];
[alert setAlertStyle:NSCriticalAlertStyle];
diff --git a/Source/SPQueryController.m b/Source/SPQueryController.m
index 5559c946..c7f79e1f 100644
--- a/Source/SPQueryController.m
+++ b/Source/SPQueryController.m
@@ -51,7 +51,7 @@ static SPQueryController *sharedQueryController = nil;
@synthesize consoleFont;
-/*
+/**
* Returns the shared query console.
*/
+ (SPQueryController *)sharedQueryController
@@ -66,7 +66,7 @@ static SPQueryController *sharedQueryController = nil;
}
+ (id)allocWithZone:(NSZone *)zone
-{
+{
@synchronized(self) {
return [[self sharedQueryController] retain];
}
@@ -77,19 +77,19 @@ static SPQueryController *sharedQueryController = nil;
if ((self = [super initWithWindowNibName:@"Console"])) {
messagesFullSet = [[NSMutableArray alloc] init];
messagesFilteredSet = [[NSMutableArray alloc] init];
-
+
showSelectStatementsAreDisabled = NO;
showHelpStatementsAreDisabled = NO;
filterIsActive = NO;
activeFilterString = [[NSMutableString alloc] init];
-
+
// Weak reference to active messages set - starts off as full set
messagesVisibleSet = messagesFullSet;
-
+
untitledDocumentCounter = 1;
numberOfMaxAllowedHistory = 100;
allowConsoleUpdate = YES;
-
+
favoritesContainer = [[NSMutableDictionary alloc] init];
historyContainer = [[NSMutableDictionary alloc] init];
contentFilterContainer = [[NSMutableDictionary alloc] init];
@@ -101,11 +101,11 @@ static SPQueryController *sharedQueryController = nil;
NSString *convError = nil;
NSPropertyListFormat format;
NSDictionary *completionPlist;
- NSData *completionTokensData = [NSData dataWithContentsOfFile:[NSBundle pathForResource:@"CompletionTokens.plist" ofType:nil inDirectory:[[NSBundle mainBundle] bundlePath]]
+ NSData *completionTokensData = [NSData dataWithContentsOfFile:[NSBundle pathForResource:@"CompletionTokens.plist" ofType:nil inDirectory:[[NSBundle mainBundle] bundlePath]]
options:NSMappedRead error:&readError];
-
- completionPlist = [NSDictionary dictionaryWithDictionary:[NSPropertyListSerialization propertyListFromData:completionTokensData
+
+ completionPlist = [NSDictionary dictionaryWithDictionary:[NSPropertyListSerialization propertyListFromData:completionTokensData
mutabilityOption:NSPropertyListMutableContainersAndLeaves format:&format errorDescription:&convError]];
if(completionPlist == nil || readError != nil || convError != nil) {
@@ -133,11 +133,11 @@ static SPQueryController *sharedQueryController = nil;
}
}
-
+
return self;
}
-/*
+/**
* The following base protocol methods are implemented to ensure the singleton status of this class.
*/
@@ -157,34 +157,34 @@ static SPQueryController *sharedQueryController = nil;
- (void)awakeFromNib
{
prefs = [NSUserDefaults standardUserDefaults];
-
+
[self setWindowFrameAutosaveName:@"QueryConsole"];
-
+
// Show/hide table columns
[[consoleTableView tableColumnWithIdentifier:TABLEVIEW_DATE_COLUMN_IDENTIFIER] setHidden:![prefs boolForKey:SPConsoleShowTimestamps]];
[[consoleTableView tableColumnWithIdentifier:TABLEVIEW_CONNECTION_COLUMN_IDENTIFIER] setHidden:![prefs boolForKey:SPConsoleShowConnections]];
-
+
showSelectStatementsAreDisabled = ![prefs boolForKey:SPConsoleShowSelectsAndShows];
showHelpStatementsAreDisabled = ![prefs boolForKey:SPConsoleShowHelps];
-
+
[self _updateFilterState];
-
+
[loggingDisabledTextField setStringValue:([prefs boolForKey:SPConsoleEnableLogging]) ? @"" : NSLocalizedString(@"Query logging is currently disabled", @"query logging disabled label")];
-
+
// Setup data formatter
dateFormatter = [[NSDateFormatter alloc] init];
-
+
[dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
-
+
[dateFormatter setDateStyle:NSDateFormatterNoStyle];
[dateFormatter setTimeStyle:NSDateFormatterMediumStyle];
-
+
// Set the process table view's vertical gridlines if required
[consoleTableView setGridStyleMask:([prefs boolForKey:SPDisplayTableViewVerticalGridlines]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone];
// Set the strutcture and index view's font
BOOL useMonospacedFont = [prefs boolForKey:SPUseMonospacedFonts];
-
+
for (NSTableColumn *column in [consoleTableView tableColumns])
{
[[column dataCell] setFont:(useMonospacedFont) ? [NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
@@ -200,20 +200,20 @@ static SPQueryController *sharedQueryController = nil;
- (void)copy:(id)sender
{
NSResponder *firstResponder = [[self window] firstResponder];
-
+
if ((firstResponder == consoleTableView) && ([consoleTableView numberOfSelectedRows] > 0)) {
-
+
NSMutableString *string = [NSMutableString string];
NSIndexSet *rows = [consoleTableView selectedRowIndexes];
-
+
NSUInteger i = [rows firstIndex];
-
+
BOOL dateColumnIsHidden = [[consoleTableView tableColumnWithIdentifier:TABLEVIEW_DATE_COLUMN_IDENTIFIER] isHidden];
BOOL connectionColumnIsHidden = [[consoleTableView tableColumnWithIdentifier:TABLEVIEW_CONNECTION_COLUMN_IDENTIFIER] isHidden];
-
+
[string setString:@""];
-
- while (i != NSNotFound)
+
+ while (i != NSNotFound)
{
if (i < [messagesVisibleSet count]) {
SPConsoleMessage *message = NSArrayObjectAtIndex(messagesVisibleSet, i);
@@ -222,19 +222,19 @@ static SPQueryController *sharedQueryController = nil;
if (!dateColumnIsHidden)
[string appendFormat:@"/* %@ %@ ", [dateFormatter stringFromDate:[message messageDate]], (connectionColumnIsHidden) ? @"*/ ": @""];
-
+
// If the connection column is not hidden we need to include them in the copy
if (!connectionColumnIsHidden)
[string appendFormat:@"%@%@ */ ",(dateColumnIsHidden) ? @"/* " : @"", [message messageConnection]];
[string appendFormat:@"%@\n", [message message]];
}
-
+
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];
@@ -248,7 +248,7 @@ static SPQueryController *sharedQueryController = nil;
{
[messagesFullSet removeAllObjects];
[messagesFilteredSet removeAllObjects];
-
+
[consoleTableView reloadData];
}
@@ -258,15 +258,15 @@ static SPQueryController *sharedQueryController = nil;
- (IBAction)saveConsoleAs:(id)sender
{
NSSavePanel *panel = [NSSavePanel savePanel];
-
+
[panel setRequiredFileType:SPFileExtensionSQL];
-
+
[panel setExtensionHidden:NO];
[panel setAllowsOtherFileTypes:YES];
[panel setCanSelectHiddenExtension:YES];
-
+
[panel setAccessoryView:saveLogView];
-
+
[panel beginSheetForDirectory:nil file:@"untitled" modalForWindow:[self window] modalDelegate:self didEndSelector:@selector(savePanelDidEnd:returnCode:contextInfo:) contextInfo:NULL];
}
@@ -290,10 +290,10 @@ static SPQueryController *sharedQueryController = nil;
* Toggles the hiding of messages containing SELECT and SHOW statements
*/
- (IBAction)toggleShowSelectShowStatements:(id)sender
-{
+{
// Store the state of the toggle for later quick reference
showSelectStatementsAreDisabled = [sender state];
-
+
[self _updateFilterState];
}
@@ -301,10 +301,10 @@ static SPQueryController *sharedQueryController = nil;
* Toggles the hiding of messages containing HELP statements
*/
- (IBAction)toggleShowHelpStatements:(id)sender
-{
+{
// Store the state of the toggle for later quick reference
showHelpStatementsAreDisabled = [sender state];
-
+
[self _updateFilterState];
}
@@ -359,27 +359,27 @@ static SPQueryController *sharedQueryController = nil;
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
NSString *returnValue = nil;
-
+
id object = [[messagesVisibleSet objectAtIndex:row] valueForKey:[tableColumn identifier]];
-
+
if ([[tableColumn identifier] isEqualToString:TABLEVIEW_DATE_COLUMN_IDENTIFIER]) {
-
- returnValue = [dateFormatter stringFromDate:(NSDate *)object];
- }
+
+ returnValue = [dateFormatter stringFromDate:(NSDate *)object];
+ }
else {
if ([(NSString *)object length] > MESSAGE_TRUNCATE_CHARACTER_LENGTH) {
object = [NSString stringWithFormat:@"%@...", [object substringToIndex:MESSAGE_TRUNCATE_CHARACTER_LENGTH]];
}
-
+
returnValue = object;
}
-
+
NSMutableDictionary *stringAtributes = nil;
-
+
if (consoleFont) {
stringAtributes = [NSMutableDictionary dictionaryWithObject:consoleFont forKey:NSFontAttributeName];
}
-
+
// If this is an error message give it a red colour
if ([(SPConsoleMessage *)[messagesVisibleSet objectAtIndex:row] isError]) {
if (stringAtributes) {
@@ -389,7 +389,7 @@ static SPQueryController *sharedQueryController = nil;
stringAtributes = [NSMutableDictionary dictionaryWithObject:[NSColor redColor] forKey:NSForegroundColorAttributeName];
}
}
-
+
return [[[NSAttributedString alloc] initWithString:returnValue attributes:stringAtributes] autorelease];
}
@@ -402,22 +402,22 @@ static SPQueryController *sharedQueryController = nil;
- (void)controlTextDidChange:(NSNotification *)notification
{
id object = [notification object];
-
+
if ([object isEqualTo:consoleSearchField]) {
-
+
// Store the state of the text filter and the current filter string for later quick reference
[activeFilterString setString:[[object stringValue] lowercaseString]];
filterIsActive = [activeFilterString length]?YES:NO;
-
+
[self _updateFilterState];
- }
+ }
}
/**
* 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
-{
+{
// Show/hide logging disabled label
if ([keyPath isEqualToString:SPConsoleEnableLogging]) {
[loggingDisabledTextField setStringValue:([[change objectForKey:NSKeyValueChangeNewKey] boolValue]) ? @"" : @"Query logging is currently disabled"];
@@ -428,14 +428,14 @@ static SPQueryController *sharedQueryController = nil;
}
// Use monospaced fonts preference changed
else if ([keyPath isEqualToString:SPUseMonospacedFonts]) {
-
+
BOOL useMonospacedFont = [[change objectForKey:NSKeyValueChangeNewKey] boolValue];
-
+
for (NSTableColumn *column in [consoleTableView tableColumns])
{
[[column dataCell] setFont:(useMonospacedFont) ? [NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
}
-
+
[consoleTableView reloadData];
}
}
@@ -448,32 +448,38 @@ static SPQueryController *sharedQueryController = nil;
if ([menuItem action] == @selector(copy:)) {
return ([consoleTableView numberOfSelectedRows] > 0);
}
-
+
// Clear console
if ([menuItem action] == @selector(clearConsole:)) {
return ([self consoleMessageCount] > 0);
}
-
+
return [[self window] validateMenuItem:menuItem];
}
-- (BOOL) allowConsoleUpdate
+- (BOOL) allowConsoleUpdate
{
return allowConsoleUpdate;
}
-- (void) setAllowConsoleUpdate:(BOOL)allowUpdate
+- (void) setAllowConsoleUpdate:(BOOL)allowUpdate
{
allowConsoleUpdate = allowUpdate;
if (allowUpdate && [[self window] isVisible]) [self updateEntries];
}
+/**
+ * Update the Query Console and scroll to its last line.
+ */
- (void)updateEntries
{
[consoleTableView reloadData];
[consoleTableView scrollRowToVisible:([messagesVisibleSet count] - 1)];
}
+/**
+ * Return the AutoSaveName of the Query Console.
+ */
- (NSString *)windowFrameAutosaveName
{
return @"QueryConsole";
@@ -482,6 +488,9 @@ static SPQueryController *sharedQueryController = nil;
#pragma mark -
#pragma mark Completion List Controller
+/**
+ * Return an array of all pre-defined SQL functions for completion.
+ */
- (NSArray*)functionList
{
if(completionFunctionList != nil && [completionFunctionList count])
@@ -489,6 +498,9 @@ static SPQueryController *sharedQueryController = nil;
return [NSArray array];
}
+/**
+ * Return an array of all pre-defined SQL keywords for completion.
+ */
- (NSArray*)keywordList
{
if(completionKeywordList != nil && [completionKeywordList count])
@@ -496,6 +508,11 @@ static SPQueryController *sharedQueryController = nil;
return [NSArray array];
}
+/**
+ * Return the parameter list as snippet of the passed SQL functions for completion.
+ *
+ * @param func The name of the function whose parameter list is asked for
+ */
- (NSString*)argumentSnippetForFunction:(NSString*)func
{
if(functionArgumentSnippets && [functionArgumentSnippets objectForKey:[func uppercaseString]])
@@ -512,7 +529,7 @@ static SPQueryController *sharedQueryController = nil;
if(fileURL == nil) {
NSURL *new = [NSURL URLWithString:[[NSString stringWithFormat:@"Untitled %ld", (unsigned long)untitledDocumentCounter] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
untitledDocumentCounter++;
-
+
if(![favoritesContainer objectForKey:[new absoluteString]]) {
NSMutableArray *arr = [[NSMutableArray alloc] init];
[favoritesContainer setObject:arr forKey:[new absoluteString]];
@@ -541,7 +558,7 @@ static SPQueryController *sharedQueryController = nil;
return new;
}
-
+
// Register a spf file to manage all query favorites and query history items
// file path based (incl. Untitled docs) in a dictionary whereby the key represents the file URL as string.
if(![favoritesContainer objectForKey:[fileURL absoluteString]]) {
@@ -556,7 +573,7 @@ static SPQueryController *sharedQueryController = nil;
[arr release];
}
}
-
+
if(![historyContainer objectForKey:[fileURL absoluteString]]) {
if(contextInfo != nil && [contextInfo objectForKey:SPQueryHistory] && [[contextInfo objectForKey:SPQueryHistory] count]) {
NSMutableArray *arr = [[NSMutableArray alloc] init];
@@ -569,7 +586,7 @@ static SPQueryController *sharedQueryController = nil;
[arr release];
}
}
-
+
if(![contentFilterContainer objectForKey:[fileURL absoluteString]]) {
if(contextInfo != nil && [contextInfo objectForKey:SPContentFilters]) {
[contentFilterContainer setObject:[contextInfo objectForKey:SPContentFilters] forKey:[fileURL absoluteString]];
@@ -579,7 +596,7 @@ static SPQueryController *sharedQueryController = nil;
[dict release];
}
}
-
+
return fileURL;
}
@@ -703,18 +720,24 @@ static SPQueryController *sharedQueryController = nil;
NSMenuItem *historyMenuItem;
for(NSString* history in [historyContainer objectForKey:[fileURL absoluteString]]) {
historyMenuItem = [[[NSMenuItem alloc] initWithTitle:([history length] > 64) ? [NSString stringWithFormat:@"%@…", [history substringToIndex:63]] : history
- action:NULL
+ action:NULL
keyEquivalent:@""] autorelease];
[historyMenuItem setToolTip:([history length] > 256) ? [NSString stringWithFormat:@"%@…", [history substringToIndex:255]] : history];
[returnArray addObject:historyMenuItem];
}
-
+
return returnArray;
}
return [NSArray array];
}
+/**
+ * Return the number of history items for the passed file URL
+ *
+ * @param fileURL The NSURL of the current active SPDatabaseDocument
+ *
+ */
- (NSUInteger)numberOfHistoryItemsForFileURL:(NSURL *)fileURL
{
if([historyContainer objectForKey:[fileURL absoluteString]])
@@ -722,6 +745,14 @@ static SPQueryController *sharedQueryController = nil;
else
return 0;
}
+
+/**
+ * Return a mutable dictionary of all content filters for the passed file URL.
+ * If no content filters were found it returns an empty mutable dictionary.
+ *
+ * @param fileURL The NSURL of the current active SPDatabaseDocument
+ *
+ */
- (NSMutableDictionary *)contentFilterForFileURL:(NSURL *)fileURL
{
if([contentFilterContainer objectForKey:[fileURL absoluteString]])
@@ -739,7 +770,7 @@ static SPQueryController *sharedQueryController = nil;
if([fav objectForKey:@"tabtrigger"] && [[fav objectForKey:@"tabtrigger"] isEqualToString:tabTrigger])
[result addObject:fav];
}
-
+
if(includeGlobals && [prefs objectForKey:SPQueryFavorites]) {
for(id fav in [prefs objectForKey:SPQueryFavorites]) {
if([fav objectForKey:@"tabtrigger"] && [[fav objectForKey:@"tabtrigger"] isEqualToString:tabTrigger]) {
@@ -748,10 +779,18 @@ static SPQueryController *sharedQueryController = nil;
}
}
}
-
+
return [result autorelease];
}
+/**
+ * Remove a Query Favorite the passed file URL
+ *
+ * @param index The index of the to be removed favorite
+ *
+ * @param fileURL The NSURL of the current active SPDatabaseDocument
+ *
+ */
- (void)removeFavoriteAtIndex:(NSUInteger)index forFileURL:(NSURL *)fileURL
{
[[favoritesContainer objectForKey:[fileURL absoluteString]] removeObjectAtIndex:index];
@@ -771,13 +810,13 @@ static SPQueryController *sharedQueryController = nil;
{
messagesVisibleSet = nil;
[NSObject cancelPreviousPerformRequestsWithTarget:self];
-
+
[dateFormatter release], dateFormatter = nil;
-
+
[messagesFullSet release], messagesFullSet = nil;
[messagesFilteredSet release], messagesFilteredSet = nil;
[activeFilterString release], activeFilterString = nil;
-
+
[favoritesContainer release], favoritesContainer = nil;
[historyContainer release], historyContainer = nil;
[contentFilterContainer release], contentFilterContainer = nil;
@@ -798,63 +837,63 @@ static SPQueryController *sharedQueryController = nil;
*/
- (void)_updateFilterState
{
-
+
// Display start progress spinner
[progressIndicator setHidden:NO];
[progressIndicator startAnimation:self];
-
+
// Don't allow clearing the console while filtering its content
[saveConsoleButton setEnabled:NO];
[clearConsoleButton setEnabled:NO];
-
+
[messagesFilteredSet removeAllObjects];
-
+
// If filtering is disabled and all show/selects are shown, empty the filtered
// result set and set the full set to visible.
if (!filterIsActive && !showSelectStatementsAreDisabled && !showHelpStatementsAreDisabled) {
messagesVisibleSet = messagesFullSet;
-
+
[consoleTableView reloadData];
[consoleTableView scrollRowToVisible:([messagesVisibleSet count] - 1)];
-
+
[saveConsoleButton setEnabled:YES];
[clearConsoleButton setEnabled:YES];
-
+
[saveConsoleButton setTitle:NSLocalizedString(@"Save As...", @"save as button title")];
-
+
// Hide progress spinner
[progressIndicator setHidden:YES];
[progressIndicator stopAnimation:self];
return;
}
-
+
// Cache frequently used selector, avoiding dynamic binding overhead
IMP messageMatchesFilters = [self methodForSelector:@selector(_messageMatchesCurrentFilters:)];
-
+
// Loop through all the messages in the full set to determine which should be
// added to the filtered set.
- for (SPConsoleMessage *message in messagesFullSet) {
-
+ for (SPConsoleMessage *message in messagesFullSet) {
+
// Add a reference to the message to the filtered set if filters are active and the
// current message matches them
if ((messageMatchesFilters)(self, @selector(_messageMatchesCurrentFilters:), [message message])) {
[messagesFilteredSet addObject:message];
}
}
-
+
// Ensure that the filtered set is marked as the currently visible set.
messagesVisibleSet = messagesFilteredSet;
-
+
[consoleTableView reloadData];
[consoleTableView scrollRowToVisible:([messagesVisibleSet count] - 1)];
-
+
if ([messagesVisibleSet count] > 0) {
[saveConsoleButton setEnabled:YES];
[clearConsoleButton setEnabled:YES];
}
-
+
[saveConsoleButton setTitle:NSLocalizedString(@"Save View As...", @"save view as button title")];
-
+
// Hide progress spinner
[progressIndicator setHidden:YES];
[progressIndicator stopAnimation:self];
@@ -865,16 +904,16 @@ static SPQueryController *sharedQueryController = nil;
* and whether it should be hidden if the SELECT/SHOW toggle is off.
*/
- (BOOL)_messageMatchesCurrentFilters:(NSString *)message
-{
+{
BOOL messageMatchesCurrentFilters = YES;
-
+
// Check whether to hide the message based on the current filter text, if any
if (filterIsActive
&& [message rangeOfString:activeFilterString options:NSCaseInsensitiveSearch].location == NSNotFound)
{
messageMatchesCurrentFilters = NO;
}
-
+
// If hiding SELECTs and SHOWs is toggled to on, check whether the message is a SELECT or SHOW
if (messageMatchesCurrentFilters
&& showSelectStatementsAreDisabled
@@ -882,7 +921,7 @@ static SPQueryController *sharedQueryController = nil;
{
messageMatchesCurrentFilters = NO;
}
-
+
// If hiding HELP is toggled to on, check whether the message is a HELP
if (messageMatchesCurrentFilters
&& showHelpStatementsAreDisabled
@@ -890,7 +929,7 @@ static SPQueryController *sharedQueryController = nil;
{
messageMatchesCurrentFilters = NO;
}
-
+
return messageMatchesCurrentFilters;
}
@@ -901,13 +940,13 @@ static SPQueryController *sharedQueryController = nil;
- (NSString *)_getConsoleStringWithTimeStamps:(BOOL)timeStamps connections:(BOOL)connections
{
NSMutableString *consoleString = [NSMutableString string];
-
- for (SPConsoleMessage *message in messagesVisibleSet)
+
+ for (SPConsoleMessage *message in messagesVisibleSet)
{
- // As we are going to save the messages as an SQL file we need to comment
+ // As we are going to save the messages as an SQL file we need to comment
// the timestamps and connections if included.
if (timeStamps || connections) [consoleString appendString:@"/* "];
-
+
// If the timestamp column is not hidden we need to include them in the copy
if (timeStamps)
[consoleString appendFormat:@"%@ ", [dateFormatter stringFromDate:[message messageDate]]];
@@ -918,11 +957,11 @@ static SPQueryController *sharedQueryController = nil;
// Close the comment
if (timeStamps || connections) [consoleString appendString:@"*/ "];
-
+
[consoleString appendFormat:@"%@\n", [message message]];
}
-
+
return consoleString;
}
@@ -937,13 +976,13 @@ static SPQueryController *sharedQueryController = nil;
if (!error) {
messageTemp = [messageTemp stringByAppendingString:@";"];
}
-
+
SPConsoleMessage *consoleMessage = [SPConsoleMessage consoleMessageWithMessage:messageTemp date:[NSDate date] connection:connection];
-
+
[consoleMessage setIsError:error];
-
+
[messagesFullSet addObject:consoleMessage];
-
+
// If filtering is active, determine whether to add a reference to the filtered set
if ((showSelectStatementsAreDisabled || showHelpStatementsAreDisabled || filterIsActive)
&& [self _messageMatchesCurrentFilters:[consoleMessage message]])
@@ -952,7 +991,7 @@ static SPQueryController *sharedQueryController = nil;
[saveConsoleButton setEnabled:YES];
[clearConsoleButton setEnabled:YES];
}
-
+
// Reload the table and scroll to the new message if it's visible (for speed)
if (allowConsoleUpdate && [[self window] isVisible]) {
[consoleTableView noteNumberOfRowsChanged];
diff --git a/Source/SPTableContent.m b/Source/SPTableContent.m
index 77033212..122822a3 100644
--- a/Source/SPTableContent.m
+++ b/Source/SPTableContent.m
@@ -179,9 +179,12 @@
#pragma mark -
#pragma mark Table loading methods and information
-/*
+/**
* Loads aTable, retrieving column information and updating the tableViewColumns before
* reloading table data into the data array and redrawing the table.
+ *
+ * @param aTable The to be loaded table name
+ *
*/
- (void)loadTable:(NSString *)aTable
{
@@ -699,7 +702,7 @@
if (fullTableReloadRequired) [self reloadTable:self];
}
-/*
+/**
* Processes a supplied streaming result set, loading it into the data array.
*/
- (void)processResultIntoDataStorage:(MCPStreamingResult *)theResult approximateRowCount:(NSUInteger)targetRowCount
@@ -862,8 +865,9 @@
[clause replaceOccurrencesOfRegex:@"(?<!\\\\)\\$CURRENT_FIELD" withString:([fieldField titleOfSelectedItem]) ? [[fieldField titleOfSelectedItem] backtickQuotedString] : @""];
[clause flushCachedRegexData];
- // Escape % sign
- [clause replaceOccurrencesOfRegex:@"%" withString:@"%%"];
+ // Escape % sign for format insertion ie if number of arguments is greater than 0
+ if(numberOfArguments > 0)
+ [clause replaceOccurrencesOfRegex:@"%" withString:@"%%"];
[clause flushCachedRegexData];
// Replace placeholder ${} by %@
@@ -934,6 +938,14 @@
return filterString;
}
+/**
+ * Esacpe argument by looking for used quoting strings in clause
+ *
+ * @param argument The to be used filter argument which should be be escaped
+ *
+ * @param clause The entire WHERE filter clause
+ *
+ */
- (NSString *)escapeFilterArgument:(NSString *)argument againstClause:(NSString *)clause
{
@@ -959,7 +971,7 @@
return [arg autorelease];
}
-/*
+/**
* Update the table count/selection text
*/
- (void)updateCountText
@@ -1104,7 +1116,7 @@
#pragma mark -
#pragma mark Table interface actions
-/*
+/**
* Reloads the current table data, performing a new SQL query. Now attempts to preserve sort
* order, filters, and viewport. Performs the action in a new thread if a task is not already
* running.
@@ -1144,7 +1156,7 @@
[reloadPool drain];
}
-/*
+/**
* Filter the table with arguments given by the user.
* Performs the action in a new thread if necessary.
*/
@@ -1368,7 +1380,7 @@
#pragma mark -
#pragma mark Edit methods
-/*
+/**
* Collect all columns for a given 'tableForColumn' table and
* return a WHERE clause for identifying the field in quesyion.
*/
@@ -1449,7 +1461,7 @@
return fieldIDQueryStr;
}
-/*
+/**
* Adds an empty row to the table-array and goes into edit mode
*/
- (IBAction)addRow:(id)sender
@@ -2230,7 +2242,7 @@
contextInfo:nil];
}
-/*
+/**
* Tries to write a new row to the database.
* Returns YES if row is written to database, otherwise NO; also returns YES if no row
* is being edited and nothing has to be written to the database.
@@ -2399,7 +2411,7 @@
}
}
-/*
+/**
* Handle the user decision as a result of an addRow error.
*/
- (void) addRowErrorSheetDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
@@ -2419,7 +2431,7 @@
[tableContentView reloadData];
}
-/*
+/**
* A method to be called whenever the table selection changes; checks whether the current
* row is being edited, and if so attempts to save it. Returns YES if no save was necessary
* or the save was successful, and NO if a save was necessary and failed - in which case further
@@ -2581,7 +2593,7 @@
}
-/*
+/**
* Returns YES if the table contains any columns which are of any of the blob or text types,
* NO otherwise.
*/
@@ -2598,7 +2610,7 @@
return NO;
}
-/*
+/**
* Returns a string controlling which fields to retrieve for a query. Returns * (all fields) if the preferences
* option dontShowBlob isn't set; otherwise, returns a comma-separated list of all non-blob/text fields.
*/
@@ -2629,7 +2641,7 @@
}
}
-/*
+/**
* Check if table cell is editable
* Returns as array the minimum number of possible changes or
* -1 if no table name can be found or multiple table origins
@@ -2719,7 +2731,7 @@
}
-/*
+/**
* Close an open sheet.
*/
- (void)sheetDidEnd:(id)sheet returnCode:(NSInteger)returnCode contextInfo:(NSString *)contextInfo
@@ -2993,7 +3005,7 @@
}
}
-/*
+/**
* Fetches the number of rows in the selected table using a "SELECT COUNT(1)" query and return it
*/
- (NSInteger)fetchNumberOfRows
@@ -3435,7 +3447,7 @@
}
- (void)tableViewColumnDidResize:(NSNotification *)aNotification
-/*
+/**
saves the new column size in the preferences
*/
{
@@ -3746,7 +3758,7 @@
#pragma mark -
#pragma mark Other methods
-/*
+/**
* If user selected a table cell which is a blob field and tried to edit it
* cancel the fieldEditor, display the field editor sheet instead for editing
* and re-enable the fieldEditor after editing.
@@ -3818,7 +3830,7 @@
}
-/*
+/**
* Trap the enter, escape, tab and arrow keys, overriding default behaviour and continuing/ending editing,
* only within the current row.
*/