[Pharo-users] Using Playgrounds as a notepad

Alexandre Bergel alexandre.bergel at me.com
Tue Jan 5 08:06:23 EST 2016


Useful code snippet! Thanks!

Alexandre


> On Jan 4, 2016, at 10:47 PM, Peter Uhnák <i.uhnak at gmail.com> wrote:
> 
> a) Spec
> 
> ~~~~~~~~~~~
> tm := TextModel new.
> tm autoAccept: true. "otherwise you would have to pres ctrl+s to 'save' the result in memory"
> tm openWithSpec. "this will open text window
> 
> "and then you can do"
> tm text. "retrieve current text from the TextModel (returns an instance of Text)"
> tm text: 'new content' "set a new content"
> ~~~~~~~~~~
> 
> b) Workspace
> 
> ~~~~~~~~~~~~~~~~~~~
> w := Workspace new.
> w open.
> 
> w contents. "note that you must ctrl+s the content in the workspace for it to appear here (there's a yellow triangle in top right corner if the content is not saved"
> w contents: '123'.
> ~~~~~~~~~~~~~~~~~~
> Workspace can also be saved/loaded to disk.
> 
> c) Playground
> 
> ~~~~~~~~~~~~~~~~~~
> (page := GTPlayPage new)
> 	saveContent: 'initial content'.
> (playground := GTPlayground new)
> 	openOn: page.
> 
> page content. "retrieve the content; just like with Workspace you must ctrl+s when editing in the Playground itself"
> 
> "updating is a bit more complex, but it still seems to work"
> page saveContent: 'new content'.
> playground update.
> ~~~~~~~~~~~~~~~~~~~
> 
> Peter
> 
> On Mon, Jan 4, 2016 at 11:51 AM, Sven Van Caekenberghe <sven at stfx.eu> wrote:
> 
> > On 04 Jan 2016, at 07:34, Tudor Girba <tudor at tudorgirba.com> wrote:
> >
> > Hi,
> >
> >> On Jan 4, 2016, at 3:21 AM, Andy Burnett <andy.burnett at knowinnovation.com> wrote:
> >>
> >> I often find that I need to do simple manipulations to passages of text, e.g. remove all carriage returns, or extract email addresses etc.
> >>
> >> Pasting the text into a Playground doesn't work because there is always an apostrophe, or line break or... etc. and the playground complains.
> >>
> >> Is there a way to tell a Playground to just ignore the text, and give me a handle to its contents, so that I can then do something like
> >>
> >> playgroundId contents splitOn:Character space.
> >>
> >> Alternatively, is there another object that would be more appropriate? Playground would be really useful just because it is in the menu, and always available.
> >
> > The Playground does not yet allow you to do that. But, you can use the Clipboard:
> >
> > Clipboard clipboardText splitOn:Character space.
> 
> I do this a lot: using #clipboardText is a way to get to a copied string without any problems.
> 
> You can also do a Print It on 'Clipboard clipboardText asString' which will render the string using the Pharo quoting conventions.
> 
> > Cheers,
> > Doru
> >
> >> Cheers
> >> Andy
> >
> > --
> > www.tudorgirba.com
> > www.feenk.com
> >
> > "Value is always contextual."
> 
> 
> 

-- 
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel  http://www.bergel.eu
^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.







More information about the Pharo-users mailing list