Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Is there any way to detect a Paste/Cut from within a ModifyListener?
|
Re: Is there any way to detect a Paste/Cut from within a ModifyListener? [message #465315 is a reply to message #465215] |
Thu, 08 December 2005 21:40 |
Veronika Irvine Messages: 1272 Registered: July 2009 |
Senior Member |
|
|
Why not look at how many characters have changed in the VerifyEvent - see
VerifyEvent.text, VerifyEvent.start, VerifyEvent.end.
Note that typing one character when a large amount of text is selected will
also result in a significant change in the text.
"Paul Keyser" <rolarenfan@earthlink.net> wrote in message
news:dn961o$f3n$1@news.eclipse.org...
> Or, if there is not (as I suspect, having looked at the fields of
> ModifyEvent), is there some other way to detect that the user has
> pasted-into or cut-from my Text-widget?
>
> I want to save the model when the user makes a "sufficinently large"
> change; I can and do count ModifyEvents, which works fine for keystrokes,
> but when the user pastes or cuts, that is one event, yet is "large".
>
> Any ideas?
>
> thanks,
> Paul
|
|
| | |
Re: Is there any way to detect a Paste/Cut from within a ModifyListener? [message #465346 is a reply to message #465342] |
Fri, 09 December 2005 15:00 |
Veronika Irvine Messages: 1272 Registered: July 2009 |
Senior Member |
|
|
The following works for me for every single key stroke that inserts or
deletes character(s). It also works for menu selections such as cut and
paste and when API on Text is called to change the text (click the button):
public static void main (String [] args) {
Display display = new Display ();
Shell shell = new Shell (display);
shell.setLayout(new FillLayout());
final Text t = new Text(shell, SWT.BORDER | SWT.MULTI);
t.addVerifyListener(new VerifyListener() {
public void verifyText(VerifyEvent e) {
System.out.println("Verify text "+e.start+"
"+e.end+" "+e.text);
}
});
Button b = new Button(shell, SWT.PUSH);
b.setText("insert text");
b.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
t.insert("Hello");
}
});
shell.setSize(300, 300);
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
"Paul Keyser" <rolarenfan@earthlink.net> wrote in message
news:dnbg4b$m9i$1@news.eclipse.org...
> Hmmm -- what I said appears to be not quite right: *sometimes* the
> VerifyListener is called, but on many keystrokes it is not. When it is
> called, the results surprised me: only "Select All, then type" resulted in
> verifyEvent.end - verifyEvent.start being greater than zero; in
> particular, no Paste or Cut event ever seems to generate verifyEvent.end -
> verifyEvent.start > 0. So I am still puzzled, but on a higher level than
> in my prior message.
>
> thanks,
> Paul
|
|
|
Goto Forum:
Current Time: Mon Dec 09 07:31:47 GMT 2024
Powered by FUDForum. Page generated in 0.04194 seconds
|