Geertjan's Blog

  • November 24, 2011

UndoRedo on Nodes (Part 2)

Geertjan Wielenga
Product Manager

After the recording of the latest API Design Tip for the upcoming NetBeans Podcast, Jaroslav Tulach helped me with the problem I blogged about yesterday. First he expressed surprise at seeing Undo/Redo work on Nodes, which was never the intention, i.e., that feature was always intended for documents, e.g., the Java editor.

However, he then showed me where to find the Properties window in the NetBeans sources, where it is org.netbeans.core.windows.view.ui.NbSheet. It turns out that the Properties window does not have an activated node and hence the Node that implements UndoRedo.Provider is never put in the Lookup. Once we added, on line 303, "this.setActivatedNodes(nodes);", everything worked as expected, i.e., the Undo/Redo actions are now enabled, even when the Properties window is selected:

Maybe it means I should file an issue to get that line added to NbSheet?

Join the discussion

Comments ( 3 )
  • Jaroslav Tulach Friday, November 25, 2011

    We cannot just call setActivatedNodes in NbSheet, that would not be compatible. But we may design some contract where Node(s) will be able to tell the NbSheet that it should change its activated nodes.

    Maybe Boolean.TRUE.equals(node.getValue("exposeInGlobalSheet"))

    Feel free to pass API review with such change.

  • Jesse Glick Monday, November 28, 2011

    Compatible for whom?

    The reason NbSheet does not already set its own node selection is that it could introduce some kind of cycle - it is after all trying to track the activate nodes of other components.

    Anyway it is unnecessary because the problem is in the toolbar button, not the property sheet. An action marked surviveFocusChange=true will continue to work naturally even when some component with no node selection (*), such as the property sheet or the output window, is activated.

    (*) No selection is distinct from a selection containing zero nodes.

  • Ayman Habib Monday, September 17, 2012

    Following up on this excellent blog and Jesse's reply, how do I make the command associated with the global "Undo" button in the toolbar "surviveFocusChange"? I'm using Netbeans 7.0.1.

    Thanks much,

Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.