Explorar o código

moved the context menu creation code to the fxml file

Jan-Peter Klein hai 1 ano
pai
achega
50e96095ba

+ 0 - 31
src/main/java/org/cryptomator/ui/mainwindow/VaultListController.java

@@ -7,8 +7,6 @@ import org.cryptomator.cryptofs.CryptoFileSystemProvider;
 import org.cryptomator.cryptofs.DirStructure;
 import org.cryptomator.ui.addvaultwizard.AddVaultWizardComponent;
 import org.cryptomator.ui.common.FxController;
-import org.cryptomator.ui.controls.FontAwesome5Icon;
-import org.cryptomator.ui.controls.FontAwesome5IconView;
 import org.cryptomator.ui.removevault.RemoveVaultComponent;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -25,9 +23,7 @@ import javafx.collections.ObservableList;
 import javafx.event.Event;
 import javafx.fxml.FXML;
 import javafx.scene.control.Button;
-import javafx.scene.control.ContextMenu;
 import javafx.scene.control.ListView;
-import javafx.scene.control.MenuItem;
 import javafx.scene.input.ContextMenuEvent;
 import javafx.scene.input.DragEvent;
 import javafx.scene.input.KeyCode;
@@ -35,7 +31,6 @@ import javafx.scene.input.KeyEvent;
 import javafx.scene.input.MouseEvent;
 import javafx.scene.input.TransferMode;
 import javafx.scene.layout.StackPane;
-import javafx.scene.text.TextAlignment;
 import javafx.stage.Stage;
 import java.io.File;
 import java.io.IOException;
@@ -146,33 +141,7 @@ public class VaultListController implements FxController {
 		root.setOnDragDropped(this::handleDragEvent);
 		root.setOnDragExited(this::handleDragEvent);
 
-		createAddVaultContextMenu();
-	}
-
-	private void createAddVaultContextMenu() {
-		ContextMenu contextMenu = new ContextMenu();
-		FontAwesome5IconView newIcon = new FontAwesome5IconView();
-		newIcon.setGlyph(FontAwesome5Icon.PLUS);
-		newIcon.setTextAlignment(TextAlignment.CENTER);
-		newIcon.setWrappingWidth(14);
-
-		MenuItem newVaultMenuItem = new MenuItem(resourceBundle.getString("main.vaultlist.addVaultBtn.menuItemNew"), newIcon);
-		newVaultMenuItem.setOnAction(event -> didClickAddNewVault());
-		newVaultMenuItem.getStyleClass().add("add-vault-menu-item");
-
-		FontAwesome5IconView existingIcon = new FontAwesome5IconView();
-		existingIcon.setGlyph(FontAwesome5Icon.FOLDER_OPEN);
-		existingIcon.setTextAlignment(TextAlignment.CENTER);
-		existingIcon.setWrappingWidth(14);
-
-		MenuItem existingVaultMenuItem = new MenuItem(resourceBundle.getString("main.vaultlist.addVaultBtn.menuItemExisting"), existingIcon);
-		existingVaultMenuItem.setOnAction(event -> didClickAddExistingVault());
-		existingVaultMenuItem.getStyleClass().add("add-vault-menu-item");
-
-		contextMenu.getItems().addAll(newVaultMenuItem, existingVaultMenuItem);
-
 		addVaultBtn.addEventFilter(ContextMenuEvent.CONTEXT_MENU_REQUESTED, Event::consume);
-		addVaultBtn.setContextMenu(contextMenu);
 	}
 
 	@FXML

+ 18 - 0
src/main/resources/fxml/vault_list.fxml

@@ -8,6 +8,8 @@
 <?import javafx.scene.layout.StackPane?>
 <?import javafx.scene.layout.VBox?>
 <?import javafx.scene.shape.Arc?>
+<?import javafx.scene.control.ContextMenu?>
+<?import javafx.scene.control.MenuItem?>
 <StackPane xmlns:fx="http://javafx.com/fxml"
 		   xmlns="http://javafx.com/javafx"
 		   fx:id="root"
@@ -30,6 +32,22 @@
 			<graphic>
 				<FontAwesome5IconView glyph="CARET_DOWN"/>
 			</graphic>
+			<contextMenu>
+				<ContextMenu>
+					<items>
+						<MenuItem styleClass="add-vault-menu-item" text="%main.vaultlist.addVaultBtn.menuItemNew" onAction="#didClickAddNewVault" >
+							<graphic>
+								<FontAwesome5IconView glyph="PLUS" textAlignment="CENTER" wrappingWidth="14" />
+							</graphic>
+						</MenuItem>
+						<MenuItem styleClass="add-vault-menu-item" text="%main.vaultlist.addVaultBtn.menuItemExisting" onAction="#didClickAddExistingVault" >
+							<graphic>
+								<FontAwesome5IconView glyph="PLUS" textAlignment="CENTER" wrappingWidth="14" />
+							</graphic>
+						</MenuItem>
+					</items>
+				</ContextMenu>
+			</contextMenu>
 		</Button>
 	</VBox>
 	<Region styleClass="drag-n-drop-border" visible="${controller.draggingVaultOver}"/>