Skip to main content



      Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Is there any way to detect a Paste/Cut from within a ModifyListener?
Is there any way to detect a Paste/Cut from within a ModifyListener? [message #465215] Thu, 08 December 2005 06:39 Go to next message
Eclipse UserFriend
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 #465315 is a reply to message #465215] Thu, 08 December 2005 16:40 Go to previous messageGo to next message
Eclipse UserFriend
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 #465341 is a reply to message #465315] Fri, 09 December 2005 03:36 Go to previous messageGo to next message
Eclipse UserFriend
Well, I did not know about VerifyListener, which seems like it could be quite useful -- but when I
attach a VerifyListener to my Text control, it is never called, whether or not I also have a
ModifyListener (which, when attached, *is* called). The javadocs for VerifyListener suggest that
VerifyListener works with Text and requires no special handling. What's up?

thanks,
Paul
Re: Is there any way to detect a Paste/Cut from within a ModifyListener? [message #465342 is a reply to message #465341] Fri, 09 December 2005 03:43 Go to previous messageGo to next message
Eclipse UserFriend
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
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 10:00 Go to previous message
Eclipse UserFriend
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
Previous Topic:Browser widget and KeyListener
Next Topic:Centering a canvas content
Goto Forum:
  


Current Time: Sat Jul 05 23:49:55 EDT 2025

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

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

Back to the top