mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-11-04 21:36:45 +00:00
Dynamic menu language list
This commit is contained in:
parent
f5c79e33cd
commit
b33459f5d1
2 changed files with 29 additions and 25 deletions
|
@ -141,7 +141,10 @@ public class AppController implements Initializable {
|
||||||
private ToggleGroup theme;
|
private ToggleGroup theme;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private ToggleGroup language;
|
private ToggleGroup languages;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Menu languagesMenu;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private CheckMenuItem openWalletsInNewWindows;
|
private CheckMenuItem openWalletsInNewWindows;
|
||||||
|
@ -378,14 +381,7 @@ public class AppController implements Initializable {
|
||||||
selectedThemeToggle.ifPresent(toggle -> theme.selectToggle(toggle));
|
selectedThemeToggle.ifPresent(toggle -> theme.selectToggle(toggle));
|
||||||
setTheme(null);
|
setTheme(null);
|
||||||
|
|
||||||
Language configLanguage = Config.get().getLanguage();
|
prepareLanguages();
|
||||||
if(configLanguage == null) {
|
|
||||||
configLanguage = LanguagesManager.DEFAULT_LANGUAGE;
|
|
||||||
Config.get().setLanguage(configLanguage);
|
|
||||||
}
|
|
||||||
final Language selectedLanguage = configLanguage;
|
|
||||||
Optional<Toggle> selectedLanguageToggle = language.getToggles().stream().filter(toggle -> selectedLanguage.equals(toggle.getUserData())).findFirst();
|
|
||||||
selectedLanguageToggle.ifPresent(toggle -> language.selectToggle(toggle));
|
|
||||||
|
|
||||||
openWalletsInNewWindowsProperty.set(Config.get().isOpenWalletsInNewWindows());
|
openWalletsInNewWindowsProperty.set(Config.get().isOpenWalletsInNewWindows());
|
||||||
openWalletsInNewWindows.selectedProperty().bindBidirectional(openWalletsInNewWindowsProperty);
|
openWalletsInNewWindows.selectedProperty().bindBidirectional(openWalletsInNewWindowsProperty);
|
||||||
|
@ -444,6 +440,27 @@ public class AppController implements Initializable {
|
||||||
setNetworkLabel();
|
setNetworkLabel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void prepareLanguages() {
|
||||||
|
Language[] languagesList = Language.values();
|
||||||
|
for(Language language : languagesList) {
|
||||||
|
RadioMenuItem languageItem = new RadioMenuItem(LanguagesManager.getMessage("language." + language.getCode()));
|
||||||
|
languageItem.setMnemonicParsing(false);
|
||||||
|
languageItem.setToggleGroup(languages);
|
||||||
|
languageItem.setOnAction(this::setLanguage);
|
||||||
|
languageItem.setUserData(language);
|
||||||
|
languagesMenu.getItems().add(languageItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
Language configLanguage = Config.get().getLanguage();
|
||||||
|
if(configLanguage == null) {
|
||||||
|
configLanguage = LanguagesManager.DEFAULT_LANGUAGE;
|
||||||
|
Config.get().setLanguage(configLanguage);
|
||||||
|
}
|
||||||
|
final Language selectedLanguage = configLanguage;
|
||||||
|
Optional<Toggle> selectedLanguageToggle = languages.getToggles().stream().filter(toggle -> selectedLanguage.equals(toggle.getUserData())).findFirst();
|
||||||
|
selectedLanguageToggle.ifPresent(toggle -> languages.selectToggle(toggle));
|
||||||
|
}
|
||||||
|
|
||||||
private void registerShortcuts() {
|
private void registerShortcuts() {
|
||||||
org.controlsfx.tools.Platform platform = org.controlsfx.tools.Platform.getCurrent();
|
org.controlsfx.tools.Platform platform = org.controlsfx.tools.Platform.getCurrent();
|
||||||
if(platform == org.controlsfx.tools.Platform.OSX) {
|
if(platform == org.controlsfx.tools.Platform.OSX) {
|
||||||
|
@ -2358,7 +2375,7 @@ public class AppController implements Initializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLanguage(ActionEvent event) {
|
public void setLanguage(ActionEvent event) {
|
||||||
Language selectedLanguage = (Language)language.getSelectedToggle().getUserData();
|
Language selectedLanguage = (Language)languages.getSelectedToggle().getUserData();
|
||||||
if(Config.get().getLanguage() != selectedLanguage) {
|
if(Config.get().getLanguage() != selectedLanguage) {
|
||||||
Config.get().setLanguage(selectedLanguage);
|
Config.get().setLanguage(selectedLanguage);
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,7 @@
|
||||||
<ToggleGroup fx:id="theme"/>
|
<ToggleGroup fx:id="theme"/>
|
||||||
</fx:define>
|
</fx:define>
|
||||||
<fx:define>
|
<fx:define>
|
||||||
<ToggleGroup fx:id="language"/>
|
<ToggleGroup fx:id="languages"/>
|
||||||
</fx:define>
|
</fx:define>
|
||||||
<Menu fx:id="viewMenu" mnemonicParsing="false" text="View">
|
<Menu fx:id="viewMenu" mnemonicParsing="false" text="View">
|
||||||
<items>
|
<items>
|
||||||
|
@ -117,20 +117,7 @@
|
||||||
</RadioMenuItem>
|
</RadioMenuItem>
|
||||||
</items>
|
</items>
|
||||||
</Menu>
|
</Menu>
|
||||||
<Menu mnemonicParsing="false" text="%language">
|
<Menu fx:id="languagesMenu" mnemonicParsing="false" text="%language" />
|
||||||
<items>
|
|
||||||
<RadioMenuItem mnemonicParsing="false" text="%language.en" toggleGroup="$language" onAction="#setLanguage">
|
|
||||||
<userData>
|
|
||||||
<Language fx:constant="ENGLISH" />
|
|
||||||
</userData>
|
|
||||||
</RadioMenuItem>
|
|
||||||
<RadioMenuItem mnemonicParsing="false" text="%language.es" toggleGroup="$language" onAction="#setLanguage">
|
|
||||||
<userData>
|
|
||||||
<Language fx:constant="SPANISH" />
|
|
||||||
</userData>
|
|
||||||
</RadioMenuItem>
|
|
||||||
</items>
|
|
||||||
</Menu>
|
|
||||||
<SeparatorMenuItem />
|
<SeparatorMenuItem />
|
||||||
<CheckMenuItem fx:id="openWalletsInNewWindows" mnemonicParsing="false" text="Open Wallets In New Windows" onAction="#openWalletsInNewWindows"/>
|
<CheckMenuItem fx:id="openWalletsInNewWindows" mnemonicParsing="false" text="Open Wallets In New Windows" onAction="#openWalletsInNewWindows"/>
|
||||||
<CheckMenuItem fx:id="hideEmptyUsedAddresses" mnemonicParsing="false" text="Hide Empty Used Addresses" onAction="#hideEmptyUsedAddresses"/>
|
<CheckMenuItem fx:id="hideEmptyUsedAddresses" mnemonicParsing="false" text="Hide Empty Used Addresses" onAction="#hideEmptyUsedAddresses"/>
|
||||||
|
|
Loading…
Reference in a new issue