[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.tools] Re: cut, copy, paste in StyledText Widget

I was thinking the same thing that Veronika posted, but when I create a
StyledTextView (per the posted code), ctrl-c works just fine.  I am using
2.1.  The problem is most likely related to 2.0.2.  Knut was going to verify
this - or maybe you can Kyle by trying things out in 2.1.

"Veronika Irvine" <veronika_irvine@xxxxxxx> wrote in message
news:b8656o$4h8$1@xxxxxxxxxxxxxxxx
> When you created the StyledText widget in a shell, there were no keyboard
> accelerators defined on the shell so the StyledText widget was able to
> provide its own keyboard accelerators.
>
> When you created a StyledText widget within an Eclipse shell, Eclipse has
> already defined keyboard acclerators for Ctrl+C, Ctrl+V etc and therefore
> the StyledText widget no longer is given the chance to process them.
>
> "kyle farnand" <kfarnand@xxxxxxxxxxxxx> wrote in message
> news:b83man$d88$1@xxxxxxxxxxxxxxxx
> > Thanks Knut,
> >
> > I have determined that StyledText widget allows CTRL-C and CTRL-V in a
> > shell but not in a composite(i.e. in views and editors).  I have created
> > a simple view to illustrate my point.  Here is the code (class and
> > plugin.xml extension):
> >
> > import org.eclipse.swt.SWT;
> > import org.eclipse.swt.custom.StyledText;
> > import org.eclipse.swt.layout.FillLayout;
> > import org.eclipse.swt.widgets.Composite;
> > import org.eclipse.swt.widgets.Display;
> > import org.eclipse.swt.widgets.Shell;
> > import org.eclipse.ui.part.ViewPart;
> >
> > public class StyledTextView extends ViewPart
> > {
> > public void createPartControl(Composite parent)
> > {
> >
> >
> >          Display display = parent.getDisplay();
> >          final Shell shell = new Shell(display);
> >          shell.setLayout(new FillLayout(SWT.VERTICAL));
> >
> >          final StyledText styledText = new StyledText(shell, SWT.SINGLE
> > | SWT.BORDER | SWT.READ_ONLY);
> >          styledText.setText("StyledText widget");
> >
> >          shell.setSize(500, 200);
> >          shell.open();
> >          while (!shell.isDisposed())
> >          {
> >              if (!display.readAndDispatch())
> >              {
> >                  display.sleep();
> >              }
> >          }
> >
> >          parent.setLayout(new FillLayout(SWT.VERTICAL));
> >          final StyledText styledText2 = new StyledText(parent,
> > SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY);
> >          styledText2.setText("StyledText widget 2");
> >
> >      }
> > public void setFocus()
> > {}
> > }
> >
> >   --- add the following to plugin.xml (change the view id and class
> > values appropriately) ---
> >
> > <extension point="org.eclipse.ui.views">
> > <category
> >              name="Sample Style Text"
> >              description="Sample Style Text"
> >              id="com.test.SampleStyleText">
> >      </category>
> > <view
> >    id="com.YOUR_COMPANY.eclipse.views.StyledTextView"
> >    name="Sample Styled Text"
> >    icon="icons/view16/sections.gif"
> >    category="com.test.SampleStyleText"
> > class="com.YOUR_COMPANY.eclipse.views.StyledTextView">
> > </view>
> > </extension>
> >
> >
> >
> > Knut Radloff wrote:
> > > In the example below I can select some text in the StyledText widget
and
> copy the selection to the clipboard using the popup menu on
> > > the StyledText widget or using Ctrl+C. Same for the regular text
widget.
> The text on the clipboard is printed to the console when
> > > you press ctrl+c in either widget.
> > > See http://bugs.eclipse.org/bugs/show_bug.cgi?id=35210 if you're
> wondering why I'm testing for \u0003 to catch the Ctrl+C in the key
> > > listener.
> > >
> > > Knut
> > >
> > > import org.eclipse.swt.*;
> > > import org.eclipse.swt.custom.*;
> > > import org.eclipse.swt.dnd.*;
> > > import org.eclipse.swt.layout.*;
> > > import org.eclipse.swt.widgets.*;
> > >
> > > public class StyledTextClipboard {
> > >  public static void main(String[] args) {
> > >   final Display display = new Display();
> > >   final Shell shell = new Shell(display);
> > >   shell.setLayout(new FillLayout(SWT.VERTICAL));
> > >
> > >   final StyledText styledText = new StyledText(shell, SWT.SINGLE |
> SWT.BORDER | SWT.READ_ONLY);
> > >   styledText.setText("StyledText widget");
> > >   final Text text = new Text(shell, SWT.SINGLE | SWT.BORDER |
> SWT.READ_ONLY);
> > >   text.setText("Text widget");
> > >   Text pasteText = new Text(shell, SWT.BORDER | SWT.MULTI);
> > >   pasteText.setText("paste here");
> > >
> > >   Menu popupMenu = new Menu(styledText);
> > >   MenuItem copyItem = new MenuItem(popupMenu, SWT.PUSH);
> > >   copyItem.setText("Copy");
> > >   copyItem.addListener(SWT.Selection, new Listener() {
> > >    public void handleEvent(Event event) {
> > >     System.out.println("popup menu copy");
> > >     styledText.copy();
> > >    }
> > >   });
> > >   styledText.setMenu(popupMenu);
> > >
> > >   Listener copyListener = new Listener() {
> > >    public void handleEvent(Event event) {
> > >     if (event.character == '\u0003') {
> > >      Clipboard clipboard = new Clipboard(display);
> > >      TextTransfer transfer = TextTransfer.getInstance();
> > >      String text = (String) clipboard.getContents(transfer);
> > >      System.out.println("clipboard contents: " + text);
> > >      clipboard.dispose();
> > >     }
> > >    }
> > >   };
> > >   styledText.addListener(SWT.KeyDown, copyListener);
> > >   text.addListener(SWT.KeyDown, copyListener);
> > >
> > >   shell.setSize(500, 200);
> > >   shell.open();
> > >   while (!shell.isDisposed()) {
> > >    if (!display.readAndDispatch()) {
> > >     display.sleep();
> > >    }
> > >   }
> > >   display.dispose();
> > >  }
> > > }
> > >
> > > "kyle farnand" <kfarnand@xxxxxxxxxxxxx> wrote in message
> news:b80q0h$6ri$1@xxxxxxxxxxxxxxxx
> > >
> > >>Thanks for confirmation Paul.  I am also using R2.0.2 and Win2k.
> > >>
> > >>Knut and/or Lynne, maybe you could post some simple sample code that
you
> > >>know works in your environment.  If it works on my machine, I can
figure
> > >>out what the difference is (between your working code and my failing
> > >>code) and post the results.  If not, we will atleast know it is not a
> > >>difference in code that is causing the our different results.
> > >>
> > >>Open to oother suggestions but this seems like a potential bug (either
> > >>document related or functional) that should be tracked down.
> > >>
> > >>Paul T. Keyser wrote:
> > >>
> > >>>R2.0.2, Win2K
> > >>>
> > >>>I agree with Kyle Farnand who describes the problem accurately and
> correctly: I see exactly the same thing (and have posted
> > >
> > > before
> > >
> > >>>about this, but the threads died).
> > >>>
> > >>>As far as I can tell, these are the facts (R2.0.2, Win2K):
> > >>>1) Text widget: comes with an OS-supplied popupmenu in which are
items
> Cut/Copy/Paste (but Ctrl-C/V/X do *NOT* work); if you add
> > >>>your own popupmenu (via SWT) you lose the whole OS-supplied menu; if
> you then add to your own popupmenu, your own items
> > >>>Cut/Copy/Paste, and hook the API for those actions, you can restore
the
> Cut/Copy/Paste function, but there appears to be NO way
> > >
> > > to
> > >
> > >>>get Ctrl-C/V/X to work (with or without a popupmenu).
> > >>>
> > >>>2) StyledText widget: comes with *NO* popupmenu; you can add your own
> popupmenu (via SWT, pretty much the same as for the Text);
> > >>>to your own popupmenu, you can add your own items Cut/Copy/Paste, and
> hook the API for those actions, thus for the first time
> > >>>obtaining the Cut/Copy/Paste function, but there appears to be NO way
> to get Ctrl-C/V/X to work (with or without a popupmenu).
> > >>>
> > >>>Maybe what Knut and Lynne are saying is that in R2.1, the Ctrl-C/V/X
> has somehow been fixed (via fixing some bug not known to
> > >
> > > have
> > >
> > >>>been connected, but nevertheless connected)?
> > >>>
> > >>>Paul K
> > >>>
> > >>>Knut Radloff wrote:
> > >>>
> > >>>
> > >>>
> > >>>>Which build and OS are you using? Copy to clipboard (using Ctrl+C)
> works for me in a read-only single line Text and StyledText
> > >>>>widget in R2.1
> > >>>>I searched the StyledText bugs we fixed in 2.1 and didn't see
anything
> cut/paste related that may have caused your problem.
> > >>>>
> > >>>>Knut
> > >>>>"kyle farnand" <kfarnand@xxxxxxxxxxxxx> wrote in message
> news:b7n3jl$sh7$1@xxxxxxxxxxxxxxxx
> > >>>>
> > >>>>
> > >>>>>Looking at the Text tab of the SWT Controls sample view and playing
> > >>>>>around with all the different parameters, there were no parameters
> that
> > >>>>>I could set to get CTRL-C to work in either the Text or Styled Text
> > >>>>>widget (including READ_ONLY).  Right Click->Copy worked with any
> > >>>>>parameter settings on the Text widget but not on the StyledText
> widget.
> > >>>>>
> > >>>>>Is this the desired functionality for the StyledText widget?
> > >>>>>
> > >>>>>kyle farnand wrote:
> > >>>>>
> > >>>>>
> > >>>>>>I must be doing something wrong then.  I tried CTRL-C and paste
the
> > >>>>>>results into notepad and don't get anything.  I know about the API
> but
> > >>>>>>was hoping to get this functionality for free (which seems
> possible). In
> > >>>>>>the Text widget you get <right-click> menu -> copy functionality
and
> was
> > >>>>>>hoping that would be the same in StyledText widget.
> > >>>>>>
> > >>>>>>Lynne Kues wrote:
> > >>>>>>
> > >>>>>>
> > >>>>>>
> > >>>>>>>I do not understand what you are talking about.
> > >>>>>>>
> > >>>>>>>If the StyledText widget is READ_ONLY, the copy operation is
> available
> > >>>>>>>(select some text and press CTRL-C), but you cannot paste to or
cut
> > >>>>>>
> > >>>>>>>from the
> > >>>>>>
> > >>>>>>>widget since it is readonly.  Also note that there is API in the
> > >>>>>>>StyledText
> > >>>>>>>widget to cut, copy and paste programatically.
> > >>>>>>>
> > >>>>>>>"kyle farnand" <kfarnand@xxxxxxxxxxxxx> wrote in message
> > >>>>>>>news:b7mtas$n7d$1@xxxxxxxxxxxxxxxx
> > >>>>>>>
> > >>>>>>>
> > >>>>>>>
> > >>>>>>>>When I use the below code, I get copy and paste for free.
> > >>>>>>>>
> > >>>>>>>>
> > >>>>>>>>
> > >>>>>>>>>Text modelText = new Text(modelXMLContainer, SWT.READ_ONLY
> |SWT.MULTI);
> > >>>>>>>>>modelText.setText(modelString);
> > >>>>>>>>
> > >>>>>>>>But when I used the StyledText widget, I lose this
functionality.
> > >>>>>>>>
> > >>>>>>>>
> > >>>>>>>>
> > >>>>>>>>>StyledText modelText = new StyledText(modelXMLContainer,
> > >>>>>>>>
> > >>>>>>>>SWT.READ_ONLY);
> > >>>>>>>>
> > >>>>>>>>
> > >>>>>>>>>modelText.setText(modelString);
> > >>>>>>>>
> > >>>>>>>>An earlier post said I should get the same copy and paste
> functionality
> > >>>>>>>>if I use SWT.READ_ONLY in the constructor from both widgets but
> that is
> > >>>>>>>>not the case.
> > >>>>>>>>
> > >>>>>>>>Is there an easy way to get this copy and paste functionality
out
> of the
> > >>>>>>>>StyledText widget (as in the Text widget) or do I have to
> implement it
> > >>>>>>>>myself?
> > >>>>>>>>
> > >>>>>>>
> > >>>>>>>
> > >>>>>>>
> > >
> > >
> >
>
>