Expose new action system in Lua API and deprecate old one - #6588
Conversation
ad696a2 to
5ff95e9
Compare
|
I think I'd add a xournalpp/src/core/plugin/luapi_application.h Lines 3185 to 3186 in 01734d8 If we write the code in a fixed format/style, it should be possible to adapt We could of course further differentiate between different "kinds" of enums using deeper nested tables (e.g. This way the enums are native in lua, no strings are involved and also everything is kinda static (no dynamic resolution during runtime). |
|
About the enums: I think the most important thing will be, as you said, that if we add an element to the enum (not necessarily at the end), it doesn't break all the plugins using this enum. In particular, letting the plugin dev use "4" for TEXT is not good. This is more or less why the Actions themselves are referred to by their string id (and not by the enum value), so whatever solution is used could also be used for the Actions. For information, how many different enums need to be exposed/translated? |
5ff95e9 to
69e1bc4
Compare
Most of the enums from src/core/plugin/ActionBackwardCompatibilityLayer.cpp that have an integer state: Some translation may also be needed for colors. |
So the user should write: app.changeActionState("select-tool", "eraser")or (with suggestion from the language server) app.changeActionState("select-tool", app.C.SELECT_TOOL_ERASER)with Similarly with app.changeToolState("eraser-size", "fine")
app.changeToolState("highlighter-size", "very-fine")
app.changeToolState("tool-size", "thick")
app.changeToolState("pen-size", "medium")
app.changeToolState("eraser-type", "whiteout")
app.changeToolState("arrange-selection-order", "bring-to-front") |
|
In case we use the Can't we directly translate If But then, using the string as intermediate value might open the door for more comprehensive debug output when writing a plugin (as the value is human readable). Also
would be acceptable for plugins then (if Maybe part of the question here is if we should protect the plugin authors from such misuse by simply not offering the interface to the raw enum values (I'd say no and plugin authors should simply use |
I'm fine with that. It also seems simpler to expose the enum rather than to generate an "enum_to_string" and "enum_from_string" for each of those (although some already exist). |
9fafa13 to
b171de3
Compare
|
It would also help to get suggestions for the action names in |
4b8d04f to
d73f04d
Compare
|
I removed the enum values for DrawingType, StrokeType and OpacityFeature again, since they are not used in any actions. |
d349a2e to
8d460cd
Compare
|
@bhennion @atticus-sullivan This PR is up for review. |
Sorry I won't get to this the next weeks. But from what I've seen the Lua side looks good (no detailed check though) |
| TOOL_SIZE_NONE | ||
| }; | ||
|
|
||
| static std::array<std::string, 6> toolSizeNames{"veryThin", "thin", "medium", "thick", "veryThick", "none"}; |
There was a problem hiding this comment.
I think you can make them constexpr if you use std::string_view:
| static std::array<std::string, 6> toolSizeNames{"veryThin", "thin", "medium", "thick", "veryThick", "none"}; | |
| static constexpr std::array<std::string_view, 6> toolSizeNames{"veryThin", "thin", "medium", "thick", "veryThick", "none"}; |
Then you should have all the operators you need (e.g. == actually compares the strings) and the compiler can optimize as constexpr.
bhennion
left a comment
There was a problem hiding this comment.
Other than the constexpr std::string_view business, LGTM!
Let's wait for @atticus-sullivan's review on the lua side of things.
96151cc to
c170f8b
Compare
|
I have added |
bhennion
left a comment
There was a problem hiding this comment.
It all looks alright to me. Just have a couple of nitpicks.
6e6b60c to
6bc16f5
Compare
atticus-sullivan
left a comment
There was a problem hiding this comment.
First of all: Sorry it took me so long looking into this.
Looks good to me.
Just one question/observation: Is it correct none of the plugins bundled with xournalpp uses/needs to use app.C currently? 🤔
Maybe to a user it looks a bit inconsistent not using app.C for the Action as well. But looking at the code it totally makes sense. Also the current state using strings and listing all values in the lua-def leading to the suggestions by the LSP (important in my opinion) is also fine.
b9875d0 to
02bb008
Compare
02bb008 to
c0bc641
Compare
|
Thanks for the review @atticus-sullivan
Yes, that's correct. I have cleaned up the commit history and rebased on current master. Also I had to drop one commit that I introduced after @bhennion's review for simplifying getting the expected type of the action. It didn't work properly since there can be a state type without a parameter type for an action. Merging in 24 hours if no objections are raised, assuming the pipeline succeeds. |


The basic functionality works already. E.g. one can write
to toggle the setsquare or
to change to horizontal layout.
The action states are not always self-explanatory and this still needs to be addressed (brainstorming below). One can write e.g.
but how would you know that 4 corresponds to the Text tool?
One idea would be to automatically generate a .lua file that defines all these enum values. The .lua file would have to put somewhere where it can be found.
Another idea would be to add runtime info (something like
app.getAllActionNames()andapp.getActionStates(action))but that would leave the readability problem to the plugin developer and have issues when the state values change between versions for a certain action, e.g. because a new tool was introduced.
@bhennion @atticus-sullivan Any ideas/suggestions?