The Trunk: ToolBuilder-Morphic-pre.221.mcz

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

The Trunk: ToolBuilder-Morphic-pre.221.mcz

commits-2
Patrick Rein uploaded a new version of ToolBuilder-Morphic to project The Trunk:
http://source.squeak.org/trunk/ToolBuilder-Morphic-pre.221.mcz

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

Name: ToolBuilder-Morphic-pre.221
Author: pre
Time: 1 November 2018, 2:48:52.569001 pm
UUID: ab161364-1d81-e043-b4d0-eed4c48d03ee
Ancestors: ToolBuilder-Morphic-cmm.220

Refactors the MorphicUIManager to capture and use the ProvideAnswerNotification

=============== Diff against ToolBuilder-Morphic-cmm.220 ===============

Item was changed:
  ----- Method: MorphicUIManager>>chooseDirectory:from: (in category 'ui requests') -----
  chooseDirectory: label from: dir
+ "Let the user choose a file matching the given patterns. Returns a file name."
+ self askForProvidedAnswerTo: label ifSupplied: [:answer |
+ ^ answer].
+
+ ^ DirectoryChooserDialog openOn: dir label: label!
- "Let the user choose a directory"
-
- ^DirectoryChooserDialog openOn: dir label: label!

Item was changed:
  ----- Method: MorphicUIManager>>chooseFileMatching:label: (in category 'ui requests') -----
  chooseFileMatching: patterns label: aString
+ "Let the user choose a file matching the given patterns. Returns a file name."
+ self askForProvidedAnswerTo: aString ifSupplied: [:answer |
+ ^ answer].
+
+ ^ FileChooserDialog openOnPattern: patterns label: aString!
- "Let the user choose a file matching the given patterns"
- | result |
- result := FileChooserDialog openOnPattern: patterns label: aString.
- ^result!

Item was changed:
  ----- Method: MorphicUIManager>>chooseFileMatchingSuffixes:label: (in category 'ui requests') -----
  chooseFileMatchingSuffixes: suffixList label: aString
+ "Let the user choose a file matching the given suffixes. Returns a file name."
+ self askForProvidedAnswerTo: aString ifSupplied: [:answer |
+ ^ answer].
+
+ ^ FileChooserDialog openOnSuffixList: suffixList label: aString.
+ !
- "Let the user choose a file matching the given suffix list"
- | result |
- result := FileChooserDialog openOnSuffixList: suffixList label: aString.
- ^result!

Item was changed:
  ----- Method: MorphicUIManager>>chooseFont:for:setSelector:getSelector: (in category 'ui requests') -----
  chooseFont: titleString for: aModel setSelector: setSelector getSelector: getSelector
  "Open a font-chooser for the given model"
+ self askForProvidedAnswerTo: titleString ifSupplied: [:answer |
+ ^ answer].
+
  ^FontChooserTool default
  openWithWindowTitle: titleString
  for: aModel
  setSelector: setSelector
  getSelector: getSelector!

Item was changed:
  ----- Method: MorphicUIManager>>chooseFrom:lines:title: (in category 'ui requests') -----
  chooseFrom: aList lines: linesArray title: aString
  "Choose an item from the given list. Answer the index of the selected item. Cancel value is 0.
 
  There are several (historical) reasons for building a button dialog instead of a list chooser for small lists:
  1) Unfortunately, there is existing code that uses this call to create simple confirmation dialogs with a list of #(yes no cancel).
  2) Unfortunately, there is existing code that uses this call to mimick a drop-down menu with a (compact) pop-up menu."
+ self askForProvidedAnswerTo: aString ifSupplied: [:answer |
+ (answer = #cancel or: [answer isNil]) ifTrue: [^ 0].
+ ^ aList indexOf: answer].
 
  aList ifEmpty: [^ 0].
  aList size <= 7 ifTrue: [
  | dialog |
  dialog := DialogWindow new
  title: 'Please Choose';
  message: aString;
  filterEnabled: true;
  autoCancel: true; "Like a pop-up menu, click anywhere to dismiss."
  yourself.
  aList doWithIndex: [:ea :index |
  dialog createButton: ea value: index].
  dialog selectedButtonIndex: 1.
  ^ dialog getUserResponseAtHand ifNil: [0]].
 
  ^ ListChooser chooseFrom: aList title: aString!

Item was changed:
  ----- Method: MorphicUIManager>>chooseFrom:values:lines:title: (in category 'ui requests') -----
  chooseFrom: labelList values: valueList lines: linesArray title: aString
  "Choose an item from the given list. Answer the selected item."
 
  | index |
+ self askForProvidedAnswerTo: aString ifSupplied: [:answer |
+ (answer = #cancel or: [answer isNil]) ifTrue: [^ nil].
+ ^ valueList at: (valueList indexOf: answer) ifAbsent: [nil]].
+
  index := self chooseFrom: labelList lines: linesArray title: aString.
  ^ index = 0
  ifTrue: [ nil ]
  ifFalse: [ valueList at: index ]!

Item was changed:
  ----- Method: MorphicUIManager>>chooseFromOrAddTo:lines:title: (in category 'ui requests') -----
  chooseFromOrAddTo: aList lines: linesArray title: aString
 
+ self askForProvidedAnswerTo: aString ifSupplied: [:answer |
+ ^ answer].
+
  ^ ListChooser
  chooseItemFrom: aList
  title: aString
  addAllowed: true!

Item was changed:
  ----- Method: MorphicUIManager>>chooseMultipleFrom:lines:title: (in category 'ui requests') -----
  chooseMultipleFrom: aList lines: linesArray title: aString
  "Choose one or more items from the given list. Answer the indices of the selected items."
 
+ self askForProvidedAnswerTo: aString ifSupplied: [:answer |
+ ^ answer].
+
  ^ ListMultipleChooser
  chooseFrom: aList
  title: aString!

Item was changed:
  ----- Method: MorphicUIManager>>chooseMultipleFrom:values:lines:title: (in category 'ui requests') -----
  chooseMultipleFrom: labelList values: valueList lines: linesArray title: aString
  "Choose one or more items from the given list. Answer the selected items."
 
+ self askForProvidedAnswerTo: aString ifSupplied: [:answer |
+ ^ answer].
+
  ^ (ListMultipleChooser
  chooseFrom: labelList
  title: aString) ifNotNil: [:indexList |
  indexList collect: [:index | valueList at: index]]!

Item was changed:
  ----- Method: MorphicUIManager>>confirm: (in category 'ui requests') -----
  confirm: queryString
  "Put up a yes/no menu with caption queryString. Answer true if the
  response is yes, false if no. This is a modal question--the user must
  respond yes or no."
+ self askForProvidedAnswerTo: queryString ifSupplied: [:answer |
+ ^ answer].
+
+ ^ UserDialogBoxMorph confirm: queryString!
- ^UserDialogBoxMorph confirm: queryString!

Item was changed:
  ----- Method: MorphicUIManager>>confirm:orCancel: (in category 'ui requests') -----
  confirm: aString orCancel: cancelBlock
  "Put up a yes/no/cancel menu with caption aString. Answer true if  
  the response is yes, false if no. If cancel is chosen, evaluate  
  cancelBlock. This is a modal question--the user must respond yes or no."
+ self askForProvidedAnswerTo: aString ifSupplied: [:answer |
+ ^ (answer = #cancel or: [answer isNil])
+ ifTrue: [cancelBlock value]
+ ifFalse: [answer]].
+
+ ^ UserDialogBoxMorph confirm: aString orCancel: cancelBlock!
- ^UserDialogBoxMorph confirm: aString orCancel: cancelBlock!

Item was changed:
  ----- Method: MorphicUIManager>>confirm:orCancel:title: (in category 'ui requests') -----
  confirm: aString orCancel: cancelBlock title: titleString
  "Put up a yes/no/cancel menu with caption aString, and titleString to label the dialog.
  Answer true if  the response is yes, false if no. If cancel is chosen, evaluate cancelBlock.
  This is a modal question--the user must respond yes or no."
+ self askForProvidedAnswerTo: aString ifSupplied: [:answer |
+ ^ (answer = #cancel or: [answer isNil])
+ ifTrue: [cancelBlock value]
+ ifFalse: [answer]].
+
  ^ UserDialogBoxMorph
  confirm: aString
  orCancel: cancelBlock
  title: titleString
  at: nil!

Item was changed:
  ----- Method: MorphicUIManager>>confirm:title: (in category 'ui requests') -----
  confirm: queryString title: titleString
  "Put up a yes/no menu with caption queryString, and titleString to label the dialog.
  Answer true if the response is yes, false if no. This is a modal question--the user
  must respond yes or no."
+ self askForProvidedAnswerTo: queryString ifSupplied: [:answer |
+ ^ answer].
+
+ ^ UserDialogBoxMorph confirm: queryString title: titleString!
- ^UserDialogBoxMorph confirm: queryString title: titleString!

Item was changed:
  ----- Method: MorphicUIManager>>confirm:title:trueChoice:falseChoice: (in category 'ui requests') -----
  confirm: queryString title: titleString trueChoice: trueChoice falseChoice: falseChoice
  "Put up a yes/no menu with caption queryString, and titleString to label the dialog.
  The actual wording for the two choices will be as provided in the trueChoice and
  falseChoice parameters. Answer true if the response is the true-choice, false if it
  is the false-choice. This is a modal question -- the user must respond one way or
  the other."
+ self askForProvidedAnswerTo: queryString ifSupplied: [:answer |
+ ^ answer isBoolean
+ ifTrue: [answer]
+ ifFalse: [trueChoice = answer]].
+
  ^ UserDialogBoxMorph confirm: queryString title: titleString trueChoice: trueChoice falseChoice: falseChoice !

Item was changed:
  ----- Method: MorphicUIManager>>confirm:trueChoice:falseChoice: (in category 'ui requests') -----
  confirm: queryString trueChoice: trueChoice falseChoice: falseChoice
  "Put up a yes/no menu with caption queryString. The actual wording for the two choices will be as provided in the trueChoice and falseChoice parameters. Answer true if the response is the true-choice, false if it's the false-choice.
  This is a modal question -- the user must respond one way or the other."
+ self askForProvidedAnswerTo: queryString ifSupplied: [:answer |
+ ^ answer].
+
  ^ UserDialogBoxMorph confirm: queryString trueChoice: trueChoice falseChoice: falseChoice !

Item was changed:
  ----- Method: MorphicUIManager>>edit:label:accept: (in category 'ui requests') -----
  edit: aText label: labelString accept: anAction
  "Open an editor on the given string/text"
  | window |
  window := Workspace open.
  labelString ifNotNil: [ window setLabel: labelString ].
  "By default, don't style in UIManager edit: requests"
  window model
  shouldStyle: false;
  acceptContents:  aText;
  acceptAction: anAction.
+ ^ window!
- ^window.!

Item was changed:
  ----- Method: MorphicUIManager>>inform: (in category 'ui requests') -----
  inform: aString
  "Display a message for the user to read and then dismiss"
+ self askForProvidedAnswerTo: aString ifSupplied: [:answer |
+ ^ answer].
+
+ ^ UserDialogBoxMorph inform: aString!
- ^UserDialogBoxMorph inform: aString!

Item was changed:
  ----- Method: MorphicUIManager>>multiLineRequest:centerAt:initialAnswer:answerHeight: (in category 'ui requests') -----
  multiLineRequest: queryString centerAt: aPoint initialAnswer: defaultAnswer answerHeight: answerHeight
  "Create a multi-line instance of me whose question is queryString with
  the given initial answer. Invoke it centered at the given point, and
  answer the string the user accepts.  Answer nil if the user cancels.  An
  empty string returned means that the ussr cleared the editing area and
  then hit 'accept'.  Because multiple lines are invited, we ask that the user
  use the ENTER key, or (in morphic anyway) hit the 'accept' button, to
  submit; that way, the return key can be typed to move to the next line."
+ self askForProvidedAnswerTo: queryString ifSupplied: [:answer |
+ ^ answer = #default
+ ifTrue: [defaultAnswer]
+ ifFalse: [answer]].
+
+ ^ FillInTheBlankMorph
- ^FillInTheBlankMorph
  request: queryString
  initialAnswer: defaultAnswer
  centerAt: aPoint
  inWorld: self currentWorld
  onCancelReturn: nil
  acceptOnCR: false!

Item was changed:
  ----- Method: MorphicUIManager>>openDebugger:on:context:label:contents:fullView: (in category 'ui project indirecting') -----
  openDebugger: aDebugger on: process context: context label: title contents: contentsStringOrNil fullView: bool
  "open a debugger - the two versions for mvc & morphic are very close and can surely be merged so that this can be removed"
+ ^ aDebugger morphicOpenOn: process context: context label: title contents: contentsStringOrNil fullView: bool!
- ^aDebugger morphicOpenOn: process context: context label: title contents: contentsStringOrNil fullView: bool!

Item was changed:
  ----- Method: MorphicUIManager>>request:initialAnswer: (in category 'ui requests') -----
  request: queryString initialAnswer: defaultAnswer
  "Create an instance of me whose question is queryString with the given
  initial answer. Invoke it centered at the given point, and answer the
  string the user accepts. Answer the empty string if the user cancels."
+ self askForProvidedAnswerTo: queryString ifSupplied: [:answer |
+ ^ answer = #default
+ ifTrue: [defaultAnswer]
+ ifFalse: [answer]].
+
  ^FillInTheBlankMorph request: queryString initialAnswer: defaultAnswer !

Item was changed:
  ----- Method: MorphicUIManager>>request:initialAnswer:centerAt: (in category 'ui requests') -----
  request: queryString initialAnswer: defaultAnswer centerAt: aPoint
  "Create an instance of me whose question is queryString with the given
  initial answer. Invoke it centered at the given point, and answer the
  string the user accepts. Answer the empty string if the user cancels."
+ self askForProvidedAnswerTo: queryString ifSupplied: [:answer |
+ ^ answer = #default
+ ifTrue: [defaultAnswer]
+ ifFalse: [answer]].
+
+ ^ FillInTheBlankMorph request: queryString initialAnswer: defaultAnswer centerAt: aPoint!
- ^FillInTheBlankMorph request: queryString initialAnswer: defaultAnswer centerAt: aPoint!

Item was changed:
  ----- Method: MorphicUIManager>>requestPassword: (in category 'ui requests') -----
  requestPassword: queryString
  "Create an instance of me whose question is queryString. Invoke it centered
  at the cursor, and answer the string the user accepts. Answer the empty
  string if the user cancels."
+ self askForProvidedAnswerTo: queryString ifSupplied: [:answer |
+ ^ answer].
+
+ ^ FillInTheBlankMorph requestPassword: queryString!
- ^FillInTheBlankMorph requestPassword: queryString!

Item was changed:
  ----- Method: MorphicUIManager>>saveFilenameRequest:initialAnswer: (in category 'ui requests') -----
  saveFilenameRequest: queryString initialAnswer: defaultAnswer
  "Open a FileSaverDialog to ask for a place and filename to use for saving a file. The initial suggestion for the filename is defaultAnswer but the user may choose any existing file or type in a new name entirely"
+ self askForProvidedAnswerTo: queryString ifSupplied: [:answer |
+ ^ answer = #default
+ ifTrue: [defaultAnswer]
+ ifFalse: [answer]].
 
+ ^ FileSaverDialog openOnInitialFilename: defaultAnswer label: queryString
- ^FileSaverDialog openOnInitialFilename: defaultAnswer label: queryString
  !