Where can I find a use case or concrete example of setting up a service?

Romain Robbes romain.robbes at lu.unisi.ch
Fri Sep 15 07:45:12 UTC 2006


Hi Jerome,

Il giorno Sep 15, 2006, alle ore 7:16 AM, Peace Jerome ha scritto:

> Hi Edgar,
>
> This starts to help.

If you are using Squeak 3.9, the framework has changed, so Edgar's  
approach no longer works.

> I need an example that goes just
> a little slower than this. I need it to start with the
> user story.
>
> Something like...
>
> What I would like to do is:
>
> have a menu item that when I select it does...
>

Let's say your menu item tells you the name of the class which is  
currently selected in your browser, but reversed (this is extremely  
useful):


> it must appear in the ... menu and no others
>

in that case, it can appear in the browser class menu

> it should say...
>
> So to get this to happen using services you do
> this here and
> that there and
> test it by doing x.
>

Supposing this function is needed for your package Foo:
You already have a class named ClassReverser in Foo, with a method:

reverseClass: aClass
	self inform: (aClass name reversed)

To do that with services:

You find this method in a browser, and select the 'create new  
service' in the method menu.
This item asks you for the name of the service. You can call it  
'reverseClass' (without quotes).

Services will create for you a FooServiceProvider class, a method  
category named 'services' in it, and compile the following method for  
you:

reverseClass
	^ ServiceAction
			text: 'you should fill me'
			button: 'fill me'
			description: 'fill me with a longer text'
			action: [:r | "Actual action to to"]
			condition: [:r | "condition to enable/disable the service (must  
return a boolean"]

which you can now modify to have:

reverseClass
	^ ServiceAction
			text: 'reverse class name'
			button: 'reverse'
			description: 'Show the name of the current select class, but  
reversed'
			action: [:r | ClassReverser new reverseClass: r getClass]
			condition: [:r | true]

The argument of the block is an intance of (in this case)  
BrowserRequestor, which implements methods to get information from a  
browser.
You can either enter a fancier condition for the block, or drop the  
last keyword altogether (using only text:button:description:action:).

Now your service is defined, we just have to put it in the right place:

Open the Services Browser (World menu > preferences & services >  
services browser).
You have several categories in the left panel. Since you want to add  
your service to the browser, you can select the 'BrowserProvider'
category.

In it there should be a text field with the caption 'Items in  
browserClassMenu'.
To add you service there, you need to append the name of your service  
to the contents of this field.

'foo bar' -> ''foo bar reverseClass'

changing the order of the items will change the order in the menus.

	Hope it helps,	Romain


> My difficulty is that the service stuff is introducing
> new language to allow me to do what I used to do by
> modifing menu methods. I am having trouble thinking in
> the service language. And I want some way to link what
> I know to what I need to understand.
>
> If you can add the story part to your example I think
> that would help.
>
> Thanks amigo, -- Jer
>
>
>
>
>
>
> --- "Lic. Edgar J. De Cleene"
> <edgardec2001 at yahoo.com.ar> wrote:
>
>> Peace Jerome puso en su mail :
>>
>>> Hi all,
>>>
>>> I just tried to figure out how to use the service
>>> browser and got pretty throughly stumped.
>>>
>
>>> I need something that lets me start of dumb and
>> get
>>> smarter.
>>>
>>> For me a couple of use cases and examples of
>> running
>>> thru the dialogs will probably set me on the right
>>> path. Does anyone know where I can find some?
>>>
>>> Can anyone direct me to useful sources of help?
>>>
>>> Yours in curiosity, -- Jerome Peace
>
>
>> Jerome;
>> This was for SqueakLight, but should be similar in
>> 3.9
>>
>> Adding Services
>> The example is for class MiStack
>>
>>
>> initialize
>> " MiStack initialize"
>> FileList registerFileReader: self.
>>
>>
>> This method should be adecuated to service
>>
>>
>> registeredServices
>>     ^ {
>>     Service new
>>         label: 'Open saved SqueakBook';
>>         shortLabel: 'SqueakBook';
>>         description: 'load back saved notes ';
>>         action: [:stream | self reloadMeFromDisk:
>> ((RWBinaryOrTextStream
>> with: stream contents asString)reset)];
>>         shortcut: nil;
>>         categories: Service worldServiceCat.}
>>
>>
>> This is for in FileList you could select and load
>>
>> fileReaderServicesForFile: fullName suffix: suffix
>>     | services |
>>     services _ OrderedCollection new.
>>
>>     (fullName asLowercase endsWith: '.shc')
>>         ifTrue: [ services add: self
>> serviceLoadSqueakBook ].
>>     ^services
>>
>>
>>
>> serviceLoadSqueakBook
>> "Answer a service for opening a saved SqueakBook"
>>
>>     ^ (SimpleServiceEntry
>>         provider: self
>>         label: 'saved SqueakBook'
>>         selector: #reloadMeFromDisk:
>>         description: 'open a SqueakBook'
>>         buttonLabel: 'SqueakBook')
>>         argumentGetter: [:fileList | fileList
>> readOnlyStream]
>>
>>
>> Hope this helps.
>>
>> Edgar
>>
>>
>>
>> 	
>> 	
>> 		
>> __________________________________________________
>> Preguntá. Respondé. Descubrí.
>> Todo lo que querías saber, y lo que ni imaginabas,
>> está en Yahoo! Respuestas (Beta).
>> ¡Probalo ya!
>> http://www.yahoo.com.ar/respuestas
>>
>>
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>

--
Romain Robbes
http://romain.robb.es



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20060915/254e62d1/attachment.htm


More information about the Squeak-dev mailing list