Skip to content

Commit

Permalink
fix: improve file selecting logic (#33)
Browse files Browse the repository at this point in the history
* extract logic for opening file dialog

* fix platform issue

* fix typo

* delete error popup logic for aborting the operation
  • Loading branch information
hizumiaoba authored Apr 14, 2024
1 parent 4f4c241 commit 045742a
Showing 1 changed file with 32 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import javafx.scene.control.SpinnerValueFactory.IntegerSpinnerValueFactory;
import javafx.scene.control.TabPane;
import javafx.scene.control.TextField;
import javafx.stage.DirectoryChooser;
import javafx.stage.FileChooser;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -301,47 +300,50 @@ void onOpenSavesFolderBtnClick() {

@FXML
void onSelectBackupSavingFolderBtnClick() {
DirectoryChooser dc = new DirectoryChooser();
dc.setTitle("バックアップを保存するフォルダを選択してください。");
dc.setInitialDirectory(new File(System.getProperty("user.home")));
log.debug("awaiting for the user to select the backup saving folder.");
File f = dc.showDialog(null);
File f = openFileChooser("バックアップを保存するフォルダを選択してください。",
new File(System.getProperty("user.home")));
if (f == null) {
log.debug("Got nothing.");
return;
}
log.debug("Got the folder: {}", f.getAbsolutePath());
backupSavingFolderPathField.setText(f.getAbsolutePath());
assignPath(backupSavingFolderPathField, f);
}

@FXML
void onSelectLauncherExeBtnClick() {
FileChooser fc = new FileChooser();
fc.setTitle("ランチャーの実行ファイルを選択してください。");
fc.setInitialDirectory(new File(System.getProperty("user.home")));
log.debug("awaiting for the user to select the executable file.");
File f = fc.showOpenDialog(null);
void onSelectSavesFolderBtnClick() {
File f = openFileChooser("\".minecraft/saves\"フォルダを選択してください。",
new File(System.getProperty("user.home")));
if (f == null) {
log.debug("Got nothing.");
return;
}
log.debug("Got the file: {}", f.getAbsolutePath());
launcherExePathField.setText(f.getAbsolutePath());
assignPath(savesFolderPathField, f);
}

@FXML
void onSelectSavesFolderBtnClick() {
DirectoryChooser dc = new DirectoryChooser();
dc.setTitle("\".minecraft/saves\"フォルダを選択してください。");
dc.setInitialDirectory(new File(System.getProperty("user.home")));
log.debug("awaiting for the user to select the saves folder.");
File f = dc.showDialog(null);
if (f == null) {
log.debug("Got nothing.");
return;
}
log.debug("Got the folder: {}", f.getAbsolutePath());
savesFolderPathField.setText(f.getAbsolutePath());
void onSelectLauncherExeBtnClick() {
File f = openFileChooser("ランチャーの実行ファイルを選択してください。",
new File(System.getProperty("user.home")));
if (f == null) {
return;
}
assignPath(launcherExePathField, f);
}

private File openFileChooser(String title, File initialDir) {
FileChooser fc = new FileChooser();
fc.setTitle(title);
fc.setInitialDirectory(initialDir);
log.debug("awaiting for the user to select the file.");
File f = fc.showOpenDialog(null);
if (f == null) {
log.debug("Got nothing.");
return null;
}
return f;
}

private void assignPath(TextField injected, File target) {
log.debug("injecting the path: {}", target.getAbsolutePath());
injected.setText(target.getAbsolutePath());
}

@FXML
Expand Down

0 comments on commit 045742a

Please sign in to comment.