Skip to content

Commit

Permalink
Add quick-nav window
Browse files Browse the repository at this point in the history
  • Loading branch information
Col-E committed Mar 5, 2024
1 parent 446fe53 commit 5066e90
Show file tree
Hide file tree
Showing 8 changed files with 469 additions and 10 deletions.
18 changes: 15 additions & 3 deletions recaf-ui/src/main/java/software/coley/recaf/RecafApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.SplitPane;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import org.kordamp.ikonli.carbonicons.CarbonIcons;
import software.coley.recaf.cdi.UiInitializationEvent;
import software.coley.recaf.services.window.WindowManager;
import software.coley.recaf.ui.RecafTheme;
import software.coley.recaf.ui.config.KeybindingConfig;
import software.coley.recaf.ui.control.FontIconView;
import software.coley.recaf.ui.docking.DockingManager;
import software.coley.recaf.ui.docking.DockingRegion;
Expand Down Expand Up @@ -51,6 +53,8 @@ public void start(Stage stage) {
Node logging = createLoggingWrapper();
workspaceRootPane = recaf.get(WorkspaceRootPane.class);
welcomePane = recaf.get(WelcomePane.class);
KeybindingConfig keybindingConfig = recaf.get(KeybindingConfig.class);
WindowManager windowManager = recaf.get(WindowManager.class);

// Layout
SplitPane splitPane = new SplitPane(root, logging);
Expand All @@ -69,23 +73,31 @@ public void start(Stage stage) {
workspaceManager.addWorkspaceCloseListener(this);

// Display
Scene scene = new RecafScene(wrapper);
scene.addEventFilter(KeyEvent.KEY_PRESSED, (KeyEvent event) -> {
// Global keybind handling
if (keybindingConfig.getQuickNav().match(event)) {
Stage quickNav = windowManager.getQuickNav();
quickNav.show();
quickNav.requestFocus();
}
});
stage.setMinWidth(900);
stage.setMinHeight(600);
Scene value = new RecafScene(wrapper);
stage.setScene(value);
stage.setScene(scene);
stage.getIcons().add(Icons.getImage(Icons.LOGO));
stage.setTitle("Recaf");
stage.setOnCloseRequest(e -> System.exit(0));
stage.show();

// Register main window
WindowManager windowManager = recaf.get(WindowManager.class);
windowManager.register(WindowManager.WIN_MAIN, stage);

// Publish UI init event
recaf.getContainer().getBeanContainer().getEvent().fire(new UiInitializationEvent());
}

@Nonnull
private Node createLoggingWrapper() {
LoggingPane logging = recaf.get(LoggingPane.class);
DockingRegion dockingPane = recaf.get(DockingManager.class).newRegion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class WindowManager implements Service {
public static final String WIN_INFO = "system-information";
public static final String WIN_SCRIPTS = "script-manager";
public static final String WIN_MAP_PROGRESS = "mapping-progress";
public static final String WIN_QUICK_NAV = "quick-nav";
// Manager instance data
private final WindowManagerConfig config;
private final ObservableList<Stage> activeWindows = new ObservableList<>();
Expand Down Expand Up @@ -182,6 +183,14 @@ public Stage getMappingPreviewWindow() {
return Objects.requireNonNull(getWindow(WIN_MAP_PROGRESS));
}

/**
* @return Window for quick navigation display.
*/
@Nonnull
public Stage getQuickNav() {
return Objects.requireNonNull(getWindow(WIN_QUICK_NAV));
}

@Nonnull
@Override
public String getServiceId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
@ApplicationScoped
public class KeybindingConfig extends BasicConfigContainer {
public static final String ID = "bind";
private static final String ID_QUICK_NAV = "quicknav";
private static final String ID_FIND = "editor.find";
private static final String ID_REPLACE = "editor.replace";
private static final String ID_SAVE = "editor.save";
Expand All @@ -48,6 +49,7 @@ public KeybindingConfig(@Nonnull GsonProvider gsonProvider) {

// We will only be storing one 'value' so that the UI can treat it as a singular element.
bundle = new BindingBundle(Arrays.asList(
createBindForPlatform(ID_QUICK_NAV, CONTROL, G),
createBindForPlatform(ID_FIND, CONTROL, F),
createBindForPlatform(ID_REPLACE, CONTROL, R),
createBindForPlatform(ID_SAVE, CONTROL, S),
Expand Down Expand Up @@ -75,6 +77,12 @@ public KeybindingConfig(@Nonnull GsonProvider gsonProvider) {
});
}

/**
* @return Keybinding for opening the quick-nav stage.
*/
@Nonnull
public Binding getQuickNav() {
return Objects.requireNonNull(bundle.get(ID_QUICK_NAV));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import javafx.scene.control.TextField;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.text.TextAlignment;
import org.kordamp.ikonli.carbonicons.CarbonIcons;
Expand Down Expand Up @@ -50,6 +51,14 @@ public ObservableList<String> getPastSearches() {
return pastSearches;
}

/**
* @return Property of the current search text.
*/
@Nonnull
public StringProperty getSearchTextProperty() {
return searchInput.textProperty();
}

/**
* <b>Note</b>: The base {@link AbstractSearchBar} does not tie into any search systems,
* so its up to implementors to ensure this is wired up properly.
Expand Down Expand Up @@ -116,8 +125,8 @@ public void setup() {
resultCount.setAlignment(Pos.CENTER);
resultCount.setTextAlignment(TextAlignment.CENTER);
bindResultCountDisplay(resultCount.textProperty());
resultCount.styleProperty().bind(hasResults.map(b -> {
if (b) {
resultCount.styleProperty().bind(hasResults.map(has -> {
if (has) {
return "-fx-text-fill: -color-fg-default;";
} else {
return "-fx-text-fill: red;";
Expand All @@ -141,6 +150,7 @@ public void setup() {
* Called at the end of {@link #setup()}.
*/
protected void setupLayout() {
HBox.setHgrow(searchInput, Priority.ALWAYS);
HBox searchLine = new HBox(searchInput, resultCount);
searchLine.setAlignment(Pos.CENTER_LEFT);
searchLine.setSpacing(10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
Expand All @@ -23,6 +22,7 @@
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import org.fxmisc.richtext.CodeArea;
import org.kordamp.ikonli.carbonicons.CarbonIcons;
import regexodus.Matcher;
Expand All @@ -45,7 +45,7 @@
@Dependent
public class SearchBar implements EditorComponent, EventHandler<KeyEvent> {
private final KeybindingConfig keys;
private Bar bar;
private FindAndReplaceSearchBar bar;

@Inject
public SearchBar(@Nonnull KeybindingConfig keys) {
Expand All @@ -54,7 +54,7 @@ public SearchBar(@Nonnull KeybindingConfig keys) {

@Override
public void install(@Nonnull Editor editor) {
bar = new Bar(editor);
bar = new FindAndReplaceSearchBar(editor);
NodeEvents.addKeyPressHandler(editor, this);
}

Expand Down Expand Up @@ -90,7 +90,7 @@ public void handle(KeyEvent event) {
/**
* The actual search bar.
*/
private static class Bar extends AbstractSearchBar {
private static class FindAndReplaceSearchBar extends AbstractSearchBar {
private final SimpleIntegerProperty lastResultIndex = new SimpleIntegerProperty(-1);
private final ObservableList<String> pastReplaces = FXCollections.observableArrayList();
private final ObservableList<Match> resultRanges = FXCollections.observableArrayList();
Expand All @@ -104,7 +104,7 @@ private static class Bar extends AbstractSearchBar {
private Button replace;
private Button replaceAll;

private Bar(@Nonnull Editor editor) {
private FindAndReplaceSearchBar(@Nonnull Editor editor) {
this.editor = editor;

setup();
Expand Down Expand Up @@ -160,10 +160,12 @@ protected void setupLayout() {
HBox prevAndNext = new HBox(prev, next);
prevAndNext.setAlignment(Pos.CENTER);
prevAndNext.setFillHeight(false);
HBox.setHgrow(searchInput, Priority.ALWAYS);
HBox searchLine = new HBox(searchInput, resultCount, prevAndNext, new Spacer(), close);
searchLine.setAlignment(Pos.CENTER_LEFT);
searchLine.setSpacing(10);
searchLine.setPadding(new Insets(0, 5, 0, 0));
HBox.setHgrow(replaceInput, Priority.ALWAYS);
replaceLine.getChildren().addAll(replaceInput, new Spacer(0), replace, replaceAll);
replaceLine.setAlignment(Pos.CENTER_LEFT);
replaceLine.setSpacing(10);
Expand Down
Loading

0 comments on commit 5066e90

Please sign in to comment.