mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-17 18:21:26 +00:00
add contextMenu to eventListCell
This commit is contained in:
@@ -20,6 +20,7 @@ public enum FontAwesome5Icon {
|
||||
CROWN("\uF521"), //
|
||||
DONATE("\uF4B9"), //
|
||||
EDIT("\uF044"), //
|
||||
ELLIPSIS_V("\uF142"), //
|
||||
EXCHANGE_ALT("\uF362"), //
|
||||
EXCLAMATION("\uF12A"), //
|
||||
EXCLAMATION_CIRCLE("\uF06A"), //
|
||||
|
||||
@@ -6,32 +6,40 @@ import org.cryptomator.event.UpdateEvent;
|
||||
import org.cryptomator.event.VaultEvent;
|
||||
import org.cryptomator.ui.common.FxController;
|
||||
import org.cryptomator.ui.controls.FontAwesome5Icon;
|
||||
import org.cryptomator.ui.controls.FontAwesome5IconView;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.scene.layout.HBox;
|
||||
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.util.ResourceBundle;
|
||||
|
||||
public class EventListCellController implements FxController {
|
||||
|
||||
private final ObservableList<Event> eventList;
|
||||
private final ResourceBundle resourceBundle;
|
||||
private final ObjectProperty<Event> event;
|
||||
private final ObservableValue<String> message;
|
||||
private final ObservableValue<String> description;
|
||||
private final ObservableValue<FontAwesome5Icon> icon;
|
||||
|
||||
public FontAwesome5IconView eventIcon;
|
||||
public HBox eventListCell;
|
||||
@FXML
|
||||
ContextMenu eventActionsContextMenu;
|
||||
@FXML
|
||||
Button eventActionsButton;
|
||||
|
||||
@Inject
|
||||
public EventListCellController(ResourceBundle resourceBundle) {
|
||||
public EventListCellController(ObservableList<Event> eventList, ResourceBundle resourceBundle) {
|
||||
this.eventList = eventList;
|
||||
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.message = ObservableUtil.mapWithDefault(event, e -> e.getClass().getName(), "");
|
||||
this.description = ObservableUtil.mapWithDefault(event, this::selectDescription, "");
|
||||
this.icon = ObservableUtil.mapWithDefault(event, this::selectIcon, FontAwesome5Icon.BELL);
|
||||
}
|
||||
|
||||
@@ -48,11 +56,24 @@ public class EventListCellController implements FxController {
|
||||
|
||||
private String selectDescription(Event e) {
|
||||
return switch (e) {
|
||||
case UpdateEvent(_,String newVersion) -> resourceBundle.getString("preferences.updates.updateAvailable").formatted(newVersion);
|
||||
case UpdateEvent(_, String newVersion) -> resourceBundle.getString("preferences.updates.updateAvailable").formatted(newVersion);
|
||||
case VaultEvent _ -> "A vault is weird!";
|
||||
};
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void toggleEventActionsMenu(ActionEvent actionEvent) {
|
||||
if (eventActionsContextMenu.isShowing()) {
|
||||
eventActionsContextMenu.hide();
|
||||
} else {
|
||||
eventActionsContextMenu.show(eventActionsButton, Side.BOTTOM, 0.0, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void remove() {
|
||||
eventList.remove(event.getValue());
|
||||
}
|
||||
|
||||
//-- property accessors --
|
||||
public ObservableValue<String> messageProperty() {
|
||||
@@ -78,5 +99,4 @@ public class EventListCellController implements FxController {
|
||||
public FontAwesome5Icon getIcon() {
|
||||
return icon.getValue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
<?import javafx.scene.layout.HBox?>
|
||||
<?import javafx.scene.layout.Region?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<?import org.cryptomator.ui.controls.FontAwesome5IconView?>
|
||||
<VBox xmlns:fx="http://javafx.com/fxml"
|
||||
xmlns="http://javafx.com/javafx"
|
||||
fx:controller="org.cryptomator.ui.eventview.EventViewController"
|
||||
@@ -16,7 +17,11 @@
|
||||
>
|
||||
<HBox styleClass="button-bar">
|
||||
<Region HBox.hgrow="ALWAYS"/>
|
||||
<Button text="Clear" styleClass="button-right" onAction="#clearEventList" />
|
||||
<Button styleClass="button-right" onAction="#clearEventList" contentDisplay="GRAPHIC_ONLY">
|
||||
<graphic>
|
||||
<FontAwesome5IconView glyph="TRASH" glyphSize="16"/>
|
||||
</graphic>
|
||||
</Button>
|
||||
</HBox>
|
||||
<ListView fx:id="eventListView" fixedCellSize="60"/>
|
||||
</VBox>
|
||||
|
||||
@@ -5,9 +5,11 @@
|
||||
<?import javafx.scene.layout.HBox?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.ContextMenu?>
|
||||
<?import javafx.scene.control.MenuItem?>
|
||||
<HBox xmlns:fx="http://javafx.com/fxml"
|
||||
xmlns="http://javafx.com/javafx"
|
||||
fx:id="eventListCell"
|
||||
fx:controller="org.cryptomator.ui.eventview.EventListCellController"
|
||||
prefHeight="60"
|
||||
prefWidth="200"
|
||||
@@ -18,10 +20,23 @@
|
||||
</padding>
|
||||
<!-- Remark Check the containing list view for a fixed cell size before editing height properties -->
|
||||
<VBox alignment="CENTER" minWidth="20">
|
||||
<FontAwesome5IconView fx:id="eventIcon" glyph="BELL" HBox.hgrow="NEVER" glyphSize="16"/>
|
||||
<FontAwesome5IconView glyph="${controller.icon}" HBox.hgrow="NEVER" glyphSize="16"/>
|
||||
</VBox>
|
||||
<VBox spacing="4" HBox.hgrow="ALWAYS">
|
||||
<Label styleClass="header-label" text="${controller.message}"/>
|
||||
<Label styleClass="detail-label" text="${controller.description}" textOverrun="CENTER_ELLIPSIS" />
|
||||
</VBox>
|
||||
<Button fx:id="eventActionsButton" contentDisplay="GRAPHIC_ONLY" onAction="#toggleEventActionsMenu">
|
||||
<graphic>
|
||||
<FontAwesome5IconView glyph="ELLIPSIS_V" glyphSize="16"/>
|
||||
</graphic>
|
||||
</Button>
|
||||
|
||||
<fx:define>
|
||||
<ContextMenu fx:id="eventActionsContextMenu">
|
||||
<items>
|
||||
<MenuItem styleClass="add-vault-menu-item" text="Dismiss" onAction="#remove" />
|
||||
</items>
|
||||
</ContextMenu>
|
||||
</fx:define>
|
||||
</HBox>
|
||||
|
||||
Reference in New Issue
Block a user