The Trunk: Morphic-tpr.1384.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: Morphic-tpr.1384.mcz

commits-2
tim Rowledge uploaded a new version of Morphic to project The Trunk:
http://source.squeak.org/trunk/Morphic-tpr.1384.mcz

==================== Summary ====================

Name: Morphic-tpr.1384
Author: tpr
Time: 28 December 2017, 12:25:28.683916 pm
UUID: 022f21d5-ede8-4485-8d3e-8f31554aca5d
Ancestors: Morphic-mt.1383

Connect the new file dialogs to assorted image & project load/save methods

=============== Diff against Morphic-mt.1383 ===============

Item was changed:
  ----- Method: ImageMorph>>readFromFile (in category 'menu commands') -----
  readFromFile
+ "This would benefit from a way to get a list of the plausible file extensions for image files"
  | fileName |
  fileName := UIManager default
+ chooseFileMatchingSuffixes: Form allTypicalFileExtensions
+ label: 'Please enter the image file name'.
- request: 'Please enter the image file name'
- initialAnswer: 'fileName'.
  fileName isEmpty ifTrue: [^ self].
+ self image: (Form fromFileNamed:  fileName).
- self image: (Form fromFileNamed: fileName).
  !

Item was changed:
  ----- Method: Morph>>attachToResource (in category 'fileIn/out') -----
  attachToResource
+ "Connect a file -- either a saved .morph file or a graphics file as my resource.
+ There appears to be nothing preventing a user from attaching a completely unrelated file ?"
- "Produce a morph from a file -- either a saved .morph file or a graphics file"
 
  | pathName |
+ pathName := UIManager default chooseFileMatchingSuffixes: (Form allTypicalFileExtensions add: 'morph'; yourself) label: 'Choose a file to load' translated.
- pathName := Utilities chooseFileWithSuffixFromList: (#('.morph'), Utilities graphicsFileSuffixes)
- withCaption: 'Choose a file
- to load'.
  pathName ifNil: [^ self].  "User made no choice"
- pathName == #none ifTrue: [^ self inform:
- 'Sorry, no suitable files found
- (names should end with .morph, .gif,
- .bmp, .jpeg, .jpe, .jp, or .form)'].
 
  self setProperty: #resourceFilePath toValue: pathName!

Item was changed:
  ----- Method: Morph>>exportAsBMP (in category 'menus') -----
  exportAsBMP
  | fName |
+ fName := UIManager default saveFilenameRequest:'Please enter the name' translated initialAnswer: self externalName,'.bmp'.
+ fName ifNil:[^self].
- fName := UIManager default request:'Please enter the name' translated initialAnswer: self externalName,'.bmp'.
- fName isEmpty ifTrue:[^self].
  self exportAsBMPNamed: fName!

Item was changed:
  ----- Method: Morph>>exportAsGIF (in category 'menus') -----
  exportAsGIF
  | fName |
+ fName := UIManager default saveFilenameRequest:'Please enter the name' translated initialAnswer: self externalName,'.gif'.
+ fName ifNil:[^self].
- fName := UIManager default request:'Please enter the name' translated initialAnswer: self externalName,'.gif'.
- fName isEmpty ifTrue:[^self].
  self exportAsGIFNamed: fName!

Item was changed:
  ----- Method: Morph>>exportAsJPEG (in category 'menus') -----
  exportAsJPEG
  | fName |
+ fName := UIManager default saveFilenameRequest: 'Please enter the name' translated initialAnswer: self externalName,'.jpeg'.
+ fName ifNil: [^ self].
- fName := UIManager default request: 'Please enter the name' translated initialAnswer: self externalName,'.jpeg'.
- fName isEmpty ifTrue: [^ self].
  self exportAsJPEGNamed: fName!

Item was changed:
  ----- Method: Morph>>exportAsPNG (in category 'menus') -----
  exportAsPNG
  | fName |
+ fName := UIManager default saveFilenameRequest:'Please enter the name' translated initialAnswer: self externalName,'.png'.
+ fName ifNil:[^self].
- fName := UIManager default request:'Please enter the name' translated initialAnswer: self externalName,'.png'.
- fName isEmpty ifTrue:[^self].
  self exportAsPNGNamed: fName!

Item was changed:
  ----- Method: Morph>>saveOnFile (in category 'fileIn/out') -----
  saveOnFile
  "Ask the user for a filename and save myself on a SmartReferenceStream file.  Writes out the version and class structure.  The file is fileIn-able.  UniClasses will be filed out."
+ | aFileName |
+ aFileName := ('my {1}.morph' translated format: {self class name}) asFileName. "do better?"
+ aFileName := UIManager default saveFilenameRequest: 'File name?' translated
- | aFileName ok |
- aFileName := ('my {1}' translated format: {self class name}) asFileName. "do better?"
- aFileName := UIManager default request: 'File name? (".morph" will be added to end)' translated
  initialAnswer: aFileName.
+ aFileName ifNil: [^ Beeper beep].
+
- aFileName isEmpty ifTrue: [^ Beeper beep].
  self allMorphsDo: [:m | m prepareToBeSaved].
 
- ok := aFileName endsWith: '.morph'. "don't double them"
- ok := ok | (aFileName endsWith: '.sp').
- ok ifFalse: [aFileName := aFileName,'.morph'].
  self saveOnFileNamed: aFileName!

Item was changed:
  ----- Method: PasteUpMorph>>saveOnFile (in category 'objects from disk') -----
  saveOnFile
  "Ask the user for a filename and save myself on a SmartReferenceStream file.  Writes out the version and class structure.  The file is fileIn-able.  UniClasses will be filed out."
 
+ | aFileName fileStream |
- | aFileName fileStream ok |
 
  self flag: #bob0302.
  self isWorldMorph ifTrue: [^self project saveAs].
 
+ aFileName := ('my {1}.project' translated format: {self class name}) asFileName. "do better?"
+ aFileName := UIManager default saveFilenameRequest: 'File name?' translated
- aFileName := ('my {1}' translated format: {self class name}) asFileName. "do better?"
- aFileName := UIManager default request: 'File name? (".project" will be added to end)' translated
  initialAnswer: aFileName.
+ aFileName ifNil: [^ Beeper beep].
- aFileName isEmpty ifTrue: [^ Beeper beep].
  self allMorphsDo: [:m | m prepareToBeSaved].
 
+ fileStream := FileStream newFileNamed: aFileName.
- ok := aFileName endsWith: '.project'. "don't double them"
- ok := ok | (aFileName endsWith: '.sp').
- ok ifFalse: [aFileName := aFileName,'.project'].
- fileStream := FileStream newFileNamed: aFileName asFileName.
  fileStream fileOutClass: nil andObject: self. "Puts UniClass definitions out anyway"!

Item was changed:
  ----- Method: ScorePlayerMorph>>openMIDIFile (in category 'initialization') -----
  openMIDIFile
  "Open a MIDI score and re-init controls..."
  | score fileName f player |
+ fileName := UIManager default chooseFileMatchingSuffixes: #('mid' 'midi') label: 'Choose a MIDI file to open' translated.
+ fileName isNil
+ ifTrue: [^ self ].
+
- fileName := Utilities chooseFileWithSuffixFromList: #('.mid' '.midi')
- withCaption: 'Choose a MIDI file to open' translated.
- (fileName isNil or: [ fileName == #none ])
- ifTrue: [^ self inform: 'No .mid/.midi files found in the Squeak directory' translated].
  f := FileStream readOnlyFileNamed: fileName.
  score := (MIDIFileReader new readMIDIFrom: f binary) asScore.
  f close.
  player := ScorePlayer onScore: score.
  self onScorePlayer: player title: fileName!

Item was changed:
  ----- Method: TextEditor>>saveContentsInFile (in category 'menu messages') -----
  saveContentsInFile
  "Save the receiver's contents string to a file, prompting the user for a file-name.  Suggest a reasonable file-name."
 
  | fileName stringToSave parentWindow labelToUse suggestedName |
  stringToSave := paragraph text string.
  stringToSave size = 0 ifTrue: [^self inform: 'nothing to save.'].
  parentWindow := model dependents
  detect: [:dep | dep isKindOf: SystemWindow]
  ifNone: [nil].
  labelToUse := parentWindow ifNil: ['Untitled']
  ifNotNil: [parentWindow label].
  suggestedName := nil.
  #(#('Decompressed contents of: ' '.gz')) do:
  [:leaderTrailer | | lastIndex |
  "can add more here..."
 
  (labelToUse beginsWith: leaderTrailer first)
  ifTrue:
  [suggestedName := labelToUse copyFrom: leaderTrailer first size + 1
  to: labelToUse size.
  (labelToUse endsWith: leaderTrailer last)
  ifTrue:
  [suggestedName := suggestedName copyFrom: 1
  to: suggestedName size - leaderTrailer last size]
  ifFalse:
  [lastIndex := suggestedName lastIndexOf: $..
  lastIndex > 1
  ifTrue: [suggestedName := suggestedName copyFrom: 1 to: lastIndex - 1]]]].
  suggestedName ifNil: [suggestedName := labelToUse , '.text'].
+ fileName := UIManager default saveFilenameRequest: 'File name?'
- fileName := UIManager default request: 'File name?'
  initialAnswer: suggestedName.
  fileName isEmptyOrNil
  ifFalse:
  [(FileStream newFileNamed: fileName)
  nextPutAll: stringToSave;
  close]!

Item was changed:
  ----- Method: TheWorldMenu>>loadProject (in category 'commands') -----
  loadProject
 
+ | fName |
- | stdFileMenuResult path |
  "Put up a Menu and let the user choose a '.project' file to load.  Create a thumbnail and jump into the project."
 
  Project canWeLoadAProjectNow ifFalse: [^ self].
+ fName := UIManager default chooseFileMatchingSuffixes: #('pr' 'project').
+ fName ifNil:[^nil].
+
+ FileDirectory splitName: fName to:[:dir :file|
+ ProjectLoading
+ openFromDirectory: dir
+ andFileName: file]
- path := FileList2 modalFolderSelector.
- path ifNil: [^ nil].
- stdFileMenuResult := ((StandardFileMenu new) pattern: '*.pr';
- oldFileFrom: path)
- startUpWithCaption: 'Select a File:' translated.
- stdFileMenuResult ifNil: [^ nil].
- ProjectLoading
- openFromDirectory: stdFileMenuResult directory
- andFileName: stdFileMenuResult name
  !

Item was changed:
  ----- Method: TheWorldMenu>>readMorphFromAFile (in category 'commands') -----
  readMorphFromAFile
  "Produce a morph from a file -- either a saved .morph file or a graphics file"
 
  | morphOrList ff aName f m |
+ aName := UIManager default chooseFileMatchingSuffixes: (Form allTypicalFileExtensions add: 'morph'; yourself) label: 'Choose a file to load' translated.
- aName := Utilities chooseFileWithSuffixFromList:
- (#('.morph'), Utilities graphicsFileSuffixes) withCaption: 'Choose a file
- to load' translated.
  aName ifNil: [^ self].  "User made no choice"
- aName == #none ifTrue: [^ self inform:
- 'Sorry, no suitable files found
- (names should end with .morph, .gif,
- .bmp, .jpeg, .jpe, .jp, or .form)' translated].
 
  (aName asLowercase endsWith: '.morph')
  ifTrue:
  [ff := FileStream readOnlyFileNamed: aName.
  morphOrList := ff fileInObjectAndCode. "code filed in is the Model class"
  "the file may contain either a single morph or an array of morphs"
  myWorld addMorphsAndModel: morphOrList]
  ifFalse:
  [f := Form fromFileNamed: aName.
  f ifNil: [^ self error: 'unrecognized image file format' translated].
  m := myWorld drawingClass new form: f.
  myHand attachMorph: m]
  !