Skip to content

Commit

Permalink
Added "Select All" menu option.
Browse files Browse the repository at this point in the history
  • Loading branch information
renatoathaydes committed Dec 15, 2023
1 parent 2f771ce commit f8293d0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/main/java/com/athaydes/logfx/ui/LogView.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import javafx.scene.Node;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.util.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -152,6 +153,14 @@ public CompletionStage<SelectionHandler.SelectableNode> previousSelectable() {
return loadNextSelectable( true );
}

public Optional<Pair<SelectionHandler.SelectableNode, SelectionHandler.SelectableNode>> getSelectableEnds() {
var children = getChildren();
if (!children.isEmpty()) {
return Optional.of(new Pair<>(lineAt(0), lineAt(children.size() - 1)));
}
return Optional.empty();
}

private CompletionStage<SelectionHandler.SelectableNode> loadNextSelectable( boolean up ) {
var future = new CompletableFuture<SelectionHandler.SelectableNode>();
moveBy( 1, up, () -> Platform.runLater( () -> {
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/athaydes/logfx/ui/LogViewPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ public LogViewPane( TaskRunner taskRunner,
.flatMap( wrapper -> wrapper.logView.getSelectionHandler().getSelection() )
.ifPresent( content -> Clipboard.getSystemClipboard().setContent( content ) ) );

MenuItem selectAllMenuItem = new MenuItem( "Select All" );
selectAllMenuItem.setAccelerator( new KeyCodeCombination( KeyCode.A, KeyCombination.SHORTCUT_DOWN ) );
selectAllMenuItem.setOnAction( event -> selectAllLogViewRows() );

MenuItem closeMenuItem = new MenuItem( "Close" );
closeMenuItem.setAccelerator( new KeyCodeCombination( KeyCode.W, KeyCombination.SHORTCUT_DOWN ) );
closeMenuItem.setOnAction( ( event ) ->
Expand Down Expand Up @@ -181,6 +185,7 @@ public LogViewPane( TaskRunner taskRunner,

pane.setContextMenu( new ContextMenu(
copyMenuItem,
selectAllMenuItem,
new SeparatorMenuItem(),
toTopMenuItem, tailMenuItem, pageUpMenuItem, pageDownMenuItem, goToDateMenuItem, changeHighlightGroup,
new SeparatorMenuItem(),
Expand Down Expand Up @@ -231,6 +236,14 @@ public LogViewPane( TaskRunner taskRunner,
}
}

public void selectAllLogViewRows() {
getFocusedView().ifPresent(view -> {
var handler = view.getLogView().getSelectionHandler();
view.getLogView().getSelectableEnds().ifPresent(ends ->
handler.selectAllBetween(ends.getKey(), ends.getValue()));
});
}

public ObjectProperty<Orientation> orientationProperty() {
return pane.orientationProperty();
}
Expand Down

0 comments on commit f8293d0

Please sign in to comment.
-