Page 1 of 2
Gadget pane
Posted: Tue Apr 16, 2019 2:43 pm
by dunbarx
I have a utility library stack always in use. One of the handlers resident there is:
Code: Select all
function makePlainText tText
repeat for each char tChar in tText
put numToChar(charToNum(tChar)) after temp
end repeat
return temp
end makePlainText
It is useful when I need to strip all styles and properties from whatever I have copied to the clipBoard. I invoke it with a keyboard shortcut.
That is not the point. Might it be fun and useful to have a new pane ("Interesting Handlers"?) to showcase small gadgetry like this, more accessible than the "Sample Stacks" arena.
Just a thought...
Craig
Re: Gadget pane
Posted: Tue Apr 16, 2019 2:56 pm
by dunbarx
It just occurs to me, after reading the handler after decades of using it, that this:
Code: Select all
function makePlainText tText
repeat for each char tChar in tText
put tChar after temp
end repeat
return temp
end makePlainText
works just as well.
Oh well.
Craig
Re: Gadget pane
Posted: Tue Apr 16, 2019 4:27 pm
by jacque
Or, off the top of my head,
Code: Select all
set the clipboardData["styledText"] to empty
Re: Gadget pane
Posted: Tue Apr 16, 2019 5:13 pm
by dunbarx
Jacque.
Adorable. It turns out that we do not even need that:
Code: Select all
set the clipBoardData to the clipBoardData
But my gadget, or its excesses, wasn't the point. A cute community handler pane...
Craig
Re: Gadget pane
Posted: Tue Apr 16, 2019 5:27 pm
by Klaus
Question is:
What exactly are you passing to the function?
How do you pass STYLED text?

Re: Gadget pane
Posted: Wed Apr 17, 2019 2:16 am
by dunbarx
Klaus.
Not sure what you mean. If I copy some styled text from a web page, and paste it into a text field somewhere, the styles and properties are preserved.
Oftentimes I only want the "raw" text. No colors, no changes in textSize or fonts. Apparently there are several ways (see posts above) to change the clipBoardData into raw text. That was only an example, though if it engenders a new thread, great.
Nobody wants to talk about a gadget pane. (Sob).
Craig
Re: Gadget pane
Posted: Wed Apr 17, 2019 2:37 am
by FourthWorld
...should return only the plain text.
Re: Gadget pane
Posted: Wed Apr 17, 2019 2:38 am
by dunbarx
Ah,
A fourth way to do it.
Ah.
Sob...
Re: Gadget pane
Posted: Wed Apr 17, 2019 3:52 am
by FourthWorld
With the first example, makePlainText, under what circumstances does the return value differ from the input?
Re: Gadget pane
Posted: Wed Apr 17, 2019 4:39 am
by dunbarx
Richard, and Klaus, I guess.
Any of the offerings, mine and others, will transform styled and property-laden text into "raw" text. The text I am speaking of is of the sort one gets when, say, one copies something from, say, a web page with lots of, er, styled text.
When one copies that text into, say, a LC field, all that style is preserved. Great.
I very often find transforming that styled text into simple raw text very useful.
Hey, I hate to change the subject, but I have an idea. Why don't we think about a new pane where cute, short utility gadgets can be posted? I bet that would be fun and instructive.
Sob...
Craig
Re: Gadget pane
Posted: Wed Apr 17, 2019 4:47 am
by FourthWorld
dunbarx wrote: ↑Wed Apr 17, 2019 4:39 am
Richard, and Klaus, I guess.
Any of the offerings, mine and others, will transform styled and property-laden text into "raw" text. The text I am speaking of is of the sort one gets when, say, one copies something from, say, a web page with lots of, er, styled text.
When one copies that text into, say, a LC field, all that style is preserved. Great.
I very often find transforming that styled text into simple raw text very useful.
What is the format of the input string if not already text?
Styles require additional data. Usually this is done in binary form, such as within the inner operations of a field or the clipboard data. We can transform those into textual representations that include the formatting, such as htmlText or rtfText. But your script isn't working on binary structures nor parsing styled text representations, so I'm at a loss to conceive of an input that can be passed to it that isn't already plain text.
Hey, I hate to change the subject, but I have an idea. Why don't we think about a new pane where cute, short utility gadgets can be posted? I bet that would be fun and instructive.
Already built into the LC IDE: see Help -> Sample Stacks
Sob...
?
Re: Gadget pane
Posted: Wed Apr 17, 2019 12:59 pm
by Klaus
FourthWorld wrote: ↑Wed Apr 17, 2019 4:47 am
What is the format of the input string if not already text?
Styles require additional data. Usually this is done in binary form, such as within the inner operations of a field or the clipboard data. We can transform those into textual representations that include the formatting, such as htmlText or rtfText. But your script isn't working on binary structures nor parsing styled text representations, so I'm at a loss to conceive of an input that can be passed to it that isn't already plain text.
That's why I asked!

Re: Gadget pane
Posted: Wed Apr 17, 2019 2:58 pm
by dunbarx
I had early on mentioned the sample stacks. I was thinking more of sample handlers. I may start a new thread that has no examples. That has opened quite a discussion. I never meant it to.
Am I not making myself clear? If I copy a bit of text from a webpage, what lives in the clipBoard is likely very heavily styled and may contain properties (such as textSize) that may differ from one part of that text to another. If I then paste directly into a LC field, say, all that styling and all those properties are preserved.
Right?
Now then, oftentimes I want just the "raw" text. Not the styled text. The raw text. Not the styled text.
What am I missing? It must be something.
Craig
Re: Gadget pane
Posted: Wed Apr 17, 2019 3:21 pm
by bogs
I think the pane is a great idea, if I understand it right, something like the scripters handbook but in a more general way, i.e. everyone contributes, it isn't just your script gems.
Kind of like MetaCards examples reference, again, if I'm reading you rightly.

- Now I get it! (Maybe)
Not micro programs (like User Samples), but general handlers and the like.
Re: Gadget pane
Posted: Wed Apr 17, 2019 3:34 pm
by richmond62
Most Office suites (LibreOffice, Open Office, etc.) have a "paste Special" option where one can paste unformatted text.
This option is also available in the LiveCode Edit menu: command-control-V pastes plain text
Code: Select all
on mouseUp
put the text of fld "f1" into fld "f2"
end mouseUp
removes all styling.
Have a go with:
Code: Select all
on mouseUp
put the clipBoardData["text"] into fld "f1"
end mouseUp