Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
fix: invalidate options menu after closing unsaved files (fixes #1176)
Browse files Browse the repository at this point in the history
  • Loading branch information
itsaky committed Sep 6, 2023
1 parent 1bf1545 commit 6762d8d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ class CloseAllFilesAction(context: Context) : FileTabAction() {
}

override fun EditorHandlerActivity.doAction(data: ActionData): Boolean {
closeAll()
this.invalidateOptionsMenu()
closeAll {
invalidateOptionsMenu()
}
return true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ class CloseFileAction(context: Context) : FileTabAction() {
}

override fun EditorHandlerActivity.doAction(data: ActionData): Boolean {
binding.tabs.selectedTabPosition.let {
closeFile(it)
this.invalidateOptionsMenu()
binding.tabs.selectedTabPosition.let { index ->
closeFile(index) {
invalidateOptionsMenu()
}
}
return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,13 +399,13 @@ open class EditorHandlerActivity : ProjectHandlerActivity(), IEditorHandler {
return editorViewModel.areFilesModified()
}

override fun closeFile(index: Int) {
override fun closeFile(index: Int, runAfter: () -> Unit) {
if (index >= 0 && index < editorViewModel.getOpenedFileCount()) {
val opened: File = editorViewModel.getOpenedFile(index)
log.info("Closing file:", opened)
val editor = getEditorAtIndex(index)
if (editor != null && editor.isModified) {
notifyFilesUnsaved(listOf(editor)) { closeFile(index) }
notifyFilesUnsaved(listOf(editor)) { closeFile(index, runAfter) }
return
}

Expand All @@ -429,10 +429,8 @@ open class EditorHandlerActivity : ProjectHandlerActivity(), IEditorHandler {
log.error("Invalid file index. Cannot close.")
return
}
}

override fun closeAll() {
closeAll {}
runAfter()
}

override fun closeOthers() {
Expand Down Expand Up @@ -483,7 +481,7 @@ open class EditorHandlerActivity : ProjectHandlerActivity(), IEditorHandler {
binding.editorToolbar.updateMenuDisplay()
}

private fun closeAll(runAfter: () -> Unit = {}) {
override fun closeAll(runAfter: () -> Unit) {
val count = editorViewModel.getOpenedFileCount()
val unsavedFiles =
editorViewModel.getOpenedFiles().map(this::getEditorForFile).filter { it != null && it.isModified }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ interface IEditorHandler {
fun saveAllResult() : SaveResult
fun saveResult(index: Int, result: SaveResult)

fun closeFile(index: Int)
fun closeAll()
fun closeFile(index: Int) = closeFile(index) {}
fun closeFile(index: Int, runAfter: () -> Unit)
fun closeAll() = closeAll {}
fun closeAll(runAfter: () -> Unit)
fun closeOthers()
}

0 comments on commit 6762d8d

Please sign in to comment.