Re: Enable / disable a Gio::SimpleAction.

2020-10-06 Thread Carlo Wood
On Tue, 6 Oct 2020 09:04:07 +0200
Kjell Ahlstedt  wrote:

> Shall be
> 
> auto simple_action = Glib::RefPtr
> ::cast_dynamic(m_refActionGroup->lookup_action("PlacepieceBlackPawn"));
> 
> > if (simple_action)
> >   simple_action->set_enabled(row != 0 && row != 7);

Thanks that works.


I have another problem with the same popup menu: I need certain menu
entries to be radio actions (that is, only one can be selected at
a time, but there are multiple such groups in the single popup menu).

For example, I have:

Gtk::RadioAction::Group group_to_move;
m_refToMoveWhite_action = Gtk::RadioAction::create(group_to_move, 
"ToMoveWhite", "White to play");
m_refToMoveBlack_action = Gtk::RadioAction::create(group_to_move, 
"ToMoveBlack", "Black to play");

where the menu is read from a .glade file with Gtk::Builder, containing:


  
True
False
PlacepieceMenu.ToMoveWhite
White to play
True
True
  


  
True
False
PlacepieceMenu.ToMoveBlack
Black to play
True
True
  


Now I want a function to be called when I click these entries.

In the 2.4 code I had something like:

m_refActionGroup->add_action(m_refToMoveWhite_action, sigc::mem_fun(*this, 
::on_menu_to_move_white));
m_refActionGroup->add_action(m_refToMoveBlack_action, sigc::mem_fun(*this, 
::on_menu_to_move_black));

But that doesn't compile anymore. Because so many things got deprecated, the 
types of many variables
had to change and now I can't combine them anymore :/.

Ie, m_refActionGroup now has the type:

Glib::RefPtr m_refActionGroup;

maybe that has to be Glib::RefPtr before I can add both 
Gio::SimpleAction's
and Gtk::RadioAction to it? The latter isn't derived from Gio:Action either 
though :/.

I am totally stuck on this. Also cannot find any example that shows how to do 
this.

I am just very confused about how all this is supposed to work. Before it 
seemed like that
if I wanted to make a big pop-up menu then EVERY entry in the menu had to be an 
action
and well all of the same group (that was using Gtk::UIManager). Now I'm using 
Gio::Action
and Gtk::Builder instead and I have no idea how to make it working again.

Carlo Wood



___
gtkmm-list mailing list
gtkmm-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtkmm-list


Re: Enable / disable a Gio::SimpleAction.

2020-10-06 Thread Kjell Ahlstedt via gtkmm-list

On 2020-10-05 17:07, Kjell Ahlstedt wrote:


Gio::SimpleActionGroup belongs to glibmm, not to gtkmm. Both gtkmm 2.x 
and gtkmm 3.x use glibmm versions from the glibmm-2.4 ABI series. I 
don't understand how you can do what you say you do in gtkmm 2.x. 
Haven't you used Gtk::ActionGroup and Gtk::Action?  Something like


    Glib::RefPtr m_refActionGroup;
...
m_refActionGroup->get_action("PlacepieceBlackPawn")->set_sensitive(row 
!= 0 && row != 7);


Gtk::ActionGroup and Gtk::Action are deprecated in gtkmm 3.x and removed in 
gtkmm 4.x.

How do you add the Gio::SimpleAction to the Gio::SimpleActionGroup? I suppose 
you have a

Glib::RefPtr refPlacepieceBlackPawn = ..
or a
m_refActionGroup->add_action("PlacepieceBlackPawn"); that returns a 
Glib::RefPtr. 

Then it would be easy to save that Glib::RefPtr, so you 
don't need lookup_action().
If you prefer lookup_action(), this should work in gtkmm 3.x, but not in gtkmm 
4.x:

auto simple_action = 
Glib::RefPtr::cast_dynamic(m_refActionGroup->lookup_action("PlacepieceBlackPawn"));

Shall be

auto simple_action = Glib::RefPtr
::cast_dynamic(m_refActionGroup->lookup_action("PlacepieceBlackPawn"));


if (simple_action)
  simple_action->set_enabled(row != 0 && row != 7);


___
gtkmm-list mailing list
gtkmm-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtkmm-list