#UI_ENHANCEMENT by cg
authorClaus Gittinger <cg@exept.de>
Sun, 19 Nov 2017 14:56:06 +0100
changeset 17768 dde98b4c9580
parent 17767 195cf7c7e58f
child 17769 156241c3adef
#UI_ENHANCEMENT by cg class: AbstractFileBrowser class definition can remember the maxFileSize to ask if only part should be shown class: AbstractFileBrowser class added: #maxFileSizeShownWithoutAsking #maxFileSizeShownWithoutAsking: comment/format in: #documentation changed: #contentsOfFileAsDump:base:withLimit:lastPart:characterEncoding:
AbstractFileBrowser.st
--- a/AbstractFileBrowser.st	Sun Nov 19 14:10:32 2017 +0100
+++ b/AbstractFileBrowser.st	Sun Nov 19 14:56:06 2017 +0100
@@ -20,7 +20,7 @@
 		LastFileDiffDirectory LastFileDiffFile LastFileSelection
 		LastMercurialRepository LastMoveDestination LastMustMatchPattern
 		LastScriptBlockString RootHolder RuntimeAspects
-		VisitedDirectories'
+		VisitedDirectories MaxFileSizeShownWithoutAsking'
 	poolDictionaries:''
 	category:'Interface-Tools-File'
 !
@@ -97,6 +97,28 @@
     define stuff which is only needed in some parts makes this hard to understand.
     Especially the fact, that AbstractFileBrowser defines things both as abstract superclass
     and as a container is almost incomprehensable...
+
+    [class variables:]
+        CommandHistory 
+        CommandHistorySize 
+        DefaultCommandPerSuffix
+        DefaultFilters 
+        DirectoryBookmarks 
+        LastEnforcedNameSpace
+        LastFileDiffDirectory 
+        LastFileDiffFile 
+        LastFileSelection
+        LastMercurialRepository 
+        LastMoveDestination 
+        LastMustMatchPattern
+        LastScriptBlockString 
+        RootHolder 
+        RuntimeAspects
+        VisitedDirectories 
+        MaxFileSizeShownWithoutAsking ..... for big files, I will ask if only the first part is
+                                            to be shown. This number (if non-nil) suppresses this
+                                            question for files smaller.
+                                            The initial default is 1Mb (1024*1024)
 "
 ! !
 
@@ -127,6 +149,24 @@
     "Modified: / 21-11-2012 / 08:45:49 / cg"
 !
 
+maxFileSizeShownWithoutAsking
+    "the max. filesize which is loaded without asking if only the first
+     part should be shown"
+     
+    ^ MaxFileSizeShownWithoutAsking ? (1024*1024)
+
+    "Created: / 19-11-2017 / 14:48:19 / cg"
+!
+
+maxFileSizeShownWithoutAsking:anIntegerOrNilForDefault
+    "the max. filesize which is loaded without asking if only the first
+     part should be shown"
+
+    MaxFileSizeShownWithoutAsking := anIntegerOrNilForDefault
+
+    "Created: / 19-11-2017 / 14:48:45 / cg"
+!
+
 resetClassVars
     VisitedDirectories := nil.
     LastFileSelection := nil.
@@ -2973,7 +3013,7 @@
     "opens the file, get its contents and generates a dump for it"
     
     |resources fileName stream data offs 
-     addrDigits lines answer sizeLimit showLastPart|
+     addrDigits lines answer sizeLimit showLastPart setNewLimit thisFileSizeString|
 
     resources := self classResources.
 
@@ -2990,22 +3030,33 @@
         Dialog warn:(resources string:'''%1'' is unreadable.' with:fileName).
         ^ nil
     ].
-    f fileSize > (1024*1024) ifTrue:[
+    f fileSize > (self maxFileSizeShownWithoutAsking) ifTrue:[
         limitOrNil notNil ifTrue:[
             sizeLimit := limitOrNil.
             showLastPart := showLastPartOrNil
         ] ifFalse:[
-            answer := Dialog 
-                            confirmWithCancel:(resources
-                                                stringWithCRs:'"%1" is very large (%2).\\Show all or only the first 4 Mb ?' 
-                                                with:(fileName contractTo:40) allBold 
-                                                with:(UnitConverter fileSizeStringFor:f fileSize))
-                            labels:#('Cancel' 'Show All' 'Show First Part' ).
-
+            setNewLimit := false.
+            thisFileSizeString := (UnitConverter fileSizeStringFor:f fileSize).
+            
+            Dialog 
+                withOptoutOption:[ setNewLimit := true ]
+                labelled:(resources string:'No longer ask for files smaller than %1' with:thisFileSizeString)
+                do:[
+                    answer := Dialog 
+                                    confirmWithCancel:(resources
+                                                        stringWithCRs:'"%1" is very large (%2).\\Show all or only the first 4 Mb ?' 
+                                                        with:(fileName contractTo:40) allBold 
+                                                        with:thisFileSizeString)
+                                    labels:#('Cancel' 'Show All' 'Show First Part' ).
+                ].
             answer isNil ifTrue:[^ nil].
             answer ifTrue:[
                 sizeLimit := 4 * 1024 * 1024
-            ].
+            ] ifFalse:[
+                setNewLimit ifTrue:[
+                    self maxFileSizeShownWithoutAsking:(self maxFileSizeShownWithoutAsking max:f fileSize).
+                ].    
+            ].    
         ].
     ].
 
@@ -3032,6 +3083,7 @@
         characterEncoding:characterEncoding
 
     "Created: / 12-11-2017 / 12:08:10 / cg"
+    "Modified: / 19-11-2017 / 14:54:28 / cg"
 !
 
 contentsOfFileAsHexDump:f