Christoph Thiede uploaded a new version of Tools to project The Trunk:
http://source.squeak.org/trunk/Tools-ct.1211.mcz
==================== Summary ====================
Name: Tools-ct.1211
Author: ct
Time: 1 June 2023, 8:26:54.735263 pm
UUID: 0b71a9d8-b26d-854e-83ae-89d560db27a4
Ancestors: Tools-ct.1210
Proposal: In truncated file lists, inserts a link for reading the entire file. More observable than the context menu. Uses color and emphasis for highlighting the truncation message.
=============== Diff against Tools-ct.1210 ===============
Item was added:
+ ----- Method: FileList>>decorateTruncatedText:size:limit: (in category 'private') -----
+ decorateTruncatedText: truncatedText size: size limit: limit
+
+ | args |
+ args := {
+ fileName. size. limit.
+ 'Click here' translated asText
+ addAttribute: (PluggableTextAttribute evalBlock: [self get]);
+ addAttribute: TextEmphasis bold;
+ yourself }.
+ ^ Text streamContents: [:stream |
+ stream withAttributes: {TextColor red. TextEmphasis italic} do: [
+ stream nextPutAll: ('File ''{1}'' is {2} bytes long.
+ {4} to read the entire file.
+
+ Here are the first {3} characters...
+ ------------------------------------------
+ ' translated
+ asText format: args)].
+ stream nextPutAll: truncatedText.
+ stream withAttributes: {TextColor red. TextEmphasis italic} do: [
+ stream nextPutAll: ('
+ ------------------------------------------
+ ... end of the first {3} characters.
+ {4} to read the entire file.' translated
+ asText format: args)]]!
Item was changed:
----- Method: FileList>>readContentsBrief: (in category 'private') -----
readContentsBrief: brevityFlag
"Read the contents of the receiver's selected file, unless it is too long, in which case show just the first 5000 characters. Don't create a file if it doesn't already exist."
| f fileSize first5000 |
brevityFlag ifTrue: [
directory isRemoteDirectory ifTrue: [^ self readServerBrief]].
f := directory oldFileOrNoneNamed: self fullName.
f ifNil: [^ 'For some reason, this file cannot be read' translated].
self setDefaultEncoderFor: f.
(brevityFlag not or: [(fileSize := f size) <= 100000]) ifTrue:
+ [brevityState := #fullFile. "don't change till actually read"
+ ^ contents := f contentsOfEntireFile].
- [contents := f contentsOfEntireFile.
- brevityState := #fullFile. "don't change till actually read"
- ^ contents].
"if brevityFlag is true, don't display long files when first selected"
first5000 := f next: 5000.
f close.
- contents := 'File ''{1}'' is {2} bytes long.
- You may use the ''get'' command to read the entire file.
-
- Here are the first 5000 characters...
- ------------------------------------------
- {3}
- ------------------------------------------
- ... end of the first 5000 characters.' translated format: {fileName. fileSize. first5000}.
brevityState := #briefFile. "don't change till actually read"
+ ^ contents := self decorateTruncatedText: first5000 size: fileSize limit: 5000!
- ^ contents.
- !
Item was changed:
----- Method: FileList>>readContentsHex: (in category 'private') -----
readContentsHex: brevity
"retrieve the contents from the external file unless it is too long.
Don't create a file here. Check if exists."
| f size data hexData s |
f := directory oldFileOrNoneNamed: self fullName.
f == nil ifTrue: [^ 'For some reason, this file cannot be read' translated].
f binary.
((size := f size)) > 5000 & brevity
ifTrue: [data := f next: 10000. f close. brevityState := #briefHex]
ifFalse: [data := f contentsOfEntireFile. brevityState := #fullHex].
s := WriteStream on: (String new: data size*4).
0 to: data size-1 by: 16 do:
[:loc | s nextPutAll: loc printStringHex; space;
nextPut: $(; print: loc; nextPut: $); space; tab.
loc+1 to: (loc+16 min: data size) do: [:i | s nextPutAll: (data at: i) printStringHex; space].
s cr].
hexData := s contents.
+ (brevity not or: [size <= 5000]) ifTrue: [
+ ^ contents := hexData].
+
+ ^ contents := self decorateTruncatedText: hexData size: size limit: 5000!
- ^ contents := ((size > 5000) & brevity
- ifTrue: ['File ''{1}'' is {2} bytes long.
- You may use the ''get'' command to read the entire file.
-
- Here are the first 5000 characters...
- ------------------------------------------
- {3}
- ------------------------------------------
- ... end of the first 5000 characters.' translated format: {fileName. size. hexData}]
- ifFalse: [hexData]).
- !
Item was changed:
----- Method: FileList>>readServerBrief (in category 'private') -----
readServerBrief
+ | lString sizeStr fsize ff first3500 parts |
- | lString sizeStr fsize ff first5000 parts |
"If file on server is known to be long, just read the beginning. Cheat badly by reading the fileList string."
listIndex = 0 ifTrue: [^ self].
"Get size from file list entry"
lString := list at: listIndex.
parts := lString findTokens: '()'.
sortMode = #name ifTrue: [sizeStr := (parts second findTokens: ' ') third].
sortMode = #date ifTrue: [sizeStr := (parts first findTokens: ' ') third].
sortMode = #size ifTrue: [sizeStr := (parts first findTokens: ' ') first].
fsize := (sizeStr copyWithout: $,) asNumber.
fsize <= 50000 ifTrue:
[ff := directory oldFileOrNoneNamed: self fullName.
ff ifNil: [^ 'For some reason, this file cannot be read' translated].
contents := ff contentsOfEntireFile.
brevityState := #fullFile. "don't change till actually read"
^ contents].
"if brevityFlag is true, don't display long files when first selected"
+ first3500 := directory getOnly: 3500 from: fileName.
- first5000 := directory getOnly: 3500 from: fileName.
- contents := 'File ''{1}'' is {2} bytes long.
- You may use the ''get'' command to read the entire file.
-
- Here are the first 3500 characters...
- ------------------------------------------
- {3}
- ------------------------------------------
- ... end of the first 3500 characters.' translated format: {fileName. sizeStr. first5000}.
brevityState := #briefFile. "don't change till actually read"
+ ^ contents := self decorateTruncatedText: first3500 size: sizeStr limit: 3500!
- ^ contents.
-
- !
Christoph Thiede uploaded a new version of Tools to project The Trunk:
http://source.squeak.org/trunk/Tools-ct.1213.mcz
==================== Summary ====================
Name: Tools-ct.1213
Author: ct
Time: 2 June 2023, 6:27:04.95093 pm
UUID: 69d99752-1b0c-144f-96ed-57336ae8b8bd
Ancestors: Tools-mt.1211, Tools-ct.1211
Merges Tools-ct.1211 (FileList link and emphasis for truncation).
Revision:
Reuses the style from code comments for the truncation message.
=============== Diff against Tools-mt.1211 ===============
Item was added:
+ ----- Method: FileList>>decorateTruncatedText:size:limit: (in category 'private') -----
+ decorateTruncatedText: truncatedText size: size limit: limit
+
+ | attribs args |
+ attribs := ((((self userInterfaceTheme get: #comment for: #SHTextStylerST80) ifNil: [#()])
+ collect: [:ea | ea isColor ifTrue: [TextColor color: ea] ifFalse: [ea]])
+ ifEmpty: [{TextColor color: Color cyan muchDarker}])
+ copyWith: TextEmphasis italic.
+ args := {
+ fileName. size. limit.
+ 'Click here' translated asText
+ addAttribute: (PluggableTextAttribute evalBlock: [self get]);
+ addAttribute: TextEmphasis bold;
+ yourself }.
+ ^ Text streamContents: [:stream |
+ stream withAttributes: attribs do: [
+ stream nextPutAll: ('File ''{1}'' is {2} bytes long.
+ {4} to read the entire file.
+
+ Here are the first {3} characters...
+ ------------------------------------------
+ ' translated
+ asText format: args)].
+ stream nextPutAll: truncatedText.
+ stream withAttributes: attribs do: [
+ stream nextPutAll: ('
+ ------------------------------------------
+ ... end of the first {3} characters.
+ {4} to read the entire file.' translated
+ asText format: args)]]!
Item was changed:
----- Method: FileList>>readContentsBrief: (in category 'private') -----
readContentsBrief: brevityFlag
"Read the contents of the receiver's selected file, unless it is too long, in which case show just the first 5000 characters. Don't create a file if it doesn't already exist."
| f fileSize first5000 |
brevityFlag ifTrue: [
directory isRemoteDirectory ifTrue: [^ self readServerBrief]].
f := directory oldFileOrNoneNamed: self fullName.
f ifNil: [^ 'For some reason, this file cannot be read' translated].
self setDefaultEncoderFor: f.
(brevityFlag not or: [(fileSize := f size) <= 100000]) ifTrue:
+ [brevityState := #fullFile. "don't change till actually read"
+ ^ contents := f contentsOfEntireFile].
- [contents := f contentsOfEntireFile.
- brevityState := #fullFile. "don't change till actually read"
- ^ contents].
"if brevityFlag is true, don't display long files when first selected"
first5000 := f next: 5000.
f close.
- contents := 'File ''{1}'' is {2} bytes long.
- You may use the ''get'' command to read the entire file.
-
- Here are the first 5000 characters...
- ------------------------------------------
- {3}
- ------------------------------------------
- ... end of the first 5000 characters.' translated format: {fileName. fileSize. first5000}.
brevityState := #briefFile. "don't change till actually read"
+ ^ contents := self decorateTruncatedText: first5000 size: fileSize limit: 5000!
- ^ contents.
- !
Item was changed:
----- Method: FileList>>readContentsHex: (in category 'private') -----
readContentsHex: brevity
"retrieve the contents from the external file unless it is too long.
Don't create a file here. Check if exists."
| f size data hexData s |
f := directory oldFileOrNoneNamed: self fullName.
f == nil ifTrue: [^ 'For some reason, this file cannot be read' translated].
f binary.
((size := f size)) > 5000 & brevity
ifTrue: [data := f next: 10000. f close. brevityState := #briefHex]
ifFalse: [data := f contentsOfEntireFile. brevityState := #fullHex].
s := WriteStream on: (String new: data size*4).
0 to: data size-1 by: 16 do:
[:loc | s nextPutAll: loc printStringHex; space;
nextPut: $(; print: loc; nextPut: $); space; tab.
loc+1 to: (loc+16 min: data size) do: [:i | s nextPutAll: (data at: i) printStringHex; space].
s cr].
hexData := s contents.
+ (brevity not or: [size <= 5000]) ifTrue: [
+ ^ contents := hexData].
+
+ ^ contents := self decorateTruncatedText: hexData size: size limit: 5000!
- ^ contents := ((size > 5000) & brevity
- ifTrue: ['File ''{1}'' is {2} bytes long.
- You may use the ''get'' command to read the entire file.
-
- Here are the first 5000 characters...
- ------------------------------------------
- {3}
- ------------------------------------------
- ... end of the first 5000 characters.' translated format: {fileName. size. hexData}]
- ifFalse: [hexData]).
- !
Item was changed:
----- Method: FileList>>readServerBrief (in category 'private') -----
readServerBrief
+ | lString sizeStr fsize ff first3500 parts |
- | lString sizeStr fsize ff first5000 parts |
"If file on server is known to be long, just read the beginning. Cheat badly by reading the fileList string."
listIndex = 0 ifTrue: [^ self].
"Get size from file list entry"
lString := list at: listIndex.
parts := lString findTokens: '()'.
sortMode = #name ifTrue: [sizeStr := (parts second findTokens: ' ') third].
sortMode = #date ifTrue: [sizeStr := (parts first findTokens: ' ') third].
sortMode = #size ifTrue: [sizeStr := (parts first findTokens: ' ') first].
fsize := (sizeStr copyWithout: $,) asNumber.
fsize <= 50000 ifTrue:
[ff := directory oldFileOrNoneNamed: self fullName.
ff ifNil: [^ 'For some reason, this file cannot be read' translated].
contents := ff contentsOfEntireFile.
brevityState := #fullFile. "don't change till actually read"
^ contents].
"if brevityFlag is true, don't display long files when first selected"
+ first3500 := directory getOnly: 3500 from: fileName.
- first5000 := directory getOnly: 3500 from: fileName.
- contents := 'File ''{1}'' is {2} bytes long.
- You may use the ''get'' command to read the entire file.
-
- Here are the first 3500 characters...
- ------------------------------------------
- {3}
- ------------------------------------------
- ... end of the first 3500 characters.' translated format: {fileName. sizeStr. first5000}.
brevityState := #briefFile. "don't change till actually read"
+ ^ contents := self decorateTruncatedText: first3500 size: sizeStr limit: 3500!
- ^ contents.
-
- !