Fix history context menu

This commit is contained in:
crschnick 2023-12-10 16:46:05 +00:00
parent 695d478878
commit 08bf3669ba
5 changed files with 52 additions and 21 deletions

View file

@ -28,9 +28,7 @@ import javafx.scene.input.MouseButton;
import javafx.scene.layout.Region;
import org.kordamp.ikonli.javafx.FontIcon;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
public class BrowserNavBar extends SimpleComp {
@ -168,31 +166,56 @@ public class BrowserNavBar extends SimpleComp {
var cm = new ContextMenu();
var f = model.getHistory().getForwardHistory(8).stream().filter(Objects::nonNull).toList();
new LinkedList<>(f)
.descendingIterator()
.forEachRemaining(s -> cm.getItems().add(new MenuItem(s)));
var f = model.getHistory().getForwardHistory(8).stream().toList();
for (int i = f.size() - 1; i >= 0; i--) {
if (f.get(i) == null) {
continue;
}
var mi = new MenuItem(f.get(i));
int target = i + 1;
mi.setOnAction(event -> {
ThreadHelper.runFailableAsync(() -> {
BooleanScope.executeExclusive(model.getBusy(), () -> {
model.forthSync(target);
});
});
event.consume();
});
cm.getItems().add(mi);
}
if (!f.isEmpty()) {
cm.getItems().add(new SeparatorMenuItem());
}
if (model.getHistory().getCurrent() != null) {
var current = new MenuItem("> " + model.getHistory().getCurrent());
var current = new MenuItem(model.getHistory().getCurrent());
current.setDisable(true);
cm.getItems().add(current);
}
var b = model.getHistory().getBackwardHistory(Integer.MAX_VALUE).stream().filter(Objects::nonNull).toList();
var b = model.getHistory().getBackwardHistory(Integer.MAX_VALUE).stream().toList();
if (!b.isEmpty()) {
cm.getItems().add(new SeparatorMenuItem());
}
b.forEach(s -> {
cm.getItems().add(new MenuItem(s));
});
for (int i = 0; i < b.size(); i++) {
if (b.get(i) == null) {
continue;
}
for (int i = 15; i > 0; i--) {
cm.getItems().add(new MenuItem("abc"));
var mi = new MenuItem(b.get(i));
int target = i + 1;
mi.setOnAction(event -> {
ThreadHelper.runFailableAsync(() -> {
BooleanScope.executeExclusive(model.getBusy(), () -> {
model.backSync(target);
});
});
event.consume();
});
cm.getItems().add(mi);
}
cm.addEventHandler(Menu.ON_SHOWING, e -> {
Node content = cm.getSkin().getNode();
if (content instanceof Region r) {

View file

@ -53,18 +53,26 @@ public final class OpenFileSystemHistory {
}
public String back() {
return back(1);
}
public String back(int i) {
if (!canGoBack.get()) {
return null;
}
cursor.set(cursor.get() - 1);
cursor.set(Math.max(0, cursor.get() - i));
return history.get(cursor.get());
}
public String forth() {
return forth(1);
}
public String forth(int i) {
if (!canGoForth.get()) {
return null;
}
cursor.set(cursor.get() + 1);
cursor.set(Math.min(history.size() - 1, cursor.get() + i));
return history.get(cursor.get());
}

View file

@ -419,11 +419,11 @@ public final class OpenFileSystemModel {
});
}
public void backSync() throws Exception {
cdSyncWithoutCheck(history.back());
public void backSync(int i) throws Exception {
cdSyncWithoutCheck(history.back(i));
}
public void forthSync() throws Exception {
cdSyncWithoutCheck(history.forth());
public void forthSync(int i) throws Exception {
cdSyncWithoutCheck(history.forth(i));
}
}

View file

@ -19,7 +19,7 @@ public class BackAction implements LeafAction {
@Override
public void execute(OpenFileSystemModel model, List<BrowserEntry> entries) throws Exception {
model.backSync();
model.backSync(1);
}
@Override

View file

@ -19,7 +19,7 @@ public class ForwardAction implements LeafAction {
@Override
public void execute(OpenFileSystemModel model, List<BrowserEntry> entries) throws Exception {
model.forthSync();
model.forthSync(1);
}
@Override