From d24bbb998b456ecdcfe41e5c9aae8ba93152f83d Mon Sep 17 00:00:00 2001 From: fluxgen Date: Sun, 12 Sep 2004 00:31:11 +0000 Subject: inject an entire directory of menu files with include + path, patch from Ciaran McCreesh --- src/MenuCreator.cc | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/src/MenuCreator.cc b/src/MenuCreator.cc index 294b6ae..12bec82 100644 --- a/src/MenuCreator.cc +++ b/src/MenuCreator.cc @@ -20,7 +20,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: MenuCreator.cc,v 1.14 2004/09/09 14:32:56 akir Exp $ +// $Id: MenuCreator.cc,v 1.15 2004/09/12 00:31:11 fluxgen Exp $ #include "MenuCreator.hh" @@ -220,10 +220,43 @@ static void translateMenuItem(Parser &parse, ParseItem &pitem) { menu.insert(str_label.c_str(), &screen->configMenu()); } // end of config else if (str_key == "include") { // include + + // this will make sure we dont get stuck in a loop + static size_t safe_counter = 0; + if (safe_counter > 10) + return; + + safe_counter++; + string newfile = FbTk::StringUtil::expandFilename(str_label); - // inject this file into the current menu - MenuCreator::createFromFile(newfile, menu); - Fluxbox::instance()->saveMenuFilename(newfile.c_str()); + if (FbTk::Directory::isDirectory(newfile)) { + // inject every file in this directory into the current menu + FbTk::Directory dir(newfile.c_str()); + + std::vector filelist(dir.entries()); + for (size_t file_index = 0; file_index < dir.entries(); ++file_index) + filelist[file_index] = dir.readFilename(); + std::sort(filelist.begin(), filelist.end(), less()); + + for (size_t file_index = 0; file_index < dir.entries(); file_index++) { + std::string thisfile(newfile + '/' + filelist[file_index]); + + if (FbTk::Directory::isRegularFile(thisfile) && + (filelist[file_index][0] != '.') && + (thisfile[thisfile.length() - 1] != '~')) { + MenuCreator::createFromFile(thisfile, menu); + Fluxbox::instance()->saveMenuFilename(thisfile.c_str()); + } + } + + } else { + // inject this file into the current menu + MenuCreator::createFromFile(newfile, menu); + Fluxbox::instance()->saveMenuFilename(newfile.c_str()); + } + + safe_counter--; + } // end of include else if (str_key == "submenu") { -- cgit v0.11.2