Thank you very much Gary

Laurent

On Mon, Jan 24, 2011 at 12:48 PM, Gary Chambers <gazzaguru2@btinternet.com> wrote:
Hi,
��
just a few observations ;-)
��
The openModal might be better like this (so the text fields align nicely):
��
openModal
��|builder dialog content firstName|
��
��builder := UITheme builder.
��content := (builder newLabelGroup: {
����'First name' -> (firstName := (builder
������newTextEntryFor: contact getText: #firstName setText: #firstName: help: 'Enter the first name of the contact')
������acceptOnCR: false;
������minWidth: 200).
����'Last name' -> ((builder
������newTextEntryFor: contact getText: #lastName setText: #lastName: help: 'Enter the last name of the contact')
������acceptOnCR: false;
������minWidth: 200).
��}).
��
��dialog := builder newPluggableDialogWindow:'Edit contact' for: content.
��dialog rememberKeyboardFocus: firstName.
��builder openModal: dialog.
��
��dialog cancelled ifFalse: [self doOnOK].
��
��
The #useDefaultOKButton was redundant (since model was set before sending (the #for: bit)).
Resetting the model after chosing the buttons would work though. That's why you get the default
OK/Cancel (rather than the single OK you would have had via #useDefaultOKButton).
Disabling the acceptOnCR for each text frield allows the default dialog handling for the return key (defaults to OK).
Normally the initial keyboard focus for a dialog is the default button, if specified. Remembering the first name field
prior to opening will give that field focus.
��
��
It might be nice to use the enablement feature for the buttons on the main contact list:
��
��
contactSelectedIndex
��^ selectedContactIndex ifNil: [selectedContactIndex := 0]
��
��
��
contactSelectedIndex: aSmallInteger
��
��selectedContactIndex := aSmallInteger.
��self
����changed: #contactSelectedIndex;
����changed: #hasSelectedContact
��
��
��
hasSelectedContact
��
��^selectedContactIndex > 0
��
��
addButtonClick
��|newContact|
��newContact := Contact new.
��
��ContactEditor new
����contact: newContact;
����onOK: [��Contact database add: newContact.
��������self changed: #contacts.
��������self contactSelectedIndex: Contact database size ];
����openModal
��
��
removeButtonClick
��
��[Contact database removeAt: selectedContactIndex]
����on: Error
����do: [UITheme builder alert: 'Cannot remove selected contact.'].
��self
����contactSelectedIndex: (self contactSelectedIndex min: Contact database size);
����changed: #contacts
��
��
��
open
|builder content|
builder := UITheme builder.
content := builder newColumn: {����
��builder
����newListFor: self����
����list: #contacts
����selected: #contactSelectedIndex
����changeSelected: #contactSelectedIndex:
����help: 'contacts'.
��builder newRow: {
����builder newButtonFor: self action: #addButtonClick label: 'Add' help: 'Create a new contact'.
����builder newButtonFor: self action: #removeButtonClick getEnabled: #hasSelectedContact label: 'Remove' help: 'Remove selected contact'.
����builder newButtonFor: self action: #editButtonClick getEnabled: #hasSelectedContact label: 'Edit' help: 'Edit selected contact'�� }}.
����
(content openInWindowLabeled: 'Contacts') extent: 400@500.
��
��
��
��
Nice example. Good luck.

Regards, Gary
----- Original Message -----
Sent: Sunday, January 23, 2011 1:39 PM
Subject: Polymorph example

Hi,

I've written a tiny little application to prepare a screencast on Polymorph / GUI. As I'm far from being expert on this, can someone check that it is done "the right way" ��(especially on how to manage OK/Cancel ) ?��

Gofer it
squeaksource: 'LaurentLSandbox';
package: 'AddressBook';
load.
(Smalltalk at:#ContactListEditor) open.


Thanks.


Laurent Laffont -��@lolgzs

Pharo Smalltalk Screencasts: http://www.pharocasts.com/
Blog: http://magaloma.blogspot.com/