Copy and Pasting Text via clipboard, but keeping formating
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 44
- Joined: Tue Jul 12, 2011 7:43 pm
Copy and Pasting Text via clipboard, but keeping formating
Hey fellow livecoders,
In my application a user has the ability to copy text out of an attachment from their email and paste it into the application. There the user uses this text to build out a pdf and send it out as an attachment via email. My issue here is that the method I am using strips the text of indentations or any other advanced formatting. Is the a way I can utilize the clipboard to copy text but also maintain the formatting?
In my application a user has the ability to copy text out of an attachment from their email and paste it into the application. There the user uses this text to build out a pdf and send it out as an attachment via email. My issue here is that the method I am using strips the text of indentations or any other advanced formatting. Is the a way I can utilize the clipboard to copy text but also maintain the formatting?
-
- Posts: 44
- Joined: Tue Jul 12, 2011 7:43 pm
Re: Copy and Pasting Text via clipboard, but keeping formati
Here is the code that I am using for my clipboard functionality
Code: Select all
on openCard
doreadcasting
if environment() <> "mobile" then exit openCard
iphoneControlCreate "input"
put the result into inputID
iphoneControlSet inputID, "rect", the rect of grc 2
iphoneControlSet inputID, "visible", "true"
iphoneControlSet inputID, "opaque", "false"
iphoneControlSet inputID, "fontName", "Helvetica"
iphoneControlSet inputID, "fontSize", 18
iphoneControlSet inputID, "borderStyle", "none"
iphoneControlSet inputID, "clearButtonMode", "unless editing"
iphoneControlSet inputID, "autoCapitalizationType", "words"
iphoneControlSet inputID, "autoCorrectionType", "No"
iphoneControlSet inputID, "autoClear", "false"
end openCard
on inputBeginEditing
put iphonecontrolGet(inputID, "text") into field "field"
end inputBeginEditing
on inputTextChanged
put iphonecontrolGet(inputID, "text") into fld "field"
end inputTextChanged
on inputEndEditing
do nothing
#answer iphonecontrolGet(inputID, "text")
end inputEndEditing
-
- Posts: 44
- Joined: Tue Jul 12, 2011 7:43 pm
Re: Copy and Pasting Text via clipboard, but keeping formati
This is what I think I'll do,
Using clipboardData["rtf"] I'll try a put the rtf data into a html ui webview where it hopefully can be displayed. Assuming that I can somehow use a ui webview to display rtf correctly, I have a PDFprint function that I use to build a pdf, hopefully of the contents of that web view.
Using clipboardData["rtf"] I'll try a put the rtf data into a html ui webview where it hopefully can be displayed. Assuming that I can somehow use a ui webview to display rtf correctly, I have a PDFprint function that I use to build a pdf, hopefully of the contents of that web view.
-
- Posts: 44
- Joined: Tue Jul 12, 2011 7:43 pm
Re: Copy and Pasting Text via clipboard, but keeping formati
I'm having trouble trying to work with my new potential solution-
So what I am trying to do is generate a uiwebview, within that uiwebview I want to populate it with rich text. This rich text is ideally copied from an email or attachment using clipboard data pasted. Hopefully the uiwebview can display the text in the application.
This route is more complicated than I like but from my understanding it could be the only way to display rich text in live code (rich text being bullets, indentations, etc).
Can livecode display rich text? If so must it be done with a uiwebview? Answers to those questions would be extremely appreciated by me!
So what I am trying to do is generate a uiwebview, within that uiwebview I want to populate it with rich text. This rich text is ideally copied from an email or attachment using clipboard data pasted. Hopefully the uiwebview can display the text in the application.
This route is more complicated than I like but from my understanding it could be the only way to display rich text in live code (rich text being bullets, indentations, etc).
Can livecode display rich text? If so must it be done with a uiwebview? Answers to those questions would be extremely appreciated by me!
Re: Copy and Pasting Text via clipboard, but keeping formati
If you copy rtf data to the clipboard, you should be able to set a field to that data
set the rtftext of field "fieldname" to the clipboarddata["rtf"] (or "htmltext" or....)
The question is, do you actually have rtf text as one of the array elements in the clipboard. I think you can "put the keys of the clipboarddata" to see what data types are currently available.
On mac, most applications I tested only have text and unicode, but copying from textedit has styles and rtf in addition, so setting the rtftext of a field to the clipboarddata["rtf"] should work fine. (also, if you have rtf text with different heights you'll want to turn off fixed line height for the field)
EDIT: You can confirm that rtftext is available in the clipboard with a line like so..
if rtf is among the lines of the keys of the clipboarddata then
-- use the rtftext
else
-- handle it some other way.
end if
set the rtftext of field "fieldname" to the clipboarddata["rtf"] (or "htmltext" or....)
The question is, do you actually have rtf text as one of the array elements in the clipboard. I think you can "put the keys of the clipboarddata" to see what data types are currently available.
On mac, most applications I tested only have text and unicode, but copying from textedit has styles and rtf in addition, so setting the rtftext of a field to the clipboarddata["rtf"] should work fine. (also, if you have rtf text with different heights you'll want to turn off fixed line height for the field)
EDIT: You can confirm that rtftext is available in the clipboard with a line like so..
if rtf is among the lines of the keys of the clipboarddata then
-- use the rtftext
else
-- handle it some other way.
end if
Last edited by sturgis on Wed Aug 01, 2012 12:21 am, edited 1 time in total.
-
- Posts: 44
- Joined: Tue Jul 12, 2011 7:43 pm
Re: Copy and Pasting Text via clipboard, but keeping formati
Thanks so much for the response! I'm going to play around with this and respond with the results.
-
- Posts: 44
- Joined: Tue Jul 12, 2011 7:43 pm
Re: Copy and Pasting Text via clipboard, but keeping formati
This method works perfectly for me! I cannot express how grateful I am for you saving my ass there B-)
Re: Copy and Pasting Text via clipboard, but keeping formati
Glad its working for ya!
-
- Posts: 44
- Joined: Tue Jul 12, 2011 7:43 pm
Re: Copy and Pasting Text via clipboard, but keeping formati
This method doesn't work so swimmingly for me in the iOS simulator.... I probably should have thought to test it in the app before I got so excited.
I created a sample stack that works exactly how I want it to in livecode but when I bring it into the simulator it does nothing.
Any ideas?
I created a sample stack that works exactly how I want it to in livecode but when I bring it into the simulator it does nothing.
Any ideas?
-
- Posts: 44
- Joined: Tue Jul 12, 2011 7:43 pm
Re: Copy and Pasting Text via clipboard, but keeping formati
I feel like setting the rtftext of a field to the clipboarddata["rtf"] may not work within iOS but I'm not sure. Why else would it work in livecode but not in the simulator right?
Re: Copy and Pasting Text via clipboard, but keeping formati
Are you using lc fields or creating a control with mobilecontrolcreate?
Are you checking to make sure there is actually rtf data in the clipboard data?
Can you describe what happens in ios? No paste? Corrupt text?
Can you post your script? I can't currently test with ios, but I can try your code in android and see if it works there..
Are you checking to make sure there is actually rtf data in the clipboard data?
Can you describe what happens in ios? No paste? Corrupt text?
Can you post your script? I can't currently test with ios, but I can try your code in android and see if it works there..
-
- Posts: 44
- Joined: Tue Jul 12, 2011 7:43 pm
Re: Copy and Pasting Text via clipboard, but keeping formati
Yeah, I'm just using livecode scrolling fields to paste the text in and I couldn't get rtf test code to work but I'll try again and see if I can get a positive result in livecode but a negative one in iOS.
I'm using a test stack that a built which basically just consists of 2 buttons and a field. The field is a scrolling field called "tester" that the text gets pasted into.
The two buttons are:
Paste- which I use to put the unparsed rtf data into the "tester" field, with the code as follows:
Prime- Which I use to put the rtf data into field parsed, with the code as follows:
I'm using a test stack that a built which basically just consists of 2 buttons and a field. The field is a scrolling field called "tester" that the text gets pasted into.
The two buttons are:
Paste- which I use to put the unparsed rtf data into the "tester" field, with the code as follows:
Code: Select all
put the clipboardData["rtf"] into field "tester"
Code: Select all
set the rtftext of field "tester" to the clipboarddata["rtf']
-
- Posts: 44
- Joined: Tue Jul 12, 2011 7:43 pm
Re: Copy and Pasting Text via clipboard, but keeping formati
Also when I run the same stack in the simulator, no matter what text I copy it doesn't paste. Could it because iOS doesn't reference clipboardData for what data is copied on the phone?
Re: Copy and Pasting Text via clipboard, but keeping formati
Just checked the dicionary, does look like clipboard and clipboarddata are not yet supported on ios/android. I'll check the release notes too in a bit, but doubt it will differ.
If you're trying to copy from another app into the lc app i'm not sure there is currently a way to do this. Doesn't look like a direct paste is available either. If you're trying to copy from a browser control inside the lc app, it might be possible to work around the limitation..
Sorry for steering you the wrong way, hopefully LC will get more of this stuff implemented soon.
If you know objective c you might also be able to implement your own paste function as an external. (or you might see if Monte will add copy/paste for ios functionality to mergext)
If you're trying to copy from another app into the lc app i'm not sure there is currently a way to do this. Doesn't look like a direct paste is available either. If you're trying to copy from a browser control inside the lc app, it might be possible to work around the limitation..
Sorry for steering you the wrong way, hopefully LC will get more of this stuff implemented soon.
If you know objective c you might also be able to implement your own paste function as an external. (or you might see if Monte will add copy/paste for ios functionality to mergext)
-
- Posts: 44
- Joined: Tue Jul 12, 2011 7:43 pm
Re: Copy and Pasting Text via clipboard, but keeping formati
This is very upsetting news =/
I really appreciate the help thought and thanks for looking into it more.
The idea of the application is to copy text from an email attachment like a .doc or .rtf, just a text field with rtf. Unfortunately I don't know objective C but if there is a work around using the browser control I guess that's the way I will have to do it.
I guess this bring me back to my original concept using html to parse the data and hopefully print that in a pdf. I wish it was as simple as putting the text in a scrolling field =/
I really appreciate the help thought and thanks for looking into it more.
The idea of the application is to copy text from an email attachment like a .doc or .rtf, just a text field with rtf. Unfortunately I don't know objective C but if there is a work around using the browser control I guess that's the way I will have to do it.
I guess this bring me back to my original concept using html to parse the data and hopefully print that in a pdf. I wish it was as simple as putting the text in a scrolling field =/