diff --git a/extras/Introjucer/Source/Application/jucer_Application.h b/extras/Introjucer/Source/Application/jucer_Application.h index 3b248116f7..d377793fc4 100644 --- a/extras/Introjucer/Source/Application/jucer_Application.h +++ b/extras/Introjucer/Source/Application/jucer_Application.h @@ -199,11 +199,9 @@ public: menu.addSeparator(); menu.addCommandItem (commandManager, CommandIDs::closeDocument); menu.addCommandItem (commandManager, CommandIDs::saveDocument); - menu.addCommandItem (commandManager, CommandIDs::saveDocumentAs); menu.addSeparator(); menu.addCommandItem (commandManager, CommandIDs::closeProject); menu.addCommandItem (commandManager, CommandIDs::saveProject); - menu.addCommandItem (commandManager, CommandIDs::saveProjectAs); menu.addSeparator(); menu.addCommandItem (commandManager, CommandIDs::openInIDE); menu.addCommandItem (commandManager, CommandIDs::saveAndOpenInIDE); diff --git a/extras/Introjucer/Source/Application/jucer_CommandIDs.h b/extras/Introjucer/Source/Application/jucer_CommandIDs.h index a564d99f14..8177d07c75 100644 --- a/extras/Introjucer/Source/Application/jucer_CommandIDs.h +++ b/extras/Introjucer/Source/Application/jucer_CommandIDs.h @@ -32,11 +32,9 @@ namespace CommandIDs static const int open = 0x200020; static const int closeDocument = 0x200030; static const int saveDocument = 0x200040; - static const int saveDocumentAs = 0x200050; static const int closeProject = 0x200051; static const int saveProject = 0x200060; - static const int saveProjectAs = 0x200070; static const int openInIDE = 0x200072; static const int saveAndOpenInIDE = 0x200073; static const int showProjectSettings = 0x200074; diff --git a/extras/Introjucer/Source/Application/jucer_DocumentEditorComponent.cpp b/extras/Introjucer/Source/Application/jucer_DocumentEditorComponent.cpp index 49772d5246..23672245ca 100644 --- a/extras/Introjucer/Source/Application/jucer_DocumentEditorComponent.cpp +++ b/extras/Introjucer/Source/Application/jucer_DocumentEditorComponent.cpp @@ -55,81 +55,3 @@ void DocumentEditorComponent::documentAboutToClose (OpenDocumentManager::Documen jassertfalse } } - -ApplicationCommandTarget* DocumentEditorComponent::getNextCommandTarget() -{ - return findFirstTargetParentComponent(); -} - -void DocumentEditorComponent::getAllCommands (Array & commands) -{ - const CommandID ids[] = { CommandIDs::saveDocument, - CommandIDs::saveDocumentAs, - CommandIDs::closeDocument }; - - commands.addArray (ids, numElementsInArray (ids)); -} - -void DocumentEditorComponent::getCommandInfo (const CommandID commandID, ApplicationCommandInfo& result) -{ - result.setActive (document != nullptr); - String name; - - if (document != nullptr) - name = " '" + document->getName().substring (0, 32) + "'"; - - switch (commandID) - { - case CommandIDs::saveDocument: - result.setInfo ("Save" + name, - "Saves the current document", - CommandCategories::general, 0); - result.defaultKeypresses.add (KeyPress ('s', ModifierKeys::commandModifier, 0)); - break; - - case CommandIDs::saveDocumentAs: - result.setInfo ("Save" + name + " As...", - "Saves the current document to a different filename", - CommandCategories::general, 0); - result.setActive (document != nullptr && document->canSaveAs()); - result.defaultKeypresses.add (KeyPress ('s', ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0)); - break; - - case CommandIDs::closeDocument: - result.setInfo ("Close" + name, - "Closes the current document", - CommandCategories::general, 0); - #if JUCE_MAC - result.defaultKeypresses.add (KeyPress ('w', ModifierKeys::commandModifier | ModifierKeys::ctrlModifier, 0)); - #else - result.defaultKeypresses.add (KeyPress ('w', ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0)); - #endif - break; - - default: - break; - } -} - -bool DocumentEditorComponent::perform (const InvocationInfo& info) -{ - switch (info.commandID) - { - case CommandIDs::saveDocument: - document->save(); - return true; - - case CommandIDs::saveDocumentAs: - document->saveAs(); - return true; - - case CommandIDs::closeDocument: - OpenDocumentManager::getInstance()->closeDocument (document, true); - return true; - - default: - break; - } - - return false; -} diff --git a/extras/Introjucer/Source/Application/jucer_DocumentEditorComponent.h b/extras/Introjucer/Source/Application/jucer_DocumentEditorComponent.h index b396c663e9..14af39cfa0 100644 --- a/extras/Introjucer/Source/Application/jucer_DocumentEditorComponent.h +++ b/extras/Introjucer/Source/Application/jucer_DocumentEditorComponent.h @@ -33,7 +33,6 @@ /** */ class DocumentEditorComponent : public Component, - public ApplicationCommandTarget, public OpenDocumentManager::DocumentCloseListener { public: @@ -44,12 +43,6 @@ public: OpenDocumentManager::Document* getDocument() const { return document; } void documentAboutToClose (OpenDocumentManager::Document* document); - //============================================================================== - ApplicationCommandTarget* getNextCommandTarget(); - void getAllCommands (Array & commands); - void getCommandInfo (CommandID commandID, ApplicationCommandInfo& result); - bool perform (const InvocationInfo& info); - protected: OpenDocumentManager::Document* document; diff --git a/extras/Introjucer/Source/Application/jucer_MainWindow.cpp b/extras/Introjucer/Source/Application/jucer_MainWindow.cpp index 1402a837de..addd969f8c 100644 --- a/extras/Introjucer/Source/Application/jucer_MainWindow.cpp +++ b/extras/Introjucer/Source/Application/jucer_MainWindow.cpp @@ -51,14 +51,8 @@ MainWindow::MainWindow() centreWithSize (800, 600); // Register all the app commands.. - { - commandManager->registerAllCommandsForTarget (this); - commandManager->registerAllCommandsForTarget (getProjectContentComponent()); - - // use some temporary objects to harvest their commands.. - DocumentEditorComponent dec (nullptr); - commandManager->registerAllCommandsForTarget (&dec); - } + commandManager->registerAllCommandsForTarget (this); + commandManager->registerAllCommandsForTarget (getProjectContentComponent()); // update key mappings.. { diff --git a/extras/Introjucer/Source/Application/jucer_OpenDocumentManager.cpp b/extras/Introjucer/Source/Application/jucer_OpenDocumentManager.cpp index 27f95be7e3..a2883d77cd 100644 --- a/extras/Introjucer/Source/Application/jucer_OpenDocumentManager.cpp +++ b/extras/Introjucer/Source/Application/jucer_OpenDocumentManager.cpp @@ -56,8 +56,6 @@ public: Project* getProject() const { return project; } bool needsSaving() const { return false; } bool save() { return true; } - bool canSaveAs() const { return false; } - bool saveAs() { return false; } bool hasFileBeenModifiedExternally() { return fileModificationTime != file.getLastModificationTime(); } void reloadFromFile() { fileModificationTime = file.getLastModificationTime(); } String getName() const { return file.getFileName(); } diff --git a/extras/Introjucer/Source/Application/jucer_OpenDocumentManager.h b/extras/Introjucer/Source/Application/jucer_OpenDocumentManager.h index 06c3e6a789..9b1fd0c92e 100644 --- a/extras/Introjucer/Source/Application/jucer_OpenDocumentManager.h +++ b/extras/Introjucer/Source/Application/jucer_OpenDocumentManager.h @@ -57,8 +57,6 @@ public: virtual File getFile() const = 0; virtual bool needsSaving() const = 0; virtual bool save() = 0; - virtual bool canSaveAs() const = 0; - virtual bool saveAs() = 0; virtual bool hasFileBeenModifiedExternally() = 0; virtual void reloadFromFile() = 0; virtual Component* createEditor() = 0; @@ -144,7 +142,6 @@ public: bool isForNode (const ValueTree& node) const { return false; } bool refersToProject (Project& p) const { return project == &p; } Project* getProject() const { return project; } - bool canSaveAs() const { return true; } String getName() const { return getFile().getFileName(); } String getType() const { return getFile().getFileExtension() + " file"; } File getFile() const { return modDetector.getFile(); } @@ -178,12 +175,6 @@ public: return true; } - bool saveAs() - { - jassertfalse; //xxx todo - return false; - } - Component* createEditor(); Component* createViewer() { return createEditor(); } diff --git a/extras/Introjucer/Source/Project/jucer_ProjectContentComponent.cpp b/extras/Introjucer/Source/Project/jucer_ProjectContentComponent.cpp index 0f9d5e95bf..c9289e562f 100644 --- a/extras/Introjucer/Source/Project/jucer_ProjectContentComponent.cpp +++ b/extras/Introjucer/Source/Project/jucer_ProjectContentComponent.cpp @@ -215,19 +215,24 @@ ApplicationCommandTarget* ProjectContentComponent::getNextCommandTarget() void ProjectContentComponent::getAllCommands (Array & commands) { - const CommandID ids[] = { CommandIDs::saveProject, - CommandIDs::saveProjectAs, + const CommandID ids[] = { CommandIDs::saveDocument, + CommandIDs::closeDocument, + CommandIDs::saveProject, CommandIDs::closeProject, CommandIDs::openInIDE, CommandIDs::saveAndOpenInIDE, CommandIDs::showProjectSettings, - StandardApplicationCommandIDs::del}; + StandardApplicationCommandIDs::del }; commands.addArray (ids, numElementsInArray (ids)); } void ProjectContentComponent::getCommandInfo (const CommandID commandID, ApplicationCommandInfo& result) { + String documentName; + if (currentDocument != nullptr) + documentName = " '" + currentDocument->getName().substring (0, 32) + "'"; + switch (commandID) { case CommandIDs::saveProject: @@ -235,15 +240,6 @@ void ProjectContentComponent::getCommandInfo (const CommandID commandID, Applica "Saves the current project", CommandCategories::general, 0); result.setActive (project != nullptr); - result.defaultKeypresses.add (KeyPress ('s', ModifierKeys::commandModifier, 0)); - break; - - case CommandIDs::saveProjectAs: - result.setInfo ("Save Project As...", - "Saves the current project to a different filename", - CommandCategories::general, 0); - result.setActive (project != nullptr); - result.defaultKeypresses.add (KeyPress ('s', ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0)); break; case CommandIDs::closeProject: @@ -253,6 +249,26 @@ void ProjectContentComponent::getCommandInfo (const CommandID commandID, Applica result.setActive (project != nullptr); break; + case CommandIDs::saveDocument: + result.setInfo ("Save" + documentName, + "Saves the current document", + CommandCategories::general, 0); + result.setActive (currentDocument != nullptr || project != nullptr); + result.defaultKeypresses.add (KeyPress ('s', ModifierKeys::commandModifier, 0)); + break; + + case CommandIDs::closeDocument: + result.setInfo ("Close" + documentName, + "Closes the current document", + CommandCategories::general, 0); + result.setActive (currentDocument != nullptr); + #if JUCE_MAC + result.defaultKeypresses.add (KeyPress ('w', ModifierKeys::commandModifier | ModifierKeys::ctrlModifier, 0)); + #else + result.defaultKeypresses.add (KeyPress ('w', ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0)); + #endif + break; + case CommandIDs::openInIDE: #if JUCE_MAC result.setInfo ("Open in XCode...", @@ -310,36 +326,37 @@ bool ProjectContentComponent::perform (const InvocationInfo& info) switch (info.commandID) { case CommandIDs::saveProject: - if (project != nullptr) - { - if (! reinvokeCommandAfterClosingPropertyEditors (info)) - project->save (true, true); - } - - break; - - case CommandIDs::saveProjectAs: - if (project != nullptr) - { - if (! reinvokeCommandAfterClosingPropertyEditors (info)) - project->saveAsInteractive (true); - } + if (project != nullptr && ! reinvokeCommandAfterClosingPropertyEditors (info)) + project->save (true, true); break; case CommandIDs::closeProject: { - MainWindow* mw = findParentComponentOfClass(); + MainWindow* const mw = findParentComponentOfClass(); - if (mw != nullptr) - { - if (! reinvokeCommandAfterClosingPropertyEditors (info)) - mw->closeCurrentProject(); - } + if (mw != nullptr && ! reinvokeCommandAfterClosingPropertyEditors (info)) + mw->closeCurrentProject(); } break; + case CommandIDs::saveDocument: + if (! reinvokeCommandAfterClosingPropertyEditors (info)) + { + if (currentDocument != nullptr) + currentDocument->save(); + else if (project != nullptr) + project->save (true, true); + } + + break; + + case CommandIDs::closeDocument: + if (currentDocument != nullptr) + OpenDocumentManager::getInstance()->closeDocument (currentDocument, true); + break; + case CommandIDs::openInIDE: if (project != nullptr) { diff --git a/modules/juce_gui_basics/commands/juce_KeyPressMappingSet.cpp b/modules/juce_gui_basics/commands/juce_KeyPressMappingSet.cpp index 6671b1cc08..5fa892f5a5 100644 --- a/modules/juce_gui_basics/commands/juce_KeyPressMappingSet.cpp +++ b/modules/juce_gui_basics/commands/juce_KeyPressMappingSet.cpp @@ -273,8 +273,7 @@ XmlElement* KeyPressMappingSet::createXml (const bool saveDifferencesFromDefault doc->setAttribute ("basedOnDefaults", saveDifferencesFromDefaultSet); - int i; - for (i = 0; i < mappings.size(); ++i) + for (int i = 0; i < mappings.size(); ++i) { const CommandMapping* const cm = mappings.getUnchecked(i); @@ -294,7 +293,7 @@ XmlElement* KeyPressMappingSet::createXml (const bool saveDifferencesFromDefault if (defaultSet != nullptr) { - for (i = 0; i < defaultSet->mappings.size(); ++i) + for (int i = 0; i < defaultSet->mappings.size(); ++i) { const CommandMapping* const cm = defaultSet->mappings.getUnchecked(i);