mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-08 18:19:42 +00:00
GuiLyXFiles: minor generalization
This commit is contained in:
parent
9f403b5173
commit
e141781aad
@ -39,9 +39,8 @@ using namespace lyx::support;
|
||||
namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
namespace {
|
||||
|
||||
void getFiles(QMap<QString, QString> & in, QString const type)
|
||||
void GuiLyXFiles::getFiles(QMap<QString, QString> & in, QString const type)
|
||||
{
|
||||
// We look for lyx files in the subdirectory dir of
|
||||
// 1) user_lyxdir
|
||||
@ -112,7 +111,7 @@ void getFiles(QMap<QString, QString> & in, QString const type)
|
||||
QDirIterator it(dir, QDir::Files, QDirIterator::Subdirectories);
|
||||
while (it.hasNext()) {
|
||||
QString fn(QFile(it.next()).fileName());
|
||||
if (!fn.endsWith(".lyx"))
|
||||
if (!fn.endsWith(getSuffix()))
|
||||
continue;
|
||||
QString const relpath = toqstr(makeRelPath(qstring_to_ucs4(fn),
|
||||
qstring_to_ucs4(dir)));
|
||||
@ -140,8 +139,6 @@ void getFiles(QMap<QString, QString> & in, QString const type)
|
||||
}
|
||||
}
|
||||
|
||||
}// namespace anon
|
||||
|
||||
|
||||
GuiLyXFiles::GuiLyXFiles(GuiView & lv)
|
||||
: GuiDialog(lv, "lyxfiles", qt_("New File From Template"))
|
||||
@ -193,6 +190,15 @@ GuiLyXFiles::GuiLyXFiles(GuiView & lv)
|
||||
}
|
||||
|
||||
|
||||
QString const GuiLyXFiles::getSuffix()
|
||||
{
|
||||
if (type_ == "bind" || type_ == "ui")
|
||||
return toqstr(".") + type_;
|
||||
|
||||
return ".lyx";
|
||||
}
|
||||
|
||||
|
||||
void GuiLyXFiles::changed_adaptor()
|
||||
{
|
||||
changed();
|
||||
@ -273,7 +279,7 @@ void GuiLyXFiles::updateContents()
|
||||
QString const filename = info.fileName();
|
||||
QString const guiname =
|
||||
toqstr(translateIfPossible(
|
||||
qstring_to_ucs4(filename.left(filename.lastIndexOf(".lyx")).replace('_', ' '))));
|
||||
qstring_to_ucs4(filename.left(filename.lastIndexOf(getSuffix())).replace('_', ' '))));
|
||||
item->setIcon(0, iconprovider.icon(info));
|
||||
item->setData(0, Qt::UserRole, info.filePath());
|
||||
item->setData(0, Qt::DisplayRole, guiname);
|
||||
@ -390,12 +396,18 @@ void GuiLyXFiles::dispatchParams()
|
||||
if (type_ == "templates")
|
||||
arg = "newfile ";
|
||||
arg += fromqstr(file_);
|
||||
FuncCode const lfun = (type_ == toqstr("examples")) ?
|
||||
LFUN_FILE_OPEN : getLfun();
|
||||
FuncCode const lfun = getLfun();
|
||||
|
||||
dispatch(FuncRequest(lfun, arg));
|
||||
}
|
||||
|
||||
FuncCode GuiLyXFiles::getLfun() const
|
||||
{
|
||||
if (type_ == toqstr("examples"))
|
||||
return LFUN_FILE_OPEN;
|
||||
return LFUN_BUFFER_NEW_TEMPLATE;
|
||||
}
|
||||
|
||||
Dialog * createGuiLyXFiles(GuiView & lv) { return new GuiLyXFiles(lv); }
|
||||
|
||||
|
||||
|
@ -59,7 +59,11 @@ private:
|
||||
///
|
||||
bool isBufferDependent() const { return false; }
|
||||
///
|
||||
FuncCode getLfun() const { return LFUN_BUFFER_NEW_TEMPLATE; }
|
||||
FuncCode getLfun() const;
|
||||
///
|
||||
QString const getSuffix();
|
||||
///
|
||||
void getFiles(QMap<QString, QString> &, QString const);
|
||||
|
||||
private:
|
||||
/// contains the search box
|
||||
|
Loading…
Reference in New Issue
Block a user