]> git.lyx.org Git - features.git/commitdiff
GuiLyXFiles: minor generalization
authorJuergen Spitzmueller <spitz@lyx.org>
Tue, 19 Mar 2019 12:29:32 +0000 (13:29 +0100)
committerJuergen Spitzmueller <spitz@lyx.org>
Tue, 19 Mar 2019 12:29:32 +0000 (13:29 +0100)
src/frontends/qt4/GuiLyXFiles.cpp
src/frontends/qt4/GuiLyXFiles.h

index 0e43706bf5dcc83c6d1d5363654807fd9def8896..35d86d222c49d2c90cd785210b5af2d9bccf9714 100644 (file)
@@ -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); }
 
 
index 05eff9ff6850dc7927a7bd91a6ae8efaf5771d29..329e4d5a840203ebee0b772b85747d1591df9a25 100644 (file)
@@ -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