'From Squeak3.5 of ''11 April 2003'' [latest update: #5180] on 11 May 2003 at 10:31:32 pm'! "Change Set: KCP-0068-Imports Date: 11 May 2003 Author: stephane ducasse Introduce a class that stores and collect imported images and others data. Fix also some dirts: deprecate Dictionary>>inspectFormsWithLabel: and define a better creation interface in GraphicalDictionaryMenu and FormInspectView."! Object subclass: #Imports instanceVariableNames: 'imports ' classVariableNames: '' poolDictionaries: '' category: 'System-Support'! !Imports commentStamp: 'sd 5/11/2003 20:34' prior: 0! I represent imported resources such as images, sounds, and other kind of files. For now I only store images in a simple way. To access my default instance use: Imports default. However I'm not a strict singleton and clients may create several of me using new. ! !BitmapFillStyle methodsFor: 'Morphic menu' stamp: 'sd 5/11/2003 22:18'! chooseNewGraphicIn: aMorph event: evt "Used by any morph that can be represented by a graphic" | reasonableForms aGraphicalMenu myGraphic | reasonableForms _ (SketchMorph allSubInstances collect: [:m | m form]) asOrderedCollection. reasonableForms addAll: Imports default images. reasonableForms addAll: (BitmapFillStyle allSubInstances collect:[:f| f form]). reasonableForms _ reasonableForms asSet asOrderedCollection. (reasonableForms includes: (myGraphic _ self form)) ifTrue: [reasonableForms remove: myGraphic]. reasonableForms addFirst: myGraphic. aGraphicalMenu _ GraphicalMenu new initializeFor: self withForms: reasonableForms coexist: true. aGraphicalMenu selector: #newForm:forMorph:; argument: aMorph. evt hand attachMorph: aGraphicalMenu.! ! !Dictionary methodsFor: 'deprecated' stamp: 'sd 5/11/2003 21:44'! inspectFormsWithLabel: aLabel self deprecated: [self inspectFormsWithLabel: aLabel] explanation: 'Use GraphicalDictionaryMenu>>openOn:withLabel in Morphic or FormInspectView>>openOn:withLabel: in MVC'! ! !Dictionary methodsFor: 'deprecated' stamp: 'sd 5/11/2003 21:37'! inspectFormsWithLabelDeprecated: aLabel "Open a Form Dictionary inspector on the receiver, with the given label." | viewClass aList aGraphicalMenu | self couldOpenInMorphic ifTrue: [aList _ self collect: [:f | f]. aList isEmpty ifTrue: [^ self inform: 'Empty!!']. aGraphicalMenu _ GraphicalDictionaryMenu new initializeFor: nil fromDictionary: self. ^ HandMorph attach: (aGraphicalMenu wrappedInWindowWithTitle: aLabel)]. viewClass _ PluggableTextView. Smalltalk at: #FormInspectView ifPresent: [:formInspectView | viewClass _ formInspectView]. ^ DictionaryInspector openOn: self withEvalPane: true withLabel: aLabel valueViewClass: viewClass! ! !FileList2 methodsFor: 'as yet unclassified' stamp: 'sd 5/11/2003 22:15'! importImage "Import the given image file and store the resulting Form in the default Imports" | fname image | fname _ fileName sansPeriodSuffix. image _ Form fromFileNamed: self fullName. Imports default importImage: image named: fname. ! ! !Form class methodsFor: 'fileIn/Out' stamp: 'sd 5/11/2003 22:17'! importImage: fullName "Import the given image file and store the resulting Form in the default Imports the image is named with the short filename up to the first period." | image | image _ Form fromFileNamed: fullName. Imports default importImage: image named: (FileDirectory localNameFor: fullName) sansPeriodSuffix ! ! !FormInspectView class methodsFor: 'instance creation' stamp: 'sd 5/11/2003 21:36'! openOn: aFormDictionary withLabel: aLabel "open a graphical dictionary in a window having the label aLabel. aFormDictionary should be a dictionary containing as value a form." ^ DictionaryInspector openOn: aFormDictionary withEvalPane: true withLabel: aLabel valueViewClass: self! ! !Imports methodsFor: 'initialize' stamp: 'sd 5/11/2003 18:17'! initialize imports := Dictionary new.! ! !Imports methodsFor: 'images' stamp: 'sd 5/11/2003 20:36'! images "returns all the imported images" ^ imports values ! ! !Imports methodsFor: 'images' stamp: 'sd 5/11/2003 21:51'! importImage: anImage named: aName imports at: aName put: anImage ! ! !Imports methodsFor: 'images' stamp: 'sd 5/11/2003 22:26'! namesAndImagesDo: aBlock "iterate over all the names and image" ^ imports keysAndValuesDo: aBlock ! ! !Imports methodsFor: 'images' stamp: 'sd 5/11/2003 22:21'! viewImages "Open up a special Form inspector on the dictionary of graphical imports." "Imports default viewImages" | widgetClass | imports size isZero ifTrue: [^ self inform: 'The ImageImports repository is currently empty, so there is nothing to view at this time. You can use a file list to import graphics from external files into Imports, and once you have done that, you will find this command more interesting.']. widgetClass := self couldOpenInMorphic ifTrue: [GraphicalDictionaryMenu] ifFalse: [FormInspectView]. widgetClass openOn: imports withLabel: 'Graphical Imports' ! ! !Imports class methodsFor: 'instance creation' stamp: 'sd 5/11/2003 18:16'! default default isNil ifTrue: [ default := self new]. ^ default! ! !Imports class methodsFor: 'instance creation' stamp: 'sd 5/11/2003 18:16'! new ^ super new initialize! ! !Morph methodsFor: 'menus' stamp: 'sd 5/11/2003 22:17'! chooseNewGraphicCoexisting: aBoolean "Allow the user to choose a different form for her form-based morph" | reasonableForms replacee aGraphicalMenu myGraphic | reasonableForms _ (SketchMorph allInstances select: [:m | ((m owner isKindOf: SketchEditorMorph) or: [m owner isKindOf: IconicButton]) not] thenCollect: [:m | m form]) asSet "eliminate duplicates" asOrderedCollection. reasonableForms addAll: Imports default images. reasonableForms _ reasonableForms asSet asOrderedCollection. (reasonableForms includes: (myGraphic _ self form)) ifTrue: [reasonableForms remove: myGraphic]. reasonableForms addFirst: myGraphic. aGraphicalMenu _ GraphicalMenu new initializeFor: self withForms: reasonableForms coexist: aBoolean. aBoolean ifFalse: [replacee _ self topRendererOrSelf. replacee owner replaceSubmorph: replacee by: aGraphicalMenu] ifTrue: [self primaryHand attachMorph: aGraphicalMenu]! ! !GraphicalDictionaryMenu class methodsFor: 'example' stamp: 'sd 5/11/2003 20:53'! example "GraphicalDictionaryMenu example" | aDict | aDict _ Dictionary new. #('ColorTilesOff' 'ColorTilesOn' 'Controls') do: [:aString | aDict at: aString put: (ScriptingSystem formAtKey: aString)]. self openOn: aDict withLabel: 'Testing One Two Three'! ! !GraphicalDictionaryMenu class methodsFor: 'example' stamp: 'sd 5/11/2003 20:56'! example2 "GraphicalDictionaryMenu example2" | aDict | aDict _ Dictionary new. self openOn: aDict withLabel: 'Testing Zero'! ! !GraphicalDictionaryMenu class methodsFor: 'instance creation' stamp: 'sd 5/11/2003 20:58'! openOn: aFormDictionary withLabel: aLabel "open a graphical dictionary in a window having the label aLabel. aFormDictionary should be a dictionary containing as value a form." | inst | aFormDictionary size isZero ifTrue: [^ self inform: 'Empty!!']. inst := self new initializeFor: nil fromDictionary: aFormDictionary. HandMorph attach: (inst wrappedInWindowWithTitle: aLabel). ^ inst! ! !ScreenController methodsFor: 'menu messages' stamp: 'sd 5/11/2003 22:04'! viewImageImports "Open an inspector on forms imported from Image files." Imports default viewImages! ! !StandardScriptingSystem methodsFor: 'form dictionary' stamp: 'sd 5/11/2003 21:32'! inspectFormDictionary "ScriptingSystem inspectFormDictionary" GraphicalDictionaryMenu openOn: FormDictionary withLabel: 'Testing One Two Three'! ! !EToySystem class methodsFor: 'development support' stamp: 'sd 5/11/2003 22:13'! loadJanForms "EToySystem loadJanForms" | aReferenceStream newFormDict | aReferenceStream _ ReferenceStream fileNamed: 'JanForms'. newFormDict _ aReferenceStream next. aReferenceStream close. newFormDict associationsDo: [:assoc | Imports default importImage: assoc value named: assoc key]! ! !SystemDictionary methodsFor: 'deprecated' stamp: 'sd 5/11/2003 20:04'! imageImports ^ self deprecated: [self imageImportsDeprecated] explanation: 'You should use the following expression Imports default images to get all the imported images' ! ! !SystemDictionary methodsFor: 'deprecated' stamp: 'sd 5/11/2003 20:02'! imageImportsDeprecated "Answer the global dictionary of image imports, creating it if necessary. 7/24/96 sw" "Smalltalk viewImageImports" (self includesKey: #ImageImports) ifFalse: [self at: #ImageImports put: Dictionary new]. ^ self at: #ImageImports! ! !SystemDictionary methodsFor: 'deprecated' stamp: 'sd 5/11/2003 19:53'! viewImageImports self deprecated: [self viewImageImportsDeprecated] explanation: 'Use instead the Imports default viewImage'! ! !SystemDictionary methodsFor: 'deprecated' stamp: 'sd 5/11/2003 19:52'! viewImageImportsDeprecated | imageImports | "Open up a special Form inspector on the dictionary of graphical imports." (imageImports _ self imageImports) size == 0 ifTrue: [^ self inform: 'The ImageImports repository is currently empty, so there is nothing to view at this time. You can use a file list to import graphics from external files into ImageImports, and once you have done that, you will find this command more interesting.']. imageImports inspectFormsWithLabel: 'Graphical Imports'! ! !TheWorldMenu methodsFor: 'construction' stamp: 'sd 5/11/2003 22:07'! helpMenu "Build the help menu for the world." | screenCtrl genieEnabledString | screenCtrl _ ScreenController new. genieEnabledString _ World currentHand isGenieEnabled ifTrue: ['disable'] ifFalse: ['enable']. ^ self fillIn: (self menu: 'help...') from: { {'about this system...'. {Smalltalk. #aboutThisSystem}. 'current version information.'}. {'update code from server'. {Utilities. #updateFromServer}. 'load latest code updates via the internet'}. {'preferences...'. {Preferences. #openPreferencesInspector}. 'view and change various options.'}. {'set language...' . {Project. #chooseNaturalLanguage}. 'choose the language in which tiles should be displayed.'} . nil. {genieEnabledString , ' genie'. {World currentHand. #switchGenieEnabled}. genieEnabledString , ' gesture recognizer for the world''s current hand'}. {'genie gesture dictionaries'. {CRDictionary. #openInstanceBrowserMorph}. 'edit or inspect gesture dictionaries'.}. {'choose genie text dictionary'. {CRDictionary. #chooseTextDictionary}. 'select the dictionary used for text input'.}. {'genie display properties'. {CRDisplayProperties. #openInstanceBrowserMorph}. 'edit or inspect display properies'.}. nil. {'command-key help'. { Utilities . #openCommandKeyHelp}. 'summary of keyboard shortcuts.'}. {'world menu help'. { self . #worldMenuHelp}. 'helps find menu items buried in submenus.'}. "{'info about flaps' . { Utilities . #explainFlaps}. 'describes how to enable and use flaps.'}." {'font size summary' . { Utilities . #fontSizeSummary}. 'summary of names and sizes of available fonts.'}. {'useful expressions' . { Utilities . #openStandardWorkspace}. 'a window full of useful expressions.'}. {'annotation setup...' . { Preferences . #editAnnotations}. 'Click here to get a little window that will allow you to specify which types of annotations, in which order, you wish to see in the annotation panes of browsers and other tools'}. nil. {'graphical imports' . { Imports default . #viewImages}. 'view the global repository called ImageImports; you can easily import external graphics into ImageImports via the FileList'}. {'standard graphics library' . { ScriptingSystem . #inspectFormDictionary}. 'lets you view and change the system''s standard library of graphics.'}. nil. {'telemorphic...' . {self. #remoteDo}. 'commands for doing multi-machine "telemorphic" experiments'}. {#soundEnablingString . { Preferences . #toggleSoundEnabling}. 'turning sound off will completely disable Squeak''s use of sound.'}. {'definition for...' . { Utilities . #lookUpDefinition}. 'if connected to the internet, use this to look up the definition of an English word.'}. nil. {'set author initials...' . { screenCtrl . #setAuthorInitials }. 'supply initials to be used to identify the author of code and other content.'}. {'vm statistics' . { screenCtrl . #vmStatistics}. 'obtain some intriguing data about the vm.'}. nil. {'purge undo records' . { CommandHistory . #resetAllHistory }. 'save space by removing all the undo information remembered in all projects.'}. {'space left' . { screenCtrl . #garbageCollect}. 'perform a full garbage-collection and report how many bytes of space remain in the image.'}. } ! !