same behavior for document naming as for folder naming

preferencesAboutTextFull
Clément Fauconnier 3 years ago
parent 05b6bf87b3
commit fe06bdf1df
  1. 39
      src/document/UBDocumentController.cpp
  2. 21
      src/document/UBDocumentController.h

@ -1645,10 +1645,15 @@ UBDocumentTreeItemDelegate::UBDocumentTreeItemDelegate(QObject *parent)
void UBDocumentTreeItemDelegate::commitAndCloseEditor()
{
QLineEdit *lineEditor = qobject_cast<QLineEdit*>(sender());
if (lineEditor) {
emit commitData(lineEditor);
QLineEdit *lineEditor = dynamic_cast<QLineEdit*>(sender());
if (lineEditor)
{
if (lineEditor->hasAcceptableInput())
{
emit commitData(lineEditor);
//emit closeEditor(lineEditor);
}
emit UBApplication::documentController->reorderDocumentsRequested();
}
}
@ -1678,13 +1683,26 @@ QWidget *UBDocumentTreeItemDelegate::createEditor(QWidget *parent, const QStyleO
//N/C - NNE - 20140407 : Add the test for the index column.
if(index.column() == 0){
mExistingFileNames.clear();
const UBDocumentTreeModel *indexModel = qobject_cast<const UBDocumentTreeModel*>(index.model());
if (indexModel) {
mExistingFileNames = indexModel->nodeNameList(index.parent());
mExistingFileNames.removeOne(index.data().toString());
const UBDocumentTreeModel *docModel = 0;
const UBSortFilterProxyModel *proxy = dynamic_cast<const UBSortFilterProxyModel*>(index.model());
if(proxy){
docModel = dynamic_cast<UBDocumentTreeModel*>(proxy->sourceModel());
}else{
docModel = dynamic_cast<const UBDocumentTreeModel*>(index.model());
}
QModelIndex sourceIndex = proxy->mapToSource(index);
if (docModel) {
mExistingFileNames = docModel->nodeNameList(sourceIndex.parent());
mExistingFileNames.removeOne(sourceIndex.data().toString());
}
QLineEdit *nameEditor = new QLineEdit(parent);
UBValidator* validator = new UBValidator(mExistingFileNames);
nameEditor->setValidator(validator);
connect(nameEditor, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor()));
connect(nameEditor, SIGNAL(textChanged(QString)), this, SLOT(processChangedText(QString)));
return nameEditor;
@ -1760,7 +1778,12 @@ void UBDocumentController::createNewDocument()
? docModel->virtualPathForIndex(selectedIndex)
: docModel->virtualDirForIndex(selectedIndex);
UBDocumentProxy *document = pManager->createDocument(groupName);
QDateTime now = QDateTime::currentDateTime();
QString documentName = docModel->adjustNameForParentIndex(now.toString(Qt::SystemLocaleShortDate), selectedIndex.parent());
UBDocumentProxy *document = pManager->createDocument(groupName, documentName);
selectDocument(document, true, false, true);
if (document)

@ -321,6 +321,27 @@ private:
void updateIndexEnvirons(const QModelIndex &index);
};
class UBValidator : public QValidator
{
const QStringList mExistingFileNames;
public:
UBValidator(const QStringList existingFileNames, QObject *parent = nullptr)
: QValidator(parent)
, mExistingFileNames(existingFileNames)
{
}
QValidator::State validate(QString &input, int &pos) const
{
if (mExistingFileNames.contains(input))
return QValidator::Intermediate;
else
return QValidator::Acceptable;
}
};
class UBDocumentTreeItemDelegate : public QStyledItemDelegate
{
Q_OBJECT

Loading…
Cancel
Save