mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
fix: broken 'Close all files' behavior (fixes #1549)
This commit is contained in:
@@ -69,8 +69,8 @@ import com.itsaky.androidide.preferences.internal.launchAppAfterInstall
|
||||
import com.itsaky.androidide.projects.IProjectManager
|
||||
import com.itsaky.androidide.projects.ProjectManagerImpl
|
||||
import com.itsaky.androidide.tasks.cancelIfActive
|
||||
import com.itsaky.androidide.ui.ContentTranslatingDrawerLayout
|
||||
import com.itsaky.androidide.ui.CodeEditorView
|
||||
import com.itsaky.androidide.ui.ContentTranslatingDrawerLayout
|
||||
import com.itsaky.androidide.uidesigner.UIDesignerActivity
|
||||
import com.itsaky.androidide.utils.ActionMenuUtils.createMenu
|
||||
import com.itsaky.androidide.utils.ApkInstallationSessionCallback
|
||||
|
||||
@@ -34,6 +34,7 @@ import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.io.File
|
||||
import java.util.Collections
|
||||
|
||||
/** ViewModel for data used in [com.itsaky.androidide.activities.editor.EditorActivityKt] */
|
||||
@Suppress("PropertyName")
|
||||
@@ -126,14 +127,15 @@ class EditorViewModel : ViewModel() {
|
||||
}
|
||||
|
||||
internal var files: MutableList<File>
|
||||
get() = this._files.value ?: EMPTY_FILES
|
||||
get() = this._files.value ?: Collections.emptyList()
|
||||
set(value) {
|
||||
this._files.value = value
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
private val EMPTY_FILES = mutableListOf<File>()
|
||||
private inline fun updateFiles(crossinline action: (files: MutableList<File>) -> Unit) {
|
||||
val files = this.files
|
||||
action(files)
|
||||
this.files = files
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -141,9 +143,8 @@ class EditorViewModel : ViewModel() {
|
||||
*
|
||||
* @param file The file that has been opened.
|
||||
*/
|
||||
fun addFile(file: File) {
|
||||
fun addFile(file: File) = updateFiles { files ->
|
||||
files.add(file)
|
||||
this.files = files
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -151,17 +152,16 @@ class EditorViewModel : ViewModel() {
|
||||
*
|
||||
* @param index The index of the closed file.
|
||||
*/
|
||||
fun removeFile(index: Int) {
|
||||
fun removeFile(index: Int) = updateFiles { files ->
|
||||
files.removeAt(index)
|
||||
this.files = files
|
||||
|
||||
if (this.files.isEmpty()) {
|
||||
if (files.isEmpty()) {
|
||||
mCurrentFile.value = null
|
||||
}
|
||||
}
|
||||
|
||||
fun removeAllFiles() {
|
||||
this.files = EMPTY_FILES
|
||||
fun removeAllFiles() = updateFiles { files ->
|
||||
files.clear()
|
||||
setCurrentFile(-1, null)
|
||||
}
|
||||
|
||||
@@ -170,9 +170,8 @@ class EditorViewModel : ViewModel() {
|
||||
mCurrentFile.value = index to file
|
||||
}
|
||||
|
||||
fun updateFile(index: Int, newFile: File) {
|
||||
fun updateFile(index: Int, newFile: File) = updateFiles { files ->
|
||||
files[index] = newFile
|
||||
this.files = files
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -200,7 +199,7 @@ class EditorViewModel : ViewModel() {
|
||||
* @return The list of opened files.
|
||||
*/
|
||||
fun getOpenedFiles(): List<File> {
|
||||
return files
|
||||
return Collections.unmodifiableList(files)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -84,6 +84,7 @@ import io.github.rosemoe.sora.widget.IDEEditorSearcher
|
||||
import io.github.rosemoe.sora.widget.component.EditorAutoCompletion
|
||||
import io.github.rosemoe.sora.widget.component.EditorBuiltinComponent
|
||||
import io.github.rosemoe.sora.widget.component.EditorTextActionWindow
|
||||
import kotlinx.coroutines.CoroutineName
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
@@ -133,7 +134,7 @@ open class IDEEditor @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||
*
|
||||
* All the jobs in this scope are cancelled when the editor is released.
|
||||
*/
|
||||
val editorScope = CoroutineScope(Dispatchers.Default)
|
||||
val editorScope = CoroutineScope(Dispatchers.Default + CoroutineName("IDEEditor"))
|
||||
|
||||
protected val eventDispatcher = EditorEventDispatcher()
|
||||
|
||||
@@ -270,7 +271,7 @@ open class IDEEditor @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||
this.sigHelpCancelChecker = it
|
||||
}
|
||||
|
||||
editorScope.launch {
|
||||
editorScope.launch(Dispatchers.Default) {
|
||||
cancelChecker.job = coroutineContext[Job]
|
||||
val params = SignatureHelpParams(file.toPath(), cursorLSPPosition, cancelChecker)
|
||||
val help = languageServer.signatureHelp(params)
|
||||
|
||||
Reference in New Issue
Block a user