#include "qt_helpers.h"
#include "support/debug.h"
-#include "support/FileFilterList.h"
#include "support/FileName.h"
#include "support/gettext.h"
#include "support/os.h"
#ifdef USE_NATIVE_FILEDIALOG
#include <QApplication>
-#include "support/filetools.h"
-
-using lyx::support::makeAbsPath;
#endif
namespace lyx {
-using support::FileFilterList;
using support::os::internal_path;
FileDialog::Result FileDialog::save(QString const & path,
- FileFilterList const & filters,
- QString const & suggested)
+ QStringList const & filters, QString const & suggested)
{
LYXERR(Debug::GUI, "Select with path \"" << fromqstr(path)
- << "\", mask \"" << to_utf8(filters.as_string())
+ << "\", mask \"" << fromqstr(filters.join(";;"))
<< "\", suggested \"" << fromqstr(suggested) << '"');
FileDialog::Result result;
result.first = FileDialog::Chosen;
#ifdef USE_NATIVE_FILEDIALOG
- QString const startsWith = toqstr(
- makeAbsPath(fromqstr(suggested), fromqstr(path)).absFilename());
+ QString const startsWith = makeAbsPath(suggested, path);
QString const name =
QFileDialog::getSaveFileName(qApp->focusWidget(),
- title_,
- startsWith,
- toqstr(filters.as_string()),
- 0,
- QFileDialog::DontConfirmOverwrite);
+ title_, startsWith, filters, 0, QFileDialog::DontConfirmOverwrite);
result.second = toqstr(internal_path(fromqstr(name)));
#else
LyXFileDialog dlg(title_, path, filters, private_->b1, private_->b2);
FileDialog::Result FileDialog::open(QString const & path,
- FileFilterList const & filters,
- QString const & suggested)
+ QStringList const & filters, QString const & suggested)
{
LYXERR(Debug::GUI, "Select with path \"" << fromqstr(path)
- << "\", mask \"" << filters.as_string()
+ << "\", mask \"" << fromqstr(filters.join(";;"))
<< "\", suggested \"" << fromqstr(suggested) << '"');
FileDialog::Result result;
result.first = FileDialog::Chosen;
#ifdef USE_NATIVE_FILEDIALOG
- QString const startsWith = toqstr(
- makeAbsPath(fromqstr(suggested), fromqstr(path)).absFilename());
+ QString const startsWith = makeAbsPath(suggested, path);
result.second = internalPath(
QFileDialog::getOpenFileName(qApp->focusWidget(),
- title_, startsWith, toqstr(filters.as_string()) ));
+ title_, startsWith, filters));
#else
LyXFileDialog dlg(title_, path, filters, private_->b1, private_->b2);
FileDialog::Result FileDialog::opendir(QString const & path,
- QString const & suggested)
+ QString const & suggested)
{
LYXERR(Debug::GUI, "Select with path \"" << fromqstr(path)
<< "\", suggested \"" << fromqstr(suggested) << '"');
result.first = FileDialog::Chosen;
#ifdef USE_NATIVE_FILEDIALOG
- QString const startsWith = toqstr(
- makeAbsPath(fromqstr(suggested), fromqstr(path)).absFilename());
+ QString const startsWith = makeAbsPath(suggested, path);
result.second = toqstr(internal_path(fromqstr(
QFileDialog::getExistingDirectory(qApp->focusWidget(),
title_, startsWith))));
#else
- FileFilterList const filter(_("Directories"));
-
- LyXFileDialog dlg(title_, path, filter, private_->b1, private_->b2);
+ LyXFileDialog dlg(title_, path, QStringList(qt_("Directories")),
+ private_->b1, private_->b2);
dlg.setFileMode(QFileDialog::DirectoryOnly);
namespace lyx {
-namespace support { class FileFilterList; }
-
-
/**
* \class FileDialog
* \brief GUI-I definition of file dialog interface
void setButton2(QString const & label, QString const & dir);
/// Choose a file for opening, starting in directory \c path.
- Result open(QString const & path,
- support::FileFilterList const & filters,
+ Result open(QString const & path, QStringList const & filters,
QString const & suggested = QString());
/// Choose a directory, starting in directory \c path.
QString const & suggested = QString());
/// Choose a file for saving, starting in directory \c path.
- Result save(QString const & path,
- support::FileFilterList const & filters,
+ Result save(QString const & path, QStringList const & filters,
QString const & suggested = QString());
private:
#include "support/debug.h"
#include "support/ExceptionMessage.h"
-#include "support/FileFilterList.h"
#include "support/FileName.h"
#include "support/filetools.h" // changeExtension
#include "support/gettext.h"
{
QString const label1 = qt_("Documents|#o#O");
QString const dir1 = toqstr(lyxrc.document_path);
- FileFilterList const filter(_("BibTeX Databases (*.bib)"));
+ QStringList const filter(qt_("BibTeX Databases (*.bib)"));
return browseRelFile(in_name, bufferFilepath(),
qt_("Select a BibTeX database to add"), filter, false, label1, dir1);
}
{
QString const label1 = qt_("Documents|#o#O");
QString const dir1 = toqstr(lyxrc.document_path);
- FileFilterList const filter(_("BibTeX Styles (*.bst)"));
+ QStringList const filter(qt_("BibTeX Styles (*.bst)"));
return browseRelFile(in_name, bufferFilepath(),
qt_("Select a BibTeX style"), filter, false, label1, dir1);
}
#include "support/convert.h"
#include "support/debug.h"
#include "support/filetools.h"
-#include "support/FileFilterList.h"
#include "support/gettext.h"
#include "support/lstrings.h"
#ifdef Q_WS_MACX
while (true) {
// create file type filter, putting the prefered on to the front
- docstring filterSpec;
+ QStringList filter;
for (size_t i = 0; i != types.size(); ++i) {
docstring s = bformat(_("%1$s Files"), typeNames[types[i]])
+ " (*." + from_ascii(extensions[types[i]]) + ")";
if (types[i] == type)
- filterSpec = s + filterSpec;
+ filter.prepend(toqstr(s));
else
- filterSpec += ";;" + s;
+ filter.append(toqstr(s));
}
- FileFilterList const filter(filterSpec);
+ filter = fileFilters(filter.join(";;"));
// show save dialog for the graphic
FileDialog dlg(qt_("Choose a filename to save the pasted graphic as"));
#include "support/debug.h"
#include "support/FileName.h"
-#include "support/FileFilterList.h"
#include "support/filetools.h"
#include "support/lstrings.h"
{
QString const label1 = qt_("Layouts|#o#O");
QString const dir1 = toqstr(lyxrc.document_path);
- FileFilterList const filter(_("LyX Layout (*.layout)"));
+ QStringList const filter(qt_("LyX Layout (*.layout)"));
QString file = browseRelFile(QString(), bufferFilepath(),
qt_("Local layout file"), filter, false,
label1, dir1);
#include "graphics/GraphicsImage.h"
#include "support/convert.h"
-#include "support/FileFilterList.h"
#include "support/filetools.h"
#include "support/lstrings.h"
#include "support/lyxlib.h"
}
-static string templateFilters(string const & template_name)
+static QStringList templateFilters(QString const & template_name)
{
/// Determine the template file extension
external::TemplateManager const & etm =
external::TemplateManager::get();
external::Template const * const et_ptr =
- etm.getTemplateByName(template_name);
- return et_ptr ? et_ptr->fileRegExp : string();
+ etm.getTemplateByName(fromqstr(template_name));
+
+ return fileFilters(et_ptr ? toqstr(et_ptr->fileRegExp) : QString());
}
{
QString const title = qt_("Select external file");
QString const bufpath = bufferFilepath();
- FileFilterList const filter =
- FileFilterList(from_utf8(templateFilters(fromqstr(template_name))));
+ QStringList const filter = templateFilters(template_name);
QString const label1 = qt_("Documents|#o#O");
QString const dir1 = toqstr(lyxrc.document_path);
#include "support/convert.h"
#include "support/debug.h"
-#include "support/FileFilterList.h"
#include "support/filetools.h"
#include "support/gettext.h"
#include "support/lstrings.h"
clipdir = addName(package().system_support().absFilename(), "clipart");
return browseRelFile(in_name, bufferFilepath(),
- title, FileFilterList(), false,
+ title, fileFilters(QString()), false,
qt_("Clipart|#C#c"), toqstr(clipdir),
qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
}
#include "Buffer.h"
#include "Format.h"
#include "FuncRequest.h"
-#include "support/gettext.h"
#include "LyXRC.h"
#include "qt_helpers.h"
#include "LyXRC.h"
-#include "support/os.h"
+#include "support/gettext.h"
#include "support/lstrings.h"
-#include "support/FileFilterList.h"
+#include "support/os.h"
#include "support/FileName.h"
#include "support/filetools.h"
QString const title = qt_("Select document to include");
// input TeX, verbatim, or LyX file ?
- FileFilterList filters;
+ QStringList filters;
switch (in_type) {
case INCLUDE:
case INPUT:
- filters = FileFilterList(_("LaTeX/LyX Documents (*.tex *.lyx)"));
+ filters = fileFilters(qt_("LaTeX/LyX Documents (*.tex *.lyx)"));
break;
case VERBATIM:
case LISTINGS:
#include "Session.h"
#include "support/debug.h"
-#include "support/FileFilterList.h"
#include "support/FileName.h"
#include "support/filetools.h"
#include "support/foreach.h"
*/
QString browseFile(QString const & filename,
QString const & title,
- support::FileFilterList const & filters,
+ QStringList const & filters,
bool save = false,
QString const & label1 = QString(),
QString const & dir1 = QString(),
QString const & name,
QString const & ext,
QString const & title,
- support::FileFilterList const & filters)
+ QStringList const & filters)
{
// FIXME UNICODE
QString const label1 = qt_("System files|#S#s");
} // namespace frontend
QString browseRelFile(QString const & filename, QString const & refpath,
- QString const & title, FileFilterList const & filters, bool save,
+ QString const & title, QStringList const & filters, bool save,
QString const & label1, QString const & dir1,
QString const & label2, QString const & dir2)
{
void PrefPaths::select_exampledir()
{
- QString file = form_->browsedir(internalPath(exampleDirED->text()),
+ QString file = browseDir(internalPath(exampleDirED->text()),
qt_("Select directory for example files"));
if (!file.isEmpty())
exampleDirED->setText(file);
void PrefPaths::select_templatedir()
{
- QString file = form_->browsedir(internalPath(templateDirED->text()),
+ QString file = browseDir(internalPath(templateDirED->text()),
qt_("Select a document templates directory"));
if (!file.isEmpty())
templateDirED->setText(file);
void PrefPaths::select_tempdir()
{
- QString file = form_->browsedir(internalPath(tempDirED->text()),
+ QString file = browseDir(internalPath(tempDirED->text()),
qt_("Select a temporary directory"));
if (!file.isEmpty())
tempDirED->setText(file);
void PrefPaths::select_backupdir()
{
- QString file = form_->browsedir(internalPath(backupDirED->text()),
+ QString file = browseDir(internalPath(backupDirED->text()),
qt_("Select a backups directory"));
if (!file.isEmpty())
backupDirED->setText(file);
void PrefPaths::select_workingdir()
{
- QString file = form_->browsedir(internalPath(workingDirED->text()),
+ QString file = browseDir(internalPath(workingDirED->text()),
qt_("Select a document directory"));
if (!file.isEmpty())
workingDirED->setText(file);
QString GuiPreferences::browsebind(QString const & file) const
{
return browseLibFile("bind", file, "bind", qt_("Choose bind file"),
- FileFilterList(_("LyX bind files (*.bind)")));
+ QStringList(qt_("LyX bind files (*.bind)")));
}
QString GuiPreferences::browseUI(QString const & file) const
{
return browseLibFile("ui", file, "ui", qt_("Choose UI file"),
- FileFilterList(_("LyX UI files (*.ui)")));
+ QStringList(qt_("LyX UI files (*.ui)")));
}
QString GuiPreferences::browsekbmap(QString const & file) const
{
return browseLibFile("kbd", file, "kmap", qt_("Choose keyboard map"),
- FileFilterList(_("LyX keyboard maps (*.kmap)")));
+ QStringList(qt_("LyX keyboard maps (*.kmap)")));
}
QString GuiPreferences::browsedict(QString const & file) const
{
return browseFile(file, qt_("Choose personal dictionary"),
- FileFilterList(lyxrc.use_spell_lib ? _("*.pws") : _("*.ispell")));
+ QStringList(lyxrc.use_spell_lib ? qt_("*.pws") : qt_("*.ispell")));
}
QString GuiPreferences::browse(QString const & file,
QString const & title) const
{
- return browseFile(file, title, FileFilterList(), true);
-}
-
-
-QString GuiPreferences::browsedir(QString const & path,
- QString const & title) const
-{
- return browseDir(path, title);
+ return browseFile(file, title, QStringList(), true);
}
/// general browse
QString browse(QString const & file, QString const & title) const;
- /// browse directory
- QString browsedir(QString const & path, QString const & title) const;
-
/// set a color
void setColor(ColorCode col, std::string const & hex);
#include "LyXRC.h"
#include "support/convert.h"
-#include "support/FileFilterList.h"
#include "support/filetools.h"
#include "support/gettext.h"
#include "support/os.h"
{
QString file =
browseRelFile(QString(), bufferFilepath(), qt_("Print to file"),
- FileFilterList(_("PostScript files (*.ps)")), true);
+ QStringList(qt_("PostScript files (*.ps)")), true);
if (!file.isEmpty()) {
fileED->setText(file);
changed();
#include "support/assert.h"
#include "support/debug.h"
-#include "support/FileFilterList.h"
#include "support/FileName.h"
#include "support/filetools.h"
#include "support/gettext.h"
dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
dlg.setButton1(qt_("Templates|#T#t"), toqstr(lyxrc.template_path));
- FileDialog::Result result =
- dlg.open(toqstr(lyxrc.template_path),
- FileFilterList(_("LyX Documents (*.lyx)")));
+ FileDialog::Result result = dlg.open(toqstr(lyxrc.template_path),
+ QStringList(qt_("LyX Documents (*.lyx)")));
if (result.first == FileDialog::Later)
return FileName();
toqstr(addPath(package().system_support().absFilename(), "examples")));
FileDialog::Result result =
- dlg.open(toqstr(initpath), FileFilterList(_("LyX Documents (*.lyx)")));
+ dlg.open(toqstr(initpath), QStringList(qt_("LyX Documents (*.lyx)")));
if (result.first == FileDialog::Later)
return;
filter += ')';
FileDialog::Result result =
- dlg.open(toqstr(initpath), FileFilterList(filter));
+ dlg.open(toqstr(initpath), fileFilters(toqstr(filter)));
if (result.first == FileDialog::Later)
return;
toqstr(addPath(package().system_support().absFilename(),
"examples")));
- FileDialog::Result result =
- dlg.open(toqstr(initpath),
- FileFilterList(_("LyX Documents (*.lyx)")));
+ FileDialog::Result result = dlg.open(toqstr(initpath),
+ QStringList(qt_("LyX Documents (*.lyx)")));
if (result.first == FileDialog::Later)
return;
LFUN_FILE_INSERT_PLAINTEXT_PARA : LFUN_FILE_INSERT_PLAINTEXT));
FileDialog::Result result = dlg.open(toqstr(bv->buffer().filePath()),
- FileFilterList());
+ QStringList());
if (result.first == FileDialog::Later)
return;
if (!isLyXFilename(fname.absFilename()))
fname.changeExtension(".lyx");
- FileFilterList const filter(_("LyX Documents (*.lyx)"));
-
FileDialog::Result result =
dlg.save(toqstr(fname.onlyPath().absFilename()),
- filter,
+ QStringList(qt_("LyX Documents (*.lyx)")),
toqstr(fname.onlyFileName()));
if (result.first == FileDialog::Later)
#include "qt_helpers.h"
-#include "support/FileFilterList.h"
#include "support/lstrings.h"
#include <QApplication>
LyXFileDialog::LyXFileDialog(QString const & title,
QString const & path,
- support::FileFilterList const & filters,
+ QStringList const & filters,
FileDialog::Button const & b1,
FileDialog::Button const & b2)
// FIXME replace that with guiApp->currentView()
- : QFileDialog(qApp->focusWidget(), title, path, toqstr(filters.as_string()))
+ : QFileDialog(qApp->focusWidget(), title, path)
{
+ setFilters(filters);
QDir dir(path);
// FIXME: workaround for a bug in qt which makes LyX crash
// with hidden paths (bug 4513). Recheck with recent Qt versions.
namespace lyx {
-namespace support { class FileFilterList; }
-
class LyXFileDialog : public QFileDialog
{
Q_OBJECT
public:
LyXFileDialog(QString const & title,
QString const & path,
- support::FileFilterList const & filters,
+ QStringList const & filters,
FileDialog::Button const & b1,
FileDialog::Button const & b2);
#include <fstream>
#include <locale>
+// for FileFilter.
+// FIXME: Remove
+#include <boost/regex.hpp>
+#include <boost/tokenizer.hpp>
+
+
using namespace std;
using namespace lyx::support;
return toqstr(support::getExtension(fromqstr(name)));
}
+
+/** Convert relative path into absolute path based on a basepath.
+ If relpath is absolute, just use that.
+ If basepath doesn't exist use CWD.
+ */
+QString makeAbsPath(QString const & relpath, QString const & base)
+{
+ return toqstr(support::makeAbsPath(fromqstr(relpath),
+ fromqstr(base)).absFilename());
+}
+
+
+/////////////////////////////////////////////////////////////////////////
+//
+// FileFilterList
+//
+/////////////////////////////////////////////////////////////////////////
+
+/** Given a string such as
+ * "<glob> <glob> ... *.{abc,def} <glob>",
+ * convert the csh-style brace expresions:
+ * "<glob> <glob> ... *.abc *.def <glob>".
+ * Requires no system support, so should work equally on Unix, Mac, Win32.
+ */
+static string const convert_brace_glob(string const & glob)
+{
+ // Matches " *.{abc,def,ghi}", storing "*." as group 1 and
+ // "abc,def,ghi" as group 2.
+ static boost::regex const glob_re(" *([^ {]*)\\{([^ }]+)\\}");
+ // Matches "abc" and "abc,", storing "abc" as group 1.
+ static boost::regex const block_re("([^,}]+),?");
+
+ string pattern;
+
+ string::const_iterator it = glob.begin();
+ string::const_iterator const end = glob.end();
+ while (true) {
+ boost::match_results<string::const_iterator> what;
+ if (!boost::regex_search(it, end, what, glob_re)) {
+ // Ensure that no information is lost.
+ pattern += string(it, end);
+ break;
+ }
+
+ // Everything from the start of the input to
+ // the start of the match.
+ pattern += string(what[-1].first, what[-1].second);
+
+ // Given " *.{abc,def}", head == "*." and tail == "abc,def".
+ string const head = string(what[1].first, what[1].second);
+ string const tail = string(what[2].first, what[2].second);
+
+ // Split the ','-separated chunks of tail so that
+ // $head{$chunk1,$chunk2} becomes "$head$chunk1 $head$chunk2".
+ string const fmt = " " + head + "$1";
+ pattern += boost::regex_merge(tail, block_re, fmt);
+
+ // Increment the iterator to the end of the match.
+ it += distance(it, what[0].second);
+ }
+
+ return pattern;
+}
+
+
+struct Filter
+{
+ /* \param description text describing the filters.
+ * \param one or more wildcard patterns, separated by
+ * whitespace.
+ */
+ Filter(docstring const & description, std::string const & globs);
+
+ docstring const & description() const { return desc_; }
+
+ QString toString() const;
+
+ docstring desc_;
+ std::vector<std::string> globs_;
+};
+
+
+Filter::Filter(docstring const & description, string const & globs)
+ : desc_(description)
+{
+ typedef boost::tokenizer<boost::char_separator<char> > Tokenizer;
+ boost::char_separator<char> const separator(" ");
+
+ // Given "<glob> <glob> ... *.{abc,def} <glob>", expand to
+ // "<glob> <glob> ... *.abc *.def <glob>"
+ string const expanded_globs = convert_brace_glob(globs);
+
+ // Split into individual globs.
+ vector<string> matches;
+ Tokenizer const tokens(expanded_globs, separator);
+ globs_ = vector<string>(tokens.begin(), tokens.end());
+}
+
+
+QString Filter::toString() const
+{
+ QString s;
+
+ bool const has_description = desc_.empty();
+
+ if (has_description) {
+ s += toqstr(desc_);
+ s += " (";
+ }
+
+ for (size_t i = 0; i != globs_.size(); ++i) {
+ if (i > 0)
+ s += ' ';
+ s += toqstr(globs_[i]);
+ }
+
+ if (has_description)
+ s += ')';
+ return s;
+}
+
+
+/** \c FileFilterList parses a Qt-style list of available file filters
+ * to generate the corresponding vector.
+ * For example "TeX documents (*.tex);;LyX Documents (*.lyx)"
+ * will be parsed to fill a vector of size 2, whilst "*.{p[bgp]m} *.pdf"
+ * will result in a vector of size 1 in which the description field is empty.
+ */
+struct FileFilterList
+{
+ // FIXME UNICODE: globs_ should be unicode...
+ /** \param qt_style_filter a list of available file filters.
+ * Eg. "TeX documents (*.tex);;LyX Documents (*.lyx)".
+ * The "All files (*)" filter is always added to the list.
+ */
+ explicit FileFilterList(docstring const & qt_style_filter =
+ docstring());
+
+ typedef std::vector<Filter>::size_type size_type;
+
+ bool empty() const { return filters_.empty(); }
+ size_type size() const { return filters_.size(); }
+ Filter & operator[](size_type i) { return filters_[i]; }
+ Filter const & operator[](size_type i) const { return filters_[i]; }
+
+ void parse_filter(std::string const & filter);
+ std::vector<Filter> filters_;
+};
+
+
+FileFilterList::FileFilterList(docstring const & qt_style_filter)
+{
+ // FIXME UNICODE
+ string const filter = to_utf8(qt_style_filter)
+ + (qt_style_filter.empty() ? string() : ";;")
+ + to_utf8(_("All Files "))
+#if defined(_WIN32)
+ + ("(*.*)");
+#else
+ + ("(*)");
+#endif
+
+ // Split data such as "TeX documents (*.tex);;LyX Documents (*.lyx)"
+ // into individual filters.
+ static boost::regex const separator_re(";;");
+
+ string::const_iterator it = filter.begin();
+ string::const_iterator const end = filter.end();
+ while (true) {
+ boost::match_results<string::const_iterator> what;
+
+ if (!boost::regex_search(it, end, what, separator_re)) {
+ parse_filter(string(it, end));
+ break;
+ }
+
+ // Everything from the start of the input to
+ // the start of the match.
+ parse_filter(string(what[-1].first, what[-1].second));
+
+ // Increment the iterator to the end of the match.
+ it += distance(it, what[0].second);
+ }
+}
+
+
+void FileFilterList::parse_filter(string const & filter)
+{
+ // Matches "TeX documents (*.tex)",
+ // storing "TeX documents " as group 1 and "*.tex" as group 2.
+ static boost::regex const filter_re("([^(]*)\\(([^)]+)\\) *$");
+
+ boost::match_results<string::const_iterator> what;
+ if (!boost::regex_search(filter, what, filter_re)) {
+ // Just a glob, no description.
+ filters_.push_back(Filter(docstring(), trim(filter)));
+ } else {
+ // FIXME UNICODE
+ docstring const desc = from_utf8(string(what[1].first, what[1].second));
+ string const globs = string(what[2].first, what[2].second);
+ filters_.push_back(Filter(trim(desc), trim(globs)));
+ }
+}
+
+
+/** \returns the equivalent of the string passed in
+ * although any brace expressions are expanded.
+ * (E.g. "*.{png,jpg}" -> "*.png *.jpg")
+ */
+QStringList fileFilters(QString const & desc)
+{
+ // we have: "*.{gif,png,jpg,bmp,pbm,ppm,tga,tif,xpm,xbm}"
+ // but need: "*.cpp;*.cc;*.C;*.cxx;*.c++"
+ FileFilterList filters(qstring_to_ucs4(desc));
+ LYXERR0("DESC: " << fromqstr(desc));
+ QStringList list;
+ for (size_t i = 0; i != filters.filters_.size(); ++i) {
+ QString f = filters.filters_[i].toString();
+ LYXERR0("FILTER: " << fromqstr(f));
+ list.append(f);
+ }
+ return list;
+}
+
} // namespace lyx
namespace lyx {
-namespace support { class FileFilterList; }
namespace support { class FileName; }
namespace frontend {
QString browseRelFile(QString const & filename,
QString const & refpath,
QString const & title,
- support::FileFilterList const & filters,
+ QStringList const & filters,
bool save = false,
QString const & label1 = QString(),
QString const & dir1 = QString(),
QString internalPath(QString const &);
QString onlyFilename(QString const & str);
QString onlyPath(QString const & str);
+QStringList fileFilters(QString const & description);
QString changeExtension(QString const & oldname, QString const & extension);
--- /dev/null
+// -*- C++ -*-
+/**
+ * \file qt_i18n.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Dekel Tsur
+ * \author Richard Heck
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef QTI18N_H
+#define QTI18N_H
+
+class QString;
+
+namespace lyx {
+
+/**
+* qt_ - i18nize string and convert to QString
+ *
+ * Use this in qt4/ instead of _()
+ */
+QString const qt_(char const * str, const char * comment = 0);
+
+
+} // namespace lyx
+
+#endif // QTI18_H
+++ /dev/null
-/**
- * \file FileFilterList.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Angus Leeming
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "support/FileFilterList.h"
-
-#include "support/lstrings.h"
-#include "support/gettext.h"
-
-#include <boost/regex.hpp>
-#include <boost/tokenizer.hpp>
-
-#include <sstream>
-
-using namespace std;
-
-namespace {
-
-/** Given a string such as
- * "<glob> <glob> ... *.{abc,def} <glob>",
- * convert the csh-style brace expresions:
- * "<glob> <glob> ... *.abc *.def <glob>".
- * Requires no system support, so should work equally on Unix, Mac, Win32.
- */
-string const convert_brace_glob(string const & glob)
-{
- // Matches " *.{abc,def,ghi}", storing "*." as group 1 and
- // "abc,def,ghi" as group 2.
- static boost::regex const glob_re(" *([^ {]*)\\{([^ }]+)\\}");
- // Matches "abc" and "abc,", storing "abc" as group 1.
- static boost::regex const block_re("([^,}]+),?");
-
- string pattern;
-
- string::const_iterator it = glob.begin();
- string::const_iterator const end = glob.end();
- while (true) {
- boost::match_results<string::const_iterator> what;
- if (!boost::regex_search(it, end, what, glob_re)) {
- // Ensure that no information is lost.
- pattern += string(it, end);
- break;
- }
-
- // Everything from the start of the input to
- // the start of the match.
- pattern += string(what[-1].first, what[-1].second);
-
- // Given " *.{abc,def}", head == "*." and tail == "abc,def".
- string const head = string(what[1].first, what[1].second);
- string const tail = string(what[2].first, what[2].second);
-
- // Split the ','-separated chunks of tail so that
- // $head{$chunk1,$chunk2} becomes "$head$chunk1 $head$chunk2".
- string const fmt = " " + head + "$1";
- pattern += boost::regex_merge(tail, block_re, fmt);
-
- // Increment the iterator to the end of the match.
- it += distance(it, what[0].second);
- }
-
- return pattern;
-}
-
-} // namespace anon
-
-
-namespace lyx {
-namespace support {
-
-FileFilterList::Filter::Filter(docstring const & description,
- string const & globs)
- : desc_(description)
-{
- typedef boost::tokenizer<boost::char_separator<char> > Tokenizer;
- boost::char_separator<char> const separator(" ");
-
- // Given "<glob> <glob> ... *.{abc,def} <glob>", expand to
- // "<glob> <glob> ... *.abc *.def <glob>"
- string const expanded_globs = convert_brace_glob(globs);
-
- // Split into individual globs.
- vector<string> matches;
- Tokenizer const tokens(expanded_globs, separator);
- globs_ = vector<string>(tokens.begin(), tokens.end());
-}
-
-
-FileFilterList::FileFilterList(docstring const & qt_style_filter)
-{
- // FIXME UNICODE
- string const filter = to_utf8(qt_style_filter)
- + (qt_style_filter.empty() ? string() : ";;")
- + to_utf8(_("All Files "))
-#if defined(_WIN32)
- + ("(*.*)");
-#else
- + ("(*)");
-#endif
-
- // Split data such as "TeX documents (*.tex);;LyX Documents (*.lyx)"
- // into individual filters.
- static boost::regex const separator_re(";;");
-
- string::const_iterator it = filter.begin();
- string::const_iterator const end = filter.end();
- while (true) {
- boost::match_results<string::const_iterator> what;
-
- if (!boost::regex_search(it, end, what, separator_re)) {
- parse_filter(string(it, end));
- break;
- }
-
- // Everything from the start of the input to
- // the start of the match.
- parse_filter(string(what[-1].first, what[-1].second));
-
- // Increment the iterator to the end of the match.
- it += distance(it, what[0].second);
- }
-}
-
-
-void FileFilterList::parse_filter(string const & filter)
-{
- // Matches "TeX documents (*.tex)",
- // storing "TeX documents " as group 1 and "*.tex" as group 2.
- static boost::regex const filter_re("([^(]*)\\(([^)]+)\\) *$");
-
- boost::match_results<string::const_iterator> what;
- if (!boost::regex_search(filter, what, filter_re)) {
- // Just a glob, no description.
- filters_.push_back(Filter(docstring(), trim(filter)));
- } else {
- // FIXME UNICODE
- docstring const desc = from_utf8(string(what[1].first, what[1].second));
- string const globs = string(what[2].first, what[2].second);
- filters_.push_back(Filter(trim(desc), trim(globs)));
- }
-}
-
-
-docstring const FileFilterList::as_string() const
-{
- // FIXME UNICODE
- ostringstream ss;
-
- vector<Filter>::const_iterator fit = filters_.begin();
- vector<Filter>::const_iterator const fend = filters_.end();
- for (; fit != fend; ++fit) {
- Filter::glob_iterator const gbegin = fit->begin();
- Filter::glob_iterator const gend = fit->end();
- if (gbegin == gend)
- continue;
-
- if (ss.tellp() > 0)
- ss << ";;";
-
- bool const has_description = !fit->description().empty();
- if (has_description)
- ss << to_utf8(fit->description()) << " (";
-
- for (Filter::glob_iterator git = gbegin; git != gend; ++git) {
- if (git != gbegin)
- ss << ' ';
- ss << *git;
- }
-
- if (has_description)
- ss << ')';
- }
-
- return from_utf8(ss.str());
-}
-
-} // namespace support
-} // namespace lyx
+++ /dev/null
-// -*- C++ -*-
-/**
- * \file FileFilterList.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Angus Leeming
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#ifndef FILE_FILTER_LIST_H
-#define FILE_FILTER_LIST_H
-
-#include "support/docstring.h"
-
-#include <string>
-#include <vector>
-
-namespace lyx {
-namespace support {
-
-/** \c FileFilterList parses a Qt-style list of available file filters
- * to generate the corresponding vector.
- * For example "TeX documents (*.tex);;LyX Documents (*.lyx)"
- * will be parsed to fill a vector of size 2, whilst "*.{p[bgp]m} *.pdf"
- * will result in a vector of size 1 in which the description field is empty.
- */
-class FileFilterList {
-public:
- // FIXME UNICODE: globs_ should be unicode...
- class Filter {
- docstring desc_;
- std::vector<std::string> globs_;
- public:
- /* \param description text describing the filters.
- * \param one or more wildcard patterns, separated by
- * whitespace.
- */
- Filter(docstring const & description,
- std::string const & globs);
-
- docstring const & description() const { return desc_; }
-
- typedef std::vector<std::string>::const_iterator glob_iterator;
- glob_iterator begin() const { return globs_.begin(); }
- glob_iterator end() const { return globs_.end(); }
- };
-
- /** \param qt_style_filter a list of available file filters.
- * Eg. "TeX documents (*.tex);;LyX Documents (*.lyx)".
- * The "All files (*)" filter is always added to the list.
- */
- explicit FileFilterList(docstring const & qt_style_filter =
- docstring());
-
- typedef std::vector<Filter>::size_type size_type;
-
- bool empty() const { return filters_.empty(); }
- size_type size() const { return filters_.size(); }
- Filter & operator[](size_type i) { return filters_[i]; }
- Filter const & operator[](size_type i) const { return filters_[i]; }
-
- /** \returns the equivalent of the string passed to the c-tor
- * although any brace expressions are expanded.
- * (E.g. "*.{png,jpg}" -> "*.png *.jpg")
- */
- docstring const as_string() const;
-
-private:
- void parse_filter(std::string const & filter);
- std::vector<Filter> filters_;
-};
-
-} // namespace support
-} // namespace lyx
-
-#endif // NOT FILE_FILTER_LIST_H
environment.h \
environment.cpp \
ExceptionMessage.h \
- FileFilterList.cpp \
- FileFilterList.h \
FileName.cpp \
FileName.h \
FileNameList.h \