Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
nmaddix
Posts: 111
Registered: ‎12-16-2008
My Device: Not Specified

Can't copy selected text from email message

Hello-

I've added a new item to the context menu in the email viewer screen and I want it to copy the selected text to the clipboard and then do something with it. It works fine if I manually copy the text by selecting and choosing 'copy' but I don't want the user to have to do that first and then choose my new menu item.

 

I'm trying to copy the selected text programmatically as suggested in this posting:

http://208.74.204.192/rim/board/message?board.id=java_dev&thread.id=6787&view=by_date_ascending&page...

 

Looks like it should work but when I call isSelectionCopyable() on either the Screen or Field object I get a return of false. Calling selectionCopy() on either one does nothing also.

 

Any ideas how I can get around this?

 

Thanks!

Nicholas

Please use plain text.
Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Can't copy selected text from email message

[ Edited ]

It's hard to deduce what you are doing and why it isn't working without a code snippet.

 

The thread you reference was somebody looking for a way to retreive text that was selected by the user. I think I understand that you want to select the text programmatically.

 

The select will always return false (for isCopyable) if there is no selection.

 

Have you tried maybe just calling getText() on the field? This should retrieve all of the text in the field, right?

 

 

Message Edited by RexDoug on 12-17-2008 05:37 PM
Please use plain text.
Developer
nmaddix
Posts: 111
Registered: ‎12-16-2008
My Device: Not Specified

Re: Can't copy selected text from email message

Thanks for the reply! Actually I'm doing exactly what that person is doing, using the same code as presented in that message. I want the user to be able to select text and then activate my menu option and have it act on the text (via automatically copying to the clipboard first) without the user having to manually select the copy option first. I want only the selected text, not all of it.

 

I have created an application menu option using the following code:

 

ApplicationMenuItemRepository amir = ApplicationMenuItemRepository.getInstance();
amir.addMenuItem(ApplicationMenuItemRepository.MENUITEM_EMAIL_EDIT, new DemoMenuItem());

 

My DemoMenuItem class extends ApplicationMenuItem as directed by the docs on extending application menus.

 

This all works and my menu item is called correctly when selected. It executes this code in the run() method of my DemoMenuItem object:

 

Screen s = UiApplication.getUiApplication().getActiveScreen();

Field fld = s.getFieldWithFocus();

 

For s I get an object of type

net.rim.device.apps.internal.blackberryemail.email.EmailEditorScreen

looks good!

 

For fld I get an object of type

net.rim.device.apps.api.utility.framework.ModelScreen$ScrollbarManager

 

The fld object looks suspicious but regardless, calling isSelectionCopyable() or selectionCopy() on either the s or fld objects does not work as I indicated before.

 

Thanks,

Nicholas

Please use plain text.
Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Can't copy selected text from email message

You've got me stumped. I can't see how the ScrollbarManager can have the focus if you have selected text in the EmailEditField.

 

 

Please use plain text.
Developer
nmaddix
Posts: 111
Registered: ‎12-16-2008
My Device: Not Specified

Re: Can't copy selected text from email message

That is weird. But you'd think that calling isSelectionCopyable() or selectionCopy() on the EmailEditorScreen object I have in s would do what I want. But no luck.

 

Does anyone know where I can find documentation on that object? Novice blackberry programmer here...

 

 

Please use plain text.
Administrator
MSohm
Posts: 14,268
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: Can't copy selected text from email message

This approach isn't supported.  However, your ApplicationMenuItem should receive a copy of the email message the user is writing as a parameter in its run method.  You could read the text from here, display it on your own screen and allow the user to select the area you wish to work with.

 

You can then modify the message with the new text, call Message.updateUi to update the email message shown in the Messages application.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
Developer
nmaddix
Posts: 111
Registered: ‎12-16-2008
My Device: Not Specified

Re: Can't copy selected text from email message

Thanks Mark-

That's a shame. I'll tinker with that but it's a lot of steps. Appreciate you passing on the idea!

 

Nicholas

Please use plain text.