diff --git a/src/contextmenu.cpp b/src/contextmenu.cpp index 117616a..2b52dda 100644 --- a/src/contextmenu.cpp +++ b/src/contextmenu.cpp @@ -35,13 +35,13 @@ ContextMenu::ContextMenu(GMenu2X &gmenu2x, Menu &menu) tr.translate("Add link in $1", menu.selSection().c_str(), NULL), std::bind(&GMenu2X::addLink, &gmenu2x))); - if (app && !app->getManual().empty()) { - options.push_back(std::make_shared( - tr.translate("Show manual of $1", app->getTitle().c_str(), NULL), - std::bind(&GMenu2X::showManual, &gmenu2x))); - } - - if (app && app->isEditable()) { + if (app) { + if (!app->getManual().empty()) { + options.push_back(std::make_shared( + tr.translate("Show manual of $1", + app->getTitle().c_str(), NULL), + std::bind(&GMenu2X::showManual, &gmenu2x))); + } /* FIXME(percuei): This permits to mask the "Edit link" entry * on the contextual menu in case CPUFREQ support is @@ -49,17 +49,19 @@ ContextMenu::ContextMenu(GMenu2X &gmenu2x, Menu &menu) * This is not a good idea as it'll break things if * a new config option is added to the contextual menu. */ - if (!app->isOpk() + if (app->isEditable() && ( + !app->isOpk() #if defined(ENABLE_CPUFREQ) || true #endif || !app->getSelectorDir().empty() - ) { + )) { options.push_back(std::make_shared( tr.translate("Edit $1", app->getTitle().c_str(), NULL), std::bind(&GMenu2X::editLink, &gmenu2x))); } - if (!app->isOpk()) { + + if (app->isDeletable()) { options.push_back(std::make_shared( tr.translate("Delete $1", app->getTitle().c_str(), NULL), std::bind(&GMenu2X::deleteLink, &gmenu2x))); diff --git a/src/linkapp.cpp b/src/linkapp.cpp index e9e270f..5110225 100644 --- a/src/linkapp.cpp +++ b/src/linkapp.cpp @@ -81,12 +81,13 @@ private: #ifdef HAVE_LIBOPK -LinkApp::LinkApp(GMenu2X *gmenu2x_, const char* linkfile, +LinkApp::LinkApp(GMenu2X *gmenu2x_, const char* linkfile, bool deletable, struct OPK *opk, const char *metadata_) #else -LinkApp::LinkApp(GMenu2X *gmenu2x_, const char* linkfile) +LinkApp::LinkApp(GMenu2X *gmenu2x_, const char* linkfile, bool deletable) #endif : Link(gmenu2x_, bind(&LinkApp::start, this)) + , deletable(deletable) { manual = ""; file = linkfile; diff --git a/src/linkapp.h b/src/linkapp.h index 3ac34b9..51a27e4 100644 --- a/src/linkapp.h +++ b/src/linkapp.h @@ -40,7 +40,7 @@ private: std::string sclock; int iclock; std::string exec, params, workdir, manual, selectordir, selectorfilter; - bool selectorbrowser, editable; + bool selectorbrowser, deletable, editable; std::string file; @@ -61,10 +61,10 @@ public: bool isOpk() { return isOPK; } const std::string &getOpkFile() { return opkFile; } - LinkApp(GMenu2X *gmenu2x, const char* linkfile, + LinkApp(GMenu2X *gmenu2x, const char* linkfile, bool deletable, struct OPK *opk = NULL, const char *metadata = NULL); #else - LinkApp(GMenu2X *gmenu2x, const char* linkfile); + LinkApp(GMenu2X *gmenu2x, const char* linkfile, bool deletable); bool isOpk() { return false; } #endif @@ -93,6 +93,7 @@ public: void showManual(); void selector(int startSelection=0, const std::string &selectorDir=""); bool targetExists(); + bool isDeletable() { return deletable; } bool isEditable() { return editable; } const std::string &getFile() { return file; } diff --git a/src/menu.cpp b/src/menu.cpp index e4fc0a0..1a10d26 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -495,7 +495,7 @@ bool Menu::addLink(string path, string file, string section) { INFO("Section: '%s(%i)'\n", sections[isection].c_str(), isection); - LinkApp* link = new LinkApp(gmenu2x, linkpath.c_str()); + LinkApp* link = new LinkApp(gmenu2x, linkpath.c_str(), true); link->setSize(gmenu2x->skinConfInt["linkWidth"],gmenu2x->skinConfInt["linkHeight"]); links[isection].push_back( link ); } @@ -698,7 +698,10 @@ void Menu::openPackage(std::string path, bool order) if (!has_metadata) break; - link = new LinkApp(gmenu2x, path.c_str(), opk, name); + // Note: OPK links can only be deleted by removing the OPK itself, + // but that is not something we want to do in the menu, + // so consider this link undeletable. + link = new LinkApp(gmenu2x, path.c_str(), false, opk, name); link->setSize(gmenu2x->skinConfInt["linkWidth"], gmenu2x->skinConfInt["linkHeight"]); addSection(link->getCategory()); @@ -844,8 +847,11 @@ void Menu::readLinks() { + sections[correct], linkfiles); sort(linkfiles.begin(), linkfiles.end(),case_less()); - for (uint x=0; xsetSize(gmenu2x->skinConfInt["linkWidth"], gmenu2x->skinConfInt["linkHeight"]); if (link->targetExists()) links[i].push_back(link);