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

Commit f32e200

Browse files
committed
fix: invalidate options menu after closing unsaved files (fixes #1176)
1 parent 9bea0d0 commit f32e200

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

app/src/main/java/com/itsaky/androidide/actions/file/CloseAllFilesAction.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ class CloseAllFilesAction(context: Context) : FileTabAction() {
3838
}
3939

4040
override fun EditorHandlerActivity.doAction(data: ActionData): Boolean {
41-
closeAll()
42-
this.invalidateOptionsMenu()
41+
closeAll {
42+
invalidateOptionsMenu()
43+
}
4344
return true
4445
}
4546
}

app/src/main/java/com/itsaky/androidide/actions/file/CloseFileAction.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ class CloseFileAction(context: Context) : FileTabAction() {
3838
}
3939

4040
override fun EditorHandlerActivity.doAction(data: ActionData): Boolean {
41-
binding.tabs.selectedTabPosition.let {
42-
closeFile(it)
43-
this.invalidateOptionsMenu()
41+
binding.tabs.selectedTabPosition.let { index ->
42+
closeFile(index) {
43+
invalidateOptionsMenu()
44+
}
4445
}
4546
return true
4647
}

app/src/main/java/com/itsaky/androidide/activities/editor/EditorHandlerActivity.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -399,13 +399,13 @@ open class EditorHandlerActivity : ProjectHandlerActivity(), IEditorHandler {
399399
return editorViewModel.areFilesModified()
400400
}
401401

402-
override fun closeFile(index: Int) {
402+
override fun closeFile(index: Int, runAfter: () -> Unit) {
403403
if (index >= 0 && index < editorViewModel.getOpenedFileCount()) {
404404
val opened: File = editorViewModel.getOpenedFile(index)
405405
log.info("Closing file:", opened)
406406
val editor = getEditorAtIndex(index)
407407
if (editor != null && editor.isModified) {
408-
notifyFilesUnsaved(listOf(editor)) { closeFile(index) }
408+
notifyFilesUnsaved(listOf(editor)) { closeFile(index, runAfter) }
409409
return
410410
}
411411

@@ -429,10 +429,8 @@ open class EditorHandlerActivity : ProjectHandlerActivity(), IEditorHandler {
429429
log.error("Invalid file index. Cannot close.")
430430
return
431431
}
432-
}
433432

434-
override fun closeAll() {
435-
closeAll {}
433+
runAfter()
436434
}
437435

438436
override fun closeOthers() {
@@ -483,7 +481,7 @@ open class EditorHandlerActivity : ProjectHandlerActivity(), IEditorHandler {
483481
binding.editorToolbar.updateMenuDisplay()
484482
}
485483

486-
private fun closeAll(runAfter: () -> Unit = {}) {
484+
override fun closeAll(runAfter: () -> Unit) {
487485
val count = editorViewModel.getOpenedFileCount()
488486
val unsavedFiles =
489487
editorViewModel.getOpenedFiles().map(this::getEditorForFile).filter { it != null && it.isModified }

app/src/main/java/com/itsaky/androidide/interfaces/IEditorHandler.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ interface IEditorHandler {
4646
fun saveAllResult() : SaveResult
4747
fun saveResult(index: Int, result: SaveResult)
4848

49-
fun closeFile(index: Int)
50-
fun closeAll()
49+
fun closeFile(index: Int) = closeFile(index) {}
50+
fun closeFile(index: Int, runAfter: () -> Unit)
51+
fun closeAll() = closeAll {}
52+
fun closeAll(runAfter: () -> Unit)
5153
fun closeOthers()
5254
}

0 commit comments

Comments
 (0)