From e141781aad0bbe12a75c50c0113e07a1b4d5f842 Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Tue, 19 Mar 2019 13:29:32 +0100 Subject: [PATCH] GuiLyXFiles: minor generalization --- src/frontends/qt4/GuiLyXFiles.cpp | 28 ++++++++++++++++++++-------- src/frontends/qt4/GuiLyXFiles.h | 6 +++++- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/frontends/qt4/GuiLyXFiles.cpp b/src/frontends/qt4/GuiLyXFiles.cpp index 0e43706bf5..35d86d222c 100644 --- a/src/frontends/qt4/GuiLyXFiles.cpp +++ b/src/frontends/qt4/GuiLyXFiles.cpp @@ -39,9 +39,8 @@ using namespace lyx::support; namespace lyx { namespace frontend { -namespace { -void getFiles(QMap & in, QString const type) +void GuiLyXFiles::getFiles(QMap & in, QString const type) { // We look for lyx files in the subdirectory dir of // 1) user_lyxdir @@ -112,7 +111,7 @@ void getFiles(QMap & 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 & 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); } diff --git a/src/frontends/qt4/GuiLyXFiles.h b/src/frontends/qt4/GuiLyXFiles.h index 05eff9ff68..329e4d5a84 100644 --- a/src/frontends/qt4/GuiLyXFiles.h +++ b/src/frontends/qt4/GuiLyXFiles.h @@ -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 const); private: /// contains the search box -- 2.39.2