-
Notifications
You must be signed in to change notification settings - Fork 236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add context menu #439
Add context menu #439
Conversation
IMHO it would be better to use
|
Ah! Good point! I assumed it was just a right-click. |
I've included @JFormDesigner's point about the |
Since I haven't heard anything else about the default offset values, I'm going to merge this. They can always be modified later on if need be. |
If I wanted a context menu containing the usual RichTextFX exposes the functionality of a text-field with methods simply named But:
I'm wondering if you would be kind enough to write one, and then let us do something like create a static method styleClassedTextArea.contextMenu = StyleClassTextArea.makeDefaultContextMenu() or even <StyleClassedTextArea>
<contextMenu>
<StyleClassedTextArea fx:factory="makeDefaultContextMenu"/>
</contextMenu>
</StyleClassedTextArea> |
Here you go, modify and style as needed, to use do: private class DefaultContextMenu extends ContextMenu
{
private MenuItem cut, copy, delete, paste, undo, redo;
private GenericStyledArea area;
private IndexRange range;
public DefaultContextMenu()
{
showingProperty().addListener( (ob,ov,showing) -> checkMenuItems( showing ) );
cut = new MenuItem( "Cut" );
cut.setOnAction( AE -> { hide(); area.cut(); } );
copy = new MenuItem( "Copy" );
copy.setOnAction( AE -> { hide(); area.copy(); } );
delete = new MenuItem( "Delete" );
delete.setOnAction( AE -> { hide(); area.deleteText( range ); } );
paste = new MenuItem( "Paste" );
paste.setOnAction( AE -> { hide(); area.paste(); } );
redo = new MenuItem( "Redo" );
redo.setOnAction( AE -> { hide(); area.redo(); } );
undo = new MenuItem( "Undo" );
undo.setOnAction( AE -> { hide(); area.undo(); } );
getItems().addAll( copy, cut, delete, paste, redo, undo );
}
private void checkMenuItems( boolean showing )
{
if ( ! showing ) return;
area = (GenericStyledArea) getOwnerNode();
UndoManager history = area.getUndoManager();
undo.setDisable( ! history.isUndoAvailable() );
redo.setDisable( ! history.isRedoAvailable() );
range = area.getSelection();
boolean noSelection = range.getLength() == 0;
delete.setDisable( noSelection );
copy.setDisable( noSelection );
cut.setDisable( noSelection );
}
} |
This addresses #363.
There is no
ContextMenu
by default: this matches the same behavior as all other nodes.Questions
5
or some positive non-zero value? In the TestFX test, having it as zero will fail the tests because the mouse clicks on the menu rather than the area once it is shown. Developer who set the menu in their code will also need to override the default values every time, which is unnecessary boilerplate.2
. There's no specific reason for this choice, so it's up for modification.