diff --git a/extras/Projucer/Source/Application/jucer_Application.cpp b/extras/Projucer/Source/Application/jucer_Application.cpp index a0624e8492..ae69081f68 100644 --- a/extras/Projucer/Source/Application/jucer_Application.cpp +++ b/extras/Projucer/Source/Application/jucer_Application.cpp @@ -73,13 +73,10 @@ void ProjucerApplication::initialise (const String& commandLine) + "MHz Cores: " + String (SystemStats::getNumCpus()) + " " + String (SystemStats::getMemorySizeInMegabytes()) + "MB"); - initialiseBasics(); - isRunningCommandLine = commandLine.isNotEmpty() && ! commandLine.startsWith ("-NSDocumentRevisionsDebugMode"); - licenseController.reset (new LicenseController); - licenseController->addLicenseStatusChangedCallback (this); + initialiseBasics(); if (isRunningCommandLine) { @@ -125,12 +122,10 @@ void ProjucerApplication::initialise (const String& commandLine) void ProjucerApplication::initialiseBasics() { - LookAndFeel::setDefaultLookAndFeel (&lookAndFeel); + settings = std::make_unique(); - settings.reset (new StoredSettings()); - ImageCache::setCacheTimeout (30 * 1000); - icons.reset (new Icons()); - tooltipWindow.setMillisecondsBeforeTipAppears (1200); + licenseController.reset (new LicenseController); + licenseController->addLicenseStatusChangedCallback (this); } bool ProjucerApplication::initialiseLogger (const char* filePrefix) @@ -154,6 +149,13 @@ bool ProjucerApplication::initialiseLogger (const char* filePrefix) void ProjucerApplication::handleAsyncUpdate() { + LookAndFeel::setDefaultLookAndFeel (&lookAndFeel); + + ImageCache::setCacheTimeout (30 * 1000); + icons = std::make_unique(); + + tooltipWindow = std::make_unique (nullptr, 1200); + if (licenseController != nullptr) licenseController->startWebviewIfNeeded(); @@ -236,7 +238,8 @@ void ProjucerApplication::shutdown() commandManager.reset(); settings.reset(); - LookAndFeel::setDefaultLookAndFeel (nullptr); + if (! isRunningCommandLine) + LookAndFeel::setDefaultLookAndFeel (nullptr); // clean up after ourselves and delete any temp project files that may have // been created from PIPs diff --git a/extras/Projucer/Source/Application/jucer_Application.h b/extras/Projucer/Source/Application/jucer_Application.h index bb039af796..9a910daa37 100644 --- a/extras/Projucer/Source/Application/jucer_Application.h +++ b/extras/Projucer/Source/Application/jucer_Application.h @@ -187,7 +187,7 @@ private: //============================================================================== void* server = nullptr; - TooltipWindow tooltipWindow; + std::unique_ptr tooltipWindow; AvailableModuleList jucePathModuleList, userPathsModuleList; diff --git a/extras/Projucer/Source/Application/jucer_CommandLine.cpp b/extras/Projucer/Source/Application/jucer_CommandLine.cpp index 7fa08b9483..c62b761e76 100644 --- a/extras/Projucer/Source/Application/jucer_CommandLine.cpp +++ b/extras/Projucer/Source/Application/jucer_CommandLine.cpp @@ -74,7 +74,7 @@ namespace project.reset (new Project (projectFile)); - if (! project->loadFrom (projectFile, true)) + if (! project->loadFrom (projectFile, true, false)) { project.reset(); ConsoleApplication::fail ("Failed to load the project file: " + projectFile.getFullPathName()); @@ -222,7 +222,6 @@ namespace //============================================================================== static void showStatus (const ArgumentList& args) { - hideDockIcon(); args.checkMinNumArguments (2); LoadedProject proj (args[1]); diff --git a/modules/juce_gui_extra/documents/juce_FileBasedDocument.cpp b/modules/juce_gui_extra/documents/juce_FileBasedDocument.cpp index 794ca5a69a..52f9c979f3 100644 --- a/modules/juce_gui_extra/documents/juce_FileBasedDocument.cpp +++ b/modules/juce_gui_extra/documents/juce_FileBasedDocument.cpp @@ -23,8 +23,7 @@ FileBasedDocument::FileBasedDocument (const String& fileExtension_, const String& fileWildcard_, const String& openFileDialogTitle_, const String& saveFileDialogTitle_) - : changedSinceSave (false), - fileExtension (fileExtension_), + : fileExtension (fileExtension_), fileWildcard (fileWildcard_), openFileDialogTitle (openFileDialogTitle_), saveFileDialogTitle (saveFileDialogTitle_) @@ -36,7 +35,7 @@ FileBasedDocument::~FileBasedDocument() } //============================================================================== -void FileBasedDocument::setChangedFlag (const bool hasChanged) +void FileBasedDocument::setChangedFlag (bool hasChanged) { if (changedSinceSave != hasChanged) { @@ -62,14 +61,15 @@ void FileBasedDocument::setFile (const File& newFile) } //============================================================================== -Result FileBasedDocument::loadFrom (const File& newFile, const bool showMessageOnFailure) +Result FileBasedDocument::loadFrom (const File& newFile, bool showMessageOnFailure, bool showWaitCursor) { - MouseCursor::showWaitCursor(); + if (showWaitCursor) + MouseCursor::showWaitCursor(); - const File oldFile (documentFile); + auto oldFile = documentFile; documentFile = newFile; - Result result (Result::fail (TRANS("The file doesn't exist"))); + auto result = Result::fail (TRANS("The file doesn't exist")); if (newFile.existsAsFile()) { @@ -78,7 +78,9 @@ Result FileBasedDocument::loadFrom (const File& newFile, const bool showMessageO if (result.wasOk()) { setChangedFlag (false); - MouseCursor::hideWaitCursor(); + + if (showWaitCursor) + MouseCursor::hideWaitCursor(); setLastDocumentOpened (newFile); return result; @@ -86,7 +88,9 @@ Result FileBasedDocument::loadFrom (const File& newFile, const bool showMessageO } documentFile = oldFile; - MouseCursor::hideWaitCursor(); + + if (showWaitCursor) + MouseCursor::hideWaitCursor(); if (showMessageOnFailure) AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon, @@ -125,8 +129,8 @@ static bool askToOverwriteFile (const File& newFile) } //============================================================================== -FileBasedDocument::SaveResult FileBasedDocument::save (const bool askUserForFileIfNotSpecified, - const bool showMessageOnFailure) +FileBasedDocument::SaveResult FileBasedDocument::save (bool askUserForFileIfNotSpecified, + bool showMessageOnFailure) { return saveAs (documentFile, false, @@ -135,9 +139,10 @@ FileBasedDocument::SaveResult FileBasedDocument::save (const bool askUserForFile } FileBasedDocument::SaveResult FileBasedDocument::saveAs (const File& newFile, - const bool warnAboutOverwritingExistingFiles, - const bool askUserForFileIfNotSpecified, - const bool showMessageOnFailure) + bool warnAboutOverwritingExistingFiles, + bool askUserForFileIfNotSpecified, + bool showMessageOnFailure, + bool showWaitCursor) { if (newFile == File()) { @@ -154,24 +159,29 @@ FileBasedDocument::SaveResult FileBasedDocument::saveAs (const File& newFile, && ! askToOverwriteFile (newFile)) return userCancelledSave; - MouseCursor::showWaitCursor(); + if (showWaitCursor) + MouseCursor::showWaitCursor(); - const File oldFile (documentFile); + auto oldFile = documentFile; documentFile = newFile; - const Result result (saveDocument (newFile)); + auto result = saveDocument (newFile); if (result.wasOk()) { setChangedFlag (false); - MouseCursor::hideWaitCursor(); + + if (showWaitCursor) + MouseCursor::hideWaitCursor(); sendChangeMessage(); // because the filename may have changed return savedOk; } documentFile = oldFile; - MouseCursor::hideWaitCursor(); + + if (showWaitCursor) + MouseCursor::hideWaitCursor(); if (showMessageOnFailure) AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon, @@ -191,13 +201,13 @@ FileBasedDocument::SaveResult FileBasedDocument::saveIfNeededAndUserAgrees() if (! hasChangedSinceSaved()) return savedOk; - const int r = AlertWindow::showYesNoCancelBox (AlertWindow::QuestionIcon, - TRANS("Closing document..."), - TRANS("Do you want to save the changes to \"DCNM\"?") - .replace ("DCNM", getDocumentTitle()), - TRANS("Save"), - TRANS("Discard changes"), - TRANS("Cancel")); + auto r = AlertWindow::showYesNoCancelBox (AlertWindow::QuestionIcon, + TRANS("Closing document..."), + TRANS("Do you want to save the changes to \"DCNM\"?") + .replace ("DCNM", getDocumentTitle()), + TRANS("Save"), + TRANS("Discard changes"), + TRANS("Cancel")); if (r == 1) // save changes return save (true, true); @@ -213,16 +223,11 @@ File FileBasedDocument::getSuggestedSaveAsFile (const File& defaultFile) return defaultFile.withFileExtension (fileExtension).getNonexistentSibling (true); } -FileBasedDocument::SaveResult FileBasedDocument::saveAsInteractive (const bool warnAboutOverwritingExistingFiles) +FileBasedDocument::SaveResult FileBasedDocument::saveAsInteractive (bool warnAboutOverwritingExistingFiles) { - File f; + auto f = documentFile.existsAsFile() ? documentFile : getLastDocumentOpened(); - if (documentFile.existsAsFile()) - f = documentFile; - else - f = getLastDocumentOpened(); - - String legalFilename (File::createLegalFileName (getDocumentTitle())); + auto legalFilename = File::createLegalFileName (getDocumentTitle()); if (legalFilename.isEmpty()) legalFilename = "unnamed"; @@ -238,7 +243,8 @@ FileBasedDocument::SaveResult FileBasedDocument::saveAsInteractive (const bool w if (fc.browseForFileToSave (warnAboutOverwritingExistingFiles)) { - File chosen (fc.getResult()); + auto chosen = fc.getResult(); + if (chosen.getFileExtension().isEmpty()) { chosen = chosen.withFileExtension (fileExtension); diff --git a/modules/juce_gui_extra/documents/juce_FileBasedDocument.h b/modules/juce_gui_extra/documents/juce_FileBasedDocument.h index 8fb9131f40..776afb704a 100644 --- a/modules/juce_gui_extra/documents/juce_FileBasedDocument.h +++ b/modules/juce_gui_extra/documents/juce_FileBasedDocument.h @@ -100,7 +100,8 @@ public: @see loadDocument, loadFromUserSpecifiedFile */ Result loadFrom (const File& fileToLoadFrom, - bool showMessageOnFailure); + bool showMessageOnFailure, + bool showWaitCursor = true); /** Asks the user for a file and tries to load it. @@ -175,12 +176,15 @@ public: filename @param showMessageOnFailure if true and the write operation fails, it'll show a message box to warn the user + @param showWaitCursor if true, the 'wait' mouse cursor will be showin during + saving @see saveIfNeededAndUserAgrees, save, saveAsInteractive */ SaveResult saveAs (const File& newFile, bool warnAboutOverwritingExistingFiles, bool askUserForFileIfNotSpecified, - bool showMessageOnFailure); + bool showMessageOnFailure, + bool showWaitCursor = true); /** Prompts the user for a filename and tries to save to it. @@ -279,7 +283,7 @@ protected: private: //============================================================================== File documentFile; - bool changedSinceSave; + bool changedSinceSave = false; String fileExtension, fileWildcard, openFileDialogTitle, saveFileDialogTitle; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FileBasedDocument)