Fixed #393: Do not dismiss text actions window for certain actions

This commit is contained in:
Akash Yadav
2022-10-29 17:55:49 +05:30
parent 32ee8ce579
commit f25cfb2a18
9 changed files with 46 additions and 4 deletions
@@ -0,0 +1,34 @@
/*
* This file is part of AndroidIDE.
*
* AndroidIDE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* AndroidIDE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
*/
package com.itsaky.androidide.actions
/**
* A [ActionItem] related to the code editor. Subclasses can choose whether to dismiss the actions
* window when this action is performed.
*
* @author Akash Yadav
*/
interface EditorActionItem : ActionItem {
/**
* Whether the actions window should be dismissed or not once this action is performed.
*
* @return `true` if the actions window must be dismissed, `false` otherwise.
*/
fun dismissOnAction(): Boolean = true
}
@@ -23,7 +23,7 @@ import androidx.core.content.ContextCompat
import com.itsaky.androidide.views.editor.IDEEditor
/** @author Akash Yadav */
abstract class BaseEditorAction : ActionItem {
abstract class BaseEditorAction : EditorActionItem {
override var label: String = ""
override var visible: Boolean = true
@@ -21,7 +21,7 @@ import com.itsaky.androidide.views.editor.CodeEditorView
import com.itsaky.androidide.views.editor.IDEEditor
/** @author Akash Yadav */
abstract class EditorRelatedAction : EditorActivityAction() {
abstract class EditorRelatedAction : EditorActivityAction(), EditorActionItem {
override var requiresUIThread: Boolean = true
@@ -39,4 +39,6 @@ class SelectAllAction() : BaseEditorAction() {
editor.selectAll()
return true
}
override fun dismissOnAction() = false
}
@@ -43,6 +43,7 @@ import com.itsaky.androidide.actions.ActionData
import com.itsaky.androidide.actions.ActionItem
import com.itsaky.androidide.actions.ActionsRegistry
import com.itsaky.androidide.actions.ActionsRegistry.Companion.getInstance
import com.itsaky.androidide.actions.EditorActionItem
import com.itsaky.androidide.actions.editor.SelectAllAction
import com.itsaky.androidide.databinding.LayoutPopupMenuItemBinding
import com.itsaky.androidide.lsp.api.ILanguageServerRegistry
@@ -313,7 +314,7 @@ open class EditorActionsMenu constructor(val editor: IDEEditor) :
}
override fun onExec(action: ActionItem, result: Any) {
if (action !is SelectAllAction) {
if (action !is EditorActionItem || action.dismissOnAction()) {
dismiss()
}
}
@@ -21,6 +21,7 @@ import android.content.Context
import android.graphics.drawable.Drawable
import com.itsaky.androidide.actions.ActionData
import com.itsaky.androidide.actions.ActionItem
import com.itsaky.androidide.actions.EditorActionItem
import com.itsaky.androidide.actions.hasRequiredData
import com.itsaky.androidide.actions.markInvisible
import com.itsaky.androidide.actions.requireFile
@@ -37,7 +38,7 @@ import java.io.File
* Base class for java code actions
* @author Akash Yadav
*/
abstract class BaseJavaCodeAction : ActionItem {
abstract class BaseJavaCodeAction : EditorActionItem {
override var visible: Boolean = true
override var enabled: Boolean = true
override var icon: Drawable? = null
@@ -44,4 +44,6 @@ class CommentAction : BaseJavaCodeAction() {
return true
}
override fun dismissOnAction() = false
}
@@ -48,4 +48,6 @@ class UncommentAction : BaseJavaCodeAction() {
return true
}
override fun dismissOnAction() = false
}
Binary file not shown.