share goodRenameDefault code with FileOperation
authorClaus Gittinger <cg@exept.de>
Fri, 11 Oct 2002 15:38:13 +0200
changeset 3976 0da3f9c89ecc
parent 3975 dcaac82381dc
child 3977 52e9db551c1a
share goodRenameDefault code with FileOperation
FileBrowser.st
--- a/FileBrowser.st	Fri Oct 11 15:37:52 2002 +0200
+++ b/FileBrowser.st	Fri Oct 11 15:38:13 2002 +0200
@@ -372,6 +372,79 @@
     "Modified: 15.8.1997 / 15:27:19 / cg"
 ! !
 
+!FileBrowser class methodsFor:'fileList user interaction'!
+
+goodRenameDefaultFor:oldName lastOld:lastOldName lastNew:lastNewName
+    |prefix suffix lastNewSize lastOldSize t
+     lastOldWOSuffix lastNewWOSuffix oldWOSuffix lastOldRest oldRest lastNewRest
+     lastRemoved lastInserted|
+
+    lastNewName isNil ifTrue:[ ^ nil].
+
+    lastNewSize := lastNewName size.
+    lastOldSize := lastOldName size.
+
+    "/ intelligent default ...
+    (lastNewName endsWith:lastOldName) ifTrue:[
+        prefix := lastNewName copyTo:(lastNewSize - lastOldSize).
+        ^ (prefix , oldName).
+    ].
+    (lastOldName endsWith:lastNewName) ifTrue:[
+        prefix := lastOldName copyTo:(lastOldSize - lastNewSize).
+        ^ (oldName copyFrom:prefix size+1).
+    ].
+    (lastOldName withoutSeparators = lastNewName) ifTrue:[
+        "/ intelligent default ...
+        ^ oldName withoutSeparators.
+    ].
+    (lastNewName startsWith:lastOldName) ifTrue:[
+        "/ intelligent default ...
+        suffix := lastNewName copyLast:(lastNewSize - lastOldSize).
+        ^ (oldName , suffix).
+    ].
+    (lastOldName startsWith:lastNewName) ifTrue:[
+        suffix := lastOldName copyLast:(lastOldSize - lastNewSize).
+        (oldName endsWith:suffix) ifTrue:[
+            ^ (oldName copyWithoutLast:suffix size).
+        ]
+    ].
+
+    lastOldWOSuffix := lastOldName asFilename withoutSuffix name.
+    lastNewWOSuffix := lastNewName asFilename withoutSuffix name.
+    oldWOSuffix := oldName asFilename withoutSuffix name.
+
+    prefix := lastOldWOSuffix commonPrefixWith:oldWOSuffix.
+    (lastNewWOSuffix startsWith:prefix) ifTrue:[
+        lastOldRest := lastOldWOSuffix copyFrom:prefix size + 1.
+        lastNewRest := lastNewWOSuffix copyFrom:prefix size + 1.
+        oldRest := oldWOSuffix copyFrom:prefix size + 1.
+
+        (lastNewRest endsWith:lastOldRest) ifTrue:[
+            t := lastNewRest copyWithoutLast:lastOldRest size.
+            ^ ((prefix , t , oldRest) asFilename withSuffix:oldName asFilename suffix) name
+        ].
+    ].
+
+    suffix := lastOldWOSuffix commonSuffixWith:lastNewWOSuffix.
+    suffix size > 0 ifTrue:[
+        "/ last change changed something at the beginning
+        prefix := oldWOSuffix commonPrefixWith:lastOldWOSuffix.
+        prefix size > 0 ifTrue:[
+            "/ this name starts with the same characters
+            lastRemoved := lastOldWOSuffix copyWithoutLast:suffix size.
+            lastInserted := lastNewWOSuffix copyWithoutLast:suffix size.
+            (lastRemoved startsWith:lastInserted) ifTrue:[
+                oldWOSuffix size >= lastInserted size ifTrue:[
+                    ^ (oldWOSuffix copyTo:lastInserted size) , (oldName copyFrom:lastRemoved size + 1)
+                ]
+            ].
+            ^ lastInserted , (oldName copyFrom:lastRemoved size + 1)
+        ].
+    ].
+
+    ^ nil
+! !
+
 !FileBrowser class methodsFor:'history'!
 
 addToCommandHistory:aCommandString for:aFilename
@@ -3368,19 +3441,19 @@
 
     self selectedFilesDo:[:oldName |
         queryBox title:(resources string:'Rename ''%1'' to:' with:oldName).
-        initialText := oldName.
 
         lastNewName notNil ifTrue:[
             "/ intelligent default ...
-            initialText := self goodRenameDefaultFor:oldName lastOld:lastOldName lastNew:lastNewName
+            initialText := self class goodRenameDefaultFor:oldName lastOld:lastOldName lastNew:lastNewName
         ].
         queryBox initialText:(initialText ? oldName).
-        queryBox action:[:newName | 
-                            fileListView removeFromSelection:(fileList indexOf:oldName).
-                            self doRename:oldName to:newName. 
-                            lastOldName := oldName.
-                            lastNewName := newName.
-                        ].
+        queryBox 
+            action:[:newName | 
+                fileListView removeFromSelection:(fileList indexOf:oldName).
+                self doRename:oldName to:newName. 
+                lastOldName := oldName.
+                lastNewName := newName.
+            ].
     
         queryBox showAtPointer
     ]
@@ -3434,72 +3507,6 @@
     "Modified: 18.9.1997 / 16:32:39 / stefan"
 !
 
-goodRenameDefaultFor:oldName lastOld:lastOldName lastNew:lastNewName
-    |prefix suffix lastNewSize lastOldSize t
-     lastOldWOSuffix lastNewWOSuffix oldWOSuffix lastOldRest oldRest lastNewRest
-     lastRemoved lastInserted|
-
-    lastNewName isNil ifTrue:[ ^ nil].
-
-    lastNewSize := lastNewName size.
-    lastOldSize := lastOldName size.
-
-    "/ intelligent default ...
-    (lastNewName endsWith:lastOldName) ifTrue:[
-        prefix := lastNewName copyTo:(lastNewSize - lastOldSize).
-        ^ (prefix , oldName).
-    ].
-    (lastOldName endsWith:lastNewName) ifTrue:[
-        prefix := lastOldName copyTo:(lastOldSize - lastNewSize).
-        ^ (oldName copyFrom:prefix size+1).
-    ].
-    (lastOldName withoutSeparators = lastNewName) ifTrue:[
-        "/ intelligent default ...
-        ^ oldName withoutSeparators.
-    ].
-    (lastNewName startsWith:lastOldName) ifTrue:[
-        "/ intelligent default ...
-        suffix := lastNewName copyLast:(lastNewSize - lastOldSize).
-        ^ (oldName , suffix).
-    ].
-    (lastOldName startsWith:lastNewName) ifTrue:[
-        suffix := lastOldName copyLast:(lastOldSize - lastNewSize).
-        (oldName endsWith:suffix) ifTrue:[
-            ^ (oldName copyWithoutLast:suffix size).
-        ]
-    ].
-
-    lastOldWOSuffix := lastOldName asFilename withoutSuffix name.
-    lastNewWOSuffix := lastNewName asFilename withoutSuffix name.
-    oldWOSuffix := oldName asFilename withoutSuffix name.
-
-    prefix := lastOldWOSuffix commonPrefixWith:oldWOSuffix.
-    (lastNewWOSuffix startsWith:prefix) ifTrue:[
-        lastOldRest := lastOldWOSuffix copyFrom:prefix size + 1.
-        lastNewRest := lastNewWOSuffix copyFrom:prefix size + 1.
-        oldRest := oldWOSuffix copyFrom:prefix size + 1.
-
-        (lastNewRest endsWith:lastOldRest) ifTrue:[
-            t := lastNewRest copyWithoutLast:lastOldRest size.
-            ^ ((prefix , t , oldRest) asFilename withSuffix:oldName asFilename suffix) name
-        ].
-    ].
-
-    suffix := lastOldWOSuffix commonSuffixWith:lastNewWOSuffix.
-    suffix size > 0 ifTrue:[
-        "/ last change changed something at the beginning
-        prefix := oldWOSuffix commonPrefixWith:lastOldWOSuffix.
-        prefix size > 0 ifTrue:[
-            "/ this name starts with the same characters
-            lastRemoved := lastOldWOSuffix copyWithoutLast:suffix size.
-            lastInserted := lastNewWOSuffix copyWithoutLast:suffix size.
-            ^ lastInserted , (oldName copyFrom:lastRemoved size + 1)
-        ].
-    ].
-
-    ^ nil
-!
-
 hasSlideShow
     ^ [CodingExamples_GUI::SlideShow notNil]
 
@@ -8113,5 +8120,5 @@
 !FileBrowser class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libtool/FileBrowser.st,v 1.508 2002-10-08 19:25:50 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/FileBrowser.st,v 1.509 2002-10-11 13:38:13 cg Exp $'
 ! !