From 4c6be5671e4ae7466d45ced4f4a87e26c0b17814 Mon Sep 17 00:00:00 2001 From: jules Date: Thu, 20 Aug 2015 10:38:06 +0100 Subject: [PATCH] Introjucer: if groups are sorted, then adding new files retains the sort order. --- .../ComponentEditor/jucer_JucerDocument.cpp | 4 +- .../Project Saving/jucer_ProjectExport_MSVC.h | 4 +- .../Project Saving/jucer_ProjectSaver.h | 4 +- .../Source/Project/jucer_Module.cpp | 6 +-- .../Source/Project/jucer_Project.cpp | 44 ++++++++++++++++--- .../Introjucer/Source/Project/jucer_Project.h | 3 +- .../Source/Project/jucer_ProjectTree_Base.h | 14 ++++-- .../Source/Project/jucer_ProjectTree_Group.h | 10 ++++- .../Source/Wizards/jucer_NewFileWizard.cpp | 6 +-- .../Wizards/jucer_ProjectWizard_Animated.h | 4 +- .../Wizards/jucer_ProjectWizard_AudioApp.h | 4 +- .../Wizards/jucer_ProjectWizard_AudioPlugin.h | 8 ++-- .../Wizards/jucer_ProjectWizard_Console.h | 2 +- .../Wizards/jucer_ProjectWizard_GUIApp.h | 6 +-- .../Wizards/jucer_ProjectWizard_openGL.h | 4 +- 15 files changed, 83 insertions(+), 40 deletions(-) diff --git a/extras/Introjucer/Source/ComponentEditor/jucer_JucerDocument.cpp b/extras/Introjucer/Source/ComponentEditor/jucer_JucerDocument.cpp index 1534145e20..c1ff3e0b61 100644 --- a/extras/Introjucer/Source/ComponentEditor/jucer_JucerDocument.cpp +++ b/extras/Introjucer/Source/ComponentEditor/jucer_JucerDocument.cpp @@ -752,8 +752,8 @@ public: odm.closeDocument (cpp, true); odm.closeDocument (header, true); - parent.addFile (headerFile, 0, true); - parent.addFile (cppFile, 0, true); + parent.addFileRetainingSortOrder (headerFile, true); + parent.addFileRetainingSortOrder (cppFile, true); } } } diff --git a/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_MSVC.h b/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_MSVC.h index 422488631c..3c1a9eccd1 100644 --- a/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_MSVC.h +++ b/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_MSVC.h @@ -627,11 +627,11 @@ public: { if (iconFile != File::nonexistent) { - group.addFile (iconFile, -1, true); + group.addFileAtIndex (iconFile, -1, true); group.findItemForFile (iconFile).getShouldAddToResourceValue() = false; } - group.addFile (rcFile, -1, true); + group.addFileAtIndex (rcFile, -1, true); group.findItemForFile (rcFile).getShouldAddToResourceValue() = false; break; diff --git a/extras/Introjucer/Source/Project Saving/jucer_ProjectSaver.h b/extras/Introjucer/Source/Project Saving/jucer_ProjectSaver.h index 6794e9a8af..5c705a9b10 100644 --- a/extras/Introjucer/Source/Project Saving/jucer_ProjectSaver.h +++ b/extras/Introjucer/Source/Project Saving/jucer_ProjectSaver.h @@ -137,7 +137,7 @@ public: if (item.isValid()) return item; - generatedFilesGroup.addFile (file, -1, true); + generatedFilesGroup.addFileAtIndex (file, -1, true); return generatedFilesGroup.findItemForFile (file); } @@ -504,7 +504,7 @@ private: const File& f = binaryDataFiles.getReference(i); filesCreated.add (f); - generatedFilesGroup.addFile (f, -1, ! f.hasFileExtension (".h")); + generatedFilesGroup.addFileRetainingSortOrder (f, ! f.hasFileExtension (".h")); } } else diff --git a/extras/Introjucer/Source/Project/jucer_Module.cpp b/extras/Introjucer/Source/Project/jucer_Module.cpp index a2dab5c8cd..233861c6e0 100644 --- a/extras/Introjucer/Source/Project/jucer_Module.cpp +++ b/extras/Introjucer/Source/Project/jucer_Module.cpp @@ -601,9 +601,9 @@ void LibraryModule::addBrowseableCode (ProjectExporter& exporter, const Array= 0;) @@ -802,7 +820,7 @@ Project::Item Project::Item::addNewSubGroup (const String& name, int insertIndex return group; } -bool Project::Item::addFile (const File& file, int insertIndex, const bool shouldCompile) +bool Project::Item::addFileAtIndex (const File& file, int insertIndex, const bool shouldCompile) { if (file == File::nonexistent || file.isHidden() || file.getFileName().startsWithChar ('.')) return false; @@ -813,9 +831,7 @@ bool Project::Item::addFile (const File& file, int insertIndex, const bool shoul for (DirectoryIterator iter (file, false, "*", File::findFilesAndDirectories); iter.next();) if (! project.getMainGroup().findItemForFile (iter.getFile()).isValid()) - group.addFile (iter.getFile(), -1, shouldCompile); - - group.sortAlphabetically (false); + group.addFileRetainingSortOrder (iter.getFile(), shouldCompile); } else if (file.existsAsFile()) { @@ -830,6 +846,20 @@ bool Project::Item::addFile (const File& file, int insertIndex, const bool shoul return true; } +bool Project::Item::addFileRetainingSortOrder (const File& file, bool shouldCompile) +{ + const bool wasSortedGroupsNotFirst = isGroupSorted (state, false); + const bool wasSortedGroupsFirst = isGroupSorted (state, true); + + if (! addFileAtIndex (file, 0, shouldCompile)) + return false; + + if (wasSortedGroupsNotFirst || wasSortedGroupsFirst) + sortAlphabetically (wasSortedGroupsFirst); + + return true; +} + void Project::Item::addFileUnchecked (const File& file, int insertIndex, const bool shouldCompile) { Item item (project, ValueTree (Ids::FILE)); diff --git a/extras/Introjucer/Source/Project/jucer_Project.h b/extras/Introjucer/Source/Project/jucer_Project.h index 7d946c5cc2..db3c0e1662 100644 --- a/extras/Introjucer/Source/Project/jucer_Project.h +++ b/extras/Introjucer/Source/Project/jucer_Project.h @@ -181,7 +181,8 @@ public: Item addNewSubGroup (const String& name, int insertIndex); Item getOrCreateSubGroup (const String& name); void addChild (const Item& newChild, int insertIndex); - bool addFile (const File& file, int insertIndex, bool shouldCompile); + bool addFileAtIndex (const File& file, int insertIndex, bool shouldCompile); + bool addFileRetainingSortOrder (const File& file, bool shouldCompile); void addFileUnchecked (const File& file, int insertIndex, bool shouldCompile); bool addRelativeFile (const RelativePath& file, int insertIndex, bool shouldCompile); void removeItemFromProject(); diff --git a/extras/Introjucer/Source/Project/jucer_ProjectTree_Base.h b/extras/Introjucer/Source/Project/jucer_ProjectTree_Base.h index 9afa293b29..d10be8df1d 100644 --- a/extras/Introjucer/Source/Project/jucer_ProjectTree_Base.h +++ b/extras/Introjucer/Source/Project/jucer_ProjectTree_Base.h @@ -151,7 +151,7 @@ public: for (int i = 0; i < fc.getResults().size(); ++i) files.add (fc.getResults().getReference(i).getFullPathName()); - addFiles (files, 0); + addFilesRetainingSortOrder (files); } } @@ -167,10 +167,16 @@ public: } } - virtual void addFiles (const StringArray& files, int insertIndex) + virtual void addFilesAtIndex (const StringArray& files, int insertIndex) { if (ProjectTreeItemBase* p = getParentProjectItem()) - p->addFiles (files, insertIndex); + p->addFilesAtIndex (files, insertIndex); + } + + virtual void addFilesRetainingSortOrder (const StringArray& files) + { + if (ProjectTreeItemBase* p = getParentProjectItem()) + p->addFilesRetainingSortOrder (files); } virtual void moveSelectedItemsTo (OwnedArray &, int /*insertIndex*/) @@ -264,7 +270,7 @@ public: if (files.size() == 1 && File (files[0]).hasFileExtension (Project::projectFileExtension)) IntrojucerApp::getApp().openFile (files[0]); else - addFiles (files, insertIndex); + addFilesAtIndex (files, insertIndex); } bool isInterestedInDragSource (const DragAndDropTarget::SourceDetails& dragSourceDetails) override diff --git a/extras/Introjucer/Source/Project/jucer_ProjectTree_Group.h b/extras/Introjucer/Source/Project/jucer_ProjectTree_Group.h index 61d62d9fb9..3e18a93958 100644 --- a/extras/Introjucer/Source/Project/jucer_ProjectTree_Group.h +++ b/extras/Introjucer/Source/Project/jucer_ProjectTree_Group.h @@ -48,17 +48,23 @@ public: return false; } - void addFiles (const StringArray& files, int insertIndex) override + void addFilesAtIndex (const StringArray& files, int insertIndex) override { for (int i = 0; i < files.size(); ++i) { const File file (files[i]); - if (item.addFile (file, insertIndex, true)) + if (item.addFileAtIndex (file, insertIndex, true)) ++insertIndex; } } + void addFilesRetainingSortOrder (const StringArray& files) override + { + for (int i = files.size(); --i >= 0;) + item.addFileRetainingSortOrder (files[i], true); + } + void moveSelectedItemsTo (OwnedArray& selectedNodes, int insertIndex) override { moveItems (selectedNodes, item, insertIndex); diff --git a/extras/Introjucer/Source/Wizards/jucer_NewFileWizard.cpp b/extras/Introjucer/Source/Wizards/jucer_NewFileWizard.cpp index 01c4dbe4dd..d9541f0abf 100644 --- a/extras/Introjucer/Source/Wizards/jucer_NewFileWizard.cpp +++ b/extras/Introjucer/Source/Wizards/jucer_NewFileWizard.cpp @@ -67,7 +67,7 @@ public: { if (fillInNewCppFileTemplate (newFile, parent, templateName)) { - parent.addFile (newFile, 0, true); + parent.addFileRetainingSortOrder (newFile, true); return true; } @@ -96,7 +96,7 @@ public: { if (fillInNewCppFileTemplate (newFile, parent, templateName)) { - parent.addFile (newFile, 0, true); + parent.addFileRetainingSortOrder (newFile, true); return true; } @@ -171,7 +171,7 @@ public: if (FileHelpers::overwriteFileWithNewDataIfDifferent (newFile, content)) { - parent.addFile (newFile, 0, true); + parent.addFileRetainingSortOrder (newFile, true); return true; } diff --git a/extras/Introjucer/Source/Wizards/jucer_ProjectWizard_Animated.h b/extras/Introjucer/Source/Wizards/jucer_ProjectWizard_Animated.h index f2100ff9f2..86b663aa88 100644 --- a/extras/Introjucer/Source/Wizards/jucer_ProjectWizard_Animated.h +++ b/extras/Introjucer/Source/Wizards/jucer_ProjectWizard_Animated.h @@ -54,7 +54,7 @@ struct AnimatedAppWizard : public NewProjectWizard if (! FileHelpers::overwriteFileWithNewDataIfDifferent (contentCompCpp, windowCpp)) failedFiles.add (contentCompCpp.getFullPathName()); - sourceGroup.addFile (contentCompCpp, -1, true); + sourceGroup.addFileAtIndex (contentCompCpp, -1, true); // create main cpp @@ -68,7 +68,7 @@ struct AnimatedAppWizard : public NewProjectWizard if (! FileHelpers::overwriteFileWithNewDataIfDifferent (mainCppFile, mainCpp)) failedFiles.add (mainCppFile.getFullPathName()); - sourceGroup.addFile (mainCppFile, -1, true); + sourceGroup.addFileAtIndex (mainCppFile,-1, true); return true; } diff --git a/extras/Introjucer/Source/Wizards/jucer_ProjectWizard_AudioApp.h b/extras/Introjucer/Source/Wizards/jucer_ProjectWizard_AudioApp.h index 7fb8ea8fe8..8018e3c7db 100644 --- a/extras/Introjucer/Source/Wizards/jucer_ProjectWizard_AudioApp.h +++ b/extras/Introjucer/Source/Wizards/jucer_ProjectWizard_AudioApp.h @@ -54,7 +54,7 @@ struct AudioAppWizard : public NewProjectWizard if (! FileHelpers::overwriteFileWithNewDataIfDifferent (contentCompCpp, windowCpp)) failedFiles.add (contentCompCpp.getFullPathName()); - sourceGroup.addFile (contentCompCpp, -1, true); + sourceGroup.addFileAtIndex (contentCompCpp, -1, true); // create main cpp @@ -68,7 +68,7 @@ struct AudioAppWizard : public NewProjectWizard if (! FileHelpers::overwriteFileWithNewDataIfDifferent (mainCppFile, mainCpp)) failedFiles.add (mainCppFile.getFullPathName()); - sourceGroup.addFile (mainCppFile, -1, true); + sourceGroup.addFileAtIndex (mainCppFile, -1, true); return true; } diff --git a/extras/Introjucer/Source/Wizards/jucer_ProjectWizard_AudioPlugin.h b/extras/Introjucer/Source/Wizards/jucer_ProjectWizard_AudioPlugin.h index 12f83e224f..4b5318c3af 100644 --- a/extras/Introjucer/Source/Wizards/jucer_ProjectWizard_AudioPlugin.h +++ b/extras/Introjucer/Source/Wizards/jucer_ProjectWizard_AudioPlugin.h @@ -94,10 +94,10 @@ struct AudioPluginAppWizard : public NewProjectWizard if (! FileHelpers::overwriteFileWithNewDataIfDifferent (editorHFile, editorH)) failedFiles.add (editorHFile.getFullPathName()); - sourceGroup.addFile (filterCppFile, -1, true); - sourceGroup.addFile (filterHFile, -1, false); - sourceGroup.addFile (editorCppFile, -1, true); - sourceGroup.addFile (editorHFile, -1, false); + sourceGroup.addFileAtIndex (filterCppFile, -1, true); + sourceGroup.addFileAtIndex (filterHFile, -1, false); + sourceGroup.addFileAtIndex (editorCppFile, -1, true); + sourceGroup.addFileAtIndex (editorHFile, -1, false); return true; } diff --git a/extras/Introjucer/Source/Wizards/jucer_ProjectWizard_Console.h b/extras/Introjucer/Source/Wizards/jucer_ProjectWizard_Console.h index d14fe4f5a7..f0312a42a5 100644 --- a/extras/Introjucer/Source/Wizards/jucer_ProjectWizard_Console.h +++ b/extras/Introjucer/Source/Wizards/jucer_ProjectWizard_Console.h @@ -74,7 +74,7 @@ struct ConsoleAppWizard : public NewProjectWizard if (! FileHelpers::overwriteFileWithNewDataIfDifferent (mainCppFile, mainCpp)) failedFiles.add (mainCppFile.getFullPathName()); - sourceGroup.addFile (mainCppFile, -1, true); + sourceGroup.addFileAtIndex (mainCppFile, -1, true); } return true; diff --git a/extras/Introjucer/Source/Wizards/jucer_ProjectWizard_GUIApp.h b/extras/Introjucer/Source/Wizards/jucer_ProjectWizard_GUIApp.h index 486deca770..e441af9563 100644 --- a/extras/Introjucer/Source/Wizards/jucer_ProjectWizard_GUIApp.h +++ b/extras/Introjucer/Source/Wizards/jucer_ProjectWizard_GUIApp.h @@ -93,8 +93,8 @@ struct GUIAppWizard : public NewProjectWizard if (! FileHelpers::overwriteFileWithNewDataIfDifferent (contentCompCpp, windowCpp)) failedFiles.add (contentCompCpp.getFullPathName()); - sourceGroup.addFile (contentCompCpp, -1, true); - sourceGroup.addFile (contentCompH, -1, false); + sourceGroup.addFileAtIndex (contentCompCpp, -1, true); + sourceGroup.addFileAtIndex (contentCompH, -1, false); } if (createMainCpp) @@ -110,7 +110,7 @@ struct GUIAppWizard : public NewProjectWizard if (! FileHelpers::overwriteFileWithNewDataIfDifferent (mainCppFile, mainCpp)) failedFiles.add (mainCppFile.getFullPathName()); - sourceGroup.addFile (mainCppFile, -1, true); + sourceGroup.addFileAtIndex (mainCppFile, -1, true); } return true; diff --git a/extras/Introjucer/Source/Wizards/jucer_ProjectWizard_openGL.h b/extras/Introjucer/Source/Wizards/jucer_ProjectWizard_openGL.h index 263f019e28..0cda662b33 100644 --- a/extras/Introjucer/Source/Wizards/jucer_ProjectWizard_openGL.h +++ b/extras/Introjucer/Source/Wizards/jucer_ProjectWizard_openGL.h @@ -54,7 +54,7 @@ struct OpenGLAppWizard : public NewProjectWizard if (! FileHelpers::overwriteFileWithNewDataIfDifferent (contentCompCpp, windowCpp)) failedFiles.add (contentCompCpp.getFullPathName()); - sourceGroup.addFile (contentCompCpp, -1, true); + sourceGroup.addFileAtIndex (contentCompCpp, -1, true); // create main cpp @@ -68,7 +68,7 @@ struct OpenGLAppWizard : public NewProjectWizard if (! FileHelpers::overwriteFileWithNewDataIfDifferent (mainCppFile, mainCpp)) failedFiles.add (mainCppFile.getFullPathName()); - sourceGroup.addFile (mainCppFile, -1, true); + sourceGroup.addFileAtIndex (mainCppFile, -1, true); return true; }