[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: Make copy paste possible from a styledText

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@xxxxxxxx> wrote in message
> > news:bavcno$k1j$1@xxxxxxxxxxxxxxxx
> > > 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.
> > >