]> git.lyx.org Git - features.git/commitdiff
Introducing FileNameList, cleanup some headers and put back dirList() into FileName.
authorAbdelrazak Younes <younes@lyx.org>
Wed, 5 Dec 2007 10:32:49 +0000 (10:32 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Wed, 5 Dec 2007 10:32:49 +0000 (10:32 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21965 a592a061-630c-0410-9148-cb99ea01b6c8

13 files changed:
src/Buffer.cpp
src/Buffer.h
src/Converter.cpp
src/insets/InsetBibtex.cpp
src/insets/InsetBibtex.h
src/insets/InsetCitation.cpp
src/insets/InsetInclude.cpp
src/insets/InsetInclude.h
src/support/FileName.cpp
src/support/FileName.h
src/support/FileNameList.h [new file with mode: 0644]
src/support/FileZipListDir.h
src/support/filetools.cpp

index 71b58902ee672598a11eb63afb18aa71cb24487b..0b2c71b1cc86111e305c21950318032de4ea180a 100644 (file)
@@ -79,6 +79,7 @@
 #include "support/convert.h"
 #include "support/debug.h"
 #include "support/FileFilterList.h"
+#include "support/FileNameList.h"
 #include "support/filetools.h"
 #include "support/ForkedCalls.h"
 #include "support/gettext.h"
@@ -129,6 +130,7 @@ using support::changeExtension;
 using support::cmd_ret;
 using support::createBufferTmpDir;
 using support::FileName;
+using support::FileNameList;
 using support::libFileSearch;
 using support::latex_path;
 using support::ltrim;
@@ -229,6 +231,10 @@ public:
 
        ///
        Undo undo_;
+
+       /// A cache for the bibfiles (including bibfiles of loaded child
+       /// documents), needed for appropriate update of natbib labels.
+       mutable FileNameList bibfilesCache_;
 };
 
 
@@ -1450,22 +1456,22 @@ void Buffer::updateBibfilesCache() const
                return;
        }
 
-       bibfilesCache_.clear();
+       d->bibfilesCache_.clear();
        for (InsetIterator it = inset_iterator_begin(inset()); it; ++it) {
                if (it->lyxCode() == BIBTEX_CODE) {
                        InsetBibtex const & inset =
                                static_cast<InsetBibtex const &>(*it);
-                       vector<FileName> const bibfiles = inset.getFiles(*this);
-                       bibfilesCache_.insert(bibfilesCache_.end(),
+                       FileNameList const bibfiles = inset.getFiles(*this);
+                       d->bibfilesCache_.insert(d->bibfilesCache_.end(),
                                bibfiles.begin(),
                                bibfiles.end());
                } else if (it->lyxCode() == INCLUDE_CODE) {
                        InsetInclude & inset =
                                static_cast<InsetInclude &>(*it);
                        inset.updateBibfilesCache(*this);
-                       vector<FileName> const & bibfiles =
+                       FileNameList const & bibfiles =
                                        inset.getBibfilesCache(*this);
-                       bibfilesCache_.insert(bibfilesCache_.end(),
+                       d->bibfilesCache_.insert(d->bibfilesCache_.end(),
                                bibfiles.begin(),
                                bibfiles.end());
                }
@@ -1473,7 +1479,7 @@ void Buffer::updateBibfilesCache() const
 }
 
 
-vector<FileName> const & Buffer::getBibfilesCache() const
+FileNameList const & Buffer::getBibfilesCache() const
 {
        // if this is a child document and the parent is already loaded
        // use the parent's cache instead
@@ -1483,10 +1489,10 @@ vector<FileName> const & Buffer::getBibfilesCache() const
                return tmp->getBibfilesCache();
 
        // We update the cache when first used instead of at loading time.
-       if (bibfilesCache_.empty())
+       if (d->bibfilesCache_.empty())
                const_cast<Buffer *>(this)->updateBibfilesCache();
 
-       return bibfilesCache_;
+       return d->bibfilesCache_;
 }
 
 
index 944530d338c76196197488f4a48e82df85723b80..5e61cb1116b572b46ea952422e7d46a312ad8ba7 100644 (file)
@@ -14,7 +14,6 @@
 
 #include "insets/InsetCode.h"
 
-#include "support/FileName.h"
 #include "support/strfwd.h"
 #include "support/types.h"
 
@@ -54,6 +53,11 @@ class GuiBufferDelegate;
 class WorkAreaManager;
 }
 
+namespace support {
+class FileName;
+class FileNameList;
+}
+
 /** The buffer object.
  * This is the buffer object. It contains all the informations about
  * a document loaded into LyX.
@@ -298,7 +302,7 @@ public:
        void updateBibfilesCache() const;
        /// Return the cache with all bibfiles in use (including bibfiles
        /// of loaded child documents).
-       std::vector<support::FileName> const & getBibfilesCache() const;
+       support::FileNameList const & getBibfilesCache() const;
        ///
        void getLabelList(std::vector<docstring> &) const;
 
@@ -453,10 +457,6 @@ private:
        /// The pointer never changes although *pimpl_'s contents may.
        Impl * const d;
 
-       /// A cache for the bibfiles (including bibfiles of loaded child
-       /// documents), needed for appropriate update of natbib labels.
-       mutable std::vector<support::FileName> bibfilesCache_;
-
        frontend::GuiBufferDelegate * gui_;
 };
 
index e6f67460feabad06070e499345cef7e7ba95fd5f..136227b219811b50e6f807f263aadd44fc528996 100644 (file)
@@ -25,7 +25,9 @@
 #include "frontends/alert.h"
 
 #include "support/debug.h"
+#include "support/FileNameList.h"
 #include "support/filetools.h"
+#include "support/FileZipListDir.h"
 #include "support/gettext.h"
 #include "support/lstrings.h"
 #include "support/lyxlib.h"
@@ -33,7 +35,6 @@
 #include "support/Package.h"
 #include "support/Path.h"
 #include "support/Systemcall.h"
-#include "support/FileZipListDir.h"
 
 using std::find_if;
 using std::string;
@@ -49,6 +50,7 @@ using support::changeExtension;
 using support::compare_ascii_no_case;
 using support::contains;
 using support::FileName;
+using support::FileNameList;
 using support::getExtension;
 using support::libFileSearch;
 using support::libScriptSearch;
@@ -511,8 +513,6 @@ bool Converters::convert(Buffer const * buffer,
 bool Converters::move(string const & fmt,
                      FileName const & from, FileName const & to, bool copy)
 {
-       if (from == to)
-               return true;
 
        bool no_errors = true;
        string const path = onlyPath(from.absFilename());
@@ -520,9 +520,10 @@ bool Converters::move(string const & fmt,
        string const to_base = removeExtension(to.absFilename());
        string const to_extension = getExtension(to.absFilename());
 
-       vector<FileName> const files =
-                       support::dirList(FileName(path), getExtension(from.absFilename()));
-       for (vector<FileName>::const_iterator it = files.begin();
+       FileNameList const files = FileName(path).dirList(getExtension(from.absFilename()));
+       if (from == to)
+               return true;
+       for (FileNameList::const_iterator it = files.begin();
             it != files.end(); ++it) {
                string const from2 = it->absFilename();
                string const file2 = onlyFilename(from2);
index 63f870576c3c78fae42dc13b3aec83f64add6c6f..3f92e03234bcb21b8af2e7e7d0251fd67bd30ff5 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "support/ExceptionMessage.h"
 #include "support/docstream.h"
+#include "support/FileNameList.h"
 #include "support/filetools.h"
 #include "support/lstrings.h"
 #include "support/lyxlib.h"
@@ -48,6 +49,7 @@ using support::contains;
 using support::copy;
 using support::DocFileName;
 using support::FileName;
+using support::FileNameList;
 using support::findtexfile;
 using support::isValidLaTeXFilename;
 using support::latex_path;
@@ -333,12 +335,12 @@ int InsetBibtex::latex(Buffer const & buffer, odocstream & os,
 }
 
 
-vector<FileName> const InsetBibtex::getFiles(Buffer const & buffer) const
+FileNameList const InsetBibtex::getFiles(Buffer const & buffer) const
 {
        FileName path(buffer.filePath());
        support::PathChanger p(path);
 
-       vector<FileName> vec;
+       FileNameList vec;
 
        string tmp;
        // FIXME UNICODE
@@ -601,7 +603,7 @@ namespace {
 void InsetBibtex::fillWithBibKeys(Buffer const & buffer,
                BiblioInfo & keylist, InsetIterator const & /*di*/) const
 {
-       vector<FileName> const files = getFiles(buffer);
+       FileNameList const files = getFiles(buffer);
        for (vector<FileName>::const_iterator it = files.begin();
             it != files.end(); ++ it) {
                // This bibtex parser is a first step to parse bibtex files
index 2b8e8dea6ac74104dc3bececf7dd55957bc1e5bd..25ce300c9b2854a2d7614b8a8fbc15c5df528702 100644 (file)
 #include "InsetCommand.h"
 #include "BiblioInfo.h"
 
-#include "support/FileName.h"
+namespace lyx {
 
+namespace support {
+class FileNameList;
+}
 
-namespace lyx {
 
 /** Used to insert BibTeX's information
   */
@@ -41,7 +43,7 @@ public:
        virtual void fillWithBibKeys(Buffer const &,
                BiblioInfo &, InsetIterator const &) const;
        ///
-       std::vector<support::FileName> const getFiles(Buffer const &) const;
+       support::FileNameList const getFiles(Buffer const &) const;
        ///
        bool addDatabase(std::string const &);
        ///
index 43920a695c09f6d5330568ab1091786c3c103696..5d5bbdacd278dea08ed56f78fdd93981a2c357c8 100644 (file)
 
 #include "support/lstrings.h"
 #include "support/docstream.h"
+#include "support/FileNameList.h"
 
 #include <algorithm>
 
+using std::string;
+using std::vector;
 
 namespace lyx {
 
 using support::FileName;
+using support::FileNameList;
 using support::getStringFromVector;
 using support::getVectorFromString;
 using support::ltrim;
@@ -37,9 +41,6 @@ using support::rtrim;
 using support::split;
 using support::tokenPos;
 
-using std::string;
-using std::vector;
-
 namespace {
 
 vector<string> const init_possible_cite_commands()
@@ -152,10 +153,10 @@ docstring const getNatbibLabel(Buffer const & buffer,
 
        BiblioInfo biblist;
 
-       vector<FileName> const & bibfilesCache = buffer.getBibfilesCache();
+       FileNameList const & bibfilesCache = buffer.getBibfilesCache();
        // compare the cached timestamps with the actual ones.
        bool changed = false;
-       for (vector<FileName>::const_iterator it = bibfilesCache.begin();
+       for (FileNameList::const_iterator it = bibfilesCache.begin();
                        it != bibfilesCache.end(); ++ it) {
                FileName const f = *it;
                std::time_t lastw = f.lastModified();
index ba1207c283177e2a2b723e834223b0782d6804d8..e8d91dfced42359f0810e2bf557a56767322d3ef 100644 (file)
@@ -44,6 +44,7 @@
 #include "insets/InsetListingsParams.h"
 
 #include "support/docstream.h"
+#include "support/FileNameList.h"
 #include "support/filetools.h"
 #include "support/lstrings.h" // contains
 #include "support/lyxalgo.h"
@@ -63,6 +64,7 @@ using support::contains;
 using support::copy;
 using support::DocFileName;
 using support::FileName;
+using support::FileNameList;
 using support::getVectorFromString;
 using support::isLyXFilename;
 using support::isValidLaTeXFilename;
@@ -726,17 +728,17 @@ void InsetInclude::updateBibfilesCache(Buffer const & buffer)
 }
 
 
-std::vector<FileName> const &
+FileNameList const &
 InsetInclude::getBibfilesCache(Buffer const & buffer) const
 {
        Buffer * const tmp = getChildBuffer(buffer, params());
        if (tmp) {
                tmp->setParent(0);
-               std::vector<FileName> const & cache = tmp->getBibfilesCache();
+               FileNameList const & cache = tmp->getBibfilesCache();
                tmp->setParent(&buffer);
                return cache;
        }
-       static std::vector<FileName> const empty;
+       static FileNameList const empty;
        return empty;
 }
 
index 50e95babc7722a18969567b4d6801fdc869e19f0..f495d1d9ed8eb612c07754a253e3fae9c58c54e4 100644 (file)
@@ -21,8 +21,6 @@
 #include "Counters.h"
 #include "EmbeddedFiles.h"
 
-#include "support/FileName.h"
-
 #include <boost/scoped_ptr.hpp>
 
 namespace lyx {
@@ -32,6 +30,9 @@ class Dimension;
 class LaTeXFeatures;
 class RenderMonitoredPreview;
 
+namespace support {
+class FileNameList;
+}
 
 /// for including tex/lyx files
 class InsetInclude : public InsetCommand {
@@ -73,7 +74,7 @@ public:
         *  Return an empty vector if the child doc is not loaded.
         *  \param buffer the Buffer containing this inset.
         */
-       std::vector<support::FileName> const &
+       support::FileNameList const &
                getBibfilesCache(Buffer const & buffer) const;
        ///
        EDITABLE editable() const { return IS_EDITABLE; }
index cc476eecc841faaccb7ec814f85e0ce77605f3f0..2c8fa57b1e0fec6e986449ce3ddfc11d16d55b0f 100644 (file)
@@ -11,6 +11,7 @@
 #include <config.h>
 
 #include "support/FileName.h"
+#include "support/FileNameList.h"
 
 #include "support/debug.h"
 #include "support/filetools.h"
@@ -230,6 +231,39 @@ bool FileName::isDirWritable() const
 }
 
 
+FileNameList FileName::dirList(std::string const & ext) const
+{
+       FileNameList dirlist;
+       if (!isDirectory()) {
+               LYXERR0("Directory '" << *this << "' does not exist!");
+               return dirlist;
+       }
+
+       QDir dir = d->fi.absoluteDir();
+
+       if (!ext.empty()) {
+               QString filter;
+               switch (ext[0]) {
+               case '.': filter = "*" + toqstr(ext); break;
+               case '*': filter = toqstr(ext); break;
+               default: filter = "*." + toqstr(ext);
+               }
+               dir.setNameFilters(QStringList(filter));
+               LYXERR(Debug::FILES, "filtering on extension "
+                       << fromqstr(filter) << " is requested.");
+       }
+
+       QFileInfoList list = dir.entryInfoList();
+       for (int i = 0; i != list.size(); ++i) {
+               FileName fi(fromqstr(list.at(i).absoluteFilePath()));
+               dirlist.push_back(fi);
+               LYXERR(Debug::FILES, "found file " << fi);
+       }
+
+       return dirlist;
+}
+
+
 FileName FileName::tempName(FileName const & dir, std::string const & mask)
 {
        return support::tempName(dir, mask);
index be47e158f76a6364736f8731867b9361068c13bc..c293f66021fada455cd4ad35df7cabf2aba3d827 100644 (file)
@@ -20,6 +20,9 @@
 namespace lyx {
 namespace support {
 
+/// Defined in "FileNameList.h".
+class FileNameList;
+
 /**
  * Class for storing file names.
  * The file name may be empty. If it is not empty it is an absolute path.
@@ -82,6 +85,8 @@ public:
        bool isWritable() const;
        /// return true when file/directory is writable (write test file)
        bool isDirWritable() const;
+       /// \return list other files in the directory having optional extension 'ext'.
+       FileNameList dirList(std::string const & ext) const;
        
        /// copy a file
        /// \return true when file/directory is writable (write test file)
@@ -226,7 +231,6 @@ private:
 bool operator==(DocFileName const &, DocFileName const &);
 bool operator!=(DocFileName const &, DocFileName const &);
 
-
 } // namespace support
 } // namespace lyx
 
diff --git a/src/support/FileNameList.h b/src/support/FileNameList.h
new file mode 100644 (file)
index 0000000..20b6a85
--- /dev/null
@@ -0,0 +1,34 @@
+// -*- C++ -*-
+/**
+ * \file FileNameList.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef FILENAMELIST_H
+#define FILENAMELIST_H
+
+#include "support/FileName.h"
+
+#include <vector>
+
+namespace lyx {
+namespace support {
+
+/**
+ * Class for storing file name list.
+ * std::vector can not be forward declared in a simple way. Creating a class solves
+ * this problem.
+ */
+class FileNameList: public std::vector<FileName>
+{
+};
+
+} // namespace support
+} // namespace lyx
+
+#endif // FILENAMELIST_H
index d49e0500ce3d4417cea404e880be2041ce675e25..8dd051fcdd2650139c8a248d8dd4bddc2ca4aeb2 100644 (file)
 #include <utility>
 #include <string>
 
-namespace lyx {
-namespace support {
-
-/// \return list other files in the directory having optional extension 'ext'.
-std::vector<FileName> dirList(FileName const & filename, std::string const & ext);
-
-
-} // namespace support
-} // namespace lyx
-
 /// The following functions are implemented in minizip/zipunzip.cpp, and are not in
 /// the lyx::support namespace
 
index 13d018932fb67983769852bfcc7d894987f7dbfb..cc77812708580b7ddc40427df9fa3e73da35bbd4 100644 (file)
@@ -938,38 +938,5 @@ int compare_timestamps(FileName const & file1, FileName const & file2)
 }
 
 
-std::vector<FileName> dirList(FileName const & filename, std::string const & ext)
-{
-       std::vector<FileName> dirlist;
-       if (!filename.isDirectory()) {
-               LYXERR0("Directory '" << filename << "' does not exist!");
-               return dirlist;
-       }
-
-       QDir dir(toqstr(filename.absoluteFilePath()));
-
-       if (!ext.empty()) {
-               QString filter;
-               switch (ext[0]) {
-               case '.': filter = "*" + toqstr(ext); break;
-               case '*': filter = toqstr(ext); break;
-               default: filter = "*." + toqstr(ext);
-               }
-               dir.setNameFilters(QStringList(filter));
-               LYXERR(Debug::FILES, "filtering on extension "
-                       << fromqstr(filter) << " is requested.");
-       }
-
-       QFileInfoList list = dir.entryInfoList();
-       for (int i = 0; i != list.size(); ++i) {
-               FileName fi(fromqstr(list.at(i).absoluteFilePath()));
-               dirlist.push_back(fi);
-               LYXERR(Debug::FILES, "found file " << fi);
-       }
-
-       return dirlist;
-}
-
-
 } //namespace support
 } // namespace lyx