Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
/*
* 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.locations
import android.content.Context
import android.graphics.drawable.Drawable
import androidx.core.content.ContextCompat
import com.itsaky.androidide.actions.ActionData
import com.itsaky.androidide.actions.ActionItem
import com.itsaky.androidide.actions.ActionMenu
import com.itsaky.androidide.idetooltips.TooltipTag
import com.itsaky.androidide.resources.R
/** @author Akash Yadav */
object CodeActionsMenu : ActionMenu {
const val ID = "ide.editor.code.actions"
override val children: MutableSet<ActionItem> = mutableSetOf()
override val id: String = ID
override var label: String = "Code actions"
override var visible = true
override var enabled: Boolean = true
override var icon: Drawable? = null
override fun retrieveTooltipTag(isAlternateContext: Boolean) =
TooltipTag.EDITOR_TOOLBAR_CODE_ACTIONS
override var requiresUIThread: Boolean = false
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)
}
}
}
/*
* 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.locations

import android.content.Context
import android.graphics.drawable.Drawable
import androidx.core.content.ContextCompat
import com.itsaky.androidide.actions.ActionData
import com.itsaky.androidide.actions.ActionItem
import com.itsaky.androidide.actions.ActionMenu
import com.itsaky.androidide.idetooltips.TooltipTag
import com.itsaky.androidide.resources.R

/** @author Akash Yadav */
object CodeActionsMenu : ActionMenu {
const val ID = "ide.editor.code.actions"

override val children: MutableSet<ActionItem> = mutableSetOf()
override val id: String = ID

override var label: String = "Code actions"
override var visible = true
override var enabled: Boolean = true
override var icon: Drawable? = null

override fun retrieveTooltipTag(isReadOnlyContext: Boolean) = TooltipTag.EDITOR_TOOLBAR_CODE_ACTIONS

override var requiresUIThread: Boolean = false
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)
}
}
}
9 changes: 9 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ buildscript {
}
}

// ADFA-6821: production sources are warning-free; keep them that way. Test sources
// (compile*UnitTestKotlin, compile*AndroidTestKotlin) still have warnings, so they are left out
// rather than breaking testV8DebugUnitTest and the analysis workflow that depends on it.
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
if (!name.endsWith("TestKotlin")) {
compilerOptions.allWarningsAsErrors.set(true)
}
}

android {
namespace = BuildConfig.PACKAGE_NAME

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import org.slf4j.LoggerFactory
*/
abstract class AbstractCancellableRunAction(
context: Context,
@StringRes private val labelRes: Int,
@DrawableRes private val iconRes: Int,
@param:StringRes private val labelRes: Int,
@param:DrawableRes private val iconRes: Int,
) : BaseBuildAction() {
// Execute on UI thread as this action might try to show dialogs to the user
final override var requiresUIThread: Boolean = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import com.itsaky.androidide.viewmodel.BuildViewModel
*/
abstract class AbstractModuleAssemblerAction(
context: Context,
@StringRes private val labelRes: Int,
@DrawableRes private val iconRes: Int,
@param:StringRes private val labelRes: Int,
@param:DrawableRes private val iconRes: Int,
) : AbstractCancellableRunAction(context, labelRes, iconRes) {
/**
* Extra Gradle arguments (e.g. `-P` properties) to pass for this action's build. Subclasses
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,25 @@ import com.itsaky.androidide.lsp.IDEDebugClientImpl
* @author Akash Yadav
*/
abstract class AbstractDebuggerAction(
@DrawableRes private val iconRes: Int
@param:DrawableRes private val iconRes: Int,
) : ActionItem {
// debugger actions must always be executed in a background thread
override var requiresUIThread = false
override var location = ActionItem.Location.DEBUGGER_ACTIONS

// debugger actions must always be executed in a background thread
override var requiresUIThread = false
override var location = ActionItem.Location.DEBUGGER_ACTIONS
override var visible = true
override var enabled = true
override var icon: Drawable? = null

override var visible = true
override var enabled = true
override var icon: Drawable? = null
protected val debugClient: IDEDebugClientImpl?
get() = IDEDebugClientImpl.getInstance()

protected val debugClient: IDEDebugClientImpl?
get() = IDEDebugClientImpl.getInstance()
protected open fun checkEnabled(data: ActionData): Boolean = debugClient?.isVmConnected() == true

protected open fun checkEnabled(data: ActionData): Boolean = debugClient?.isVmConnected() == true
override fun prepare(data: ActionData) {
super.prepare(data)

override fun prepare(data: ActionData) {
super.prepare(data)

icon = ContextCompat.getDrawable(data.requireContext(), iconRes)
enabled = checkEnabled(data)
}
icon = ContextCompat.getDrawable(data.requireContext(), iconRes)
enabled = checkEnabled(data)
}
}
140 changes: 70 additions & 70 deletions app/src/main/java/com/itsaky/androidide/actions/editor/CopyAction.kt
Original file line number Diff line number Diff line change
@@ -1,70 +1,70 @@
/*
* 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.editor
import android.content.Context
import com.itsaky.androidide.actions.ActionData
import com.itsaky.androidide.actions.BaseEditorAction
import com.itsaky.androidide.idetooltips.TooltipTag
import com.itsaky.androidide.resources.R
/** @author Akash Yadav */
class CopyAction(context: Context, override val order: Int) :
BaseEditorAction() {
init {
label = context.getString(R.string.copy)
val arr = context.obtainStyledAttributes(intArrayOf(android.R.attr.actionModeCopyDrawable))
icon = arr.getDrawable(0)?.let { tintDrawable(context, it) }
arr.recycle()
}
companion object {
const val ID = "ide.editor.code.text.copy"
}
override val id: String = ID
override fun prepare(data: ActionData) {
super.prepare(data)
if (!visible) return
val target = getTextTarget(data)
visible = target != null
enabled = visible && target?.hasSelection() == true
}
override suspend fun execAction(data: ActionData): Boolean {
val target = getTextTarget(data) ?: return false
if (!target.hasSelection()) return false
target.copyText()
return true
}
override fun retrieveTooltipTag(isAlternateContext: Boolean): String {
return if (isAlternateContext) {
TooltipTag.EDITOR_TOOLBAR_OUTPUT_COPY
} else {
TooltipTag.EDITOR_TOOLBAR_COPY
}
}
}
/*
* 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.editor

import android.content.Context
import com.itsaky.androidide.actions.ActionData
import com.itsaky.androidide.actions.BaseEditorAction
import com.itsaky.androidide.idetooltips.TooltipTag
import com.itsaky.androidide.resources.R

/** @author Akash Yadav */
class CopyAction(
context: Context,
override val order: Int,
) : BaseEditorAction() {
init {
label = context.getString(R.string.copy)

val arr = context.obtainStyledAttributes(intArrayOf(android.R.attr.actionModeCopyDrawable))
icon = arr.getDrawable(0)?.let { tintDrawable(context, it) }
arr.recycle()
}

companion object {
const val ID = "ide.editor.code.text.copy"
}

override val id: String = ID

override fun prepare(data: ActionData) {
super.prepare(data)

if (!visible) return

val target = getTextTarget(data)

visible = target != null
enabled = visible && target?.hasSelection() == true
}

override suspend fun execAction(data: ActionData): Boolean {
val target = getTextTarget(data) ?: return false
if (!target.hasSelection()) return false

target.copyText()
return true
}

override fun retrieveTooltipTag(isReadOnlyContext: Boolean): String =
if (isReadOnlyContext) {
TooltipTag.EDITOR_TOOLBAR_OUTPUT_COPY
} else {
TooltipTag.EDITOR_TOOLBAR_COPY
}
}
Loading
Loading