Date:2015-04-24 14:46:27 (8 years 11 months ago)
Author:Maarten ter Huurne
Commit:ef6d378c5e401954308260d1fe3a53429fa66f4c
Message:Removed the "Rename section" option

This option is not compatible with section names being provided by
other sources than user-created links. Examples of other sources are
built-in action links, links installed by a distro in a read-only
directory and metadata from OPK files.
Files: src/contextmenu.cpp (1 diff)
src/gmenu2x.cpp (1 diff)
src/gmenu2x.h (1 diff)
src/menu.cpp (1 diff)
src/menu.h (1 diff)

Change Details

src/contextmenu.cpp
7272            tr["Add section"],
7373            std::bind(&GMenu2X::addSection, &gmenu2x)));
7474    options.push_back(std::make_shared<MenuOption>(
75            tr["Rename section"],
76            std::bind(&GMenu2X::renameSection, &gmenu2x)));
77    options.push_back(std::make_shared<MenuOption>(
7875            tr["Delete section"],
7976            std::bind(&GMenu2X::deleteSection, &gmenu2x)));
8077
src/gmenu2x.cpp
10201020    }
10211021}
10221022
1023void GMenu2X::renameSection() {
1024    InputDialog id(*this, input, tr["Insert a new name for this section"],menu->selSection());
1025    if (id.exec()) {
1026        //only if a section with the same name does not exist & !samename
1027        if (menu->selSection() != id.getInput()
1028         && find(menu->getSections().begin(),menu->getSections().end(), id.getInput())
1029                == menu->getSections().end()) {
1030            //section directory doesn't exists
1031            string newsectiondir = getHome() + "/sections/" + id.getInput();
1032            string sectiondir = getHome() + "/sections/" + menu->selSection();
1033
1034            if (!rename(sectiondir.c_str(), newsectiondir.c_str())) {
1035                string oldpng = menu->selSection() + ".png";
1036                string newpng = id.getInput() + ".png";
1037                string oldicon = sc.getSkinFilePath(oldpng);
1038                string newicon = sc.getSkinFilePath(newpng);
1039
1040                if (!oldicon.empty() && newicon.empty()) {
1041                    newicon = oldicon;
1042                    newicon.replace(newicon.find(oldpng), oldpng.length(), newpng);
1043
1044                    if (!fileExists(newicon)) {
1045                        rename(oldicon.c_str(), newicon.c_str());
1046                        sc.move("skin:"+oldpng, "skin:"+newpng);
1047                    }
1048                }
1049                menu->renameSection(menu->selSectionIndex(), id.getInput());
1050            }
1051        }
1052    }
1053}
1054
10551023void GMenu2X::deleteSection() {
10561024    MessageBox mb(*this,tr["You will lose all the links in this section."]+"\n"+tr["Are you sure?"]);
10571025    mb.setButton(InputManager::ACCEPT, tr["Yes"]);
src/gmenu2x.h
199199    void editLink();
200200    void deleteLink();
201201    void addSection();
202    void renameSection();
203202    void deleteSection();
204203
205204    int drawButton(Surface& s, const std::string &btn, const std::string &text, int x=5, int y=-10);
src/menu.cpp
820820
821821    closedir(dirp);
822822}
823
824void Menu::renameSection(int index, string const& name) {
825    sections[index] = name;
826}
src/menu.h
160160    void setLinkIndex(int i);
161161
162162    const std::vector<std::string> &getSections() { return sections; }
163    void renameSection(int index, std::string const& name);
164163};
165164
166165#endif // MENU_H

Archive Download the corresponding diff file



interactive