Andreas Raab uploaded a new version of Morphic to project The Trunk:
http://source.squeak.org/trunk/Morphic-ar.263.mcz ==================== Summary ==================== Name: Morphic-ar.263 Author: ar Time: 12 December 2009, 1:15:03 am UUID: 33f47745-2771-e445-92e1-63563462cb77 Ancestors: Morphic-HenrikSperreJohansen.262 Adds a modal UserDialogBoxMorph for simple inform: or confirm: dialogs. =============== Diff against Morphic-HenrikSperreJohansen.262 =============== Item was added: + ----- Method: UserDialogBoxMorph>>flash (in category 'events') ----- + flash + "Flash me" + 1 to: 2 do:[:i| + self color: Color black. + self world doOneCycleNow. + (Delay forMilliseconds: 50) wait. + self color: Color white. + self world doOneCycleNow. + (Delay forMilliseconds: 50) wait. + ].! Item was added: + ----- Method: UserDialogBoxMorph>>justDroppedInto:event: (in category 'events') ----- + justDroppedInto: aMorph event: event + "aggressively preserve focus" + event hand newMouseFocus: self.! Item was added: + ----- Method: UserDialogBoxMorph>>mouseDown: (in category 'events') ----- + mouseDown: event + (self containsPoint: event position) ifFalse:[ + Beeper beepPrimitive. + ^self flash]. + event hand grabMorph: self.! Item was added: + ----- Method: UserDialogBoxMorph>>initialize (in category 'initialization') ----- + initialize + | titleRow titleFill | + super initialize. + self color: Color white. + self listDirection: #topToBottom; wrapCentering: #center; + hResizing: #shrinkWrap; vResizing: #shrinkWrap. + self layoutInset: 0@0; cellInset: 5@5. + self borderStyle: BorderStyle thinGray. + self useRoundedCorners; + addDropShadow; + shadowColor: (TranslucentColor r: 0.0 g: 0.0 b: 0.0 alpha: 0.666); + shadowOffset: 1 @ 1. + + titleRow := AlignmentMorph newRow. + titleRow hResizing: #spaceFill; vResizing: #shrinkWrap. + titleRow layoutInset: 2@2. + titleRow color: Preferences menuTitleColor. + titleFill := GradientFillStyle ramp: {0.0 -> Color white. 1 ->Preferences menuTitleColor}. + titleFill radial: false; origin: titleRow topLeft; direction: 0 @ TextStyle defaultFont height. + titleRow fillStyle: titleFill. + + titleMorph := StringMorph new. + titleMorph emphasis: 1. + titleRow addMorph: titleMorph. + labelMorph := TextMorph new. + labelMorph margins: 5@5. + labelMorph lock. + buttonRow := AlignmentMorph newRow vResizing: #shrinkWrap. + buttonRow hResizing: #shrinkWrap; layoutInset: 5@5; cellInset: 5@5. + buttonRow color: Color transparent. + self addMorphBack: titleRow. + self addMorphBack: labelMorph. + self addMorphBack: buttonRow. + self addDropShadow.! Item was added: + ----- Method: UserDialogBoxMorph>>label: (in category 'constructing') ----- + label: aString + "The dialog's label (String)" + labelMorph contents: aString. + ! Item was added: + ----- Method: UserDialogBoxMorph>>label (in category 'constructing') ----- + label + "The dialog's label (String)" + ^labelMorph contents + ! Item was added: + ----- Method: UserDialogBoxMorph class>>confirm:orCancel: (in category 'utilities') ----- + confirm: aString orCancel: cancelBlock + "UserDialogBoxMorph confirm: 'Do you like chocolate?'" + | dialog resp | + dialog := self new. + dialog title: 'Confirmation'. + dialog label: aString. + dialog addButton: ' Yes ' translated value: true. + dialog addButton: ' No ' translated value: false.. + dialog addButton: ' Cancel ' translated value: nil.. + resp := dialog runModalIn: ActiveWorld forHand: ActiveHand. + ^resp ifNil:[cancelBlock value]! Item was added: + ----- Method: UserDialogBoxMorph>>title: (in category 'constructing') ----- + title: aString + titleMorph contents: aString! Item was added: + ----- Method: UserDialogBoxMorph>>title (in category 'constructing') ----- + title + ^titleMorph contents! Item was added: + AlignmentMorph subclass: #UserDialogBoxMorph + instanceVariableNames: 'titleMorph labelMorph buttonRow value' + classVariableNames: '' + poolDictionaries: '' + category: 'Morphic-Windows'! + + !UserDialogBoxMorph commentStamp: 'ar 12/11/2009 22:33' prior: 0! + A DialogBoxMorph is Morph used in simple yes/no/confirm dialogs. Strongly modal.! Item was added: + ----- Method: UserDialogBoxMorph>>closeDialog: (in category 'running') ----- + closeDialog: returnValue + value := returnValue. + self delete.! Item was added: + ----- Method: UserDialogBoxMorph>>addButton:value: (in category 'constructing') ----- + addButton: buttonLabel value: buttonValue + "Adds a button with the given label and value. + The value is returned if the user presses the button." + | button | + button := PluggableButtonMorphPlus new. + button label: buttonLabel. + button action:[self closeDialog: buttonValue]. + button color: Preferences menuColor. + buttonRow addMorphBack: button. + ! Item was added: + ----- Method: UserDialogBoxMorph>>handleFocusEvent: (in category 'constructing') ----- + handleFocusEvent: evt + "Handle focus events. Valid menu transitions are determined based on the menu currently holding the focus after the mouse went down on one of its children." + self processEvent: evt. + + "Need to handle keyboard input if we have the focus." + ^self handleEvent: evt! Item was added: + ----- Method: UserDialogBoxMorph class>>inform: (in category 'utilities') ----- + inform: aString + "UserDialogBoxMorph inform: 'Squeak is great!!'" + ^self inform: aString title: 'Note:'! Item was added: + ----- Method: UserDialogBoxMorph>>mouseUp: (in category 'events') ----- + mouseUp: event + "aggressively preserve focus" + event hand newMouseFocus: self.! Item was added: + ----- Method: UserDialogBoxMorph>>wantsToBeDroppedInto: (in category 'events') ----- + wantsToBeDroppedInto: aMorph + "Return true if it's okay to drop the receiver into aMorph" + ^aMorph isWorldMorph "only into worlds"! Item was added: + ----- Method: UserDialogBoxMorph>>updateFill (in category 'running') ----- + updateFill + | fill | + fill := GradientFillStyle ramp: {0.0 -> Color white. 1 ->Preferences menuColor}. + fill radial: false; + origin: self topLeft; + direction: 0 @ self height. + self fillStyle: fill. + ! Item was added: + ----- Method: UserDialogBoxMorph>>runModalIn:forHand: (in category 'running') ----- + runModalIn: aWorld forHand: aHand + "Ensure that we have a reasonable minimum size" + | oldFocus | + (ProvideAnswerNotification signal: self label) ifNotNil:[:answer| ^answer]. + self openInWorld: aWorld. + self setConstrainedPosition: aHand position - (self fullBounds extent // 2) hangOut: false. + oldFocus := aHand keyboardFocus. + aHand newMouseFocus: self. + aHand newKeyboardFocus: self. + [self isInWorld] whileTrue:[aWorld doOneSubCycle]. + oldFocus ifNotNil:[aHand keyboardFocus: oldFocus]. + ^value! Item was added: + ----- Method: UserDialogBoxMorph class>>confirm:title: (in category 'utilities') ----- + confirm: aString title: titleString + "UserDialogBoxMorph confirm: 'Make your choice carefully' withCRs title: 'Do you like chocolate?'" + | dialog | + dialog := self new. + dialog title: titleString. + dialog label: aString. + dialog addButton: ' Yes ' translated value: true. + dialog addButton: ' No ' translated value: false.. + ^dialog runModalIn: ActiveWorld forHand: ActiveHand! Item was added: + ----- Method: UserDialogBoxMorph class>>confirm: (in category 'utilities') ----- + confirm: aString + "UserDialogBoxMorph confirm: 'Do you like chocolate?'" + ^self confirm: aString title: 'Confirm'! Item was added: + ----- Method: UserDialogBoxMorph class>>inform:title: (in category 'utilities') ----- + inform: aString title: titleString + "UserDialogBoxMorph inform: 'Squeak is great!!' title: 'Will you look at this:'" + | dialog | + dialog := self new. + dialog title: titleString. + dialog label: aString. + dialog addButton: ' OK ' translated value: nil. + ^dialog runModalIn: ActiveWorld forHand: ActiveHand! |
Free forum by Nabble | Edit this page |