aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-01-05 11:46:41 +0000
committerBibiko <bibiko@eva.mpg.de>2010-01-05 11:46:41 +0000
commitde9bca67824b192ede852ae74eab175dacb2f686 (patch)
tree1ee55d891b84caf810807945afc01a72bf20fc11
parentc4815ab7eed05ceb82470e524e5066d1c22c8f3b (diff)
downloadsequelpro-de9bca67824b192ede852ae74eab175dacb2f686.tar.gz
sequelpro-de9bca67824b192ede852ae74eab175dacb2f686.tar.bz2
sequelpro-de9bca67824b192ede852ae74eab175dacb2f686.zip
• added Save/Copy History List to "Query History"'s popup menu
• moved "Clear History" from gear menu to "Query History"'s popup menu and added a confirmation sheet to it • "Clear History" now distinguishes between Untitled and SPF doc - if Untitled: clear global history list stored in the Prefs - if SPF doc: clear the document-based history list only
-rw-r--r--Interfaces/English.lproj/DBView.xib217
-rw-r--r--Source/CustomQuery.h16
-rw-r--r--Source/CustomQuery.m153
3 files changed, 322 insertions, 64 deletions
diff --git a/Interfaces/English.lproj/DBView.xib b/Interfaces/English.lproj/DBView.xib
index 5372ad52..9c8fd125 100644
--- a/Interfaces/English.lproj/DBView.xib
+++ b/Interfaces/English.lproj/DBView.xib
@@ -23,7 +23,7 @@
</object>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
- <integer value="662"/>
+ <integer value="1183"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -3207,9 +3207,55 @@
<object class="NSMutableArray" key="NSMenuItems">
<bool key="EncodedWithXMLCoder">YES</bool>
<reference ref="13183167"/>
+ <object class="NSMenuItem" id="839393306">
+ <reference key="NSMenu" ref="766637184"/>
+ <string key="NSTitle">Copy History</string>
+ <string key="NSKeyEquiv"/>
+ <int key="NSKeyEquivModMask">524288</int>
+ <int key="NSMnemonicLoc">2147483647</int>
+ <reference key="NSOnImage" ref="450876295"/>
+ <reference key="NSMixedImage" ref="414351669"/>
+ <string key="NSAction">_popUpItemAction:</string>
+ <int key="NSTag">300000</int>
+ <reference key="NSTarget" ref="830957297"/>
+ </object>
+ <object class="NSMenuItem" id="216334303">
+ <reference key="NSMenu" ref="766637184"/>
+ <bool key="NSIsAlternate">YES</bool>
+ <string key="NSTitle">Save History…</string>
+ <string key="NSKeyEquiv"/>
+ <int key="NSMnemonicLoc">2147483647</int>
+ <reference key="NSOnImage" ref="450876295"/>
+ <reference key="NSMixedImage" ref="414351669"/>
+ <string key="NSAction">_popUpItemAction:</string>
+ <int key="NSTag">300001</int>
+ <reference key="NSTarget" ref="830957297"/>
+ </object>
+ <object class="NSMenuItem" id="6128">
+ <reference key="NSMenu" ref="766637184"/>
+ <string key="NSTitle">Clear History</string>
+ <string key="NSKeyEquiv"/>
+ <int key="NSMnemonicLoc">2147483647</int>
+ <reference key="NSOnImage" ref="450876295"/>
+ <reference key="NSMixedImage" ref="414351669"/>
+ <string key="NSAction">_popUpItemAction:</string>
+ <int key="NSTag">300002</int>
+ <reference key="NSTarget" ref="830957297"/>
+ </object>
+ <object class="NSMenuItem" id="584172454">
+ <reference key="NSMenu" ref="766637184"/>
+ <bool key="NSIsDisabled">YES</bool>
+ <bool key="NSIsSeparator">YES</bool>
+ <string key="NSTitle"/>
+ <string key="NSKeyEquiv"/>
+ <int key="NSMnemonicLoc">2147483647</int>
+ <reference key="NSOnImage" ref="450876295"/>
+ <reference key="NSMixedImage" ref="414351669"/>
+ <string key="NSAction">_popUpItemAction:</string>
+ <reference key="NSTarget" ref="830957297"/>
+ </object>
<object class="NSMenuItem" id="252023923">
<reference key="NSMenu" ref="766637184"/>
- <bool key="NSIsHidden">YES</bool>
<string key="NSTitle">..placeholder for seachfield..</string>
<string key="NSKeyEquiv"/>
<int key="NSMnemonicLoc">2147483647</int>
@@ -3232,6 +3278,7 @@
</object>
</object>
</object>
+ <int key="NSSelectedIndex">3</int>
<bool key="NSPullDown">YES</bool>
<int key="NSPreferredEdge">3</int>
<bool key="NSUsesItemFromMenu">YES</bool>
@@ -3346,7 +3393,6 @@
</object>
</object>
</object>
- <int key="NSSelectedIndex">2</int>
<bool key="NSPullDown">YES</bool>
<int key="NSPreferredEdge">3</int>
<bool key="NSUsesItemFromMenu">YES</bool>
@@ -3454,17 +3500,6 @@
<int key="NSTag">4</int>
<reference key="NSTarget" ref="984501775"/>
</object>
- <object class="NSMenuItem" id="131332669">
- <reference key="NSMenu" ref="60735230"/>
- <string key="NSTitle">Clear History</string>
- <string key="NSKeyEquiv"/>
- <int key="NSMnemonicLoc">2147483647</int>
- <reference key="NSOnImage" ref="450876295"/>
- <reference key="NSMixedImage" ref="414351669"/>
- <string key="NSAction">_popUpItemAction:</string>
- <int key="NSTag">5</int>
- <reference key="NSTarget" ref="984501775"/>
- </object>
<object class="NSMenuItem" id="128208712">
<reference key="NSMenu" ref="60735230"/>
<string key="NSTitle">History Replaces Editor Content</string>
@@ -3639,7 +3674,7 @@
</object>
<bool key="NSNoAutoenable">YES</bool>
</object>
- <int key="NSSelectedIndex">18</int>
+ <int key="NSSelectedIndex">17</int>
<bool key="NSPullDown">YES</bool>
<int key="NSPreferredEdge">1</int>
<bool key="NSUsesItemFromMenu">YES</bool>
@@ -12504,22 +12539,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
</object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
- <string key="label">clearHistoryMenuItem</string>
- <reference key="source" ref="601471102"/>
- <reference key="destination" ref="131332669"/>
- </object>
- <int key="connectionID">5315</int>
- </object>
- <object class="IBConnectionRecord">
- <object class="IBActionConnection" key="connection">
- <string key="label">gearMenuItemSelected:</string>
- <reference key="source" ref="601471102"/>
- <reference key="destination" ref="131332669"/>
- </object>
- <int key="connectionID">5316</int>
- </object>
- <object class="IBConnectionRecord">
- <object class="IBOutletConnection" key="connection">
<string key="label">autouppercaseKeywordsMenuItem</string>
<reference key="source" ref="601471102"/>
<reference key="destination" ref="81663257"/>
@@ -14811,6 +14830,54 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
</object>
<int key="connectionID">6667</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">clearHistoryMenuItem</string>
+ <reference key="source" ref="601471102"/>
+ <reference key="destination" ref="6128"/>
+ </object>
+ <int key="connectionID">6671</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">saveHistoryMenuItem</string>
+ <reference key="source" ref="601471102"/>
+ <reference key="destination" ref="216334303"/>
+ </object>
+ <int key="connectionID">6672</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">copyHistoryMenuItem</string>
+ <reference key="source" ref="601471102"/>
+ <reference key="destination" ref="839393306"/>
+ </object>
+ <int key="connectionID">6673</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBActionConnection" key="connection">
+ <string key="label">copyQueryHistory:</string>
+ <reference key="source" ref="601471102"/>
+ <reference key="destination" ref="839393306"/>
+ </object>
+ <int key="connectionID">6674</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBActionConnection" key="connection">
+ <string key="label">saveQueryHistory:</string>
+ <reference key="source" ref="601471102"/>
+ <reference key="destination" ref="216334303"/>
+ </object>
+ <int key="connectionID">6675</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBActionConnection" key="connection">
+ <string key="label">clearQueryHistory:</string>
+ <reference key="source" ref="601471102"/>
+ <reference key="destination" ref="6128"/>
+ </object>
+ <int key="connectionID">6676</int>
+ </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@@ -17262,7 +17329,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<reference ref="92094248"/>
<reference ref="1041161373"/>
<reference ref="371024017"/>
- <reference ref="131332669"/>
<reference ref="233912625"/>
<reference ref="413416694"/>
<reference ref="852328440"/>
@@ -17324,11 +17390,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<reference key="parent" ref="60735230"/>
</object>
<object class="IBObjectRecord">
- <int key="objectID">5294</int>
- <reference key="object" ref="131332669"/>
- <reference key="parent" ref="60735230"/>
- </object>
- <object class="IBObjectRecord">
<int key="objectID">5293</int>
<reference key="object" ref="233912625"/>
<reference key="parent" ref="60735230"/>
@@ -17424,6 +17485,10 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<reference ref="13183167"/>
<reference ref="252023923"/>
<reference ref="194438958"/>
+ <reference ref="216334303"/>
+ <reference ref="6128"/>
+ <reference ref="584172454"/>
+ <reference ref="839393306"/>
</object>
<reference key="parent" ref="830957297"/>
</object>
@@ -20871,6 +20936,26 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<reference key="object" ref="843215079"/>
<reference key="parent" ref="429029434"/>
</object>
+ <object class="IBObjectRecord">
+ <int key="objectID">6668</int>
+ <reference key="object" ref="839393306"/>
+ <reference key="parent" ref="766637184"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">6669</int>
+ <reference key="object" ref="216334303"/>
+ <reference key="parent" ref="766637184"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">6670</int>
+ <reference key="object" ref="6128"/>
+ <reference key="parent" ref="766637184"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">6677</int>
+ <reference key="object" ref="584172454"/>
+ <reference key="parent" ref="766637184"/>
+ </object>
</object>
</object>
<object class="NSMutableDictionary" key="flattenedProperties">
@@ -21568,7 +21653,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<string>5291.IBPluginDependency</string>
<string>5292.IBPluginDependency</string>
<string>5293.IBPluginDependency</string>
- <string>5294.IBPluginDependency</string>
<string>5295.IBPluginDependency</string>
<string>5296.IBPluginDependency</string>
<string>5297.IBPluginDependency</string>
@@ -22151,6 +22235,13 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<string>6653.IBAttributePlaceholdersKey</string>
<string>6653.IBPluginDependency</string>
<string>6654.IBPluginDependency</string>
+ <string>6668.IBAttributePlaceholdersKey</string>
+ <string>6668.IBPluginDependency</string>
+ <string>6669.IBAttributePlaceholdersKey</string>
+ <string>6669.IBPluginDependency</string>
+ <string>6670.IBAttributePlaceholdersKey</string>
+ <string>6670.IBPluginDependency</string>
+ <string>6677.IBPluginDependency</string>
<string>669.IBPluginDependency</string>
<string>669.ImportedFromIB2</string>
<string>67.ImportedFromIB2</string>
@@ -22448,7 +22539,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<integer value="1"/>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<integer value="1"/>
- <string>{{570, 699}, {212, 108}}</string>
+ <string>{{510, 680}, {212, 108}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<integer value="1"/>
<object class="NSMutableDictionary">
@@ -22473,7 +22564,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
</object>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<integer value="1"/>
- <string>{{502, 636}, {212, 47}}</string>
+ <string>{{628, 680}, {212, 108}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<integer value="1"/>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -23032,10 +23123,10 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<integer value="1"/>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{313, 430}, {944, 550}}</string>
+ <string>{{253, 411}, {944, 550}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<boolean value="NO"/>
- <string>{{313, 430}, {944, 550}}</string>
+ <string>{{253, 411}, {944, 550}}</string>
<integer value="1"/>
<integer value="1"/>
<string>{{62, 352}, {845, 504}}</string>
@@ -23201,8 +23292,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{247, 228}, {256, 357}}</string>
- <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>{{522, 364}, {256, 445}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -23986,6 +24076,33 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
</object>
<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="839393306"/>
+ <string key="toolTip">Copy all history items into the pasteboard.</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="216334303"/>
+ <string key="toolTip">Save all history items to file. Press ⌥ for copy them.</string>
+ </object>
+ </object>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <object class="NSMutableDictionary">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference key="dict.sortedKeys" ref="0"/>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ </object>
+ </object>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<integer value="1"/>
<integer value="1"/>
@@ -24149,7 +24266,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">6667</int>
+ <int key="maxID">6677</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -25662,7 +25779,9 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<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>
@@ -25675,6 +25794,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<string>helpTargetDispatcher:</string>
<string>runAllQueries:</string>
<string>runSelectedQueries:</string>
+ <string>saveQueryHistory:</string>
<string>showAutoHelpForCurrentWord:</string>
<string>showHelpForCurrentWord:</string>
<string>showHelpForSearchString:</string>
@@ -25699,6 +25819,9 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</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">
@@ -25714,6 +25837,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<string>commentCurrentQueryMenuItem</string>
<string>commentLineOrSelectionMenuItem</string>
<string>completionListMenuItem</string>
+ <string>copyHistoryMenuItem</string>
<string>customQueryScrollView</string>
<string>customQueryView</string>
<string>editorFontMenuItem</string>
@@ -25741,6 +25865,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<string>runAllMenuItem</string>
<string>runSelectionButton</string>
<string>runSelectionMenuItem</string>
+ <string>saveHistoryMenuItem</string>
<string>saveQueryFavoriteButton</string>
<string>saveQueryFavoriteGlobal</string>
<string>shiftLeftMenuItem</string>
@@ -25762,6 +25887,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<string>NSMenuItem</string>
<string>NSMenuItem</string>
<string>NSMenuItem</string>
+ <string>NSMenuItem</string>
<string>NSScrollView</string>
<string>CMCopyTable</string>
<string>NSMenuItem</string>
@@ -25789,6 +25915,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<string>NSMenuItem</string>
<string>id</string>
<string>NSMenuItem</string>
+ <string>NSMenuItem</string>
<string>NSButton</string>
<string>id</string>
<string>NSMenuItem</string>
diff --git a/Source/CustomQuery.h b/Source/CustomQuery.h
index 121b4853..960859d0 100644
--- a/Source/CustomQuery.h
+++ b/Source/CustomQuery.h
@@ -45,6 +45,9 @@
#define SP_SAVE_ALL_FAVORTITE_MENUITEM_TAG 100001
#define SP_SAVE_SELECTION_FAVORTITE_MENUITEM_TAG 100000
#define SP_FAVORITE_HEADER_MENUITEM_TAG 200000
+#define SP_HISTORY_COPY_MENUITEM_TAG 300000
+#define SP_HISTORY_SAVE_MENUITEM_TAG 300001
+#define SP_HISTORY_CLEAR_MENUITEM_TAG 300002
@class SPQueryFavoriteManager;
@@ -69,7 +72,11 @@
IBOutlet NSMenuItem *queryHistorySearchMenuItem;
IBOutlet id queryHistorySearchFieldView;
IBOutlet NSSearchField *queryHistorySearchField;
-
+ IBOutlet NSMenuItem *clearHistoryMenuItem;
+ IBOutlet NSMenuItem *saveHistoryMenuItem;
+ IBOutlet NSMenuItem *copyHistoryMenuItem;
+ IBOutlet NSPopUpButton *encodingPopUp;
+
IBOutlet CMTextView *textView;
IBOutlet CMCopyTable *customQueryView;
IBOutlet NSScrollView *customQueryScrollView;
@@ -83,7 +90,6 @@
IBOutlet NSMenuItem *runSelectionMenuItem;
IBOutlet NSMenuItem *runAllMenuItem;
- IBOutlet NSMenuItem *clearHistoryMenuItem;
IBOutlet NSMenuItem *shiftLeftMenuItem;
IBOutlet NSMenuItem *shiftRightMenuItem;
IBOutlet NSMenuItem *completionListMenuItem;
@@ -161,6 +167,9 @@
- (IBAction)helpSelectHelpTargetWeb:(id)sender;
- (IBAction)filterQueryFavorites:(id)sender;
- (IBAction)filterQueryHistory:(id)sender;
+- (IBAction)saveQueryHistory:(id)sender;
+- (IBAction)copyQueryHistory:(id)sender;
+- (IBAction)clearQueryHistory:(id)sender;
// Query actions
- (void)performQueries:(NSArray *)queries withCallback:(SEL)customQueryCallbackMethod;
@@ -195,6 +204,7 @@
- (void)commentOutCurrentQueryTakingSelection:(BOOL)takeSelection;
- (NSString *)usedQuery;
- (NSString *)argumentForRow:(NSUInteger)rowIndex ofTable:(NSString *)tableForColumn andDatabase:(NSString *)database;
-- (unsigned int)numberOfQueries;
+- (NSUInteger)numberOfQueries;
+- (NSString *)buildHistoryString;
@end
diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m
index 4772823e..358361b6 100644
--- a/Source/CustomQuery.m
+++ b/Source/CustomQuery.m
@@ -40,6 +40,7 @@
#import "SPQueryFavoriteManager.h"
#import "SPQueryController.h"
#import "SPConstants.h"
+#import "SPEncodingPopupAccessory.h"
@implementation CustomQuery
@@ -225,7 +226,7 @@
[prefs synchronize];
// Choose history item
- if ([queryHistoryButton indexOfSelectedItem] > 1) {
+ if ([queryHistoryButton indexOfSelectedItem] > 6) {
BOOL replaceContent = [prefs boolForKey:SPQueryHistoryReplacesContent];
@@ -253,17 +254,6 @@
*/
- (IBAction)gearMenuItemSelected:(id)sender
{
- // "Clear History" menu item - clear query history
- if (sender == clearHistoryMenuItem) {
-
- // Remove all history buttons except the search field and separator beginning from the end
- while([queryHistoryButton numberOfItems] > 3)
- [queryHistoryButton removeItemAtIndex:[queryHistoryButton numberOfItems]-1];
-
- // Remove all items from the queryController
- [[SPQueryController sharedQueryController] replaceHistoryByArray:[NSMutableArray array] forFileURL:[tableDocumentInstance fileURL]];
-
- }
// "Shift Right" menu item - indent the selection with an additional tab.
if (sender == shiftRightMenuItem) {
@@ -338,6 +328,67 @@
}
}
+- (IBAction)saveQueryHistory:(id)sender
+{
+ NSSavePanel *panel = [NSSavePanel savePanel];
+
+ [panel setRequiredFileType:SPFileExtensionSQL];
+
+ [panel setExtensionHidden:NO];
+ [panel setAllowsOtherFileTypes:YES];
+ [panel setCanSelectHiddenExtension:YES];
+ [panel setCanCreateDirectories:YES];
+
+ [panel setAccessoryView:[SPEncodingPopupAccessory encodingAccessory:[prefs integerForKey:SPLastSQLFileEncoding] includeDefaultEntry:NO encodingPopUp:&encodingPopUp]];
+
+ [encodingPopUp setEnabled:YES];
+
+ [panel beginSheetForDirectory:nil file:@"history" modalForWindow:tableWindow modalDelegate:self didEndSelector:@selector(savePanelDidEnd:returnCode:contextInfo:) contextInfo:@"saveHistory"];
+}
+
+- (IBAction)copyQueryHistory:(id)sender
+{
+
+ NSPasteboard *pb = [NSPasteboard generalPasteboard];
+
+ [pb declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
+ [pb setString:[self buildHistoryString] forType:NSStringPboardType];
+
+}
+
+// "Clear History" menu item - clear query history
+- (IBAction)clearQueryHistory:(id)sender
+{
+
+ NSString *infoString;
+
+ if ([tableDocumentInstance isUntitled])
+ infoString = NSLocalizedString(@"Are you sure you want to clear the global history list? This action cannot be undone.", @"clear global history list informative message");
+ else
+ infoString = [NSString stringWithFormat:NSLocalizedString(@"Are you sure you want to clear the history list for “%@”? This action cannot be undone.", @"clear history list for “%@” informative message"), [tableDocumentInstance displayName]];
+
+ NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Clear History?", @"clear history message")
+ defaultButton:NSLocalizedString(@"Clear", @"clear button")
+ alternateButton:NSLocalizedString(@"Cancel", @"cancel button")
+ otherButton:nil
+ informativeTextWithFormat:infoString];
+
+ [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:tableWindow
+ modalDelegate:self
+ didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
+ contextInfo:@"clearHistory"];
+
+}
+
/*
* Set font panel's valid modes
*/
@@ -618,11 +669,14 @@
[[SPQueryController sharedQueryController] addHistory:usedQuery forFileURL:[tableDocumentInstance fileURL]];
// Add it to the document's current popup list
- [queryHistoryButton insertItemWithTitle:usedQuery atIndex:3];
+ if([queryHistoryButton numberOfItems] > 8)
+ [queryHistoryButton insertItemWithTitle:usedQuery atIndex:7];
+ else
+ [queryHistoryButton addItemWithTitle:usedQuery];
// Check for max history
NSUInteger maxHistoryItems = [[prefs objectForKey:SPCustomQueryMaxHistoryItems] intValue];
- while ( [queryHistoryButton numberOfItems] > maxHistoryItems + 3 )
+ while ( [queryHistoryButton numberOfItems] > maxHistoryItems + 6 )
[queryHistoryButton removeItemAtIndex:[queryHistoryButton numberOfItems]-1];
}
@@ -2719,6 +2773,19 @@
return numberOfQueries;
}
+- (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;
+}
/*
* This method is called as part of Key Value Observing which is used to watch for prefernce changes which effect the interface.
*/
@@ -2743,10 +2810,29 @@
}
/**
- * Called when the save query favorite sheet is dismissed.
+ * Called when the save query favorite/clear history sheet is dismissed.
*/
- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(NSString *)contextInfo
{
+
+ if ([contextInfo isEqualToString:@"clearHistory"]) {
+ if (returnCode == NSOKButton) {
+
+ // Remove all history buttons up to the search field and separator beginning from the end
+ while([queryHistoryButton numberOfItems] > 7)
+ [queryHistoryButton removeItemAtIndex:[queryHistoryButton numberOfItems]-1];
+
+ // 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]];
+
+ }
+ return;
+ }
+
if ([contextInfo isEqualToString:@"addAllToNewQueryFavorite"] || [contextInfo isEqualToString:@"addSelectionToNewQueryFavorite"]) {
if (returnCode == NSOKButton) {
@@ -2793,6 +2879,25 @@
[queryFavoriteNameTextField setStringValue:@""];
}
+- (void)savePanelDidEnd:(NSSavePanel *)panel returnCode:(NSInteger)returnCode contextInfo:(id)contextInfo
+{
+ if([contextInfo isEqualToString:@"saveHistory"]) {
+ if (returnCode == NSOKButton) {
+ NSError *error = nil;
+
+ [prefs setInteger:[[encodingPopUp selectedItem] tag] forKey:SPLastSQLFileEncoding];
+ [prefs synchronize];
+
+ [[self buildHistoryString] writeToFile:[panel filename]
+ atomically:YES
+ encoding:[[encodingPopUp selectedItem] tag]
+ error:&error];
+
+ if (error) [[NSAlert alertWithError:error] runModal];
+ }
+ }
+}
+
/**
* Menu item validation.
*/
@@ -2819,6 +2924,22 @@
return NO;
}
+ // Control Clear History menu item title according to isUntitled
+ 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")];
+ } else {
+ [menuItem setTitle:[NSString stringWithFormat:NSLocalizedString(@"Clear History for “%@”", @"clear history for “%@” menu title"), [tableDocumentInstance displayName]]];
+ [menuItem setToolTip:NSLocalizedString(@"Clear the document-based history list", @"clear the document-based history list tooltip message")];
+ }
+ }
+
+ // Check for History items
+ if ( [menuItem tag] >= SP_HISTORY_COPY_MENUITEM_TAG && [menuItem tag] <= SP_HISTORY_CLEAR_MENUITEM_TAG ) {
+ return ([queryHistoryButton numberOfItems]-7);
+ }
+
return YES;
}
@@ -2890,7 +3011,7 @@
NSMenu *menu = [queryHistoryButton menu];
NSString *searchPattern = [queryHistorySearchField stringValue];
- for (i = 3; i < [menu numberOfItems]; i++)
+ for (i = 7; i < [menu numberOfItems]; i++)
{
[[menu itemAtIndex:i] setHidden:(![[[menu itemAtIndex:i] title] isMatchedByRegex:[NSString stringWithFormat:@"(?i).*%@.*", searchPattern]])];
}