Give FileFilterList its own .[Ch] files.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9305 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2004-11-25 11:08:32 +00:00
parent e1a01fc544
commit 8eea28ec80
25 changed files with 216 additions and 128 deletions

View File

@ -63,9 +63,9 @@
#include "graphics/Previews.h"
#include "support/filefilterlist.h"
#include "support/filetools.h"
#include "support/forkedcontr.h"
#include "support/globbing.h"
#include "support/path_defines.h"
#include "support/tostr.h"
#include "support/types.h"

View File

@ -1,3 +1,9 @@
2004-11-25 Angus Leeming <leeming@lyx.org>
* BufferView_pimpl.C:
* lyx_cb.C:
* lyxfunc.C: s/globbing.h/filefilterlist.h/ in #includes.
2004-11-24 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* lyxfunc.C (getStatus, dispatch): use FuncStatus::message; only

View File

@ -1,3 +1,14 @@
2004-11-25 Angus Leeming <leeming@lyx.org>
* ControlBibtex.C:
* ControlExternal.C:
* ControlGraphics.C:
* ControlInclude.C:
* ControlPrefs.C:
* ControlPrint.C: s/globbing.h/filefilterlist.h/ in #includes.
* helper_funcs.C: remove #include "globbing.h".
2004-11-22 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* ControlSpellchecker.C (check): update the view when setting the

View File

@ -22,8 +22,8 @@
#include "tex_helpers.h"
#include "gettext.h"
#include "support/filefilterlist.h"
#include "support/filetools.h"
#include "support/globbing.h"
using std::pair;
using std::string;

View File

@ -27,8 +27,8 @@
#include "insets/ExternalSupport.h"
#include "insets/ExternalTemplate.h"
#include "support/filefilterlist.h"
#include "support/filetools.h"
#include "support/globbing.h"
#include "support/tostr.h"
using std::advance;

View File

@ -26,8 +26,8 @@
#include "insets/insetgraphics.h"
#include "support/FileInfo.h"
#include "support/filefilterlist.h"
#include "support/filetools.h"
#include "support/globbing.h"
#include "support/path_defines.h"
#include "support/tostr.h"
#include "support/types.h"

View File

@ -24,8 +24,8 @@
#include "insets/insetinclude.h"
#include "support/filefilterlist.h"
#include "support/filetools.h"
#include "support/globbing.h"
#include <utility>

View File

@ -20,7 +20,7 @@
#include "funcrequest.h"
#include "LColor.h"
#include "support/globbing.h"
#include "support/filefilterlist.h"
#include <sstream>

View File

@ -22,8 +22,8 @@
#include "PrinterParams.h"
#include "support/tostr.h"
#include "support/filefilterlist.h"
#include "support/filetools.h"
#include "support/globbing.h"
using std::string;

View File

@ -21,7 +21,6 @@
#include "support/filetools.h"
#include "support/path_defines.h"
#include "support/globbing.h"
using std::pair;
using std::vector;

View File

@ -1,3 +1,8 @@
2004-11-25 Angus Leeming <leeming@lyx.org>
* FileDialog.C:
* FileDialog_private.C: s/globbing.h/filefilterlist.h/ in #includes.
2004-11-22 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* lengthvalidator.[Ch]: add GlueLength validator

View File

@ -19,7 +19,7 @@
#include "debug.h"
#include "gettext.h"
#include "support/globbing.h"
#include "support/filefilterlist.h"
/** when this is defined, the code will use
* QFileDialog::getOpenFileName and friends to create filedialogs.

View File

@ -13,7 +13,7 @@
#include "FileDialog_private.h"
#include "qt_helpers.h"
#include "support/globbing.h"
#include "support/filefilterlist.h"
#include "support/lstrings.h"
#include <qapplication.h>

View File

@ -1,3 +1,9 @@
2004-11-25 Angus Leeming <leeming@lyx.org>
* FileDialog.C: s/globbing.h/filefilterlist.h/ in #includes.
* FormFileDialog.C: add #include "filefilterlist.h"
* FormBibtex.C: remove #include "globbing.h".
2004-11-16 Lars Gullik Bjonnes <larsbj@gullik.net>
* Layoutengine.[Ch]: Break up circular dependency between Box and

View File

@ -16,7 +16,7 @@
#include "debug.h"
#include "gettext.h"
#include "support/globbing.h"
#include "support/filefilterlist.h"
#include "support/lstrings.h"
using lyx::support::rsplit;

View File

@ -22,7 +22,6 @@
#include "xformsBC.h"
#include "support/filetools.h"
#include "support/globbing.h"
#include "support/lstrings.h"
#include "support/lyxalgo.h"

View File

@ -20,6 +20,7 @@
#include "frontends/Dialogs.h"
#include "support/FileInfo.h"
#include "support/filefilterlist.h"
#include "support/filetools.h"
#include "support/globbing.h"
#include "support/lstrings.h"

View File

@ -34,10 +34,10 @@
#include "frontends/lyx_gui.h"
#include "frontends/LyXView.h"
#include "support/filefilterlist.h"
#include "support/FileInfo.h"
#include "support/filetools.h"
#include "support/forkedcall.h"
#include "support/globbing.h"
#include "support/lyxlib.h"
#include "support/os.h"
#include "support/path.h"

View File

@ -78,10 +78,10 @@
#include "frontends/Menubar.h"
#include "frontends/Toolbars.h"
#include "support/filefilterlist.h"
#include "support/FileInfo.h"
#include "support/filetools.h"
#include "support/forkedcontr.h"
#include "support/globbing.h"
#include "support/lstrings.h"
#include "support/path.h"
#include "support/path_defines.h"

View File

@ -1,3 +1,10 @@
2004-11-25 Angus Leeming <leeming@lyx.org>
* filefilterlist.[Ch]:
* globbing.[Ch]: split FileFilterList into its own .[Ch] files.
* Makefile.am: add filefilterlist.[Ch].
2004-11-16 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* textutils.h (isKommaChar): remove

View File

@ -28,6 +28,8 @@ libsupport_la_SOURCES = \
copied_ptr.h \
cow_ptr.h \
debugstream.h \
filefilterlist.C \
filefilterlist.h \
filename.C \
filename.h \
filetools.C \

View File

@ -0,0 +1,107 @@
/**
* \file filefilterlist.C
* 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/globbing.h"
#include "support/lstrings.h"
// FIXME Interface violation
#include "gettext.h"
#include <boost/regex.hpp>
#include </usr/include/glob.h>
#include <sstream>
using std::distance;
using std::ostringstream;
using std::string;
using std::vector;
namespace lyx {
namespace support {
FileFilterList::FileFilterList(string const & qt_style_filter)
{
string const filter = qt_style_filter
+ (qt_style_filter.empty() ? string() : ";;")
+ _("All files (*)");
// 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(string(), trim(filter)));
} else {
string const desc = 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)));
}
}
string const FileFilterList::str(bool expand) const
{
ostringstream ss;
vector<Filter>::const_iterator const begin = filters_.begin();
vector<Filter>::const_iterator const end = filters_.end();
vector<Filter>::const_iterator it = begin;
for (; it != end; ++it) {
string const globs = expand ?
convert_brace_glob(it->globs()) : it->globs();
if (it != begin)
ss << ";;";
bool const has_description = !it->description().empty();
if (has_description)
ss << it->description() << " (";
ss << globs;
if (has_description)
ss << ')';
}
return ss.str();
}
} // namespace support
} // namespace lyx

View File

@ -0,0 +1,59 @@
// -*- 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 <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:
class Filter {
std::string desc_;
std::string globs_;
public:
Filter(std::string const & d, std::string const & g)
: desc_(d), globs_(g) {}
std::string const & description() const { return desc_; }
std::string const & globs() const { return globs_; }
};
/** \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(std::string const & qt_style_filter = std::string());
std::vector<Filter> const & filters() const { return filters_; }
/** \param expand pass each glob through \c convert_brace_glob.
* \returns the equivalent of the string passed to the c-tor.
*/
std::string const str(bool expand) const;
private:
void parse_filter(std::string const & filter);
std::vector<Filter> filters_;
};
} // namespace support
} // namespace lyx
#endif // NOT FILE_FILTER_LIST_H

View File

@ -14,18 +14,12 @@
#include "support/lstrings.h"
#include "support/path.h"
// FIXME Interface violation
#include "gettext.h"
#include <boost/regex.hpp>
#include <boost/tokenizer.hpp>
#include <glob.h>
#include <sstream>
using std::distance;
using std::ostringstream;
using std::string;
using std::vector;
@ -111,77 +105,5 @@ vector<string> const expand_globs(string const & mask,
return matches;
}
FileFilterList::FileFilterList(string const & qt_style_filter)
{
string const filter = qt_style_filter
+ (qt_style_filter.empty() ? string() : ";;")
+ _("All files (*)");
// 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(string(), trim(filter)));
} else {
string const desc = 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)));
}
}
string const FileFilterList::str(bool expand) const
{
ostringstream ss;
vector<Filter>::const_iterator const begin = filters_.begin();
vector<Filter>::const_iterator const end = filters_.end();
vector<Filter>::const_iterator it = begin;
for (; it != end; ++it) {
string const globs = expand ?
convert_brace_glob(it->globs()) : it->globs();
if (it != begin)
ss << ";;";
bool const has_description = !it->description().empty();
if (has_description)
ss << it->description() << " (";
ss << globs;
if (has_description)
ss << ')';
}
return ss.str();
}
} // namespace support
} // namespace lyx

View File

@ -48,42 +48,6 @@ std::vector<std::string> const
expand_globs(std::string const & mask,
std::string const & directory = std::string());
/** \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:
class Filter {
std::string desc_;
std::string globs_;
public:
Filter(std::string const & d, std::string const & g)
: desc_(d), globs_(g) {}
std::string const & description() const { return desc_; }
std::string const & globs() const { return globs_; }
};
/** \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(std::string const & qt_style_filter = std::string());
std::vector<Filter> const & filters() const { return filters_; }
/** \param expand pass each glob through \c convert_brace_glob.
* \returns the equivalent of the string passed to the c-tor.
*/
std::string const str(bool expand) const;
private:
void parse_filter(std::string const & filter);
std::vector<Filter> filters_;
};
} // namespace support
} // namespace lyx