aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2009-09-01 15:19:01 +0000
committerBibiko <bibiko@eva.mpg.de>2009-09-01 15:19:01 +0000
commitd4c06608e4154e30a9934d1393100c7c84727c64 (patch)
tree460addfc42ebdd9d351d390b051ffe2bb7256507
parentb5ccc9bd71123ea6a45100c0353c40e42e489f3a (diff)
downloadsequelpro-d4c06608e4154e30a9934d1393100c7c84727c64.tar.gz
sequelpro-d4c06608e4154e30a9934d1393100c7c84727c64.tar.bz2
sequelpro-d4c06608e4154e30a9934d1393100c7c84727c64.zip
• query favorite manager
- first step to allow to manage global favs (stored in the prefs) and connection-based (not yet implemented - will be stored in ApplicationSupport/SequelPro) - fav table is now a grouped table à la Table List - second column in fav table will be used soon ;) - now the sheet has two buttons "Save" and "Cancel" in order to be able to dismiss changes - enabled table view inline editing of query names
-rw-r--r--Interfaces/English.lproj/QueryFavoriteManager.xib467
-rw-r--r--Source/CustomQuery.m49
-rw-r--r--Source/SPQueryFavoriteManager.h20
-rw-r--r--Source/SPQueryFavoriteManager.m419
4 files changed, 627 insertions, 328 deletions
diff --git a/Interfaces/English.lproj/QueryFavoriteManager.xib b/Interfaces/English.lproj/QueryFavoriteManager.xib
index e33fd010..b943f8d3 100644
--- a/Interfaces/English.lproj/QueryFavoriteManager.xib
+++ b/Interfaces/English.lproj/QueryFavoriteManager.xib
@@ -45,7 +45,7 @@
<string key="NSWindowContentMaxSize">{3.40282e+38, 3.40282e+38}</string>
<string key="NSWindowContentMinSize">{500, 371}</string>
<object class="NSView" key="NSWindowView" id="1006">
- <reference key="NSNextResponder"/>
+ <nil key="NSNextResponder"/>
<int key="NSvFlags">256</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -62,9 +62,8 @@
<object class="NSButton" id="478413208">
<reference key="NSNextResponder" ref="813298639"/>
<int key="NSvFlags">292</int>
- <string key="NSFrame">{{0, -1}, {32, 25}}</string>
+ <string key="NSFrame">{{0, -2}, {32, 25}}</string>
<reference key="NSSuperview" ref="813298639"/>
- <reference key="NSWindow"/>
<bool key="NSEnabled">YES</bool>
<object class="NSButtonCell" key="NSCell" id="63587388">
<int key="NSCellFlags">67239424</int>
@@ -91,9 +90,8 @@
<object class="NSButton" id="960187291">
<reference key="NSNextResponder" ref="813298639"/>
<int key="NSvFlags">292</int>
- <string key="NSFrame">{{31, -1}, {32, 25}}</string>
+ <string key="NSFrame">{{31, -2}, {32, 25}}</string>
<reference key="NSSuperview" ref="813298639"/>
- <reference key="NSWindow"/>
<bool key="NSEnabled">YES</bool>
<object class="NSButtonCell" key="NSCell" id="1023807891">
<int key="NSCellFlags">67239424</int>
@@ -126,20 +124,27 @@
<object class="NSTableView" id="522643855">
<reference key="NSNextResponder" ref="106335880"/>
<int key="NSvFlags">4352</int>
- <string key="NSFrameSize">{190, 338}</string>
+ <string key="NSFrameSize">{162, 323}</string>
<reference key="NSSuperview" ref="106335880"/>
- <reference key="NSWindow"/>
<bool key="NSEnabled">YES</bool>
- <object class="_NSCornerView" key="NSCornerView">
- <nil key="NSNextResponder"/>
+ <object class="NSTableHeaderView" key="NSHeaderView" id="724842455">
+ <reference key="NSNextResponder" ref="642947098"/>
+ <int key="NSvFlags">4352</int>
+ <string key="NSFrameSize">{162, 17}</string>
+ <reference key="NSSuperview" ref="642947098"/>
+ <reference key="NSTableView" ref="522643855"/>
+ </object>
+ <object class="_NSCornerView" key="NSCornerView" id="299150059">
+ <reference key="NSNextResponder" ref="205303038"/>
<int key="NSvFlags">-2147483392</int>
- <string key="NSFrame">{{176, 0}, {16, 17}}</string>
+ <string key="NSFrame">{{-22, 0}, {12, 17}}</string>
+ <reference key="NSSuperview" ref="205303038"/>
</object>
<object class="NSMutableArray" key="NSTableColumns">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSTableColumn" id="901293108">
<string key="NSIdentifier">name</string>
- <double key="NSWidth">1.870000e+02</double>
+ <double key="NSWidth">1.300000e+02</double>
<double key="NSMinWidth">4.000000e+01</double>
<double key="NSMaxWidth">1.000000e+03</double>
<object class="NSTableHeaderCell" key="NSHeaderCell">
@@ -155,7 +160,7 @@
<int key="NSColorSpace">3</int>
<bytes key="NSWhite">MC4zMzMzMzI5OQA</bytes>
</object>
- <object class="NSColor" key="NSTextColor">
+ <object class="NSColor" key="NSTextColor" id="75208904">
<int key="NSColorSpace">6</int>
<string key="NSCatalogName">System</string>
<string key="NSColorName">headerTextColor</string>
@@ -166,7 +171,7 @@
</object>
</object>
<object class="NSTextFieldCell" key="NSDataCell" id="56401947">
- <int key="NSCellFlags">69336641</int>
+ <int key="NSCellFlags">337772097</int>
<int key="NSCellFlags2">133120</int>
<string key="NSContents">Text Cell</string>
<reference key="NSSupport" ref="26"/>
@@ -187,6 +192,43 @@
<reference key="NSColor" ref="646528321"/>
</object>
</object>
+ <int key="NSResizingMask">3</int>
+ <bool key="NSIsResizeable">YES</bool>
+ <bool key="NSIsEditable">YES</bool>
+ <reference key="NSTableView" ref="522643855"/>
+ </object>
+ <object class="NSTableColumn" id="183746003">
+ <string key="NSIdentifier">tabtrigger</string>
+ <double key="NSWidth">2.600000e+01</double>
+ <double key="NSMinWidth">1.000000e+01</double>
+ <double key="NSMaxWidth">3.402823e+38</double>
+ <object class="NSTableHeaderCell" key="NSHeaderCell">
+ <int key="NSCellFlags">75628032</int>
+ <int key="NSCellFlags2">0</int>
+ <string key="NSContents"/>
+ <reference key="NSSupport" ref="26"/>
+ <object class="NSColor" key="NSBackgroundColor">
+ <int key="NSColorSpace">6</int>
+ <string key="NSCatalogName">System</string>
+ <string key="NSColorName">headerColor</string>
+ <object class="NSColor" key="NSColor" id="359131077">
+ <int key="NSColorSpace">3</int>
+ <bytes key="NSWhite">MQA</bytes>
+ </object>
+ </object>
+ <reference key="NSTextColor" ref="75208904"/>
+ </object>
+ <object class="NSTextFieldCell" key="NSDataCell" id="577317691">
+ <int key="NSCellFlags">337772096</int>
+ <int key="NSCellFlags2">133120</int>
+ <string key="NSContents">Text Cell</string>
+ <reference key="NSSupport" ref="26"/>
+ <reference key="NSControlView" ref="522643855"/>
+ <reference key="NSBackgroundColor" ref="392588142"/>
+ <reference key="NSTextColor" ref="810868150"/>
+ </object>
+ <int key="NSResizingMask">3</int>
+ <bool key="NSIsResizeable">YES</bool>
<reference key="NSTableView" ref="522643855"/>
</object>
</object>
@@ -211,18 +253,17 @@
</object>
</object>
<double key="NSRowHeight">1.600000e+01</double>
- <int key="NSTvFlags">442499072</int>
- <int key="NSColumnAutoresizingStyle">0</int>
+ <int key="NSTvFlags">1245741056</int>
+ <string key="NSAutosaveName">SPQueryFavoriteManagerTable</string>
+ <int key="NSColumnAutoresizingStyle">1</int>
<int key="NSDraggingSourceMaskForLocal">15</int>
<int key="NSDraggingSourceMaskForNonLocal">0</int>
- <bool key="NSAllowsTypeSelect">NO</bool>
+ <bool key="NSAllowsTypeSelect">YES</bool>
<int key="NSTableViewSelectionHighlightStyle">1</int>
</object>
</object>
- <string key="NSFrame">{{1, 1}, {168, 338}}</string>
+ <string key="NSFrame">{{0, 17}, {162, 323}}</string>
<reference key="NSSuperview" ref="205303038"/>
- <reference key="NSWindow"/>
- <reference key="NSNextKeyView" ref="522643855"/>
<reference key="NSDocView" ref="522643855"/>
<reference key="NSBGColor" ref="392588142"/>
<int key="NScvFlags">4</int>
@@ -230,35 +271,46 @@
<object class="NSScroller" id="322405876">
<reference key="NSNextResponder" ref="205303038"/>
<int key="NSvFlags">-2147483392</int>
- <string key="NSFrame">{{183, 1}, {11, 317}}</string>
+ <string key="NSFrame">{{158, 17}, {11, 322}}</string>
<reference key="NSSuperview" ref="205303038"/>
- <reference key="NSWindow"/>
<int key="NSsFlags">256</int>
<reference key="NSTarget" ref="205303038"/>
<string key="NSAction">_doScroller:</string>
- <double key="NSPercent">9.964158e-01</double>
+ <double key="NSPercent">9.968944e-01</double>
</object>
<object class="NSScroller" id="336819166">
<reference key="NSNextResponder" ref="205303038"/>
<int key="NSvFlags">-2147483392</int>
<string key="NSFrame">{{-100, -100}, {311, 15}}</string>
<reference key="NSSuperview" ref="205303038"/>
- <reference key="NSWindow"/>
- <bool key="NSEnabled">YES</bool>
<int key="NSsFlags">1</int>
<reference key="NSTarget" ref="205303038"/>
<string key="NSAction">_doScroller:</string>
<double key="NSPercent">9.953271e-01</double>
</object>
+ <object class="NSClipView" id="642947098">
+ <reference key="NSNextResponder" ref="205303038"/>
+ <int key="NSvFlags">2304</int>
+ <object class="NSMutableArray" key="NSSubviews">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference ref="724842455"/>
+ </object>
+ <string key="NSFrameSize">{162, 17}</string>
+ <reference key="NSSuperview" ref="205303038"/>
+ <reference key="NSDocView" ref="724842455"/>
+ <reference key="NSBGColor" ref="392588142"/>
+ <int key="NScvFlags">4</int>
+ </object>
+ <reference ref="299150059"/>
</object>
- <string key="NSFrame">{{-2, 22}, {170, 340}}</string>
+ <string key="NSFrame">{{0, 21}, {162, 340}}</string>
<reference key="NSSuperview" ref="813298639"/>
- <reference key="NSWindow"/>
- <reference key="NSNextKeyView" ref="106335880"/>
- <int key="NSsFlags">658</int>
+ <int key="NSsFlags">528</int>
<reference key="NSVScroller" ref="322405876"/>
<reference key="NSHScroller" ref="336819166"/>
<reference key="NSContentView" ref="106335880"/>
+ <reference key="NSHeaderClipView" ref="642947098"/>
+ <reference key="NSCornerView" ref="299150059"/>
<bytes key="NSScrollAmts">QSAAAEEgAABBkAAAQZAAAA</bytes>
</object>
<object class="NSImageView" id="545397681">
@@ -276,9 +328,8 @@
<string>NeXT TIFF v4.0 pasteboard type</string>
</object>
</object>
- <string key="NSFrame">{{94, 0}, {73, 23}}</string>
+ <string key="NSFrame">{{94, 0}, {68, 23}}</string>
<reference key="NSSuperview" ref="813298639"/>
- <reference key="NSWindow"/>
<bool key="NSEnabled">YES</bool>
<object class="NSImageCell" key="NSCell" id="177143920">
<int key="NSCellFlags">130560</int>
@@ -297,9 +348,8 @@
<object class="BWAnchoredPopUpButton" id="482670840">
<reference key="NSNextResponder" ref="813298639"/>
<int key="NSvFlags">292</int>
- <string key="NSFrame">{{62, -1}, {32, 24}}</string>
+ <string key="NSFrame">{{62, -2}, {32, 24}}</string>
<reference key="NSSuperview" ref="813298639"/>
- <reference key="NSWindow"/>
<bool key="NSEnabled">YES</bool>
<object class="BWAnchoredPopUpButtonCell" key="NSCell" id="929623756">
<int key="NSCellFlags">71433792</int>
@@ -422,6 +472,7 @@
<reference key="NSMenu" ref="299613786"/>
<bool key="NSIsDisabled">YES</bool>
<bool key="NSIsSeparator">YES</bool>
+ <bool key="NSIsHidden">YES</bool>
<string key="NSTitle"/>
<string key="NSKeyEquiv"/>
<int key="NSMnemonicLoc">2147483647</int>
@@ -432,6 +483,7 @@
</object>
<object class="NSMenuItem" id="846349687">
<reference key="NSMenu" ref="299613786"/>
+ <bool key="NSIsHidden">YES</bool>
<string key="NSTitle">Remove All...</string>
<string key="NSKeyEquiv"/>
<int key="NSMnemonicLoc">2147483647</int>
@@ -442,7 +494,6 @@
</object>
</object>
</object>
- <int key="NSSelectedIndex">5</int>
<bool key="NSPullDown">YES</bool>
<int key="NSPreferredEdge">1</int>
<bool key="NSUsesItemFromMenu">YES</bool>
@@ -450,9 +501,8 @@
</object>
</object>
</object>
- <string key="NSFrameSize">{167, 361}</string>
+ <string key="NSFrameSize">{162, 361}</string>
<reference key="NSSuperview" ref="141381185"/>
- <reference key="NSWindow"/>
<string key="NSClassName">NSView</string>
</object>
<object class="NSCustomView" id="36799862">
@@ -465,7 +515,6 @@
<int key="NSvFlags">268</int>
<string key="NSFrame">{{17, 327}, {45, 14}}</string>
<reference key="NSSuperview" ref="36799862"/>
- <reference key="NSWindow"/>
<bool key="NSEnabled">YES</bool>
<object class="NSTextFieldCell" key="NSCell" id="448987091">
<int key="NSCellFlags">68288064</int>
@@ -485,25 +534,22 @@
<object class="NSTextField" id="247897226">
<reference key="NSNextResponder" ref="36799862"/>
<int key="NSvFlags">266</int>
- <string key="NSFrame">{{58, 325}, {254, 19}}</string>
+ <string key="NSFrame">{{58, 325}, {259, 19}}</string>
<reference key="NSSuperview" ref="36799862"/>
- <reference key="NSWindow"/>
<bool key="NSEnabled">YES</bool>
<object class="NSTextFieldCell" key="NSCell" id="474077606">
<int key="NSCellFlags">-1804468671</int>
<int key="NSCellFlags2">272761856</int>
<string key="NSContents"/>
<reference key="NSSupport" ref="26"/>
+ <string key="NSPlaceholderString">[no selection]</string>
<reference key="NSControlView" ref="247897226"/>
<bool key="NSDrawsBackground">YES</bool>
<object class="NSColor" key="NSBackgroundColor" id="570692726">
<int key="NSColorSpace">6</int>
<string key="NSCatalogName">System</string>
<string key="NSColorName">textBackgroundColor</string>
- <object class="NSColor" key="NSColor" id="359131077">
- <int key="NSColorSpace">3</int>
- <bytes key="NSWhite">MQA</bytes>
- </object>
+ <reference key="NSColor" ref="359131077"/>
</object>
<object class="NSColor" key="NSTextColor">
<int key="NSColorSpace">6</int>
@@ -526,32 +572,8 @@
<object class="NSTextView" id="556251150">
<reference key="NSNextResponder" ref="221447089"/>
<int key="NSvFlags">2322</int>
- <object class="NSMutableSet" key="NSDragTypes">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <object class="NSMutableArray" key="set.sortedObjects">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <string>Apple HTML pasteboard type</string>
- <string>Apple PDF pasteboard type</string>
- <string>Apple PICT pasteboard type</string>
- <string>Apple PNG pasteboard type</string>
- <string>Apple URL pasteboard type</string>
- <string>CorePasteboardFlavorType 0x6D6F6F76</string>
- <string>CorePasteboardFlavorType 0x75726C20</string>
- <string>NSColor pasteboard type</string>
- <string>NSFilenamesPboardType</string>
- <string>NSStringPboardType</string>
- <string>NeXT Encapsulated PostScript v1.2 pasteboard type</string>
- <string>NeXT RTFD pasteboard type</string>
- <string>NeXT Rich Text Format v1.0 pasteboard type</string>
- <string>NeXT TIFF v4.0 pasteboard type</string>
- <string>NeXT font pasteboard type</string>
- <string>NeXT ruler pasteboard type</string>
- <string>WebURLsWithTitlesPboardType</string>
- </object>
- </object>
- <string key="NSFrameSize">{290, 14}</string>
+ <string key="NSFrameSize">{295, 14}</string>
<reference key="NSSuperview" ref="221447089"/>
- <reference key="NSWindow"/>
<object class="NSTextContainer" key="NSTextContainer" id="74289808">
<object class="NSLayoutManager" key="NSLayoutManager">
<object class="NSTextStorage" key="NSTextStorage">
@@ -568,7 +590,7 @@
<nil key="NSDelegate"/>
</object>
<reference key="NSTextView" ref="556251150"/>
- <double key="NSWidth">2.900000e+02</double>
+ <double key="NSWidth">2.950000e+02</double>
<int key="NSTCFlags">1</int>
</object>
<object class="NSTextViewSharedData" key="NSSharedData">
@@ -618,15 +640,13 @@
<nil key="NSDefaultParagraphStyle"/>
</object>
<int key="NSTVFlags">6</int>
- <string key="NSMaxSize">{582, 1e+07}</string>
+ <string key="NSMaxSize">{592, 1e+07}</string>
<string key="NSMinize">{223, 0}</string>
<nil key="NSDelegate"/>
</object>
</object>
- <string key="NSFrame">{{1, 1}, {290, 270}}</string>
+ <string key="NSFrame">{{1, 1}, {295, 270}}</string>
<reference key="NSSuperview" ref="407061848"/>
- <reference key="NSWindow"/>
- <reference key="NSNextKeyView" ref="556251150"/>
<reference key="NSDocView" ref="556251150"/>
<reference key="NSBGColor" ref="359131077"/>
<object class="NSCursor" key="NSCursor">
@@ -640,7 +660,6 @@
<int key="NSvFlags">256</int>
<string key="NSFrame">{{-100, -100}, {11, 133}}</string>
<reference key="NSSuperview" ref="407061848"/>
- <reference key="NSWindow"/>
<int key="NSsFlags">256</int>
<reference key="NSTarget" ref="407061848"/>
<string key="NSAction">_doScroller:</string>
@@ -651,7 +670,6 @@
<int key="NSvFlags">256</int>
<string key="NSFrame">{{-100, -100}, {87, 18}}</string>
<reference key="NSSuperview" ref="407061848"/>
- <reference key="NSWindow"/>
<int key="NSsFlags">1</int>
<reference key="NSTarget" ref="407061848"/>
<string key="NSAction">_doScroller:</string>
@@ -659,10 +677,8 @@
<double key="NSPercent">9.456522e-01</double>
</object>
</object>
- <string key="NSFrame">{{20, 45}, {292, 272}}</string>
+ <string key="NSFrame">{{20, 45}, {297, 272}}</string>
<reference key="NSSuperview" ref="36799862"/>
- <reference key="NSWindow"/>
- <reference key="NSNextKeyView" ref="221447089"/>
<int key="NSsFlags">514</int>
<reference key="NSVScroller" ref="978638217"/>
<reference key="NSHScroller" ref="1008017707"/>
@@ -671,14 +687,14 @@
<object class="NSButton" id="556514169">
<reference key="NSNextResponder" ref="36799862"/>
<int key="NSvFlags">289</int>
- <string key="NSFrame">{{230, 7}, {87, 28}}</string>
+ <string key="NSFrame">{{235, 7}, {87, 28}}</string>
<reference key="NSSuperview" ref="36799862"/>
- <reference key="NSWindow"/>
+ <int key="NSTag">1</int>
<bool key="NSEnabled">YES</bool>
<object class="NSButtonCell" key="NSCell" id="908635119">
<int key="NSCellFlags">67239424</int>
<int key="NSCellFlags2">134348800</int>
- <string key="NSContents">Close</string>
+ <string key="NSContents">Save</string>
<reference key="NSSupport" ref="26"/>
<reference key="NSControlView" ref="556514169"/>
<int key="NSButtonFlags">-2038284033</int>
@@ -689,16 +705,34 @@
<int key="NSPeriodicInterval">25</int>
</object>
</object>
+ <object class="NSButton" id="602197876">
+ <reference key="NSNextResponder" ref="36799862"/>
+ <int key="NSvFlags">289</int>
+ <string key="NSFrame">{{150, 7}, {87, 28}}</string>
+ <reference key="NSSuperview" ref="36799862"/>
+ <bool key="NSEnabled">YES</bool>
+ <object class="NSButtonCell" key="NSCell" id="615814080">
+ <int key="NSCellFlags">67239424</int>
+ <int key="NSCellFlags2">134348800</int>
+ <string key="NSContents">Close</string>
+ <reference key="NSSupport" ref="26"/>
+ <reference key="NSControlView" ref="602197876"/>
+ <int key="NSButtonFlags">-2038284033</int>
+ <int key="NSButtonFlags2">129</int>
+ <string key="NSAlternateContents"/>
+ <string type="base64-UTF8" key="NSKeyEquivalent">Gw</string>
+ <int key="NSPeriodicDelay">200</int>
+ <int key="NSPeriodicInterval">25</int>
+ </object>
+ </object>
</object>
- <string key="NSFrame">{{168, 0}, {332, 361}}</string>
+ <string key="NSFrame">{{163, 0}, {337, 361}}</string>
<reference key="NSSuperview" ref="141381185"/>
- <reference key="NSWindow"/>
<string key="NSClassName">NSView</string>
</object>
</object>
<string key="NSFrameSize">{500, 361}</string>
<reference key="NSSuperview" ref="1006"/>
- <reference key="NSWindow"/>
<bool key="NSIsVertical">YES</bool>
<int key="NSDividerStyle">2</int>
</object>
@@ -707,7 +741,6 @@
<int key="NSvFlags">10</int>
<string key="NSFrame">{{0, 358}, {500, 5}}</string>
<reference key="NSSuperview" ref="1006"/>
- <reference key="NSWindow"/>
<string key="NSOffsets">{0, 0}</string>
<object class="NSTextFieldCell" key="NSTitleCell">
<int key="NSCellFlags">67239424</int>
@@ -727,29 +760,15 @@
</object>
</object>
<string key="NSFrameSize">{500, 371}</string>
- <reference key="NSSuperview"/>
- <reference key="NSWindow"/>
</object>
<string key="NSScreenRect">{{0, 0}, {1680, 1028}}</string>
<string key="NSMinSize">{500, 393}</string>
<string key="NSMaxSize">{3.40282e+38, 3.40282e+38}</string>
+ <string key="NSFrameAutosaveName">SPQueryFavoriteManagerWindow</string>
</object>
<object class="NSUserDefaultsController" id="592597522">
<bool key="NSSharedInstance">YES</bool>
</object>
- <object class="NSArrayController" id="524128400">
- <object class="NSMutableArray" key="NSDeclaredKeys">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <string>name</string>
- <string>query</string>
- </object>
- <bool key="NSEditable">YES</bool>
- <object class="_NSManagedProxy" key="_NSManagedProxy"/>
- <bool key="NSPreservesSelection">YES</bool>
- <bool key="NSSelectsInsertedObjects">YES</bool>
- <bool key="NSFilterRestrictsInsertion">YES</bool>
- <bool key="NSClearsFilterPredicateOnInsertion">YES</bool>
- </object>
<object class="NSMenu" id="855448788">
<string key="NSTitle"/>
<object class="NSMutableArray" key="NSMenuItems">
@@ -855,91 +874,6 @@
<int key="connectionID">146</int>
</object>
<object class="IBConnectionRecord">
- <object class="IBBindingConnection" key="connection">
- <string key="label">contentArray: values.queryFavorites</string>
- <reference key="source" ref="524128400"/>
- <reference key="destination" ref="592597522"/>
- <object class="NSNibBindingConnector" key="connector">
- <reference key="NSSource" ref="524128400"/>
- <reference key="NSDestination" ref="592597522"/>
- <string key="NSLabel">contentArray: values.queryFavorites</string>
- <string key="NSBinding">contentArray</string>
- <string key="NSKeyPath">values.queryFavorites</string>
- <object class="NSDictionary" key="NSOptions">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <object class="NSMutableArray" key="dict.sortedKeys">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <string>NSDeletesObjectsOnRemove</string>
- <string>NSHandlesContentAsCompoundValue</string>
- </object>
- <object class="NSMutableArray" key="dict.values">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <boolean value="YES" id="5"/>
- <reference ref="5"/>
- </object>
- </object>
- <int key="NSNibBindingConnectorVersion">2</int>
- </object>
- </object>
- <int key="connectionID">152</int>
- </object>
- <object class="IBConnectionRecord">
- <object class="IBOutletConnection" key="connection">
- <string key="label">queryFavoritesController</string>
- <reference key="source" ref="1001"/>
- <reference key="destination" ref="524128400"/>
- </object>
- <int key="connectionID">157</int>
- </object>
- <object class="IBConnectionRecord">
- <object class="IBBindingConnection" key="connection">
- <string key="label">value: arrangedObjects.name</string>
- <reference key="source" ref="901293108"/>
- <reference key="destination" ref="524128400"/>
- <object class="NSNibBindingConnector" key="connector">
- <reference key="NSSource" ref="901293108"/>
- <reference key="NSDestination" ref="524128400"/>
- <string key="NSLabel">value: arrangedObjects.name</string>
- <string key="NSBinding">value</string>
- <string key="NSKeyPath">arrangedObjects.name</string>
- <int key="NSNibBindingConnectorVersion">2</int>
- </object>
- </object>
- <int key="connectionID">165</int>
- </object>
- <object class="IBConnectionRecord">
- <object class="IBBindingConnection" key="connection">
- <string key="label">enabled: canRemove</string>
- <reference key="source" ref="960187291"/>
- <reference key="destination" ref="524128400"/>
- <object class="NSNibBindingConnector" key="connector">
- <reference key="NSSource" ref="960187291"/>
- <reference key="NSDestination" ref="524128400"/>
- <string key="NSLabel">enabled: canRemove</string>
- <string key="NSBinding">enabled</string>
- <string key="NSKeyPath">canRemove</string>
- <int key="NSNibBindingConnectorVersion">2</int>
- </object>
- </object>
- <int key="connectionID">169</int>
- </object>
- <object class="IBConnectionRecord">
- <object class="IBBindingConnection" key="connection">
- <string key="label">enabled: canAdd</string>
- <reference key="source" ref="478413208"/>
- <reference key="destination" ref="524128400"/>
- <object class="NSNibBindingConnector" key="connector">
- <reference key="NSSource" ref="478413208"/>
- <reference key="NSDestination" ref="524128400"/>
- <string key="NSLabel">enabled: canAdd</string>
- <string key="NSBinding">enabled</string>
- <string key="NSKeyPath">canAdd</string>
- <int key="NSNibBindingConnectorVersion">2</int>
- </object>
- </object>
- <int key="connectionID">171</int>
- </object>
- <object class="IBConnectionRecord">
<object class="IBActionConnection" key="connection">
<string key="label">addQueryFavorite:</string>
<reference key="source" ref="1001"/>
@@ -997,14 +931,6 @@
</object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
- <string key="label">dataSource</string>
- <reference key="source" ref="522643855"/>
- <reference key="destination" ref="1001"/>
- </object>
- <int key="connectionID">192</int>
- </object>
- <object class="IBConnectionRecord">
- <object class="IBOutletConnection" key="connection">
<string key="label">delegate</string>
<reference key="source" ref="522643855"/>
<reference key="destination" ref="1001"/>
@@ -1052,51 +978,6 @@
<int key="connectionID">213</int>
</object>
<object class="IBConnectionRecord">
- <object class="IBBindingConnection" key="connection">
- <string key="label">value: selection.name</string>
- <reference key="source" ref="247897226"/>
- <reference key="destination" ref="524128400"/>
- <object class="NSNibBindingConnector" key="connector">
- <reference key="NSSource" ref="247897226"/>
- <reference key="NSDestination" ref="524128400"/>
- <string key="NSLabel">value: selection.name</string>
- <string key="NSBinding">value</string>
- <string key="NSKeyPath">selection.name</string>
- <object class="NSDictionary" key="NSOptions">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <object class="NSMutableArray" key="dict.sortedKeys">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <string>NSContinuouslyUpdatesValue</string>
- <string>NSNoSelectionPlaceholder</string>
- </object>
- <object class="NSMutableArray" key="dict.values">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <reference ref="5"/>
- <string>no selection</string>
- </object>
- </object>
- <int key="NSNibBindingConnectorVersion">2</int>
- </object>
- </object>
- <int key="connectionID">232</int>
- </object>
- <object class="IBConnectionRecord">
- <object class="IBBindingConnection" key="connection">
- <string key="label">value: selection.query</string>
- <reference key="source" ref="556251150"/>
- <reference key="destination" ref="524128400"/>
- <object class="NSNibBindingConnector" key="connector">
- <reference key="NSSource" ref="556251150"/>
- <reference key="NSDestination" ref="524128400"/>
- <string key="NSLabel">value: selection.query</string>
- <string key="NSBinding">value</string>
- <string key="NSKeyPath">selection.query</string>
- <int key="NSNibBindingConnectorVersion">2</int>
- </object>
- </object>
- <int key="connectionID">237</int>
- </object>
- <object class="IBConnectionRecord">
<object class="IBActionConnection" key="connection">
<string key="label">saveFavoriteToFile:</string>
<reference key="source" ref="1001"/>
@@ -1152,6 +1033,38 @@
</object>
<int key="connectionID">262</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBActionConnection" key="connection">
+ <string key="label">closeQueryManagerSheet:</string>
+ <reference key="source" ref="1001"/>
+ <reference key="destination" ref="602197876"/>
+ </object>
+ <int key="connectionID">273</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">dataSource</string>
+ <reference key="source" ref="522643855"/>
+ <reference key="destination" ref="1001"/>
+ </object>
+ <int key="connectionID">274</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">removeButton</string>
+ <reference key="source" ref="1001"/>
+ <reference key="destination" ref="960187291"/>
+ </object>
+ <int key="connectionID">275</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">nextKeyView</string>
+ <reference key="source" ref="522643855"/>
+ <reference key="destination" ref="556251150"/>
+ </object>
+ <int key="connectionID">277</int>
+ </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@@ -1217,11 +1130,11 @@
<reference key="object" ref="813298639"/>
<object class="NSMutableArray" key="children">
<bool key="EncodedWithXMLCoder">YES</bool>
- <reference ref="205303038"/>
<reference ref="960187291"/>
<reference ref="478413208"/>
<reference ref="545397681"/>
<reference ref="482670840"/>
+ <reference ref="205303038"/>
</object>
<reference key="parent" ref="141381185"/>
</object>
@@ -1233,6 +1146,7 @@
<reference ref="522643855"/>
<reference ref="322405876"/>
<reference ref="336819166"/>
+ <reference ref="724842455"/>
</object>
<reference key="parent" ref="813298639"/>
</object>
@@ -1270,6 +1184,7 @@
<object class="NSMutableArray" key="children">
<bool key="EncodedWithXMLCoder">YES</bool>
<reference ref="901293108"/>
+ <reference ref="183746003"/>
</object>
<reference key="parent" ref="205303038"/>
</object>
@@ -1306,6 +1221,7 @@
<reference ref="350107303"/>
<reference ref="407061848"/>
<reference ref="556514169"/>
+ <reference ref="602197876"/>
</object>
<reference key="parent" ref="141381185"/>
</object>
@@ -1402,12 +1318,6 @@
<reference key="parent" ref="1002"/>
</object>
<object class="IBObjectRecord">
- <int key="objectID">148</int>
- <reference key="object" ref="524128400"/>
- <reference key="parent" ref="1002"/>
- <string key="objectName">Query Favorites</string>
- </object>
- <object class="IBObjectRecord">
<int key="objectID">205</int>
<reference key="object" ref="855448788"/>
<object class="NSMutableArray" key="children">
@@ -1526,6 +1436,39 @@
<reference key="object" ref="335130454"/>
<reference key="parent" ref="299613786"/>
</object>
+ <object class="IBObjectRecord">
+ <int key="objectID">263</int>
+ <reference key="object" ref="183746003"/>
+ <object class="NSMutableArray" key="children">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference ref="577317691"/>
+ </object>
+ <reference key="parent" ref="522643855"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">264</int>
+ <reference key="object" ref="577317691"/>
+ <reference key="parent" ref="183746003"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">265</int>
+ <reference key="object" ref="724842455"/>
+ <reference key="parent" ref="205303038"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">271</int>
+ <reference key="object" ref="602197876"/>
+ <object class="NSMutableArray" key="children">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference ref="615814080"/>
+ </object>
+ <reference key="parent" ref="36799862"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">272</int>
+ <reference key="object" ref="615814080"/>
+ <reference key="parent" ref="602197876"/>
+ </object>
</object>
</object>
<object class="NSMutableDictionary" key="flattenedProperties">
@@ -1560,7 +1503,6 @@
<string>14.ImportedFromIB2</string>
<string>142.IBPluginDependency</string>
<string>143.IBPluginDependency</string>
- <string>148.IBPluginDependency</string>
<string>15.IBPluginDependency</string>
<string>17.IBAttributePlaceholdersKey</string>
<string>17.IBPluginDependency</string>
@@ -1605,20 +1547,26 @@
<string>26.ImportedFromIB2</string>
<string>260.IBAttributePlaceholdersKey</string>
<string>260.IBPluginDependency</string>
+ <string>263.IBPluginDependency</string>
+ <string>264.IBPluginDependency</string>
+ <string>265.IBPluginDependency</string>
+ <string>27.CustomClassName</string>
<string>27.IBPluginDependency</string>
<string>27.ImportedFromIB2</string>
+ <string>271.IBPluginDependency</string>
+ <string>272.IBPluginDependency</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{296, 167}, {500, 371}}</string>
- <string>{{296, 167}, {500, 371}}</string>
+ <string>{{455, 97}, {500, 371}}</string>
+ <string>{{455, 97}, {500, 371}}</string>
<boolean value="NO"/>
<string>{196, 240}</string>
<string>{{357, 418}, {480, 270}}</string>
- <reference ref="5"/>
+ <boolean value="YES"/>
<string>{500, 371}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -1639,7 +1587,6 @@
<string>com.apple.InterfaceBuilder.CocoaPlugin</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">
@@ -1681,7 +1628,7 @@
<string>com.brandonwalkin.BWToolkit</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
- <string>{{347, 38}, {241, 152}}</string>
+ <string>{{312, -3}, {241, 152}}</string>
<string>com.brandonwalkin.BWToolkit</string>
<string>com.brandonwalkin.BWToolkit</string>
<object class="NSMutableDictionary">
@@ -1741,7 +1688,13 @@ cGxhY2luZyBhbGwgY3VycmVudCBmYXZvcml0ZXMgcHJlc3Mg4oyYKQ</string>
</object>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>ImageAndTextCell</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
</object>
</object>
<object class="NSMutableDictionary" key="unlocalizedProperties">
@@ -1764,7 +1717,7 @@ cGxhY2luZyBhbGwgY3VycmVudCBmYXZvcml0ZXMgcHJlc3Mg4oyYKQ</string>
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">262</int>
+ <int key="maxID">277</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -1931,6 +1884,14 @@ cGxhY2luZyBhbGwgY3VycmVudCBmYXZvcml0ZXMgcHJlc3Mg4oyYKQ</string>
<object class="NSMutableArray" key="referencedPartialClassDescriptionsV3.1+">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBPartialClassDescription">
+ <string key="className">ImageAndTextCell</string>
+ <string key="superclassName">NSTextFieldCell</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBDocumentRelativeSource</string>
+ <string key="minorKey">../../Source/ImageAndTextCell.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
<string key="className">NSObject</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier" id="348289768">
<string key="majorKey">IBDocumentRelativeSource</string>
@@ -1976,7 +1937,7 @@ cGxhY2luZyBhbGwgY3VycmVudCBmYXZvcml0ZXMgcHJlc3Mg4oyYKQ</string>
<string>favoriteNameTextField</string>
<string>favoriteQueryTextView</string>
<string>favoritesTableView</string>
- <string>queryFavoritesController</string>
+ <string>removeButton</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -1985,7 +1946,7 @@ cGxhY2luZyBhbGwgY3VycmVudCBmYXZvcml0ZXMgcHJlc3Mg4oyYKQ</string>
<string>NSTextField</string>
<string>NSTextView</string>
<string>NSTableView</string>
- <string>NSArrayController</string>
+ <string>id</string>
</object>
</object>
<reference key="sourceIdentifier" ref="348289768"/>
diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m
index dcb42c26..2088642f 100644
--- a/Source/CustomQuery.m
+++ b/Source/CustomQuery.m
@@ -171,6 +171,12 @@
contextInfo:@"addAllToNewQueryFavorite"];
}
else if ([queryFavoritesButton indexOfSelectedItem] == 3) {
+
+ // init query favorites controller
+ [prefs synchronize];
+ if(favoritesManager) [favoritesManager release];
+ favoritesManager = [[SPQueryFavoriteManager alloc] initWithDelegate:self];
+
// Open query favorite manager
[NSApp beginSheet:[favoritesManager window]
modalForWindow:tableWindow
@@ -187,7 +193,9 @@
if(replaceContent)
[textView setSelectedRange:NSMakeRange(0,[[textView string] length])];
- [textView insertText:[[[prefs objectForKey:@"queryFavorites"] objectAtIndex:([queryFavoritesButton indexOfSelectedItem] - 6)] objectForKey:@"query"]];
+ // [textView insertText:[[[prefs objectForKey:@"queryFavorites"] objectAtIndex:([queryFavoritesButton indexOfSelectedItem] - 6)] objectForKey:@"query"]];
+ // The actual query strings have been already stored as tooltip
+ [textView insertText:[[queryFavoritesButton selectedItem] toolTip]];
}
}
@@ -196,9 +204,12 @@
*/
- (IBAction)chooseQueryHistory:(id)sender
{
+
+ [prefs synchronize];
+
// Choose history item
if ([queryHistoryButton indexOfSelectedItem] > 1) {
-;
+
BOOL replaceContent = [prefs boolForKey:@"QueryHistoryReplacesContent"];
if([[NSApp currentEvent] modifierFlags] & (NSShiftKeyMask|NSControlKeyMask|NSAlternateKeyMask|NSCommandKeyMask))
@@ -233,6 +244,7 @@
// [queryHistoryButton addItemWithTitle:NSLocalizedString(@"Query History…",@"Title of query history popup button")];
[prefs setObject:[NSArray array] forKey:@"queryHistory"];
+ [prefs synchronize];
}
// "Shift Right" menu item - indent the selection with an additional tab.
@@ -2389,8 +2401,20 @@
*/
- (void)queryFavoritesHaveBeenUpdated:(id)manager
{
- // NSInteger i;
- NSMutableArray *favorites = ([favoritesManager queryFavorites]) ? [favoritesManager queryFavorites] : [prefs objectForKey:@"queryFavorites"];
+
+ NSMutableArray *favorites = [[NSMutableArray alloc] init];
+
+ // Invoked after adding a favorite from inside CustomQuery
+ if(manager == nil) {
+ [favorites addObjectsFromArray:[prefs objectForKey:@"queryFavorites"]];
+ }
+ // Invoked by the query favorite manager
+ else if(manager == favoritesManager){
+ // Update global query favorites
+ [favorites addObjectsFromArray:[favoritesManager globalQueryFavorites]];
+ [prefs setObject:favorites forKey:@"queryFavorites"];
+ [prefs synchronize];
+ }
// Remove all favorites beginning from the end
while([queryFavoritesButton numberOfItems] > 6)
@@ -2400,13 +2424,19 @@
NSMenu *menu = [queryFavoritesButton menu];
int i = 6;
for (NSDictionary *favorite in favorites) {
- NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:[favorite objectForKey:@"name"] action:NULL keyEquivalent:@""];
+ NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:[NSString stringWithString:[favorite objectForKey:@"name"]] action:NULL keyEquivalent:@""];
[item setTag:i++];
- [item setToolTip:[favorite objectForKey:@"query"]];
+ [item setToolTip:[NSString stringWithString:[favorite objectForKey:@"query"]]];
[menu addItem:item];
[item release];
}
+
+ [favorites release];
+
+ [prefs synchronize];
+ [queryFavoritesSearchField setStringValue:@""];
+
}
#pragma mark -
@@ -2459,7 +2489,9 @@
queryToBeAddded = [textView string];
}
- [favorites addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:[queryFavoriteNameTextField stringValue], queryToBeAddded, nil] forKeys:[NSArray arrayWithObjects:@"name", @"query", nil]]];
+ [favorites addObject:[NSDictionary dictionaryWithObjects:
+ [NSArray arrayWithObjects:[queryFavoriteNameTextField stringValue], queryToBeAddded, nil]
+ forKeys:[NSArray arrayWithObjects:@"name", @"query", nil]]];
[prefs setObject:favorites forKey:@"queryFavorites"];
[prefs synchronize];
@@ -2527,9 +2559,6 @@
// init tableView's data source
fullResult = [[NSMutableArray alloc] init];
- // init query favorites controller
- favoritesManager = [[SPQueryFavoriteManager alloc] initWithDelegate:self];
-
prefs = [NSUserDefaults standardUserDefaults];
}
diff --git a/Source/SPQueryFavoriteManager.h b/Source/SPQueryFavoriteManager.h
index c7ce22e0..820f2a1a 100644
--- a/Source/SPQueryFavoriteManager.h
+++ b/Source/SPQueryFavoriteManager.h
@@ -25,6 +25,14 @@
#import <Cocoa/Cocoa.h>
+enum sp_favorite_types
+{
+ SP_FAVORITETYPE_HEADER = 0,
+ SP_FAVORITETYPE_GLOBAL = 1,
+ SP_FAVORITETYPE_CONNECTION = 2,
+};
+
+
@interface NSObject (SPQueryFavoriteManagerDelegate)
- (void)queryFavoritesHaveBeenUpdated:(id)manager;
@@ -43,13 +51,21 @@
IBOutlet NSTableView *favoritesTableView;
IBOutlet NSTextField *favoriteNameTextField;
IBOutlet NSTextView *favoriteQueryTextView;
- IBOutlet NSArrayController *queryFavoritesController;
+ IBOutlet id removeButton;
+
+ NSMutableArray *favorites;
+ NSMutableArray *favoriteProperties;
+
+ NSMutableString *pendingQueryString;
+
+ NSUInteger selectedRowBeforeChangingSelection;
}
- (id)initWithDelegate:(id)managerDelegate;
// Accessors
-- (NSMutableArray *)queryFavorites;
+- (NSMutableArray *)globalQueryFavorites;
+- (NSMutableArray *)connectionQueryFavorites;
- (id)customQueryInstance;
// IBAction methods
diff --git a/Source/SPQueryFavoriteManager.m b/Source/SPQueryFavoriteManager.m
index df5b802a..e49dbb13 100644
--- a/Source/SPQueryFavoriteManager.m
+++ b/Source/SPQueryFavoriteManager.m
@@ -24,13 +24,21 @@
// More info at <http://code.google.com/p/sequel-pro/>
#import "SPQueryFavoriteManager.h"
+#import "ImageAndTextCell.h"
#import "SPEncodingPopupAccessory.h"
#define DEFAULT_QUERY_FAVORITE_FILE_EXTENSION @"sql"
#define DEFAULT_SEQUELPRO_FILE_EXTENSION @"spf"
+#define SP_MULTIPLE_SELECTION_PLACEHOLDER_STRING NSLocalizedString(@"[multiple selection]", @"[multiple selection]")
+#define SP_NO_SELECTION_PLACEHOLDER_STRING NSLocalizedString(@"[no selection]", @"[no selection]")
+
#define QUERY_FAVORITES_PB_DRAG_TYPE @"SequelProQueryFavoritesPasteboard"
+@interface SPQueryFavoriteManager (Private)
+- (void)_writePendingQueryString;
+@end
+
@implementation SPQueryFavoriteManager
/**
@@ -42,6 +50,11 @@
delegate = managerDelegate;
prefs = [NSUserDefaults standardUserDefaults];
+
+ favoriteProperties = [[NSMutableArray alloc] init];
+ favorites = [[NSMutableArray alloc] init];
+ selectedRowBeforeChangingSelection = 0;
+ pendingQueryString = [[NSMutableString alloc] init];
delegateRespondsToFavoriteUpdates = [delegate respondsToSelector:@selector(queryFavoritesHaveBeenUpdated:)];
}
@@ -49,11 +62,20 @@
return self;
}
+- (void)dealloc
+{
+ [favoriteProperties release];
+ [favorites release];
+ [pendingQueryString release];
+ [super dealloc];
+}
+
/**
* Upon awakening bind the query text view's background colour.
*/
- (void)awakeFromNib
{
+
[favoriteQueryTextView setAllowsDocumentBackgroundColorChange:YES];
NSMutableDictionary *bindingOptions = [NSMutableDictionary dictionary];
@@ -64,23 +86,64 @@
toObject:[NSUserDefaultsController sharedUserDefaultsController]
withKeyPath:@"values.CustomQueryEditorBackgroundColor"
options:bindingOptions];
-
+
+
+ [favorites addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"GLOBAL", @"name", nil]];
+ [favoriteProperties addObject:[NSNumber numberWithInt:SP_FAVORITETYPE_HEADER]];
+
+ // Build data source for global queryFavorites (as mutable copy! otherwise each
+ // change will be stored in the prefs at once)
+ if([prefs objectForKey:@"queryFavorites"]) {
+ for(id fav in [prefs objectForKey:@"queryFavorites"]) {
+ [favorites addObject:[fav mutableCopy]];
+ [favoriteProperties addObject:[NSNumber numberWithInt:SP_FAVORITETYPE_GLOBAL]];
+ }
+ }
+ [favoritesTableView reloadData];
+
+ // Set Remove button state
+ [removeButton setEnabled:([favorites count] > 1)];
+
// Select the first query
- [queryFavoritesController setSelectionIndex:0];
-
+ [favoritesTableView selectRowIndexes:[NSIndexSet indexSetWithIndex:1] byExtendingSelection:NO];
+
// Register drag types
- [favoritesTableView registerForDraggedTypes:[NSArray arrayWithObject:QUERY_FAVORITES_PB_DRAG_TYPE]];
+ [favoritesTableView registerForDraggedTypes:[NSArray arrayWithObject:QUERY_FAVORITES_PB_DRAG_TYPE]];
}
#pragma mark -
#pragma mark Accessor methods
/**
- * Returns the query favorites array.
+ * Returns the global query favorites array.
*/
-- (NSMutableArray *)queryFavorites
+- (NSMutableArray *)globalQueryFavorites
{
- return [queryFavoritesController arrangedObjects];
+ NSMutableArray *globals = [NSMutableArray array];
+
+ NSUInteger i;
+
+ for(i=1; i<[favorites count]; i++)
+ if([[favoriteProperties objectAtIndex:i] intValue] == SP_FAVORITETYPE_GLOBAL)
+ [globals addObject:[favorites objectAtIndex:i]];
+
+ return globals;
+}
+
+/**
+ * Returns the global query favorites array.
+ */
+- (NSMutableArray *)connectionQueryFavorites
+{
+ NSMutableArray *conns = [NSMutableArray array];
+
+ NSUInteger i;
+
+ for(i=1; i<[favorites count]; i++)
+ if([[favoriteProperties objectAtIndex:i] intValue] == SP_FAVORITETYPE_CONNECTION)
+ [conns addObject:[favorites objectAtIndex:i]];
+
+ return conns;
}
/**
@@ -99,20 +162,24 @@
*/
- (IBAction)addQueryFavorite:(id)sender
{
+
+ [self _writePendingQueryString];
NSMutableDictionary *favorite = [NSMutableDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"New Favorite", @"", nil] forKeys:[NSArray arrayWithObjects:@"name", @"query", nil]];
- [queryFavoritesController addObject:favorite];
- [queryFavoritesController setSelectionIndex:([[queryFavoritesController arrangedObjects] count] - 1)];
-
+ [favorites addObject:favorite];
+ [favoriteProperties addObject:[NSNumber numberWithInt:SP_FAVORITETYPE_GLOBAL]];
[favoritesTableView reloadData];
- [favoritesTableView scrollRowToVisible:[favoritesTableView selectedRow]];
+
+ [favoritesTableView selectRowIndexes:[NSIndexSet indexSetWithIndex:([favorites count] - 1)] byExtendingSelection:NO];
- [prefs synchronize];
+ [favoritesTableView scrollRowToVisible:[favoritesTableView selectedRow]];
+
+ selectedRowBeforeChangingSelection = [favorites count] - 1;
+
+ [removeButton setEnabled:([favorites count] > 1)];
- // Inform the delegate that the query favorites have been updated
- if (delegateRespondsToFavoriteUpdates) {
- [delegate queryFavoritesHaveBeenUpdated:self];
- }
+ [[self window] makeFirstResponder:favoriteNameTextField];
+
}
/**
@@ -167,16 +234,21 @@
if ([favoritesTableView numberOfSelectedRows] == 1) {
NSMutableDictionary *favorite = [NSMutableDictionary dictionaryWithObjects:[NSArray arrayWithObjects:[[favoriteNameTextField stringValue] stringByAppendingFormat:@" Copy"], [favoriteQueryTextView string], nil] forKeys:[NSArray arrayWithObjects:@"name", @"query", nil]];
- [queryFavoritesController addObject:favorite];
- [queryFavoritesController setSelectionIndex:([[queryFavoritesController arrangedObjects] count] - 1)];
+ [self _writePendingQueryString];
+
+ [favorites addObject:favorite];
+ [favoriteProperties addObject:[NSNumber numberWithInt:SP_FAVORITETYPE_GLOBAL]];
[favoritesTableView reloadData];
+
+ // Update selection
+ [favoritesTableView selectRowIndexes:[NSIndexSet indexSetWithIndex:([favorites count] - 1)] byExtendingSelection:NO];
+ selectedRowBeforeChangingSelection = [favorites count] - 1;
+
[favoritesTableView scrollRowToVisible:[favoritesTableView selectedRow]];
- // Inform the delegate that the query favorites have been updated
- if (delegateRespondsToFavoriteUpdates) {
- [delegate queryFavoritesHaveBeenUpdated:self];
- }
+ [[self window] makeFirstResponder:favoriteNameTextField];
+
}
}
@@ -231,16 +303,23 @@
- (IBAction)closeQueryManagerSheet:(id)sender
{
- // Ensure taht last changes will be written to prefs
- [[self window] makeFirstResponder:favoritesTableView];
- [prefs synchronize];
-
[NSApp endSheet:[self window] returnCode:0];
[[self window] orderOut:self];
-
- // Inform the delegate that the query favorites have been updated
- if (delegateRespondsToFavoriteUpdates) {
- [delegate queryFavoritesHaveBeenUpdated:self];
+
+ // Save button was pressed
+ if([sender tag]) {
+ // Ensure that last changes will be written to prefs
+ // if only one favorite is selected; otherwise unstable state
+ if ([favoritesTableView numberOfSelectedRows] == 1) {
+ [self _writePendingQueryString];
+ [[self window] makeFirstResponder:favoritesTableView];
+ [favoritesTableView selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRowBeforeChangingSelection] byExtendingSelection:NO];
+ }
+
+ // Inform the delegate that the query favorites have been updated
+ if (delegateRespondsToFavoriteUpdates)
+ [delegate queryFavoritesHaveBeenUpdated:self];
+
}
}
@@ -270,17 +349,191 @@
/**
* Returns the number of query favorites.
*/
-- (int)numberOfRowsInTableView:(NSTableView *)aTableView
+- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
{
- return [[queryFavoritesController arrangedObjects] count];
+ return [favorites count];
}
/**
* Returns the value for the requested table column and row index.
*/
-- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
+- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
{
- return [[[queryFavoritesController arrangedObjects] objectAtIndex:rowIndex] objectForKey:[aTableColumn identifier]];
+ if(![[favorites objectAtIndex:rowIndex] objectForKey:[aTableColumn identifier]]) return @"";
+
+ return [[favorites objectAtIndex:rowIndex] objectForKey:[aTableColumn identifier]];
+}
+
+/*
+ * Save favorite names if inline edited (suppress empty names)
+ */
+- (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
+{
+
+ if([[aTableColumn identifier] isEqualToString:@"name"] && [anObject length]) {
+ [[favorites objectAtIndex:rowIndex] setObject:[anObject description] forKey:@"name"];
+ [[favorites objectAtIndex:rowIndex] setObject:[favoriteQueryTextView string] forKey:@"query"];
+ [favoriteNameTextField setStringValue:[anObject description]];
+ }
+
+ [favoritesTableView reloadData];
+}
+
+/*
+ * Before selecting an other favorite save pending query string changes
+ * and make sure that no group table item can be selected
+ */
+- (BOOL)tableView:(NSTableView *)aTableView shouldSelectRow:(NSInteger)rowIndex
+{
+ [pendingQueryString setString:[favoriteQueryTextView string]];
+ [self _writePendingQueryString];
+ return ([[favoriteProperties objectAtIndex:rowIndex] intValue] == SP_FAVORITETYPE_HEADER) ? NO : YES;
+}
+
+/*
+ * Update name and query view and control several table selection modi
+ */
+- (void)tableViewSelectionDidChange:(NSNotification *)aNotification
+{
+
+ // store the last selected favorite for writing the pending query string
+ // - for a single favorite selection
+ if([favoritesTableView numberOfSelectedRows] == 1)
+ selectedRowBeforeChangingSelection = [favoritesTableView selectedRow];
+ // - for multiple favorite selection
+ if([favoritesTableView numberOfSelectedRows] > 1) {
+
+ // Save query string directly
+ if(selectedRowBeforeChangingSelection > 0 && selectedRowBeforeChangingSelection < [favorites count])
+ [[favorites objectAtIndex:selectedRowBeforeChangingSelection] setObject:[favoriteQueryTextView string] forKey:@"query"];
+
+ // Update name text field
+ [[favoriteNameTextField cell] setPlaceholderString:SP_MULTIPLE_SELECTION_PLACEHOLDER_STRING];
+ [favoriteNameTextField setStringValue:@""];
+ [favoriteNameTextField setEditable:NO];
+ [favoriteNameTextField setSelectable:NO];
+
+ // This is an "hack"; if one set it to @"" it could happen that
+ // the wrong pending query string will be saved
+ [favoriteQueryTextView setTextColor:[NSColor clearColor]];
+ [favoriteQueryTextView setEditable:NO];
+ [favoriteQueryTextView setSelectable:NO];
+
+ return;
+
+ } else {
+ [favoriteNameTextField setEditable:YES];
+ [favoriteNameTextField setSelectable:YES];
+ [favoriteQueryTextView setSelectable:YES];
+ [favoriteQueryTextView setEditable:YES];
+ }
+
+
+ // only the "GLOBAL" header is in the table
+ if([favorites count] < 2) {
+ [self _writePendingQueryString];
+ [[self window] makeFirstResponder:favoritesTableView];
+ [[favoriteNameTextField cell] setPlaceholderString:SP_NO_SELECTION_PLACEHOLDER_STRING];
+ [favoriteNameTextField setStringValue:@""];
+ [favoriteQueryTextView setString:@""];
+ [pendingQueryString setString:@""];
+ selectedRowBeforeChangingSelection = -1;
+ return;
+ }
+
+ // Update name and query field contents
+ NSUInteger row = (NSUInteger)[[aNotification object] selectedRow];
+
+ // This is needed if one deletes the last table item
+ if(row > [favorites count] - 1) row = [favorites count] - 1;
+ if(row < 1) row = 1;
+
+ [favoriteNameTextField setStringValue:[[favorites objectAtIndex:row] objectForKey:@"name"]];
+ [favoriteQueryTextView setString:[[favorites objectAtIndex:row] objectForKey:@"query"]];
+
+}
+
+/*
+ * Set indention levels for headers and favorites
+ * (maybe in the future use an image for headers for expanding and collapsing)
+ */
+- (void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
+{
+ if([[favoriteProperties objectAtIndex:rowIndex] intValue] == SP_FAVORITETYPE_HEADER && [[aTableColumn identifier] isEqualToString:@"name"]) {
+ // if([[[favoriteProperties objectAtIndex:rowIndex] objectForKey:@"isGroup"] isEqualToString:@"1"])
+ // [(ImageAndTextCell*)aCell setImage:[NSImage imageNamed:@"NSRightFacingTriangleTemplate"]];
+ // else
+ // [(ImageAndTextCell*)aCell setImage:[NSImage imageNamed:@"NSLeftFacingTriangleTemplate"]];
+ [(ImageAndTextCell*)aCell setIndentationLevel:0];
+ }
+ else if([[favoriteProperties objectAtIndex:rowIndex] intValue] != SP_FAVORITETYPE_HEADER && [[aTableColumn identifier] isEqualToString:@"name"]) {
+ // [(ImageAndTextCell*)aCell setImage:[NSImage imageNamed:@"dummy-small"]];
+ [(ImageAndTextCell*)aCell setIndentationLevel:1];
+ }
+}
+
+/*
+ * A row of an header return is slighlty larger
+ */
+- (CGFloat)tableView:(NSTableView *)aTableView heightOfRow:(NSInteger)rowIndex
+{
+ return ([[favoriteProperties objectAtIndex:rowIndex] intValue] == SP_FAVORITETYPE_HEADER) ? 20 : 18;
+}
+
+/*
+ * Only favorite name can be edited inline
+ */
+- (BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
+{
+ return ([[favoriteProperties objectAtIndex:rowIndex] intValue] == SP_FAVORITETYPE_HEADER) ? NO : YES;
+}
+
+/*
+ * favoriteProperties holds the data if a table row is a group header or not
+ */
+- (BOOL)tableView:(NSTableView *)aTableView isGroupRow:(NSInteger)rowIndex
+{
+ return ([[favoriteProperties objectAtIndex:rowIndex] intValue] == SP_FAVORITETYPE_HEADER) ? YES : NO;
+}
+
+/*
+ * Changes in the name text field will be saved in data source directly
+ * to update the table view accordingly
+ */
+- (void)controlTextDidChange:(NSNotification *)notification
+{
+
+ // Do nothing if no favorite is selected
+ if([favoritesTableView selectedRow] < 1) return;
+
+ id object = [notification object];
+
+ if(object == favoriteNameTextField) {
+ [[favorites objectAtIndex:[favoritesTableView selectedRow]] setObject:[favoriteNameTextField stringValue] forKey:@"name"];
+ [favoritesTableView reloadData];
+ }
+
+}
+
+/*
+ * Changes in the query text view will be cached as pending query string which will update
+ * the data source before selecting an other favorite or before an other event.
+ * If multiple rows are selected update name field.
+ */
+- (void)textViewDidChangeSelection:(NSNotification *)notification
+{
+ id object = [notification object];
+
+ if(object == favoriteQueryTextView) {
+ if(![favoriteQueryTextView isEditable]) return;
+ [pendingQueryString setString:[NSString stringWithString:[favoriteQueryTextView string]]];
+ if([favoritesTableView numberOfSelectedRows] > 1) {
+ [[favoriteNameTextField cell] setPlaceholderString:SP_MULTIPLE_SELECTION_PLACEHOLDER_STRING];
+ [favoriteNameTextField setStringValue:@""];
+ selectedRowBeforeChangingSelection = -1;
+ return;
+ }
+ }
}
#pragma mark -
@@ -291,6 +544,10 @@
*/
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem
{
+
+ // Disable all if only GLOBAL is in the table
+ if([favorites count] < 2) return NO;
+
SEL action = [menuItem action];
if ( (action == @selector(copyQueryFavorite:)) ||
@@ -304,7 +561,7 @@
return ([favoritesTableView numberOfSelectedRows] > 0);
}
else if (action == @selector(removeAllQueryFavorites:)) {
- return ([[queryFavoritesController arrangedObjects] count] > 0);
+ return ([favorites count] > 0);
}
return YES;
@@ -319,15 +576,25 @@
- (BOOL)tableView:(NSTableView *)tableView writeRows:(NSArray *)rows toPasteboard:(NSPasteboard *)pboard
{
if ([rows count] == 1) {
+
NSArray *pboardTypes = [NSArray arrayWithObject:QUERY_FAVORITES_PB_DRAG_TYPE];
NSInteger originalRow = [[rows objectAtIndex:0] intValue];
-
+
[pboard declareTypes:pboardTypes owner:nil];
[pboard setString:[[NSNumber numberWithInt:originalRow] stringValue] forType:QUERY_FAVORITES_PB_DRAG_TYPE];
-
+
+ // Save query string before dragging
+ // and suppress the writing of pending query string changes
+ [[favorites objectAtIndex:selectedRowBeforeChangingSelection] setObject:[favoriteQueryTextView string] forKey:@"query"];
+ selectedRowBeforeChangingSelection = -1;
return YES;
+ } else {
+ [favoritesTableView selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRowBeforeChangingSelection] byExtendingSelection:NO];
+ [[favoriteNameTextField cell] setPlaceholderString:SP_MULTIPLE_SELECTION_PLACEHOLDER_STRING];
+ [favoriteNameTextField setStringValue:@""];
+ [favoriteQueryTextView setTextColor:[NSColor clearColor]];
}
-
+
return NO;
}
@@ -342,7 +609,7 @@
if (([pboardTypes containsObject:QUERY_FAVORITES_PB_DRAG_TYPE]) && (operation == NSTableViewDropAbove)) {
NSInteger originalRow = [[[info draggingPasteboard] stringForType:QUERY_FAVORITES_PB_DRAG_TYPE] intValue];
- if ((row != originalRow) && (row != (originalRow + 1))) {
+ if ((row != originalRow) && (row != (originalRow + 1)) && (row > 0)) {
return NSDragOperationMove;
}
}
@@ -354,6 +621,7 @@
/**
* Return whether or not to accept the drop of the supplied rows.
*/
+
- (BOOL)tableView:(NSTableView *)tableView acceptDrop:(id <NSDraggingInfo>)info row:(NSInteger)row dropOperation:(NSTableViewDropOperation)operation
{
NSInteger originalRow = [[[info draggingPasteboard] stringForType:QUERY_FAVORITES_PB_DRAG_TYPE] intValue];
@@ -361,10 +629,10 @@
if (destinationRow > originalRow) destinationRow--;
- NSMutableDictionary *draggedRow = [NSMutableDictionary dictionaryWithDictionary:[[queryFavoritesController arrangedObjects] objectAtIndex:originalRow]];
+ NSMutableDictionary *draggedRow = [NSMutableDictionary dictionaryWithDictionary:[favorites objectAtIndex:originalRow]];
- [queryFavoritesController removeObjectAtArrangedObjectIndex:originalRow];
- [queryFavoritesController insertObject:draggedRow atArrangedObjectIndex:destinationRow];
+ [favorites removeObjectAtIndex:originalRow];
+ [favorites insertObject:draggedRow atIndex:destinationRow];
[favoritesTableView reloadData];
[favoritesTableView selectRowIndexes:[NSIndexSet indexSetWithIndex:destinationRow] byExtendingSelection:NO];
@@ -380,34 +648,48 @@
*/
- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(NSString *)contextInfo
{
- if ([contextInfo isEqualToString:@"removeAllFavorites"]) {
- if (returnCode == NSAlertAlternateReturn) {
- [queryFavoritesController removeObjects:[queryFavoritesController arrangedObjects]];
- }
- }
+ // Is disabled - do we need that?
+ // if ([contextInfo isEqualToString:@"removeAllFavorites"]) {
+ // if (returnCode == NSAlertAlternateReturn) {
+ // [favorites removeObjects:[queryFavoritesController arrangedObjects]];
+ // }
+ // }
if([contextInfo isEqualToString:@"removeSelectedFavorites"]) {
if (returnCode == NSAlertAlternateReturn) {
NSIndexSet *indexes = [favoritesTableView selectedRowIndexes];
// get last index
NSUInteger currentIndex = [indexes lastIndex];
+ NSUInteger idx = currentIndex;
+
+ // Prevend to write pending changes
+ selectedRowBeforeChangingSelection = -1;
+ [pendingQueryString setString:@""];
while (currentIndex != NSNotFound) {
- [queryFavoritesController removeObjectAtArrangedObjectIndex:currentIndex];
+ [favorites removeObjectAtIndex:currentIndex];
+ [favoriteProperties removeObjectAtIndex:currentIndex];
// get next index (beginning from the end)
currentIndex = [indexes indexLessThanIndex:currentIndex];
+ [favoritesTableView reloadData];
}
- [favoritesTableView reloadData];
-
- [prefs synchronize];
-
// Set focus to favorite list to avoid an unstable state
[[self window] makeFirstResponder:favoritesTableView];
- // Inform the delegate that the query favorites have been updated
- if (delegateRespondsToFavoriteUpdates)
- [delegate queryFavoritesHaveBeenUpdated:self];
+ // Try to reselect a favorite
+ [favoritesTableView selectRowIndexes:[NSIndexSet indexSet] byExtendingSelection:NO];
+ if(idx > [favorites count]-1)
+ idx = [favorites count]-1;
+ if(idx != 0)
+ [favoritesTableView selectRowIndexes:[NSIndexSet indexSetWithIndex:idx] byExtendingSelection:NO];
+
+ if(idx > 1) {
+ [favoriteNameTextField setStringValue:[[favorites objectAtIndex:idx] objectForKey:@"name"]];
+ [favoriteQueryTextView setString:[[favorites objectAtIndex:idx] objectForKey:@"query"]];
+ }
+
+ [removeButton setEnabled:([favorites count] > 1)];
}
}
}
@@ -443,15 +725,12 @@
NSIndexSet *indexes = [favoritesTableView selectedRowIndexes];
- // get last index
- NSUInteger currentIndex = [indexes lastIndex];
+ // Get selected items and preserve the order
+ NSUInteger i;
+ for (i=1; i<[favorites count]; i++)
+ if([indexes containsIndex:i])
+ [favoriteData addObject:[favorites objectAtIndex:i]];
- while (currentIndex != NSNotFound) {
- [favoriteData addObject:[[self queryFavorites] objectAtIndex:currentIndex]];
-
- // get next index (beginning from the end)
- currentIndex = [indexes indexLessThanIndex:currentIndex];
- }
[data setObject:favoriteData forKey:@"queryFavorites"];
[spfdata setObject:data forKey:@"data"];
@@ -480,4 +759,18 @@
}
}
+/*
+ * Before an other favorite will be chosen or an other event will unfocus the
+ * query text view store the query into the data source
+ */
+- (void)_writePendingQueryString
+{
+ if(selectedRowBeforeChangingSelection > 0 && selectedRowBeforeChangingSelection < [favorites count] ) {
+ [[favorites objectAtIndex:selectedRowBeforeChangingSelection] setObject:[NSString stringWithString:pendingQueryString] forKey:@"query"];
+ } else if(selectedRowBeforeChangingSelection = 0) {
+ [[favorites objectAtIndex:[favoritesTableView selectedRow]] setObject:[NSString stringWithString:pendingQueryString] forKey:@"query"];
+ }
+ [pendingQueryString setString:@""];
+}
+
@end