keyboard shortcuts for cut/copy/paste failing [message #453933] |
Thu, 14 April 2005 08:57 |
Eclipse User |
|
|
|
Originally posted by: doug-list.threepenny.net
I'm trying to support copying text from a tree control by attaching a
text control at the right location in the tree when the user clicks in
the tree.
It all works fine, but the keyboard shortcuts fail (Ctrl-C etc.).
I can right click in the text window and choose "Copy" and that works,
but no good from the keyboard.
The relevant chunk of code is below which is adapted from the snippet
for how to do this for a table (for which keyboard shortcuts seem to
work for me).
BTW, I know the focus is set to this window because I can edit the text
inside it just fine, so the keystrokes are going there.
Any ideas?
Doug
protected void leftMouseDown(MouseEvent e)
{
// Figure out which item the user clicked on
Point pt = new Point(e.x, e.y) ;
TreeItem item = m_Tree.getItem(pt) ;
if (item == null)
{
System.out.println("No item clicked") ;
return ;
}
ControlEditor editor = new ControlEditor (m_Tree);
editor.grabHorizontal = true;
final Text text = new Text (m_Tree, SWT.NULL);
Listener textListener = new Listener () {
public void handleEvent (final Event e) {
switch (e.type) {
case SWT.FocusOut:
text.dispose ();
break;
case SWT.Traverse:
switch (e.detail) {
case SWT.TRAVERSE_RETURN:
//FALL THROUGH
case SWT.TRAVERSE_ESCAPE: text.dispose ();
e.doit = false;
}
break;
}
}
};
text.addListener (SWT.FocusOut, textListener);
text.addListener (SWT.Traverse, textListener);
text.setText (item.getText());
text.setFont(m_Tree.getFont()) ;
editor.setEditor(text) ;
text.setBounds(item.getBounds()) ;
text.setFocus ();
text.setVisible(true) ;
}
|
|
|
Re: keyboard shortcuts for cut/copy/paste failing [message #453960 is a reply to message #453933] |
Thu, 14 April 2005 22:31 |
Eclipse User |
|
|
|
Originally posted by: doug-list.threepenny.net
OK, problem solved.
Turned out I had a menu registering its accelerator as "Ctrl-C" so it
got the message not the control.
Seems like the wrong message flow to me, but removing that accelerator
solves the problem and I seem to remember Windows code doing the
accelerator map before dispatching the message, so this would make sense.
Doug
Doug Pearson wrote:
> I'm trying to support copying text from a tree control by attaching a
> text control at the right location in the tree when the user clicks in
> the tree.
>
> It all works fine, but the keyboard shortcuts fail (Ctrl-C etc.).
> I can right click in the text window and choose "Copy" and that works,
> but no good from the keyboard.
>
> The relevant chunk of code is below which is adapted from the snippet
> for how to do this for a table (for which keyboard shortcuts seem to
> work for me).
>
> BTW, I know the focus is set to this window because I can edit the text
> inside it just fine, so the keystrokes are going there.
>
> Any ideas?
>
> Doug
>
> protected void leftMouseDown(MouseEvent e)
> {
> // Figure out which item the user clicked on
> Point pt = new Point(e.x, e.y) ;
> TreeItem item = m_Tree.getItem(pt) ;
>
> if (item == null)
> {
> System.out.println("No item clicked") ;
> return ;
> }
>
> ControlEditor editor = new ControlEditor (m_Tree);
> editor.grabHorizontal = true;
>
> final Text text = new Text (m_Tree, SWT.NULL);
> Listener textListener = new Listener () {
> public void handleEvent (final Event e) {
> switch (e.type) {
> case SWT.FocusOut:
> text.dispose ();
> break;
> case SWT.Traverse:
> switch (e.detail) {
> case SWT.TRAVERSE_RETURN:
> //FALL THROUGH
> case SWT.TRAVERSE_ESCAPE:
> text.dispose ();
> e.doit = false;
> }
> break;
> }
> }
> };
> text.addListener (SWT.FocusOut, textListener);
> text.addListener (SWT.Traverse, textListener);
> text.setText (item.getText());
> text.setFont(m_Tree.getFont()) ;
>
> editor.setEditor(text) ;
> text.setBounds(item.getBounds()) ;
>
> text.setFocus ();
> text.setVisible(true) ;
> }
>
|
|
|
Powered by
FUDForum. Page generated in 0.01383 seconds