Unfortunately I still do not fully understand the code.
One point which I try to understand is
HowDoI/GAction - GNOME Wiki! section Action scopes.
What code do I need to get actions for whole app, and what code to get action for one window only.
From HowDoI/GAction - GNOME Wiki!
I may get the feeling that I have to define window actions in activateCb()?
To test I modified your example in this way:
static void test1_callback(GSimpleAction *action, GVariant *parameter, gpointer user_data)
{
g_print("Test1 Callback\n");
GtkWindow *w = gtk_application_get_active_window (GTK_APPLICATION (user_data));
gtk_window_maximize (w);
}
My assumption was, that as test1_callback() in an app action, it would maximize all open windows now. But it seems to maximize only one. While quit_program() closes all windows and terminates the app.
Next change what I did was
g_menu_append(section, "Test1", "win.test1");
changing “app.test1” to “win.test1”. Result is that menu entry is grey and can not be selected. Why?
[EDIT]
Well, after one hour of google search I found some more info about Action scopes in
https://wiki.gnome.org/HowDoI/ApplicationMenu
(I did not read that page carefully at the beginning due to the DEPRECATION WARNING).
I really hope Mr Ron Tarrant will write some tutorials about the non trivial points of GTK at some time in the future
[EDIT 2]
“app” actions affect the application as a whole and are installed directly on the GtkApplication. “win” actions affect one window specifically and are installed onto each GtkApplicationWindow.
From
https://wiki.gnome.org/HowDoI/GAction
we can learn that we can create a a “window” action with
13 window.add_action(action)
and bind it to a button with
19 button.set_action_name("win.save")
But how will the saveCB callback detect that it is a “windows” action from
12 action.connect("activate", saveCb)
From HowDoI/ApplicationMenu - GNOME Wiki!
it seems that for win and app actions there is only a cosmetic difference:
When the application menu is shown by the shell, the “win.” actions are referring to the copy of this action on the currently focused window. If such an action does not exist, the menu item will be greyed out.
But creating a menu item that is always greyed out makes no real sense. So there is no real benefit for win actions, we can always app actions, as C. Eric Cashon did in his example code?