]> git.lyx.org Git - features.git/commitdiff
GuiLyXFiles: A bit more work towards generalization
authorJuergen Spitzmueller <spitz@lyx.org>
Tue, 19 Mar 2019 15:58:23 +0000 (16:58 +0100)
committerJuergen Spitzmueller <spitz@lyx.org>
Tue, 19 Mar 2019 16:00:01 +0000 (17:00 +0100)
Bind and Ui files can be displayed in this dialog now (via lfun
dialog-show lyxfiles ui|bind), although it is not yet usable in prefs.

src/frontends/qt4/GuiLyXFiles.cpp
src/frontends/qt4/GuiLyXFiles.h

index c1f04ab5583913cc0c15b6a3e3eb22461c4bc86d..6d380bc708f8a563ede0ede36f94a320813b9ef8 100644 (file)
@@ -183,9 +183,6 @@ GuiLyXFiles::GuiLyXFiles(GuiView & lv)
        //filesLW->setViewMode(QListView::ListMode);
        filesLW->setIconSize(QSize(22, 22));
 
-       fileTypeCO->addItem(qt_("Templates"), toqstr("templates"));
-       fileTypeCO->addItem(qt_("Examples"), toqstr("examples"));
-
        setFocusProxy(filter_);
 }
 
@@ -199,6 +196,12 @@ QString const GuiLyXFiles::getSuffix()
 }
 
 
+bool GuiLyXFiles::translateName() const
+{
+       return (type_ == "templates" || type_ == "examples");
+}
+
+
 void GuiLyXFiles::changed_adaptor()
 {
        changed();
@@ -277,9 +280,9 @@ void GuiLyXFiles::updateContents()
                        catItem = filesLW->findItems(cat, Qt::MatchExactly).first();
                QTreeWidgetItem * item = new QTreeWidgetItem();
                QString const filename = info.fileName();
-               QString const guiname =
-                               toqstr(translateIfPossible(
-                                              qstring_to_ucs4(filename.left(filename.lastIndexOf(getSuffix())).replace('_', ' '))));
+               QString guiname = filename.left(filename.lastIndexOf(getSuffix())).replace('_', ' ');
+               if (translateName())
+                       guiname = toqstr(translateIfPossible(qstring_to_ucs4(guiname)));
                item->setIcon(0, iconprovider.icon(info));
                item->setData(0, Qt::UserRole, info.filePath());
                item->setData(0, Qt::DisplayRole, guiname);
@@ -365,23 +368,33 @@ bool GuiLyXFiles::isValid()
 bool GuiLyXFiles::initialiseParams(string const & type)
 {
        type_ = type.empty() ? toqstr("templates") : toqstr(type);
-       paramsToDialog(type_);
+       paramsToDialog();
        return true;
 }
 
 
-void GuiLyXFiles::paramsToDialog(QString const & command)
+void GuiLyXFiles::paramsToDialog()
 {
-       if (!command.isEmpty()) {
-               int i = fileTypeCO->findData(command);
+       fileTypeCO->clear();
+       if (type_ == "examples" || type_ == "templates") {
+               fileTypeCO->addItem(qt_("Templates"), toqstr("templates"));
+               fileTypeCO->addItem(qt_("Examples"), toqstr("examples"));
+       } else if (type_ == "ui")
+               fileTypeCO->addItem(qt_("User Interface Files"), toqstr("ui"));
+       else if (type_ == "bind")
+               fileTypeCO->addItem(qt_("Key Binding Files"), toqstr("bind"));
+
+       if (!type_.isEmpty()) {
+               int i = fileTypeCO->findData(type_);
                if (i != -1)
                        fileTypeCO->setCurrentIndex(i);
        }
-       if (command == "examples")
+       if (type_ == "examples")
                setTitle(qt_("Open Example File"));
-       else {
+       else if (type_ == "templates")
                setTitle(qt_("New File From Template"));
-       }
+       else
+               setTitle(qt_("Open File"));
 
        bc().setValid(isValid());
 }
@@ -406,7 +419,9 @@ FuncCode GuiLyXFiles::getLfun() const
 {
        if (type_ == "examples")
                return LFUN_FILE_OPEN;
-       return LFUN_BUFFER_NEW_TEMPLATE;
+       else if (type_ == "templates")
+               return LFUN_BUFFER_NEW_TEMPLATE;
+       return LFUN_NOACTION;
 }
 
 Dialog * createGuiLyXFiles(GuiView & lv) { return new GuiLyXFiles(lv); }
index 329e4d5a840203ebee0b772b85747d1591df9a25..45d611598e5c526c6d5b6d19dbe45aa3626980ac 100644 (file)
@@ -51,7 +51,7 @@ private:
        ///
        bool initialiseParams(std::string const & data);
        ///
-       void paramsToDialog(QString const & command);
+       void paramsToDialog();
        ///
        void clearParams() {}
        ///
@@ -63,6 +63,8 @@ private:
        ///
        QString const getSuffix();
        ///
+       bool translateName() const;
+       ///
        void getFiles(QMap<QString, QString> &, QString const);
 
 private: