瀏覽代碼

Select updates tab when showing preferences window and an update is available

Sebastian Stenzel 6 年之前
父節點
當前提交
e32fbc1d79

+ 28 - 1
main/ui/src/main/java/org/cryptomator/ui/preferences/PreferencesController.java

@@ -1,13 +1,40 @@
 package org.cryptomator.ui.preferences;
 
+import javafx.beans.binding.BooleanBinding;
+import javafx.fxml.FXML;
+import javafx.scene.control.Tab;
+import javafx.scene.control.TabPane;
+import javafx.stage.Stage;
+import javafx.stage.WindowEvent;
 import org.cryptomator.ui.common.FxController;
+import org.cryptomator.ui.fxapp.UpdateChecker;
 
 import javax.inject.Inject;
 
 @PreferencesScoped
 public class PreferencesController implements FxController {
 
+	private final Stage window;
+	private final BooleanBinding updateAvailable;
+	public TabPane tabPane;
+	public Tab generalTab;
+	public Tab updatesTab;
+
 	@Inject
-	public PreferencesController() {}
+	public PreferencesController(@PreferencesWindow Stage window, UpdateChecker updateChecker) {
+		this.window = window;
+		this.updateAvailable = updateChecker.latestVersionProperty().isNotNull();
+	}
+
+	@FXML
+	public void initialize() {
+		window.setOnShowing(this::windowWillAppear);
+	}
+
+	private void windowWillAppear(WindowEvent windowEvent) {
+		if (updateAvailable.get()) {
+			tabPane.getSelectionModel().select(updatesTab);
+		}
+	}
 
 }

+ 3 - 2
main/ui/src/main/resources/fxml/preferences.fxml

@@ -4,17 +4,18 @@
 <?import javafx.scene.control.TabPane?>
 <TabPane xmlns="http://javafx.com/javafx"
 		 xmlns:fx="http://javafx.com/fxml"
+		 fx:id="tabPane"
 		 fx:controller="org.cryptomator.ui.preferences.PreferencesController"
 		 side="TOP"
 		 tabClosingPolicy="UNAVAILABLE"
 		 tabDragPolicy="FIXED">
 	<tabs>
-		<Tab text="TODO General">
+		<Tab fx:id="generalTab" text="TODO General">
 			<content>
 				<fx:include source="/fxml/preferences_general.fxml"/>
 			</content>
 		</Tab>
-		<Tab text="TODO Updates">
+		<Tab fx:id="updatesTab" text="TODO Updates">
 			<content>
 				<fx:include source="/fxml/preferences_updates.fxml"/>
 			</content>