GoogleCodeArchive / piccolo2d

Automatically exported from code.google.com/p/piccolo2d
0 stars 0 forks source link

When deleting a selected node using the keyboard <DEL> a selection change is not fired #177

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What is the expected output? What do you see instead?
A selection change is done (see code below) but I also expect a selection 
changed, because the selection changes if the node has been deleted by 
keyboard action.
Instead no selection changed can be catched

PSelectionEventHandler.java
    /**
     * Delete selection when delete key is pressed (if enabled).
     * 
     * @param e the key press event
     */
    public void keyPressed(final PInputEvent e) {
        if (e.getKeyCode() == KeyEvent.VK_DELETE && deleteKeyActive) {
            final Iterator selectionEn = selection.keySet().iterator();
            while (selectionEn.hasNext()) {
                final PNode node = (PNode) selectionEn.next();
                node.removeFromParent();
            }
            selection.clear();
// The following code is my change to make it run; possible solution?
//            postSelectionChanged();
        }
    }

What version of the product are you using? On what operating system?
1.2.1 and 1.3
Windows Vista

Please provide any additional information below.

Original issue reported on code.google.com by tbit455...@aol.com on 20 Apr 2010 at 3:30

GoogleCodeExporter commented 9 years ago
Added unit test to svn trunk.

$ svn commit -m "Issue 177 ; adding unit test for selection notification on 
delete
key event" src/test/java/
Adding         
src/test/java/edu/umd/cs/piccolox/event/PSelectionEventHandlerTest.java
Transmitting file data .
Committed revision 1016.

The patch proposed above looks reasonable to me.  Should this go on trunk for 
version
2.0 or on the 1.3 release branch for version 1.3.1 or both?

Original comment by heue...@gmail.com on 27 Apr 2010 at 9:00

GoogleCodeExporter commented 9 years ago
Two changes need to be made in order for this to be a fix.

#1 addition of postSelectionChanged
#2 Pressing delete on an empty selection shouldn't fire event

Following patch ensures thsoe things:

Index: src/main/java/edu/umd/cs/piccolox/event/PSelectionEventHandler.java
===================================================================
--- 
src/main/java/edu/umd/cs/piccolox/event/PSelectionEventHandler.java (revision 
1016)
+++ 
src/main/java/edu/umd/cs/piccolox/event/PSelectionEventHandler.java (working 
copy)
@@ -783,13 +783,14 @@
      * @param e the key press event
      */
     public void keyPressed(final PInputEvent e) {
-        if (e.getKeyCode() == KeyEvent.VK_DELETE && deleteKeyActive) {
+        if (e.getKeyCode() == KeyEvent.VK_DELETE && deleteKeyActive && 
!selection.isEmpty()) {
             final Iterator selectionEn = selection.keySet().iterator();
             while (selectionEn.hasNext()) {
                 final PNode node = (PNode) selectionEn.next();
                 node.removeFromParent();
             }
             selection.clear();
+            postSelectionChanged();
         }
     }

Original comment by allain.lalonde on 28 Apr 2010 at 2:59

GoogleCodeExporter commented 9 years ago
Good point.  I'll add a few more test cases to the unit test and apply that 
patch to
svn trunk.

Original comment by heue...@gmail.com on 28 Apr 2010 at 3:28

GoogleCodeExporter commented 9 years ago
It probably should be applied for eventual release in 1.3.1

Original comment by allain.lalonde on 28 Apr 2010 at 1:57

GoogleCodeExporter commented 9 years ago
$ svn commit -m "Issue 177 ; adding additional unit tests and applying patch" .
...
Committed revision 1017.

Original comment by heue...@gmail.com on 28 Apr 2010 at 4:48

GoogleCodeExporter commented 9 years ago

Original comment by heue...@gmail.com on 26 Nov 2013 at 8:47