From 8eea28ec805e70b17974512a0175c7f86df8f2ba Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Thu, 25 Nov 2004 11:08:32 +0000 Subject: [PATCH] Give FileFilterList its own .[Ch] files. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9305 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView_pimpl.C | 2 +- src/ChangeLog | 6 ++ src/frontends/controllers/ChangeLog | 11 ++ src/frontends/controllers/ControlBibtex.C | 2 +- src/frontends/controllers/ControlExternal.C | 2 +- src/frontends/controllers/ControlGraphics.C | 2 +- src/frontends/controllers/ControlInclude.C | 2 +- src/frontends/controllers/ControlPrefs.C | 2 +- src/frontends/controllers/ControlPrint.C | 2 +- src/frontends/controllers/helper_funcs.C | 1 - src/frontends/qt2/ChangeLog | 5 + src/frontends/qt2/FileDialog.C | 2 +- src/frontends/qt2/FileDialog_private.C | 2 +- src/frontends/xforms/ChangeLog | 6 ++ src/frontends/xforms/FileDialog.C | 2 +- src/frontends/xforms/FormBibtex.C | 1 - src/frontends/xforms/FormFiledialog.C | 1 + src/lyx_cb.C | 2 +- src/lyxfunc.C | 2 +- src/support/ChangeLog | 7 ++ src/support/Makefile.am | 2 + src/support/filefilterlist.C | 107 ++++++++++++++++++++ src/support/filefilterlist.h | 59 +++++++++++ src/support/globbing.C | 78 -------------- src/support/globbing.h | 36 ------- 25 files changed, 216 insertions(+), 128 deletions(-) create mode 100644 src/support/filefilterlist.C create mode 100644 src/support/filefilterlist.h diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 62c17dbb50..d1ef1b60a1 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -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" diff --git a/src/ChangeLog b/src/ChangeLog index 6e03fbe666..861fdf51a5 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2004-11-25 Angus Leeming + + * BufferView_pimpl.C: + * lyx_cb.C: + * lyxfunc.C: s/globbing.h/filefilterlist.h/ in #includes. + 2004-11-24 Jean-Marc Lasgouttes * lyxfunc.C (getStatus, dispatch): use FuncStatus::message; only diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index 93a0439272..572535bab0 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,14 @@ +2004-11-25 Angus Leeming + + * 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 * ControlSpellchecker.C (check): update the view when setting the diff --git a/src/frontends/controllers/ControlBibtex.C b/src/frontends/controllers/ControlBibtex.C index 9d7fb6c069..6d4c4328f0 100644 --- a/src/frontends/controllers/ControlBibtex.C +++ b/src/frontends/controllers/ControlBibtex.C @@ -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; diff --git a/src/frontends/controllers/ControlExternal.C b/src/frontends/controllers/ControlExternal.C index f4c75bd187..9c6a251b14 100644 --- a/src/frontends/controllers/ControlExternal.C +++ b/src/frontends/controllers/ControlExternal.C @@ -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; diff --git a/src/frontends/controllers/ControlGraphics.C b/src/frontends/controllers/ControlGraphics.C index d7ca70aacf..a7a46506b6 100644 --- a/src/frontends/controllers/ControlGraphics.C +++ b/src/frontends/controllers/ControlGraphics.C @@ -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" diff --git a/src/frontends/controllers/ControlInclude.C b/src/frontends/controllers/ControlInclude.C index 841543e175..7fa1a1756b 100644 --- a/src/frontends/controllers/ControlInclude.C +++ b/src/frontends/controllers/ControlInclude.C @@ -24,8 +24,8 @@ #include "insets/insetinclude.h" +#include "support/filefilterlist.h" #include "support/filetools.h" -#include "support/globbing.h" #include diff --git a/src/frontends/controllers/ControlPrefs.C b/src/frontends/controllers/ControlPrefs.C index 67f0dc910e..93f2698267 100644 --- a/src/frontends/controllers/ControlPrefs.C +++ b/src/frontends/controllers/ControlPrefs.C @@ -20,7 +20,7 @@ #include "funcrequest.h" #include "LColor.h" -#include "support/globbing.h" +#include "support/filefilterlist.h" #include diff --git a/src/frontends/controllers/ControlPrint.C b/src/frontends/controllers/ControlPrint.C index 38844fb6d2..bd2344d8af 100644 --- a/src/frontends/controllers/ControlPrint.C +++ b/src/frontends/controllers/ControlPrint.C @@ -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; diff --git a/src/frontends/controllers/helper_funcs.C b/src/frontends/controllers/helper_funcs.C index 739e3578cb..7d9fdb1614 100644 --- a/src/frontends/controllers/helper_funcs.C +++ b/src/frontends/controllers/helper_funcs.C @@ -21,7 +21,6 @@ #include "support/filetools.h" #include "support/path_defines.h" -#include "support/globbing.h" using std::pair; using std::vector; diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index 918c219ff0..f37cdd4904 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,8 @@ +2004-11-25 Angus Leeming + + * FileDialog.C: + * FileDialog_private.C: s/globbing.h/filefilterlist.h/ in #includes. + 2004-11-22 Jürgen Spitzmüller * lengthvalidator.[Ch]: add GlueLength validator diff --git a/src/frontends/qt2/FileDialog.C b/src/frontends/qt2/FileDialog.C index 7af88fd208..90e92d8c87 100644 --- a/src/frontends/qt2/FileDialog.C +++ b/src/frontends/qt2/FileDialog.C @@ -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. diff --git a/src/frontends/qt2/FileDialog_private.C b/src/frontends/qt2/FileDialog_private.C index be328bbe14..bad9d561c0 100644 --- a/src/frontends/qt2/FileDialog_private.C +++ b/src/frontends/qt2/FileDialog_private.C @@ -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 diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 5a19d8a3e4..4a187c0dee 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,9 @@ +2004-11-25 Angus Leeming + + * 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 * Layoutengine.[Ch]: Break up circular dependency between Box and diff --git a/src/frontends/xforms/FileDialog.C b/src/frontends/xforms/FileDialog.C index 43ef10feb1..9402b5d728 100644 --- a/src/frontends/xforms/FileDialog.C +++ b/src/frontends/xforms/FileDialog.C @@ -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; diff --git a/src/frontends/xforms/FormBibtex.C b/src/frontends/xforms/FormBibtex.C index a517664ff4..3703e07f82 100644 --- a/src/frontends/xforms/FormBibtex.C +++ b/src/frontends/xforms/FormBibtex.C @@ -22,7 +22,6 @@ #include "xformsBC.h" #include "support/filetools.h" -#include "support/globbing.h" #include "support/lstrings.h" #include "support/lyxalgo.h" diff --git a/src/frontends/xforms/FormFiledialog.C b/src/frontends/xforms/FormFiledialog.C index df009195aa..e75b9f3e19 100644 --- a/src/frontends/xforms/FormFiledialog.C +++ b/src/frontends/xforms/FormFiledialog.C @@ -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" diff --git a/src/lyx_cb.C b/src/lyx_cb.C index 6988a430e7..6ed9e15399 100644 --- a/src/lyx_cb.C +++ b/src/lyx_cb.C @@ -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" diff --git a/src/lyxfunc.C b/src/lyxfunc.C index fb7343aab1..5596079293 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -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" diff --git a/src/support/ChangeLog b/src/support/ChangeLog index 52d1d79f78..5e5a357c05 100644 --- a/src/support/ChangeLog +++ b/src/support/ChangeLog @@ -1,3 +1,10 @@ +2004-11-25 Angus Leeming + + * filefilterlist.[Ch]: + * globbing.[Ch]: split FileFilterList into its own .[Ch] files. + + * Makefile.am: add filefilterlist.[Ch]. + 2004-11-16 Jean-Marc Lasgouttes * textutils.h (isKommaChar): remove diff --git a/src/support/Makefile.am b/src/support/Makefile.am index 8dd8cbc26a..8c2d922f63 100644 --- a/src/support/Makefile.am +++ b/src/support/Makefile.am @@ -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 \ diff --git a/src/support/filefilterlist.C b/src/support/filefilterlist.C new file mode 100644 index 0000000000..168a95eeb5 --- /dev/null +++ b/src/support/filefilterlist.C @@ -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 + +#include "support/filefilterlist.h" +#include "support/globbing.h" +#include "support/lstrings.h" + +// FIXME Interface violation +#include "gettext.h" + +#include + +#include + +#include + +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 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 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::const_iterator const begin = filters_.begin(); + vector::const_iterator const end = filters_.end(); + vector::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 diff --git a/src/support/filefilterlist.h b/src/support/filefilterlist.h new file mode 100644 index 0000000000..984d1398f8 --- /dev/null +++ b/src/support/filefilterlist.h @@ -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 +#include + +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 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 filters_; +}; + +} // namespace support +} // namespace lyx + +#endif // NOT FILE_FILTER_LIST_H diff --git a/src/support/globbing.C b/src/support/globbing.C index 190b38e5e4..8e663a0cc3 100644 --- a/src/support/globbing.C +++ b/src/support/globbing.C @@ -14,18 +14,12 @@ #include "support/lstrings.h" #include "support/path.h" -// FIXME Interface violation -#include "gettext.h" - #include #include #include -#include - using std::distance; -using std::ostringstream; using std::string; using std::vector; @@ -111,77 +105,5 @@ vector 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 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 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::const_iterator const begin = filters_.begin(); - vector::const_iterator const end = filters_.end(); - vector::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 diff --git a/src/support/globbing.h b/src/support/globbing.h index a5f7b04e58..0ee1141512 100644 --- a/src/support/globbing.h +++ b/src/support/globbing.h @@ -48,42 +48,6 @@ std::vector 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 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 filters_; -}; - } // namespace support } // namespace lyx -- 2.39.2