[LyX/master] GuiLyXFiles: Fix crash and disabling with header selection
Juergen Spitzmueller
spitz at lyx.org
Tue Aug 11 17:01:31 UTC 2020
commit 075d220d6e927458c3e38d50fbecd6a7f30ece99
Author: Juergen Spitzmueller <spitz at lyx.org>
Date: Tue Aug 11 19:26:23 2020 +0200
GuiLyXFiles: Fix crash and disabling with header selection
Fixes #11929
---
src/frontends/qt/GuiLyXFiles.cpp | 27 +++++++++++++++++++++------
src/frontends/qt/GuiLyXFiles.h | 2 +-
2 files changed, 22 insertions(+), 7 deletions(-)
diff --git a/src/frontends/qt/GuiLyXFiles.cpp b/src/frontends/qt/GuiLyXFiles.cpp
index 25b6fa4..c9dbf90 100644
--- a/src/frontends/qt/GuiLyXFiles.cpp
+++ b/src/frontends/qt/GuiLyXFiles.cpp
@@ -210,9 +210,9 @@ GuiLyXFiles::GuiLyXFiles(GuiView & lv)
this, SLOT(slotButtonBox(QAbstractButton *)));
connect(filesLW, SIGNAL(itemClicked(QTreeWidgetItem *, int)),
- this, SLOT(changed_adaptor()));
+ this, SLOT(fileSelectionChanged()));
connect(filesLW, SIGNAL(itemSelectionChanged()),
- this, SLOT(changed_adaptor()));
+ this, SLOT(fileSelectionChanged()));
connect(filter_, SIGNAL(textEdited(QString)),
this, SLOT(filterLabels()));
connect(filter_, SIGNAL(rightButtonClicked()),
@@ -252,8 +252,14 @@ bool GuiLyXFiles::translateName() const
}
-void GuiLyXFiles::changed_adaptor()
+void GuiLyXFiles::fileSelectionChanged()
{
+ if (!filesLW->currentItem()
+ || !filesLW->currentItem()->data(0, Qt::UserRole).toString().endsWith(getSuffix())) {
+ // not a file (probably a header)
+ bc().setValid(false);
+ return;
+ }
changed();
}
@@ -277,9 +283,11 @@ void GuiLyXFiles::on_languageCO_activated(int i)
void GuiLyXFiles::on_filesLW_itemDoubleClicked(QTreeWidgetItem * item, int)
{
- if (!item->data(0, Qt::UserRole).toString().endsWith(getSuffix()))
+ if (!item || !item->data(0, Qt::UserRole).toString().endsWith(getSuffix())) {
// not a file (probably a header)
+ bc().setValid(false);
return;
+ }
applyView();
dispatchParams();
@@ -288,10 +296,17 @@ void GuiLyXFiles::on_filesLW_itemDoubleClicked(QTreeWidgetItem * item, int)
void GuiLyXFiles::on_filesLW_itemClicked(QTreeWidgetItem * item, int)
{
+ if (!item) {
+ bc().setValid(false);
+ return;
+ }
+
QString const data = item->data(0, Qt::UserRole).toString();
- if (!data.endsWith(getSuffix()))
+ if (!data.endsWith(getSuffix())) {
// not a file (probably a header)
+ bc().setValid(false);
return;
+ }
languageCO->clear();
QMap<QString, QString>::const_iterator i =available_languages_.constBegin();
@@ -512,7 +527,7 @@ void GuiLyXFiles::resetFilter()
QString const GuiLyXFiles::getRealPath(QString relpath)
{
- if (relpath.isEmpty())
+ if (relpath.isEmpty() && filesLW->currentItem() != nullptr)
relpath = filesLW->currentItem()->data(0, Qt::UserRole).toString();
QString const language = languageCO->itemData(languageCO->currentIndex()).toString();
if (localizations_.contains(relpath)) {
diff --git a/src/frontends/qt/GuiLyXFiles.h b/src/frontends/qt/GuiLyXFiles.h
index bc12913..62be392 100644
--- a/src/frontends/qt/GuiLyXFiles.h
+++ b/src/frontends/qt/GuiLyXFiles.h
@@ -40,7 +40,7 @@ Q_SIGNALS:
void fileSelected(QString const file);
private Q_SLOTS:
- void changed_adaptor();
+ void fileSelectionChanged();
void on_fileTypeCO_activated(int);
void on_languageCO_activated(int);
void on_filesLW_itemDoubleClicked(QTreeWidgetItem *, int);
More information about the lyx-cvs
mailing list