-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[GSoC'24] CardTemplateEditor: Implementation of Keyboard Shortcuts #16722
[GSoC'24] CardTemplateEditor: Implementation of Keyboard Shortcuts #16722
Conversation
when (menuItem.itemId) { | ||
R.id.action_add -> { |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DIdn't removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Subject: [PATCH] Template
---
Index: AnkiDroid/src/main/java/com/ichi2/anki/CardTemplateEditor.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/CardTemplateEditor.kt b/AnkiDroid/src/main/java/com/ichi2/anki/CardTemplateEditor.kt
--- a/AnkiDroid/src/main/java/com/ichi2/anki/CardTemplateEditor.kt (revision 49cae72ffb7fe08a5a9a77a0c87b8bf1dac5b2b2)
+++ b/AnkiDroid/src/main/java/com/ichi2/anki/CardTemplateEditor.kt (date 1720726825334)
@@ -564,25 +564,50 @@
}
override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
- when (menuItem.itemId) {
+ return when (menuItem.itemId) {
R.id.action_add -> addCard()
- R.id.action_reposition -> showRepositionDialog()
- R.id.action_rename -> showRenameDialog()
- R.id.action_copy_as_markdown -> copyMarkdownTemplateToClipboard()
- R.id.action_insert_field -> showInsertFieldDialog()
- R.id.action_delete -> deleteCard()
+ R.id.action_reposition -> {
+ showRepositionDialog()
+ return true
+ }
+
+ R.id.action_rename -> {
+ showRenameDialog()
+ return true
+ }
+
+ R.id.action_copy_as_markdown -> {
+ copyMarkdownTemplateToClipboard()
+ return true
+
+ }
+
+ R.id.action_insert_field -> {
+ showInsertFieldDialog()
+ return true
+
+ }
+
+ R.id.action_delete -> {
+ return deleteCard()
+ }
+
R.id.action_add_deck_override -> {
displayDeckOverrideDialog(tempModel)
return true
}
+
R.id.action_preview -> {
performPreview()
return true
}
+
R.id.action_confirm -> saveNote()
R.id.action_card_browser_appearance -> openBrowserAppearance()
+ else -> {
+ false
+ }
}
- return false
}
},
viewLifecycleOwner,
should resolve the test issue
49cae72
to
4d92a55
Compare
@criticalAY Thank You ❤️ |
} | ||
|
||
fun addCard(): Boolean { | ||
Timber.i("CardTemplateEditor:: Add template button pressed") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This timber is false. You Timber it also when the user click "a".
I prefer the Timbers to remain in the onMenuItemSelected
and also in onKeyUp
. Because we are trying to tell to which event we react, and those two methods are the one dealing with the event.
Same remakrs for every other functions you introduce please
} | ||
confirmAddCards(tempModel.notetype, numAffectedCards) | ||
return when (menuItem.itemId) { | ||
R.id.action_add -> addCard() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer for addCard
not to return anything, and have return true
in the code. It does not seems that addCard
has any reason to return anything
} | ||
}, | ||
viewLifecycleOwner, | ||
Lifecycle.State.RESUMED | ||
) | ||
} | ||
|
||
fun deleteCard(): Boolean { | ||
val col = templateEditor.getColUnsafe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a "todo" stating to use withCol
? I don't request a change right now because you are just moving code and that's unrelated to your change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, it was not clear, this is the kind of remark that should be applied everywhere. We should not use getColUnsafe
It's currently used, so I won't require you to rewrite this part of the code, your commit is an improvement to our codebase. Still, each getColUnsafe
should have its todo
val col = templateEditor.getColUnsafe | ||
val tempModel = templateEditor.tempModel | ||
Timber.i("CardTemplateEditor:: Delete template button pressed") | ||
val res = resources |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use it a single time, we can delete this line and use resources
instead
0 | ||
} | ||
confirmDeleteCards(template, tempModel.notetype, numAffectedCards) | ||
deleteCard() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please call it deleteNote
, because you'll delete the whole note
return true | ||
} | ||
|
||
fun addCard(): Boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please call it addCardTemplate
. You're adding card templates. As a side effect it add cards, but that's not the main effect.
} | ||
}, | ||
viewLifecycleOwner, | ||
Lifecycle.State.RESUMED | ||
) | ||
} | ||
|
||
fun deleteCard(): Boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please call it deleteCardTemplate
. Same reason as "addCard" above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Arthur-Milchior in previous review you said
Please call it deleteNote, because you'll delete the whole note
// Don't do anything if only one template | ||
if (tempModel.templateCount < 2) { | ||
templateEditor.showSimpleMessageDialog(res.getString(R.string.card_template_editor_cant_delete)) | ||
return true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As for addCard
, I'd prefer you don't return a boolean, given it's always the same value.
But keep the early return
return true | ||
} | ||
|
||
fun saveNote(): Boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
saveNoteType
- Implemented keyboard shortcuts: - Ctrl+P: Perform Preview - Ctrl+1: Navigate to Front Edit - Ctrl+2: Navigate to Back Edit - Ctrl+3: Navigate to Styling Edit - Ctrl+S: Save Note - Ctrl+R: Rename template - Ctrl+I: Show Insert Field Dialog - Ctrl+A: Add template - Ctrl+B: Open Browser Appearance - Ctrl+D: Delete template - Ctrl+O: Display Deck Override Dialog - Ctrl+M: Copy Markdown Template to Clipboard
4d92a55
to
41d7402
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, cheers!
} | ||
}, | ||
viewLifecycleOwner, | ||
Lifecycle.State.RESUMED | ||
) | ||
} | ||
|
||
fun deleteCard(): Boolean { | ||
val col = templateEditor.getColUnsafe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, it was not clear, this is the kind of remark that should be applied everywhere. We should not use getColUnsafe
It's currently used, so I won't require you to rewrite this part of the code, your commit is an improvement to our codebase. Still, each getColUnsafe
should have its todo
} | ||
|
||
if (deletionWouldOrphanNote(col, tempModel, ordinal)) { | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created #16789. The user should be told why it's not done. But this an already existing bug, so it's not blocking
Purpose / Description
Implement keyboard shortcuts to enhance the user experience by providing quick access to commonly used functionalities within the application. This will improve the overall usability, especially for power users who prefer using the keyboard over the mouse.
Approach
The shortcuts are implemented by adding event listeners for keypress events and mapping them to the respective functions. The approach ensures that the shortcuts are intuitive and do not conflict with existing shortcuts.
How Has This Been Tested?
HP Chromebook
Checklist
Please, go through these checks before submitting the PR.