-
Notifications
You must be signed in to change notification settings - Fork 772
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
GMenu for main menubar #4372
GMenu for main menubar #4372
Conversation
161b0c6
to
9e2d25c
Compare
This comment was marked as outdated.
This comment was marked as outdated.
The last commit introduces a database for GAction's. The way GAction's work mean we have to rethink the way we handle actions as well. Please look at this doc to understand better what follows. A GAction can have a state (e.g. a boolean for checkboxes, or an integer for radiobuttons), and/or a parameter (e.g. the path of the file for "Recent files" entries). Let me explain: to each menu entry is associated a GAction, and possibly a target value.
So for instance, all the entries in a radio list are linked to the same GAction (but different target values). In particular, the enum in core/enums/Actions.enum.h is inadequate to this setting: we do not want one ActionType per menu entry (as it is in master), but one per "categories" of actions (e.g. just SET_COLUMNS instead of SET_COLUMNS_1, ... , SET_COLUMNS_8). Now comes the issue: I need to filll the action database. For this, I need:
@xournalpp/core @Febbe If you could have a look at the content of control/actions/ActionDatabase.cpp, and share
|
The only idea I have checking this at compile time is to read the contents of |
I guess making a test unit would also be possible. |
f68dd0b
to
e010b78
Compare
One question: Is there any backwards compatibility planned with plugins that use |
Backwards compatibility for the plugin interface has indeed been on my mind recently.
In the long run, once 1. is done, I'd imagine the content of Control::actionPerformed should be moved to a plugin compatilibty layer. Ideally, plugins would be given access to the new actions (with parameters and states) and the old ones would be marked as deprecated and eventually retired. |
87a7b49
to
b84f278
Compare
d345a48
to
34d9f0b
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.
I am a bit unsure, why we need this database, or what's its exact purpose. Especially, why the Gio.ActionMap interface is not sufficient.
@@ -0,0 +1,104 @@ | |||
<?php |
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.
Nit (opinionated): PHP is not my favorite scripting language, because it requires an interpreter, which is often not common, even on development stations. Python would be my choice.
But doing it via CMake or via the c++ preprocessor might also be a solution:
https://stackoverflow.com/questions/1801363/c-c-any-way-to-get-reflective-enums
With c++20's consteval and std::sort being constexpr, we might be able to generate those arrays via c++ on compile time, and having on top an efficient way to access the Action from its string via binary search / std::lower_bound
.
Note, this comment has nearly to zero priority.
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 simply copied the original script we have for ActionType and ActionGroup and adapted it, I don't care for php myself either and any better solution is more than welcome!
My main motivation was to make it possible to define an action and everything we need to know about it in a single place or so (i.e. the specializations in ActionProperties.h). |
Such assumptions must be made with benchmarks. Gtk hopefully uses an ordered flatmap or at least a tree based map. Both have a very high mapping speed, when it comes to string mappings. On the other hand with your approach, we can map the actions by the enum which is quite nice, but it doubles the state.
Yep, that's anyway a good idea. What do you think about https://docs.gtk.org/gtk4/method.Application.set_accels_for_action.html can we integrate the initialization of default values also in this structure? Overall, I think this is useful, when it proofs to be otherwise, we can still refactor it. |
No it does not, we just keep a ref to the same action that has been added to the GActionMap. The state is only stored once.
Already done. Adding a ActionProperties::accelerators member adds those accelerators automatically. See e.g. Action:UNDO. |
Nice! |
Rebased on master: the new pdf marker opacity feature should still work :) |
|
Sorry I wasn't clear. The problem is not gtk3 vs gtk4. The issue is more simple (and less important): before this PR, the toolbar buttons were styled using the What I don't know how to do (I don't think it's possible in a reasonable amount of code) is to have the buttons of the toolbar follow the theme's All in all, it's not that important and we can leave it like that, IMO. |
Adds an action database (owned by control) which registers GAction's to the main window. The actions are named so that they are connected to the menu entries. This action database is indexed by a new enum Action. This also updates enum generation scripts.
…ActionProperties.h
Fixed a couple of nitpicks I found in the code (uneeded includes, debug output) and made a cmake flag for debug output concerning the action database. Is every one happy with this? (I'd be happier if we merged this relatively soon as rebasing whenever a new action is added is a bit cumbersome.) |
This is basically ready to merge right? |
Yes |
Thank you for the work @bhennion |
As discussed in #2722, the use of GtkMenuItem and derived classes have been deprecated in GTK3 and removed in GTK4.
So we need to get rid of them before porting.
They are replaced by the menu structure tree-type GMenu/GMenuItem triggering the activation/toggle of GAction's.
This PR is very early WIP, as a proof-of-concept and a way to discuss the pros and cons of various solutions. For now, all the static menus and submenus are there (but the entries are not activatable...), and the only dynamically populated submenu is the Recent Documents submenu. (also the toolbar are not generated anymore)
You can clic on gtk-new (or press Ctrl+N) or on some recently-opened file and see stuff in the terminal, so actions are triggered (not the right ones though).
You can already spot some of the issues we have to fix:
I AM NOT SURE THIS IS ACTUALLY POSSIBLEEdit: Yes it is!Some doc:
https://wiki.gnome.org/HowDoI/ApplicationMenu
https://wiki.gnome.org/HowDoI/GAction
https://docs.gtk.org/gio/class.MenuItem.html
https://docs.gtk.org/gio/class.Menu.html
https://docs.gtk.org/gio/class.Action.html
https://docs.gtk.org/gio/class.SimpleAction.html
https://docs.gtk.org/gio/class.ActionMap.html
https://gitlab.gnome.org/GNOME/Initiatives/-/wikis/App-Menu-Retirement