show event specific context menu

This commit is contained in:
Armin Schrenk
2025-02-18 18:32:06 +01:00
parent f8a83c9cc8
commit c39710ede0
4 changed files with 66 additions and 16 deletions

View File

@@ -263,7 +263,7 @@ public class Vault {
private void consumeVaultEvent(FilesystemEvent e) {
long timestamp = Instant.now().toEpochMilli();
Platform.runLater(() -> eventQueue.addLast(new VaultEvent(timestamp, vaultSettings.id, vaultSettings.path.get().toString(), e)));
Platform.runLater(() -> eventQueue.addLast(new VaultEvent(timestamp, this, e)));
}
// ******************************************************************************

View File

@@ -1,13 +1,14 @@
package org.cryptomator.event;
import org.cryptomator.common.vaults.Vault;
import org.cryptomator.cryptofs.event.FilesystemEvent;
import java.time.Instant;
public record VaultEvent(long timestamp, String vaultId, String displayName, FilesystemEvent actualEvent) implements Event {
public record VaultEvent(long timestamp, Vault v, FilesystemEvent actualEvent) implements Event {
public VaultEvent(String vaultId, String displayName, FilesystemEvent actualEvent) {
this(Instant.now().toEpochMilli(), vaultId, displayName, actualEvent);
public VaultEvent(Vault v, FilesystemEvent actualEvent) {
this(Instant.now().toEpochMilli(), v, actualEvent);
}
@Override

View File

@@ -1,6 +1,9 @@
package org.cryptomator.ui.eventview;
import org.cryptomator.common.ObservableUtil;
import org.cryptomator.common.vaults.Vault;
import org.cryptomator.cryptofs.event.ConflictResolvedEvent;
import org.cryptomator.cryptofs.event.FilesystemEvent;
import org.cryptomator.event.Event;
import org.cryptomator.event.UpdateEvent;
import org.cryptomator.event.VaultEvent;
@@ -8,20 +11,24 @@ import org.cryptomator.ui.common.FxController;
import org.cryptomator.ui.controls.FontAwesome5Icon;
import javax.inject.Inject;
import javafx.application.Application;
import javafx.beans.Observable;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.value.ObservableValue;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.geometry.Side;
import javafx.scene.control.Button;
import javafx.scene.control.ContextMenu;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.ResourceBundle;
public class EventListCellController implements FxController {
private final ObservableList<Event> eventList;
private final ObservableList<Event> events;
private final Application app;
private final ResourceBundle resourceBundle;
private final ObjectProperty<Event> event;
private final ObservableValue<String> message;
@@ -29,18 +36,29 @@ public class EventListCellController implements FxController {
private final ObservableValue<FontAwesome5Icon> icon;
@FXML
ContextMenu eventActionsContextMenu;
ContextMenu basicEventActions;
@FXML
ContextMenu conflictResoledEventActions;
@FXML
Button eventActionsButton;
@Inject
public EventListCellController(ObservableList<Event> eventList, ResourceBundle resourceBundle) {
this.eventList = eventList;
public EventListCellController(ObservableList<Event> events, Application app, ResourceBundle resourceBundle) {
this.events = events;
this.app = app;
this.resourceBundle = resourceBundle;
this.event = new SimpleObjectProperty<>(null);
this.message = ObservableUtil.mapWithDefault(event, e -> e.getClass().getName(), "");
this.description = ObservableUtil.mapWithDefault(event, this::selectDescription, "");
this.icon = ObservableUtil.mapWithDefault(event, this::selectIcon, FontAwesome5Icon.BELL);
event.addListener(this::hideContextMenus);
}
private void hideContextMenus(Observable observable, Event oldValue, Event newValue) {
//hide all context menus
basicEventActions.hide();
conflictResoledEventActions.hide();
}
public void setEvent(Event item) {
@@ -62,17 +80,41 @@ public class EventListCellController implements FxController {
}
@FXML
public void toggleEventActionsMenu(ActionEvent actionEvent) {
if (eventActionsContextMenu.isShowing()) {
eventActionsContextMenu.hide();
} else {
eventActionsContextMenu.show(eventActionsButton, Side.BOTTOM, 0.0, 0.0);
public void toggleEventActionsMenu() {
var e = event.get();
if(e != null) {
var contextMenu = switch (e) {
case VaultEvent _ -> conflictResoledEventActions;
default -> basicEventActions;
};
if (contextMenu.isShowing()) {
contextMenu.hide();
} else {
contextMenu.show(eventActionsButton, Side.BOTTOM, 0.0, 0.0);
}
}
}
@FXML
public void remove() {
eventList.remove(event.getValue());
events.remove(event.getValue());
}
@FXML
public void openVaultStoragePath() {
if(event.getValue() instanceof VaultEvent(_, Vault v, _)) {
app.getHostServices().showDocument(v.getPath().toUri().toString());
}
}
@FXML
public void showResolvedConflict() {
if(event.getValue() instanceof VaultEvent(_, Vault v, FilesystemEvent fse) && fse instanceof ConflictResolvedEvent cre) {
if(v.isUnlocked()) {
//TODO
}
}
}
//-- property accessors --