]> git.lyx.org Git - features.git/commitdiff
move the filefilter stuff closer to the only place where it is used
authorAndré Pönitz <poenitz@gmx.net>
Sun, 20 Apr 2008 19:56:01 +0000 (19:56 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Sun, 20 Apr 2008 19:56:01 +0000 (19:56 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@24395 a592a061-630c-0410-9148-cb99ea01b6c8

20 files changed:
src/frontends/qt4/FileDialog.cpp
src/frontends/qt4/FileDialog.h
src/frontends/qt4/GuiBibtex.cpp
src/frontends/qt4/GuiClipboard.cpp
src/frontends/qt4/GuiDocument.cpp
src/frontends/qt4/GuiExternal.cpp
src/frontends/qt4/GuiGraphics.cpp
src/frontends/qt4/GuiInclude.cpp
src/frontends/qt4/GuiPrefs.cpp
src/frontends/qt4/GuiPrefs.h
src/frontends/qt4/GuiPrint.cpp
src/frontends/qt4/GuiView.cpp
src/frontends/qt4/LyXFileDialog.cpp
src/frontends/qt4/LyXFileDialog.h
src/frontends/qt4/qt_helpers.cpp
src/frontends/qt4/qt_helpers.h
src/frontends/qt4/qt_i18n.h [new file with mode: 0644]
src/support/FileFilterList.cpp [deleted file]
src/support/FileFilterList.h [deleted file]
src/support/Makefile.am

index c6e8b85c8da0a8cc57a413b2b04ccf133e4a032f..a3af75db1a42fde61d1b7020eb008e4828ff5f30 100644 (file)
@@ -17,7 +17,6 @@
 #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;
 
 
@@ -83,25 +78,19 @@ void FileDialog::setButton2(QString const & label, QString const & dir)
 
 
 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);
@@ -126,21 +115,19 @@ FileDialog::Result FileDialog::save(QString const & path,
 
 
 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);
 
@@ -159,7 +146,7 @@ FileDialog::Result FileDialog::open(QString const & path,
 
 
 FileDialog::Result FileDialog::opendir(QString const & path,
-                                           QString const & suggested)
+       QString const & suggested)
 {
        LYXERR(Debug::GUI, "Select with path \"" << fromqstr(path)
                           << "\", suggested \"" << fromqstr(suggested) << '"');
@@ -167,15 +154,13 @@ FileDialog::Result FileDialog::opendir(QString const & path,
        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);
 
index 9dbd54e578d02de50fd30ec1b94c42db41b1c51b..f5da6eb73e0e4506bfedd4fb5016f381a580275b 100644 (file)
@@ -21,9 +21,6 @@
 
 namespace lyx {
 
-namespace support { class FileFilterList; }
-
-
 /**
  * \class FileDialog
  * \brief GUI-I definition of file dialog interface
@@ -62,8 +59,7 @@ public:
        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.
@@ -71,8 +67,7 @@ public:
                             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:
index a1c97cd6edb37e2ba17b63decfa0e49a3ebb918d..28286367b4e25602d117f72c3cf96891b5e15243 100644 (file)
@@ -32,7 +32,6 @@
 
 #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"
@@ -424,7 +423,7 @@ QString GuiBibtex::browseBib(QString const & in_name) const
 {
        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);
 }
@@ -434,7 +433,7 @@ QString GuiBibtex::browseBst(QString const & in_name) const
 {
        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);
 }
index ad032181e2337e457bf876669ff4c2045410cf19..3c7798870e4434bf8a9aea077c5ca2a1f0abdc2b 100644 (file)
@@ -25,7 +25,6 @@
 #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
@@ -347,16 +346,16 @@ FileName GuiClipboard::getPastedGraphicsFileName(Cursor const & cur,
        
        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"));
index bc4864fce3185513e5efe6dace3ab231284787d2..4eedfbabefa335262e8f21bebefc3dbbd17f9e03 100644 (file)
@@ -43,7 +43,6 @@
 
 #include "support/debug.h"
 #include "support/FileName.h"
-#include "support/FileFilterList.h"
 #include "support/filetools.h"
 #include "support/lstrings.h"
 
@@ -1223,7 +1222,7 @@ void GuiDocument::browseLayout()
 {
        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);
index 2fe1ce848abe26dbd71a81587f4a6f7e824e47a3..6a77567b2bc3157daa6ce8524848d13d4156886a 100644 (file)
@@ -28,7 +28,6 @@
 #include "graphics/GraphicsImage.h"
 
 #include "support/convert.h"
-#include "support/FileFilterList.h"
 #include "support/filetools.h"
 #include "support/lstrings.h"
 #include "support/lyxlib.h"
@@ -707,14 +706,15 @@ void GuiExternal::editExternal()
 }
 
 
-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());
 }
 
 
@@ -723,8 +723,7 @@ QString GuiExternal::browse(QString const & input,
 {
        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);
index aaa8bc5c79af69f9d00cc8ecdec70ce08c07f647..1eff038b7d9c73ef76846dac5750996f6ef6cd1c 100644 (file)
@@ -32,7 +32,6 @@
 
 #include "support/convert.h"
 #include "support/debug.h"
-#include "support/FileFilterList.h"
 #include "support/filetools.h"
 #include "support/gettext.h"
 #include "support/lstrings.h"
@@ -751,7 +750,7 @@ QString GuiGraphics::browse(QString const & in_name) const
                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));
 }
index 7caf50fb188c850f262995896abc80b60ffd1cdf..5633059109d4354176b5a3a54939889bb3f77e44 100644 (file)
 #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"
 
@@ -309,11 +308,11 @@ QString GuiInclude::browse(QString const & in_name, Type in_type) const
        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:
index 1b781fb45a7fbe8251b0a6bb12d7a3a6d446f751..3e0a3db0429f9267b3b06f501f9354ad633dbe07 100644 (file)
@@ -32,7 +32,6 @@
 #include "Session.h"
 
 #include "support/debug.h"
-#include "support/FileFilterList.h"
 #include "support/FileName.h"
 #include "support/filetools.h"
 #include "support/foreach.h"
@@ -86,7 +85,7 @@ namespace frontend {
 */
 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(),
@@ -121,7 +120,7 @@ QString browseLibFile(QString const & dir,
        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");
@@ -182,7 +181,7 @@ QString browseDir(QString const & pathname,
 } // 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)
 {
@@ -988,7 +987,7 @@ void PrefPaths::update(LyXRC const & rc)
 
 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);
@@ -997,7 +996,7 @@ void PrefPaths::select_exampledir()
 
 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);
@@ -1006,7 +1005,7 @@ void PrefPaths::select_templatedir()
 
 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);
@@ -1015,7 +1014,7 @@ void PrefPaths::select_tempdir()
 
 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);
@@ -1024,7 +1023,7 @@ void PrefPaths::select_backupdir()
 
 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);
@@ -2549,42 +2548,35 @@ void GuiPreferences::updateScreenFonts()
 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);
 }
 
 
index afca6d4b421dc596a3e819086f7b9839464b46c2..36a2b2e15ef3dd632fec9b3ceb6712876198f17d 100644 (file)
@@ -490,9 +490,6 @@ public:
        /// 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);
 
index 20003e48ac5376f816bc34fc716369cd5d16c9fb..af74910ff14bfdffb6c30eb5280b9e58e3ca9f93 100644 (file)
@@ -23,7 +23,6 @@
 #include "LyXRC.h"
 
 #include "support/convert.h"
-#include "support/FileFilterList.h"
 #include "support/filetools.h"
 #include "support/gettext.h"
 #include "support/os.h"
@@ -87,7 +86,7 @@ void GuiPrint::browseClicked()
 {
        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();
index ffb301e4889dfccefde885f69c3454042a4d2059..bf3a906a824a47b0bad0148e9bee8a058e2a4185 100644 (file)
@@ -55,7 +55,6 @@
 
 #include "support/assert.h"
 #include "support/debug.h"
-#include "support/FileFilterList.h"
 #include "support/FileName.h"
 #include "support/filetools.h"
 #include "support/gettext.h"
@@ -1117,9 +1116,8 @@ static FileName selectTemplateFile()
        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();
@@ -1178,7 +1176,7 @@ void GuiView::openDocument(string const & fname)
                                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;
@@ -1317,7 +1315,7 @@ void GuiView::importDocument(string const & argument)
                filter += ')';
 
                FileDialog::Result result =
-                       dlg.open(toqstr(initpath), FileFilterList(filter));
+                       dlg.open(toqstr(initpath), fileFilters(toqstr(filter)));
 
                if (result.first == FileDialog::Later)
                        return;
@@ -1430,9 +1428,8 @@ void GuiView::insertLyXFile(docstring const & fname)
                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;
@@ -1470,7 +1467,7 @@ void GuiView::insertPlaintextFile(docstring const & fname,
                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;
@@ -1511,11 +1508,9 @@ bool GuiView::renameBuffer(Buffer & b, docstring const & newname)
                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)
index e0f94e7386c638e4fe4b2a8e66ae0712b6c335d4..0df10992e241e29fc6ab24d4653d1a30195f3d54 100644 (file)
@@ -14,7 +14,6 @@
 
 #include "qt_helpers.h"
 
-#include "support/FileFilterList.h"
 #include "support/lstrings.h"
 
 #include <QApplication>
@@ -44,12 +43,13 @@ static QString getLabel(QString const & qstr)
 
 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.
index 2419b2cad2048efea9c65385754e877dc0959da3..60d7fd2d6d748b02788eedaee04e43ff0bd523d4 100644 (file)
@@ -20,8 +20,6 @@ class QToolButton;
 
 namespace lyx {
 
-namespace support { class FileFilterList; }
-
 class LyXFileDialog : public QFileDialog
 {
        Q_OBJECT
@@ -29,7 +27,7 @@ class LyXFileDialog : public QFileDialog
 public:
        LyXFileDialog(QString const & title,
                      QString const & path,
-                     support::FileFilterList const & filters,
+                     QStringList const & filters,
                      FileDialog::Button const & b1,
                      FileDialog::Button const & b2);
 
index 5cb11cbea53001da275bd0a9ee704090180dab24..89ce0d57171375b57842b759e30cc23a815a1cdc 100644 (file)
 #include <fstream>
 #include <locale>
 
+// for FileFilter.
+// FIXME: Remove
+#include <boost/regex.hpp>
+#include <boost/tokenizer.hpp>
+
+
 using namespace std;
 using namespace lyx::support;
 
@@ -303,4 +309,228 @@ QString getExtension(QString const & name)
        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
index a088c00efec5f7315b6cecada3d31a9184b26ad1..6e5a2c6cb8f3e4d82258da599375b32c6983af51 100644 (file)
@@ -29,7 +29,6 @@ class LengthCombo;
 
 namespace lyx {
 
-namespace support { class FileFilterList; }
 namespace support { class FileName; }
 
 namespace frontend {
@@ -83,7 +82,7 @@ support::FileName libFileSearch(QString const & dir, QString const & name,
 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(),
@@ -105,6 +104,7 @@ QStringList texFileList(QString const & filename);
 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);
 
diff --git a/src/frontends/qt4/qt_i18n.h b/src/frontends/qt4/qt_i18n.h
new file mode 100644 (file)
index 0000000..29b966e
--- /dev/null
@@ -0,0 +1,30 @@
+// -*- 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
diff --git a/src/support/FileFilterList.cpp b/src/support/FileFilterList.cpp
deleted file mode 100644 (file)
index c35eadf..0000000
+++ /dev/null
@@ -1,186 +0,0 @@
-/**
- * \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
diff --git a/src/support/FileFilterList.h b/src/support/FileFilterList.h
deleted file mode 100644 (file)
index 4497630..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-// -*- 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
index 86c5f4d7f2909a8ca728a2b6c2c3c5f3adfb26b6..0408a08a6cd28dade09123e7d5331b62de2f0c8b 100644 (file)
@@ -55,8 +55,6 @@ liblyxsupport_la_SOURCES = \
        environment.h \
        environment.cpp \
        ExceptionMessage.h \
-       FileFilterList.cpp \
-       FileFilterList.h \
        FileName.cpp \
        FileName.h \
        FileNameList.h \