Skip to content

Commit 90dea94

Browse files
feat(ADFA-2351): Add tooltips to code text actions (#971)
1 parent b1292aa commit 90dea94

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

app/src/main/java/com/itsaky/androidide/actions/file/FormatCodeAction.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import androidx.core.content.ContextCompat
2222
import com.itsaky.androidide.actions.ActionData
2323
import com.itsaky.androidide.actions.ActionItem
2424
import com.itsaky.androidide.actions.EditorRelatedAction
25+
import com.itsaky.androidide.idetooltips.TooltipTag
2526
import com.itsaky.androidide.resources.R
2627

2728
/**
@@ -32,6 +33,8 @@ import com.itsaky.androidide.resources.R
3233
class FormatCodeAction(context: Context, override val order: Int) : EditorRelatedAction() {
3334
override val id: String = "ide.editor.code.text.format"
3435
override var location: ActionItem.Location = ActionItem.Location.EDITOR_TEXT_ACTIONS
36+
override fun retrieveTooltipTag(isReadOnlyContext: Boolean) =
37+
TooltipTag.EDITOR_TOOLBAR_FORMAT_CODE
3538

3639
init {
3740
label = context.getString(R.string.title_format_code)

editor/src/main/java/com/itsaky/androidide/editor/ui/EditorActionsMenu.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ open class EditorActionsMenu(val editor: IDEEditor) :
287287
registry.registerActionExecListener(this)
288288
onFillMenu(registry, data)
289289

290-
this.list.adapter = ActionsListAdapter(getMenu(), editor = editor)
290+
this.list.adapter = ActionsListAdapter(getMenu(), editor = editor, location = onGetActionLocation())
291291

292292
}
293293

@@ -368,7 +368,8 @@ open class EditorActionsMenu(val editor: IDEEditor) :
368368
private class ActionsListAdapter(
369369
val menu: Menu?,
370370
val forceShowTitle: Boolean = false,
371-
val editor: IDEEditor
371+
val editor: IDEEditor,
372+
val location: ActionItem.Location
372373
) : RecyclerView.Adapter<VH>() {
373374

374375

@@ -390,6 +391,11 @@ open class EditorActionsMenu(val editor: IDEEditor) :
390391

391392
override fun onBindViewHolder(holder: VH, position: Int) {
392393
val item = getItem(position) ?: return
394+
395+
val action = getInstance().findAction(location, item.itemId)
396+
val tooltipTag = action?.retrieveTooltipTag(false) ?: ""
397+
val tag = tooltipTag.ifEmpty { item.contentDescription?.toString() ?: "" }
398+
393399
val button = holder.binding.root
394400
button.text = if (forceShowTitle) item.title else ""
395401
button.tooltipText = item.title
@@ -412,8 +418,6 @@ open class EditorActionsMenu(val editor: IDEEditor) :
412418
}
413419

414420
button.setOnLongClickListener {
415-
val tag = item.contentDescription?.toString() ?: ""
416-
417421
if (tag.isNotEmpty()) {
418422
TooltipManager.showIdeCategoryTooltip(
419423
context = editor.context,
@@ -443,7 +447,7 @@ open class EditorActionsMenu(val editor: IDEEditor) :
443447
TransitionManager.beginDelayedTransition(this.list, ChangeBounds())
444448
this.list.layoutManager = LinearLayoutManager(editor.context)
445449
this.list.adapter =
446-
ActionsListAdapter(item.subMenu, true, editor)
450+
ActionsListAdapter(item.subMenu, true, editor, location = onGetActionLocation())
447451

448452
this.list.post {
449453
measureActionsList()

idetooltips/src/main/java/com/itsaky/androidide/idetooltips/TooltipTag.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ object TooltipTag {
1111
const val EDITOR_TOOLBAR_COPY = "editor.toolbar.copy"
1212
const val EDITOR_TOOLBAR_OUTPUT_COPY = "output.selection.copy"
1313
const val EDITOR_TOOLBAR_CUT = "editor.toolbar.cut"
14-
const val EDITOR_TOOLBAR_EXPAND_SELECTION = "editor.toolbar.expandselection"
14+
const val EDITOR_TOOLBAR_EXPAND_SELECTION = "editor.toolbar.expandselect"
1515
const val EDITOR_TOOLBAR_LONG_SELECT = "editor.toolbar.longselect"
1616
const val EDITOR_TOOLBAR_PASTE = "editor.toolbar.paste"
1717
const val EDITOR_TOOLBAR_SELECT_ALL = "editor.toolbar.selectall"
1818
const val EDITOR_TOOLBAR_OUTPUT_SELECT_ALL = "output.selection.selectall"
19+
const val EDITOR_TOOLBAR_FORMAT_CODE = "editor.toolbar.formatcode"
1920
const val EDITOR_TOOLBAR_HELP = "editor.toolbar.help"
2021
const val PROJECT_APP_LOGS = "project.applogs"
2122
const val PROJECT_IDE_LOGS = "project.idelogs"

0 commit comments

Comments
 (0)