Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,19 @@ abstract class FileChooserPageBase protected constructor(
}
}

protected open fun loadPreferences() {
/**
* Loads the file previously saved in the settings, if any, and returns whether such a file was found.
* If not, it proposes a default file instead, which is not something the user has chosen or confirmed
* before, so the caller must not treat it as if it were.
*/
protected open fun loadPreferences(): Boolean {
val oldFile = preferences.get(PREF_SELECTED_FILE, null)
if (oldFile != null) {
return if (oldFile != null) {
fxFile.value = updateChosenFile(File(oldFile))
true
} else {
fxFile.value = proposeChosenFile()
false
}
}

Expand Down Expand Up @@ -265,8 +272,13 @@ abstract class FileChooserPageBase protected constructor(
// updated again. The wizard would stay disabled with no way out.
showError(null)
} else {
loadPreferences()
tryChosenFile(fxFile.value)
// Validate only a file the user chose and saved before; a self-proposed default is relative
// to the working directory and has nothing to do with what the user is about to pick here.
if (loadPreferences()) {
tryChosenFile(fxFile.value)
} else {
showError(null)
}
}
resetCenterPane()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,27 @@ class FileChooserPageBaseTest {
}

@Test
fun `a single file page still reports a missing file`() = runBlocking {
fun `a single file page does not report an error about its own proposed file`() = runBlocking {
withContext(Dispatchers.JavaFx) {
val page = createPage(allowMultipleChoice = false)

page.setActive(true)

assertNull(page.errorMessage.value,
"the page reports an error about a file it proposed itself, not one the user chose or saved before")
}
}

@Test
fun `a single file page still reports a previously saved file that is now missing`() = runBlocking {
withContext(Dispatchers.JavaFx) {
val page = createPage(allowMultipleChoice = false)
page.preferences.put(PREF_SELECTED_FILE, File(MISSING_FILE_NAME).absolutePath)

page.setActive(true)

assertFalse(page.errorMessage.value.isNullOrBlank(),
"a single missing file must still be reported, it is shown in the UI and can be corrected")
"a file the user chose and saved before, which has since gone missing, must still be reported")
}
}

Expand Down
Loading