mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 05:16:21 +00:00
move funtion with std::vector to filetools
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21903 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
6d24433cc5
commit
aef7e129e7
@ -519,7 +519,8 @@ bool Converters::move(string const & fmt,
|
||||
string const to_base = removeExtension(to.absFilename());
|
||||
string const to_extension = getExtension(to.absFilename());
|
||||
|
||||
vector<FileName> const files = FileName(path).dirList(getExtension(from.absFilename()));
|
||||
vector<FileName> const files =
|
||||
support::dirList(FileName(path), getExtension(from.absFilename()));
|
||||
for (vector<FileName>::const_iterator it = files.begin();
|
||||
it != files.end(); ++it) {
|
||||
string const from2 = it->absFilename();
|
||||
|
@ -326,37 +326,9 @@ bool FileName::createDirectory(int permission) const
|
||||
}
|
||||
|
||||
|
||||
std::vector<FileName> FileName::dirList(std::string const & ext)
|
||||
docstring const FileName::absoluteFilePath() const
|
||||
{
|
||||
std::vector<FileName> dirlist;
|
||||
if (!isDirectory()) {
|
||||
LYXERR0("Directory '" << *this << "' does not exist!");
|
||||
return dirlist;
|
||||
}
|
||||
|
||||
QDir dir(d->fi.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;
|
||||
fi.d->fi = list.at(i);
|
||||
dirlist.push_back(fi);
|
||||
LYXERR(Debug::FILES, "found file " << fi);
|
||||
}
|
||||
|
||||
return dirlist;
|
||||
return qstring_to_ucs4(d->fi.absoluteFilePath());
|
||||
}
|
||||
|
||||
|
||||
@ -588,7 +560,7 @@ bool FileName::isZippedFile() const
|
||||
docstring const FileName::relPath(string const & path) const
|
||||
{
|
||||
// FIXME UNICODE
|
||||
return makeRelPath(qstring_to_ucs4(d->fi.absoluteFilePath()), from_utf8(path));
|
||||
return makeRelPath(absoluteFilePath(), from_utf8(path));
|
||||
}
|
||||
|
||||
|
||||
|
@ -15,7 +15,6 @@
|
||||
#include "support/strfwd.h"
|
||||
|
||||
#include <ctime>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace lyx {
|
||||
@ -139,12 +138,11 @@ public:
|
||||
|
||||
/// change to a directory, return success
|
||||
bool chdir() const;
|
||||
|
||||
/// \return list other files in the directory having optional extension 'ext'.
|
||||
std::vector<FileName> dirList(std::string const & ext = empty_string());
|
||||
|
||||
/// \param buffer_path if empty, uses `pwd`
|
||||
docstring const relPath(std::string const & path) const;
|
||||
|
||||
docstring const absoluteFilePath() const;
|
||||
|
||||
private:
|
||||
///
|
||||
|
@ -934,5 +934,39 @@ int compare_timestamps(FileName const & file1, FileName const & file2)
|
||||
return cmp;
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
|
@ -275,6 +275,9 @@ typedef std::pair<int, std::string> cmd_ret;
|
||||
|
||||
cmd_ret const runCommand(std::string const & cmd);
|
||||
|
||||
/// \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
|
||||
|
Loading…
Reference in New Issue
Block a user