View Single Post
Old 04-06-2024, 07:48 PM   #15
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 7,705
Karma: 5444398
Join Date: Nov 2009
Device: many
If anyone is building their own Sigil on Windows and or Linux, I would love to have the following patch applied to the latest Sigil source, built, and tested.

Code:
diff --git a/src/MainUI/OPFModel.cpp b/src/MainUI/OPFModel.cpp
index 3e9e7715f..7bbb8a95a 100644
--- a/src/MainUI/OPFModel.cpp
+++ b/src/MainUI/OPFModel.cpp
@@ -741,6 +741,7 @@ void OPFModel::SortHTMLFilesByAlphanumeric(QList <QModelIndex> index_list)
 
 bool OPFModel::FilenameIsValid(const QString &old_bookpath, const QString &new_filename)
 {
+    QString FullPathToMainFolder = m_Book->GetFolderKeeper()->GetFullPathToMainFolder();
     foreach(QChar character, new_filename) {
         if (FORBIDDEN_FILENAME_CHARS.contains(character)) {
             Utility::DisplayStdErrorDialog(
@@ -766,9 +767,14 @@ bool OPFModel::FilenameIsValid(const QString &old_bookpath, const QString &new_f
     QString proposed_bookpath = sdir.isEmpty() ? new_filename : sdir + "/" + new_filename;
     const QStringList existing_bookpaths = m_Book->GetFolderKeeper()->GetAllBookPaths();
     if (existing_bookpaths.contains(proposed_bookpath, Qt::CaseInsensitive)) {
-        Utility::DisplayStdErrorDialog(
-            tr("The filename \"%1\" is already in use.\n").arg(new_filename));
-        return false;
+        QString orig_full_path = FullPathToMainFolder + "/" + old_bookpath;
+        QString proposed_full_path = FullPathToMainFolder + "/" + proposed_bookpath;
+        // if different files
+        if (QFileInfo(orig_full_path) != QFileInfo(proposed_full_path)) {
+            Utility::DisplayStdErrorDialog(
+                tr("The filename \"%1\" is already in use.\n").arg(new_filename));
+            return false;
+        }
     }
     return true;
 }


To test after rebuilding, just open Sigil and right click in BookBrowser on Section0001.xhtml and try renaming it to:

secTioN0001.xhtml

And let me know if it succeeds and if the OPF is properly updated.

This appears to work on macOS but really needs to be tested on Windows and Linux.

I am sure there are similar things that still have to be tracked down and changed for that to work with Move (and Restructure to Sigil Norm) but if this works, it will be a good first step.

Thanks
KevinH is offline   Reply With Quote