diff options
author | rowanbeentje <rowan@beent.je> | 2009-04-02 01:23:26 +0000 |
---|---|---|
committer | rowanbeentje <rowan@beent.je> | 2009-04-02 01:23:26 +0000 |
commit | 00910549fefaaa0954aa080a3ec1be5a4746062b (patch) | |
tree | 896bc68f6426e58be635ef0238aad7b045057651 | |
parent | 8fd7a25952b3d5317a22e14c83af06b56c32710a (diff) | |
download | sequelpro-00910549fefaaa0954aa080a3ec1be5a4746062b.tar.gz sequelpro-00910549fefaaa0954aa080a3ec1be5a4746062b.tar.bz2 sequelpro-00910549fefaaa0954aa080a3ec1be5a4746062b.zip |
- Add a new "gear" action menu underneath the custom query view, including a number of items:
- Add menu commands for "Run All" and "Run Selected", with additional keyboard shortcuts - cmd-R for Run all, addressing #137
- Add menu commands for indenting text, outdenting text, and to show autocompletion is available
- Add menu commands to toggle autopairing and autoindenting
- Also hidden menu commands for history navigation and clearing, not hooked in yet (see #207)
- Add a new method to our string additions: lineRangesForRange
- Add "shift right" (indent) and "shift left" (outdent) support to CMTextView, including for multiple lines
-rw-r--r-- | Interfaces/English.lproj/DBView.xib | 524 | ||||
-rw-r--r-- | Source/CMTextView.h | 18 | ||||
-rw-r--r-- | Source/CMTextView.m | 134 | ||||
-rw-r--r-- | Source/CustomQuery.h | 7 | ||||
-rw-r--r-- | Source/CustomQuery.m | 53 | ||||
-rw-r--r-- | Source/SPStringAdditions.h | 1 | ||||
-rw-r--r-- | Source/SPStringAdditions.m | 33 |
7 files changed, 728 insertions, 42 deletions
diff --git a/Interfaces/English.lproj/DBView.xib b/Interfaces/English.lproj/DBView.xib index fda5eac2..46020c39 100644 --- a/Interfaces/English.lproj/DBView.xib +++ b/Interfaces/English.lproj/DBView.xib @@ -8,7 +8,6 @@ <string key="IBDocument.HIToolboxVersion">353.00</string> <object class="NSMutableArray" key="IBDocument.EditedObjectIDs"> <bool key="EncodedWithXMLCoder">YES</bool> - <integer value="5"/> </object> <object class="NSArray" key="IBDocument.PluginDependencies"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -45,7 +44,7 @@ <string key="NSWindowContentMaxSize">{3.40282e+38, 3.40282e+38}</string> <string key="NSWindowContentMinSize">{780, 480}</string> <object class="NSView" key="NSWindowView" id="579726586"> - <reference key="NSNextResponder"/> + <nil key="NSNextResponder"/> <int key="NSvFlags">256</int> <object class="NSMutableArray" key="NSSubviews"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -175,7 +174,6 @@ </object> <string key="NSFrame">{{1, 1}, {194, 393}}</string> <reference key="NSSuperview" ref="233472824"/> - <reference key="NSNextKeyView" ref="251040077"/> <reference key="NSDocView" ref="251040077"/> <object class="NSColor" key="NSBGColor" id="1024678221"> <int key="NSColorSpace">6</int> @@ -207,7 +205,6 @@ </object> <string key="NSFrameSize">{196, 395}</string> <reference key="NSSuperview" ref="355288374"/> - <reference key="NSNextKeyView" ref="73685676"/> <int key="NSsFlags">530</int> <reference key="NSVScroller" ref="693168867"/> <reference key="NSHScroller" ref="656188692"/> @@ -292,7 +289,6 @@ </object> <string key="NSFrame">{{1, 1}, {194, 123}}</string> <reference key="NSSuperview" ref="298226231"/> - <reference key="NSNextKeyView" ref="347093764"/> <reference key="NSDocView" ref="347093764"/> <reference key="NSBGColor" ref="1024678221"/> <int key="NScvFlags">4</int> @@ -319,7 +315,6 @@ </object> <string key="NSFrame">{{0, 404}, {196, 125}}</string> <reference key="NSSuperview" ref="355288374"/> - <reference key="NSNextKeyView" ref="685057119"/> <int key="NSsFlags">530</int> <reference key="NSVScroller" ref="245346414"/> <reference key="NSHScroller" ref="353686052"/> @@ -371,7 +366,7 @@ <reference key="NSControlView" ref="1029554648"/> <int key="NSButtonFlags">-2042609409</int> <int key="NSButtonFlags2">35</int> - <object class="NSCustomResource" key="NSNormalImage" id="414958262"> + <object class="NSCustomResource" key="NSNormalImage"> <string key="NSClassName">NSImage</string> <string key="NSResourceName">button_action</string> </object> @@ -386,7 +381,10 @@ <string key="NSKeyEquiv"/> <int key="NSKeyEquivModMask">1048576</int> <int key="NSMnemonicLoc">2147483647</int> - <reference key="NSImage" ref="414958262"/> + <object class="NSCustomResource" key="NSImage"> + <string key="NSClassName">NSImage</string> + <string key="NSResourceName">button_action</string> + </object> <string key="NSAction">_popUpItemAction:</string> <reference key="NSTarget" ref="753352469"/> </object> @@ -551,7 +549,7 @@ <object class="NSTabViewItem" id="831053945"> <string key="NSIdentifier">source</string> <object class="NSView" key="NSView" id="461236772"> - <nil key="NSNextResponder"/> + <reference key="NSNextResponder" ref="714795046"/> <int key="NSvFlags">256</int> <object class="NSMutableArray" key="NSSubviews"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -1275,7 +1273,6 @@ </object> <string key="NSFrame">{{1, 17}, {625, 289}}</string> <reference key="NSSuperview" ref="22340145"/> - <reference key="NSNextKeyView" ref="715508012"/> <reference key="NSDocView" ref="715508012"/> <reference key="NSBGColor" ref="1024678221"/> <int key="NScvFlags">4</int> @@ -1308,7 +1305,6 @@ </object> <string key="NSFrame">{{1, 0}, {625, 17}}</string> <reference key="NSSuperview" ref="22340145"/> - <reference key="NSNextKeyView" ref="926883367"/> <reference key="NSDocView" ref="926883367"/> <reference key="NSBGColor" ref="1024678221"/> <int key="NScvFlags">4</int> @@ -1317,7 +1313,6 @@ </object> <string key="NSFrame">{{-1, 22}, {627, 307}}</string> <reference key="NSSuperview" ref="220777809"/> - <reference key="NSNextKeyView" ref="16936123"/> <int key="NSsFlags">562</int> <reference key="NSVScroller" ref="943144555"/> <reference key="NSHScroller" ref="456666876"/> @@ -1751,7 +1746,6 @@ </object> <string key="NSFrame">{{1, 17}, {625, 141}}</string> <reference key="NSSuperview" ref="376224367"/> - <reference key="NSNextKeyView" ref="584834515"/> <reference key="NSDocView" ref="584834515"/> <reference key="NSBGColor" ref="1024678221"/> <int key="NScvFlags">4</int> @@ -1784,7 +1778,6 @@ </object> <string key="NSFrame">{{1, 0}, {625, 17}}</string> <reference key="NSSuperview" ref="376224367"/> - <reference key="NSNextKeyView" ref="459548655"/> <reference key="NSDocView" ref="459548655"/> <reference key="NSBGColor" ref="1024678221"/> <int key="NScvFlags">4</int> @@ -1793,7 +1786,6 @@ </object> <string key="NSFrame">{{-1, 22}, {627, 159}}</string> <reference key="NSSuperview" ref="1063281455"/> - <reference key="NSNextKeyView" ref="794929378"/> <int key="NSsFlags">562</int> <reference key="NSVScroller" ref="1019209947"/> <reference key="NSHScroller" ref="328951385"/> @@ -1938,6 +1930,7 @@ </object> </object> <string key="NSFrame">{{10, 7}, {637, 544}}</string> + <reference key="NSSuperview" ref="714795046"/> </object> <string key="NSLabel">Structure</string> <reference key="NSColor" ref="62854682"/> @@ -1946,7 +1939,7 @@ <object class="NSTabViewItem" id="624106058"> <string key="NSIdentifier">content</string> <object class="NSView" key="NSView" id="1013108064"> - <reference key="NSNextResponder" ref="714795046"/> + <nil key="NSNextResponder"/> <int key="NSvFlags">256</int> <object class="NSMutableArray" key="NSSubviews"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -2553,7 +2546,6 @@ </object> </object> <string key="NSFrame">{{10, 7}, {637, 544}}</string> - <reference key="NSSuperview" ref="714795046"/> </object> <string key="NSLabel">Content</string> <reference key="NSColor" ref="62854682"/> @@ -2843,7 +2835,7 @@ <object class="NSPopUpButton" id="86760255"> <reference key="NSNextResponder" ref="345834048"/> <int key="NSvFlags">268</int> - <string key="NSFrame">{{214, 248}, {186, 22}}</string> + <string key="NSFrame">{{251, 248}, {186, 22}}</string> <reference key="NSSuperview" ref="345834048"/> <bool key="NSEnabled">YES</bool> <object class="NSPopUpButtonCell" key="NSCell" id="830957297"> @@ -2892,7 +2884,7 @@ <object class="NSPopUpButton" id="872178320"> <reference key="NSNextResponder" ref="345834048"/> <int key="NSvFlags">264</int> - <string key="NSFrame">{{17, 248}, {195, 22}}</string> + <string key="NSFrame">{{54, 248}, {195, 22}}</string> <reference key="NSSuperview" ref="345834048"/> <bool key="NSEnabled">YES</bool> <object class="NSPopUpButtonCell" key="NSCell" id="416049103"> @@ -2993,6 +2985,216 @@ <int key="NSPeriodicInterval">25</int> </object> </object> + <object class="NSPopUpButton" id="306040895"> + <reference key="NSNextResponder" ref="345834048"/> + <int key="NSvFlags">268</int> + <string key="NSFrame">{{5, 248}, {47, 22}}</string> + <reference key="NSSuperview" ref="345834048"/> + <bool key="NSEnabled">YES</bool> + <object class="NSPopUpButtonCell" key="NSCell" id="862191789"> + <int key="NSCellFlags">-2076049856</int> + <int key="NSCellFlags2">134350848</int> + <reference key="NSSupport" ref="26"/> + <reference key="NSControlView" ref="306040895"/> + <int key="NSButtonFlags">-2036186881</int> + <int key="NSButtonFlags2">65</int> + <reference key="NSAlternateImage" ref="790379580"/> + <string key="NSAlternateContents"/> + <string key="NSKeyEquivalent"/> + <int key="NSPeriodicDelay">400</int> + <int key="NSPeriodicInterval">75</int> + <object class="NSMenuItem" key="NSMenuItem" id="119993756"> + <reference key="NSMenu" ref="856738817"/> + <bool key="NSIsHidden">YES</bool> + <string key="NSTitle"/> + <string key="NSKeyEquiv"/> + <int key="NSKeyEquivModMask">1048576</int> + <int key="NSMnemonicLoc">2147483647</int> + <object class="NSCustomResource" key="NSImage"> + <string key="NSClassName">NSImage</string> + <string key="NSResourceName">NSActionTemplate</string> + </object> + <reference key="NSOnImage" ref="594889092"/> + <reference key="NSMixedImage" ref="515625830"/> + <string key="NSAction">_popUpItemAction:</string> + <reference key="NSTarget" ref="862191789"/> + </object> + <bool key="NSMenuItemRespectAlignment">YES</bool> + <object class="NSMenu" key="NSMenu" id="856738817"> + <string key="NSTitle">Custom Query Actions</string> + <object class="NSMutableArray" key="NSMenuItems"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="119993756"/> + <object class="NSMenuItem" id="16843309"> + <reference key="NSMenu" ref="856738817"/> + <string key="NSTitle">Run All Queries</string> + <string key="NSKeyEquiv">r</string> + <int key="NSKeyEquivModMask">1048576</int> + <int key="NSMnemonicLoc">2147483647</int> + <reference key="NSOnImage" ref="594889092"/> + <reference key="NSMixedImage" ref="515625830"/> + <string key="NSAction">_popUpItemAction:</string> + <int key="NSTag">1</int> + <reference key="NSTarget" ref="862191789"/> + </object> + <object class="NSMenuItem" id="841484892"> + <reference key="NSMenu" ref="856738817"/> + <bool key="NSIsDisabled">YES</bool> + <string key="NSTitle">Run Current Query</string> + <string key="NSKeyEquiv">r</string> + <int key="NSKeyEquivModMask">1572864</int> + <int key="NSMnemonicLoc">2147483647</int> + <reference key="NSOnImage" ref="594889092"/> + <reference key="NSMixedImage" ref="515625830"/> + <string key="NSAction">_popUpItemAction:</string> + <int key="NSTag">2</int> + <reference key="NSTarget" ref="862191789"/> + </object> + <object class="NSMenuItem" id="16193184"> + <reference key="NSMenu" ref="856738817"/> + <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="594889092"/> + <reference key="NSMixedImage" ref="515625830"/> + <string key="NSAction">_popUpItemAction:</string> + <reference key="NSTarget" ref="862191789"/> + </object> + <object class="NSMenuItem" id="912951930"> + <reference key="NSMenu" ref="856738817"/> + <bool key="NSIsHidden">YES</bool> + <string key="NSTitle">Previous Query from History</string> + <string type="base64-UTF8" key="NSKeyEquiv">75yAA</string> + <int key="NSKeyEquivModMask">262144</int> + <int key="NSMnemonicLoc">2147483647</int> + <reference key="NSOnImage" ref="594889092"/> + <reference key="NSMixedImage" ref="515625830"/> + <string key="NSAction">_popUpItemAction:</string> + <int key="NSTag">3</int> + <reference key="NSTarget" ref="862191789"/> + </object> + <object class="NSMenuItem" id="948704282"> + <reference key="NSMenu" ref="856738817"/> + <bool key="NSIsHidden">YES</bool> + <string key="NSTitle">Next Query from History</string> + <string type="base64-UTF8" key="NSKeyEquiv">75yBA</string> + <int key="NSKeyEquivModMask">262144</int> + <int key="NSMnemonicLoc">2147483647</int> + <reference key="NSOnImage" ref="594889092"/> + <reference key="NSMixedImage" ref="515625830"/> + <string key="NSAction">_popUpItemAction:</string> + <int key="NSTag">4</int> + <reference key="NSTarget" ref="862191789"/> + </object> + <object class="NSMenuItem" id="302197001"> + <reference key="NSMenu" ref="856738817"/> + <bool key="NSIsHidden">YES</bool> + <string key="NSTitle">Clear History</string> + <string key="NSKeyEquiv"/> + <int key="NSMnemonicLoc">2147483647</int> + <reference key="NSOnImage" ref="594889092"/> + <reference key="NSMixedImage" ref="515625830"/> + <string key="NSAction">_popUpItemAction:</string> + <int key="NSTag">5</int> + <reference key="NSTarget" ref="862191789"/> + </object> + <object class="NSMenuItem" id="396840368"> + <reference key="NSMenu" ref="856738817"/> + <bool key="NSIsSeparator">YES</bool> + <bool key="NSIsHidden">YES</bool> + <string key="NSTitle"/> + <string key="NSKeyEquiv"/> + <int key="NSMnemonicLoc">2147483647</int> + <reference key="NSOnImage" ref="594889092"/> + <reference key="NSMixedImage" ref="515625830"/> + <string key="NSAction">_popUpItemAction:</string> + <reference key="NSTarget" ref="862191789"/> + </object> + <object class="NSMenuItem" id="794483714"> + <reference key="NSMenu" ref="856738817"/> + <string key="NSTitle">Shift Right</string> + <string key="NSKeyEquiv">]</string> + <int key="NSKeyEquivModMask">1048576</int> + <int key="NSMnemonicLoc">2147483647</int> + <reference key="NSOnImage" ref="594889092"/> + <reference key="NSMixedImage" ref="515625830"/> + <string key="NSAction">_popUpItemAction:</string> + <int key="NSTag">6</int> + <reference key="NSTarget" ref="862191789"/> + </object> + <object class="NSMenuItem" id="249395809"> + <reference key="NSMenu" ref="856738817"/> + <string key="NSTitle">Shift Left</string> + <string key="NSKeyEquiv">[</string> + <int key="NSKeyEquivModMask">1048576</int> + <int key="NSMnemonicLoc">2147483647</int> + <reference key="NSOnImage" ref="594889092"/> + <reference key="NSMixedImage" ref="515625830"/> + <string key="NSAction">_popUpItemAction:</string> + <int key="NSTag">7</int> + <reference key="NSTarget" ref="862191789"/> + </object> + <object class="NSMenuItem" id="476443841"> + <reference key="NSMenu" ref="856738817"/> + <string key="NSTitle">Completion List</string> + <string type="base64-UTF8" key="NSKeyEquiv">Gw</string> + <int key="NSKeyEquivModMask">524288</int> + <int key="NSMnemonicLoc">2147483647</int> + <reference key="NSOnImage" ref="594889092"/> + <reference key="NSMixedImage" ref="515625830"/> + <string key="NSAction">_popUpItemAction:</string> + <int key="NSTag">8</int> + <reference key="NSTarget" ref="862191789"/> + </object> + <object class="NSMenuItem" id="31327174"> + <reference key="NSMenu" ref="856738817"/> + <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="594889092"/> + <reference key="NSMixedImage" ref="515625830"/> + <string key="NSAction">_popUpItemAction:</string> + <reference key="NSTarget" ref="862191789"/> + </object> + <object class="NSMenuItem" id="372816397"> + <reference key="NSMenu" ref="856738817"/> + <string key="NSTitle">Indent New Lines</string> + <string key="NSKeyEquiv"/> + <int key="NSMnemonicLoc">2147483647</int> + <int key="NSState">1</int> + <reference key="NSOnImage" ref="594889092"/> + <reference key="NSMixedImage" ref="515625830"/> + <string key="NSAction">_popUpItemAction:</string> + <int key="NSTag">9</int> + <reference key="NSTarget" ref="862191789"/> + </object> + <object class="NSMenuItem" id="275385613"> + <reference key="NSMenu" ref="856738817"/> + <string key="NSTitle">Auto-pair Characters</string> + <string key="NSKeyEquiv"/> + <int key="NSMnemonicLoc">2147483647</int> + <int key="NSState">1</int> + <reference key="NSOnImage" ref="594889092"/> + <reference key="NSMixedImage" ref="515625830"/> + <string key="NSAction">_popUpItemAction:</string> + <int key="NSTag">10</int> + <reference key="NSTarget" ref="862191789"/> + </object> + </object> + <bool key="NSNoAutoenable">YES</bool> + </object> + <int key="NSSelectedIndex">8</int> + <bool key="NSPullDown">YES</bool> + <int key="NSPreferredEdge">1</int> + <bool key="NSUsesItemFromMenu">YES</bool> + <bool key="NSAltersState">YES</bool> + <int key="NSArrowPosition">2</int> + </object> + </object> </object> <string key="NSFrame">{{0, 165}, {627, 269}}</string> <reference key="NSSuperview" ref="894339536"/> @@ -3438,14 +3640,14 @@ <reference key="NSTabView" ref="714795046"/> </object> </object> - <reference key="NSSelectedTabViewItem" ref="624106058"/> + <reference key="NSSelectedTabViewItem" ref="831053945"/> <reference key="NSFont" ref="26"/> <int key="NSTvFlags">134217731</int> <bool key="NSAllowTruncatedLabels">YES</bool> <bool key="NSDrawsBackground">YES</bool> <object class="NSMutableArray" key="NSSubviews"> <bool key="EncodedWithXMLCoder">YES</bool> - <reference ref="1013108064"/> + <reference ref="461236772"/> </object> </object> </object> @@ -3461,7 +3663,6 @@ </object> </object> <string key="NSFrameSize">{863, 550}</string> - <reference key="NSSuperview"/> </object> <string key="NSScreenRect">{{0, 0}, {1440, 878}}</string> <string key="NSMinSize">{780, 502}</string> @@ -11628,6 +11829,110 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> </object> <int key="connectionID">5224</int> </object> + <object class="IBConnectionRecord"> + <object class="IBActionConnection" key="connection"> + <string key="label">performClick:</string> + <reference key="source" ref="811536132"/> + <reference key="destination" ref="16843309"/> + </object> + <int key="connectionID">5259</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">runSelectionMenuItem</string> + <reference key="source" ref="601471102"/> + <reference key="destination" ref="841484892"/> + </object> + <int key="connectionID">5260</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBActionConnection" key="connection"> + <string key="label">performClick:</string> + <reference key="source" ref="1009499029"/> + <reference key="destination" ref="841484892"/> + </object> + <int key="connectionID">5261</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">autoindentMenuItem</string> + <reference key="source" ref="601471102"/> + <reference key="destination" ref="372816397"/> + </object> + <int key="connectionID">5262</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">autopairMenuItem</string> + <reference key="source" ref="601471102"/> + <reference key="destination" ref="275385613"/> + </object> + <int key="connectionID">5263</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBActionConnection" key="connection"> + <string key="label">gearMenuItemSelected:</string> + <reference key="source" ref="601471102"/> + <reference key="destination" ref="275385613"/> + </object> + <int key="connectionID">5264</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBActionConnection" key="connection"> + <string key="label">gearMenuItemSelected:</string> + <reference key="source" ref="601471102"/> + <reference key="destination" ref="372816397"/> + </object> + <int key="connectionID">5265</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">completionListMenuItem</string> + <reference key="source" ref="601471102"/> + <reference key="destination" ref="476443841"/> + </object> + <int key="connectionID">5266</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">shiftLeftMenuItem</string> + <reference key="source" ref="601471102"/> + <reference key="destination" ref="249395809"/> + </object> + <int key="connectionID">5267</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">shiftRightMenuItem</string> + <reference key="source" ref="601471102"/> + <reference key="destination" ref="794483714"/> + </object> + <int key="connectionID">5268</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBActionConnection" key="connection"> + <string key="label">gearMenuItemSelected:</string> + <reference key="source" ref="601471102"/> + <reference key="destination" ref="476443841"/> + </object> + <int key="connectionID">5269</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBActionConnection" key="connection"> + <string key="label">gearMenuItemSelected:</string> + <reference key="source" ref="601471102"/> + <reference key="destination" ref="249395809"/> + </object> + <int key="connectionID">5270</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBActionConnection" key="connection"> + <string key="label">gearMenuItemSelected:</string> + <reference key="source" ref="601471102"/> + <reference key="destination" ref="794483714"/> + </object> + <int key="connectionID">5271</int> + </object> </object> <object class="IBMutableOrderedSet" key="objectRecords"> <object class="NSArray" key="orderedObjects"> @@ -15465,10 +15770,11 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> <object class="NSMutableArray" key="children"> <bool key="EncodedWithXMLCoder">YES</bool> <reference ref="678281118"/> - <reference ref="872178320"/> <reference ref="811536132"/> - <reference ref="86760255"/> <reference ref="1009499029"/> + <reference ref="306040895"/> + <reference ref="86760255"/> + <reference ref="872178320"/> </object> <reference key="parent" ref="894339536"/> </object> @@ -16465,6 +16771,116 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> <reference key="object" ref="924446696"/> <reference key="parent" ref="23713489"/> </object> + <object class="IBObjectRecord"> + <int key="objectID">5242</int> + <reference key="object" ref="306040895"/> + <object class="NSMutableArray" key="children"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="862191789"/> + </object> + <reference key="parent" ref="345834048"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">5243</int> + <reference key="object" ref="862191789"/> + <object class="NSMutableArray" key="children"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="856738817"/> + </object> + <reference key="parent" ref="306040895"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">5244</int> + <reference key="object" ref="856738817"/> + <object class="NSMutableArray" key="children"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="119993756"/> + <reference ref="16843309"/> + <reference ref="841484892"/> + <reference ref="16193184"/> + <reference ref="912951930"/> + <reference ref="948704282"/> + <reference ref="396840368"/> + <reference ref="794483714"/> + <reference ref="302197001"/> + <reference ref="249395809"/> + <reference ref="476443841"/> + <reference ref="31327174"/> + <reference ref="372816397"/> + <reference ref="275385613"/> + </object> + <reference key="parent" ref="862191789"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">5245</int> + <reference key="object" ref="119993756"/> + <reference key="parent" ref="856738817"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">5246</int> + <reference key="object" ref="16843309"/> + <reference key="parent" ref="856738817"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">5247</int> + <reference key="object" ref="841484892"/> + <reference key="parent" ref="856738817"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">5248</int> + <reference key="object" ref="16193184"/> + <reference key="parent" ref="856738817"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">5249</int> + <reference key="object" ref="912951930"/> + <reference key="parent" ref="856738817"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">5250</int> + <reference key="object" ref="948704282"/> + <reference key="parent" ref="856738817"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">5251</int> + <reference key="object" ref="396840368"/> + <reference key="parent" ref="856738817"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">5252</int> + <reference key="object" ref="794483714"/> + <reference key="parent" ref="856738817"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">5253</int> + <reference key="object" ref="302197001"/> + <reference key="parent" ref="856738817"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">5254</int> + <reference key="object" ref="249395809"/> + <reference key="parent" ref="856738817"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">5255</int> + <reference key="object" ref="476443841"/> + <reference key="parent" ref="856738817"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">5256</int> + <reference key="object" ref="31327174"/> + <reference key="parent" ref="856738817"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">5257</int> + <reference key="object" ref="372816397"/> + <reference key="parent" ref="856738817"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">5258</int> + <reference key="object" ref="275385613"/> + <reference key="parent" ref="856738817"/> + </object> </object> </object> <object class="NSMutableDictionary" key="flattenedProperties"> @@ -17475,6 +17891,24 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> <string>5201.IBAttributePlaceholdersKey</string> <string>5201.IBPluginDependency</string> <string>5202.IBPluginDependency</string> + <string>5242.IBPluginDependency</string> + <string>5243.IBPluginDependency</string> + <string>5244.IBEditorWindowLastContentRect</string> + <string>5244.IBPluginDependency</string> + <string>5245.IBPluginDependency</string> + <string>5246.IBPluginDependency</string> + <string>5247.IBPluginDependency</string> + <string>5248.IBPluginDependency</string> + <string>5249.IBPluginDependency</string> + <string>5250.IBPluginDependency</string> + <string>5251.IBPluginDependency</string> + <string>5252.IBPluginDependency</string> + <string>5253.IBPluginDependency</string> + <string>5254.IBPluginDependency</string> + <string>5255.IBPluginDependency</string> + <string>5256.IBPluginDependency</string> + <string>5257.IBPluginDependency</string> + <string>5258.IBPluginDependency</string> <string>557.IBPluginDependency</string> <string>557.ImportedFromIB2</string> <string>565.IBEditorWindowLastContentRect</string> @@ -17941,7 +18375,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> <object class="IBToolTipAttribute" key="NS.object.0"> <string key="name">ToolTip</string> <reference key="object" ref="811536132"/> - <string key="toolTip">Run all queries in the editor (Enter or fn-Return)</string> + <string type="base64-UTF8" key="toolTip">UnVuIGFsbCBxdWVyaWVzIGluIHRoZSBlZGl0b3IgKOKMmFIsIEVudGVyIG9yIGZuLVJldHVybik</string> </object> </object> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> @@ -18800,8 +19234,8 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> </object> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>{{80, 456}, {863, 550}}</string> - <string>{{80, 456}, {863, 550}}</string> + <string>{{80, 306}, {863, 550}}</string> + <string>{{80, 306}, {863, 550}}</string> <reference ref="9"/> <reference ref="9"/> <string>{{62, 352}, {845, 504}}</string> @@ -18984,6 +19418,24 @@ aGUgYWN0aXZlIHNlbGVjdGlvbiAo4oyl4oyYUik</string> <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>{{286, 465}, {236, 220}}</string> + <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>com.apple.InterfaceBuilder.CocoaPlugin</string> + <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>com.apple.InterfaceBuilder.CocoaPlugin</string> + <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>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <reference ref="9"/> <string>{{456, 426}, {292, 112}}</string> <string>{{456, 426}, {292, 112}}</string> @@ -19254,7 +19706,7 @@ Y2hhbmdlIHRoZSBvcmRlcg</string> </object> </object> <nil key="sourceID"/> - <int key="maxID">5224</int> + <int key="maxID">5271</int> </object> <object class="IBClassDescriber" key="IBDocument.Classes"> <object class="NSMutableArray" key="referencedPartialClassDescriptions"> @@ -19328,6 +19780,7 @@ Y2hhbmdlIHRoZSBvcmRlcg</string> <string>closeQueryFavoritesSheet:</string> <string>closeSheet:</string> <string>copyQueryFavorite:</string> + <string>gearMenuItemSelected:</string> <string>removeQueryFavorite:</string> <string>runAllQueries:</string> <string>runSelectedQueries:</string> @@ -19343,6 +19796,7 @@ Y2hhbmdlIHRoZSBvcmRlcg</string> <string>id</string> <string>id</string> <string>id</string> + <string>id</string> </object> </object> <object class="NSMutableDictionary" key="outlets"> @@ -19350,6 +19804,9 @@ Y2hhbmdlIHRoZSBvcmRlcg</string> <object class="NSMutableArray" key="dict.sortedKeys"> <bool key="EncodedWithXMLCoder">YES</bool> <string>affectedRowsText</string> + <string>autoindentMenuItem</string> + <string>autopairMenuItem</string> + <string>completionListMenuItem</string> <string>copyQueryFavoriteButton</string> <string>customQueryView</string> <string>errorText</string> @@ -19360,6 +19817,9 @@ Y2hhbmdlIHRoZSBvcmRlcg</string> <string>removeQueryFavoriteButton</string> <string>runAllButton</string> <string>runSelectionButton</string> + <string>runSelectionMenuItem</string> + <string>shiftLeftMenuItem</string> + <string>shiftRightMenuItem</string> <string>tableWindow</string> <string>textView</string> <string>valueSheet</string> @@ -19368,6 +19828,9 @@ Y2hhbmdlIHRoZSBvcmRlcg</string> <object class="NSMutableArray" key="dict.values"> <bool key="EncodedWithXMLCoder">YES</bool> <string>id</string> + <string>NSMenuItem</string> + <string>NSMenuItem</string> + <string>NSMenuItem</string> <string>id</string> <string>CMCopyTable</string> <string>id</string> @@ -19378,8 +19841,11 @@ Y2hhbmdlIHRoZSBvcmRlcg</string> <string>id</string> <string>id</string> <string>id</string> + <string>NSMenuItem</string> + <string>NSMenuItem</string> + <string>NSMenuItem</string> <string>id</string> - <string>id</string> + <string>CMTextView</string> <string>id</string> <string>id</string> </object> diff --git a/Source/CMTextView.h b/Source/CMTextView.h index 761e1189..4dadb33d 100644 --- a/Source/CMTextView.h +++ b/Source/CMTextView.h @@ -32,13 +32,15 @@ - (BOOL) isNextCharMarkedBy:(id)attribute; - (BOOL) areAdjacentCharsLinked; - (BOOL) wrapSelectionWithPrefix:(NSString *)prefix suffix:(NSString *)suffix; -- (NSArray *)completionsForPartialWordRange:(NSRange)charRange indexOfSelectedItem:(int *)index; -- (NSArray *)keywords; -- (void)setAutoindent:(BOOL)enableAutoindent; -- (BOOL)autoindent; -- (void)setAutoindentIgnoresEnter:(BOOL)enableAutoindentIgnoresEnter; -- (BOOL)autoindentIgnoresEnter; -- (void)setAutopair:(BOOL)enableAutopair; -- (BOOL)autopair; +- (BOOL) shiftSelectionRight; +- (BOOL) shiftSelectionLeft; +- (NSArray *) completionsForPartialWordRange:(NSRange)charRange indexOfSelectedItem:(int *)index; +- (NSArray *) keywords; +- (void) setAutoindent:(BOOL)enableAutoindent; +- (BOOL) autoindent; +- (void) setAutoindentIgnoresEnter:(BOOL)enableAutoindentIgnoresEnter; +- (BOOL) autoindentIgnoresEnter; +- (void) setAutopair:(BOOL)enableAutopair; +- (BOOL) autopair; @end diff --git a/Source/CMTextView.m b/Source/CMTextView.m index 2532cf1e..cfd42884 100644 --- a/Source/CMTextView.m +++ b/Source/CMTextView.m @@ -252,15 +252,18 @@ YY_BUFFER_STATE yy_scan_string (const char *); { // Handle newlines, adding any indentation found on the current line to the new line - ignoring the enter key if appropriate - if (aSelector == @selector(insertNewline:) && (!autoindentIgnoresEnter || [[NSApp currentEvent] keyCode] != 0x4C)) { + if (aSelector == @selector(insertNewline:) + && autoindentEnabled + && (!autoindentIgnoresEnter || [[NSApp currentEvent] keyCode] != 0x4C)) + { NSString *textViewString = [[self textStorage] string]; NSString *currentLine, *indentString = nil; NSScanner *whitespaceScanner; - NSUInteger lineStart, lineEnd; + NSRange currentLineRange; // Extract the current line based on the text caret or selection start position - [textViewString getLineStart:&lineStart end:NULL contentsEnd:&lineEnd forRange:NSMakeRange([self selectedRange].location, 0)]; - currentLine = [[NSString alloc] initWithString:[textViewString substringWithRange:NSMakeRange(lineStart, lineEnd - lineStart)]]; + currentLineRange = [textViewString lineRangeForRange:NSMakeRange([self selectedRange].location, 0)]; + currentLine = [[NSString alloc] initWithString:[textViewString substringWithRange:currentLineRange]]; // Scan all indentation characters on the line into a string whitespaceScanner = [[NSScanner alloc] initWithString:currentLine]; @@ -283,6 +286,129 @@ YY_BUFFER_STATE yy_scan_string (const char *); /* + * Shifts the selection, if any, rightwards by indenting any selected lines with one tab. + * If the caret is within a line, the selection is not changed after the index; if the selection + * has length, all lines crossed by the length are indented and fully selected. + * Returns whether or not an indentation was performed. + */ +- (BOOL) shiftSelectionRight +{ + NSString *textViewString = [[self textStorage] string]; + NSRange currentLineRange; + NSArray *lineRanges; + NSString *tabString = @"\t"; + int i, indentedLinesLength = 0; + + if ([self selectedRange].location == NSNotFound) return NO; + + // Indent the currently selected line if the caret is within a single line + if ([self selectedRange].length == 0) { + NSRange currentLineRange; + + // Extract the current line range based on the text caret + currentLineRange = [textViewString lineRangeForRange:[self selectedRange]]; + + // Register the indent for undo + [self shouldChangeTextInRange:NSMakeRange(currentLineRange.location, 0) replacementString:tabString]; + + // Insert the new tab + [self replaceCharactersInRange:NSMakeRange(currentLineRange.location, 0) withString:tabString]; + + return YES; + } + + // Otherwise, the selection has a length - get an array of current line ranges for the specified selection + lineRanges = [textViewString lineRangesForRange:[self selectedRange]]; + + // Loop through the ranges, storing a count of the overall length. + for (i = 0; i < [lineRanges count]; i++) { + currentLineRange = NSRangeFromString([lineRanges objectAtIndex:i]); + indentedLinesLength += currentLineRange.length + 1; + + // Register the indent for undo + [self shouldChangeTextInRange:NSMakeRange(currentLineRange.location+i, 0) replacementString:tabString]; + + // Insert the new tab + [self replaceCharactersInRange:NSMakeRange(currentLineRange.location+i, 0) withString:tabString]; + } + + // Select the entirety of the new range + [self setSelectedRange:NSMakeRange(NSRangeFromString([lineRanges objectAtIndex:0]).location, indentedLinesLength)]; + + return YES; +} + + +/* + * Shifts the selection, if any, leftwards by un-indenting any selected lines by one tab if possible. + * If the caret is within a line, the selection is not changed after the undent; if the selection has + * length, all lines crossed by the length are un-indented and fully selected. + * Returns whether or not an indentation was performed. + */ +- (BOOL) shiftSelectionLeft +{ + NSString *textViewString = [[self textStorage] string]; + NSRange currentLineRange; + NSArray *lineRanges; + int i, unindentedLines = 0, unindentedLinesLength = 0; + + if ([self selectedRange].location == NSNotFound) return NO; + + // Undent the currently selected line if the caret is within a single line + if ([self selectedRange].length == 0) { + NSRange currentLineRange; + + // Extract the current line range based on the text caret + currentLineRange = [textViewString lineRangeForRange:[self selectedRange]]; + + // Ensure that the line has length and that the first character is a tab + if (currentLineRange.length < 1 + || [textViewString characterAtIndex:currentLineRange.location] != '\t') + return NO; + + // Register the undent for undo + [self shouldChangeTextInRange:NSMakeRange(currentLineRange.location, 1) replacementString:@""]; + + // Remove the tab + [self replaceCharactersInRange:NSMakeRange(currentLineRange.location, 1) withString:@""]; + + return YES; + } + + // Otherwise, the selection has a length - get an array of current line ranges for the specified selection + lineRanges = [textViewString lineRangesForRange:[self selectedRange]]; + + // Loop through the ranges, storing a count of the total lines changed and the new length. + for (i = 0; i < [lineRanges count]; i++) { + currentLineRange = NSRangeFromString([lineRanges objectAtIndex:i]); + unindentedLinesLength += currentLineRange.length; + + // Ensure that the line has length and that the first character is a tab + if (currentLineRange.length < 1 + || [textViewString characterAtIndex:currentLineRange.location-unindentedLines] != '\t') + continue; + + // Register the undent for undo + [self shouldChangeTextInRange:NSMakeRange(currentLineRange.location-unindentedLines, 1) replacementString:@""]; + + // Remove the tab + [self replaceCharactersInRange:NSMakeRange(currentLineRange.location-unindentedLines, 1) withString:@""]; + + // As a line has been unindented, modify counts and lengths + unindentedLines++; + unindentedLinesLength--; + } + + // If a change was made, select the entirety of the new range and return success + if (unindentedLines) { + [self setSelectedRange:NSMakeRange(NSRangeFromString([lineRanges objectAtIndex:0]).location, unindentedLinesLength)]; + return YES; + } + + return NO; +} + +/* * Handle autocompletion, returning a list of suggested completions for the supplied character range. */ - (NSArray *)completionsForPartialWordRange:(NSRange)charRange indexOfSelectedItem:(int *)index diff --git a/Source/CustomQuery.h b/Source/CustomQuery.h index 1abc5e57..908dd594 100644 --- a/Source/CustomQuery.h +++ b/Source/CustomQuery.h @@ -46,6 +46,12 @@ IBOutlet id copyQueryFavoriteButton; IBOutlet id runSelectionButton; IBOutlet id runAllButton; + IBOutlet NSMenuItem *runSelectionMenuItem; + IBOutlet NSMenuItem *shiftLeftMenuItem; + IBOutlet NSMenuItem *shiftRightMenuItem; + IBOutlet NSMenuItem *completionListMenuItem; + IBOutlet NSMenuItem *autoindentMenuItem; + IBOutlet NSMenuItem *autopairMenuItem; NSArray *queryResult; NSUserDefaults *prefs; @@ -60,6 +66,7 @@ - (IBAction)chooseQueryFavorite:(id)sender; - (IBAction)chooseQueryHistory:(id)sender; - (IBAction)closeSheet:(id)sender; +- (IBAction)gearMenuItemSelected:(id)sender; // queryFavoritesSheet methods - (IBAction)addQueryFavorite:(id)sender; diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m index 115c4d36..baa81170 100644 --- a/Source/CustomQuery.m +++ b/Source/CustomQuery.m @@ -155,6 +155,49 @@ closes the sheet } +/* + * Perform simple actions (which don't require their own method), triggered by selecting the appropriate menu item + * in the "gear" action menu displayed beneath the cusotm query view. + */ +- (IBAction)gearMenuItemSelected:(id)sender +{ + + // "Shift Right" menu item - indent the selection with an additional tab. + if (sender == shiftRightMenuItem) { + [textView shiftSelectionRight]; + } + + // "Shift Left" menu item - un-indent the selection by one tab if possible. + if (sender == shiftLeftMenuItem) { + [textView shiftSelectionLeft]; + } + + // "Completion List" menu item - used to autocomplete. Uses a different shortcut to avoid the menu button flickering + // on normal autocomplete usage. + if (sender == completionListMenuItem) { + [textView complete:self]; + } + + // "Indent new lines" toggle + if (sender == autoindentMenuItem) { + BOOL enableAutoindent = ([autoindentMenuItem state] == NSOffState); + [prefs setBool:enableAutoindent forKey:@"CustomQueryAutoindent"]; + [prefs synchronize]; + [autoindentMenuItem setState:enableAutoindent?NSOnState:NSOffState]; + [textView setAutoindent:enableAutoindent]; + } + + // "Auto-pair characters" toggle + if (sender == autopairMenuItem) { + BOOL enableAutopair = ([autopairMenuItem state] == NSOffState); + [prefs setBool:enableAutopair forKey:@"CustomQueryAutopair"]; + [prefs synchronize]; + [autopairMenuItem setState:enableAutopair?NSOnState:NSOffState]; + [textView setAutopair:enableAutopair]; + } +} + + #pragma mark - #pragma mark queryFavoritesSheet methods @@ -549,8 +592,10 @@ sets the connection (received from TableDocument) and makes things that have to [textView setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; } [textView setContinuousSpellCheckingEnabled:NO]; + [autoindentMenuItem setState:([prefs boolForKey:@"CustomQueryAutoindent"]?NSOnState:NSOffState)]; [textView setAutoindent:[prefs boolForKey:@"CustomQueryAutoindent"]]; [textView setAutoindentIgnoresEnter:YES]; + [autopairMenuItem setState:([prefs boolForKey:@"CustomQueryAutopair"]?NSOnState:NSOffState)]; [textView setAutopair:[prefs boolForKey:@"CustomQueryAutopair"]]; [queryFavoritesView registerForDraggedTypes:[NSArray arrayWithObjects:@"SequelProPasteboard", nil]]; while ( (column = [enumerator nextObject]) ) @@ -891,9 +936,10 @@ traps enter key and // Ensure that the notification is from the custom query text view if ( [aNotification object] != textView ) return; - // If no text is selected, disable the button. + // If no text is selected, disable the button and action menu. if ( [textView selectedRange].location == NSNotFound ) { [runSelectionButton setEnabled:NO]; + [runSelectionMenuItem setEnabled:NO]; return; } @@ -922,12 +968,15 @@ traps enter key and ) { [runSelectionButton setTitle:NSLocalizedString(@"Run Current", @"Title of button to run current query in custom query view")]; + [runSelectionMenuItem setTitle:NSLocalizedString(@"Run Current Query", @"Title of action menu item to run current query in custom query view")]; // If a valid query is present at the cursor position, enable the button if ([self queryAtPosition:selectionPosition]) { [runSelectionButton setEnabled:YES]; + [runSelectionMenuItem setEnabled:YES]; } else { [runSelectionButton setEnabled:NO]; + [runSelectionMenuItem setEnabled:NO]; } } @@ -935,6 +984,8 @@ traps enter key and } else { [runSelectionButton setTitle:NSLocalizedString(@"Run Selection", @"Title of button to run selected text in custom query view")]; [runSelectionButton setEnabled:YES]; + [runSelectionMenuItem setTitle:NSLocalizedString(@"Run Selected Text", @"Title of action menu item to run selected text in custom query view")]; + [runSelectionMenuItem setEnabled:YES]; } } diff --git a/Source/SPStringAdditions.h b/Source/SPStringAdditions.h index be999ba4..1d706666 100644 --- a/Source/SPStringAdditions.h +++ b/Source/SPStringAdditions.h @@ -28,6 +28,7 @@ + (NSString *)stringForTimeInterval:(float)timeInterval; - (NSString *)backtickQuotedString; +- (NSArray *)lineRangesForRange:(NSRange)aRange; #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5 - (NSArray *)componentsSeparatedByCharactersInSet:(NSCharacterSet *)set; diff --git a/Source/SPStringAdditions.m b/Source/SPStringAdditions.m index 74c98b4f..2c719f6c 100644 --- a/Source/SPStringAdditions.m +++ b/Source/SPStringAdditions.m @@ -136,6 +136,39 @@ return quotedString; } +// ------------------------------------------------------------------------------- +// lineRangesForRange +// +// Returns an array of serialised NSRanges, each representing a line within the string +// which is at least partially covered by the NSRange supplied. +// Each line includes the line termination character(s) for the line. As per +// lineRangeForRange, lines are split by CR, LF, CRLF, U+2028 (Unicode line separator), +// or U+2029 (Unicode paragraph separator). +// ------------------------------------------------------------------------------- +- (NSArray *)lineRangesForRange:(NSRange)aRange +{ + NSMutableArray *lineRangesArray = [NSMutableArray array]; + NSRange currentLineRange; + + // Check that the range supplied is valid - if not return an empty array. + if (aRange.location == NSNotFound || aRange.location + aRange.length > [self length]) + return lineRangesArray; + + // Get the range of the first string covered by the specified range, and add it to the array + currentLineRange = [self lineRangeForRange:NSMakeRange(aRange.location, 0)]; + [lineRangesArray addObject:NSStringFromRange(currentLineRange)]; + + // Loop through until the line end matches or surpasses the end of the specified range + while (currentLineRange.location + currentLineRange.length < aRange.location + aRange.length) { + currentLineRange = [self lineRangeForRange:NSMakeRange(currentLineRange.location + currentLineRange.length, 0)]; + [lineRangesArray addObject:NSStringFromRange(currentLineRange)]; + } + + // Return the constructed array of ranges + return lineRangesArray; +} + + #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5 /* * componentsSeparatedByCharactersInSet: |