mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
fix(actions): make ActionItem visible and enabled by default
This commit is contained in:
@@ -23,6 +23,7 @@ import android.graphics.PorterDuffColorFilter
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.view.Menu
|
||||
import android.view.View
|
||||
import androidx.annotation.CallSuper
|
||||
import com.itsaky.androidide.utils.resolveAttr
|
||||
|
||||
/**
|
||||
@@ -87,7 +88,11 @@ interface ActionItem {
|
||||
*
|
||||
* @param data The data containing various information about the event.
|
||||
*/
|
||||
fun prepare(data: ActionData)
|
||||
@CallSuper
|
||||
fun prepare(data: ActionData) {
|
||||
visible = true
|
||||
enabled = true
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the action. The action executed in a background thread by default.
|
||||
|
||||
@@ -42,6 +42,7 @@ object CodeActionsMenu : ActionMenu {
|
||||
override var location: ActionItem.Location = ActionItem.Location.EDITOR_TEXT_ACTIONS
|
||||
|
||||
override fun prepare(data: ActionData) {
|
||||
super.prepare(data)
|
||||
if (icon == null) {
|
||||
icon = ContextCompat.getDrawable(data[Context::class.java]!!, R.drawable.ic_code)
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ abstract class BaseBuildAction : EditorActivityAction() {
|
||||
get() = Lookup.getDefault().lookup(BuildService.KEY_BUILD_SERVICE)
|
||||
|
||||
override fun prepare(data: ActionData) {
|
||||
super.prepare(data)
|
||||
val context = data.getActivity()
|
||||
if (context == null) {
|
||||
visible = false
|
||||
|
||||
@@ -33,6 +33,7 @@ abstract class BaseEditorAction : EditorActionItem {
|
||||
override var location: ActionItem.Location = ActionItem.Location.EDITOR_TEXT_ACTIONS
|
||||
|
||||
override fun prepare(data: ActionData) {
|
||||
super.prepare(data)
|
||||
getEditor(data)
|
||||
?: kotlin.run {
|
||||
visible = false
|
||||
|
||||
@@ -41,6 +41,7 @@ abstract class EditorActivityAction : ActionItem {
|
||||
CoroutineName("${javaClass.simpleName}Scope")
|
||||
|
||||
override fun prepare(data: ActionData) {
|
||||
super.prepare(data)
|
||||
if (!data.hasRequiredData(Context::class.java)) {
|
||||
markInvisible()
|
||||
}
|
||||
|
||||
@@ -26,6 +26,8 @@ abstract class EditorRelatedAction : EditorActivityAction(), EditorActionItem {
|
||||
override var requiresUIThread: Boolean = true
|
||||
|
||||
override fun prepare(data: ActionData) {
|
||||
super<EditorActionItem>.prepare(data)
|
||||
super<EditorActivityAction>.prepare(data)
|
||||
val editor =
|
||||
data.getEditor()
|
||||
?: run {
|
||||
|
||||
+1
-1
@@ -67,7 +67,7 @@ class QuickRunWithCancellationAction(context: Context, override val order: Int)
|
||||
override var requiresUIThread: Boolean = true
|
||||
|
||||
override fun prepare(data: ActionData) {
|
||||
|
||||
super.prepare(data)
|
||||
val context = data.getActivity() ?: run {
|
||||
markInvisible()
|
||||
return
|
||||
|
||||
@@ -41,6 +41,7 @@ class LongSelectAction(context: Context, override val order: Int) : EditorRelate
|
||||
}
|
||||
|
||||
override fun prepare(data: ActionData) {
|
||||
super.prepare(data)
|
||||
data.getEditor() ?: markInvisible()
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ class DisconnectLogSendersAction(context: Context, override val order: Int) : Ed
|
||||
}
|
||||
|
||||
override fun prepare(data: ActionData) {
|
||||
super.prepare(data)
|
||||
data.getActivity() ?: run {
|
||||
markInvisible()
|
||||
return
|
||||
|
||||
@@ -36,11 +36,6 @@ class FileTreeAction(context: Context, override val order: Int) : EditorActivity
|
||||
icon = ContextCompat.getDrawable(context, R.drawable.ic_folder)
|
||||
}
|
||||
|
||||
override fun prepare(data: ActionData) {
|
||||
visible = true
|
||||
enabled = true
|
||||
}
|
||||
|
||||
override suspend fun execAction(data: ActionData): Boolean {
|
||||
val context = data.getActivity() ?: return false
|
||||
|
||||
|
||||
@@ -40,6 +40,8 @@ class FindActionMenu(context: Context, override val order: Int) : EditorActivity
|
||||
}
|
||||
|
||||
override fun prepare(data: ActionData) {
|
||||
super<ActionMenu>.prepare(data)
|
||||
super<EditorActivityAction>.prepare(data)
|
||||
visible = true
|
||||
enabled = children.size > 0
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ class FindInProjectAction() : EditorActivityAction() {
|
||||
override val id: String = "ide.editor.find.inProject"
|
||||
|
||||
override fun prepare(data: ActionData) {
|
||||
super.prepare(data)
|
||||
data.getActivity()
|
||||
?: run {
|
||||
markInvisible()
|
||||
|
||||
@@ -47,6 +47,7 @@ class LaunchAppAction(context: Context, override val order: Int) : EditorActivit
|
||||
}
|
||||
|
||||
override fun prepare(data: ActionData) {
|
||||
super.prepare(data)
|
||||
data.getActivity() ?: run {
|
||||
markInvisible()
|
||||
return
|
||||
|
||||
@@ -44,7 +44,7 @@ class SaveFileAction(context: Context, override val order: Int) : EditorRelatedA
|
||||
}
|
||||
|
||||
override fun prepare(data: ActionData) {
|
||||
|
||||
super.prepare(data)
|
||||
val context =
|
||||
data.getActivity()
|
||||
?: run {
|
||||
|
||||
@@ -34,6 +34,7 @@ abstract class BaseDirNodeAction(context: Context,
|
||||
@DrawableRes iconRes: Int? = null) : BaseFileTreeAction(context, labelRes, iconRes) {
|
||||
|
||||
override fun prepare(data: ActionData) {
|
||||
super.prepare(data)
|
||||
if (!data.hasFileTreeData()) {
|
||||
markInvisible()
|
||||
return
|
||||
|
||||
@@ -53,6 +53,7 @@ abstract class BaseFileTreeAction(
|
||||
}
|
||||
|
||||
override fun prepare(data: ActionData) {
|
||||
super.prepare(data)
|
||||
if (!data.hasFileTreeData()) {
|
||||
markInvisible()
|
||||
return
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
package com.itsaky.androidide.actions.sidebar
|
||||
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.view.Menu
|
||||
import com.itsaky.androidide.actions.ActionData
|
||||
import com.itsaky.androidide.actions.ActionItem
|
||||
import com.itsaky.androidide.actions.SidebarActionItem
|
||||
@@ -41,10 +40,6 @@ abstract class AbstractSidebarAction : SidebarActionItem {
|
||||
override var icon: Drawable? = null
|
||||
override var label: String = ""
|
||||
|
||||
// should not be needed
|
||||
override fun prepare(data: ActionData) {
|
||||
}
|
||||
|
||||
override suspend fun execAction(data: ActionData): Any {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -54,6 +54,7 @@ abstract class BaseJavaCodeAction : EditorActionItem {
|
||||
protected abstract val titleTextRes: Int
|
||||
|
||||
override fun prepare(data: ActionData) {
|
||||
super.prepare(data)
|
||||
if (
|
||||
!data.hasRequiredData(Context::class.java, JavaLanguageServer::class.java, File::class.java)
|
||||
) {
|
||||
|
||||
-1
@@ -39,7 +39,6 @@ class VariableToStatementAction : BaseJavaCodeAction() {
|
||||
|
||||
override val titleTextRes: Int = R.string.action_convert_to_statement
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
override fun prepare(data: ActionData) {
|
||||
super.prepare(data)
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ class RedoAction(context: Context) : UiDesignerAction() {
|
||||
}
|
||||
|
||||
override fun prepare(data: ActionData) {
|
||||
super.prepare(data)
|
||||
visible = true
|
||||
enabled = data.requireWorkspace().undoManager.canRedo()
|
||||
}
|
||||
|
||||
+1
@@ -41,6 +41,7 @@ class ShowHierarchyAction(context: Context) : UiDesignerAction() {
|
||||
}
|
||||
|
||||
override fun prepare(data: ActionData) {
|
||||
super.prepare(data)
|
||||
if (!data.hasRequiredData(Context::class.java, Fragment::class.java)) {
|
||||
markInvisible()
|
||||
return
|
||||
|
||||
@@ -47,6 +47,7 @@ class ShowXmlAction(context: Context) : UiDesignerAction() {
|
||||
}
|
||||
|
||||
override fun prepare(data: ActionData) {
|
||||
super.prepare(data)
|
||||
if (!data.hasRequiredData(Context::class.java, Fragment::class.java)) {
|
||||
markInvisible()
|
||||
return
|
||||
|
||||
@@ -44,6 +44,7 @@ abstract class UiDesignerAction : ActionItem {
|
||||
override var visible: Boolean = true
|
||||
|
||||
override fun prepare(data: ActionData) {
|
||||
super.prepare(data)
|
||||
if (!data.hasRequiredData(Context::class.java, Fragment::class.java)) {
|
||||
markInvisible()
|
||||
return
|
||||
|
||||
@@ -38,6 +38,7 @@ class UndoAction(context: Context) : UiDesignerAction() {
|
||||
}
|
||||
|
||||
override fun prepare(data: ActionData) {
|
||||
super.prepare(data)
|
||||
visible = true
|
||||
enabled = data.requireWorkspace().undoManager.canUndo()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user