diff --git a/src/gmenu2x.cpp b/src/gmenu2x.cpp index ac6e17d..1982adb 100644 --- a/src/gmenu2x.cpp +++ b/src/gmenu2x.cpp @@ -1026,11 +1026,6 @@ void GMenu2X::addSection() { void GMenu2X::deleteSection() { - string path = getHome() + "/sections/" + menu->selSection(); - if (rmdir(path.c_str()) && errno != ENOENT) { - WARNING("Removal of section dir \"%s\" failed: %s\n", - path.c_str(), strerror(errno)); - } menu->deleteSelectedSection(); } diff --git a/src/menu.cpp b/src/menu.cpp index e8306d8..30c842d 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -500,13 +500,22 @@ void Menu::deleteSelectedLink() } } -void Menu::deleteSelectedSection() { - INFO("Deleting section '%s'\n", selSection().c_str()); +void Menu::deleteSelectedSection() +{ + string const& sectionName = selSection(); + INFO("Deleting section '%s'\n", sectionName.c_str()); - gmenu2x.sc.del("sections/"+selSection()+".png"); - links.erase( links.begin()+selSectionIndex() ); - sections.erase( sections.begin()+selSectionIndex() ); + gmenu2x.sc.del("sections/" + sectionName + ".png"); + auto idx = selSectionIndex(); + links.erase(links.begin() + idx); + sections.erase(sections.begin() + idx); setSectionIndex(0); //reload sections + + string path = GMenu2X::getHome() + "/sections/" + sectionName; + if (rmdir(path.c_str()) && errno != ENOENT) { + WARNING("Removal of section dir \"%s\" failed: %s\n", + path.c_str(), strerror(errno)); + } } bool Menu::linkChangeSection(uint linkIndex, uint oldSectionIndex, uint newSectionIndex) {