From: Juergen Spitzmueller Date: Tue, 19 Mar 2019 15:58:23 +0000 (+0100) Subject: GuiLyXFiles: A bit more work towards generalization X-Git-Tag: lyx-2.4.0dev-acb2ca7b~2439 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=52d2ba16ed8accc2f54157f9c260e4d1672910a0;p=features.git GuiLyXFiles: A bit more work towards generalization 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. --- diff --git a/src/frontends/qt4/GuiLyXFiles.cpp b/src/frontends/qt4/GuiLyXFiles.cpp index c1f04ab558..6d380bc708 100644 --- a/src/frontends/qt4/GuiLyXFiles.cpp +++ b/src/frontends/qt4/GuiLyXFiles.cpp @@ -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); } diff --git a/src/frontends/qt4/GuiLyXFiles.h b/src/frontends/qt4/GuiLyXFiles.h index 329e4d5a84..45d611598e 100644 --- a/src/frontends/qt4/GuiLyXFiles.h +++ b/src/frontends/qt4/GuiLyXFiles.h @@ -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 const); private: