#UI_ENHANCEMENT by cg
authorClaus Gittinger <cg@exept.de>
Sun, 19 Nov 2017 15:02:45 +0100
changeset 17769 156241c3adef
parent 17768 dde98b4c9580
child 17770 2555e5410582
#UI_ENHANCEMENT by cg class: AbstractFileBrowser changed: #fileContentsAsByteArray #openDiffViewOn:and: class: AbstractFileBrowser class comment/format in: #contentsOfFileAsDump:base:withLimit:lastPart:characterEncoding: #maxFileSizeShownWithoutAsking:
AbstractFileBrowser.st
--- a/AbstractFileBrowser.st	Sun Nov 19 14:56:06 2017 +0100
+++ b/AbstractFileBrowser.st	Sun Nov 19 15:02:45 2017 +0100
@@ -160,10 +160,15 @@
 
 maxFileSizeShownWithoutAsking:anIntegerOrNilForDefault
     "the max. filesize which is loaded without asking if only the first
-     part should be shown"
+     part should be shown.
+     Nil resets to the default (currently 1Mb)"
 
     MaxFileSizeShownWithoutAsking := anIntegerOrNilForDefault
 
+    "
+     self maxFileSizeShownWithoutAsking:nil
+    "
+
     "Created: / 19-11-2017 / 14:48:45 / cg"
 !
 
@@ -3051,7 +3056,7 @@
                 ].
             answer isNil ifTrue:[^ nil].
             answer ifTrue:[
-                sizeLimit := 4 * 1024 * 1024
+                sizeLimit := (4 * 1024 * 1024) "max:self maxFileSizeShownWithoutAsking".
             ] ifFalse:[
                 setNewLimit ifTrue:[
                     self maxFileSizeShownWithoutAsking:(self maxFileSizeShownWithoutAsking max:f fileSize).
@@ -3083,7 +3088,7 @@
         characterEncoding:characterEncoding
 
     "Created: / 12-11-2017 / 12:08:10 / cg"
-    "Modified: / 19-11-2017 / 14:54:28 / cg"
+    "Modified: / 19-11-2017 / 15:01:34 / cg"
 !
 
 contentsOfFileAsHexDump:f 
@@ -6928,18 +6933,26 @@
 !
 
 fileContentsAsByteArray
-    |file|
+    |file fileSize|
 
     file := self firstSelectedFile.
     file isNil ifTrue:[^ self ].
-    file asFilename fileSize > (1024*1024) ifTrue:[
-        file asFilename fileSize > (128*1024*1024) ifTrue:[
+
+    file := file asFilename.
+    
+    (fileSize := file fileSize) > (1024*1024) ifTrue:[
+        fileSize > (128*1024*1024) ifTrue:[
             Dialog warn:(resources string:'File is too big').
             ^ self.
         ].
-        (Dialog confirm:(resources string:'File is big - proceed ?')) ifFalse:[^ self].
-    ].
-    file asFilename binaryContentsOfEntireFile inspect
+        (Dialog confirm:(resources 
+                            string:'File is big (%1) - proceed?' 
+                            with:(UnitConverter fileSizeStringFor:fileSize))
+        ) ifFalse:[^ self].
+    ].
+    file binaryContentsOfEntireFile inspect
+
+    "Modified: / 19-11-2017 / 14:58:43 / cg"
 !
 
 fileFileIn
@@ -8026,7 +8039,7 @@
 openDiffViewOn:fileArg1 and:fileArg2
     "open a diff-view on two files"
 
-    |file1 file2 text1 text2 d err nm l1 sameContents msg|
+    |file1 file2 file1Size file2Size text1 text2 d err nm l1 sameContents msg|
 
     file1 := fileArg1.
     file2 := fileArg2.
@@ -8067,9 +8080,11 @@
         ].
 
         self withActivityIndicationDo:[
-            ((file1 notNil and:[file1 fileSize > (1024*1024*32)])
-            or:[ file2 fileSize > (1024*1024*32) ]) ifTrue:[
-                file1 fileSize = file2 fileSize ifTrue:[
+            file1Size := file1 isNil ifTrue:[0] ifFalse:[file1 fileSize].
+            file2Size := file2 isNil ifTrue:[0] ifFalse:[file2 fileSize].
+            
+            ((file1Size > (1024*1024*32)) or:[ file2Size > (1024*1024*32) ]) ifTrue:[
+                file1Size = file2Size ifTrue:[
                     ProgressIndicator
                         displayBusyIndicator:'Comparing...'
                         at:(Screen default center)
@@ -8115,7 +8130,7 @@
         ]
     ]
 
-    "Modified: / 03-05-2012 / 08:03:16 / cg"
+    "Modified: / 19-11-2017 / 15:00:47 / cg"
 !
 
 openDirectoryDiffView