22
33#include < sigc++/signal.h>
44
5+ #include < gtkmm/applicationwindow.h>
56#include < gtkmm/gestureclick.h>
67#include < gtkmm/icontheme.h>
78
89#include " gui/eventtransmitter.h"
910#include " gui/instance.h"
11+ #include " gui/menufunctions.h"
1012
1113#include " theatre/chase.h"
1214#include " theatre/effect.h"
@@ -233,22 +235,19 @@ void ObjectList::constructContextMenu() {
233235
234236 FolderObject *obj = SelectedObject ().Get ();
235237 if (obj != &Instance::Management ().RootFolder ()) {
236- std::shared_ptr<Gio::SimpleActionGroup> actions =
237- Gio::SimpleActionGroup::create ();
238+ Gio::ActionMap &actions = Instance::MainWindow ();
238239 // Move up & down
239- menu->append (" Move up" , " move_object_up" );
240- actions->add_action (" move_object_up" ,
241- sigc::mem_fun (*this , &ObjectList::onMoveUpSelected));
240+ AddMenuItem (actions, menu, " Move up" , " move_object_up" ,
241+ sigc::mem_fun (*this , &ObjectList::onMoveUpSelected));
242242
243- menu->append (" Move down" , " move_object_down" );
244- actions->add_action (" move_object_down" ,
245- sigc::mem_fun (*this , &ObjectList::onMoveDownSelected));
243+ AddMenuItem (actions, menu, " Move down" , " move_object_down" ,
244+ sigc::mem_fun (*this , &ObjectList::onMoveDownSelected));
246245
247246 // Move-to submenu
248247 std::shared_ptr<Gio::Menu> move_to_menu = Gio::Menu::create ();
249248
250249 int folder_counter = 0 ;
251- constructFolderMenu (* move_to_menu, * actions,
250+ constructFolderMenu (move_to_menu, actions,
252251 Instance::Management ().RootFolder (), folder_counter);
253252 menu->append_submenu (" Move to" , move_to_menu);
254253 }
@@ -257,33 +256,34 @@ void ObjectList::constructContextMenu() {
257256 _contextMenu.set_parent (_listView);
258257}
259258
260- void ObjectList::constructFolderMenu (Gio::Menu &menu,
261- Gio::SimpleActionGroup &actions,
262- Folder &folder, int &counter) {
263- if (folder.Children ().empty ()) {
259+ void ObjectList::constructFolderMenu (const std::shared_ptr<Gio::Menu> &menu,
260+ Gio::ActionMap &actions, Folder &folder,
261+ int &counter) {
262+ std::shared_ptr<Gio::Menu> sub_menu;
263+ for (const ObservingPtr<FolderObject> &object : folder.Children ()) {
264+ Folder *subFolder = dynamic_cast <Folder *>(object.Get ());
265+ if (subFolder) {
266+ if (!sub_menu) {
267+ sub_menu = Gio::Menu::create ();
268+ const std::string name = " moveto_" + std::to_string (counter);
269+ ++counter;
270+ AddMenuItem (actions, sub_menu, " ." , name,
271+ [&]() { onMoveSelected (&folder); });
272+ }
273+ constructFolderMenu (sub_menu, actions, *subFolder, counter);
274+ }
275+ }
276+
277+ if (sub_menu) {
278+ menu->append_submenu (folder.Name (), sub_menu);
279+ } else {
280+ // If the folder is empty, we create a single menu item
264281 const std::string name = " moveto_" + std::to_string (counter);
265282 ++counter;
266- menu.append (folder.Name (), name);
267- std::shared_ptr<Gio::SimpleAction> parent =
268- actions.add_action (name, [&]() { onMoveSelected (&folder); });
283+ std::shared_ptr<Gio::SimpleAction> item = AddMenuItem (
284+ actions, menu, folder.Name (), name, [&]() { onMoveSelected (&folder); });
269285
270- if (&folder == SelectedObject ()) parent->set_enabled (false );
271- } else {
272- std::shared_ptr<Gio::Menu> sub_menu;
273- for (const ObservingPtr<FolderObject> &object : folder.Children ()) {
274- Folder *subFolder = dynamic_cast <Folder *>(object.Get ());
275- if (subFolder) {
276- if (!sub_menu) {
277- sub_menu = Gio::Menu::create ();
278- const std::string name = " moveto_" + std::to_string (counter);
279- ++counter;
280- menu.append (" ." , name);
281- actions.add_action (name, [&]() { onMoveSelected (&folder); });
282- }
283- constructFolderMenu (*sub_menu, actions, *subFolder, counter);
284- }
285- }
286- menu.append_submenu (folder.Name (), sub_menu);
286+ if (&folder == SelectedObject ()) item->set_enabled (false );
287287 }
288288}
289289
@@ -304,8 +304,17 @@ void ObjectList::TreeViewWithMenu::OnButtonPress(double x, double y) {
304304}
305305
306306void ObjectList::onMoveSelected (Folder *destination) {
307- Folder::Move (SelectedObject (), *destination);
308- Instance::Events ().EmitUpdate ();
307+ try {
308+ Folder::Move (SelectedObject (), *destination);
309+ Instance::Events ().EmitUpdate ();
310+ } catch (std::exception &e) {
311+ dialog_ = std::make_unique<Gtk::MessageDialog>(
312+ Instance::MainWindow (),
313+ " Could not move item to " + destination->Name () + " : " + e.what (),
314+ false , Gtk::MessageType::ERROR, Gtk::ButtonsType::OK, true );
315+ dialog_->signal_response ().connect ([this ](int ) { dialog_.reset (); });
316+ dialog_->show ();
317+ }
309318}
310319
311320void ObjectList::onMoveUpSelected () {
0 commit comments