improved last fix + fixed an issue where rename a folder could result broken folders hierarchy

preferencesAboutTextFull
Clément Fauconnier 4 years ago
parent a3ad10b459
commit d30d9862d4
  1. 2
      src/core/UBPersistenceManager.cpp
  2. 29
      src/document/UBDocumentController.cpp
  3. 2
      src/document/UBDocumentController.h

@ -227,7 +227,7 @@ QDialog::DialogCode UBPersistenceManager::processInteractiveReplacementDialog(UB
return QDialog::Rejected; return QDialog::Rejected;
} }
QStringList docList = mDocumentTreeStructureModel->nodeNameList(parentIndex); QStringList docList = mDocumentTreeStructureModel->nodeNameList(parentIndex, true);
QString docName = pProxy->metaData(UBSettings::documentName).toString(); QString docName = pProxy->metaData(UBSettings::documentName).toString();
if (docList.contains(docName)) { if (docList.contains(docName)) {

@ -539,7 +539,14 @@ bool UBDocumentTreeModel::setData(const QModelIndex &index, const QVariant &valu
if (!index.isValid() || value.toString().isEmpty()) { if (!index.isValid() || value.toString().isEmpty()) {
return false; return false;
} }
setNewName(index, value.toString());
QString fullNewName = value.toString();
if (isCatalog(index))
{
fullNewName.replace('/', '-');
}
setNewName(index, fullNewName);
return true; return true;
} }
return QAbstractItemModel::setData(index, value, role); return QAbstractItemModel::setData(index, value, role);
@ -1019,7 +1026,7 @@ QString UBDocumentTreeModel::virtualPathForIndex(const QModelIndex &pIndex) cons
return virtualDirForIndex(pIndex) + "/" + curNode->nodeName(); return virtualDirForIndex(pIndex) + "/" + curNode->nodeName();
} }
QStringList UBDocumentTreeModel::nodeNameList(const QModelIndex &pIndex) const QStringList UBDocumentTreeModel::nodeNameList(const QModelIndex &pIndex, bool distinctNodeType) const
{ {
QStringList result; QStringList result;
@ -1030,12 +1037,21 @@ QStringList UBDocumentTreeModel::nodeNameList(const QModelIndex &pIndex) const
foreach (UBDocumentTreeNode *curNode, catalog->children()) foreach (UBDocumentTreeNode *curNode, catalog->children())
{ {
/* this function is only used (at this time) to compare filenames eachother, so it has to distinguish a folder named "A" from a file named "A" if (distinctNodeType)
// notice that it is a really poor way to search for file indexes, and that the code where it is called should be entirely reworked, when the time permits it. */ {
if (curNode->nodeType() != UBDocumentTreeNode::Catalog) if (curNode->nodeType() == UBDocumentTreeNode::Catalog)
{
result << "folder - " + curNode->nodeName();
}
else
{
result << curNode->nodeName(); result << curNode->nodeName();
}
}
else else
result << "folder - " + curNode->nodeName(); {
result << curNode->nodeName();
}
} }
return result; return result;
@ -1166,7 +1182,6 @@ void UBDocumentTreeModel::setNewName(const QModelIndex &index, const QString &ne
QString magicSeparator = "+!##s"; QString magicSeparator = "+!##s";
if (isCatalog(index)) { if (isCatalog(index)) {
QString fullNewName = newName; QString fullNewName = newName;
fullNewName.replace('/', '-');
if (!newName.contains(magicSeparator)) { if (!newName.contains(magicSeparator)) {
indexNode->setNodeName(fullNewName); indexNode->setNodeName(fullNewName);
QString virtualDir = virtualDirForIndex(index); QString virtualDir = virtualDirForIndex(index);

@ -209,7 +209,7 @@ public:
UBDocumentProxy *proxyForIndex(const QModelIndex &pIndex) const; UBDocumentProxy *proxyForIndex(const QModelIndex &pIndex) const;
QString virtualDirForIndex(const QModelIndex &pIndex) const; QString virtualDirForIndex(const QModelIndex &pIndex) const;
QString virtualPathForIndex(const QModelIndex &pIndex) const; QString virtualPathForIndex(const QModelIndex &pIndex) const;
QStringList nodeNameList(const QModelIndex &pIndex) const; QStringList nodeNameList(const QModelIndex &pIndex, bool distinctNodeType = false) const;
bool newNodeAllowed(const QModelIndex &pSelectedIndex) const; bool newNodeAllowed(const QModelIndex &pSelectedIndex) const;
QModelIndex goTo(const QString &dir); QModelIndex goTo(const QString &dir);
bool inTrash(const QModelIndex &index) const; bool inTrash(const QModelIndex &index) const;

Loading…
Cancel
Save