aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Interfaces/English.lproj/DBView.xib191
-rw-r--r--Source/SPHistoryController.h59
-rw-r--r--Source/SPHistoryController.m256
-rw-r--r--Source/TableDocument.h2
-rw-r--r--Source/TableDocument.m18
-rw-r--r--Source/TablesList.h2
-rw-r--r--Source/TablesList.m2
-rw-r--r--sequel-pro.xcodeproj/project.pbxproj6
8 files changed, 508 insertions, 28 deletions
diff --git a/Interfaces/English.lproj/DBView.xib b/Interfaces/English.lproj/DBView.xib
index bac14af4..65c4decc 100644
--- a/Interfaces/English.lproj/DBView.xib
+++ b/Interfaces/English.lproj/DBView.xib
@@ -8,7 +8,7 @@
<string key="IBDocument.HIToolboxVersion">353.00</string>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
- <integer value="5"/>
+ <integer value="3994"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -47,7 +47,7 @@
<string key="NSWindowContentMaxSize">{3.40282e+38, 3.40282e+38}</string>
<string key="NSWindowContentMinSize">{780, 480}</string>
<object class="NSView" key="NSWindowView" id="579726586">
- <reference key="NSNextResponder"/>
+ <nil key="NSNextResponder"/>
<int key="NSvFlags">256</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -186,7 +186,6 @@
</object>
<string key="NSFrameSize">{212, 26}</string>
<reference key="NSSuperview" ref="199860064"/>
- <reference key="NSNextKeyView" ref="643201879"/>
<reference key="NSDocView" ref="643201879"/>
<object class="NSColor" key="NSBGColor" id="529261656">
<int key="NSColorSpace">6</int>
@@ -222,7 +221,6 @@
</object>
<string key="NSFrameSize">{212, 26}</string>
<reference key="NSSuperview" ref="801427893"/>
- <reference key="NSNextKeyView" ref="588922296"/>
<int key="NSsFlags">0</int>
<reference key="NSVScroller" ref="540853896"/>
<reference key="NSHScroller" ref="566705316"/>
@@ -337,7 +335,6 @@
</object>
<string key="NSFrameSize">{212, 354}</string>
<reference key="NSSuperview" ref="233472824"/>
- <reference key="NSNextKeyView" ref="251040077"/>
<reference key="NSDocView" ref="251040077"/>
<object class="NSColor" key="NSBGColor" id="1024678221">
<int key="NSColorSpace">6</int>
@@ -369,7 +366,6 @@
</object>
<string key="NSFrameSize">{212, 354}</string>
<reference key="NSSuperview" ref="1017775084"/>
- <reference key="NSNextKeyView" ref="73685676"/>
<int key="NSsFlags">528</int>
<reference key="NSVScroller" ref="693168867"/>
<reference key="NSHScroller" ref="656188692"/>
@@ -494,7 +490,6 @@
</object>
<string key="NSFrameSize">{212, 145}</string>
<reference key="NSSuperview" ref="298226231"/>
- <reference key="NSNextKeyView" ref="347093764"/>
<reference key="NSDocView" ref="347093764"/>
<reference key="NSBGColor" ref="1024678221"/>
<int key="NScvFlags">6</int>
@@ -521,7 +516,6 @@
</object>
<string key="NSFrameSize">{212, 145}</string>
<reference key="NSSuperview" ref="192579410"/>
- <reference key="NSNextKeyView" ref="685057119"/>
<int key="NSsFlags">512</int>
<reference key="NSVScroller" ref="245346414"/>
<reference key="NSHScroller" ref="353686052"/>
@@ -794,7 +788,7 @@
<object class="NSTabViewItem" id="831053945">
<string key="NSIdentifier">source</string>
<object class="NSView" key="NSView" id="461236772">
- <nil key="NSNextResponder"/>
+ <reference key="NSNextResponder" ref="714795046"/>
<int key="NSvFlags">256</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -1303,7 +1297,6 @@
</object>
<string key="NSFrame">{{1, 17}, {688, 289}}</string>
<reference key="NSSuperview" ref="22340145"/>
- <reference key="NSNextKeyView" ref="715508012"/>
<reference key="NSDocView" ref="715508012"/>
<reference key="NSBGColor" ref="1024678221"/>
<int key="NScvFlags">4</int>
@@ -1336,7 +1329,6 @@
</object>
<string key="NSFrame">{{1, 0}, {688, 17}}</string>
<reference key="NSSuperview" ref="22340145"/>
- <reference key="NSNextKeyView" ref="926883367"/>
<reference key="NSDocView" ref="926883367"/>
<reference key="NSBGColor" ref="1024678221"/>
<int key="NScvFlags">4</int>
@@ -1345,7 +1337,6 @@
</object>
<string key="NSFrame">{{-1, 22}, {690, 307}}</string>
<reference key="NSSuperview" ref="220777809"/>
- <reference key="NSNextKeyView" ref="16936123"/>
<int key="NSsFlags">562</int>
<reference key="NSVScroller" ref="943144555"/>
<reference key="NSHScroller" ref="456666876"/>
@@ -1888,7 +1879,6 @@
</object>
<string key="NSFrame">{{1, 17}, {688, 142}}</string>
<reference key="NSSuperview" ref="376224367"/>
- <reference key="NSNextKeyView" ref="584834515"/>
<reference key="NSDocView" ref="584834515"/>
<reference key="NSBGColor" ref="1024678221"/>
<int key="NScvFlags">4</int>
@@ -1921,7 +1911,6 @@
</object>
<string key="NSFrame">{{1, 0}, {688, 17}}</string>
<reference key="NSSuperview" ref="376224367"/>
- <reference key="NSNextKeyView" ref="459548655"/>
<reference key="NSDocView" ref="459548655"/>
<reference key="NSBGColor" ref="1024678221"/>
<int key="NScvFlags">4</int>
@@ -1930,7 +1919,6 @@
</object>
<string key="NSFrame">{{-1, 22}, {690, 160}}</string>
<reference key="NSSuperview" ref="1063281455"/>
- <reference key="NSNextKeyView" ref="794929378"/>
<int key="NSsFlags">562</int>
<reference key="NSVScroller" ref="1019209947"/>
<reference key="NSHScroller" ref="328951385"/>
@@ -2043,6 +2031,7 @@
</object>
</object>
<string key="NSFrame">{{10, 7}, {700, 544}}</string>
+ <reference key="NSSuperview" ref="714795046"/>
</object>
<string key="NSLabel">Structure</string>
<reference key="NSColor" ref="62854682"/>
@@ -4111,7 +4100,7 @@
<object class="NSTabViewItem" id="986490149">
<string key="NSIdentifier">relations</string>
<object class="NSView" key="NSView" id="49633996">
- <reference key="NSNextResponder" ref="714795046"/>
+ <nil key="NSNextResponder"/>
<int key="NSvFlags">256</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -4487,21 +4476,20 @@
</object>
</object>
<string key="NSFrame">{{10, 7}, {700, 544}}</string>
- <reference key="NSSuperview" ref="714795046"/>
</object>
<string key="NSLabel">Relations</string>
<reference key="NSColor" ref="62854682"/>
<reference key="NSTabView" ref="714795046"/>
</object>
</object>
- <reference key="NSSelectedTabViewItem" ref="986490149"/>
+ <reference key="NSSelectedTabViewItem" ref="831053945"/>
<reference key="NSFont" ref="26"/>
<int key="NSTvFlags">134217731</int>
<bool key="NSAllowTruncatedLabels">YES</bool>
<bool key="NSDrawsBackground">YES</bool>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
- <reference ref="49633996"/>
+ <reference ref="461236772"/>
</object>
</object>
</object>
@@ -4517,7 +4505,6 @@
</object>
</object>
<string key="NSFrameSize">{944, 550}</string>
- <reference key="NSSuperview"/>
</object>
<string key="NSScreenRect">{{0, 0}, {1920, 1178}}</string>
<string key="NSMinSize">{780, 502}</string>
@@ -8759,7 +8746,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<reference key="NSControlView" ref="269606631"/>
<int key="NSButtonFlags">-2030812929</int>
<int key="NSButtonFlags2">34</int>
- <object class="NSCustomResource" key="NSNormalImage">
+ <object class="NSCustomResource" key="NSNormalImage" id="435122777">
<string key="NSClassName">NSImage</string>
<string key="NSResourceName">NSGoLeftTemplate</string>
</object>
@@ -8785,7 +8772,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<reference key="NSControlView" ref="943423465"/>
<int key="NSButtonFlags">-2030812929</int>
<int key="NSButtonFlags2">34</int>
- <object class="NSCustomResource" key="NSNormalImage">
+ <object class="NSCustomResource" key="NSNormalImage" id="888810603">
<string key="NSClassName">NSImage</string>
<string key="NSResourceName">NSGoRightTemplate</string>
</object>
@@ -10881,7 +10868,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<string key="NSExtension">NSResponder</string>
</object>
<object class="NSCustomView" id="884983195">
- <nil key="NSNextResponder"/>
+ <reference key="NSNextResponder"/>
<int key="NSvFlags">301</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -10963,8 +10950,45 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<int key="NSArrowPosition">2</int>
</object>
</object>
+ <object class="NSSegmentedControl" id="731293720">
+ <reference key="NSNextResponder" ref="884983195"/>
+ <int key="NSvFlags">301</int>
+ <string key="NSFrame">{{208, 3}, {61, 25}}</string>
+ <reference key="NSSuperview" ref="884983195"/>
+ <bool key="NSEnabled">YES</bool>
+ <object class="NSSegmentedCell" key="NSCell" id="253177824">
+ <int key="NSCellFlags">67239424</int>
+ <int key="NSCellFlags2">0</int>
+ <reference key="NSSupport" ref="244931163"/>
+ <reference key="NSControlView" ref="731293720"/>
+ <object class="NSMutableArray" key="NSSegmentImages">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSSegmentItem">
+ <double key="NSSegmentItemWidth">2.700000e+01</double>
+ <reference key="NSSegmentItemImage" ref="435122777"/>
+ <string key="NSSegmentItemLabel"/>
+ <string key="NSSegmentItemTooltip">Back</string>
+ <bool key="NSSegmentItemDisabled">YES</bool>
+ <int key="NSSegmentItemImageScaling">0</int>
+ </object>
+ <object class="NSSegmentItem">
+ <double key="NSSegmentItemWidth">2.700000e+01</double>
+ <reference key="NSSegmentItemImage" ref="888810603"/>
+ <string key="NSSegmentItemLabel"/>
+ <string key="NSSegmentItemTooltip">Forward</string>
+ <int key="NSSegmentItemTag">1</int>
+ <bool key="NSSegmentItemDisabled">YES</bool>
+ <int key="NSSegmentItemImageScaling">0</int>
+ </object>
+ </object>
+ <int key="NSSelectedSegment">1</int>
+ <int key="NSTrackingMode">2</int>
+ <int key="NSSegmentStyle">2</int>
+ </object>
+ </object>
</object>
- <string key="NSFrameSize">{200, 32}</string>
+ <string key="NSFrameSize">{269, 32}</string>
+ <reference key="NSSuperview"/>
<string key="NSClassName">NSView</string>
</object>
<object class="NSCustomView" id="730777562">
@@ -11064,6 +11088,9 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<object class="NSCustomObject" id="631714493">
<string key="NSClassName">SPDatabaseData</string>
</object>
+ <object class="NSCustomObject" id="796834585">
+ <string key="NSClassName">SPHistoryController</string>
+ </object>
<object class="NSMenu" id="556141845">
<string key="NSTitle"/>
<object class="NSMutableArray" key="NSMenuItems">
@@ -14488,6 +14515,54 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
</object>
<int key="connectionID">6286</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">historyControl</string>
+ <reference key="source" ref="427689665"/>
+ <reference key="destination" ref="731293720"/>
+ </object>
+ <int key="connectionID">6296</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">spHistoryControllerInstance</string>
+ <reference key="source" ref="427689665"/>
+ <reference key="destination" ref="796834585"/>
+ </object>
+ <int key="connectionID">6298</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">historyControl</string>
+ <reference key="source" ref="796834585"/>
+ <reference key="destination" ref="731293720"/>
+ </object>
+ <int key="connectionID">6299</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBActionConnection" key="connection">
+ <string key="label">historyControlClicked:</string>
+ <reference key="source" ref="796834585"/>
+ <reference key="destination" ref="731293720"/>
+ </object>
+ <int key="connectionID">6300</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">theDocument</string>
+ <reference key="source" ref="796834585"/>
+ <reference key="destination" ref="427689665"/>
+ </object>
+ <int key="connectionID">6301</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">spHistoryControllerInstance</string>
+ <reference key="source" ref="438574515"/>
+ <reference key="destination" ref="796834585"/>
+ </object>
+ <int key="connectionID">6302</int>
+ </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@@ -16048,9 +16123,10 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<object class="NSMutableArray" key="children">
<bool key="EncodedWithXMLCoder">YES</bool>
<reference ref="359419551"/>
+ <reference ref="731293720"/>
</object>
<reference key="parent" ref="1043842561"/>
- <string key="objectName">Select DB Toolbar View</string>
+ <string key="objectName">Custom Toolbar Views</string>
</object>
<object class="IBObjectRecord">
<int key="objectID">3995</int>
@@ -20464,6 +20540,26 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<reference key="object" ref="134854992"/>
<reference key="parent" ref="727834078"/>
</object>
+ <object class="IBObjectRecord">
+ <int key="objectID">6293</int>
+ <reference key="object" ref="731293720"/>
+ <object class="NSMutableArray" key="children">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference ref="253177824"/>
+ </object>
+ <reference key="parent" ref="884983195"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">6294</int>
+ <reference key="object" ref="253177824"/>
+ <reference key="parent" ref="731293720"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">6297</int>
+ <reference key="object" ref="796834585"/>
+ <reference key="parent" ref="1043842561"/>
+ <string key="objectName">SPHistoryController</string>
+ </object>
</object>
</object>
<object class="NSMutableDictionary" key="flattenedProperties">
@@ -21692,6 +21788,11 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<string>6277.IBPluginDependency</string>
<string>6278.IBPluginDependency</string>
<string>6279.IBPluginDependency</string>
+ <string>6293.IBPluginDependency</string>
+ <string>6293.IBSegmentedControlTracker.RoundRobinState</string>
+ <string>6293.IBSegmentedControlTracker.WasGrowing</string>
+ <string>6294.IBPluginDependency</string>
+ <string>6297.IBPluginDependency</string>
<string>654.IBPluginDependency</string>
<string>654.ImportedFromIB2</string>
<string>655.IBPluginDependency</string>
@@ -22468,7 +22569,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<string>{3.40282e+38, 3.40282e+38}</string>
<string>{120, 100}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{412, 275}, {200, 32}}</string>
+ <string>{{339, 92}, {269, 32}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>{628, 654}</string>
<string>{{284, 769}, {200, 32}}</string>
@@ -23469,6 +23570,11 @@ aGUgYWN0aXZlIHNlbGVjdGlvbiAo4oyl4oyYUik</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <reference ref="8"/>
+ <reference ref="8"/>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
@@ -23688,7 +23794,7 @@ Y2hhbmdlIHRoZSBvcmRlcg</string>
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">6286</int>
+ <int key="maxID">6302</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -24171,6 +24277,31 @@ Y2hhbmdlIHRoZSBvcmRlcg</string>
</object>
</object>
<object class="IBPartialClassDescription">
+ <string key="className">SPHistoryController</string>
+ <string key="superclassName">NSObject</string>
+ <object class="NSMutableDictionary" key="actions">
+ <string key="NS.key.0">historyControlClicked:</string>
+ <string key="NS.object.0">NSSegmentedControl</string>
+ </object>
+ <object class="NSMutableDictionary" key="outlets">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSMutableArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>historyControl</string>
+ <string>theDocument</string>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>NSSegmentedControl</string>
+ <string>TableDocument</string>
+ </object>
+ </object>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBProjectSource</string>
+ <string key="minorKey">Source/SPHistoryController.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
<string key="className">SPTableData</string>
<string key="superclassName">NSObject</string>
<object class="NSMutableDictionary" key="outlets">
@@ -24482,9 +24613,11 @@ Y2hhbmdlIHRoZSBvcmRlcg</string>
<string>dbTablesTableView</string>
<string>extendedTableInfoInstance</string>
<string>favoritesButton</string>
+ <string>historyControl</string>
<string>queryProgressBar</string>
<string>sidebarGrabber</string>
<string>spExportControllerInstance</string>
+ <string>spHistoryControllerInstance</string>
<string>syntaxView</string>
<string>syntaxViewContent</string>
<string>tableContentInstance</string>
@@ -24528,6 +24661,8 @@ Y2hhbmdlIHRoZSBvcmRlcg</string>
<string>id</string>
<string>id</string>
<string>id</string>
+ <string>id</string>
+ <string>id</string>
<string>NSButton</string>
<string>NSTableView</string>
<string>NSSplitView</string>
@@ -24859,6 +24994,7 @@ Y2hhbmdlIHRoZSBvcmRlcg</string>
<string>renameTableMenuItem</string>
<string>separatorTableContextMenuItem</string>
<string>separatorTableMenuItem</string>
+ <string>spHistoryControllerInstance</string>
<string>tabView</string>
<string>tableContentInstance</string>
<string>tableDataInstance</string>
@@ -24901,6 +25037,7 @@ Y2hhbmdlIHRoZSBvcmRlcg</string>
<string>NSMenuItem</string>
<string>NSMenuItem</string>
<string>NSMenuItem</string>
+ <string>SPHistoryController</string>
<string>id</string>
<string>id</string>
<string>id</string>
diff --git a/Source/SPHistoryController.h b/Source/SPHistoryController.h
new file mode 100644
index 00000000..110ebea3
--- /dev/null
+++ b/Source/SPHistoryController.h
@@ -0,0 +1,59 @@
+//
+// $Id: SPFieldEditorController.h 802 2009-06-03 20:46:57Z bibiko $
+//
+// SPHistoryController.h
+// sequel-pro
+//
+// Created by Rowan Beentje on July 23, 2009
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// More info at <http://code.google.com/p/sequel-pro/>
+
+#import <Cocoa/Cocoa.h>
+
+@class TableDocument;
+
+enum sphistory_view_types
+{
+ SP_VIEW_STRUCTURE = 0,
+ SP_VIEW_CONTENT = 1,
+ SP_VIEW_CUSTOMQUERY = 2,
+ SP_VIEW_STATUS = 3,
+ SP_VIEW_RELATIONS = 4
+};
+
+@interface SPHistoryController : NSObject {
+ IBOutlet TableDocument *theDocument;
+ IBOutlet NSSegmentedControl *historyControl;
+
+ NSMutableArray *history;
+ unsigned int historyPosition;
+ BOOL restoringHistoryState;
+}
+
+// Interface interaction
+- (void) updateToolbarItem;
+- (IBAction) historyControlClicked:(NSSegmentedControl *)theControl;
+- (unsigned int) currentlySelectedView;
+
+// Adding or updating history entries
+- (void) updateHistoryEntries;
+
+// Loading history entries
+- (void) loadEntryAtPosition:(unsigned int)position;
+- (void) abortEntryLoad;
+
+@end
diff --git a/Source/SPHistoryController.m b/Source/SPHistoryController.m
new file mode 100644
index 00000000..fc6e03b9
--- /dev/null
+++ b/Source/SPHistoryController.m
@@ -0,0 +1,256 @@
+//
+// $Id: SPFieldEditorController.h 802 2009-06-03 20:46:57Z bibiko $
+//
+// SPHistoryController.h
+// sequel-pro
+//
+// Created by Rowan Beentje on July 23, 2009
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// More info at <http://code.google.com/p/sequel-pro/>
+
+#import "TableDocument.h"
+#import "TablesList.h"
+#import "SPHistoryController.h"
+
+
+@implementation SPHistoryController
+
+#pragma mark Setup and teardown
+
+/**
+ * Initialise by creating a blank history array
+ */
+- (id) init
+{
+ if (self = [super init]) {
+ history = [[NSMutableArray alloc] init];
+ historyPosition = NSNotFound;
+ restoringHistoryState = NO;
+ }
+ return self;
+}
+
+- (void) dealloc
+{
+ [history release];
+ [super dealloc];
+}
+
+#pragma mark -
+#pragma mark Interface interaction
+
+/**
+ * Updates the toolbar item to reflect the current history state and position
+ */
+- (void) updateToolbarItem
+{
+ BOOL backEnabled = NO;
+ BOOL forwardEnabled = NO;
+
+ // Set the active state of the segments if appropriate
+ if ([history count] && historyPosition > 0) backEnabled = YES;
+ if ([history count] && historyPosition + 1 < [history count]) forwardEnabled = YES;
+
+ [historyControl setEnabled:backEnabled forSegment:0];
+ [historyControl setEnabled:forwardEnabled forSegment:1];
+}
+
+/**
+ * Trigger a navigation action in response to a click
+ */
+- (IBAction) historyControlClicked:(NSSegmentedControl *)theControl
+{
+ switch ([theControl selectedSegment]) {
+
+ // Back button clicked:
+ case 0:
+ if (historyPosition == NSNotFound || !historyPosition) return;
+ [self loadEntryAtPosition:historyPosition - 1];
+ break;
+
+ // Forward button clicked:
+ case 1:
+ if (historyPosition == NSNotFound || historyPosition + 1 >= [history count]) return;
+ [self loadEntryAtPosition:historyPosition + 1];
+ break;
+ }
+}
+
+/**
+ * Retrieve the view that is currently selected from the database
+ */
+- (unsigned int) currentlySelectedView
+{
+ unsigned int theView = NSNotFound;
+
+ NSString *viewName = [[[theDocument valueForKey:@"tableTabView"] selectedTabViewItem] identifier];
+ if ([viewName isEqualToString:@"source"]) {
+ theView = SP_VIEW_STRUCTURE;
+ } else if ([viewName isEqualToString:@"content"]) {
+ theView = SP_VIEW_CONTENT;
+ } else if ([viewName isEqualToString:@"customQuery"]) {
+ theView = SP_VIEW_CUSTOMQUERY;
+ } else if ([viewName isEqualToString:@"status"]) {
+ theView = SP_VIEW_STATUS;
+ } else if ([viewName isEqualToString:@"relations"]) {
+ theView = SP_VIEW_RELATIONS;
+ }
+
+ return theView;
+}
+
+#pragma mark -
+#pragma mark Adding or updating history entries
+
+/**
+ * Call to store or update a history item for the document state. Checks against
+ * the latest stored details; if they match, a new history item is not created.
+ * This should therefore be called without worry of duplicates.
+ */
+- (void) updateHistoryEntries
+{
+
+ // Don't modify anything if we're in the process of restoring an old history state
+ if (restoringHistoryState) return;
+
+ // Work out the current document details
+ NSString *theDatabase = [theDocument database];
+ NSString *theTable = [theDocument table];
+ unsigned int theView = [self currentlySelectedView];
+
+ // Check for a duplicate against the current entry
+ if (historyPosition != NSNotFound) {
+ NSDictionary *currentHistoryItem = [history objectAtIndex:historyPosition];
+ if ([[currentHistoryItem objectForKey:@"database"] isEqualToString:theDatabase]
+ && [[currentHistoryItem objectForKey:@"table"] isEqualToString:theTable]
+ && [[currentHistoryItem objectForKey:@"view"] intValue] == theView)
+ {
+ return;
+ }
+ }
+
+ // If there's any items after the current history position, remove them
+ if (historyPosition != NSNotFound && historyPosition < [history count] - 1) {
+ [history removeObjectsInRange:NSMakeRange(historyPosition + 1, [history count] - historyPosition - 1)];
+
+ // Special case: if the last history item is currently active, and has no table,
+ // but the new selection does - delete the last entry, in order to replace it.
+ // This improves history flow.
+ } else if (historyPosition != NSNotFound && historyPosition == [history count] - 1
+ && [[[history objectAtIndex:historyPosition] objectForKey:@"database"] isEqualToString:theDatabase]
+ && ![[history objectAtIndex:historyPosition] objectForKey:@"table"])
+ {
+ [history removeLastObject];
+ }
+
+ // Construct and add the new history entry
+ NSMutableDictionary *newEntry = [NSMutableDictionary dictionaryWithObjectsAndKeys:
+ theDatabase, @"database",
+ theTable, @"table",
+ [NSNumber numberWithInt:theView], @"view",
+ nil];
+ [history addObject:newEntry];
+ historyPosition = [history count] - 1;
+ [self updateToolbarItem];
+}
+
+#pragma mark -
+#pragma mark Loading history entries
+
+/**
+ * Load a history entry and attempt to return the interface to that state.
+ */
+- (void) loadEntryAtPosition:(unsigned int)position
+{
+
+ // Sanity check the input
+ if (position == NSNotFound || position < 0 || position >= [history count]) {
+ NSBeep();
+ return;
+ }
+
+ restoringHistoryState = YES;
+
+ // Update the position and extract the history entry
+ historyPosition = position;
+ NSDictionary *historyEntry = [history objectAtIndex:historyPosition];
+
+ // Check and set the database
+ if (![[theDocument database] isEqualToString:[historyEntry objectForKey:@"database"]]) {
+ NSPopUpButton *chooseDatabaseButton = [theDocument valueForKey:@"chooseDatabaseButton"];
+ [chooseDatabaseButton selectItemWithTitle:[historyEntry objectForKey:@"database"]];
+ [theDocument chooseDatabase:self];
+ if (![[theDocument database] isEqualToString:[historyEntry objectForKey:@"database"]]) {
+ return [self abortEntryLoad];
+ }
+ }
+
+ // Check and set the table
+ if ([historyEntry objectForKey:@"table"] && ![[theDocument table] isEqualToString:[historyEntry objectForKey:@"table"]]) {
+ TablesList *tablesListInstance = [theDocument valueForKey:@"tablesListInstance"];
+ NSArray *tables = [tablesListInstance tables];
+ if ([tables indexOfObject:[historyEntry objectForKey:@"table"]] == NSNotFound) {
+ return [self abortEntryLoad];
+ }
+ [[tablesListInstance valueForKey:@"tablesListView"] selectRowIndexes:[NSIndexSet indexSetWithIndex:[tables indexOfObject:[historyEntry objectForKey:@"table"]]] byExtendingSelection:NO];
+ if (![[theDocument table] isEqualToString:[historyEntry objectForKey:@"table"]]) {
+ return [self abortEntryLoad];
+ }
+ } else if (![historyEntry objectForKey:@"table"] && [theDocument table]) {
+ TablesList *tablesListInstance = [theDocument valueForKey:@"tablesListInstance"];
+ [[tablesListInstance valueForKey:@"tablesListView"] deselectAll:self];
+ }
+
+ // Check and set the view
+ if ([self currentlySelectedView] != [[historyEntry objectForKey:@"view"] intValue]) {
+ switch ([[historyEntry objectForKey:@"view"] intValue]) {
+ case SP_VIEW_STRUCTURE:
+ [theDocument viewStructure:self];
+ break;
+ case SP_VIEW_CONTENT:
+ [theDocument viewContent:self];
+ break;
+ case SP_VIEW_CUSTOMQUERY:
+ [theDocument viewQuery:self];
+ break;
+ case SP_VIEW_STATUS:
+ [theDocument viewStatus:self];
+ break;
+ case SP_VIEW_RELATIONS:
+ [theDocument viewRelations:self];
+ break;
+ }
+ if ([self currentlySelectedView] != [[historyEntry objectForKey:@"view"] intValue]) {
+ return [self abortEntryLoad];
+ }
+ }
+
+ restoringHistoryState = NO;
+ [self updateToolbarItem];
+}
+
+/**
+ * Convenience method for aborting history load - could at some point
+ * clean up the history list, show an alert, etc
+ */
+- (void) abortEntryLoad
+{
+ NSBeep();
+ restoringHistoryState = NO;
+}
+
+@end
diff --git a/Source/TableDocument.h b/Source/TableDocument.h
index 5cd9dc6c..97da96f9 100644
--- a/Source/TableDocument.h
+++ b/Source/TableDocument.h
@@ -46,6 +46,7 @@
IBOutlet id tableDataInstance;
IBOutlet id extendedTableInfoInstance;
IBOutlet id databaseDataInstance;
+ IBOutlet id spHistoryControllerInstance;
IBOutlet id spExportControllerInstance;
IBOutlet id tableWindow;
@@ -64,6 +65,7 @@
IBOutlet id databaseEncodingButton;
IBOutlet id addDatabaseButton;
IBOutlet id chooseDatabaseButton;
+ IBOutlet id historyControl;
IBOutlet id variablesTableView;
IBOutlet NSTabView *tableTabView;
diff --git a/Source/TableDocument.m b/Source/TableDocument.m
index 00c31a15..76e0337b 100644
--- a/Source/TableDocument.m
+++ b/Source/TableDocument.m
@@ -43,6 +43,7 @@
#import "MainController.h"
#import "SPExtendedTableInfo.h"
#import "SPConnectionController.h"
+#import "SPHistoryController.h"
#import "SPPreferenceController.h"
#import "SPPrintAccessory.h"
#import "QLPreviewPanel.h"
@@ -168,6 +169,7 @@
if ([connectionController database] && ![[connectionController database] isEqualToString:@""]) {
if (selectedDatabase) [selectedDatabase release], selectedDatabase = nil;
selectedDatabase = [[NSString alloc] initWithString:[connectionController database]];
+ [spHistoryControllerInstance updateHistoryEntries];
}
// Update the database list
@@ -416,6 +418,9 @@
[tablesListInstance setConnection:mySQLConnection];
[tableDumpInstance setConnection:mySQLConnection];
[tableWindow setTitle:[NSString stringWithFormat:@"(MySQL %@) %@/%@", mySQLVersion, [self name], [self database]]];
+
+ // Add a history entry
+ [spHistoryControllerInstance updateHistoryEntries];
}
/**
@@ -1550,6 +1555,7 @@
[tableTabView selectTabViewItemAtIndex:0];
[mainToolbar setSelectedItemIdentifier:@"SwitchToTableStructureToolbarItemIdentifier"];
+ [spHistoryControllerInstance updateHistoryEntries];
}
- (IBAction)viewContent:(id)sender
@@ -1563,6 +1569,7 @@
[tableTabView selectTabViewItemAtIndex:1];
[mainToolbar setSelectedItemIdentifier:@"SwitchToTableContentToolbarItemIdentifier"];
+ [spHistoryControllerInstance updateHistoryEntries];
}
- (IBAction)viewQuery:(id)sender
@@ -1583,6 +1590,7 @@
[tableTabView selectTabViewItemAtIndex:2];
[mainToolbar setSelectedItemIdentifier:@"SwitchToRunQueryToolbarItemIdentifier"];
+ [spHistoryControllerInstance updateHistoryEntries];
// Set the focus on the text field if no query has been run
if (![[customQueryTextView string] length]) [tableWindow makeFirstResponder:customQueryTextView];
@@ -1606,6 +1614,7 @@
[tableTabView selectTabViewItemAtIndex:3];
[mainToolbar setSelectedItemIdentifier:@"SwitchToTableInfoToolbarItemIdentifier"];
+ [spHistoryControllerInstance updateHistoryEntries];
}
- (IBAction)viewRelations:(id)sender
@@ -1626,6 +1635,7 @@
[tableTabView selectTabViewItemAtIndex:4];
[mainToolbar setSelectedItemIdentifier:@"SwitchToTableRelationsToolbarItemIdentifier"];
+ [spHistoryControllerInstance updateHistoryEntries];
}
@@ -1751,7 +1761,12 @@
chooseDatabaseToolbarItem = toolbarItem;
[self updateChooseDatabaseToolbarItemWidth];
}
-
+
+ } else if ([itemIdentifier isEqualToString:@"HistoryNavigationToolbarItemIdentifier"]) {
+ [toolbarItem setLabel:NSLocalizedString(@"History", @"toolbar item for navigation history")];
+ [toolbarItem setPaletteLabel:[toolbarItem label]];
+ [toolbarItem setView:historyControl];
+
} else if ([itemIdentifier isEqualToString:@"ToggleConsoleIdentifier"]) {
//set the text label to be displayed in the toolbar and customization palette
[toolbarItem setPaletteLabel:NSLocalizedString(@"Show/Hide Console", @"toolbar item for show/hide console")];
@@ -1847,6 +1862,7 @@
{
return [NSArray arrayWithObjects:
@"DatabaseSelectToolbarItemIdentifier",
+ @"HistoryNavigationToolbarItemIdentifier",
@"ToggleConsoleIdentifier",
@"ClearConsoleIdentifier",
@"FlushPrivilegesIdentifier",
diff --git a/Source/TablesList.h b/Source/TablesList.h
index 68578010..250f451f 100644
--- a/Source/TablesList.h
+++ b/Source/TablesList.h
@@ -25,6 +25,7 @@
#import <Cocoa/Cocoa.h>
#import <MCPKit/MCPKit.h>
+#import "SPHistoryController.h"
enum sp_table_types
{
@@ -54,6 +55,7 @@ enum sp_table_types
IBOutlet id tableDataInstance;
IBOutlet id extendedTableInfoInstance;
IBOutlet id databaseDataInstance;
+ IBOutlet SPHistoryController *spHistoryControllerInstance;
IBOutlet id tableWindow;
IBOutlet id copyTableSheet;
diff --git a/Source/TablesList.m b/Source/TablesList.m
index e5f4a35d..6d611306 100644
--- a/Source/TablesList.m
+++ b/Source/TablesList.m
@@ -1297,6 +1297,8 @@
[tableWindow setTitle:[NSString stringWithFormat:@"(MySQL %@) %@/%@", [tableDocumentInstance mySQLVersion],
[tableDocumentInstance name], [tableDocumentInstance database]]];
}
+
+ [spHistoryControllerInstance updateHistoryEntries];
}
#pragma mark -
diff --git a/sequel-pro.xcodeproj/project.pbxproj b/sequel-pro.xcodeproj/project.pbxproj
index 05809064..37b7a690 100644
--- a/sequel-pro.xcodeproj/project.pbxproj
+++ b/sequel-pro.xcodeproj/project.pbxproj
@@ -141,6 +141,7 @@
588B2CC80FE5641E00EC5FC0 /* ssh-connected.png in Resources */ = {isa = PBXBuildFile; fileRef = 588B2CC50FE5641E00EC5FC0 /* ssh-connected.png */; };
588B2CC90FE5641E00EC5FC0 /* ssh-connecting.png in Resources */ = {isa = PBXBuildFile; fileRef = 588B2CC60FE5641E00EC5FC0 /* ssh-connecting.png */; };
588B2CCA0FE5641E00EC5FC0 /* ssh-disconnected.png in Resources */ = {isa = PBXBuildFile; fileRef = 588B2CC70FE5641E00EC5FC0 /* ssh-disconnected.png */; };
+ 589235321020C1230011DE00 /* SPHistoryController.m in Sources */ = {isa = PBXBuildFile; fileRef = 589235301020C1230011DE00 /* SPHistoryController.m */; };
58C56EF50F438E120035701E /* SPDataCellFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = 58C56EF40F438E120035701E /* SPDataCellFormatter.m */; };
58CB20ED0F79A75D005EA204 /* button_edit_mode_selected.tiff in Resources */ = {isa = PBXBuildFile; fileRef = 58CB20EC0F79A75D005EA204 /* button_edit_mode_selected.tiff */; };
58CDB3300FCE138D00F8ACA3 /* SPSSHTunnel.m in Sources */ = {isa = PBXBuildFile; fileRef = 58CDB32F0FCE138D00F8ACA3 /* SPSSHTunnel.m */; };
@@ -490,6 +491,8 @@
588B2CC50FE5641E00EC5FC0 /* ssh-connected.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "ssh-connected.png"; sourceTree = "<group>"; };
588B2CC60FE5641E00EC5FC0 /* ssh-connecting.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "ssh-connecting.png"; sourceTree = "<group>"; };
588B2CC70FE5641E00EC5FC0 /* ssh-disconnected.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "ssh-disconnected.png"; sourceTree = "<group>"; };
+ 589235301020C1230011DE00 /* SPHistoryController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPHistoryController.m; sourceTree = "<group>"; };
+ 589235311020C1230011DE00 /* SPHistoryController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPHistoryController.h; sourceTree = "<group>"; };
58C56EF30F438E120035701E /* SPDataCellFormatter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPDataCellFormatter.h; sourceTree = "<group>"; };
58C56EF40F438E120035701E /* SPDataCellFormatter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPDataCellFormatter.m; sourceTree = "<group>"; };
58CB20EC0F79A75D005EA204 /* button_edit_mode_selected.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = button_edit_mode_selected.tiff; sourceTree = "<group>"; };
@@ -879,6 +882,8 @@
BC9F0880100FCF2C00A80D32 /* SPFieldEditorController.m */,
17E6414C0EF01EF6001BC333 /* SPGrowlController.h */,
17E6414D0EF01EF6001BC333 /* SPGrowlController.m */,
+ 589235311020C1230011DE00 /* SPHistoryController.h */,
+ 589235301020C1230011DE00 /* SPHistoryController.m */,
B57747D50F7A8978003B34F9 /* SPPreferenceController.h */,
B57747D30F7A8974003B34F9 /* SPPreferenceController.m */,
29A1B7E30FD1293A000B88E8 /* SPPrintAccessory.h */,
@@ -1587,6 +1592,7 @@
58D2E229101222670063EF1D /* SPTextAndLinkCell.m in Sources */,
BC05F1C5101241DF008A97F8 /* AMIndeterminateProgressIndicatorCell.m in Sources */,
584192A1101E57BB0089807F /* NSMutableArray-MultipleSort.m in Sources */,
+ 589235321020C1230011DE00 /* SPHistoryController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};