'From etoys3.0 of 7 March 2008 [latest update: #2138] on 9 September 2008 at 4:48:32 pm'! "Change Set: chooser-bf Date: 9 September 2008 Author: Bert Freudenberg Enable Find button in Sugar, bringing up the Journal's object chooser"! !ProjectNavigationMorph methodsFor: 'as yet unclassified' stamp: 'bf 9/9/2008 16:10'! showMenuFor: aSymbol event: evt (#(publishProject publishProjectSimple) includes: aSymbol) ifTrue: [ self doPublishButtonMenuEvent: evt. ^true "we did show the menu" ]. (#(findAProject findAProjectSimple chooseObject) includes: aSymbol) ifTrue: [ self doFindButtonMenuEvent: evt. ^true "we did show the menu" ]. (aSymbol == #stopSqueak) ifTrue: [ self doStopButtonMenuEvent: evt. ^true "we did show the menu" ]. ^false ! ! !SugarJournal methodsFor: 'org.laptop.Journal' stamp: 'bf 9/9/2008 13:25'! onObjectChooserCancelledSend: aSelector to: anObject "Automatically generated" ^self onDBusSignal: 'ObjectChooserCancelled' interface: 'org.laptop.Journal' signature: 's' send: aSelector to: anObject! ! !SugarJournal methodsFor: 'org.laptop.Journal' stamp: 'bf 9/9/2008 13:25'! onObjectChooserResponseSend: aSelector to: anObject "Automatically generated" ^self onDBusSignal: 'ObjectChooserResponse' interface: 'org.laptop.Journal' signature: 'ss' send: aSelector to: anObject! ! !SugarJournal methodsFor: 'matching' stamp: 'bf 9/9/2008 14:48'! onObjectChooserCancelled: chooserId send: aSelector to: anObject ^self onDBusSignal: 'ObjectChooserCancelled' interface: 'org.laptop.Journal' arguments: {0 -> chooserId} send: aSelector to: anObject! ! !SugarJournal methodsFor: 'matching' stamp: 'bf 9/9/2008 14:48'! onObjectChooserResponse: chooserId send: aSelector to: anObject ^self onDBusSignal: 'ObjectChooserResponse' interface: 'org.laptop.Journal' arguments: {0 -> chooserId} send: aSelector to: anObject! ! !SugarLauncher methodsFor: 'accessing' stamp: 'bf 9/9/2008 13:30'! journal ^SugarJournal new ! ! !SugarLauncher methodsFor: 'datastore' stamp: 'bf 9/9/2008 15:20'! handleStream: tmpStream mimetype: mimetype titled: title "tmpStream was loaded from journal, is not a project, do something sensible" "this ignores the mimetype, we really should do better ..." [ [(ExternalDropHandler lookupExternalDropHandler: tmpStream) handle: tmpStream in: World dropEvent: ActiveHand lastEvent] ifError: [self inform: ('Cannot open {1}' translated withCRs format: {title})] ] ensure: [tmpStream ifNotNil: [tmpStream close]].! ! !SugarLauncher methodsFor: 'datastore' stamp: 'bf 9/9/2008 13:45'! resumeJournalEntry: id | props file title project mimetype | props := self dataStore getProperties: id. title := (props at: 'title' ifAbsent: ['untitled' translated]) utf8ToSqueak. mimetype := props at: 'mime_type' ifAbsent: ['']. mimetype isEmpty ifTrue: [^self welcome: '']. mimetype = 'application/x-squeak-project' ifFalse: [ "Do not modify original non-project journal entry when later saving this project" parameters removeKey: 'OBJECT_ID' ifAbsent: []. "reuse drop code" WorldState addDeferredUIMessage: [ self open: id title: title mimetype: mimetype]. ^Project enterNew]. ProjectLoading showProgressBarDuring: [ Display fillWhite;forceToScreen. file := self getFile: id. "load project and close temp file (which will thus be deleted)" project := ProjectLoading loadName: ((title copyReplaceAll: '/' with: '\') contractTo: 64) stream: file fromDirectory: nil withProjectView: nil. file close. project name: title. project projectParameterAt: #sugarAutoSave put: true. project enter]. ! ! !SugarLauncher methodsFor: 'chooser' stamp: 'bf 9/9/2008 14:42'! chooseObject | chooserId | chooserId := self journal chooseObject: 0. self journal onObjectChooserResponse: chooserId send: #chooser:response: to: self; onObjectChooserCancelled: chooserId send: #chooserDone: to: self! ! !SugarLauncher methodsFor: 'chooser' stamp: 'bf 9/9/2008 14:41'! chooserDone: chooserId self journal onObjectChooserResponse: chooserId send: nil to: self; onObjectChooserCancelled: chooserId send: nil to: self! ! !SugarLauncher methodsFor: 'chooser' stamp: 'bf 9/9/2008 14:50'! chooser: chooserId response: objectId self chooserDone: chooserId. WorldState addDeferredUIMessage: [ | props title mimetype | props := self dataStore getProperties: objectId. title := (props at: 'title' ifAbsent: ['untitled' translated]) utf8ToSqueak. mimetype := props at: 'mime_type' ifAbsent: ['']. self open: objectId title: title mimetype: mimetype].! ! !SugarLauncher methodsFor: 'chooser' stamp: 'bf 9/9/2008 13:44'! open: id title: titleString mimetype: mimeString | file | ActiveHand lastEvent position: World center. Utilities informUser: 'Opening journal entry' translated, String cr, (titleString copyReplaceAll: String lf with: String cr) during: [file := self getFile: id]. self handleStream: file mimetype: mimeString titled: titleString.! ! !SugarLibrary class methodsFor: 'singleton management' stamp: 'bf 9/9/2008 16:42'! newDefault "Answer a new instance of SugarLibrary." | i | i _ SugarLibrary new. "i loadFrom: (FileDirectory on: 'C:\tmp\SugarEtoysIcon\SugarEtoysIcon\32x32')." i iconAt: 'new' put: self newIcon. i iconAt: 'prev' put: self prevIcon. i iconAt: 'next' put: self nextIcon. i iconAt: 'save' put: self saveIcon. i iconAt: 'open' put: self openIcon. i iconAt: 'paint' put: self paintIcon. i iconAt: 'language' put: self languageIcon. i iconAt: 'undo' put: self undoIcon. i iconAt: 'close' put: self closeIcon. i iconAt: 'share' put: self shareIcon. i iconAt: 'miniShare' put: self miniShareIcon. i iconAt: 'supplies' put: self suppliesIcon. i iconAt: 'stop' put: self stopIcon. i iconAt: 'zoom' put: self zoomIcon. i iconAt: 'help' put: self helpIcon. i iconAt: 'miniPrivate' put: self miniPrivateIcon. i iconAt: 'private' put: self privateIcon. i iconAt: 'newProject' put: (i iconAt: 'new'). i iconAt: 'previousProject' put: (i iconAt: 'prev'). i iconAt: 'nextProject' put: (i iconAt: 'next'). i iconAt: 'publishProject' put: (i iconAt: 'save'). i iconAt: 'findAProjectSimple' put: (i iconAt: 'open'). i iconAt: 'chooseObject' put: (i iconAt: 'open'). i iconAt: 'doNewPainting' put: (i iconAt: 'paint'). i iconAt: 'chooseLanguage' put: (i iconAt: 'language'). i iconAt: 'undoOrRedoLastCommand' put: (i iconAt: 'undo'). i iconAt: 'toggleSupplies' put: (i iconAt: 'supplies'). i iconAt: 'quitSqueak' put: (i iconAt: 'close'). i iconAt: 'shareThisWorld' put: (i iconAt: 'share'). i iconAt: 'shareMenu' put: (i iconAt: 'private'). i iconAt: 'chooseScreenSetting' put: (i iconAt: 'zoom'). i iconAt: 'stopSqueak' put: (i iconAt: 'stop'). i iconAt: 'toggleHelp' put: (i iconAt: 'help'). ^ i ! ! !SugarNavigatorBar methodsFor: 'initialization' stamp: 'bf 9/9/2008 16:34'! findButtonAppearance findButton ifNotNil: [ | wasSugar isSugar oldButton | wasSugar := findButton actionSelector = #chooseObject. isSugar := SugarLauncher isRunningInSugar. wasSugar = isSugar ifFalse: [ oldButton := findButton. findButton := isSugar ifTrue: [self buttonChoose] ifFalse: [self buttonFind]. oldButton owner replaceSubmorph: oldButton by: findButton]].! ! !SugarNavigatorBar methodsFor: 'buttons creation' stamp: 'bf 9/9/2008 16:05'! buttonChoose "Answer a button for choosing objects from the Journal" ^ self makeButton: 'FIND' translated balloonText: 'Click here to find an entry in the Journal. Hold down this button to reveal additional options.' translated for: #chooseObject ! ! !SugarNavigatorBar methodsFor: 'button actions' stamp: 'bf 9/9/2008 16:05'! chooseObject SugarLauncher current chooseObject! ! "Postscript:" SugarLibrary clearDefault. SugarNavigatorBar allInstancesDo: [:b | b sugarLib: SugarLibrary default]. !