diff options
-rw-r--r-- | Interfaces/English.lproj/BundleEditor.xib | 745 | ||||
-rw-r--r-- | Source/SPAppController.h | 2 | ||||
-rw-r--r-- | Source/SPAppController.m | 166 | ||||
-rw-r--r-- | Source/SPBundleCommandTextView.m | 21 | ||||
-rw-r--r-- | Source/SPBundleEditorController.h | 15 | ||||
-rw-r--r-- | Source/SPBundleEditorController.m | 233 | ||||
-rw-r--r-- | Source/SPCopyTable.m | 202 | ||||
-rw-r--r-- | Source/SPEditSheetTextView.m | 21 | ||||
-rw-r--r-- | Source/SPStringAdditions.m | 2 | ||||
-rw-r--r-- | Source/SPTextView.h | 2 | ||||
-rw-r--r-- | Source/SPTextView.m | 195 | ||||
-rw-r--r-- | Source/SPTextViewAdditions.m | 83 |
12 files changed, 692 insertions, 995 deletions
diff --git a/Interfaces/English.lproj/BundleEditor.xib b/Interfaces/English.lproj/BundleEditor.xib index 5bbbb3c9..5ce66d26 100644 --- a/Interfaces/English.lproj/BundleEditor.xib +++ b/Interfaces/English.lproj/BundleEditor.xib @@ -23,7 +23,7 @@ </object> <object class="NSMutableArray" key="IBDocument.EditedObjectIDs"> <bool key="EncodedWithXMLCoder">YES</bool> - <integer value="820"/> + <integer value="686"/> </object> <object class="NSArray" key="IBDocument.PluginDependencies"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -446,7 +446,7 @@ <string>public.url</string> </object> </object> - <string key="NSFrameSize">{468, 92}</string> + <string key="NSFrameSize">{468, 112}</string> <reference key="NSSuperview" ref="971406968"/> <object class="NSTextContainer" key="NSTextContainer" id="1001899575"> <object class="NSLayoutManager" key="NSLayoutManager"> @@ -528,7 +528,7 @@ <nil key="NSDelegate"/> </object> </object> - <string key="NSFrame">{{1, 1}, {468, 190}}</string> + <string key="NSFrame">{{1, 1}, {468, 210}}</string> <reference key="NSSuperview" ref="179792134"/> <reference key="NSNextKeyView" ref="965862131"/> <reference key="NSDocView" ref="965862131"/> @@ -561,7 +561,7 @@ <double key="NSPercent">0.94565218687057495</double> </object> </object> - <string key="NSFrame">{{20, 105}, {470, 192}}</string> + <string key="NSFrame">{{20, 105}, {470, 212}}</string> <reference key="NSSuperview" ref="338542681"/> <reference key="NSNextKeyView" ref="971406968"/> <int key="NSsFlags">562</int> @@ -632,33 +632,6 @@ <integer value="1" key="style"/> </object> </object> - <object class="NSButton" id="892755176"> - <reference key="NSNextResponder" ref="338542681"/> - <int key="NSvFlags">268</int> - <string key="NSFrame">{{201, 390}, {201, 18}}</string> - <reference key="NSSuperview" ref="338542681"/> - <bool key="NSEnabled">YES</bool> - <object class="NSButtonCell" key="NSCell" id="1063662617"> - <int key="NSCellFlags">-2080244224</int> - <int key="NSCellFlags2">131072</int> - <string key="NSContents">Disable Bundle</string> - <reference key="NSSupport" ref="26"/> - <reference key="NSControlView" ref="892755176"/> - <int key="NSButtonFlags">1211912703</int> - <int key="NSButtonFlags2">2</int> - <object class="NSCustomResource" key="NSNormalImage"> - <string key="NSClassName">NSImage</string> - <string key="NSResourceName">NSSwitch</string> - </object> - <object class="NSButtonImageSource" key="NSAlternateImage"> - <string key="NSImageName">NSSwitch</string> - </object> - <string key="NSAlternateContents"/> - <string key="NSKeyEquivalent"/> - <int key="NSPeriodicDelay">200</int> - <int key="NSPeriodicInterval">25</int> - </object> - </object> <object class="NSPopUpButton" id="1013555552"> <reference key="NSNextResponder" ref="338542681"/> <int key="NSvFlags">268</int> @@ -725,6 +698,39 @@ <int key="NSArrowPosition">2</int> </object> </object> + <object class="NSPopUpButton" id="904079305"> + <reference key="NSNextResponder" ref="338542681"/> + <int key="NSvFlags">268</int> + <string key="NSFrame">{{236, 387}, {167, 22}}</string> + <reference key="NSSuperview" ref="338542681"/> + <bool key="NSEnabled">YES</bool> + <object class="NSPopUpButtonCell" key="NSCell" id="886363818"> + <int key="NSCellFlags">-2076049856</int> + <int key="NSCellFlags2">133120</int> + <reference key="NSSupport" ref="26"/> + <reference key="NSControlView" ref="904079305"/> + <int key="NSButtonFlags">109199615</int> + <int key="NSButtonFlags2">129</int> + <string key="NSAlternateContents"/> + <string key="NSKeyEquivalent"/> + <int key="NSPeriodicDelay">400</int> + <int key="NSPeriodicInterval">75</int> + <nil key="NSMenuItem"/> + <bool key="NSMenuItemRespectAlignment">YES</bool> + <object class="NSMenu" key="NSMenu" id="416241867"> + <string key="NSTitle">OtherViews</string> + <object class="NSMutableArray" key="NSMenuItems"> + <bool key="EncodedWithXMLCoder">YES</bool> + </object> + <reference key="NSMenuFont" ref="604392898"/> + </object> + <int key="NSSelectedIndex">-1</int> + <int key="NSPreferredEdge">1</int> + <bool key="NSUsesItemFromMenu">YES</bool> + <bool key="NSAltersState">YES</bool> + <int key="NSArrowPosition">2</int> + </object> + </object> <object class="NSPopUpButton" id="117047836"> <reference key="NSNextResponder" ref="338542681"/> <int key="NSvFlags">268</int> @@ -859,6 +865,38 @@ <reference key="NSTextColor" ref="576381864"/> </object> </object> + <object class="NSTextField" id="669651343"> + <reference key="NSNextResponder" ref="338542681"/> + <int key="NSvFlags">268</int> + <string key="NSFrame">{{236, 410}, {167, 14}}</string> + <reference key="NSSuperview" ref="338542681"/> + <bool key="NSEnabled">YES</bool> + <object class="NSTextFieldCell" key="NSCell" id="44795332"> + <int key="NSCellFlags">68288064</int> + <int key="NSCellFlags2">4326400</int> + <string key="NSContents">Scope:</string> + <reference key="NSSupport" ref="26"/> + <reference key="NSControlView" ref="669651343"/> + <reference key="NSBackgroundColor" ref="90467341"/> + <reference key="NSTextColor" ref="576381864"/> + </object> + </object> + <object class="NSTextField" id="864339274"> + <reference key="NSNextResponder" ref="338542681"/> + <int key="NSvFlags">268</int> + <string key="NSFrame">{{17, 320}, {167, 14}}</string> + <reference key="NSSuperview" ref="338542681"/> + <bool key="NSEnabled">YES</bool> + <object class="NSTextFieldCell" key="NSCell" id="553916693"> + <int key="NSCellFlags">68288064</int> + <int key="NSCellFlags2">4326400</int> + <string key="NSContents">Command:</string> + <reference key="NSSupport" ref="26"/> + <reference key="NSControlView" ref="864339274"/> + <reference key="NSBackgroundColor" ref="90467341"/> + <reference key="NSTextColor" ref="576381864"/> + </object> + </object> <object class="NSTextField" id="931989616"> <reference key="NSNextResponder" ref="338542681"/> <int key="NSvFlags">268</int> @@ -943,108 +981,6 @@ <reference key="NSTextColor" ref="676992401"/> </object> </object> - <object class="NSBox" id="477430580"> - <reference key="NSNextResponder" ref="338542681"/> - <int key="NSvFlags">10</int> - <object class="NSMutableArray" key="NSSubviews"> - <bool key="EncodedWithXMLCoder">YES</bool> - <object class="NSView" id="346382683"> - <reference key="NSNextResponder" ref="477430580"/> - <int key="NSvFlags">256</int> - <object class="NSMutableArray" key="NSSubviews"> - <bool key="EncodedWithXMLCoder">YES</bool> - <object class="NSButton" id="799580933"> - <reference key="NSNextResponder" ref="346382683"/> - <int key="NSvFlags">293</int> - <string key="NSFrame">{{16, 11}, {134, 17}}</string> - <reference key="NSSuperview" ref="346382683"/> - <int key="NSTag">1</int> - <bool key="NSEnabled">YES</bool> - <object class="NSButtonCell" key="NSCell" id="176613618"> - <int key="NSCellFlags">67239424</int> - <int key="NSCellFlags2">134348800</int> - <string key="NSContents">Query Editor</string> - <object class="NSFont" key="NSSupport" id="29"> - <string key="NSName">LucidaGrande-Bold</string> - <double key="NSSize">12</double> - <int key="NSfFlags">16</int> - </object> - <reference key="NSControlView" ref="799580933"/> - <int key="NSButtonFlags">-1232846593</int> - <int key="NSButtonFlags2">173</int> - <string key="NSAlternateContents"/> - <string key="NSKeyEquivalent"/> - <int key="NSPeriodicDelay">400</int> - <int key="NSPeriodicInterval">75</int> - </object> - </object> - <object class="NSButton" id="126436931"> - <reference key="NSNextResponder" ref="346382683"/> - <int key="NSvFlags">293</int> - <string key="NSFrame">{{158, 11}, {134, 17}}</string> - <reference key="NSSuperview" ref="346382683"/> - <int key="NSTag">2</int> - <bool key="NSEnabled">YES</bool> - <object class="NSButtonCell" key="NSCell" id="32494124"> - <int key="NSCellFlags">67239424</int> - <int key="NSCellFlags2">134348800</int> - <string key="NSContents">Input Field</string> - <reference key="NSSupport" ref="29"/> - <reference key="NSControlView" ref="126436931"/> - <int key="NSButtonFlags">-1232846593</int> - <int key="NSButtonFlags2">173</int> - <string key="NSAlternateContents"/> - <string key="NSKeyEquivalent"/> - <int key="NSPeriodicDelay">400</int> - <int key="NSPeriodicInterval">75</int> - </object> - </object> - <object class="NSButton" id="594438970"> - <reference key="NSNextResponder" ref="346382683"/> - <int key="NSvFlags">293</int> - <string key="NSFrame">{{300, 11}, {134, 17}}</string> - <reference key="NSSuperview" ref="346382683"/> - <int key="NSTag">4</int> - <bool key="NSEnabled">YES</bool> - <object class="NSButtonCell" key="NSCell" id="670066090"> - <int key="NSCellFlags">67239424</int> - <int key="NSCellFlags2">134348800</int> - <string key="NSContents">Data Table</string> - <reference key="NSSupport" ref="29"/> - <reference key="NSControlView" ref="594438970"/> - <int key="NSButtonFlags">-1232846593</int> - <int key="NSButtonFlags2">173</int> - <string key="NSAlternateContents"/> - <string key="NSKeyEquivalent"/> - <int key="NSPeriodicDelay">400</int> - <int key="NSPeriodicInterval">75</int> - </object> - </object> - </object> - <string key="NSFrame">{{1, 1}, {474, 34}}</string> - <reference key="NSSuperview" ref="477430580"/> - </object> - </object> - <string key="NSFrame">{{17, 288}, {476, 50}}</string> - <reference key="NSSuperview" ref="338542681"/> - <string key="NSOffsets">{0, 0}</string> - <object class="NSTextFieldCell" key="NSTitleCell"> - <int key="NSCellFlags">67239424</int> - <int key="NSCellFlags2">0</int> - <string key="NSContents">Command:</string> - <reference key="NSSupport" ref="26"/> - <reference key="NSBackgroundColor" ref="957408670"/> - <object class="NSColor" key="NSTextColor"> - <int key="NSColorSpace">3</int> - <bytes key="NSWhite">MCAwLjgwMDAwMDAxMTkAA</bytes> - </object> - </object> - <reference key="NSContentView" ref="346382683"/> - <int key="NSBorderType">1</int> - <int key="NSBoxType">0</int> - <int key="NSTitlePosition">2</int> - <bool key="NSTransparent">NO</bool> - </object> </object> <string key="NSFrame">{{143, 0}, {512, 444}}</string> <reference key="NSSuperview" ref="358491109"/> @@ -1294,14 +1230,6 @@ </object> <object class="IBConnectionRecord"> <object class="IBOutletConnection" key="connection"> - <string key="label">disableCheckBox</string> - <reference key="source" ref="1001"/> - <reference key="destination" ref="892755176"/> - </object> - <int key="connectionID">835</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBOutletConnection" key="connection"> <string key="label">inputPopupButton</string> <reference key="source" ref="1001"/> <reference key="destination" ref="117047836"/> @@ -1326,30 +1254,6 @@ </object> <object class="IBConnectionRecord"> <object class="IBOutletConnection" key="connection"> - <string key="label">editorScopeButton</string> - <reference key="source" ref="1001"/> - <reference key="destination" ref="799580933"/> - </object> - <int key="connectionID">839</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBOutletConnection" key="connection"> - <string key="label">inputFieldScopeButton</string> - <reference key="source" ref="1001"/> - <reference key="destination" ref="126436931"/> - </object> - <int key="connectionID">840</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBOutletConnection" key="connection"> - <string key="label">dataTableScopeButton</string> - <reference key="source" ref="1001"/> - <reference key="destination" ref="594438970"/> - </object> - <int key="connectionID">841</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBOutletConnection" key="connection"> <string key="label">outputPopupButton</string> <reference key="source" ref="1001"/> <reference key="destination" ref="570587248"/> @@ -1446,39 +1350,6 @@ </object> <object class="IBConnectionRecord"> <object class="IBBindingConnection" key="connection"> - <string key="label">value: selection.disabled</string> - <reference key="source" ref="892755176"/> - <reference key="destination" ref="707140570"/> - <object class="NSNibBindingConnector" key="connector"> - <reference key="NSSource" ref="892755176"/> - <reference key="NSDestination" ref="707140570"/> - <string key="NSLabel">value: selection.disabled</string> - <string key="NSBinding">value</string> - <string key="NSKeyPath">selection.disabled</string> - <object class="NSDictionary" key="NSOptions"> - <bool key="EncodedWithXMLCoder">YES</bool> - <object class="NSArray" key="dict.sortedKeys"> - <bool key="EncodedWithXMLCoder">YES</bool> - <string>NSMultipleValuesPlaceholder</string> - <string>NSNoSelectionPlaceholder</string> - <string>NSNotApplicablePlaceholder</string> - <string>NSNullPlaceholder</string> - </object> - <object class="NSMutableArray" key="dict.values"> - <bool key="EncodedWithXMLCoder">YES</bool> - <integer value="0"/> - <integer value="0"/> - <integer value="0"/> - <integer value="0"/> - </object> - </object> - <int key="NSNibBindingConnectorVersion">2</int> - </object> - </object> - <int key="connectionID">872</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBBindingConnection" key="connection"> <string key="label">value: arrangedObjects.bundleName</string> <reference key="source" ref="256079468"/> <reference key="destination" ref="707140570"/> @@ -1534,105 +1405,6 @@ <int key="connectionID">880</int> </object> <object class="IBConnectionRecord"> - <object class="IBBindingConnection" key="connection"> - <string key="label">value: selection.editor</string> - <reference key="source" ref="799580933"/> - <reference key="destination" ref="707140570"/> - <object class="NSNibBindingConnector" key="connector"> - <reference key="NSSource" ref="799580933"/> - <reference key="NSDestination" ref="707140570"/> - <string key="NSLabel">value: selection.editor</string> - <string key="NSBinding">value</string> - <string key="NSKeyPath">selection.editor</string> - <object class="NSDictionary" key="NSOptions"> - <bool key="EncodedWithXMLCoder">YES</bool> - <object class="NSArray" key="dict.sortedKeys"> - <bool key="EncodedWithXMLCoder">YES</bool> - <string>NSMultipleValuesPlaceholder</string> - <string>NSNoSelectionPlaceholder</string> - <string>NSNotApplicablePlaceholder</string> - <string>NSNullPlaceholder</string> - </object> - <object class="NSMutableArray" key="dict.values"> - <bool key="EncodedWithXMLCoder">YES</bool> - <integer value="0"/> - <integer value="0"/> - <integer value="0"/> - <integer value="0"/> - </object> - </object> - <int key="NSNibBindingConnectorVersion">2</int> - </object> - </object> - <int key="connectionID">886</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBBindingConnection" key="connection"> - <string key="label">value: selection.inputfield</string> - <reference key="source" ref="126436931"/> - <reference key="destination" ref="707140570"/> - <object class="NSNibBindingConnector" key="connector"> - <reference key="NSSource" ref="126436931"/> - <reference key="NSDestination" ref="707140570"/> - <string key="NSLabel">value: selection.inputfield</string> - <string key="NSBinding">value</string> - <string key="NSKeyPath">selection.inputfield</string> - <object class="NSDictionary" key="NSOptions"> - <bool key="EncodedWithXMLCoder">YES</bool> - <object class="NSArray" key="dict.sortedKeys"> - <bool key="EncodedWithXMLCoder">YES</bool> - <string>NSMultipleValuesPlaceholder</string> - <string>NSNoSelectionPlaceholder</string> - <string>NSNotApplicablePlaceholder</string> - <string>NSNullPlaceholder</string> - </object> - <object class="NSMutableArray" key="dict.values"> - <bool key="EncodedWithXMLCoder">YES</bool> - <integer value="0"/> - <integer value="0"/> - <integer value="0"/> - <integer value="0"/> - </object> - </object> - <int key="NSNibBindingConnectorVersion">2</int> - </object> - </object> - <int key="connectionID">892</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBBindingConnection" key="connection"> - <string key="label">value: selection.datatable</string> - <reference key="source" ref="594438970"/> - <reference key="destination" ref="707140570"/> - <object class="NSNibBindingConnector" key="connector"> - <reference key="NSSource" ref="594438970"/> - <reference key="NSDestination" ref="707140570"/> - <string key="NSLabel">value: selection.datatable</string> - <string key="NSBinding">value</string> - <string key="NSKeyPath">selection.datatable</string> - <object class="NSDictionary" key="NSOptions"> - <bool key="EncodedWithXMLCoder">YES</bool> - <object class="NSArray" key="dict.sortedKeys"> - <bool key="EncodedWithXMLCoder">YES</bool> - <string>NSMultipleValuesPlaceholder</string> - <string>NSNoSelectionPlaceholder</string> - <string>NSNotApplicablePlaceholder</string> - <string>NSNullPlaceholder</string> - </object> - <object class="NSMutableArray" key="dict.values"> - <bool key="EncodedWithXMLCoder">YES</bool> - <integer value="0"/> - <integer value="0"/> - <integer value="0"/> - <integer value="0"/> - </object> - </object> - <int key="NSNibBindingConnectorVersion">2</int> - </object> - </object> - <int key="connectionID">898</int> - </object> - <object class="IBConnectionRecord"> <object class="IBActionConnection" key="connection"> <string key="label">revealCommandBundleInFinder:</string> <reference key="source" ref="1001"/> @@ -1674,30 +1446,6 @@ </object> <object class="IBConnectionRecord"> <object class="IBActionConnection" key="connection"> - <string key="label">scopeButtonChanged:</string> - <reference key="source" ref="1001"/> - <reference key="destination" ref="799580933"/> - </object> - <int key="connectionID">912</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBActionConnection" key="connection"> - <string key="label">scopeButtonChanged:</string> - <reference key="source" ref="1001"/> - <reference key="destination" ref="126436931"/> - </object> - <int key="connectionID">913</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBActionConnection" key="connection"> - <string key="label">scopeButtonChanged:</string> - <reference key="source" ref="1001"/> - <reference key="destination" ref="594438970"/> - </object> - <int key="connectionID">914</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBActionConnection" key="connection"> <string key="label">inputFallbackPopupButtonChanged:</string> <reference key="source" ref="1001"/> <reference key="destination" ref="1013555552"/> @@ -1768,6 +1516,134 @@ </object> <int key="connectionID">931</int> </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">nextKeyView</string> + <reference key="source" ref="586526060"/> + <reference key="destination" ref="209604501"/> + </object> + <int key="connectionID">940</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">nextKeyView</string> + <reference key="source" ref="209604501"/> + <reference key="destination" ref="904079305"/> + </object> + <int key="connectionID">941</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">nextKeyView</string> + <reference key="source" ref="904079305"/> + <reference key="destination" ref="117047836"/> + </object> + <int key="connectionID">942</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">nextKeyView</string> + <reference key="source" ref="117047836"/> + <reference key="destination" ref="1013555552"/> + </object> + <int key="connectionID">943</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">nextKeyView</string> + <reference key="source" ref="1013555552"/> + <reference key="destination" ref="965862131"/> + </object> + <int key="connectionID">944</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">nextKeyView</string> + <reference key="source" ref="965862131"/> + <reference key="destination" ref="570587248"/> + </object> + <int key="connectionID">945</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">nextKeyView</string> + <reference key="source" ref="570587248"/> + <reference key="destination" ref="233794614"/> + </object> + <int key="connectionID">946</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">nextKeyView</string> + <reference key="source" ref="233794614"/> + <reference key="destination" ref="70452502"/> + </object> + <int key="connectionID">948</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">nextKeyView</string> + <reference key="source" ref="70452502"/> + <reference key="destination" ref="552615839"/> + </object> + <int key="connectionID">949</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">nextKeyView</string> + <reference key="source" ref="552615839"/> + <reference key="destination" ref="679408795"/> + </object> + <int key="connectionID">950</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">nextKeyView</string> + <reference key="source" ref="679408795"/> + <reference key="destination" ref="275669410"/> + </object> + <int key="connectionID">951</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">nextKeyView</string> + <reference key="source" ref="275669410"/> + <reference key="destination" ref="369890801"/> + </object> + <int key="connectionID">952</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">nextKeyView</string> + <reference key="source" ref="369890801"/> + <reference key="destination" ref="972789208"/> + </object> + <int key="connectionID">953</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">nextKeyView</string> + <reference key="source" ref="972789208"/> + <reference key="destination" ref="586526060"/> + </object> + <int key="connectionID">954</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBActionConnection" key="connection"> + <string key="label">scopeButtonChanged:</string> + <reference key="source" ref="1001"/> + <reference key="destination" ref="904079305"/> + </object> + <int key="connectionID">955</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">scopePopupButton</string> + <reference key="source" ref="1001"/> + <reference key="destination" ref="904079305"/> + </object> + <int key="connectionID">956</int> + </object> </object> <object class="IBMutableOrderedSet" key="objectRecords"> <object class="NSArray" key="orderedObjects"> @@ -1982,13 +1858,14 @@ <reference ref="70452502"/> <reference ref="334638351"/> <reference ref="117047836"/> - <reference ref="477430580"/> <reference ref="62695080"/> - <reference ref="892755176"/> <reference ref="679408795"/> <reference ref="179792134"/> <reference ref="277233496"/> <reference ref="552615839"/> + <reference ref="669651343"/> + <reference ref="904079305"/> + <reference ref="864339274"/> </object> <reference key="parent" ref="358491109"/> <string key="objectName">Bundle Content View</string> @@ -2200,20 +2077,6 @@ <reference key="parent" ref="334638351"/> </object> <object class="IBObjectRecord"> - <int key="objectID">786</int> - <reference key="object" ref="892755176"/> - <object class="NSMutableArray" key="children"> - <bool key="EncodedWithXMLCoder">YES</bool> - <reference ref="1063662617"/> - </object> - <reference key="parent" ref="338542681"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">787</int> - <reference key="object" ref="1063662617"/> - <reference key="parent" ref="892755176"/> - </object> - <object class="IBObjectRecord"> <int key="objectID">768</int> <reference key="object" ref="117047836"/> <object class="NSMutableArray" key="children"> @@ -2241,59 +2104,6 @@ <reference key="parent" ref="131002945"/> </object> <object class="IBObjectRecord"> - <int key="objectID">816</int> - <reference key="object" ref="477430580"/> - <object class="NSMutableArray" key="children"> - <bool key="EncodedWithXMLCoder">YES</bool> - <reference ref="799580933"/> - <reference ref="126436931"/> - <reference ref="594438970"/> - </object> - <reference key="parent" ref="338542681"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">805</int> - <reference key="object" ref="799580933"/> - <object class="NSMutableArray" key="children"> - <bool key="EncodedWithXMLCoder">YES</bool> - <reference ref="176613618"/> - </object> - <reference key="parent" ref="477430580"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">806</int> - <reference key="object" ref="176613618"/> - <reference key="parent" ref="799580933"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">809</int> - <reference key="object" ref="126436931"/> - <object class="NSMutableArray" key="children"> - <bool key="EncodedWithXMLCoder">YES</bool> - <reference ref="32494124"/> - </object> - <reference key="parent" ref="477430580"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">810</int> - <reference key="object" ref="32494124"/> - <reference key="parent" ref="126436931"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">807</int> - <reference key="object" ref="594438970"/> - <object class="NSMutableArray" key="children"> - <bool key="EncodedWithXMLCoder">YES</bool> - <reference ref="670066090"/> - </object> - <reference key="parent" ref="477430580"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">808</int> - <reference key="object" ref="670066090"/> - <reference key="parent" ref="594438970"/> - </object> - <object class="IBObjectRecord"> <int key="objectID">817</int> <reference key="object" ref="679408795"/> <object class="NSMutableArray" key="children"> @@ -2402,6 +2212,58 @@ <reference key="object" ref="18029675"/> <reference key="parent" ref="973574710"/> </object> + <object class="IBObjectRecord"> + <int key="objectID">932</int> + <reference key="object" ref="904079305"/> + <object class="NSMutableArray" key="children"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="886363818"/> + </object> + <reference key="parent" ref="338542681"/> + <string key="objectName">Pop Up Button (Input)</string> + </object> + <object class="IBObjectRecord"> + <int key="objectID">933</int> + <reference key="object" ref="886363818"/> + <object class="NSMutableArray" key="children"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="416241867"/> + </object> + <reference key="parent" ref="904079305"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">934</int> + <reference key="object" ref="416241867"/> + <reference key="parent" ref="886363818"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">936</int> + <reference key="object" ref="669651343"/> + <object class="NSMutableArray" key="children"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="44795332"/> + </object> + <reference key="parent" ref="338542681"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">937</int> + <reference key="object" ref="44795332"/> + <reference key="parent" ref="669651343"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">938</int> + <reference key="object" ref="864339274"/> + <object class="NSMutableArray" key="children"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="553916693"/> + </object> + <reference key="parent" ref="338542681"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">939</int> + <reference key="object" ref="553916693"/> + <reference key="parent" ref="864339274"/> + </object> </object> </object> <object class="NSMutableDictionary" key="flattenedProperties"> @@ -2476,8 +2338,6 @@ <string>781.IBPluginDependency</string> <string>782.IBEditorWindowLastContentRect</string> <string>782.IBPluginDependency</string> - <string>786.IBPluginDependency</string> - <string>787.IBPluginDependency</string> <string>788.IBAttributePlaceholdersKey</string> <string>788.IBPluginDependency</string> <string>789.IBPluginDependency</string> @@ -2493,16 +2353,6 @@ <string>802.IBPluginDependency</string> <string>804.IBAttributePlaceholdersKey</string> <string>804.IBPluginDependency</string> - <string>805.IBAttributePlaceholdersKey</string> - <string>805.IBPluginDependency</string> - <string>806.IBPluginDependency</string> - <string>807.IBAttributePlaceholdersKey</string> - <string>807.IBPluginDependency</string> - <string>808.IBPluginDependency</string> - <string>809.IBAttributePlaceholdersKey</string> - <string>809.IBPluginDependency</string> - <string>810.IBPluginDependency</string> - <string>816.IBPluginDependency</string> <string>817.IBAttributePlaceholdersKey</string> <string>817.IBPluginDependency</string> <string>818.IBPluginDependency</string> @@ -2523,13 +2373,22 @@ <string>908.IBPluginDependency</string> <string>909.IBPluginDependency</string> <string>920.IBPluginDependency</string> + <string>932.IBAttributePlaceholdersKey</string> + <string>932.IBPluginDependency</string> + <string>933.IBPluginDependency</string> + <string>934.IBEditorWindowLastContentRect</string> + <string>934.IBPluginDependency</string> + <string>936.IBPluginDependency</string> + <string>937.IBPluginDependency</string> + <string>938.IBPluginDependency</string> + <string>939.IBPluginDependency</string> </object> <object class="NSMutableArray" key="dict.values"> <bool key="EncodedWithXMLCoder">YES</bool> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>{{515, 73}, {655, 444}}</string> + <string>{{91, 257}, {655, 444}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>{{515, 73}, {655, 444}}</string> + <string>{{91, 257}, {655, 444}}</string> <boolean value="NO"/> <boolean value="YES"/> <string>{726, 444}</string> @@ -2657,8 +2516,6 @@ <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>{{430, 598}, {167, 4}}</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"> @@ -2705,62 +2562,47 @@ <string key="NS.key.0">ToolTip</string> <object class="IBToolTipAttribute" key="NS.object.0"> <string key="name">ToolTip</string> - <reference key="object" ref="799580933"/> - <string key="toolTip">Bundle Command will be executable in the Query Editor</string> + <reference key="object" ref="679408795"/> + <string type="base64-UTF8" key="toolTip">Q2xvc2UgdGhlIEJ1bmRsZSBFZGl0b3Igd2l0aG91dCBzYXZpbmcgKA/ijospA</string> </object> </object> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <object class="NSMutableDictionary"> - <string key="NS.key.0">ToolTip</string> - <object class="IBToolTipAttribute" key="NS.object.0"> - <string key="name">ToolTip</string> - <reference key="object" ref="594438970"/> - <string key="toolTip">Bundle Command will be executable in the data tables of the Content View and Custom Query View</string> - </object> - </object> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <object class="NSMutableDictionary"> - <string key="NS.key.0">ToolTip</string> - <object class="IBToolTipAttribute" key="NS.object.0"> - <string key="name">ToolTip</string> - <reference key="object" ref="126436931"/> - <string key="toolTip">Bundle Command will be executable in any text input field but not in the Query Editor</string> - </object> - </object> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>SPBundleCommandTextView</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <object class="NSMutableDictionary"> <string key="NS.key.0">ToolTip</string> <object class="IBToolTipAttribute" key="NS.object.0"> <string key="name">ToolTip</string> - <reference key="object" ref="679408795"/> - <string type="base64-UTF8" key="toolTip">Q2xvc2UgdGhlIEJ1bmRsZSBFZGl0b3Igd2l0aG91dCBzYXZpbmcgKA/ijospA</string> + <reference key="object" ref="552615839"/> + <string key="toolTip">Save any changes and close the Bundle Editor (⌘S)</string> </object> </object> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>{{151, 519}, {268, 73}}</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>SPBundleCommandTextView</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <object class="NSMutableDictionary"> <string key="NS.key.0">ToolTip</string> <object class="IBToolTipAttribute" key="NS.object.0"> <string key="name">ToolTip</string> - <reference key="object" ref="552615839"/> - <string key="toolTip">Save any changes and close the Bundle Editor (⌘S)</string> + <reference key="object" ref="904079305"/> + <string key="toolTip">Choose the scope on which the Bundle command will run</string> </object> </object> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>{{151, 519}, {268, 73}}</string> - <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>{{211, 598}, {167, 4}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> @@ -2784,7 +2626,7 @@ </object> </object> <nil key="sourceID"/> - <int key="maxID">931</int> + <int key="maxID">956</int> </object> <object class="IBClassDescriber" key="IBDocument.Classes"> <object class="NSMutableArray" key="referencedPartialClassDescriptions"> @@ -3043,19 +2885,16 @@ <string>commandBundleArrayController</string> <string>commandTextView</string> <string>commandsTableView</string> - <string>dataTableScopeButton</string> - <string>disableCheckBox</string> <string>duplicateMenuItem</string> - <string>editorScopeButton</string> <string>fallbackLabelField</string> <string>inputFallbackPopupButton</string> - <string>inputFieldScopeButton</string> <string>inputPopupButton</string> <string>keyEquivalentField</string> <string>nameTextField</string> <string>outputPopupButton</string> <string>removeButton</string> <string>revealInFinderMenuItem</string> + <string>scopePopupButton</string> <string>tootlipTextField</string> </object> <object class="NSMutableArray" key="dict.values"> @@ -3064,19 +2903,16 @@ <string>NSArrayController</string> <string>id</string> <string>NSTableView</string> - <string>NSButton</string> - <string>NSButton</string> <string>NSMenuItem</string> - <string>NSButton</string> <string>NSTextField</string> <string>NSPopUpButton</string> - <string>NSButton</string> <string>NSPopUpButton</string> <string>SRRecorderControl</string> <string>NSTextField</string> <string>NSPopUpButton</string> <string>NSButton</string> <string>NSMenuItem</string> + <string>NSPopUpButton</string> <string>NSTextField</string> </object> </object> @@ -3088,19 +2924,16 @@ <string>commandBundleArrayController</string> <string>commandTextView</string> <string>commandsTableView</string> - <string>dataTableScopeButton</string> - <string>disableCheckBox</string> <string>duplicateMenuItem</string> - <string>editorScopeButton</string> <string>fallbackLabelField</string> <string>inputFallbackPopupButton</string> - <string>inputFieldScopeButton</string> <string>inputPopupButton</string> <string>keyEquivalentField</string> <string>nameTextField</string> <string>outputPopupButton</string> <string>removeButton</string> <string>revealInFinderMenuItem</string> + <string>scopePopupButton</string> <string>tootlipTextField</string> </object> <object class="NSMutableArray" key="dict.values"> @@ -3122,22 +2955,10 @@ <string key="candidateClassName">NSTableView</string> </object> <object class="IBToOneOutletInfo"> - <string key="name">dataTableScopeButton</string> - <string key="candidateClassName">NSButton</string> - </object> - <object class="IBToOneOutletInfo"> - <string key="name">disableCheckBox</string> - <string key="candidateClassName">NSButton</string> - </object> - <object class="IBToOneOutletInfo"> <string key="name">duplicateMenuItem</string> <string key="candidateClassName">NSMenuItem</string> </object> <object class="IBToOneOutletInfo"> - <string key="name">editorScopeButton</string> - <string key="candidateClassName">NSButton</string> - </object> - <object class="IBToOneOutletInfo"> <string key="name">fallbackLabelField</string> <string key="candidateClassName">NSTextField</string> </object> @@ -3146,10 +2967,6 @@ <string key="candidateClassName">NSPopUpButton</string> </object> <object class="IBToOneOutletInfo"> - <string key="name">inputFieldScopeButton</string> - <string key="candidateClassName">NSButton</string> - </object> - <object class="IBToOneOutletInfo"> <string key="name">inputPopupButton</string> <string key="candidateClassName">NSPopUpButton</string> </object> @@ -3174,6 +2991,10 @@ <string key="candidateClassName">NSMenuItem</string> </object> <object class="IBToOneOutletInfo"> + <string key="name">scopePopupButton</string> + <string key="candidateClassName">NSPopUpButton</string> + </object> + <object class="IBToOneOutletInfo"> <string key="name">tootlipTextField</string> <string key="candidateClassName">NSTextField</string> </object> @@ -3719,7 +3540,6 @@ <string>NSActionTemplate</string> <string>NSMenuCheckmark</string> <string>NSMenuMixedState</string> - <string>NSSwitch</string> <string>button_add</string> <string>button_remove</string> </object> @@ -3728,7 +3548,6 @@ <string>{10, 10}</string> <string>{9, 8}</string> <string>{7, 2}</string> - <string>{15, 15}</string> <string>{128, 128}</string> <string>{128, 128}</string> </object> diff --git a/Source/SPAppController.h b/Source/SPAppController.h index 35c9ee63..9a17dcb6 100644 --- a/Source/SPAppController.h +++ b/Source/SPAppController.h @@ -97,4 +97,6 @@ - (void)handleEventWithURL:(NSURL*)url; +- (IBAction)executeBundleItemForApp:(id)sender; + @end diff --git a/Source/SPAppController.m b/Source/SPAppController.m index c5704f80..9a4e23e6 100644 --- a/Source/SPAppController.m +++ b/Source/SPAppController.m @@ -33,6 +33,9 @@ #import "SPWindowController.h" #import "SPPreferencesUpgrade.h" #import "SPBundleEditorController.h" +#import "SPTooltip.h" +#import "SPBundleHTMLOutputController.h" +#import "SPAlertSheets.h" #import <PSMTabBar/PSMTabBarControl.h> #import <Sparkle/Sparkle.h> @@ -598,6 +601,132 @@ NSLog(@"command id: %@", passedProcessID); } +- (IBAction)executeBundleItemForApp:(id)sender +{ + + NSInteger idx = [sender tag] - 1000000; + NSString *infoPath = nil; + NSArray *bundleItems = [[NSApp delegate] bundleItemsForScope:SPBundleScopeGeneral]; + if(idx >=0 && idx < [bundleItems count]) { + infoPath = [[bundleItems objectAtIndex:idx] objectForKey:SPBundleInternPathToFileKey]; + } else { + if([sender tag] == 0 && [[sender toolTip] length]) { + infoPath = [sender toolTip]; + } + } + + if(!infoPath) { + NSBeep(); + return; + } + + NSError *readError = nil; + NSString *convError = nil; + NSPropertyListFormat format; + NSDictionary *cmdData = nil; + NSData *pData = [NSData dataWithContentsOfFile:infoPath options:NSUncachedRead error:&readError]; + + cmdData = [[NSPropertyListSerialization propertyListFromData:pData + mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError] retain]; + + if(!cmdData || readError != nil || [convError length] || !(format == NSPropertyListXMLFormat_v1_0 || format == NSPropertyListBinaryFormat_v1_0)) { + NSLog(@"“%@” file couldn't be read.", infoPath); + NSBeep(); + if (cmdData) [cmdData release]; + return; + } else { + if([cmdData objectForKey:SPBundleFileCommandKey] && [[cmdData objectForKey:SPBundleFileCommandKey] length]) { + + NSString *cmd = [cmdData objectForKey:SPBundleFileCommandKey]; + NSString *inputAction = @""; + NSString *inputFallBackAction = @""; + NSError *err = nil; + NSString *bundleInputFilePath = [NSString stringWithFormat:@"%@_%@", SPBundleTaskInputFilePath, [NSString stringWithNewUUID]]; + + [[NSFileManager defaultManager] removeItemAtPath:bundleInputFilePath error:nil]; + + if([cmdData objectForKey:SPBundleFileInputSourceKey]) + inputAction = [[cmdData objectForKey:SPBundleFileInputSourceKey] lowercaseString]; + if([cmdData objectForKey:SPBundleFileInputSourceFallBackKey]) + inputFallBackAction = [[cmdData objectForKey:SPBundleFileInputSourceFallBackKey] lowercaseString]; + + NSMutableDictionary *env = [NSMutableDictionary dictionary]; + [env setObject:[infoPath stringByDeletingLastPathComponent] forKey:@"SP_BUNDLE_PATH"]; + [env setObject:bundleInputFilePath forKey:@"SP_BUNDLE_INPUT_FILE"]; + + NSError *inputFileError = nil; + NSString *input = @""; + if([inputAction isEqualToString:SPBundleInputSourceSelectedTableRowsAsTab]) { + input = [self rowsAsTabStringWithHeaders:YES onlySelectedRows:YES]; + } + else if([inputAction isEqualToString:SPBundleInputSourceSelectedTableRowsAsCsv]) { + input = [self rowsAsCsvStringWithHeaders:YES onlySelectedRows:YES]; + } + else if([inputAction isEqualToString:SPBundleInputSourceSelectedTableRowsAsSqlInsert]) { + input = [self rowsAsSqlInsertsOnlySelectedRows:YES]; + } + else if([inputAction isEqualToString:SPBundleInputSourceTableRowsAsTab]) { + input = [self rowsAsTabStringWithHeaders:YES onlySelectedRows:NO]; + } + else if([inputAction isEqualToString:SPBundleInputSourceTableRowsAsCsv]) { + input = [self rowsAsCsvStringWithHeaders:YES onlySelectedRows:NO]; + } + else if([inputAction isEqualToString:SPBundleInputSourceTableRowsAsSqlInsert]) { + input = [self rowsAsSqlInsertsOnlySelectedRows:NO]; + } + + if(input == nil) input = @""; + [input writeToFile:bundleInputFilePath + atomically:YES + encoding:NSUTF8StringEncoding + error:&inputFileError]; + + if(inputFileError != nil) { + NSString *errorMessage = [inputFileError localizedDescription]; + SPBeginAlertSheet(NSLocalizedString(@"Bundle Error", @"bundle error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [NSApp mainWindow], self, nil, nil, + [NSString stringWithFormat:@"%@ “%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [cmdData objectForKey:@"name"], errorMessage]); + if (cmdData) [cmdData release]; + return; + } + + NSString *output = [cmd runBashCommandWithEnvironment:env atCurrentDirectoryPath:nil error:&err]; + + [[NSFileManager defaultManager] removeItemAtPath:bundleInputFilePath error:nil]; + + if(err == nil && output && [cmdData objectForKey:SPBundleFileOutputActionKey]) { + if([[cmdData objectForKey:SPBundleFileOutputActionKey] length] + && ![[cmdData objectForKey:SPBundleFileOutputActionKey] isEqualToString:SPBundleOutputActionNone]) { + NSString *action = [[cmdData objectForKey:SPBundleFileOutputActionKey] lowercaseString]; + NSPoint pos = [NSEvent mouseLocation]; + pos.y -= 16; + + if([action isEqualToString:SPBundleOutputActionShowAsTextTooltip]) { + [SPTooltip showWithObject:output atLocation:pos]; + } + + else if([action isEqualToString:SPBundleOutputActionShowAsHTMLTooltip]) { + [SPTooltip showWithObject:output atLocation:pos ofType:@"html"]; + } + + else if([action isEqualToString:SPBundleOutputActionShowAsHTML]) { + SPBundleHTMLOutputController *c = [[SPBundleHTMLOutputController alloc] init]; + [c displayHTMLContent:output withOptions:nil]; + } + } + } else { + NSString *errorMessage = [err localizedDescription]; + SPBeginAlertSheet(NSLocalizedString(@"BASH Error", @"bash error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [NSApp mainWindow], self, nil, nil, + [NSString stringWithFormat:@"%@ “%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [cmdData objectForKey:@"name"], errorMessage]); + } + + } + + if (cmdData) [cmdData release]; + + } + +} + #pragma mark - #pragma mark Window management @@ -1001,6 +1130,7 @@ // Rebuild Bundles main menu item + // Add default menu items NSMenuItem *anItem; anItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Bundle Editor", @"bundle editor menu item label") action:@selector(openBundleEditor:) keyEquivalent:@"b"]; [anItem setKeyEquivalentModifierMask:(NSCommandKeyMask|NSAlternateKeyMask|NSControlKeyMask)]; @@ -1010,18 +1140,20 @@ [menu addItem:anItem]; [anItem release]; + // Bail out if no Bundle was installed if(!foundInstalledBundles) return; // Add installed Bundles + // For each scope add a submenu but not for the last one (should be General always) [menu addItem:[NSMenuItem separatorItem]]; - NSArray *scopes = [NSArray arrayWithObjects:SPBundleScopeInputField, SPBundleScopeQueryEditor, SPBundleScopeDataTable, nil]; + NSArray *scopes = [NSArray arrayWithObjects:SPBundleScopeInputField, SPBundleScopeDataTable, SPBundleScopeGeneral, nil]; NSArray *scopeTitles = [NSArray arrayWithObjects:NSLocalizedString(@"Input Fields", @"input fields menu item label"), - NSLocalizedString(@"Query Editor", @"query editor menu item label"), - NSLocalizedString(@"Data Table", @"data table menu item label"),nil]; + NSLocalizedString(@"Data Table", @"data table menu item label"), + NSLocalizedString(@"General", @"general menu item label"),nil]; NSArray *scopeSelector = [NSArray arrayWithObjects:@"executeBundleItemForInputField:", - @"executeBundleItemForEditor:", - @"executeBundleItemForDataTable:", nil]; + @"executeBundleItemForDataTable:", + @"executeBundleItemForApp:", nil]; NSInteger k = 0; for(NSString* scope in scopes) { @@ -1034,13 +1166,25 @@ continue; } - NSMenu *bundleMenu = [[[NSMenu alloc] init] autorelease]; - NSMenuItem *bundleSubMenuItem = [[NSMenuItem alloc] initWithTitle:[scopeTitles objectAtIndex:k] action:nil keyEquivalent:@""]; - [bundleSubMenuItem setTag:10000000]; + NSMenu *bundleMenu = nil; + NSMenuItem *bundleSubMenuItem = nil; + + // Add last scope (General) not as submenu + if(k < [scopes count]-1) { + bundleMenu = [[[NSMenu alloc] init] autorelease]; + + bundleSubMenuItem = [[NSMenuItem alloc] initWithTitle:[scopeTitles objectAtIndex:k] action:nil keyEquivalent:@""]; + [bundleSubMenuItem setTag:10000000]; - [menu addItem:bundleSubMenuItem]; - [menu setSubmenu:bundleMenu forItem:bundleSubMenuItem]; + [menu addItem:bundleSubMenuItem]; + [menu setSubmenu:bundleMenu forItem:bundleSubMenuItem]; + + } else { + bundleMenu = menu; + [menu addItem:[NSMenuItem separatorItem]]; + } + // Add found Category submenus NSMutableArray *categorySubMenus = [NSMutableArray array]; NSMutableArray *categoryMenus = [NSMutableArray array]; if([bundleCategories count]) { @@ -1078,7 +1222,7 @@ } } - [bundleSubMenuItem release]; + if(bundleSubMenuItem)[bundleSubMenuItem release]; k++; } diff --git a/Source/SPBundleCommandTextView.m b/Source/SPBundleCommandTextView.m index 3213eda7..b90cea43 100644 --- a/Source/SPBundleCommandTextView.m +++ b/Source/SPBundleCommandTextView.m @@ -443,27 +443,6 @@ [[self delegate] setDoGroupDueToChars]; } - - if([[[[self delegate] class] description] isEqualToString:@"SPBundleEditorController"]) { - [super keyDown: theEvent]; - return; - } - - // Check for assign key equivalents inside user-defined bundle commands - NSDictionary *keyEquivalents = [[NSApp delegate] bundleKeyEquivalentsForScope:SPBundleScopeInputField]; - if([keyEquivalents count]) { - for(NSString* key in [keyEquivalents allKeys]) { - NSArray *keyData = [keyEquivalents objectForKey:key]; - if([[keyData objectAtIndex:0] isEqualToString:charactersIgnMod] && [[[keyEquivalents objectForKey:key] objectAtIndex:1] intValue] == curFlags) { - NSMenuItem *item = [[[NSMenuItem alloc] init] autorelease]; - [item setToolTip:[[keyEquivalents objectForKey:key] objectAtIndex:2]]; - [item setTag:0]; - [self executeBundleItemForInputField:item]; - return; - } - } - } - [super keyDown: theEvent]; } diff --git a/Source/SPBundleEditorController.h b/Source/SPBundleEditorController.h index eca5659f..e07589e1 100644 --- a/Source/SPBundleEditorController.h +++ b/Source/SPBundleEditorController.h @@ -39,10 +39,7 @@ IBOutlet NSPopUpButton* inputPopupButton; IBOutlet NSPopUpButton* inputFallbackPopupButton; IBOutlet NSPopUpButton* outputPopupButton; - IBOutlet NSButton *editorScopeButton; - IBOutlet NSButton *inputFieldScopeButton; - IBOutlet NSButton *dataTableScopeButton; - IBOutlet NSButton *disableCheckBox; + IBOutlet NSPopUpButton* scopePopupButton; IBOutlet NSButton *removeButton; IBOutlet NSMenuItem *duplicateMenuItem; IBOutlet NSMenuItem *revealInFinderMenuItem; @@ -56,23 +53,21 @@ NSString *oldBundleName; BOOL isTableCellEditing; - NSMenu *inputEditorScopePopUpMenu; + NSMenu *inputGeneralScopePopUpMenu; NSMenu *inputInputFieldScopePopUpMenu; NSMenu *inputDataTableScopePopUpMenu; NSMenu *inputNonePopUpMenu; - NSMenu *outputEditorScopePopUpMenu; + NSMenu *outputGeneralScopePopUpMenu; NSMenu *outputInputFieldScopePopUpMenu; NSMenu *outputDataTableScopePopUpMenu; - NSMenu *inputFallbackEditorScopePopUpMenu; NSMenu *inputFallbackInputFieldScopePopUpMenu; - NSArray *inputEditorScopeArray; + NSArray *inputGeneralScopeArray; NSArray *inputInputFieldScopeArray; NSArray *inputDataTableScopeArray; - NSArray *outputEditorScopeArray; + NSArray *outputGeneralScopeArray; NSArray *outputInputFieldScopeArray; NSArray *outputDataTableScopeArray; - NSArray *inputFallbackEditorScopeArray; NSArray *inputFallbackInputFieldScopeArray; BOOL doGroupDueToChars; diff --git a/Source/SPBundleEditorController.m b/Source/SPBundleEditorController.m index 1f9a9732..bb628c55 100644 --- a/Source/SPBundleEditorController.m +++ b/Source/SPBundleEditorController.m @@ -56,23 +56,21 @@ - (void)dealloc { - [inputEditorScopePopUpMenu release]; + [inputGeneralScopePopUpMenu release]; [inputInputFieldScopePopUpMenu release]; [inputDataTableScopePopUpMenu release]; - [outputEditorScopePopUpMenu release]; + [outputGeneralScopePopUpMenu release]; [outputInputFieldScopePopUpMenu release]; [outputDataTableScopePopUpMenu release]; - [inputFallbackEditorScopePopUpMenu release]; [inputFallbackInputFieldScopePopUpMenu release]; [inputNonePopUpMenu release]; - [inputEditorScopeArray release]; + [inputGeneralScopeArray release]; [inputInputFieldScopeArray release]; [inputDataTableScopeArray release]; - [outputEditorScopeArray release]; + [outputGeneralScopeArray release]; [outputInputFieldScopeArray release]; [outputDataTableScopeArray release]; - [inputFallbackEditorScopeArray release]; [inputFallbackInputFieldScopeArray release]; if(commandBundleArray) [commandBundleArray release], commandBundleArray = nil; @@ -86,43 +84,40 @@ { // Init all needed menus - inputEditorScopePopUpMenu = [[NSMenu alloc] initWithTitle:@""]; + inputGeneralScopePopUpMenu = [[NSMenu alloc] initWithTitle:@""]; inputInputFieldScopePopUpMenu = [[NSMenu alloc] initWithTitle:@""]; inputDataTableScopePopUpMenu = [[NSMenu alloc] initWithTitle:@""]; inputNonePopUpMenu = [[NSMenu alloc] initWithTitle:@""]; - outputEditorScopePopUpMenu = [[NSMenu alloc] initWithTitle:@""]; + outputGeneralScopePopUpMenu = [[NSMenu alloc] initWithTitle:@""]; outputInputFieldScopePopUpMenu = [[NSMenu alloc] initWithTitle:@""]; outputDataTableScopePopUpMenu = [[NSMenu alloc] initWithTitle:@""]; - inputFallbackEditorScopePopUpMenu = [[NSMenu alloc] initWithTitle:@""]; inputFallbackInputFieldScopePopUpMenu = [[NSMenu alloc] initWithTitle:@""]; - inputEditorScopeArray = [[NSArray arrayWithObjects:SPBundleInputSourceNone, SPBundleInputSourceSelectedText, SPBundleInputSourceEntireContent, nil] retain]; + inputGeneralScopeArray = [[NSArray arrayWithObjects:SPBundleInputSourceNone, nil] retain]; inputInputFieldScopeArray = [[NSArray arrayWithObjects:SPBundleInputSourceNone, SPBundleInputSourceSelectedText, SPBundleInputSourceEntireContent, nil] retain]; inputDataTableScopeArray = [[NSArray arrayWithObjects:SPBundleInputSourceNone, SPBundleInputSourceSelectedTableRowsAsTab, SPBundleInputSourceSelectedTableRowsAsCsv, SPBundleInputSourceSelectedTableRowsAsSqlInsert, SPBundleInputSourceTableRowsAsTab, SPBundleInputSourceTableRowsAsCsv, SPBundleInputSourceTableRowsAsSqlInsert, nil] retain]; - outputEditorScopeArray = [[NSArray arrayWithObjects:SPBundleOutputActionNone, SPBundleOutputActionInsertAsText, SPBundleOutputActionInsertAsSnippet, SPBundleOutputActionReplaceSelection, SPBundleOutputActionReplaceContent, SPBundleOutputActionShowAsTextTooltip, SPBundleOutputActionShowAsHTMLTooltip, SPBundleOutputActionShowAsHTML, nil] retain]; - outputInputFieldScopeArray = [[NSArray arrayWithObjects:SPBundleOutputActionNone, SPBundleOutputActionInsertAsText, SPBundleOutputActionReplaceSelection, SPBundleOutputActionReplaceContent, SPBundleOutputActionShowAsTextTooltip, SPBundleOutputActionShowAsHTMLTooltip, SPBundleOutputActionShowAsHTML, nil] retain]; + outputInputFieldScopeArray = [[NSArray arrayWithObjects:SPBundleOutputActionNone, SPBundleOutputActionInsertAsText, SPBundleOutputActionInsertAsSnippet, SPBundleOutputActionReplaceSelection, SPBundleOutputActionReplaceContent, SPBundleOutputActionShowAsTextTooltip, SPBundleOutputActionShowAsHTMLTooltip, SPBundleOutputActionShowAsHTML, nil] retain]; + outputGeneralScopeArray = [[NSArray arrayWithObjects:SPBundleOutputActionNone, SPBundleOutputActionShowAsTextTooltip, SPBundleOutputActionShowAsHTMLTooltip, SPBundleOutputActionShowAsHTML, nil] retain]; outputDataTableScopeArray = [[NSArray arrayWithObjects:SPBundleOutputActionNone, SPBundleOutputActionShowAsTextTooltip, SPBundleOutputActionShowAsHTMLTooltip, SPBundleOutputActionShowAsHTML, nil] retain]; - inputFallbackEditorScopeArray = [[NSArray arrayWithObjects:SPBundleInputSourceNone, SPBundleInputSourceCurrentWord, SPBundleInputSourceCurrentLine, SPBundleInputSourceCurrentQuery, SPBundleInputSourceEntireContent, nil] retain]; - inputFallbackInputFieldScopeArray = [[NSArray arrayWithObjects:SPBundleInputSourceNone, SPBundleInputSourceCurrentWord, SPBundleInputSourceCurrentLine, SPBundleInputSourceEntireContent, nil] retain]; + inputFallbackInputFieldScopeArray = [[NSArray arrayWithObjects:SPBundleInputSourceNone, SPBundleInputSourceCurrentWord, SPBundleInputSourceCurrentLine, SPBundleInputSourceCurrentQuery, SPBundleInputSourceEntireContent, nil] retain]; NSMutableArray *allPopupScopeItems = [NSMutableArray array]; - [allPopupScopeItems addObjectsFromArray:inputEditorScopeArray]; + [allPopupScopeItems addObjectsFromArray:inputGeneralScopeArray]; [allPopupScopeItems addObjectsFromArray:inputInputFieldScopeArray]; [allPopupScopeItems addObjectsFromArray:inputDataTableScopeArray]; - [allPopupScopeItems addObjectsFromArray:outputEditorScopeArray]; [allPopupScopeItems addObjectsFromArray:outputInputFieldScopeArray]; + [allPopupScopeItems addObjectsFromArray:outputGeneralScopeArray]; [allPopupScopeItems addObjectsFromArray:outputDataTableScopeArray]; - [allPopupScopeItems addObjectsFromArray:inputFallbackEditorScopeArray]; [allPopupScopeItems addObjectsFromArray:inputFallbackInputFieldScopeArray]; NSDictionary *menuItemTitles = [NSDictionary dictionaryWithObjects: [NSArray arrayWithObjects: NSLocalizedString(@"None", @"none menu item label"), - NSLocalizedString(@"Selected Text", @"selected text menu item label"), - NSLocalizedString(@"Entire Content", @"entire content menu item label"), + NSLocalizedString(@"None", @"none menu item label"), NSLocalizedString(@"Selected Text", @"selected text menu item label"), NSLocalizedString(@"Entire Content", @"entire content menu item label"), + NSLocalizedString(@"None", @"none menu item label"), NSLocalizedString(@"Selected Rows (TSV)", @"selected rows (TSV) menu item label"), NSLocalizedString(@"Selected Rows (CSV)", @"selected rows (CSV) menu item label"), @@ -130,6 +125,7 @@ NSLocalizedString(@"Table Content (TSV)", @"table content (TSV) menu item label"), NSLocalizedString(@"Table Content (CSV)", @"table content (CSV) menu item label"), NSLocalizedString(@"Table Content (SQL)", @"table content (SQL) menu item label"), + NSLocalizedString(@"None", @"none menu item label"), NSLocalizedString(@"Insert as Text", @"insert as text item label"), NSLocalizedString(@"Insert as Snippet", @"insert as snippet item label"), @@ -138,33 +134,29 @@ NSLocalizedString(@"Show as Text Tooltip", @"show as text tooltip item label"), NSLocalizedString(@"Show as HTML Tooltip", @"show as html tooltip item label"), NSLocalizedString(@"Show as HTML", @"show as html item label"), + NSLocalizedString(@"None", @"none menu item label"), - NSLocalizedString(@"Insert as Text", @"insert as text item label"), - NSLocalizedString(@"Replace Selection", @"replace selection item label"), - NSLocalizedString(@"Replace Entire Content", @"replace entire content item label"), NSLocalizedString(@"Show as Text Tooltip", @"show as text tooltip item label"), NSLocalizedString(@"Show as HTML Tooltip", @"show as html tooltip item label"), NSLocalizedString(@"Show as HTML", @"show as html item label"), + NSLocalizedString(@"None", @"none menu item label"), NSLocalizedString(@"Show as Text Tooltip", @"show as text tooltip item label"), NSLocalizedString(@"Show as HTML Tooltip", @"show as html tooltip item label"), NSLocalizedString(@"Show as HTML", @"show as html item label"), + NSLocalizedString(@"None", @"none menu item label"), NSLocalizedString(@"Current Word", @"current word item label"), NSLocalizedString(@"Current Line", @"current line item label"), NSLocalizedString(@"Current Query", @"current query item label"), NSLocalizedString(@"Entire Content", @"entire content item label"), - NSLocalizedString(@"None", @"none menu item label"), - NSLocalizedString(@"Current Word", @"current word item label"), - NSLocalizedString(@"Current Line", @"current line item label"), - NSLocalizedString(@"Entire Content", @"entire content item label"), nil] forKeys:allPopupScopeItems]; NSMenuItem *anItem; - for(NSString* title in inputEditorScopeArray) { + for(NSString* title in inputGeneralScopeArray) { anItem = [[NSMenuItem alloc] initWithTitle:[menuItemTitles objectForKey:title] action:@selector(inputPopupButtonChanged:) keyEquivalent:@""]; - [inputEditorScopePopUpMenu addItem:anItem]; + [inputGeneralScopePopUpMenu addItem:anItem]; [anItem release]; } for(NSString* title in inputInputFieldScopeArray) { @@ -177,9 +169,9 @@ [inputDataTableScopePopUpMenu addItem:anItem]; [anItem release]; } - for(NSString* title in outputEditorScopeArray) { + for(NSString* title in outputGeneralScopeArray) { anItem = [[NSMenuItem alloc] initWithTitle:[menuItemTitles objectForKey:title] action:@selector(outputPopupButtonChanged:) keyEquivalent:@""]; - [outputEditorScopePopUpMenu addItem:anItem]; + [outputGeneralScopePopUpMenu addItem:anItem]; [anItem release]; } for(NSString* title in outputInputFieldScopeArray) { @@ -192,11 +184,6 @@ [outputDataTableScopePopUpMenu addItem:anItem]; [anItem release]; } - for(NSString* title in inputFallbackEditorScopeArray) { - anItem = [[NSMenuItem alloc] initWithTitle:[menuItemTitles objectForKey:title] action:@selector(inputFallbackPopupButtonChanged:) keyEquivalent:@""]; - [inputFallbackEditorScopePopUpMenu addItem:anItem]; - [anItem release]; - } for(NSString* title in inputFallbackInputFieldScopeArray) { anItem = [[NSMenuItem alloc] initWithTitle:[menuItemTitles objectForKey:title] action:@selector(inputFallbackPopupButtonChanged:) keyEquivalent:@""]; [inputFallbackInputFieldScopePopUpMenu addItem:anItem]; @@ -206,6 +193,26 @@ [inputNonePopUpMenu addItem:anItem]; [anItem release]; + [inputGeneralScopePopUpMenu removeAllItems]; + anItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"General", @"general scope menu label") action:@selector(scopeButtonChanged:) keyEquivalent:@""]; + [anItem setTag:0]; + [inputGeneralScopePopUpMenu addItem:anItem]; + [anItem release]; + anItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Input Field", @"input field scope menu label") action:@selector(scopeButtonChanged:) keyEquivalent:@""]; + [anItem setTag:1]; + [inputGeneralScopePopUpMenu addItem:anItem]; + [anItem release]; + anItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Data Table", @"data table scope menu label") action:@selector(scopeButtonChanged:) keyEquivalent:@""]; + [anItem setTag:2]; + [inputGeneralScopePopUpMenu addItem:anItem]; + [anItem release]; + [inputGeneralScopePopUpMenu addItem:[NSMenuItem separatorItem]]; + anItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Disable Command", @"disable command menu label") action:@selector(scopeButtonChanged:) keyEquivalent:@""]; + [anItem setTag:10]; + [inputGeneralScopePopUpMenu addItem:anItem]; + [anItem release]; + [scopePopupButton setMenu:inputGeneralScopePopUpMenu]; + [keyEquivalentField setCanCaptureGlobalHotKeys:YES]; } @@ -221,8 +228,8 @@ NSInteger selectedIndex = [senderMenu indexOfItem:sender]; NSString *input = SPBundleInputSourceNone; - if(senderMenu == inputEditorScopePopUpMenu) - input = [inputEditorScopeArray objectAtIndex:selectedIndex]; + if(senderMenu == inputGeneralScopePopUpMenu) + input = [inputGeneralScopeArray objectAtIndex:selectedIndex]; else if(senderMenu == inputInputFieldScopePopUpMenu) input = [inputInputFieldScopeArray objectAtIndex:selectedIndex]; else if(senderMenu == inputDataTableScopePopUpMenu) @@ -245,9 +252,7 @@ NSInteger selectedIndex = [senderMenu indexOfItem:sender]; NSString *input = SPBundleInputSourceNone; - if(senderMenu == inputFallbackEditorScopePopUpMenu) - input = [inputFallbackEditorScopeArray objectAtIndex:selectedIndex]; - else if(senderMenu == inputFallbackInputFieldScopePopUpMenu) + if(senderMenu == inputFallbackInputFieldScopePopUpMenu) input = [inputFallbackInputFieldScopeArray objectAtIndex:selectedIndex]; [currentDict setObject:input forKey:SPBundleFileInputSourceFallBackKey]; @@ -263,8 +268,8 @@ NSInteger selectedIndex = [senderMenu indexOfItem:sender]; NSString *output = SPBundleOutputActionNone; - if(senderMenu == outputEditorScopePopUpMenu) - output = [outputEditorScopeArray objectAtIndex:selectedIndex]; + if(senderMenu == outputGeneralScopePopUpMenu) + output = [outputGeneralScopeArray objectAtIndex:selectedIndex]; else if(senderMenu == outputInputFieldScopePopUpMenu) output = [outputInputFieldScopeArray objectAtIndex:selectedIndex]; else if(senderMenu == outputDataTableScopePopUpMenu) @@ -278,35 +283,22 @@ { id currentDict = [commandBundleArray objectAtIndex:[commandsTableView selectedRow]]; - NSInteger inputMask = [[currentDict objectForKey:SPBundleScopeQueryEditor] intValue] * 1 + - [[currentDict objectForKey:SPBundleScopeInputField] intValue] * 2 + - [[currentDict objectForKey:SPBundleScopeDataTable] intValue] * 4; - - if(inputMask < 1 || inputMask > 7) { - inputMask = 7; - NSNumber *on = [NSNumber numberWithInt:1]; - [currentDict setObject:on forKey:SPBundleScopeQueryEditor]; - [currentDict setObject:on forKey:SPBundleScopeInputField]; - [currentDict setObject:on forKey:SPBundleScopeDataTable]; - } - - [currentDict setObject:[NSNumber numberWithInt:inputMask] forKey:@"inputMask"]; - if(inputMask > 4) { - [currentDict setObject:SPBundleInputSourceNone forKey:SPBundleFileInputSourceKey]; - [currentDict setObject:SPBundleInputSourceNone forKey:SPBundleFileInputSourceFallBackKey]; - if(![[currentDict objectForKey:SPBundleFileOutputActionKey] isEqualToString:SPBundleOutputActionShowAsTextTooltip] - && ![[currentDict objectForKey:SPBundleFileOutputActionKey] isEqualToString:SPBundleOutputActionShowAsHTMLTooltip]) { - [currentDict setObject:SPBundleOutputActionNone forKey:SPBundleFileOutputActionKey]; - } + NSInteger selectedTag = [sender tag]; + switch(selectedTag) { + case 0: + [currentDict setObject:SPBundleScopeGeneral forKey:SPBundleFileScopeKey]; + break; + case 1: + [currentDict setObject:SPBundleScopeInputField forKey:SPBundleFileScopeKey]; + break; + case 2: + [currentDict setObject:SPBundleScopeDataTable forKey:SPBundleFileScopeKey]; + break; + default: + [currentDict setObject:@"" forKey:SPBundleFileScopeKey]; } - if([[currentDict objectForKey:SPBundleFileInputSourceKey] isEqualToString:SPBundleInputSourceSelectedText]) { - if(inputMask > 1 && [[currentDict objectForKey:SPBundleFileInputSourceFallBackKey] isEqualToString:SPBundleInputSourceCurrentQuery]) - [currentDict setObject:SPBundleInputSourceNone forKey:SPBundleFileInputSourceFallBackKey]; - } - if((inputMask == 2 || inputMask == 3) && [[currentDict objectForKey:SPBundleFileOutputActionKey] isEqualToString:SPBundleOutputActionInsertAsSnippet]) - [currentDict setObject:SPBundleOutputActionInsertAsText forKey:SPBundleFileOutputActionKey]; [self _updateInputPopupButton]; @@ -376,8 +368,8 @@ } // Add a new Bundle else { - bundle = [NSMutableDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"New Bundle", @"New Name", @"", SPBundleScopeInputField, [NSNumber numberWithInt:1], nil] - forKeys:[NSArray arrayWithObjects:@"bundleName", SPBundleFileNameKey, SPBundleFileCommandKey, SPBundleFileScopeKey, SPBundleScopeInputField, nil]]; + bundle = [NSMutableDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"New Bundle", @"New Name", @"", SPBundleScopeGeneral, nil] + forKeys:[NSArray arrayWithObjects:@"bundleName", SPBundleFileNameKey, SPBundleFileCommandKey, SPBundleFileScopeKey, nil]]; } if ([commandsTableView numberOfSelectedRows] > 0) { insertIndex = [[commandsTableView selectedRowIndexes] lastIndex]+1; @@ -499,18 +491,6 @@ [bundleCommand addEntriesFromDictionary:cmdData]; [bundleCommand setObject:[bundle stringByDeletingPathExtension] forKey:@"bundleName"]; - NSInteger inputMask = 0; - - // Handle stored scopes - NSArray *scopes = [[cmdData objectForKey:SPBundleFileScopeKey] componentsSeparatedByString:@" "]; - for(NSString *scope in scopes) { - [bundleCommand setObject:[NSNumber numberWithInt:1] forKey:scope]; - if([scope isEqualToString:SPBundleScopeQueryEditor]) inputMask += 1; - if([scope isEqualToString:SPBundleScopeInputField]) inputMask += 2; - if([scope isEqualToString:SPBundleScopeDataTable]) inputMask += 4; - [bundleCommand setObject:[NSNumber numberWithInt:inputMask] forKey:@"inputMask"]; - } - [commandBundleArray addObject:bundleCommand]; } @@ -599,35 +579,9 @@ NSMutableDictionary *saveDict = [NSMutableDictionary dictionary]; [saveDict addEntriesFromDictionary:bundle]; - // Build scope key - NSMutableString *scopes = [NSMutableString string]; - if([bundle objectForKey:SPBundleScopeQueryEditor] && [[bundle objectForKey:SPBundleScopeQueryEditor] intValue]) { - if([scopes length]) [scopes appendString:@" "]; - [scopes appendString:SPBundleScopeQueryEditor]; - } - if([bundle objectForKey:SPBundleScopeInputField] && [[bundle objectForKey:SPBundleScopeInputField] intValue]) { - if([scopes length]) [scopes appendString:@" "]; - [scopes appendString:SPBundleScopeInputField]; - } - if([bundle objectForKey:SPBundleScopeDataTable] && [[bundle objectForKey:SPBundleScopeDataTable] intValue]) { - if([scopes length]) [scopes appendString:@" "]; - [scopes appendString:SPBundleScopeDataTable]; - } - if(![scopes length]) { - // For safety reasons - [scopes setString:[NSString stringWithFormat:@"%@ %@ %@", SPBundleScopeQueryEditor, SPBundleScopeInputField, SPBundleScopeDataTable]]; - [saveDict setObject:SPBundleInputSourceNone forKey:SPBundleFileInputSourceKey]; - [saveDict setObject:SPBundleOutputActionNone forKey:SPBundleFileOutputActionKey]; - } - [saveDict setObject:scopes forKey:SPBundleFileScopeKey]; - // Remove unnecessary keys [saveDict removeObjectsForKeys:[NSArray arrayWithObjects: @"bundleName", - @"inputMask", - SPBundleScopeQueryEditor, - SPBundleScopeInputField, - SPBundleScopeDataTable, nil]]; // Remove a given old command.plist file @@ -668,8 +622,8 @@ // Use a AppleScript script since NSWorkspace performFileOperation or NSFileManager moveItemAtPath // have problems probably due access rights. - NSString *moveToTrahCommand = [NSString stringWithFormat:@"osascript -e 'tell application \"Finder\" to move (POSIX file \"%@\") to the trash'", thePath]; - [moveToTrahCommand runBashCommandWithEnvironment:nil atCurrentDirectoryPath:nil error:&error]; + NSString *moveToTrashCommand = [NSString stringWithFormat:@"osascript -e 'tell application \"Finder\" to move (POSIX file \"%@\") to the trash'", thePath]; + [moveToTrashCommand runBashCommandWithEnvironment:nil atCurrentDirectoryPath:nil error:&error]; if(error != nil) { NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while moving “%@” to Trash.", @"error while moving “%@” to trash"), thePath] defaultButton:NSLocalizedString(@"OK", @"OK button") @@ -1086,24 +1040,33 @@ NSString *output = [currentDict objectForKey:SPBundleFileOutputActionKey]; if(!output || ![output length]) output = SPBundleOutputActionNone; - NSInteger inputMask = [[currentDict objectForKey:@"inputMask"] intValue]; - switch(inputMask) { - case 1: - [inputPopupButton setMenu:inputEditorScopePopUpMenu]; - anIndex = [inputEditorScopeArray indexOfObject:input]; - if(anIndex == NSNotFound) anIndex = 0; - [inputPopupButton selectItemAtIndex:anIndex]; - [inputFallbackPopupButton setMenu:inputFallbackEditorScopePopUpMenu]; - anIndex = [inputFallbackEditorScopeArray indexOfObject:inputfallback]; - if(anIndex == NSNotFound) anIndex = 0; - [inputFallbackPopupButton selectItemAtIndex:anIndex]; - [outputPopupButton setMenu:outputEditorScopePopUpMenu]; - anIndex = [outputEditorScopeArray indexOfObject:output]; + NSString *scope = [currentDict objectForKey:SPBundleFileScopeKey]; + if(!scope) scope = SPBundleScopeGeneral; + + if([scope isEqualToString:SPBundleScopeGeneral]) + [scopePopupButton selectItemWithTag:0]; + else if([scope isEqualToString:SPBundleScopeInputField]) + [scopePopupButton selectItemWithTag:1]; + else if([scope isEqualToString:SPBundleScopeDataTable]) + [scopePopupButton selectItemWithTag:2]; + else + [scopePopupButton selectItemWithTag:10]; + + [currentDict setObject:[NSNumber numberWithBool:NO] forKey:SPBundleFileDisabledKey]; + + switch([[scopePopupButton selectedItem] tag]) { + case 0: // General + [inputPopupButton setMenu:inputNonePopUpMenu]; + [inputPopupButton selectItemAtIndex:0]; + [outputPopupButton setMenu:outputGeneralScopePopUpMenu]; + anIndex = [outputGeneralScopeArray indexOfObject:output]; if(anIndex == NSNotFound) anIndex = 0; [outputPopupButton selectItemAtIndex:anIndex]; + input = SPBundleInputSourceNone; + [inputFallbackPopupButton setHidden:YES]; + [fallbackLabelField setHidden:YES]; break; - case 2: - case 3: + case 1: // Input Field [inputPopupButton setMenu:inputInputFieldScopePopUpMenu]; anIndex = [inputInputFieldScopeArray indexOfObject:input]; if(anIndex == NSNotFound) anIndex = 0; @@ -1117,7 +1080,7 @@ if(anIndex == NSNotFound) anIndex = 0; [outputPopupButton selectItemAtIndex:anIndex]; break; - case 4: + case 2: // Data Table [inputPopupButton setMenu:inputDataTableScopePopUpMenu]; anIndex = [inputDataTableScopeArray indexOfObject:input]; if(anIndex == NSNotFound) anIndex = 0; @@ -1126,22 +1089,18 @@ anIndex = [outputDataTableScopeArray indexOfObject:output]; if(anIndex == NSNotFound) anIndex = 0; [outputPopupButton selectItemAtIndex:anIndex]; + input = SPBundleInputSourceNone; + [inputFallbackPopupButton setHidden:YES]; + [fallbackLabelField setHidden:YES]; break; - case 5: - case 6: - case 7: - [inputPopupButton setMenu:inputNonePopUpMenu]; - [inputPopupButton selectItemAtIndex:0]; - [outputPopupButton setMenu:outputDataTableScopePopUpMenu]; - anIndex = [outputDataTableScopeArray indexOfObject:output]; - if(anIndex == NSNotFound) anIndex = 0; - [outputPopupButton selectItemAtIndex:anIndex]; + case 10: // Disable command + [currentDict setObject:[NSNumber numberWithBool:YES] forKey:SPBundleFileDisabledKey]; break; default: [inputPopupButton setMenu:inputNonePopUpMenu]; [inputPopupButton selectItemAtIndex:0]; - [outputPopupButton setMenu:outputDataTableScopePopUpMenu]; - anIndex = [outputDataTableScopeArray indexOfObject:output]; + [outputPopupButton setMenu:outputGeneralScopePopUpMenu]; + anIndex = [outputGeneralScopeArray indexOfObject:output]; if(anIndex == NSNotFound) anIndex = 0; [outputPopupButton selectItemAtIndex:anIndex]; } diff --git a/Source/SPCopyTable.m b/Source/SPCopyTable.m index 77dd14f6..28fcb476 100644 --- a/Source/SPCopyTable.m +++ b/Source/SPCopyTable.m @@ -804,132 +804,132 @@ NSInteger MENU_EDIT_COPY_AS_SQL = 2003; - (IBAction)executeBundleItemForDataTable:(id)sender { - NSInteger idx = [sender tag] - 1000000; - NSString *infoPath = nil; - NSArray *bundleItems = [[NSApp delegate] bundleItemsForScope:SPBundleScopeDataTable]; - if(idx >=0 && idx < [bundleItems count]) { - infoPath = [[bundleItems objectAtIndex:idx] objectForKey:SPBundleInternPathToFileKey]; - } else { - if([sender tag] == 0 && [[sender toolTip] length]) { - infoPath = [sender toolTip]; - } + NSInteger idx = [sender tag] - 1000000; + NSString *infoPath = nil; + NSArray *bundleItems = [[NSApp delegate] bundleItemsForScope:SPBundleScopeDataTable]; + if(idx >=0 && idx < [bundleItems count]) { + infoPath = [[bundleItems objectAtIndex:idx] objectForKey:SPBundleInternPathToFileKey]; + } else { + if([sender tag] == 0 && [[sender toolTip] length]) { + infoPath = [sender toolTip]; } + } - if(!infoPath) { - NSBeep(); - return; - } + if(!infoPath) { + NSBeep(); + return; + } - NSError *readError = nil; - NSString *convError = nil; - NSPropertyListFormat format; - NSDictionary *cmdData = nil; - NSData *pData = [NSData dataWithContentsOfFile:infoPath options:NSUncachedRead error:&readError]; + NSError *readError = nil; + NSString *convError = nil; + NSPropertyListFormat format; + NSDictionary *cmdData = nil; + NSData *pData = [NSData dataWithContentsOfFile:infoPath options:NSUncachedRead error:&readError]; - cmdData = [[NSPropertyListSerialization propertyListFromData:pData - mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError] retain]; + cmdData = [[NSPropertyListSerialization propertyListFromData:pData + mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError] retain]; - if(!cmdData || readError != nil || [convError length] || !(format == NSPropertyListXMLFormat_v1_0 || format == NSPropertyListBinaryFormat_v1_0)) { - NSLog(@"“%@” file couldn't be read.", infoPath); - NSBeep(); - if (cmdData) [cmdData release]; - return; - } else { - if([cmdData objectForKey:SPBundleFileCommandKey] && [[cmdData objectForKey:SPBundleFileCommandKey] length]) { + if(!cmdData || readError != nil || [convError length] || !(format == NSPropertyListXMLFormat_v1_0 || format == NSPropertyListBinaryFormat_v1_0)) { + NSLog(@"“%@” file couldn't be read.", infoPath); + NSBeep(); + if (cmdData) [cmdData release]; + return; + } else { + if([cmdData objectForKey:SPBundleFileCommandKey] && [[cmdData objectForKey:SPBundleFileCommandKey] length]) { - NSString *cmd = [cmdData objectForKey:SPBundleFileCommandKey]; - NSString *inputAction = @""; - NSString *inputFallBackAction = @""; - NSError *err = nil; - NSString *bundleInputFilePath = [NSString stringWithFormat:@"%@_%@", SPBundleTaskInputFilePath, [NSString stringWithNewUUID]]; + NSString *cmd = [cmdData objectForKey:SPBundleFileCommandKey]; + NSString *inputAction = @""; + NSString *inputFallBackAction = @""; + NSError *err = nil; + NSString *bundleInputFilePath = [NSString stringWithFormat:@"%@_%@", SPBundleTaskInputFilePath, [NSString stringWithNewUUID]]; - [[NSFileManager defaultManager] removeItemAtPath:bundleInputFilePath error:nil]; + [[NSFileManager defaultManager] removeItemAtPath:bundleInputFilePath error:nil]; - if([cmdData objectForKey:SPBundleFileInputSourceKey]) - inputAction = [[cmdData objectForKey:SPBundleFileInputSourceKey] lowercaseString]; - if([cmdData objectForKey:SPBundleFileInputSourceFallBackKey]) - inputFallBackAction = [[cmdData objectForKey:SPBundleFileInputSourceFallBackKey] lowercaseString]; + if([cmdData objectForKey:SPBundleFileInputSourceKey]) + inputAction = [[cmdData objectForKey:SPBundleFileInputSourceKey] lowercaseString]; + if([cmdData objectForKey:SPBundleFileInputSourceFallBackKey]) + inputFallBackAction = [[cmdData objectForKey:SPBundleFileInputSourceFallBackKey] lowercaseString]; - NSMutableDictionary *env = [NSMutableDictionary dictionary]; - [env setObject:[infoPath stringByDeletingLastPathComponent] forKey:@"SP_BUNDLE_PATH"]; - [env setObject:bundleInputFilePath forKey:@"SP_BUNDLE_INPUT_FILE"]; + NSMutableDictionary *env = [NSMutableDictionary dictionary]; + [env setObject:[infoPath stringByDeletingLastPathComponent] forKey:@"SP_BUNDLE_PATH"]; + [env setObject:bundleInputFilePath forKey:@"SP_BUNDLE_INPUT_FILE"]; - if([[self delegate] respondsToSelector:@selector(usedQuery)] && [[self delegate] usedQuery]) - [env setObject:[[self delegate] usedQuery] forKey:@"SP_USED_QUERY_FOR_TABLE"]; + if([[self delegate] respondsToSelector:@selector(usedQuery)] && [[self delegate] usedQuery]) + [env setObject:[[self delegate] usedQuery] forKey:@"SP_USED_QUERY_FOR_TABLE"]; - NSError *inputFileError = nil; - NSString *input = @""; - if([inputAction isEqualToString:SPBundleInputSourceSelectedTableRowsAsTab]) { - input = [self rowsAsTabStringWithHeaders:YES onlySelectedRows:YES]; - } - else if([inputAction isEqualToString:SPBundleInputSourceSelectedTableRowsAsCsv]) { - input = [self rowsAsCsvStringWithHeaders:YES onlySelectedRows:YES]; - } - else if([inputAction isEqualToString:SPBundleInputSourceSelectedTableRowsAsSqlInsert]) { - input = [self rowsAsSqlInsertsOnlySelectedRows:YES]; - } - else if([inputAction isEqualToString:SPBundleInputSourceTableRowsAsTab]) { - input = [self rowsAsTabStringWithHeaders:YES onlySelectedRows:NO]; - } - else if([inputAction isEqualToString:SPBundleInputSourceTableRowsAsCsv]) { - input = [self rowsAsCsvStringWithHeaders:YES onlySelectedRows:NO]; - } - else if([inputAction isEqualToString:SPBundleInputSourceTableRowsAsSqlInsert]) { - input = [self rowsAsSqlInsertsOnlySelectedRows:NO]; - } - - if(input == nil) input = @""; - [input writeToFile:bundleInputFilePath - atomically:YES - encoding:NSUTF8StringEncoding - error:&inputFileError]; - - if(inputFileError != nil) { - NSString *errorMessage = [inputFileError localizedDescription]; - SPBeginAlertSheet(NSLocalizedString(@"Bundle Error", @"bundle error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [self window], self, nil, nil, - [NSString stringWithFormat:@"%@ “%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [cmdData objectForKey:@"name"], errorMessage]); - if (cmdData) [cmdData release]; - return; - } + NSError *inputFileError = nil; + NSString *input = @""; + if([inputAction isEqualToString:SPBundleInputSourceSelectedTableRowsAsTab]) { + input = [self rowsAsTabStringWithHeaders:YES onlySelectedRows:YES]; + } + else if([inputAction isEqualToString:SPBundleInputSourceSelectedTableRowsAsCsv]) { + input = [self rowsAsCsvStringWithHeaders:YES onlySelectedRows:YES]; + } + else if([inputAction isEqualToString:SPBundleInputSourceSelectedTableRowsAsSqlInsert]) { + input = [self rowsAsSqlInsertsOnlySelectedRows:YES]; + } + else if([inputAction isEqualToString:SPBundleInputSourceTableRowsAsTab]) { + input = [self rowsAsTabStringWithHeaders:YES onlySelectedRows:NO]; + } + else if([inputAction isEqualToString:SPBundleInputSourceTableRowsAsCsv]) { + input = [self rowsAsCsvStringWithHeaders:YES onlySelectedRows:NO]; + } + else if([inputAction isEqualToString:SPBundleInputSourceTableRowsAsSqlInsert]) { + input = [self rowsAsSqlInsertsOnlySelectedRows:NO]; + } + + if(input == nil) input = @""; + [input writeToFile:bundleInputFilePath + atomically:YES + encoding:NSUTF8StringEncoding + error:&inputFileError]; + + if(inputFileError != nil) { + NSString *errorMessage = [inputFileError localizedDescription]; + SPBeginAlertSheet(NSLocalizedString(@"Bundle Error", @"bundle error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [self window], self, nil, nil, + [NSString stringWithFormat:@"%@ “%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [cmdData objectForKey:@"name"], errorMessage]); + if (cmdData) [cmdData release]; + return; + } - NSString *output = [cmd runBashCommandWithEnvironment:env atCurrentDirectoryPath:nil error:&err]; + NSString *output = [cmd runBashCommandWithEnvironment:env atCurrentDirectoryPath:nil error:&err]; - [[NSFileManager defaultManager] removeItemAtPath:bundleInputFilePath error:nil]; + [[NSFileManager defaultManager] removeItemAtPath:bundleInputFilePath error:nil]; - if(err == nil && output && [cmdData objectForKey:SPBundleFileOutputActionKey]) { - if([[cmdData objectForKey:SPBundleFileOutputActionKey] length] - && ![[cmdData objectForKey:SPBundleFileOutputActionKey] isEqualToString:SPBundleOutputActionNone]) { - NSString *action = [[cmdData objectForKey:SPBundleFileOutputActionKey] lowercaseString]; - NSPoint pos = [NSEvent mouseLocation]; - pos.y -= 16; + if(err == nil && output && [cmdData objectForKey:SPBundleFileOutputActionKey]) { + if([[cmdData objectForKey:SPBundleFileOutputActionKey] length] + && ![[cmdData objectForKey:SPBundleFileOutputActionKey] isEqualToString:SPBundleOutputActionNone]) { + NSString *action = [[cmdData objectForKey:SPBundleFileOutputActionKey] lowercaseString]; + NSPoint pos = [NSEvent mouseLocation]; + pos.y -= 16; - if([action isEqualToString:SPBundleOutputActionShowAsTextTooltip]) { - [SPTooltip showWithObject:output atLocation:pos]; - } + if([action isEqualToString:SPBundleOutputActionShowAsTextTooltip]) { + [SPTooltip showWithObject:output atLocation:pos]; + } - else if([action isEqualToString:SPBundleOutputActionShowAsHTMLTooltip]) { - [SPTooltip showWithObject:output atLocation:pos ofType:@"html"]; - } + else if([action isEqualToString:SPBundleOutputActionShowAsHTMLTooltip]) { + [SPTooltip showWithObject:output atLocation:pos ofType:@"html"]; + } - else if([action isEqualToString:SPBundleOutputActionShowAsHTML]) { - SPBundleHTMLOutputController *c = [[SPBundleHTMLOutputController alloc] init]; - [c displayHTMLContent:output withOptions:nil]; - } + else if([action isEqualToString:SPBundleOutputActionShowAsHTML]) { + SPBundleHTMLOutputController *c = [[SPBundleHTMLOutputController alloc] init]; + [c displayHTMLContent:output withOptions:nil]; } - } else { - NSString *errorMessage = [err localizedDescription]; - SPBeginAlertSheet(NSLocalizedString(@"BASH Error", @"bash error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [self window], self, nil, nil, - [NSString stringWithFormat:@"%@ “%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [cmdData objectForKey:@"name"], errorMessage]); } - + } else { + NSString *errorMessage = [err localizedDescription]; + SPBeginAlertSheet(NSLocalizedString(@"BASH Error", @"bash error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [self window], self, nil, nil, + [NSString stringWithFormat:@"%@ “%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [cmdData objectForKey:@"name"], errorMessage]); } - if (cmdData) [cmdData release]; - } + if (cmdData) [cmdData release]; + } +} + /** * Only have the copy menu item enabled when row(s) are selected in * supported tables. diff --git a/Source/SPEditSheetTextView.m b/Source/SPEditSheetTextView.m index a333a850..95fcd51d 100644 --- a/Source/SPEditSheetTextView.m +++ b/Source/SPEditSheetTextView.m @@ -137,27 +137,6 @@ [[self delegate] setDoGroupDueToChars]; } - - if([[[[self delegate] class] description] isEqualToString:@"SPBundleEditorController"]) { - [super keyDown: theEvent]; - return; - } - - // Check for assign key equivalents inside user-defined bundle commands - NSDictionary *keyEquivalents = [[NSApp delegate] bundleKeyEquivalentsForScope:SPBundleScopeInputField]; - if([keyEquivalents count]) { - for(NSString* key in [keyEquivalents allKeys]) { - NSArray *keyData = [keyEquivalents objectForKey:key]; - if([[keyData objectAtIndex:0] isEqualToString:charactersIgnMod] && [[[keyEquivalents objectForKey:key] objectAtIndex:1] intValue] == curFlags) { - NSMenuItem *item = [[[NSMenuItem alloc] init] autorelease]; - [item setToolTip:[[keyEquivalents objectForKey:key] objectAtIndex:2]]; - [item setTag:0]; - [self executeBundleItemForInputField:item]; - return; - } - } - } - [super keyDown: theEvent]; } diff --git a/Source/SPStringAdditions.m b/Source/SPStringAdditions.m index ea3f6385..1f9f2738 100644 --- a/Source/SPStringAdditions.m +++ b/Source/SPStringAdditions.m @@ -535,7 +535,7 @@ if(userTerminated) { if(bashTask) [bashTask release]; NSBeep(); - NSLog(@"“%@” was terminated by user.", self); + NSLog(@"“%@” was terminated by user.", ([self length] > 50) ? [self substringToIndex:50] : self); return @""; } diff --git a/Source/SPTextView.h b/Source/SPTextView.h index 02482611..797fff34 100644 --- a/Source/SPTextView.h +++ b/Source/SPTextView.h @@ -144,6 +144,4 @@ - (BOOL)isSnippetMode; -- (IBAction)executeBundleItemForEditor:(id)sender; - @end diff --git a/Source/SPTextView.m b/Source/SPTextView.m index ef581a8f..c458e7b1 100644 --- a/Source/SPTextView.m +++ b/Source/SPTextView.m @@ -2121,21 +2121,6 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) } } - // Check for assign key equivalents inside user-defined bundle commands - NSDictionary *keyEquivalents = [[NSApp delegate] bundleKeyEquivalentsForScope:SPBundleScopeQueryEditor]; - if([keyEquivalents count]) { - for(NSString* key in [keyEquivalents allKeys]) { - NSArray *keyData = [keyEquivalents objectForKey:key]; - if([[keyData objectAtIndex:0] isEqualToString:charactersIgnMod] && [[[keyEquivalents objectForKey:key] objectAtIndex:1] intValue] == curFlags) { - NSMenuItem *item = [[[NSMenuItem alloc] init] autorelease]; - [item setToolTip:[[keyEquivalents objectForKey:key] objectAtIndex:2]]; - [item setTag:0]; - [self executeBundleItemForEditor:item]; - return; - } - } - } - // Only process for character autopairing if autopairing is enabled and a single character is being added. if ([prefs boolForKey:SPCustomQueryAutoPairCharacters] && characters && [characters length] == 1) { @@ -2928,8 +2913,8 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) [menu removeItem:bItem]; } - NSArray *bundleCategories = [[NSApp delegate] bundleCategoriesForScope:SPBundleScopeQueryEditor]; - NSArray *bundleItems = [[NSApp delegate] bundleItemsForScope:SPBundleScopeQueryEditor]; + NSArray *bundleCategories = [[NSApp delegate] bundleCategoriesForScope:SPBundleScopeInputField]; + NSArray *bundleItems = [[NSApp delegate] bundleItemsForScope:SPBundleScopeInputField]; // Add 'Bundles' sub menu for custom query editor only so far if bundles with scope 'editor' were found if(customQueryInstance && bundleItems && [bundleItems count]) { @@ -2962,7 +2947,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) else keyEq = @""; - NSMenuItem *mItem = [[[NSMenuItem alloc] initWithTitle:[item objectForKey:SPBundleInternLabelKey] action:@selector(executeBundleItemForEditor:) keyEquivalent:keyEq] autorelease]; + NSMenuItem *mItem = [[[NSMenuItem alloc] initWithTitle:[item objectForKey:SPBundleInternLabelKey] action:@selector(executeBundleItemForInputField:) keyEquivalent:keyEq] autorelease]; if([keyEq length]) [mItem setKeyEquivalentModifierMask:[[[item objectForKey:SPBundleFileKeyEquivalentKey] objectAtIndex:1] intValue]]; @@ -2994,15 +2979,6 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) - (BOOL)validateMenuItem:(NSMenuItem *)menuItem { - if([menuItem action] == @selector(executeBundleItemForEditor:)) - { - return YES; - } - if([menuItem action] == @selector(executeBundleItemForInputField:)) - { - return NO; - } - // Enable or disable the search in the MySQL help menu item depending on whether there is a // selection and whether it is a reasonable length. if ([menuItem action] == @selector(showMySQLHelpForCurrentWord:)) { @@ -3414,171 +3390,6 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) #pragma mark - -- (IBAction)executeBundleItemForEditor:(id)sender -{ - - NSInteger idx = [sender tag] - 1000000; - NSString *infoPath = nil; - NSArray *bundleItems = [[NSApp delegate] bundleItemsForScope:SPBundleScopeQueryEditor]; - if(idx >=0 && idx < [bundleItems count]) { - infoPath = [[bundleItems objectAtIndex:idx] objectForKey:SPBundleInternPathToFileKey]; - } else { - if([sender tag] == 0 && [[sender toolTip] length]) { - infoPath = [sender toolTip]; - } - } - - if(!infoPath) { - NSBeep(); - return; - } - - NSError *readError = nil; - NSString *convError = nil; - NSPropertyListFormat format; - NSDictionary *cmdData = nil; - NSData *pData = [NSData dataWithContentsOfFile:infoPath options:NSUncachedRead error:&readError]; - - cmdData = [[NSPropertyListSerialization propertyListFromData:pData - mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError] retain]; - - if(!cmdData || readError != nil || [convError length] || !(format == NSPropertyListXMLFormat_v1_0 || format == NSPropertyListBinaryFormat_v1_0)) { - NSLog(@"“%@” file couldn't be read.", infoPath); - NSBeep(); - if (cmdData) [cmdData release]; - return; - } else { - if([cmdData objectForKey:SPBundleFileCommandKey] && [[cmdData objectForKey:SPBundleFileCommandKey] length]) { - - NSString *cmd = [cmdData objectForKey:SPBundleFileCommandKey]; - NSString *inputAction = @""; - NSString *inputFallBackAction = @""; - NSError *err = nil; - NSString *bundleInputFilePath = [NSString stringWithFormat:@"%@_%@", SPBundleTaskInputFilePath, [NSString stringWithNewUUID]]; - - NSRange currentWordRange, currentQueryRange, currentSelectionRange, currentLineRange; - - [[NSFileManager defaultManager] removeItemAtPath:bundleInputFilePath error:nil]; - - if([cmdData objectForKey:SPBundleFileInputSourceKey]) - inputAction = [[cmdData objectForKey:SPBundleFileInputSourceKey] lowercaseString]; - if([cmdData objectForKey:SPBundleFileInputSourceFallBackKey]) - inputFallBackAction = [[cmdData objectForKey:SPBundleFileInputSourceFallBackKey] lowercaseString]; - - currentSelectionRange = [self selectedRange]; - currentWordRange = [self getRangeForCurrentWord]; - if(customQueryInstance && [customQueryInstance currentQueryRange].length) { - currentQueryRange = [customQueryInstance currentQueryRange]; - } else { - currentQueryRange = currentSelectionRange; - } - currentLineRange = [[self string] lineRangeForRange:NSMakeRange([self selectedRange].location, 0)]; - - NSRange replaceRange = NSMakeRange(currentSelectionRange.location, 0); - if([inputAction isEqualToString:SPBundleInputSourceSelectedText]) { - if(!currentSelectionRange.length) { - if([inputFallBackAction isEqualToString:SPBundleInputSourceCurrentWord]) - replaceRange = currentWordRange; - else if([inputFallBackAction isEqualToString:SPBundleInputSourceCurrentLine]) - replaceRange = currentLineRange; - else if([inputFallBackAction isEqualToString:SPBundleInputSourceCurrentQuery]) - replaceRange = currentQueryRange; - else if([inputAction isEqualToString:SPBundleInputSourceEntireContent]) - replaceRange = NSMakeRange(0,[[self string] length]); - } else { - replaceRange = currentSelectionRange; - } - - } - else if([inputAction isEqualToString:SPBundleInputSourceEntireContent]) { - replaceRange = NSMakeRange(0, [[self string] length]); - } - - NSMutableDictionary *env = [NSMutableDictionary dictionary]; - [env setObject:[infoPath stringByDeletingLastPathComponent] forKey:@"SP_BUNDLE_PATH"]; - [env setObject:bundleInputFilePath forKey:@"SP_BUNDLE_INPUT_FILE"]; - - if(currentSelectionRange.length) - [env setObject:[[self string] substringWithRange:currentSelectionRange] forKey:@"SP_SELECTED_TEXT"]; - - if(customQueryInstance && [customQueryInstance currentQueryRange].length) - [env setObject:[[self string] substringWithRange:[customQueryInstance currentQueryRange]] forKey:@"SP_CURRENT_QUERY"]; - - if(currentWordRange.length) - [env setObject:[[self string] substringWithRange:currentWordRange] forKey:@"SP_CURRENT_WORD"]; - - if(currentLineRange.length) - [env setObject:[[self string] substringWithRange:currentLineRange] forKey:@"SP_CURRENT_LINE"]; - - NSError *inputFileError = nil; - NSString *input = [NSString stringWithString:[[self string] substringWithRange:replaceRange]]; - [input writeToFile:bundleInputFilePath - atomically:YES - encoding:NSUTF8StringEncoding - error:&inputFileError]; - - if(inputFileError != nil) { - NSString *errorMessage = [inputFileError localizedDescription]; - SPBeginAlertSheet(NSLocalizedString(@"Bundle Error", @"bundle error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [self window], self, nil, nil, - [NSString stringWithFormat:@"%@ “%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [cmdData objectForKey:@"name"], errorMessage]); - if (cmdData) [cmdData release]; - return; - } - - NSString *output = [cmd runBashCommandWithEnvironment:env atCurrentDirectoryPath:nil error:&err]; - - [[NSFileManager defaultManager] removeItemAtPath:bundleInputFilePath error:nil]; - - if(err == nil && output && [cmdData objectForKey:SPBundleFileOutputActionKey]) { - if([[cmdData objectForKey:SPBundleFileOutputActionKey] length] - && ![[cmdData objectForKey:SPBundleFileOutputActionKey] isEqualToString:SPBundleOutputActionNone]) { - NSString *action = [[cmdData objectForKey:SPBundleFileOutputActionKey] lowercaseString]; - - if([action isEqualToString:SPBundleOutputActionInsertAsText]) { - [self insertText:output]; - } - - else if([action isEqualToString:SPBundleOutputActionInsertAsSnippet]) { - [self insertAsSnippet:output atRange:replaceRange]; - } - - else if([action isEqualToString:SPBundleOutputActionReplaceContent]) { - if([[self string] length]) - [self setSelectedRange:NSMakeRange(0, [[self string] length])]; - [self insertText:output]; - } - - else if([action isEqualToString:SPBundleOutputActionReplaceSelection]) { - [self shouldChangeTextInRange:replaceRange replacementString:output]; - [self replaceCharactersInRange:replaceRange withString:output]; - } - - else if([action isEqualToString:SPBundleOutputActionShowAsTextTooltip]) { - [SPTooltip showWithObject:output]; - } - - else if([action isEqualToString:SPBundleOutputActionShowAsHTMLTooltip]) { - [SPTooltip showWithObject:output ofType:@"html"]; - } - - else if([action isEqualToString:SPBundleOutputActionShowAsHTML]) { - SPBundleHTMLOutputController *c = [[SPBundleHTMLOutputController alloc] init]; - [c displayHTMLContent:output withOptions:nil]; - } - } - } else { - NSString *errorMessage = [err localizedDescription]; - SPBeginAlertSheet(NSLocalizedString(@"BASH Error", @"bash error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [self window], self, nil, nil, - [NSString stringWithFormat:@"%@ “%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [cmdData objectForKey:@"name"], errorMessage]); - } - - } - - if (cmdData) [cmdData release]; - - } - -} #pragma mark - diff --git a/Source/SPTextViewAdditions.m b/Source/SPTextViewAdditions.m index a33d80e4..1bc45aad 100644 --- a/Source/SPTextViewAdditions.m +++ b/Source/SPTextViewAdditions.m @@ -25,6 +25,7 @@ #import "SPAlertSheets.h" #import "SPTooltip.h" #import "SPBundleHTMLOutputController.h" +#import "SPCustomQuery.h" @implementation NSTextView (SPTextViewAdditions) @@ -528,10 +529,12 @@ NSError *err = nil; NSString *bundleInputFilePath = [NSString stringWithFormat:@"%@_%@", SPBundleTaskInputFilePath, [NSString stringWithNewUUID]]; - NSRange currentWordRange, currentSelectionRange, currentLineRange; + NSRange currentWordRange, currentSelectionRange, currentLineRange, currentQueryRange; [[NSFileManager defaultManager] removeItemAtPath:bundleInputFilePath error:nil]; + BOOL selfIsQueryEditor = ([[[self class] description] isEqualToString:@"SPTextView"]) ; + if([cmdData objectForKey:SPBundleFileInputSourceKey]) inputAction = [[cmdData objectForKey:SPBundleFileInputSourceKey] lowercaseString]; if([cmdData objectForKey:SPBundleFileInputSourceFallBackKey]) @@ -541,6 +544,14 @@ currentWordRange = [self getRangeForCurrentWord]; currentLineRange = [[self string] lineRangeForRange:NSMakeRange([self selectedRange].location, 0)]; + if(selfIsQueryEditor) { + currentQueryRange = [[self delegate] currentQueryRange]; + } else { + currentQueryRange = currentLineRange; + } + if(!currentQueryRange.length) + currentQueryRange = currentSelectionRange; + NSRange replaceRange = NSMakeRange(currentSelectionRange.location, 0); if([inputAction isEqualToString:SPBundleInputSourceSelectedText]) { if(!currentSelectionRange.length) { @@ -548,6 +559,8 @@ replaceRange = currentWordRange; else if([inputFallBackAction isEqualToString:SPBundleInputSourceCurrentLine]) replaceRange = currentLineRange; + else if([inputFallBackAction isEqualToString:SPBundleInputSourceCurrentQuery]) + replaceRange = currentQueryRange; else if([inputAction isEqualToString:SPBundleInputSourceEntireContent]) replaceRange = NSMakeRange(0,[[self string] length]); } else { @@ -563,6 +576,9 @@ [env setObject:[infoPath stringByDeletingLastPathComponent] forKey:@"SP_BUNDLE_PATH"]; [env setObject:bundleInputFilePath forKey:@"SP_BUNDLE_INPUT_FILE"]; + if(selfIsQueryEditor && [[self delegate] currentQueryRange].length) + [env setObject:[[self string] substringWithRange:[[self delegate] currentQueryRange]] forKey:@"SP_CURRENT_QUERY"]; + if(currentSelectionRange.length) [env setObject:[[self string] substringWithRange:currentSelectionRange] forKey:@"SP_SELECTED_TEXT"]; @@ -596,26 +612,7 @@ && ![[cmdData objectForKey:SPBundleFileOutputActionKey] isEqualToString:SPBundleOutputActionNone]) { NSString *action = [[cmdData objectForKey:SPBundleFileOutputActionKey] lowercaseString]; - if([action isEqualToString:SPBundleOutputActionInsertAsText]) { - [self insertText:output]; - } - - else if([action isEqualToString:SPBundleOutputActionInsertAsSnippet]) { - [self insertAsSnippet:output atRange:replaceRange]; - } - - else if([action isEqualToString:SPBundleOutputActionReplaceContent]) { - if([[self string] length]) - [self setSelectedRange:NSMakeRange(0, [[self string] length])]; - [self insertText:output]; - } - - else if([action isEqualToString:SPBundleOutputActionReplaceSelection]) { - [self shouldChangeTextInRange:replaceRange replacementString:output]; - [self replaceCharactersInRange:replaceRange withString:output]; - } - - else if([action isEqualToString:SPBundleOutputActionShowAsTextTooltip]) { + if([action isEqualToString:SPBundleOutputActionShowAsTextTooltip]) { [SPTooltip showWithObject:output]; } @@ -627,6 +624,35 @@ SPBundleHTMLOutputController *c = [[SPBundleHTMLOutputController alloc] init]; [c displayHTMLContent:output withOptions:nil]; } + + if([self isEditable]) { + + if([action isEqualToString:SPBundleOutputActionInsertAsText]) { + [self insertText:output]; + } + + else if([action isEqualToString:SPBundleOutputActionInsertAsSnippet]) { + if([self respondsToSelector:@selector(insertAsSnippet:atRange:)]) + [self insertAsSnippet:output atRange:replaceRange]; + else + [SPTooltip showWithObject:NSLocalizedString(@"Input Field doesn't support insertion of snippets.", @"input field doesn't support insertion of snippets.")]; + } + + else if([action isEqualToString:SPBundleOutputActionReplaceContent]) { + if([[self string] length]) + [self setSelectedRange:NSMakeRange(0, [[self string] length])]; + [self insertText:output]; + } + + else if([action isEqualToString:SPBundleOutputActionReplaceSelection]) { + [self shouldChangeTextInRange:replaceRange replacementString:output]; + [self replaceCharactersInRange:replaceRange withString:output]; + } + + } else { + [SPTooltip showWithObject:NSLocalizedString(@"Input Field is not editable.", @"input field is not editable.")]; + } + } } else { NSString *errorMessage = [err localizedDescription]; @@ -722,21 +748,6 @@ } -- (BOOL)validateMenuItem:(NSMenuItem *)menuItem -{ - - if([menuItem action] == @selector(executeBundleItemForEditor:)) - { - return NO; - } - if([menuItem action] == @selector(executeBundleItemForInputField:)) - { - return YES; - } - - return YES; - -} #pragma mark - #pragma mark multi-touch trackpad support |