2023-02-20 06:44:47 +13:00
|
|
|
package io.xpipe.app.browser;
|
|
|
|
|
|
|
|
import atlantafx.base.controls.Spacer;
|
2023-05-21 01:49:58 +12:00
|
|
|
import io.xpipe.app.comp.base.ModalOverlayComp;
|
|
|
|
import io.xpipe.app.fxcomps.Comp;
|
2023-02-20 06:44:47 +13:00
|
|
|
import io.xpipe.app.fxcomps.SimpleComp;
|
2023-05-21 01:49:58 +12:00
|
|
|
import io.xpipe.app.fxcomps.SimpleCompStructure;
|
|
|
|
import io.xpipe.app.fxcomps.augment.ContextMenuAugment;
|
2023-03-23 00:42:47 +13:00
|
|
|
import io.xpipe.app.fxcomps.util.PlatformThread;
|
2023-04-06 02:41:02 +12:00
|
|
|
import io.xpipe.app.fxcomps.util.Shortcuts;
|
2023-02-20 06:44:47 +13:00
|
|
|
import javafx.geometry.Insets;
|
2023-05-21 01:49:58 +12:00
|
|
|
import javafx.scene.control.Button;
|
|
|
|
import javafx.scene.control.MenuButton;
|
|
|
|
import javafx.scene.control.ToolBar;
|
2023-04-06 02:41:02 +12:00
|
|
|
import javafx.scene.input.KeyCode;
|
|
|
|
import javafx.scene.input.KeyCodeCombination;
|
2023-05-21 01:49:58 +12:00
|
|
|
import javafx.scene.input.KeyCombination;
|
2023-05-22 02:12:06 +12:00
|
|
|
import javafx.scene.input.MouseButton;
|
2023-05-21 01:49:58 +12:00
|
|
|
import javafx.scene.layout.Priority;
|
|
|
|
import javafx.scene.layout.Region;
|
|
|
|
import javafx.scene.layout.VBox;
|
2023-02-20 06:44:47 +13:00
|
|
|
import org.kordamp.ikonli.javafx.FontIcon;
|
|
|
|
|
2023-05-21 01:49:58 +12:00
|
|
|
import static io.xpipe.app.browser.BrowserFileListModel.PREDICATE_NOT_HIDDEN;
|
2023-02-20 06:44:47 +13:00
|
|
|
|
|
|
|
public class OpenFileSystemComp extends SimpleComp {
|
|
|
|
|
|
|
|
private final OpenFileSystemModel model;
|
|
|
|
|
|
|
|
public OpenFileSystemComp(OpenFileSystemModel model) {
|
|
|
|
this.model = model;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Region createSimple() {
|
2023-05-21 01:49:58 +12:00
|
|
|
var alertOverlay = new ModalOverlayComp(
|
|
|
|
Comp.of(() -> createContent()),
|
|
|
|
model.getOverlay());
|
|
|
|
return alertOverlay.createRegion();
|
|
|
|
}
|
|
|
|
|
|
|
|
private Region createContent() {
|
|
|
|
var backBtn = new Button(null, new FontIcon("fth-arrow-left"));
|
2023-02-20 06:44:47 +13:00
|
|
|
backBtn.setOnAction(e -> model.back());
|
|
|
|
backBtn.disableProperty().bind(model.getHistory().canGoBackProperty().not());
|
|
|
|
|
2023-05-21 01:49:58 +12:00
|
|
|
var forthBtn = new Button(null, new FontIcon("fth-arrow-right"));
|
2023-02-20 06:44:47 +13:00
|
|
|
forthBtn.setOnAction(e -> model.forth());
|
|
|
|
forthBtn.disableProperty().bind(model.getHistory().canGoForthProperty().not());
|
|
|
|
|
|
|
|
var refreshBtn = new Button(null, new FontIcon("mdmz-refresh"));
|
|
|
|
refreshBtn.setOnAction(e -> model.refresh());
|
2023-04-06 02:41:02 +12:00
|
|
|
Shortcuts.addShortcut(refreshBtn, new KeyCodeCombination(KeyCode.F5));
|
2023-02-20 06:44:47 +13:00
|
|
|
|
|
|
|
var terminalBtn = new Button(null, new FontIcon("mdi2c-code-greater-than"));
|
2023-05-21 01:49:58 +12:00
|
|
|
terminalBtn.setOnAction(
|
|
|
|
e -> model.openTerminalAsync(model.getCurrentPath().get()));
|
2023-03-23 00:42:47 +13:00
|
|
|
terminalBtn.disableProperty().bind(PlatformThread.sync(model.getNoDirectory()));
|
2023-02-20 06:44:47 +13:00
|
|
|
|
2023-05-21 01:49:58 +12:00
|
|
|
var menuButton = new MenuButton(null, new FontIcon("mdral-folder_open"));
|
2023-05-22 02:12:06 +12:00
|
|
|
new ContextMenuAugment<>(event -> event.getButton() == MouseButton.PRIMARY, () -> new BrowserContextMenu(model, null)).augment(new SimpleCompStructure<>(menuButton));
|
2023-02-20 06:44:47 +13:00
|
|
|
|
2023-05-21 01:49:58 +12:00
|
|
|
var filter = new BrowserFilterComp(model.getFilter()).createStructure();
|
|
|
|
Shortcuts.addShortcut(filter.toggleButton(), new KeyCodeCombination(KeyCode.F, KeyCombination.SHORTCUT_DOWN));
|
2023-02-25 11:16:27 +13:00
|
|
|
|
2023-02-20 06:44:47 +13:00
|
|
|
var topBar = new ToolBar();
|
2023-05-21 01:49:58 +12:00
|
|
|
topBar.getItems()
|
|
|
|
.setAll(backBtn, forthBtn, new Spacer(10), new BrowserNavBar(model).createRegion(), filter.get(), refreshBtn, terminalBtn, menuButton);
|
2023-02-20 06:44:47 +13:00
|
|
|
|
2023-05-21 01:49:58 +12:00
|
|
|
var directoryView = new BrowserFileListComp(model.getFileList()).createRegion();
|
2023-02-20 06:44:47 +13:00
|
|
|
|
2023-05-09 11:12:53 +12:00
|
|
|
var root = new VBox(topBar, directoryView);
|
2023-05-21 01:49:58 +12:00
|
|
|
root.getChildren().add(new BrowserStatusBarComp(model).createRegion());
|
2023-02-20 06:44:47 +13:00
|
|
|
VBox.setVgrow(directoryView, Priority.ALWAYS);
|
|
|
|
root.setPadding(Insets.EMPTY);
|
|
|
|
model.getFileList().predicateProperty().set(PREDICATE_NOT_HIDDEN);
|
2023-05-21 01:49:58 +12:00
|
|
|
return root;
|
2023-02-20 06:44:47 +13:00
|
|
|
}
|
|
|
|
}
|