]> git.lyx.org Git - features.git/commitdiff
GuiLyXFiles: Fix crash and disabling with header selection
authorJuergen Spitzmueller <spitz@lyx.org>
Tue, 11 Aug 2020 17:26:23 +0000 (19:26 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Tue, 11 Aug 2020 17:26:23 +0000 (19:26 +0200)
Fixes #11929

src/frontends/qt/GuiLyXFiles.cpp
src/frontends/qt/GuiLyXFiles.h

index 25b6fa4f67183da775532c11e6f481bf7e959802..c9dbf907b4cca9d70068df55df49e378bf4889e4 100644 (file)
@@ -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)) {
index bc129139a706c6c1ae243f97fe1fab484f864ca8..62be392ff9ed0464243cc77f2f172d2f2689f3e4 100644 (file)
@@ -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);