Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Make copy paste possible from a styledText
Make copy paste possible from a styledText [message #370312] Tue, 27 May 2003 09:56 Go to next message
Eclipse UserFriend
Originally posted by: pbeaufil.actia.fr

Hi all,
My problem is simple : i've got a view with a StyledText and i had some
text in it. I'd like that the text could be copy and paste in an other
editor (word for example) but if i use the function setEditable(true) you
can also modify the text and i do not want this to be possible.
Do you have any idea to help me ?
Thanks in advance.
Re: Make copy paste possible from a styledText [message #370341 is a reply to message #370312] Tue, 27 May 2003 20:40 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: lynne_kues.oti.com

When you use setEditable(false), you can still select text and copy it to
the clipboard.

"Pierre Beaufils" <pbeaufil@actia.fr> wrote in message
news:bavcno$k1j$1@rogue.oti.com...
> Hi all,
> My problem is simple : i've got a view with a StyledText and i had some
> text in it. I'd like that the text could be copy and paste in an other
> editor (word for example) but if i use the function setEditable(true) you
> can also modify the text and i do not want this to be possible.
> Do you have any idea to help me ?
> Thanks in advance.
>
Re: Make copy paste possible from a styledText [message #370356 is a reply to message #370341] Wed, 28 May 2003 07:09 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: pbeaufil.actia.fr

It does not work on my computer !
I\'ve got eclipse 2.1 and this is my code :

text = new StyledText (parent,SWT.WRAP | SWT.V_SCROLL);
text.setEditable(false);


Lynne Kues wrote:

> When you use setEditable(false), you can still select text and copy it to
> the clipboard.

> \"Pierre Beaufils\" <pbeaufil@actia.fr> wrote in message
> news:bavcno$k1j$1@rogue.oti.com...
> > Hi all,
> > My problem is simple : i\'ve got a view with a StyledText and i had some
> > text in it. I\'d like that the text could be copy and paste in an other
> > editor (word for example) but if i use the function setEditable(true) you
> > can also modify the text and i do not want this to be possible.
> > Do you have any idea to help me ?
> > Thanks in advance.
> >
Re: Make copy paste possible from a styledText [message #370408 is a reply to message #370356] Thu, 29 May 2003 16:25 Go to previous messageGo to next message
Paul E. Keyser is currently offline Paul E. KeyserFriend
Messages: 878
Registered: July 2009
Senior Member
You also have to add a popup-menu that handles the cases you want to handle:
protected void createPopupMenu () {
final Control c = getControl(); // the StyledText, e.g., or a regular
Text
final Menu noteMenu = new Menu(c);
c.setMenu(noteMenu);

final MenuItem copy = new MenuItem(noteMenu, SWT.NONE);
copy.setText("&Copy");
copy.addSelectionListener(new SelectionAdapter() {
public void widgetSelected (SelectionEvent e) {
doCopy();
}
});

final MenuItem cut = new MenuItem(noteMenu, SWT.NONE);
cut.setText("Cu&t");
cut.addSelectionListener(new SelectionAdapter() {
public void widgetSelected (SelectionEvent e) {
doCut();
}
});

final MenuItem paste = new MenuItem(noteMenu, SWT.NONE);
paste.setText("&Paste");
paste.addSelectionListener(new SelectionAdapter() {
public void widgetSelected (SelectionEvent e) {
doPaste();
}
});

final MenuItem all = new MenuItem(noteMenu, SWT.NONE);
all.setText("Select &All");
all.addSelectionListener(new SelectionAdapter() {
public void widgetSelected (SelectionEvent e) {
doSelectAll();
}
});
}

and then in the doFoo() methods, do this sort of thing:
protected void doCopy () {
_styledText.copy();
}

I dunno how to get the accelerators (Ctrl-C etc.) to work ...

HTH,
Paul K

Pierre Beaufils wrote:

> It does not work on my computer !
> I\'ve got eclipse 2.1 and this is my code :
>
> text = new StyledText (parent,SWT.WRAP | SWT.V_SCROLL);
> text.setEditable(false);
>
> Lynne Kues wrote:
>
> > When you use setEditable(false), you can still select text and copy it to
> > the clipboard.
>
> > \"Pierre Beaufils\" <pbeaufil@actia.fr> wrote in message
> > news:bavcno$k1j$1@rogue.oti.com...
> > > Hi all,
> > > My problem is simple : i\'ve got a view with a StyledText and i had some
> > > text in it. I\'d like that the text could be copy and paste in an other
> > > editor (word for example) but if i use the function setEditable(true) you
> > > can also modify the text and i do not want this to be possible.
> > > Do you have any idea to help me ?
> > > Thanks in advance.
> > >
Re: Make copy paste possible from a styledText [message #370412 is a reply to message #370312] Thu, 29 May 2003 17:40 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: knut_radloff.oti.com

Eclipse defines key bindings for cut/paste. This keeps StyledText from getting the cut/copy/paste keys and you have to hook into the
Eclipse key bindings. This has been asked before. Try searching the archives. IActionBars.setGlobalActionHandler or TextEditor
should be mentioned somewhere.

Knut
"Pierre Beaufils" <pbeaufil@actia.fr> wrote in message news:bavcno$k1j$1@rogue.oti.com...
> Hi all,
> My problem is simple : i've got a view with a StyledText and i had some
> text in it. I'd like that the text could be copy and paste in an other
> editor (word for example) but if i use the function setEditable(true) you
> can also modify the text and i do not want this to be possible.
> Do you have any idea to help me ?
> Thanks in advance.
>
Re: Make copy paste possible from a styledText [message #370413 is a reply to message #370312] Thu, 29 May 2003 17:44 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: knut_radloff.oti.com

See the thread "Re: cut, copy, paste in StyledText Widget" in eclipse.platform.tools.

"Pierre Beaufils" <pbeaufil@actia.fr> wrote in message news:bavcno$k1j$1@rogue.oti.com...
> Hi all,
> My problem is simple : i've got a view with a StyledText and i had some
> text in it. I'd like that the text could be copy and paste in an other
> editor (word for example) but if i use the function setEditable(true) you
> can also modify the text and i do not want this to be possible.
> Do you have any idea to help me ?
> Thanks in advance.
>
Re: Make copy paste possible from a styledText [message #370657 is a reply to message #370413] Thu, 05 June 2003 13:25 Go to previous message
Michael Taege is currently offline Michael TaegeFriend
Messages: 29
Registered: July 2009
Junior Member
Hello,

I couldn't find the thread but meanwhile a find a solution. For those how
couldn't find the thread too:

I assume that the StyledText is used in a view (or something else) with a
createPartControl(Composite parent) method,
so the code looks like this;

public void createPartControl(Composite parent) {
//creating the StyledText (looks maybe different)
StyledText textArea =
new StyledText(
parent,
SWT.BORDER
| SWT.MULTI
| SWT.READ_ONLY
| SWT.WRAP
| SWT.H_SCROLL
| SWT.V_SCROLL);
//creating the cut, copy & paste actions
Action cutAction = new Action() {
public void run() {
textArea.cut();
textArea.redraw();
}
};
Action copyAction = new Action() {
public void run() {
textArea.copy();
}
};
Action pasteAction = new Action() {
public void run() {
textArea.paste();
textArea.redraw();
}
};
//set the actions for the global action handler
IActionBars bars = getViewSite().getActionBars();
bars.setGlobalActionHandler(IWorkbenchActionConstants.CUT, cutAction);
bars.setGlobalActionHandler(IWorkbenchActionConstants.COPY, copyAction);
bars.setGlobalActionHandler(IWorkbenchActionConstants.PASTE,
pasteAction);
}

Note that if the StyledText is read-only (editable==false) 'cut' will only
'copy' the selected text to the clipboard and 'paste'
will have no effect, which makes sense because it's READ_ONLY. If you drop
the READ_ONLY parameter all Action will work fine.

Michael

"Knut Radloff" <knut_radloff@oti.com> schrieb im Newsbeitrag
news:bb5guk$art$1@rogue.oti.com...
> See the thread "Re: cut, copy, paste in StyledText Widget" in
eclipse.platform.tools.
>
> "Pierre Beaufils" <pbeaufil@actia.fr> wrote in message
news:bavcno$k1j$1@rogue.oti.com...
> > Hi all,
> > My problem is simple : i've got a view with a StyledText and i had some
> > text in it. I'd like that the text could be copy and paste in an other
> > editor (word for example) but if i use the function setEditable(true)
you
> > can also modify the text and i do not want this to be possible.
> > Do you have any idea to help me ?
> > Thanks in advance.
> >
>
>
Previous Topic:32-bit icons in tables and trees
Next Topic:How to implement "click and edit" on TreeItem
Goto Forum:
  


Current Time: Fri Apr 26 02:43:17 GMT 2024

Powered by FUDForum. Page generated in 0.03895 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top