History management refactored to allow for custom subclasses to customize it.
authorJan Vrany <jan.vrany@fit.cvut.cz>
Fri, 02 May 2014 18:53:02 +0200
changeset 14302 0db4f6f9590f
parent 14301 22794ffaad9c
child 14303 d248c2a4ec3b
History management refactored to allow for custom subclasses to customize it.
Tools__NewSystemBrowser.st
--- a/Tools__NewSystemBrowser.st	Thu May 01 13:00:03 2014 +0200
+++ b/Tools__NewSystemBrowser.st	Fri May 02 18:53:02 2014 +0200
@@ -258,26 +258,14 @@
     "Modified: / 02-06-2011 / 12:01:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
-addToFindHistory:class selector:selector
-    FindHistory := self updateHistory:FindHistory forClass:class selector:selector
-
-    "Created: / 02-07-2011 / 18:12:31 / cg"
-!
-
-addToRecentlyClosedHistory:class selector:selector
-    RecentlyClosedList := self updateHistory:RecentlyClosedList forClass:class selector:selector
-
-    "Created: / 08-09-2012 / 21:07:22 / cg"
-!
-
 bookmarkForClass:aClass selector:aSelectorOrNil
 
-    ^aSelectorOrNil
-        ifNil:[Bookmark forClass: aClass ]
-        ifNotNil:[Bookmark forClass: aClass selector: aSelectorOrNil ]
+    ^aSelectorOrNil isNil
+        ifTrue:[Bookmark forClass: aClass ]
+        ifFalse:[Bookmark forClass: aClass selector: aSelectorOrNil ]
 
     "Created: / 05-05-2011 / 23:36:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 02-06-2011 / 23:21:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 02-05-2014 / 17:34:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 bookmarks
@@ -299,7 +287,7 @@
 !
 
 updateHistory:historyOrNil forClass:class selector:selector
-    |newEntry history|
+    |newEntry history historyToRemove |
 
     newEntry := self historyEntryForClass:class selector:selector.
     newEntry isNil ifTrue:[^ historyOrNil].
@@ -308,12 +296,13 @@
         history := OrderedCollection new.
     ].
 
-    history := history
-                select:[:entry |
+    historyToRemove := history
+                reject:[:entry |
                     entry className ~= newEntry className
                     or:[entry selector ~= newEntry selector
                     or:[entry meta ~= newEntry meta]]
                 ].
+    history removeAll: historyToRemove.
 
     history addFirst:newEntry.
     history size > 30 ifTrue:[
@@ -322,7 +311,7 @@
     ^ history
 
     "Created: / 08-09-2012 / 21:09:19 / cg"
-    "Modified: / 13-09-2012 / 18:14:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 02-05-2014 / 17:45:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !NewSystemBrowser class methodsFor:'defaults'!
@@ -19156,6 +19145,7 @@
 ! !
 
 
+
 !NewSystemBrowser methodsFor:'aspects-organization'!
 
 categoryMenuVisible
@@ -22872,6 +22862,7 @@
     ^ UserPreferences current useSearchBarInBrowser or:[self codeView searchBarActionBlock notNil]
 ! !
 
+
 !NewSystemBrowser methodsFor:'binding access'!
 
 menuFor:key
@@ -24204,6 +24195,12 @@
 
 !NewSystemBrowser methodsFor:'history'!
 
+addToFindHistory:class selector:selector
+    self class updateHistory:self findHistory forClass:class selector:selector
+
+    "Created: / 02-05-2014 / 17:32:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 addToHistory: class
 
     self addToHistory: class selector: nil.
@@ -24218,6 +24215,31 @@
     "Created: / 22-02-2008 / 09:00:56 / janfrog"
     "Modified: / 25-10-2009 / 15:06:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 02-07-2011 / 18:33:22 / cg"
+!
+
+addToRecentlyClosedHistory:class selector:selector     
+    self class updateHistory:self closeHistory forClass:class selector:selector
+
+    "Created: / 02-05-2014 / 17:32:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+closeHistory
+    RecentlyClosedList isNil ifTrue:[ 
+        RecentlyClosedList := OrderedCollection new.
+    ].
+    ^ RecentlyClosedList
+
+    "Created: / 02-05-2014 / 15:58:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 02-05-2014 / 17:30:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+findHistory
+    FindHistory isNil ifTrue:[ 
+        FindHistory := OrderedCollection new.
+    ].
+    ^ FindHistory
+
+    "Created: / 02-05-2014 / 17:29:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !NewSystemBrowser methodsFor:'initialization'!
@@ -48269,6 +48291,7 @@
     "Modified: / 28-02-2012 / 16:48:38 / cg"
 ! !
 
+
 !NewSystemBrowser methodsFor:'menu actions-variables'!
 
 browseVarRefsOrModsWithTitle:browserTitle boxTitle:boxTitle variables:varType access:accessType all:browseAll
@@ -49708,6 +49731,7 @@
     "Modified: / 24-02-2014 / 22:44:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+
 !NewSystemBrowser methodsFor:'menus-dynamic'!
 
 boockmarksMenu
@@ -49810,12 +49834,13 @@
         m addSeparator.
 
         m addItem:((subItem := MenuItem label:(resources string:'Recently Closed')) submenuChannel:#recentlyClosedMenu).
-        RecentlyClosedList isEmptyOrNil ifTrue:[ subItem disable ].
+        self closeHistory isEmptyOrNil ifTrue:[ subItem disable ].
 
         "/ m addItem:((MenuItem label:(resources string:'Other Browsers')) submenuChannel:#otherBrowsersMenu).
-        m addSeparator.
+
 
         bufferNameList notEmptyOrNil ifTrue:[
+            m addSeparator.
             selected := selectedBuffer value.
             bufferNameList keysAndValuesDo:[:idx :nm |
                 |item|
@@ -49834,7 +49859,7 @@
     ].
 
     "Modified: / 09-09-2012 / 20:43:01 / cg"
-    "Modified: / 25-01-2014 / 12:16:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 02-05-2014 / 15:55:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 categoryMenuWithFind
@@ -50982,9 +51007,9 @@
     ^ [
         |m|
 
-        RecentlyClosedList notEmptyOrNil ifTrue:[
+        self closeHistory notEmptyOrNil ifTrue:[
             m := Menu new.
-            RecentlyClosedList do:[:historyEntry |
+            self closeHistory do:[:historyEntry |
                 |item itemLabel|
 
                 itemLabel := self historyMenuItemLabelFor:historyEntry.
@@ -51008,6 +51033,8 @@
         ].
         m
     ].
+
+    "Modified: / 02-05-2014 / 17:49:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 selectedClassesHierarchyMenu
@@ -52577,7 +52604,7 @@
     state := buffers at:nr.
 
     (m := state theSingleSelectedMethod) notNil ifTrue:[
-        self class addToRecentlyClosedHistory:m mclass selector:m selector
+        self addToRecentlyClosedHistory:m mclass selector:m selector
     ].
 
     "/ the buffer before that one
@@ -52614,6 +52641,7 @@
     ]
 
     "Modified: / 08-09-2012 / 21:17:10 / cg"
+    "Modified: / 02-05-2014 / 17:32:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 removeCurrentBuffer
@@ -56247,6 +56275,7 @@
     ^ navigationState projectListApplication
 ! !
 
+
 !NewSystemBrowser methodsFor:'private-history'!
 
 lastSearchPatterns
@@ -56266,11 +56295,12 @@
     cls isNil ifTrue:[
         ^ self
     ].
-    self class addToFindHistory: cls selector: sel.
+    self addToFindHistory: cls selector: sel.
     self addToHistory: cls selector: sel.
 
     "Modified: / 27-02-2008 / 16:54:06 / janfrog"
     "Modified: / 02-07-2011 / 18:29:29 / cg"
+    "Modified: / 02-05-2014 / 17:28:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 rememberSearchPattern:aString
@@ -57032,6 +57062,7 @@
     "Created: / 04-12-2011 / 22:22:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+
 !NewSystemBrowser methodsFor:'private-semantic checks'!
 
 checkAcceptedMethod:aMethod inClass:aClass
@@ -58321,12 +58352,12 @@
             |m|
 
             (m := eachNavigationState theSingleSelectedMethod) notNil ifTrue:[
-                self class addToRecentlyClosedHistory:m mclass selector:m selector
+                self addToRecentlyClosedHistory:m mclass selector:m selector
             ].
         ]
     ] ifFalse:[
         (m := navigationState theSingleSelectedMethod) notNil ifTrue:[
-            self class addToRecentlyClosedHistory:m mclass selector:m selector
+            self addToRecentlyClosedHistory:m mclass selector:m selector
         ].
     ].
 
@@ -58335,6 +58366,7 @@
 
     "Created: / 11-02-2000 / 13:23:00 / cg"
     "Modified: / 09-09-2012 / 10:26:14 / cg"
+    "Modified: / 02-05-2014 / 17:47:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 release
@@ -61489,11 +61521,11 @@
 !NewSystemBrowser class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libtool/Tools__NewSystemBrowser.st,v 1.2063 2014-04-30 18:57:56 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/Tools__NewSystemBrowser.st,v 1.2064 2014-05-02 16:53:02 vrany Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libtool/Tools__NewSystemBrowser.st,v 1.2063 2014-04-30 18:57:56 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/Tools__NewSystemBrowser.st,v 1.2064 2014-05-02 16:53:02 vrany Exp $'
 !
 
 version_HG
@@ -61502,7 +61534,7 @@
 !
 
 version_SVN
-    ^ '$Id: Tools__NewSystemBrowser.st,v 1.2063 2014-04-30 18:57:56 cg Exp $'
+    ^ '$Id: Tools__NewSystemBrowser.st,v 1.2064 2014-05-02 16:53:02 vrany Exp $'
 ! !