From: André Pönitz Date: Mon, 5 Nov 2007 22:20:23 +0000 (+0000) Subject: merge helper files; X-Git-Tag: 1.6.10~7469 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=77821e11c1543d9049a15d7a13b36abf6aa4aa5a;p=features.git merge helper files; remove duplicated lyx::frontend::setAutoTextCB(QCheckBox*, QLineEdit*, LengthCombo*) git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21455 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/frontends/frontend_helpers.cpp b/src/frontends/frontend_helpers.cpp deleted file mode 100644 index 50beccb9b3..0000000000 --- a/src/frontends/frontend_helpers.cpp +++ /dev/null @@ -1,241 +0,0 @@ -/** - * \file frontend_helpers.cpp - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author Angus Leeming - * \author Herbert Voß - * - * Full author contact details are available in file CREDITS. - */ - -#include - -#include "frontend_helpers.h" - -#include "gettext.h" -#include "Language.h" - -#include "frontends/FileDialog.h" -#include "frontends/alert.h" - -#include "support/filetools.h" -#include "support/lstrings.h" -#include "support/lyxalgo.h" -#include "support/os.h" -#include "support/Package.h" -#include "support/Path.h" -#include "support/Systemcall.h" - -#include - -#include -#include - -using std::string; -using std::vector; -using std::endl; - -namespace lyx { -namespace frontend { - -using support::addName; -using support::bformat; -using support::FileFilterList; -using support::FileName; -using support::getExtension; -using support::getVectorFromString; -using support::libFileSearch; -using support::makeAbsPath; -using support::makeRelPath; -using support::onlyFilename; -using support::onlyPath; -using support::package; -using support::prefixIs; -using support::quoteName; -using support::removeExtension; -using support::Systemcall; -using support::token; - - -namespace { - -struct Sorter -{ - bool operator()(LanguagePair const & lhs, LanguagePair const & rhs) const { - return lhs.first < rhs.first; - } -}; - - -} // namespace anon - - -vector const getLanguageData(bool character_dlg) -{ - vector::size_type const size = character_dlg ? - languages.size() + 2 : languages.size(); - - vector langs(size); - - if (character_dlg) { - langs[0].first = _("No change"); - langs[0].second = "ignore"; - langs[1].first = _("Reset"); - langs[1].second = "reset"; - } - - vector::size_type i = character_dlg ? 2 : 0; - for (Languages::const_iterator cit = languages.begin(); - cit != languages.end(); ++cit) { - langs[i].first = _(cit->second.display()); - langs[i].second = cit->second.lang(); - ++i; - } - - // Don't sort "ignore" and "reset" - vector::iterator begin = character_dlg ? - langs.begin() + 2 : langs.begin(); - - std::sort(begin, langs.end(), Sorter()); - - return langs; -} - - -docstring browseFile(docstring const & filename, docstring const & title, - FileFilterList const & filters, bool save, - docstring const & label1, docstring const & dir1, - docstring const & label2, docstring const & dir2) -{ - docstring lastPath = from_ascii("."); - if (!filename.empty()) - lastPath = from_utf8(onlyPath(to_utf8(filename))); - - FileDialog dlg(title, LFUN_SELECT_FILE_SYNC); - dlg.setButton1(label1, dir1); - dlg.setButton2(label2, dir2); - - FileDialog::Result result; - - if (save) - result = dlg.save(lastPath, filters, - from_utf8(onlyFilename(to_utf8(filename)))); - else - result = dlg.open(lastPath, filters, - from_utf8(onlyFilename(to_utf8(filename)))); - - return result.second; -} - - -docstring browseRelFile(docstring const & filename, docstring const & refpath, - docstring const & title, FileFilterList const & filters, bool save, - docstring const & label1, docstring const & dir1, - docstring const & label2, docstring const & dir2) -{ - docstring const fname = from_utf8(makeAbsPath( - to_utf8(filename), to_utf8(refpath)).absFilename()); - - docstring const outname = browseFile(fname, title, filters, save, - label1, dir1, label2, dir2); - docstring const reloutname = makeRelPath(outname, refpath); - if (prefixIs(reloutname, from_ascii("../"))) - return outname; - else - return reloutname; -} - - -docstring browseLibFile(docstring const & dir, docstring const & name, - docstring const & ext, docstring const & title, - FileFilterList const & filters) -{ - // FIXME UNICODE - docstring const label1 = _("System files|#S#s"); - docstring const dir1 = - from_utf8(addName(package().system_support().absFilename(), to_utf8(dir))); - - docstring const label2 = _("User files|#U#u"); - docstring const dir2 = - from_utf8(addName(package().user_support().absFilename(), to_utf8(dir))); - - docstring const result = browseFile(from_utf8( - libFileSearch(to_utf8(dir), to_utf8(name), to_utf8(ext)).absFilename()), - title, filters, false, dir1, dir2); - - // remove the extension if it is the default one - docstring noextresult; - if (from_utf8(getExtension(to_utf8(result))) == ext) - noextresult = from_utf8(removeExtension(to_utf8(result))); - else - noextresult = result; - - // remove the directory, if it is the default one - docstring const file = from_utf8(onlyFilename(to_utf8(noextresult))); - if (from_utf8(libFileSearch(to_utf8(dir), to_utf8(file), to_utf8(ext)).absFilename()) == result) - return file; - else - return noextresult; -} - - -docstring browseDir(docstring const & pathname, docstring const & title, - docstring const & label1, docstring const & dir1, - docstring const & label2, docstring const & dir2) -{ - docstring lastPath = from_ascii("."); - if (!pathname.empty()) - lastPath = from_utf8(onlyPath(to_utf8(pathname))); - - FileDialog dlg(title, LFUN_SELECT_FILE_SYNC); - dlg.setButton1(label1, dir1); - dlg.setButton2(label2, dir2); - - FileDialog::Result const result = - dlg.opendir(lastPath, from_utf8(onlyFilename(to_utf8(pathname)))); - - return result.second; -} - - -void rescanTexStyles() -{ - // Run rescan in user lyx directory - support::Path p(package().user_support()); - FileName const command = libFileSearch("scripts", "TeXFiles.py"); - Systemcall one; - int const status = one.startscript(Systemcall::Wait, - lyx::support::os::python() + ' ' + - quoteName(command.toFilesystemEncoding())); - if (status == 0) - return; - // FIXME UNICODE - Alert::error(_("Could not update TeX information"), - bformat(_("The script `%s' failed."), from_utf8(command.absFilename()))); -} - - -void getTexFileList(string const & filename, std::vector & list) -{ - list.clear(); - FileName const file = libFileSearch("", filename); - if (file.empty()) - return; - - list = getVectorFromString(file.fileContents(), "\n"); - - // Normalise paths like /foo//bar ==> /foo/bar - boost::RegEx regex("/{2,}"); - std::vector::iterator it = list.begin(); - std::vector::iterator end = list.end(); - for (; it != end; ++it) - *it = regex.Merge((*it), "/"); - - // remove empty items and duplicates - list.erase(std::remove(list.begin(), list.end(), ""), list.end()); - eliminate_duplicates(list); -} - -} // namespace frontend -} // namespace lyx diff --git a/src/frontends/frontend_helpers.h b/src/frontends/frontend_helpers.h deleted file mode 100644 index 0e6f5bc7ae..0000000000 --- a/src/frontends/frontend_helpers.h +++ /dev/null @@ -1,105 +0,0 @@ -// -*- C++ -*- -/** - * \file frontend_helpers.h - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author Angus Leeming - * \author Herbert Voß - * - * Full author contact details are available in file CREDITS. - */ - -#ifndef FRONTEND_HELPERS_H -#define FRONTEND_HELPERS_H - -#include "support/docstring.h" - -#include - -namespace lyx { - -namespace support { class FileFilterList; } - -namespace frontend { - -/// -typedef std::pair LanguagePair; - -/** If the caller is the character dialog, add "No change" and "Reset" -* to the vector. -*/ -std::vector const getLanguageData(bool character_dlg); - -/** Launch a file dialog and return the chosen file. - filename: a suggested filename. - title: the title of the dialog. - pattern: *.ps etc. - dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog. -*/ -docstring browseFile(docstring const & filename, - docstring const & title, - support::FileFilterList const & filters, - bool save = false, - docstring const & label1 = docstring(), - docstring const & dir1 = docstring(), - docstring const & label2 = docstring(), - docstring const & dir2 = docstring()); - - -/** Wrapper around browseFile which tries to provide a filename - relative to relpath. If the relative path is of the form "foo.txt" - or "bar/foo.txt", then it is returned as relative. OTOH, if it is - of the form "../baz/foo.txt", an absolute path is returned. This is - intended to be useful for insets which encapsulate files/ -*/ -docstring browseRelFile(docstring const & filename, - docstring const & refpath, - docstring const & title, - support::FileFilterList const & filters, - bool save = false, - docstring const & label1 = docstring(), - docstring const & dir1 = docstring(), - docstring const & label2 = docstring(), - docstring const & dir2 = docstring()); - - -/** Wrapper around browseFile which tries to provide a filename -* relative to the user or system directory. The dir, name and ext -* parameters have the same meaning as in the -* support::LibFileSearch function. -*/ -docstring browseLibFile(docstring const & dir, - docstring const & name, - docstring const & ext, - docstring const & title, - support::FileFilterList const & filters); - - -/** Launch a file dialog and return the chosen directory. - pathname: a suggested pathname. - title: the title of the dialog. - dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog. -*/ -docstring browseDir(docstring const & pathname, - docstring const & title, - docstring const & label1 = docstring(), - docstring const & dir1 = docstring(), - docstring const & label2 = docstring(), - docstring const & dir2 = docstring()); - - -/** Build filelists of all availabe bst/cls/sty-files. Done through -* kpsewhich and an external script, saved in *Files.lst. -*/ -void rescanTexStyles(); - -/** Fill \c contents from one of the three texfiles. - * Each entry in the file list is returned as a name_with_path - */ -void getTexFileList(std::string const & filename, std::vector & contents); - -} // namespace frontend -} // namespace lyx - -#endif // FRONTEND_HELPERS_H diff --git a/src/frontends/qt4/GuiBibtex.cpp b/src/frontends/qt4/GuiBibtex.cpp index 73b2ee1ec2..32bcc23aa7 100644 --- a/src/frontends/qt4/GuiBibtex.cpp +++ b/src/frontends/qt4/GuiBibtex.cpp @@ -30,9 +30,6 @@ #include "support/lstrings.h" #include "support/FileFilterList.h" -#include "frontend_helpers.h" - - #include #include #include diff --git a/src/frontends/qt4/GuiCharacter.h b/src/frontends/qt4/GuiCharacter.h index 93193e50b9..b2035cba51 100644 --- a/src/frontends/qt4/GuiCharacter.h +++ b/src/frontends/qt4/GuiCharacter.h @@ -16,7 +16,7 @@ #include "GuiDialog.h" #include "ui_CharacterUi.h" -#include "frontend_helpers.h" // for LanguagePair +#include "qt_helpers.h" // for LanguagePair #include "Font.h" #include diff --git a/src/frontends/qt4/GuiCitation.cpp b/src/frontends/qt4/GuiCitation.cpp index c39c1dd212..73b8f8f012 100644 --- a/src/frontends/qt4/GuiCitation.cpp +++ b/src/frontends/qt4/GuiCitation.cpp @@ -17,7 +17,6 @@ #include "debug.h" #include "gettext.h" -#include "frontend_helpers.h" #include "qt_helpers.h" #include "Buffer.h" #include "BufferParams.h" diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index fb30aba07e..2941113aeb 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -22,7 +22,6 @@ #include "EmbeddedFiles.h" #include "Encoding.h" #include "FloatPlacement.h" -#include "frontend_helpers.h" #include "FuncRequest.h" #include "gettext.h" #include "GuiBranches.h" diff --git a/src/frontends/qt4/GuiExternal.cpp b/src/frontends/qt4/GuiExternal.cpp index 7d17297513..9b2ab0bd06 100644 --- a/src/frontends/qt4/GuiExternal.cpp +++ b/src/frontends/qt4/GuiExternal.cpp @@ -14,7 +14,6 @@ #include "GuiExternal.h" -#include "frontend_helpers.h" #include "FuncRequest.h" #include "gettext.h" #include "Length.h" diff --git a/src/frontends/qt4/GuiGraphics.cpp b/src/frontends/qt4/GuiGraphics.cpp index 30d876ca00..12538d86f3 100644 --- a/src/frontends/qt4/GuiGraphics.cpp +++ b/src/frontends/qt4/GuiGraphics.cpp @@ -22,7 +22,6 @@ #include "LyXRC.h" #include "qt_helpers.h" #include "Validator.h" -#include "frontend_helpers.h" #include "FuncRequest.h" #include "gettext.h" @@ -95,7 +94,7 @@ using support::token; * checkbox is unchecked and clearing the line edit if it previously * said "text". */ -void setAutoTextCB(QCheckBox * checkBox, QLineEdit * lineEdit, +static void setAutoTextCB(QCheckBox * checkBox, QLineEdit * lineEdit, LengthCombo * lengthCombo/*, string text = "auto"*/) { if (!checkBox->isChecked()) @@ -106,8 +105,6 @@ void setAutoTextCB(QCheckBox * checkBox, QLineEdit * lineEdit, lengthCombo->currentLengthItem()); } - - template vector const getFirst(vector const & pr) diff --git a/src/frontends/qt4/GuiInclude.cpp b/src/frontends/qt4/GuiInclude.cpp index 41c5a05a68..02d6aae374 100644 --- a/src/frontends/qt4/GuiInclude.cpp +++ b/src/frontends/qt4/GuiInclude.cpp @@ -14,8 +14,6 @@ #include "GuiInclude.h" -#include "frontend_helpers.h" - #include "Buffer.h" #include "Format.h" #include "FuncRequest.h" diff --git a/src/frontends/qt4/GuiParagraph.cpp b/src/frontends/qt4/GuiParagraph.cpp index 39d09f64ed..29b7e8c816 100644 --- a/src/frontends/qt4/GuiParagraph.cpp +++ b/src/frontends/qt4/GuiParagraph.cpp @@ -22,7 +22,6 @@ #include "debug.h" //#include "DialogView.h" //#include "DockView.h" -#include "frontend_helpers.h" #include "FuncRequest.h" #include "gettext.h" #include "GuiView.h" diff --git a/src/frontends/qt4/GuiPrefs.cpp b/src/frontends/qt4/GuiPrefs.cpp index cfd73512f7..5c6fdcee6e 100644 --- a/src/frontends/qt4/GuiPrefs.cpp +++ b/src/frontends/qt4/GuiPrefs.cpp @@ -42,8 +42,6 @@ #include "graphics/GraphicsTypes.h" -#include "frontend_helpers.h" - #include "frontends/alert.h" #include "frontends/Application.h" @@ -1445,7 +1443,7 @@ PrefLanguage::PrefLanguage(QWidget * parent) defaultLanguageCO->clear(); // store the lang identifiers for later - std::vector const langs = frontend::getLanguageData(false); + std::vector const langs = getLanguageData(false); std::vector::const_iterator lit = langs.begin(); std::vector::const_iterator lend = langs.end(); lang_.clear(); diff --git a/src/frontends/qt4/GuiPrint.cpp b/src/frontends/qt4/GuiPrint.cpp index c652bcf74d..c57c977efc 100644 --- a/src/frontends/qt4/GuiPrint.cpp +++ b/src/frontends/qt4/GuiPrint.cpp @@ -17,8 +17,6 @@ #include "qt_helpers.h" #include "PrinterParams.h" -#include "frontend_helpers.h" - #include "Buffer.h" #include "BufferParams.h" #include "FuncRequest.h" diff --git a/src/frontends/qt4/GuiTexinfo.h b/src/frontends/qt4/GuiTexinfo.h index 9a72e23240..59d2143369 100644 --- a/src/frontends/qt4/GuiTexinfo.h +++ b/src/frontends/qt4/GuiTexinfo.h @@ -15,7 +15,7 @@ #include "GuiDialog.h" #include "ui_TexinfoUi.h" -#include "frontend_helpers.h" +#include "qt_helpers.h" #include #include diff --git a/src/frontends/qt4/Makefile.am b/src/frontends/qt4/Makefile.am index ade4dc01a3..2f82e8c739 100644 --- a/src/frontends/qt4/Makefile.am +++ b/src/frontends/qt4/Makefile.am @@ -50,8 +50,6 @@ SOURCEFILES = \ ../ButtonPolicy.h \ ../Dialog.cpp \ ../Dialog.h \ - ../frontend_helpers.cpp \ - ../frontend_helpers.h \ Resources.cpp \ Action.cpp \ alert_pimpl.cpp \ diff --git a/src/frontends/qt4/alert_pimpl.cpp b/src/frontends/qt4/alert_pimpl.cpp index b45da0f38e..00bc6003aa 100644 --- a/src/frontends/qt4/alert_pimpl.cpp +++ b/src/frontends/qt4/alert_pimpl.cpp @@ -14,9 +14,10 @@ #include "Alert_pimpl.h" #include "alert.h" -#include "ui_AskForTextUi.h" #include "qt_helpers.h" +#include "ui_AskForTextUi.h" + #include "frontends/Application.h" #include "gettext.h" diff --git a/src/frontends/qt4/qt_helpers.cpp b/src/frontends/qt4/qt_helpers.cpp index 9734a29b08..0cc436f400 100644 --- a/src/frontends/qt4/qt_helpers.cpp +++ b/src/frontends/qt4/qt_helpers.cpp @@ -18,26 +18,56 @@ #include "debug.h" #include "gettext.h" +#include "Language.h" #include "Length.h" -#include "support/os.h" +#include "frontends/FileDialog.h" +#include "frontends/alert.h" + +#include "support/filetools.h" #include "support/lstrings.h" +#include "support/lyxalgo.h" +#include "support/os.h" +#include "support/Package.h" +#include "support/Path.h" +#include "support/Systemcall.h" #include #include #include #include +#include + #include +#include +using std::string; +using std::vector; +using std::endl; namespace lyx { +using support::addName; +using support::bformat; +using support::FileFilterList; +using support::FileName; +using support::getExtension; +using support::getVectorFromString; +using support::libFileSearch; +using support::makeAbsPath; +using support::makeRelPath; +using support::onlyFilename; +using support::onlyPath; +using support::package; +using support::prefixIs; +using support::quoteName; +using support::removeExtension; +using support::Systemcall; +using support::token; using support::isStrDbl; -using std::vector; -using std::string; - +namespace frontend { string widgetsToLength(QLineEdit const * input, LengthCombo const * combo) { @@ -106,20 +136,6 @@ void lengthAutoToWidgets(QLineEdit * input, LengthCombo * combo, } -//NOTE "CB" here because we probably will want one of these -//for labeled sets, as well. -void setAutoTextCB(QCheckBox * checkBox, QLineEdit * lineEdit, - LengthCombo * lengthCombo) -{ - if (!checkBox->isChecked()) - lengthToWidgets(lineEdit, lengthCombo, - "auto", lengthCombo->currentLengthItem()); - else if (lineEdit->text() == "auto") - lengthToWidgets(lineEdit, lengthCombo, string(), - lengthCombo->currentLengthItem()); -} - - void setValid(QWidget * widget, bool valid) { if (valid) { @@ -131,6 +147,7 @@ void setValid(QWidget * widget, bool valid) } } +} // namespace frontend QString const qt_(char const * str, const char *) { @@ -143,4 +160,183 @@ QString const qt_(string const & str) return toqstr(_(str)); } +namespace { + +struct Sorter +{ + bool operator()(LanguagePair const & lhs, LanguagePair const & rhs) const { + return lhs.first < rhs.first; + } +}; + + +} // namespace anon + + +vector const getLanguageData(bool character_dlg) +{ + vector::size_type const size = character_dlg ? + languages.size() + 2 : languages.size(); + + vector langs(size); + + if (character_dlg) { + langs[0].first = _("No change"); + langs[0].second = "ignore"; + langs[1].first = _("Reset"); + langs[1].second = "reset"; + } + + vector::size_type i = character_dlg ? 2 : 0; + for (Languages::const_iterator cit = languages.begin(); + cit != languages.end(); ++cit) { + langs[i].first = _(cit->second.display()); + langs[i].second = cit->second.lang(); + ++i; + } + + // Don't sort "ignore" and "reset" + vector::iterator begin = character_dlg ? + langs.begin() + 2 : langs.begin(); + + std::sort(begin, langs.end(), Sorter()); + + return langs; +} + + +docstring browseFile(docstring const & filename, docstring const & title, + FileFilterList const & filters, bool save, + docstring const & label1, docstring const & dir1, + docstring const & label2, docstring const & dir2) +{ + docstring lastPath = from_ascii("."); + if (!filename.empty()) + lastPath = from_utf8(onlyPath(to_utf8(filename))); + + FileDialog dlg(title, LFUN_SELECT_FILE_SYNC); + dlg.setButton1(label1, dir1); + dlg.setButton2(label2, dir2); + + FileDialog::Result result; + + if (save) + result = dlg.save(lastPath, filters, + from_utf8(onlyFilename(to_utf8(filename)))); + else + result = dlg.open(lastPath, filters, + from_utf8(onlyFilename(to_utf8(filename)))); + + return result.second; +} + + +docstring browseRelFile(docstring const & filename, docstring const & refpath, + docstring const & title, FileFilterList const & filters, bool save, + docstring const & label1, docstring const & dir1, + docstring const & label2, docstring const & dir2) +{ + docstring const fname = from_utf8(makeAbsPath( + to_utf8(filename), to_utf8(refpath)).absFilename()); + + docstring const outname = browseFile(fname, title, filters, save, + label1, dir1, label2, dir2); + docstring const reloutname = makeRelPath(outname, refpath); + if (prefixIs(reloutname, from_ascii("../"))) + return outname; + else + return reloutname; +} + + +docstring browseLibFile(docstring const & dir, docstring const & name, + docstring const & ext, docstring const & title, + FileFilterList const & filters) +{ + // FIXME UNICODE + docstring const label1 = _("System files|#S#s"); + docstring const dir1 = + from_utf8(addName(package().system_support().absFilename(), to_utf8(dir))); + + docstring const label2 = _("User files|#U#u"); + docstring const dir2 = + from_utf8(addName(package().user_support().absFilename(), to_utf8(dir))); + + docstring const result = browseFile(from_utf8( + libFileSearch(to_utf8(dir), to_utf8(name), to_utf8(ext)).absFilename()), + title, filters, false, dir1, dir2); + + // remove the extension if it is the default one + docstring noextresult; + if (from_utf8(getExtension(to_utf8(result))) == ext) + noextresult = from_utf8(removeExtension(to_utf8(result))); + else + noextresult = result; + + // remove the directory, if it is the default one + docstring const file = from_utf8(onlyFilename(to_utf8(noextresult))); + if (from_utf8(libFileSearch(to_utf8(dir), to_utf8(file), to_utf8(ext)).absFilename()) == result) + return file; + else + return noextresult; +} + + +docstring browseDir(docstring const & pathname, docstring const & title, + docstring const & label1, docstring const & dir1, + docstring const & label2, docstring const & dir2) +{ + docstring lastPath = from_ascii("."); + if (!pathname.empty()) + lastPath = from_utf8(onlyPath(to_utf8(pathname))); + + FileDialog dlg(title, LFUN_SELECT_FILE_SYNC); + dlg.setButton1(label1, dir1); + dlg.setButton2(label2, dir2); + + FileDialog::Result const result = + dlg.opendir(lastPath, from_utf8(onlyFilename(to_utf8(pathname)))); + + return result.second; +} + + +void rescanTexStyles() +{ + // Run rescan in user lyx directory + support::Path p(package().user_support()); + FileName const command = libFileSearch("scripts", "TeXFiles.py"); + Systemcall one; + int const status = one.startscript(Systemcall::Wait, + lyx::support::os::python() + ' ' + + quoteName(command.toFilesystemEncoding())); + if (status == 0) + return; + // FIXME UNICODE + frontend::Alert::error(_("Could not update TeX information"), + bformat(_("The script `%s' failed."), from_utf8(command.absFilename()))); +} + + +void getTexFileList(string const & filename, std::vector & list) +{ + list.clear(); + FileName const file = libFileSearch("", filename); + if (file.empty()) + return; + + list = getVectorFromString(file.fileContents(), "\n"); + + // Normalise paths like /foo//bar ==> /foo/bar + boost::RegEx regex("/{2,}"); + std::vector::iterator it = list.begin(); + std::vector::iterator end = list.end(); + for (; it != end; ++it) + *it = regex.Merge((*it), "/"); + + // remove empty items and duplicates + list.erase(std::remove(list.begin(), list.end(), ""), list.end()); + eliminate_duplicates(list); +} + } // namespace lyx diff --git a/src/frontends/qt4/qt_helpers.h b/src/frontends/qt4/qt_helpers.h index 9cb868d471..c2437deb10 100644 --- a/src/frontends/qt4/qt_helpers.h +++ b/src/frontends/qt4/qt_helpers.h @@ -17,6 +17,8 @@ #include "support/qstring_helpers.h" #include "support/strfwd.h" +#include + class QComboBox; class QLineEdit; class QCheckBox; @@ -27,6 +29,10 @@ class LengthCombo; namespace lyx { +namespace support { class FileFilterList; } + +namespace frontend { + /// method to get a Length from widgets (LengthCombo) std::string widgetsToLength(QLineEdit const * input, LengthCombo const * combo); /// method to get a Length from widgets (QComboBox) @@ -35,20 +41,22 @@ Length widgetsToLength(QLineEdit const * input, QComboBox const * combo); //FIXME It would be nice if defaultUnit were a default argument /// method to set widgets from a Length void lengthToWidgets(QLineEdit * input, LengthCombo * combo, - Length const & len, Length::UNIT default_unit); +Length const & len, Length::UNIT default_unit); /// method to set widgets from a string void lengthToWidgets(QLineEdit * input, LengthCombo * combo, - std::string const & len, Length::UNIT default_unit); +std::string const & len, Length::UNIT default_unit); /// method to set widgets from a Length with optional "auto" if zero void lengthAutoToWidgets(QLineEdit * input, LengthCombo * combo, - Length const & len, Length::UNIT defaultUnit); +Length const & len, Length::UNIT defaultUnit); /// colors a widget red if invalid void setValid(QWidget * widget, bool valid); +} // namespace frontend + /** - * qt_ - i18nize string and convert to QString +* qt_ - i18nize string and convert to QString * * Use this in qt4/ instead of _() */ @@ -62,6 +70,82 @@ QString const qt_(char const * str, const char * comment = 0); */ QString const qt_(std::string const & str); +/// +typedef std::pair LanguagePair; + +/** If the caller is the character dialog, add "No change" and "Reset" +* to the vector. +*/ +std::vector const getLanguageData(bool character_dlg); + +/** Launch a file dialog and return the chosen file. + filename: a suggested filename. + title: the title of the dialog. + pattern: *.ps etc. + dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog. +*/ +docstring browseFile(docstring const & filename, + docstring const & title, + support::FileFilterList const & filters, + bool save = false, + docstring const & label1 = docstring(), + docstring const & dir1 = docstring(), + docstring const & label2 = docstring(), + docstring const & dir2 = docstring()); + + +/** Wrapper around browseFile which tries to provide a filename + relative to relpath. If the relative path is of the form "foo.txt" + or "bar/foo.txt", then it is returned as relative. OTOH, if it is + of the form "../baz/foo.txt", an absolute path is returned. This is + intended to be useful for insets which encapsulate files/ +*/ +docstring browseRelFile(docstring const & filename, + docstring const & refpath, + docstring const & title, + support::FileFilterList const & filters, + bool save = false, + docstring const & label1 = docstring(), + docstring const & dir1 = docstring(), + docstring const & label2 = docstring(), + docstring const & dir2 = docstring()); + + +/** Wrapper around browseFile which tries to provide a filename +* relative to the user or system directory. The dir, name and ext +* parameters have the same meaning as in the +* support::LibFileSearch function. +*/ +docstring browseLibFile(docstring const & dir, + docstring const & name, + docstring const & ext, + docstring const & title, + support::FileFilterList const & filters); + + +/** Launch a file dialog and return the chosen directory. + pathname: a suggested pathname. + title: the title of the dialog. + dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog. +*/ +docstring browseDir(docstring const & pathname, + docstring const & title, + docstring const & label1 = docstring(), + docstring const & dir1 = docstring(), + docstring const & label2 = docstring(), + docstring const & dir2 = docstring()); + + +/** Build filelists of all availabe bst/cls/sty-files. Done through +* kpsewhich and an external script, saved in *Files.lst. +*/ +void rescanTexStyles(); + +/** Fill \c contents from one of the three texfiles. + * Each entry in the file list is returned as a name_with_path + */ +void getTexFileList(std::string const & filename, std::vector & contents); + } // namespace lyx #endif // QTHELPERS_H