X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fcontrollers%2Fhelper_funcs.C;h=34ac0f1207a9a156061d489d7cd1f5c9a26cc61d;hb=120c89f24fae05379fbdc8539d3cfae574c2aecd;hp=96b40435b6c62f7f1ffa0669806e9663276ae2b5;hpb=a12309c76b8fdcc69d0daf38f0b3068ca54d70d2;p=lyx.git diff --git a/src/frontends/controllers/helper_funcs.C b/src/frontends/controllers/helper_funcs.C index 96b40435b6..34ac0f1207 100644 --- a/src/frontends/controllers/helper_funcs.C +++ b/src/frontends/controllers/helper_funcs.C @@ -1,55 +1,134 @@ -/* This file is part of - * ====================================================== - * - * LyX, The Document Processor - * - * Copyright 2001 The LyX Team. +/** + * \file helper_funcs.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. * - * ====================================================== + * \author Angus Leeming * - * \file helper_funcs.C - * \author Angus Leeming + * Full author contact details are available in file CREDITS */ #include -#ifdef __GNUG__ -#pragma implementation -#endif #include #include "LString.h" #include "helper_funcs.h" +#include "frontends/FileDialog.h" +#include "support/filetools.h" // OnlyPath, OnlyFilename +#include "support/lstrings.h" +#include "gettext.h" // _() +#include "frontends/Alert.h" + +using std::pair; using std::vector; +using std::make_pair; + -string const getStringFromVector(vector const & vec, - string const & delim) +string const browseFile(string const & filename, + string const & title, + string const & pattern, + bool save, + pair const & dir1, + pair const & dir2) { - string str; - for (vector::size_type i=0; i 0) str += delim; - str += vec[i]; + string lastPath("."); + if (!filename.empty()) + lastPath = OnlyPath(filename); + + FileDialog fileDlg(title, LFUN_SELECT_FILE_SYNC, dir1, dir2); + + FileDialog::Result result; + + while (true) { + if (save) + result = fileDlg.save(lastPath, pattern, + OnlyFilename(filename)); + else + result = fileDlg.open(lastPath, pattern, + OnlyFilename(filename)); + + if (result.second.empty()) + return result.second; + + lastPath = OnlyPath(result.second); + + if (result.second.find_first_of("#~$% ") == string::npos) + break; + + Alert::alert(_("Filename can't contain any " + "of these characters:"), + _("space, '#', '~', '$' or '%'.")); } - return str; + + return result.second; +} + + +string const browseRelFile(string const & filename, + string const & refpath, + string const & title, + string const & pattern, + bool save, + pair const & dir1, + pair const & dir2) +{ + string const fname = MakeAbsPath(filename, refpath); + + string const outname = browseFile(fname, title, pattern, save, + dir1, dir2); + string const reloutname = MakeRelPath(outname, refpath); + if (prefixIs(reloutname, "../")) + return outname; + else + return reloutname; } -vector const getVectorFromString(string const & str, - string const & delim) + +string const browseDir(string const & pathname, + string const & title, + pair const & dir1, + pair const & dir2) { - vector vec; - string keys(str); + string lastPath("."); + if (!pathname.empty()) + lastPath = OnlyPath(pathname); + + FileDialog fileDlg(title, LFUN_SELECT_FILE_SYNC, dir1, dir2); + + FileDialog::Result result; + + while (true) { + result = fileDlg.opendir(lastPath, + OnlyFilename(pathname)); - for(;;) { - string::size_type const idx = keys.find(delim); - if (idx == string::npos) break; - - vec.push_back(keys.substr(0, idx)); + if (result.second.empty()) + return result.second; - string::size_type const start = idx + delim.size(); - keys = keys.substr(start); + lastPath = OnlyPath(result.second); + + if (result.second.find_first_of("#~$% ") == string::npos) + break; + + Alert::alert(_("directory name can't contain any " + "of these characters:"), + _("space, '#', '~', '$' or '%'.")); } - return vec; + return result.second; } + +// sorry this is just a temporary hack we should include vspace.h! (Jug) +extern const char * stringFromUnit(int); + +vector const getLatexUnits() +{ + vector units; + char const * str; + for (int i = 0; (str = stringFromUnit(i)); ++i) + units.push_back(str); + + return units; +}