mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
fix: invalidate options menu after closing unsaved files (fixes #1176)
This commit is contained in:
@@ -38,8 +38,9 @@ class CloseAllFilesAction(context: Context) : FileTabAction() {
|
||||
}
|
||||
|
||||
override fun EditorHandlerActivity.doAction(data: ActionData): Boolean {
|
||||
closeAll()
|
||||
this.invalidateOptionsMenu()
|
||||
closeAll {
|
||||
invalidateOptionsMenu()
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
@@ -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 }
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
Reference in New Issue
Block a user