Skip to content

Commit

Permalink
Bugfixes:
Browse files Browse the repository at this point in the history
* local file save would create the file before user selects the file name
* Ctrl+Enter now works in the text field if user types a new file name when saving
  • Loading branch information
dbarashev committed Jun 2, 2020
1 parent 2bee42e commit cc2dccb
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class BrowserPaneBuilder<T: FolderItem>(
private lateinit var onSelectionChange: OnItemAction<T>
private lateinit var onLaunch: OnItemAction<T>
private lateinit var onOpenDirectory: OnItemAction<T>
private lateinit var onNameTyped: (filename: String, matchedItems: List<T>) -> Unit
private lateinit var onNameTyped: (filename: String, matchedItems: List<T>, withEnter: Boolean, withControl: Boolean) -> Unit
private var validationSupport: ValidationSupport = ValidationSupport()
private lateinit var i18n: Localizer

Expand All @@ -130,7 +130,7 @@ class BrowserPaneBuilder<T: FolderItem>(
onOpenDirectory: OnItemAction<T> = {},
onDelete: OnItemAction<T> = {},
onLock: OnItemAction<T> = {},
onNameTyped: (filename: String, matchedItems: List<T>) -> Unit = {_,_ ->},
onNameTyped: (filename: String, matchedItems: List<T>, withEnter: Boolean, withControl: Boolean) -> Unit = {_,_, _, _ ->},
canLock: BooleanProperty = SimpleBooleanProperty(false),
canDelete: ReadOnlyBooleanProperty = SimpleBooleanProperty(false),
itemActionFactory: ItemActionFactory<T> = Function { Collections.emptyMap() },
Expand Down Expand Up @@ -245,13 +245,13 @@ class BrowserPaneBuilder<T: FolderItem>(
listView.selectedResource.ifPresent { item -> selectItem(item, withEnter, withControl) }
}

fun onFilenameEnter(withEnter: Boolean) {
fun onFilenameEnter(withEnter: Boolean, withControl: Boolean) {
val filtered = listView.doFilter(filename.text)
if (filtered.size == 1 && withEnter) {
selectItem(filtered[0], withEnter, withEnter)
}
listView.filter(filename.text)
onNameTyped(filename.text, filtered)
onNameTyped(filename.text, filtered, withEnter, withControl)
}

listView.listView.selectionModel.selectedIndices.addListener(ListChangeListener {
Expand Down
3 changes: 3 additions & 0 deletions ganttproject/src/biz/ganttproject/storage/Document.kt
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ interface OnlineDocument {
}

fun (Document).asLocalDocument(): FileDocument? {
if (this is FileDocument) {
return this
}
if (this is ProxyDocument) {
if (this.realDocument is FileDocument) {
return this.realDocument as FileDocument
Expand Down
6 changes: 3 additions & 3 deletions ganttproject/src/biz/ganttproject/storage/FolderView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ fun <T : FolderItem> connect(
* - withEnter == true may open a folder or do something with file, depending on what is selected
*/
selectItem: (withEnter: Boolean, withControl: Boolean) -> Unit,
onFilenameEnter: (withEnter: Boolean) -> Unit) {
onFilenameEnter: (withEnter: Boolean, withControl: Boolean) -> Unit) {
listView.listView.onMouseClicked = EventHandler { evt ->
val dblClick = evt.clickCount == 2
selectItem(dblClick, dblClick)
Expand Down Expand Up @@ -408,10 +408,10 @@ fun <T : FolderItem> connect(
when (keyEvent.code) {
KeyCode.DOWN -> listView.requestFocus()
KeyCode.ENTER -> {
onFilenameEnter(true)
onFilenameEnter(true, keyEvent.isControlDown || keyEvent.isMetaDown)
}
else -> {
onFilenameEnter(false)
onFilenameEnter(false, keyEvent.isControlDown || keyEvent.isMetaDown)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class StorageDialogBuilder(
private val myDialogUi = DialogUi(dialogBuildApi) { myNotificationPane!!}

init {
// This will be called when user opens a project.
myDocumentReceiver = Consumer { document: Document ->
myDialogUi.toggleProgress(true)
val onFinish = Channel<Boolean>()
Expand All @@ -82,6 +83,7 @@ class StorageDialogBuilder(
}
}
}
// This will be called when user saves a project.
myDocumentUpdater = Consumer { document ->
myDialogUi.toggleProgress(true)
val onFinish = Channel<Boolean>()
Expand All @@ -91,6 +93,9 @@ class StorageDialogBuilder(
} else {
myProject.document.setMirror(document)
}
if (document.isLocal) {
document.asLocalDocument()?.create()
}
projectUi.saveProject(myProject, onFinish)
onFinish.receive()
myDialogUi.toggleProgress(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,15 @@ class GPCloudBrowserPane(

}

fun onNameTyped(filename: String, itemsMatched: List<FolderItem>) {
fun onNameTyped(filename: String, itemsMatched: List<FolderItem>, withEnter: Boolean, withControl: Boolean) {
this.button?.isDisable =
when (this@GPCloudBrowserPane.mode) {
StorageDialogBuilder.Mode.OPEN -> itemsMatched.isEmpty()
StorageDialogBuilder.Mode.SAVE -> filename.isBlank()
}
if (withEnter && withControl && this@GPCloudBrowserPane.mode == StorageDialogBuilder.Mode.SAVE) {
this.onAction()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ import java.util.function.Consumer

//const val GPCLOUD_HOST = "cumulus-dot-ganttproject-cloud.appspot.com"
const val GPCLOUD_IP = "216.239.32.21"
const val GPCLOUD_HOST = "cloud.ganttproject.biz"
//const val GPCLOUD_HOST = "ganttproject.cloud"
//const val GPCLOUD_HOST = "cloud.ganttproject.biz"
const val GPCLOUD_HOST = "ganttproject.cloud"
const val GPCLOUD_ORIGIN = "https://$GPCLOUD_HOST"
const val GPCLOUD_LANDING_URL = "https://$GPCLOUD_HOST"
const val GPCLOUD_PROJECT_READ_URL = "$GPCLOUD_ORIGIN/p/read"
Expand Down
15 changes: 14 additions & 1 deletion ganttproject/src/biz/ganttproject/storage/local/LocalStorage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,18 @@ class LocalStorage(
?: return
myDocumentReceiver.invoke(doc)
}

fun onNameTyped(filename: String, itemsMatched: List<FolderItem>, withEnter: Boolean, withControl: Boolean) {
this.button?.isDisable =
when (mode) {
StorageDialogBuilder.Mode.OPEN -> itemsMatched.isEmpty()
StorageDialogBuilder.Mode.SAVE -> filename.isBlank()
}
if (withEnter && withControl && mode == StorageDialogBuilder.Mode.SAVE) {
this.onAction()
}
}

}

val listViewHint = SimpleStringProperty(i18n.formatText("${myMode.name.toLowerCase()}.listViewHint"))
Expand All @@ -171,7 +183,8 @@ class LocalStorage(
if (it is FileAsFolderItem) {
myDocumentReceiver(FileDocument(it.file))
}
}
},
onNameTyped = actionButtonHandler::onNameTyped
)
withValidator(createLocalStorageValidator(
Supplier { this@LocalStorage.paneElements.listView.listView.items.isEmpty() },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,15 @@ class ProjectUIFacadeImpl(
if (project.document == null) {
saveProjectAs(project)
onFinish?.send(true)
return@launch
}

if (project.document.asLocalDocument()?.canRead() == false) {
saveProjectAs(project)
onFinish?.send(true)
return@launch
}

val document = project.document
saveProjectTryWrite(project, document)
onFinish?.send(true)
Expand Down Expand Up @@ -119,12 +123,12 @@ class ProjectUIFacadeImpl(
enum class VersionMismatchChoice { OVERWRITE, MAKE_COPY }

private fun saveProjectTrySave(project: IGanttProject, document: Document): Boolean {
val onlineDoc = document.asOnlineDocument()
try {
saveProject(document)
afterSaveProject(project)
return true
} catch (e: VersionMismatchException) {
val onlineDoc = document.asOnlineDocument()
if (onlineDoc != null) {
OptionPaneBuilder<VersionMismatchChoice>().also {
it.i18n = RootLocalizer.createWithRootKey(rootKey = "cloud.versionMismatch")
Expand Down

0 comments on commit cc2dccb

Please sign in to comment.