diff --git a/src/dialog/vnewnotebookdialog.cpp b/src/dialog/vnewnotebookdialog.cpp
index f1721918..94281084 100644
--- a/src/dialog/vnewnotebookdialog.cpp
+++ b/src/dialog/vnewnotebookdialog.cpp
@@ -229,9 +229,10 @@ void VNewNotebookDialog::handleInputChanged()
bool nameOk = !name.isEmpty();
if (pathOk && nameOk) {
// Check if the name conflicts with existing notebook name.
+ // Case-insensitive.
int idx = -1;
for (idx = 0; idx < m_notebooks.size(); ++idx) {
- if (m_notebooks[idx]->getName() == name) {
+ if (m_notebooks[idx]->getName().toLower() == name.toLower()) {
break;
}
}
@@ -239,7 +240,7 @@ void VNewNotebookDialog::handleInputChanged()
if (idx < m_notebooks.size()) {
nameOk = false;
showWarnLabel = true;
- QString nameConflictText = tr("WARNING: Name already exists. "
+ QString nameConflictText = tr("WARNING: Name (case-insensitive) already exists. "
"Please choose another name.")
.arg(vconfig.c_warningTextStyle);
m_warnLabel->setText(nameConflictText);
diff --git a/src/dialog/vnotebookinfodialog.cpp b/src/dialog/vnotebookinfodialog.cpp
index 4d70070d..8cbd0b66 100644
--- a/src/dialog/vnotebookinfodialog.cpp
+++ b/src/dialog/vnotebookinfodialog.cpp
@@ -90,9 +90,10 @@ void VNotebookInfoDialog::handleInputChanged()
if (nameOk && name != m_notebook->getName()) {
// Check if the name conflicts with existing notebook name.
+ // Case-insensitive.
int idx = -1;
for (idx = 0; idx < m_notebooks.size(); ++idx) {
- if (m_notebooks[idx]->getName() == name) {
+ if (m_notebooks[idx]->getName().toLower() == name.toLower()) {
break;
}
}
@@ -100,7 +101,7 @@ void VNotebookInfoDialog::handleInputChanged()
if (idx < m_notebooks.size()) {
nameOk = false;
showWarnLabel = true;
- QString nameConflictText = tr("WARNING: Name already exists. "
+ QString nameConflictText = tr("WARNING: Name (case-insensitive) already exists. "
"Please choose another name.")
.arg(vconfig.c_warningTextStyle);
m_warnLabel->setText(nameConflictText);
diff --git a/src/vdirectory.cpp b/src/vdirectory.cpp
index 25f22fe7..ec069397 100644
--- a/src/vdirectory.cpp
+++ b/src/vdirectory.cpp
@@ -206,14 +206,15 @@ VDirectory *VDirectory::createSubDirectory(const QString &p_name)
return ret;
}
-VDirectory *VDirectory::findSubDirectory(const QString &p_name)
+VDirectory *VDirectory::findSubDirectory(const QString &p_name, bool p_caseSensitive)
{
if (!open()) {
return NULL;
}
+ QString name = p_caseSensitive ? p_name : p_name.toLower();
for (int i = 0; i < m_subDirs.size(); ++i) {
- if (p_name == m_subDirs[i]->getName()) {
+ if (name == (p_caseSensitive ? m_subDirs[i]->getName() : m_subDirs[i]->getName().toLower())) {
return m_subDirs[i];
}
}
@@ -221,14 +222,15 @@ VDirectory *VDirectory::findSubDirectory(const QString &p_name)
return NULL;
}
-VFile *VDirectory::findFile(const QString &p_name)
+VFile *VDirectory::findFile(const QString &p_name, bool p_caseSensitive)
{
if (!open()) {
return NULL;
}
+ QString name = p_caseSensitive ? p_name : p_name.toLower();
for (int i = 0; i < m_files.size(); ++i) {
- if (p_name == m_files[i]->getName()) {
+ if (name == (p_caseSensitive ? m_files[i]->getName() : m_files[i]->getName().toLower())) {
return m_files[i];
}
}
@@ -693,12 +695,18 @@ VFile *VDirectory::tryLoadFile(QStringList &p_filePath)
VFile *file = NULL;
+#if defined(Q_OS_WIN)
+ bool caseSensitive = false;
+#else
+ bool caseSensitive = true;
+#endif
+
if (p_filePath.size() == 1) {
// File.
- file = findFile(p_filePath.at(0));
+ file = findFile(p_filePath.at(0), caseSensitive);
} else {
// Directory.
- VDirectory *dir = findSubDirectory(p_filePath.at(0));
+ VDirectory *dir = findSubDirectory(p_filePath.at(0), caseSensitive);
if (dir) {
p_filePath.removeFirst();
file = dir->tryLoadFile(p_filePath);
diff --git a/src/vdirectory.h b/src/vdirectory.h
index 7e1100d1..98c02302 100644
--- a/src/vdirectory.h
+++ b/src/vdirectory.h
@@ -21,10 +21,10 @@ public:
VDirectory *createSubDirectory(const QString &p_name);
// Returns the VDirectory with the name @p_name directly in this directory.
- VDirectory *findSubDirectory(const QString &p_name);
+ VDirectory *findSubDirectory(const QString &p_name, bool p_caseSensitive);
// Returns the VFile with the name @p_name directly in this directory.
- VFile *findFile(const QString &p_name);
+ VFile *findFile(const QString &p_name, bool p_caseSensitive);
// If current dir or its sub-dir contains @p_file.
bool containsFile(const VFile *p_file) const;
diff --git a/src/vdirectorytree.cpp b/src/vdirectorytree.cpp
index 4ca8811a..f601d3d1 100644
--- a/src/vdirectorytree.cpp
+++ b/src/vdirectorytree.cpp
@@ -347,12 +347,15 @@ void VDirectoryTree::newSubDirectory()
VNewDirDialog dialog(tr("Create Folder"), info, text, defaultText, this);
if (dialog.exec() == QDialog::Accepted) {
QString name = dialog.getNameInput();
- if (curDir->findSubDirectory(name)) {
- info = tr("Name already exists in %2. Please choose another name.")
+ // Case-insensitive.
+ if (curDir->findSubDirectory(name, false)) {
+ info = tr("Name (case-insensitive) already exists in "
+ "%2. Please choose another name.")
.arg(vconfig.c_dataTextStyle).arg(curDir->getName());
defaultText = name;
continue;
}
+
VDirectory *subDir = curDir->createSubDirectory(name);
if (!subDir) {
VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
@@ -382,8 +385,9 @@ void VDirectoryTree::newRootDirectory()
VNewDirDialog dialog(tr("Create Root Folder"), info, text, defaultText, this);
if (dialog.exec() == QDialog::Accepted) {
QString name = dialog.getNameInput();
- if (rootDir->findSubDirectory(name)) {
- info = tr("Name already exists in notebook %2. Please choose another name.")
+ if (rootDir->findSubDirectory(name, false)) {
+ info = tr("Name (case-insensitive) already exists in "
+ "notebook %2. Please choose another name.")
.arg(vconfig.c_dataTextStyle).arg(m_notebook->getName());
defaultText = name;
continue;
@@ -461,11 +465,13 @@ void VDirectoryTree::editDirectoryInfo()
if (name == curName) {
return;
}
- if (parentDir->findSubDirectory(name)) {
- info = "Name already exists. Please choose another name.";
+
+ if (parentDir->findSubDirectory(name, false)) {
+ info = "Name (case-insensitive) already exists. Please choose another name.";
defaultName = name;
continue;
}
+
if (!curDir->rename(name)) {
VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
tr("Fail to rename folder %2.")
diff --git a/src/vfilelist.cpp b/src/vfilelist.cpp
index 93db2852..740ca9e2 100644
--- a/src/vfilelist.cpp
+++ b/src/vfilelist.cpp
@@ -146,8 +146,10 @@ void VFileList::fileInfo(VFile *p_file)
if (name == curName) {
return;
}
- if (dir->findFile(name)) {
- info = "Name already exists. Please choose another name.";
+
+ // Case-insensitive when creating note.
+ if (dir->findFile(name, false)) {
+ info = "Name (case-insensitive) already exists. Please choose another name.";
defaultName = name;
continue;
}
@@ -238,11 +240,13 @@ void VFileList::newFile()
VNewFileDialog dialog(tr("Create Note"), info, text, defaultText, this);
if (dialog.exec() == QDialog::Accepted) {
QString name = dialog.getNameInput();
- if (m_directory->findFile(name)) {
- info = tr("Name already exists. Please choose another name.");
+ // Case-insensitive when creating note.
+ if (m_directory->findFile(name, false)) {
+ info = tr("Name (case-insensitive) already exists. Please choose another name.");
defaultText = name;
continue;
}
+
VFile *file = m_directory->createFile(name);
if (!file) {
VUtils::showMessage(QMessageBox::Warning, tr("Warning"),