FileApplicationNoteBook.st
changeset 4969 61bfe248d137
parent 4968 ad8e1bccc254
child 4971 e5c7cd6e0498
--- a/FileApplicationNoteBook.st	Thu Jun 12 14:50:06 2003 +0200
+++ b/FileApplicationNoteBook.st	Thu Jun 12 16:22:50 2003 +0200
@@ -59,8 +59,8 @@
 	instanceVariableNames:'fileContentsModel modifiedChannel editView enableSave
 		enableReload presentation changeItemProcess closeApplication
 		semaChangeItem printAsHexDump itemChanged itemRemoved
-		enableHexToggle textEditorChangeModificationTime md5CheckSum
-		md5HashValueComputationProcess viewModifiedChannel'
+		enableHexToggle md5CheckSum md5HashValueComputationProcess
+		viewModifiedChannel textEditorModificationTime checkModifiedBlock'
 	classVariableNames:''
 	poolDictionaries:''
 	privateIn:FileApplicationNoteBook
@@ -3785,12 +3785,18 @@
 item:aDirContentsItem
 
     (self item = aDirContentsItem and:[(self presentation == #hexDump) == self printAsHexDump value]) ifTrue:[^ true].
-    self stopChangeItemProcess.
     super item:aDirContentsItem.
     self printAsHexDump value:(self presentation == #hexDump) withoutNotifying:self.
     (self askForChange) isNil ifTrue:[ ^ false].
     self setContents ifFalse:[ ^ false].
-    self startChangeItemProcess.
+    checkModifiedBlock isNil ifTrue:[
+        checkModifiedBlock := [
+            self enqueueMessage:#checkItemForChanges 
+                for:self 
+                arguments:nil.
+        ].
+    ].
+    self setupCheckModify.
     ^ true
 !
 
@@ -3821,9 +3827,10 @@
 
 accept
 
-    | dir |
-
-    self masterApplication class openAnotherApplicationOnSameItem ifTrue:[
+    | dir master|
+
+    master := self masterApplication.
+    (master notNil and:[master class openAnotherApplicationOnSameItem]) ifTrue:[
         self updateSameFiles ifFalse:[ ^ self ].
     ].
 
@@ -3831,17 +3838,16 @@
     dir exists not ifTrue:[
         dir recursiveMakeDirectory.
     ].
-    self stopChangeItemProcess.
     editView saveAs:(self fileName).
+    textEditorModificationTime := self fileName modificationTime.
 
     self hasMD5 ifTrue:[
         md5CheckSum := self getHashForContents:self fileContentsModel value.
     ].
     self enableReload value:false.
     self itemChanged value:false.
+    self itemRemoved value:false.
     self modifiedChannel value:false.
-    self startChangeItemProcess.
-    self itemModified.
     self notify:self fileName asString, ' saved'.
 !
 
@@ -3855,11 +3861,11 @@
     self modifiedChannel value ifTrue:[
         self itemChanged value ifTrue:[
             arg := self fileName baseName allBold.
-            string := '%1 was changed by someone else.\Save your changes anyway ?' 
+            string := '%1 was changed by someone else.\Save your changes (overwrite someones changes) ?' 
         ].
         self itemRemoved value ifTrue:[
             arg := self fileName baseName allBold.
-            string := '%1 was removed by someone else.\Save your changes anyway ?' 
+            string := '%1 was removed by someone else.\Save your changes anyway (recreate the removed file) ?' 
         ].
         string isNil ifTrue:[
             arg := self fileName baseName allBold.
@@ -3974,6 +3980,7 @@
 
 reload
 
+    textEditorModificationTime := self fileName modificationTime.
     self setContents.
 !
 
@@ -3999,10 +4006,7 @@
 
 setContentsFor:aText
 
-    self semaChangeItem critical:[
-        textEditorChangeModificationTime := nil.
-        self itemChanged value:false.
-    ].
+    self itemChanged value:false.
     self fileContentsModel value:aText.
     self hasMD5 ifTrue:[
         md5CheckSum := self getHashForContents:aText.
@@ -4153,17 +4157,22 @@
 
 changeTextColorForChanged
 
-    |text|
-
-    text := editView contents asText.
+    |text prevCursorBehavior|
+
+    text := editView contents.
+self halt.
+    prevCursorBehavior := editView cursorMovementWhenUpdating.
+    editView cursorMovementWhenUpdating:nil.
+
     self itemChanged value ifTrue:[
         self fileContentsModel 
-            value:(text emphasizeAllWith:UserPreferences current emphasisForChangedCode).
+            value:(text asText emphasizeAllWith:UserPreferences current emphasisForChangedCode).
         [editView flash] fork.
     ] ifFalse:[
-        self fileContentsModel value:text string asText.
+        self fileContentsModel value:text string.
     ].
-    self fileContentsModel changed:#value.
+    editView cursorMovementWhenUpdating:prevCursorBehavior.
+    "/ self fileContentsModel changed:#value.
 !
 
 itemModified
@@ -4191,58 +4200,43 @@
 !
 
 update:something with:aParameter from:changedObject
-    |modified itemRem contMd5CheckSum viewModified p|
+    |itemRem contMd5CheckSum viewModified p|
 
     changedObject == self viewModifiedChannel ifTrue:[
         viewModified := changedObject value.
         self hasMD5 ifTrue:[
             self viewModifiedChannel value:false withoutNotifying:self.
             viewModified ifTrue:[
-                (self itemRemoved value not and:[self itemChanged value not]) ifTrue:[
-                    (p := md5HashValueComputationProcess) notNil ifTrue:[
-                        p terminate.
-                    ].
-                    md5HashValueComputationProcess := 
-                        [
-                            contMd5CheckSum := self getHashForContents:(editView list).
-                            contMd5CheckSum = md5CheckSum ifTrue:[
-                                self modifiedChannel value:false.
-                            ].
-                            md5HashValueComputationProcess := nil.
-                        ] newProcess.
-                    md5HashValueComputationProcess priority:(Processor userBackgroundPriority).
-                    self modifiedChannel value:viewModified.
-                    md5HashValueComputationProcess resume.
-                    ^ self.
-"/                    contMd5CheckSum := self getHashForContents.
-"/                    contMd5CheckSum = md5CheckSum ifTrue:[
-"/                        self modifiedChannel value:false.
-"/                        ^ self.
-"/                    ].
-                ]
+                (p := md5HashValueComputationProcess) notNil ifTrue:[
+                    p terminate.
+                ].
+                md5HashValueComputationProcess := 
+                    [
+                        contMd5CheckSum := self getHashForContents:(editView list).
+                        self modifiedChannel value:(contMd5CheckSum ~= md5CheckSum).
+                        md5HashValueComputationProcess := nil.
+                    ] newProcess.
+                md5HashValueComputationProcess priority:(Processor userBackgroundPriority).
+                md5HashValueComputationProcess resume.
             ].
-        ].
-        self modifiedChannel value:viewModified.
+        ] ifFalse:[
+            self modifiedChannel value:viewModified.
+        ]
     ].
     changedObject == self modifiedChannel ifTrue:[
-        modified := changedObject value.
-        self hasMD5 not ifTrue:[
-            self viewModifiedChannel value:modified withoutNotifying:self.
-        ].
-        self enableSave value:modified.
+        self enableSave value:changedObject value.
         self itemModified.
         ^ self
     ].
     changedObject == self itemRemoved ifTrue:[
         itemRem := changedObject value.
-        itemRem == true ifTrue:[
-            self enableSave value:true.
-        ].
+        self enableSave value:(itemRem ? false).
         self enableHexToggle value:itemRem not.
         self itemModified.
         ^ self
     ].
     changedObject == self itemChanged ifTrue:[
+        self enqueueMessage:#changeTextColorForChanged for:self arguments:nil.
         self itemModified.
         ^ self
     ].
@@ -4280,7 +4274,7 @@
 
 !FileApplicationNoteBook::TextEditor methodsFor:'privat-process'!
 
-checkMyItemForChanges
+checkItemForChanges
     |dir exist myItem|
 
     dir := self fileName directory.
@@ -4288,65 +4282,24 @@
     exist := myItem exists.
     self itemRemoved value:(exist not).
     exist ifTrue:[
-        self semaChangeItem critical:[
-            |time|
-
-            time := self fileName asAbsoluteFilename modificationTime.
-            textEditorChangeModificationTime isNil ifTrue:[
-                textEditorChangeModificationTime := time.
-            ].
-            ((textEditorChangeModificationTime = time) not) ifTrue:[
-                "/ contents changed by someone else
-                textEditorChangeModificationTime := time.
-                self notify:(resources string:'%1 was changed by someone else.' with:item fileName baseName allBold).
-                self itemChanged value:true.
-            ].
+        |time|
+
+        time := self fileName modificationTime.
+        textEditorModificationTime isNil ifTrue:[
+            textEditorModificationTime := time.
         ].
-    ]
-!
-
-startChangeItemProcess
-
-    changeItemProcess isNil ifTrue:[
-        self itemRemoved value:false.
-        self itemChanged value:false.
-        changeItemProcess := 
-            Process 
-                for:[ 
-                        [   
-                            [true] whileTrue:[
-                                self checkMyItemForChanges.
-                                Delay waitForSeconds:5
-                            ]
-                        ] ensure:[
-                            changeItemProcess := nil.
-                            textEditorChangeModificationTime := nil.
-                        ]
-                ]
-                priority:(Processor systemBackgroundPriority).
-
-        changeItemProcess name:('TextEditorLookForModify[', self fileName baseName, ']').
-        changeItemProcess resume.
+        (textEditorModificationTime ~= time) ifTrue:[
+            "/ contents changed by someone else
+            self notify:(resources string:'%1 was changed by someone else.' with:item fileName baseName allBold).
+            self itemChanged value:true.
+        ].
     ].
-!
-
-stopChangeItemProcess
-
-    | task |
-
-    task := changeItemProcess.
-    task notNil ifTrue:[
-        changeItemProcess := nil.
-
-        Error handle:[:ex|
-            Dialog warn:ex description.
-        ] do:[
-            task isDead ifFalse:[
-                task terminate.
-                task waitUntilTerminated.
-            ]
-        ]
-    ].
+    self setupCheckModify.
+!
+
+setupCheckModify
+
+    Processor addTimedBlock:checkModifiedBlock afterSeconds:3.
 ! !
 
 !FileApplicationNoteBook::TextEditor methodsFor:'queries'!
@@ -4371,7 +4324,6 @@
 
     (self doClose) ifTrue:[
         ^ super closeRequest.
-        ^ self stopChangeItemProcess.
 
     ].
 !
@@ -4399,7 +4351,8 @@
 release
     "release my resources
     "                    
-    self stopChangeItemProcess.
+    Processor removeTimedBlock:checkModifiedBlock.
+    checkModifiedBlock := nil.
     super release.
 !
 
@@ -4909,5 +4862,5 @@
 !FileApplicationNoteBook class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libtool/FileApplicationNoteBook.st,v 1.89 2003-06-12 12:50:06 penk Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/FileApplicationNoteBook.st,v 1.90 2003-06-12 14:22:50 penk Exp $'
 ! !