diff options
author | Bibiko <bibiko@eva.mpg.de> | 2010-02-05 11:37:30 +0000 |
---|---|---|
committer | Bibiko <bibiko@eva.mpg.de> | 2010-02-05 11:37:30 +0000 |
commit | 64567b12a8e9449ea3e23e20f0d236a9bde24dad (patch) | |
tree | e7d96960c5c695ac3afab0fca057dc0b63c5f83c | |
parent | f880dea7369cb6ce57c552cd359f871bf7e2e414 (diff) | |
download | sequelpro-64567b12a8e9449ea3e23e20f0d236a9bde24dad.tar.gz sequelpro-64567b12a8e9449ea3e23e20f0d236a9bde24dad.tar.bz2 sequelpro-64567b12a8e9449ea3e23e20f0d236a9bde24dad.zip |
• refactored the entire history logic in Custom Query
- queries which are longer than then 64 chars are truncated in title and queries which are longer than then 256 chars are truncated in tooltip to avoid processing time to load very long queries from history; this also decreases the memory usage
- added "Insert Next/Previous History Query" logic bound to ^↑ and ^↓
- fixed tiny GUI spacing problem in Custom Query
-rw-r--r-- | Interfaces/English.lproj/DBView.xib | 246 | ||||
-rw-r--r-- | Source/CustomQuery.h | 5 | ||||
-rw-r--r-- | Source/CustomQuery.m | 105 | ||||
-rw-r--r-- | Source/SPQueryController.h | 2 | ||||
-rw-r--r-- | Source/SPQueryController.m | 26 |
5 files changed, 336 insertions, 48 deletions
diff --git a/Interfaces/English.lproj/DBView.xib b/Interfaces/English.lproj/DBView.xib index 784d7bf5..2fe957de 100644 --- a/Interfaces/English.lproj/DBView.xib +++ b/Interfaces/English.lproj/DBView.xib @@ -23,9 +23,8 @@ </object> <object class="NSMutableArray" key="IBDocument.EditedObjectIDs"> <bool key="EncodedWithXMLCoder">YES</bool> - <integer value="5"/> <integer value="6232"/> - <integer value="4566"/> + <integer value="663"/> </object> <object class="NSArray" key="IBDocument.PluginDependencies"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -3393,6 +3392,7 @@ </object> </object> </object> + <int key="NSSelectedIndex">1</int> <bool key="NSPullDown">YES</bool> <int key="NSPreferredEdge">3</int> <bool key="NSUsesItemFromMenu">YES</bool> @@ -3403,7 +3403,7 @@ <object class="NSPopUpButton" id="363916571"> <reference key="NSNextResponder" ref="345834048"/> <int key="NSvFlags">268</int> - <string key="NSFrame">{{-10, 245}, {46, 25}}</string> + <string key="NSFrame">{{-10, 245}, {48, 25}}</string> <reference key="NSSuperview" ref="345834048"/> <bool key="NSEnabled">YES</bool> <object class="NSPopUpButtonCell" key="NSCell" id="984501775"> @@ -3476,7 +3476,6 @@ </object> <object class="NSMenuItem" id="413416694"> <reference key="NSMenu" ref="60735230"/> - <bool key="NSIsHidden">YES</bool> <string key="NSTitle">Previous Query from History</string> <string key="NSKeyEquiv"></string> <int key="NSKeyEquivModMask">262144</int> @@ -3489,7 +3488,6 @@ </object> <object class="NSMenuItem" id="233912625"> <reference key="NSMenu" ref="60735230"/> - <bool key="NSIsHidden">YES</bool> <string key="NSTitle">Next Query from History</string> <string key="NSKeyEquiv"></string> <int key="NSKeyEquivModMask">262144</int> @@ -3674,7 +3672,7 @@ </object> <bool key="NSNoAutoenable">YES</bool> </object> - <int key="NSSelectedIndex">17</int> + <int key="NSSelectedIndex">4</int> <bool key="NSPullDown">YES</bool> <int key="NSPreferredEdge">1</int> <bool key="NSUsesItemFromMenu">YES</bool> @@ -8542,7 +8540,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> <string key="NSWindowContentMaxSize">{3.40282e+38, 3.40282e+38}</string> <string key="NSWindowContentMinSize">{350, 250}</string> <object class="NSView" key="NSWindowView" id="1024486775"> - <reference key="NSNextResponder"/> + <nil key="NSNextResponder"/> <int key="NSvFlags">256</int> <object class="NSMutableArray" key="NSSubviews"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -8739,7 +8737,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> </object> <string key="NSFrame">{{1, 17}, {423, 141}}</string> <reference key="NSSuperview" ref="1041893843"/> - <reference key="NSNextKeyView" ref="134631251"/> <reference key="NSDocView" ref="134631251"/> <reference key="NSBGColor" ref="1024678221"/> <int key="NScvFlags">6</int> @@ -8773,7 +8770,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> </object> <string key="NSFrame">{{1, 0}, {423, 17}}</string> <reference key="NSSuperview" ref="1041893843"/> - <reference key="NSNextKeyView" ref="568493807"/> <reference key="NSDocView" ref="568493807"/> <reference key="NSBGColor" ref="1024678221"/> <int key="NScvFlags">4</int> @@ -8782,7 +8778,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> </object> <string key="NSFrame">{{20, 45}, {425, 159}}</string> <reference key="NSSuperview" ref="1024486775"/> - <reference key="NSNextKeyView" ref="68425806"/> <int key="NSsFlags">530</int> <reference key="NSVScroller" ref="99652168"/> <reference key="NSHScroller" ref="1053700221"/> @@ -8927,7 +8922,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> </object> </object> <string key="NSFrameSize">{465, 294}</string> - <reference key="NSSuperview"/> </object> <string key="NSScreenRect">{{0, 0}, {1920, 1178}}</string> <string key="NSMinSize">{350, 272}</string> @@ -15201,6 +15195,38 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> </object> <int key="connectionID">6759</int> </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">previousHistoryMenuItem</string> + <reference key="source" ref="601471102"/> + <reference key="destination" ref="413416694"/> + </object> + <int key="connectionID">6760</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBActionConnection" key="connection"> + <string key="label">gearMenuItemSelected:</string> + <reference key="source" ref="601471102"/> + <reference key="destination" ref="413416694"/> + </object> + <int key="connectionID">6761</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">nextHistoryMenuItem</string> + <reference key="source" ref="601471102"/> + <reference key="destination" ref="233912625"/> + </object> + <int key="connectionID">6762</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBActionConnection" key="connection"> + <string key="label">gearMenuItemSelected:</string> + <reference key="source" ref="601471102"/> + <reference key="destination" ref="233912625"/> + </object> + <int key="connectionID">6763</int> + </object> </object> <object class="IBMutableOrderedSet" key="objectRecords"> <object class="NSArray" key="orderedObjects"> @@ -22166,7 +22192,9 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> <string>5289.IBPluginDependency</string> <string>5290.IBPluginDependency</string> <string>5291.IBPluginDependency</string> + <string>5292.IBAttributePlaceholdersKey</string> <string>5292.IBPluginDependency</string> + <string>5293.IBAttributePlaceholdersKey</string> <string>5293.IBPluginDependency</string> <string>5295.IBPluginDependency</string> <string>5296.IBPluginDependency</string> @@ -23079,7 +23107,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> <integer value="1"/> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <integer value="1"/> - <string>{{510, 680}, {212, 108}}</string> + <string>{{1640, 470}, {212, 108}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <integer value="1"/> <object class="NSMutableDictionary"> @@ -23104,7 +23132,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> </object> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <integer value="1"/> - <string>{{600, 690}, {212, 108}}</string> + <string>{{517, 559}, {212, 108}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <integer value="1"/> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> @@ -23663,10 +23691,10 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <integer value="1"/> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>{{139, 140}, {944, 550}}</string> + <string>{{148, 290}, {944, 550}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <boolean value="NO"/> - <string>{{139, 140}, {944, 550}}</string> + <string>{{148, 290}, {944, 550}}</string> <integer value="1"/> <integer value="1"/> <string>{{62, 352}, {845, 504}}</string> @@ -23832,7 +23860,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>{{522, 364}, {256, 445}}</string> + <string>{{1592, 135}, {256, 445}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> @@ -23840,7 +23868,23 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <object class="NSMutableDictionary"> + <string key="NS.key.0">ToolTip</string> + <object class="IBToolTipAttribute" key="NS.object.0"> + <string key="name">ToolTip</string> + <reference key="object" ref="413416694"/> + <string key="toolTip">Replaces the current query by the previous one coming from the history.</string> + </object> + </object> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <object class="NSMutableDictionary"> + <string key="NS.key.0">ToolTip</string> + <object class="IBToolTipAttribute" key="NS.object.0"> + <string key="name">ToolTip</string> + <reference key="object" ref="233912625"/> + <string key="toolTip">Replaces the current query by the next one coming from the history.</string> + </object> + </object> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> @@ -24852,7 +24896,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> </object> </object> <nil key="sourceID"/> - <int key="maxID">6759</int> + <int key="maxID">6763</int> </object> <object class="IBClassDescriber" key="IBDocument.Classes"> <object class="NSMutableArray" key="referencedPartialClassDescriptions"> @@ -26439,6 +26483,174 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> <object class="NSMutableArray" key="referencedPartialClassDescriptionsV3.1+"> <bool key="EncodedWithXMLCoder">YES</bool> <object class="IBPartialClassDescription"> + <string key="className">CustomQuery</string> + <string key="superclassName">NSObject</string> + <object class="NSMutableDictionary" key="actions"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="NSArray" key="dict.sortedKeys"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>chooseQueryFavorite:</string> + <string>chooseQueryHistory:</string> + <string>clearQueryHistory:</string> + <string>closeSheet:</string> + <string>copyQueryHistory:</string> + <string>filterQueryFavorites:</string> + <string>filterQueryHistory:</string> + <string>gearMenuItemSelected:</string> + <string>helpSearchFindNextInPage:</string> + <string>helpSearchFindPreviousInPage:</string> + <string>helpSegmentDispatcher:</string> + <string>helpSelectHelpTargetMySQL:</string> + <string>helpSelectHelpTargetPage:</string> + <string>helpSelectHelpTargetWeb:</string> + <string>helpTargetDispatcher:</string> + <string>runAllQueries:</string> + <string>runSelectedQueries:</string> + <string>saveQueryHistory:</string> + <string>showAutoHelpForCurrentWord:</string> + <string>showHelpForCurrentWord:</string> + <string>showHelpForSearchString:</string> + </object> + <object class="NSMutableArray" key="dict.values"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>id</string> + <string>id</string> + <string>id</string> + <string>id</string> + <string>id</string> + <string>id</string> + <string>id</string> + <string>id</string> + <string>id</string> + <string>id</string> + <string>id</string> + <string>id</string> + <string>id</string> + <string>id</string> + <string>id</string> + <string>id</string> + <string>id</string> + <string>id</string> + <string>id</string> + <string>id</string> + <string>id</string> + </object> + </object> + <object class="NSMutableDictionary" key="outlets"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="NSArray" key="dict.sortedKeys"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>affectedRowsText</string> + <string>autohelpMenuItem</string> + <string>autoindentMenuItem</string> + <string>autopairMenuItem</string> + <string>autouppercaseKeywordsMenuItem</string> + <string>clearHistoryMenuItem</string> + <string>commentCurrentQueryMenuItem</string> + <string>commentLineOrSelectionMenuItem</string> + <string>completionListMenuItem</string> + <string>copyHistoryMenuItem</string> + <string>customQueryScrollView</string> + <string>customQueryView</string> + <string>editorFontMenuItem</string> + <string>encodingPopUp</string> + <string>errorText</string> + <string>helpNavigator</string> + <string>helpSearchField</string> + <string>helpSearchFieldCell</string> + <string>helpTargetSelector</string> + <string>helpWebView</string> + <string>helpWebViewWindow</string> + <string>multipleLineEditingButton</string> + <string>nextHistoryMenuItem</string> + <string>previousHistoryMenuItem</string> + <string>queryFavoriteNameTextField</string> + <string>queryFavoritesButton</string> + <string>queryFavoritesSaveAllMenuItem</string> + <string>queryFavoritesSaveAsMenuItem</string> + <string>queryFavoritesSearchField</string> + <string>queryFavoritesSearchFieldView</string> + <string>queryFavoritesSearchMenuItem</string> + <string>queryFavoritesSheet</string> + <string>queryHistoryButton</string> + <string>queryHistorySearchField</string> + <string>queryHistorySearchFieldView</string> + <string>queryHistorySearchMenuItem</string> + <string>runAllButton</string> + <string>runAllMenuItem</string> + <string>runSelectionButton</string> + <string>runSelectionMenuItem</string> + <string>saveHistoryMenuItem</string> + <string>saveQueryFavoriteButton</string> + <string>saveQueryFavoriteGlobal</string> + <string>shiftLeftMenuItem</string> + <string>shiftRightMenuItem</string> + <string>tableDocumentInstance</string> + <string>tableWindow</string> + <string>textView</string> + <string>valueSheet</string> + <string>valueTextField</string> + </object> + <object class="NSMutableArray" key="dict.values"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>id</string> + <string>NSMenuItem</string> + <string>NSMenuItem</string> + <string>NSMenuItem</string> + <string>NSMenuItem</string> + <string>NSMenuItem</string> + <string>NSMenuItem</string> + <string>NSMenuItem</string> + <string>NSMenuItem</string> + <string>NSMenuItem</string> + <string>NSScrollView</string> + <string>CMCopyTable</string> + <string>NSMenuItem</string> + <string>NSPopUpButton</string> + <string>id</string> + <string>NSSegmentedControl</string> + <string>NSSearchField</string> + <string>NSSearchFieldCell</string> + <string>NSSegmentedControl</string> + <string>WebView</string> + <string>NSWindow</string> + <string>id</string> + <string>NSMenuItem</string> + <string>NSMenuItem</string> + <string>NSTextField</string> + <string>id</string> + <string>NSMenuItem</string> + <string>NSMenuItem</string> + <string>NSSearchField</string> + <string>id</string> + <string>NSMenuItem</string> + <string>NSWindow</string> + <string>id</string> + <string>NSSearchField</string> + <string>id</string> + <string>NSMenuItem</string> + <string>id</string> + <string>NSMenuItem</string> + <string>id</string> + <string>NSMenuItem</string> + <string>NSMenuItem</string> + <string>NSButton</string> + <string>id</string> + <string>NSMenuItem</string> + <string>NSMenuItem</string> + <string>id</string> + <string>id</string> + <string>CMTextView</string> + <string>id</string> + <string>id</string> + </object> + </object> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBDocumentRelativeSource</string> + <string key="minorKey">../../Source/CustomQuery.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> <string key="className">TableDump</string> <string key="superclassName">NSObject</string> <object class="NSMutableDictionary" key="actions"> diff --git a/Source/CustomQuery.h b/Source/CustomQuery.h index e92dc4f0..8994a7e3 100644 --- a/Source/CustomQuery.h +++ b/Source/CustomQuery.h @@ -100,6 +100,8 @@ IBOutlet NSMenuItem *autouppercaseKeywordsMenuItem; IBOutlet NSMenuItem *commentCurrentQueryMenuItem; IBOutlet NSMenuItem *commentLineOrSelectionMenuItem; + IBOutlet NSMenuItem *previousHistoryMenuItem; + IBOutlet NSMenuItem *nextHistoryMenuItem; IBOutlet NSWindow *helpWebViewWindow; IBOutlet WebView *helpWebView; @@ -146,6 +148,9 @@ NSUInteger numberOfQueries; NSUInteger queryTextViewStartPosition; + + NSInteger currentHistoryOffsetIndex; + BOOL historyItemWasJustInserted; } // IBAction methods diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m index 2d1dae4d..b26cf828 100644 --- a/Source/CustomQuery.m +++ b/Source/CustomQuery.m @@ -242,7 +242,7 @@ if(replaceContent) [textView setSelectedRange:NSMakeRange(0,[[textView string] length])]; - [textView insertText:[queryHistoryButton titleOfSelectedItem]]; + [textView insertText:[[[SPQueryController sharedQueryController] historyForFileURL:[tableDocumentInstance fileURL]] objectAtIndex:[queryHistoryButton indexOfSelectedItem]-7]]; } } @@ -262,6 +262,46 @@ - (IBAction)gearMenuItemSelected:(id)sender { + if ( sender == previousHistoryMenuItem ) { + NSInteger numberOfHistoryItems = [[SPQueryController sharedQueryController] numberOfHistoryItemsForFileURL:[tableDocumentInstance fileURL]]; + currentHistoryOffsetIndex++; + NSLog(@"%ld + %ld", numberOfHistoryItems, currentHistoryOffsetIndex); + if ( numberOfHistoryItems > 0 && currentHistoryOffsetIndex < numberOfHistoryItems && currentHistoryOffsetIndex >= 0) { + historyItemWasJustInserted = YES; + // if(![textView selectedRange].length) + // [textView setSelectedRange:currentQueryRange]; + [textView breakUndoCoalescing]; + NSString *historyString = [[[SPQueryController sharedQueryController] historyForFileURL:[tableDocumentInstance fileURL]] objectAtIndex:currentHistoryOffsetIndex]; + NSRange rangeOfInsertedString = NSMakeRange([textView selectedRange].location, [historyString length]); + [textView insertText:historyString]; + [textView setSelectedRange:rangeOfInsertedString]; + } else { + currentHistoryOffsetIndex--; + NSBeep(); + } + historyItemWasJustInserted = NO; + } + + if ( sender == nextHistoryMenuItem ) { + NSInteger numberOfHistoryItems = [[SPQueryController sharedQueryController] numberOfHistoryItemsForFileURL:[tableDocumentInstance fileURL]]; + currentHistoryOffsetIndex--; + NSLog(@"%ld - %ld", numberOfHistoryItems, currentHistoryOffsetIndex); + if ( numberOfHistoryItems > 0 && currentHistoryOffsetIndex < numberOfHistoryItems && currentHistoryOffsetIndex >= 0) { + historyItemWasJustInserted = YES; + // if(![textView selectedRange].length) + // [textView setSelectedRange:currentQueryRange]; + [textView breakUndoCoalescing]; + NSString *historyString = [[[SPQueryController sharedQueryController] historyForFileURL:[tableDocumentInstance fileURL]] objectAtIndex:currentHistoryOffsetIndex]; + NSRange rangeOfInsertedString = NSMakeRange([textView selectedRange].location, [historyString length]); + [textView insertText:historyString]; + [textView setSelectedRange:rangeOfInsertedString]; + } else { + currentHistoryOffsetIndex++; + NSBeep(); + } + historyItemWasJustInserted = NO; + } + // "Shift Right" menu item - indent the selection with an additional tab. if (sender == shiftRightMenuItem) { [textView shiftSelectionRight]; @@ -682,16 +722,13 @@ // Register new history item [[SPQueryController sharedQueryController] addHistory:usedQuery forFileURL:[tableDocumentInstance fileURL]]; - // Add it to the document's current popup list - if([queryHistoryButton numberOfItems] > 7) - [queryHistoryButton insertItemWithTitle:usedQuery atIndex:7]; - else - [queryHistoryButton addItemWithTitle:usedQuery]; - - // Check for max history - NSUInteger maxHistoryItems = [[prefs objectForKey:SPCustomQueryMaxHistoryItems] integerValue]; - while ( [queryHistoryButton numberOfItems] > maxHistoryItems + 7 ) + // Refresh history popup menu + NSMenu* historyMenu = [queryHistoryButton menu]; + while([queryHistoryButton numberOfItems] > 7) [queryHistoryButton removeItemAtIndex:[queryHistoryButton numberOfItems]-1]; + + for(id historyMenuItem in [[SPQueryController sharedQueryController] historyMenuItemsForFileURL:[tableDocumentInstance fileURL]]) + [historyMenu addItem:historyMenuItem]; } @@ -1293,7 +1330,14 @@ if ( [[SPQueryController sharedQueryController] historyForFileURL:[tableDocumentInstance fileURL]] ) { - [queryHistoryButton addItemsWithTitles:[[SPQueryController sharedQueryController] historyForFileURL:[tableDocumentInstance fileURL]]]; + NSMenu* historyMenu = [queryHistoryButton menu]; + // remove items up to the last separator beginning from the end + while([queryHistoryButton numberOfItems] > 7) + [queryHistoryButton removeItemAtIndex:[queryHistoryButton numberOfItems]-1]; + + // Add history items + for(id historyMenuItem in [[SPQueryController sharedQueryController] historyMenuItemsForFileURL:[tableDocumentInstance fileURL]]) + [historyMenu addItem:historyMenuItem]; } // Populate query favorites @@ -2104,6 +2148,9 @@ [runSelectionMenuItem setEnabled:YES]; } } + + if(!historyItemWasJustInserted) + currentHistoryOffsetIndex = -1; } #pragma mark - @@ -2783,16 +2830,7 @@ - (NSString *)buildHistoryString { - NSMutableString *history = [NSMutableString string]; - NSMenu *menu = [queryHistoryButton menu]; - NSInteger i; - - for (i = 7; i < [menu numberOfItems]; i++) { - [history appendString:[[menu itemAtIndex:i] title]]; - [history appendString:@";\n"]; - } - - return history; + return [[[SPQueryController sharedQueryController] historyForFileURL:[tableDocumentInstance fileURL]] componentsJoinedByString:@";\n"]; } /* * This method is called as part of Key Value Observing which is used to watch for prefernce changes which effect the interface. @@ -2828,9 +2866,9 @@ // Clear the global history list if doc is Untitled if ([tableDocumentInstance isUntitled]) [prefs setObject:[NSArray array] forKey:SPQueryHistory]; - // otherwise remove all document-based history items from the queryController - else - [[SPQueryController sharedQueryController] replaceHistoryByArray:[NSMutableArray array] forFileURL:[tableDocumentInstance fileURL]]; + + // Remove items in the query controller + [[SPQueryController sharedQueryController] replaceHistoryByArray:[NSMutableArray array] forFileURL:[tableDocumentInstance fileURL]]; } return; @@ -2906,6 +2944,7 @@ */ - (BOOL)validateMenuItem:(NSMenuItem *)menuItem { + // Control "Save ... to Favorites" if ( [menuItem tag] == SP_SAVE_SELECTION_FAVORTITE_MENUITEM_TAG ) { if ([[textView string] length] < 1) return NO; @@ -2923,12 +2962,12 @@ } // Avoid selecting button list headers - if ( [menuItem tag] == SP_FAVORITE_HEADER_MENUITEM_TAG ) { + else if ( [menuItem tag] == SP_FAVORITE_HEADER_MENUITEM_TAG ) { return NO; } // Control Clear History menu item title according to isUntitled - if ( [menuItem tag] == SP_HISTORY_CLEAR_MENUITEM_TAG ) { + else if ( [menuItem tag] == SP_HISTORY_CLEAR_MENUITEM_TAG ) { if ( [tableDocumentInstance isUntitled] ) { [menuItem setTitle:NSLocalizedString(@"Clear Global History", @"clear global history menu item title")]; [menuItem setToolTip:NSLocalizedString(@"Clear the global history list", @"clear the global history list tooltip message")]; @@ -2939,7 +2978,7 @@ } // Check for History items - if ( [menuItem tag] >= SP_HISTORY_COPY_MENUITEM_TAG && [menuItem tag] <= SP_HISTORY_CLEAR_MENUITEM_TAG ) { + else if ( [menuItem tag] >= SP_HISTORY_COPY_MENUITEM_TAG && [menuItem tag] <= SP_HISTORY_CLEAR_MENUITEM_TAG ) { return ([queryHistoryButton numberOfItems]-7); } @@ -2983,6 +3022,9 @@ resultData = [[SPDataStorage alloc] init]; editedRow = -1; + currentHistoryOffsetIndex = -1; + historyItemWasJustInserted = NO; + prefs = [NSUserDefaults standardUserDefaults]; } @@ -3011,13 +3053,14 @@ */ - (IBAction)filterQueryHistory:(id)sender { - NSUInteger i; NSMenu *menu = [queryHistoryButton menu]; + NSUInteger numberOfItems = [menu numberOfItems]; + NSUInteger i; NSString *searchPattern = [queryHistorySearchField stringValue]; - - for (i = 7; i < [menu numberOfItems]; i++) + NSArray *history = [[SPQueryController sharedQueryController] historyForFileURL:[tableDocumentInstance fileURL]]; + for (i = 7; i < numberOfItems; i++) { - [[menu itemAtIndex:i] setHidden:(![[[menu itemAtIndex:i] title] isMatchedByRegex:[NSString stringWithFormat:@"(?i).*%@.*", searchPattern]])]; + [[menu itemAtIndex:i] setHidden:(![[history objectAtIndex:i-7] isMatchedByRegex:[NSString stringWithFormat:@"(?i).*%@.*", searchPattern]])]; } } diff --git a/Source/SPQueryController.h b/Source/SPQueryController.h index 2a7af9ca..a1948b4b 100644 --- a/Source/SPQueryController.h +++ b/Source/SPQueryController.h @@ -94,6 +94,8 @@ - (NSMutableArray *)favoritesForFileURL:(NSURL *)fileURL; - (NSMutableArray *)historyForFileURL:(NSURL *)fileURL; +- (NSArray *)historyMenuItemsForFileURL:(NSURL *)fileURL; +- (NSUInteger)numberOfHistoryItemsForFileURL:(NSURL *)fileURL; - (NSMutableDictionary *)contentFilterForFileURL:(NSURL *)fileURL; - (NSArray *)queryFavoritesForFileURL:(NSURL *)fileURL andTabTrigger:(NSString *)tabTrigger includeGlobals:(BOOL)includeGlobals; diff --git a/Source/SPQueryController.m b/Source/SPQueryController.m index 9f28c226..ae83a25d 100644 --- a/Source/SPQueryController.m +++ b/Source/SPQueryController.m @@ -644,6 +644,32 @@ static SPQueryController *sharedQueryController = nil; return [NSMutableArray array]; } +- (NSArray *)historyMenuItemsForFileURL:(NSURL *)fileURL +{ + if([historyContainer objectForKey:[fileURL absoluteString]]) { + NSMutableArray *returnArray = [[NSMutableArray arrayWithCapacity:[[historyContainer objectForKey:[fileURL absoluteString]] count]] autorelease]; + NSMenuItem *historyMenuItem; + for(id history in [historyContainer objectForKey:[fileURL absoluteString]]) { + historyMenuItem = [[[NSMenuItem alloc] initWithTitle:([history length] > 64) ? [NSString stringWithFormat:@"%@…", [history substringToIndex:63]] : history + action:NULL + keyEquivalent:@""] autorelease]; + [historyMenuItem setToolTip:([history length] > 256) ? [NSString stringWithFormat:@"%@…", [history substringToIndex:255]] : history]; + [returnArray addObject:historyMenuItem]; + } + + return returnArray; + } + + return [NSArray array]; +} + +- (NSUInteger)numberOfHistoryItemsForFileURL:(NSURL *)fileURL +{ + if([historyContainer objectForKey:[fileURL absoluteString]]) + return [[historyContainer objectForKey:[fileURL absoluteString]] count]; + else + return 0; +} - (NSMutableDictionary *)contentFilterForFileURL:(NSURL *)fileURL { if([contentFilterContainer objectForKey:[fileURL absoluteString]]) |