Commit Graph

50046 Commits

Author SHA1 Message Date
Jehan 57a0fd4dbf app, menus: fix tool options menus.
My last commit message was slightly wrong. I had one last special case to
handle: the ability to only create sub-GimpMenuShell (i.e. at a specific path
other than the root).
We are using this ability in particular for tool options submenus.
2023-04-12 22:07:08 +02:00
Jehan 033aa8e71b menus: add all the missing menus in the new GtkBuilder format!
I was handling all the problematic cases first. These remaining menus are
working fine otherwise by just implementing them, as far as my tests go.
2023-04-12 22:07:08 +02:00
Jehan 55dc688759 app, menus: use the new GimpToolbar in the GimpTextEditor. 2023-04-12 22:07:08 +02:00
Jehan da32f539d8 app: new GimpToolbar widget.
It's still pretty simple now and allows to add toolbar buttons and separators
(at start or end). There is no possibility of runtime-customization yet, but in
the future, it would be great to allow such ability and use this widget for a
main window toolbar which people can customize to add quick access to their
favorite actions.
2023-04-12 22:07:08 +02:00
Jehan f492871e88 app: better use GimpMenuShell and shift around some code as virtual…
… function implementations.

I am also preparing to create a new class GimpToolbar which will make good use
of the interface too.
2023-04-12 22:07:08 +02:00
Jehan 8a2d895ae8 app: fix non-reactive display shell after popping up tool menus.
The canvas was not reactive to any pointer or keyboard event until we hit
Escape. This was because we needed to reset the `mod_action` variable.
2023-04-12 22:07:08 +02:00
Jehan bd4cb8f67a app: improve GimpMenuShell handling of GimpRadioAction and GimpToggleAction.
Somehow the toggle actions were not working correctly on GimpMenu popped up e.g.
as dockbook menus (but it was fine in the GimpMenuBar). I straightened up the
code to be a bit clearer. I also rely on the "toggled" signal rather than
"change-state" (the latter is supposed to happen before state change actually
happen). It now works much better.
2023-04-12 22:07:08 +02:00
Jehan e800159847 menus: add dashboard-menu with proper placeholder support. 2023-04-12 22:07:08 +02:00
Jehan 987f86a218 app: make sure widgets exist when an action change state.
Otherwise it may end up in crashes while exiting GIMP. The widget must be alive
or the signal handler removed.
2023-04-12 22:07:08 +02:00
Jehan 9c7469fb22 app, menus: handle the case where a menu is used both as popup and submenu.
Several menus can be triggered either as popups on their own when right-clicking
the dockable or on items, or as a submenu in the docks main menu.
In the former case, we want the menu items to be at the root level, whereas in
the latter case, we want them inside a properly named submenu.

To handle this, I wrap these in a properly labelled <submenu> in the .ui files,
and I add a boolean flag to gimp_menu_shell_fill() which will drop the top
submenu if and only if this is the only top item. I use this flag only when
using these menus as popup menu on their own.

Also fixing a few memory leaks around these pieces of code.
2023-04-12 22:07:08 +02:00
Jehan 87a22a37ae app: run action group's update functions when changing gradient editor's…
… selection.

Since we change some actions' group name depending on the selected editor's
segment, we need to update actions accordingly.
2023-04-12 22:07:08 +02:00
Jehan 2335e14d59 app: add the gradient editor submenu and a new concept of GimpRadioAction's…
… group name.

The gradient editor submenu add 2 submenus with changing names. It was using
again bogus actions: "gradient-editor-blending-func" and
"gradient-editor-coloring-type" do nothing except for being used as name
holders.

Instead I add the concept of group name for GimpRadioAction-s and when I use a
radio action attribute as <submenu>, this submenu will use the group name (and
sync with it, if it changes).
2023-04-12 22:07:08 +02:00
Jehan b1f022f144 app, menus: now support the child menu of the GimpDockbook menu.
I only translated the undo menu into GtkBuilder's .ui format for now.
The only missing part is that the icon is now shown.

Note that in various parts, I don't rely anymore on a bogus menu action (i.e.
"undo-popup" action in this case) which does nothing but has an associated label
and icon. I simply add the label and icon as submenu attribute directly in the
.ui file, which is translatable and whose strings should be parsed by gettext.

Eventually I'll just get rid of all the various "*-popup" or "*-menu" bogus
actions.
2023-04-12 22:07:08 +02:00
Jehan 1b48792089 app: do not register shortcuts with deprecated GtkActionGroup code anymore. 2023-04-12 22:07:08 +02:00
Jehan 83c466bdec app: don't implement GtkAction activate() anymore.
All action types work fine with GAction activate() now.
2023-04-12 22:07:08 +02:00
Jehan 4776b092bd app: action names set in GimpToolControl don't need the group name appended.
Not with the new GAction-based actions.
2023-04-12 22:07:08 +02:00
Jehan 082bec3721 app: GimpEnumAction don't implement anything from GtkAction anymore. 2023-04-12 22:07:08 +02:00
Jehan 9f1fd64a41 app: GimpRadioAction is now a subclass of GimpRadioAction.
We now completely got rid of all GtkToggleAction and GtkRadioAction code in the
whole of GIMP!
2023-04-12 22:07:08 +02:00
Jehan a813f82252 app: GimpToggleAction is now a GimpActionImpl subclass. 2023-04-12 22:07:08 +02:00
Jehan dcd911ba60 menus: implement a bunch of menus in GtkBuilder format.
It's not all of them yet, just the ones which work out of the box with current
code and which I could easily trigger.
2023-04-12 22:07:08 +02:00
Jehan 9c5812ffbb app: use the new GimpMenu so that we instantly get much nicer looking menus! 2023-04-12 22:07:08 +02:00
Jehan 7af01cbb16 app: new GimpMenu widget and GimpMenuShell interface.
The new GimpMenu is derived from GtkMenu. Both GimpMenu and GimpMenuBar are now
implementing GimpMenuShell which allows to share a lot of the logic for filling
the menus, adding items, etc.
2023-04-12 22:07:08 +02:00
Jehan 06b7242cc0 app: rename GimpMenu to GimpMenuBar.
This is better in sync with GTK naming (GtkMenuBar), but especially, it will
allow me to make a GimpMenu subclass of GtkMenu.
2023-04-12 22:07:08 +02:00
Jehan 4e038a66a6 app: remove more of GtkAction API.
This is less and less a GtkAction. Note that I don't implement
gimp_action_get_name() because once we will drop completely GtkAction and make
GimpObject the parent, we can just use gimp_object_get_name().
2023-04-12 22:07:08 +02:00
Jehan c20039b25e app: move "visible" property to GimpAction, rather than GtkAction. 2023-04-12 22:07:08 +02:00
Jehan 47ff65aa86 menus: add a dockable-menu with the new GtkBuilder format.
The dialogs-menuitems is shared between dockable-menu and image-menu, just as it
was with the old format. For this, we use XSL transformation with XInclude, then
drop the namespace (because GTK doesn't like the unknown namespace being defined
and crash immediately otherwise).
2023-04-12 22:07:08 +02:00
Jehan f9fec03751 app: display shell popup menu now uses GMenuModel.
The menu is still very incomplete, but it's a start.
2023-04-12 22:07:08 +02:00
Jehan 8ec589915a app: only show the new menubar now. 2023-04-12 22:07:08 +02:00
Jehan 6ecfc4a77b plug-ins: more placeholders removed from menu paths. 2023-04-12 22:07:08 +02:00
Jehan c8a2f77c98 plug-ins: don't use "Send" placeholder either. 2023-04-12 22:07:08 +02:00
Jehan 5b009690f4 app: correctly show the pixbuf set with gimp_procedure_set_icon_pixbuf()…
… next to item labels for GtkMenuItem proxy widgets (e.g. in main menu).
2023-04-12 22:07:08 +02:00
Jehan 9eea95255a plug-ins: remove the "Acquire" of the menu path.
This is a placeholder which is not meant to appear in the menu. Our new system
uses placeholders internally, but plug-ins cannot make use of these.

Not sure anyway if this is so useful in the cases of plug-ins. At least, I don't
feel it is for these particular use cases.
2023-04-12 22:07:08 +02:00
Jehan c1fc3cf8eb app: display the optional (main) shortcut next to menu items.
Also getting rid of gimp_action_get_proxies() API which is now unneeded, I
think. Furthermore GimpMenu does not have to connect to label changes. Making
the items proxies of a GimpAction is enough to have them updated.
2023-04-12 22:07:08 +02:00
Jehan 9485b4ef5b app: implement F1 help binding on GimpMenu. 2023-04-12 22:07:08 +02:00
Jehan 01a4feb784 app, libgimpwidgets: GimpAction proxy widgets will display the proper tooltip.
The tooltip contains the reason for action inactivity, if relevant. And in case
of a GtkMenuItem in particular, it will also contain the "Press F1 for more
help" text at the bottom.
2023-04-12 22:07:08 +02:00
Jehan 63e48171a4 app: fix activating GimpEnumAction in the GimpMenu.
Not sure why gtk_actionable_set_action_name() works fine to activate base
GimpActionImpl, but not subclasses like GimpProcedureAction or GimpEnumAction
(and maybe others subclasses?), such as the "file-open-recent-*" actions. This
will have to be investigated further IMO.
2023-04-12 22:07:08 +02:00
Jehan d73337680d app: rename the dynamic label for the "file-open-recent-*" actions.
While in the menu, under a contextual "Open Recent" submenu, it is well
understandable, the action is much less understandable without context, e.g. in
the action search. So I prepend an "Open" prefix.

Maybe a future alternative could be to have GimpAction have both contextual and
non-contextual labels (a.k.a. short vs long label)?
2023-04-12 22:07:08 +02:00
Jehan 69a780babb app: add proxy support to GimpAction/GimpMenu.
The proxy properly shows a color area or viewable (depending on context), and
this is properly updated when the associated properties are changed.

The label change is also properly updated in the label part of the proxy.

Very relevant actions to test the proxy items are dynamically updated are
generated actions such as the "file-open-recent-*" actions (with both label and
viewable updates), or again the Edit > "Fill with (FG|BG Color)|Pattern" (with
color/pattern updates).
2023-04-12 22:07:08 +02:00
Jehan 2f70d1a154 app, menus: add the generated actions in the main menu.
These are the menu items such as the recently opened images, or recently used
filters, etc.

Some notes:

- I added back a "placeholder" concept in the GimpMenu logic. This will allow to
  place items at specific positions in the menu (either under the placeholder,
  which will make the last item be on top or above the placeholder to have the
  last item be in the bottom, depending on needs). Technically placeholders are
  just menu items with a label (used as placeholder key) and no associated
  action, which I will leave invisible.
- I add a logic for submenus so that they are invisible by default and are only
  made visible when we add a menu item with an action in there.
- I removed filling the "/Filters/Recently Used/Plug-ins" placeholder. As far as
  I could see, it was never filled (neither with old or new code) and the
  "/Filters/Recently Used/Filters" actually already takes care of filling the
  "Recently Used" submenu with both GEGL operations and plug-in calls.
- The old gimp_ui_manager_add_ui() API is for all types of menus, e.g. including
  the ones created by dockables or elsewhere whereas my new API is (for now)
  still specific to the top menu. This will have to be further implemented
  later. I left a bunch of "TODO GMenu"-s for the time being.
- I see 2 dock-related generated items which seem to never be added, for
  recently added and closed docks. It doesn't seem to work in the old API as
  well. I'll want to have a closer look too.
2023-04-12 22:07:08 +02:00
Jehan 37c11f0134 app: support adding new items and submenus to GimpMenu.
In particular, we use this to add the actions created by GimpPlugInProcedure
(i.e. by plug-ins) to the main menu.
2023-04-12 22:07:08 +02:00
Jehan f66e893bb3 app: GimpMenu also monitors the "label" and "tooltip" properties of GimpAction.
Some actions in particular can change their label. E.g. "file-export" and
"file-overwrite" will have customized labels containing the imported or exported
file name. The menu will now reflect such changes, live.
2023-04-12 22:07:08 +02:00
Jehan 66eeb4fe6c app, menus: make GimpMenu item visibility sync on action visibility. 2023-04-12 22:07:08 +02:00
Jehan 19b03fcc43 app: make "sensitive" a GimpAction property.
I'm starting to override GtkAction properties, starting with "sensitive" in
order to finally move away from GtkAction. Obviously, this breaks the
sensitivity check of the original menu.
2023-04-12 22:07:08 +02:00
Jehan ed8a4f7410 app: fix a segfault which may happen randomly.
I could reproduce this while closing GIMP immediately after starting it.
Sometimes the idle source would be running and working on now finalized objects.
2023-04-12 22:07:08 +02:00
Jehan 3119ad4c34 app: toggle and radio item are now correctly synced with their action state.
In particular, when running actions from somewhere else (i.e. the action
search), the menu render is updated.
2023-04-12 22:07:08 +02:00
Jehan febb9dccd6 app: fix default values of 2 actions.
"windows-show-tabs" and "windows-use-single-window-mode" were set to FALSE by
default, while it is now supposed to be TRUE, same as the config properties. The
discrepancy was only showing with my new GimpMenu which better follows the
action's state.
2023-04-12 22:07:08 +02:00
Jehan 342ad2c37f app, menus: very early prototype for a GimpMenu.
This demonstrates a first version of our replacing menu, using GAction and
GMenuModel. I had to make our own subclass of GtkMenu to process the model (from
a .ui XML file) for the following reasons:

* gtk_menu_new_from_model() doesn't support tooltips, which is a feature we use
  quite extensively in GIMP: with all our filters, being able to give a longer
  description is often useful; moreover we use tooltips to give hints about why
  a menu item is deactivated as well.
  Unfortunately it looks like GTK doesn't consider this lack as a problem and
  don't plan on adding tooltip support.
  See: https://gitlab.gnome.org/GNOME/gtk/-/issues/785
* I won't to avoid copying action's label and icons in the .ui file. This only
  duplicates strings and would be a source of issues each time we change
  action's strings (we'd have to do it in 2 places, which someone will
  inevitably forget).

Now it still has various issues:

* The syncing between actions and menu items need to be cleaned up. It's still
  in early demo code.
* It uses directly some Gtk*Action code because GimpRadioAction and
  GimpToggleAction are not directly related right now (only through their
  parents).
* gtk_application_set_menubar() might still be necessary on macOS as I think
  it's what enables the native menu system on this OS. It means that we'll have
  to edit the menu model to add back the labels (as this function does not
  extract these from the linked action since GAction has no label or icon
  concept).
* Icons are not taken into account right now.
* I'll have to verify if GimpAction with proxy work (but my guess is that right
  now, it won't).
* Action's active state is not synced with menu item active state right now.
* Various actions are inserted live, such as opened images, opened views,
  recently opened images, and so on. This needs to be implemented back.
* Plug-ins need to be able to create their own menu item into this new menu.
* For all these various reasons, I'm keeping the old menu around, for the sake
  of comparison, until the time the new one becomes feature-full.

Part of this commit is inspired by !558 and obsoletes this MR.
2023-04-12 22:07:08 +02:00
Jehan b6a99077dc app: gimp_action_activate() uses GAction API.
Since GimpAction-s are currently both a GtkAction and a GAction, let's use the
GAction API for activating actions.
2023-04-12 22:07:08 +02:00
Jehan 1b54616492 app: don't make "context" mandatory on a GimpAction.
Simply with a NULL context, we can't set or get accels from a GimpAction. Having
a mandatory context was a problem for GimpColorButton which could create a
GimpAction even though libgimpwidget has no knowledge of GimpContext.
2023-04-12 22:07:08 +02:00
Jehan a98a903976 app: get rid of gimp_action_(g|s)et_accel_path(). 2023-04-12 22:07:08 +02:00