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.
This commit is contained in:
Juergen Spitzmueller 2019-03-19 16:58:23 +01:00
parent a410b0d698
commit 52d2ba16ed
2 changed files with 32 additions and 15 deletions

View File

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

View File

@ -51,7 +51,7 @@ private:
/// ///
bool initialiseParams(std::string const & data); bool initialiseParams(std::string const & data);
/// ///
void paramsToDialog(QString const & command); void paramsToDialog();
/// ///
void clearParams() {} void clearParams() {}
/// ///
@ -63,6 +63,8 @@ private:
/// ///
QString const getSuffix(); QString const getSuffix();
/// ///
bool translateName() const;
///
void getFiles(QMap<QString, QString> &, QString const); void getFiles(QMap<QString, QString> &, QString const);
private: private: