select parent if the file does not exist anymore.

This commit is contained in:
Martin Marmsoler 2023-02-07 08:53:49 +01:00
parent ed5a27267a
commit 47eae81893

View File

@ -481,6 +481,19 @@ void DoubleTreeWidget::loadSelection() {
if (mSelectedFile.filename != "") {
index = mDiffTreeModel->index(mSelectedFile.filename);
if (!index.isValid()) {
// If index is anymore valid, because of removed file,
// select the parent if possible
auto list = mSelectedFile.filename.split(
QStringLiteral("/")); // TODO: check also on windows
list.removeLast();
while (!index.isValid() && !list.isEmpty()) {
const QString s = list.join(QStringLiteral("/"));
index = mDiffTreeModel->index(s);
list.removeLast();
}
}
state = static_cast<Qt::CheckState>(
mDiffTreeModel->data(index, Qt::CheckStateRole).toInt());
}