Browse Source

make name of notebook/folder/note case-insensitive

Le Tan 8 years ago
parent
commit
91d33c3f5c

+ 3 - 2
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("<span style=\"%1\">WARNING</span>: Name already exists. "
+            QString nameConflictText = tr("<span style=\"%1\">WARNING</span>: Name (case-insensitive) already exists. "
                                           "Please choose another name.")
                                           .arg(vconfig.c_warningTextStyle);
             m_warnLabel->setText(nameConflictText);

+ 3 - 2
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("<span style=\"%1\">WARNING</span>: Name already exists. "
+            QString nameConflictText = tr("<span style=\"%1\">WARNING</span>: Name (case-insensitive) already exists. "
                                           "Please choose another name.")
                                           .arg(vconfig.c_warningTextStyle);
             m_warnLabel->setText(nameConflictText);

+ 14 - 6
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);

+ 2 - 2
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;

+ 12 - 6
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 <span style=\"%1\">%2</span>. Please choose another name.")
+            // Case-insensitive.
+            if (curDir->findSubDirectory(name, false)) {
+                info = tr("Name (case-insensitive) already exists in "
+                          "<span style=\"%1\">%2</span>. 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 <span style=\"%1\">%2</span>. Please choose another name.")
+            if (rootDir->findSubDirectory(name, false)) {
+                info = tr("Name (case-insensitive) already exists in "
+                          "notebook <span style=\"%1\">%2</span>. 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 <span style=\"%1\">%2</span>.")

+ 8 - 4
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"),