Polymorph example

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

Polymorph example

laurent laffont
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/
Reply | Threaded
Open this post in threaded view
|

Re: Polymorph example

laurent laffont
Thank you very much Gary

Laurent

On Mon, Jan 24, 2011 at 12:48 PM, Gary Chambers <[hidden email]> 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: [hidden email].
 
 
 
 
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/

Reply | Threaded
Open this post in threaded view
|

Re: Polymorph example

laurent laffont


Laurent Laffont - @lolgzs

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


On Mon, Jan 24, 2011 at 1:45 PM, laurent laffont <[hidden email]> wrote:
Thank you very much Gary

Laurent


On Mon, Jan 24, 2011 at 12:48 PM, Gary Chambers <[hidden email]> 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: [hidden email].
 
 
 
 
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/


Reply | Threaded
Open this post in threaded view
|

Re: Polymorph example

Helene Bilbo
In reply to this post by laurent laffont
Hi,

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

in Pharo 1.1.1 my WorldMenu is broken and a „fallback World Menu“ appears.
"World discoveredWorldMenu“ says that UIThemeWatery2 does not understand smallWindowIcon, that is sent by ContactListEditor class>>menuCommandOn:

How can i fix that?

Best regards,
Helene.
Reply | Threaded
Open this post in threaded view
|

Re: Polymorph example

laurent laffont
The problem is that I've code it in Pharo 1.2 and use UITheme class>>smallWindowIcon to add the menu in ContactListEditor class>>menuCommandOn:

But in Pharo 1.1 UITheme class>>smallWindowIcon doesn't exist  (it's MenuIcon class>>smallWindowIcon).

I've uploaded a new version on SqueakSource which don't use icons + some code refactoring.

Cheers,

Laurent

On Fri, Jan 28, 2011 at 9:27 PM, Helene Bilbo <[hidden email]> wrote:

Hi,

after evaluating:
Gofer it
       squeaksource: 'LaurentLSandbox';
       package: 'AddressBook';
       load.

(Smalltalk at:#ContactListEditor) open.

in Pharo 1.1.1 my WorldMenu is broken and a „fallback World Menu“ appears.
"World discoveredWorldMenu“ says that UIThemeWatery2 does not understand
smallWindowIcon, that is sent by ContactListEditor class>>menuCommandOn:

How can i fix that?

Best regards,
Helene.
--
View this message in context: http://forum.world.st/Polymorph-example-tp3232539p3245311.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.