From 127342e1478a91b33d8532e3b4ac7a56ce396734 Mon Sep 17 00:00:00 2001 From: jules Date: Sun, 4 Aug 2013 17:53:56 +0100 Subject: [PATCH] Introjucer: minor refactoring. --- .../Application/jucer_AppearanceSettings.cpp | 2 +- .../Source/Application/jucer_Application.h | 10 +++++++++- .../Source/Application/jucer_CommonHeaders.h | 3 --- .../Source/Application/jucer_MainWindow.cpp | 18 +++++++++--------- .../Application/jucer_OpenDocumentManager.cpp | 4 ++-- .../Code Editor/jucer_SourceCodeEditor.cpp | 7 ++++--- .../components/jucer_ComponentTypeHandler.cpp | 2 ++ .../ComponentEditor/jucer_JucerDocument.cpp | 6 +++--- .../paintelements/jucer_PaintElement.cpp | 3 +++ .../ui/jucer_ComponentLayoutEditor.cpp | 3 +++ .../ui/jucer_JucerDocumentEditor.cpp | 8 +++++--- .../ui/jucer_PaintRoutineEditor.cpp | 3 +++ .../Project/jucer_ProjectContentComponent.cpp | 14 ++++++++------ .../Source/Utility/jucer_MiscUtilities.cpp | 4 ++-- .../Source/Utility/jucer_StoredSettings.cpp | 2 +- 15 files changed, 55 insertions(+), 34 deletions(-) diff --git a/extras/Introjucer/Source/Application/jucer_AppearanceSettings.cpp b/extras/Introjucer/Source/Application/jucer_AppearanceSettings.cpp index 06c4726564..da2e6a7fd6 100644 --- a/extras/Introjucer/Source/Application/jucer_AppearanceSettings.cpp +++ b/extras/Introjucer/Source/Application/jucer_AppearanceSettings.cpp @@ -112,7 +112,7 @@ void AppearanceSettings::refreshPresetSchemeList() if (newSchemes != presetSchemeFiles) { presetSchemeFiles.swapWith (newSchemes); - commandManager->commandStatusChanged(); + IntrojucerApp::getCommandManager().commandStatusChanged(); } } diff --git a/extras/Introjucer/Source/Application/jucer_Application.h b/extras/Introjucer/Source/Application/jucer_Application.h index 3b9ddb47f2..4bace9c07f 100644 --- a/extras/Introjucer/Source/Application/jucer_Application.h +++ b/extras/Introjucer/Source/Application/jucer_Application.h @@ -170,13 +170,20 @@ public: return *app; } + static ApplicationCommandManager& getCommandManager() + { + ApplicationCommandManager* cm = IntrojucerApp::getApp().commandManager; + jassert (cm != nullptr); + return *cm; + } + //============================================================================== class MainMenuModel : public MenuBarModel { public: MainMenuModel() { - setApplicationCommandManagerToWatch (commandManager); + setApplicationCommandManagerToWatch (&getCommandManager()); } StringArray getMenuBarNames() @@ -582,6 +589,7 @@ public: MainWindowList mainWindowList; OpenDocumentManager openDocumentManager; + ScopedPointer commandManager; ScopedPointer appearanceEditorWindow, utf8Window; diff --git a/extras/Introjucer/Source/Application/jucer_CommonHeaders.h b/extras/Introjucer/Source/Application/jucer_CommonHeaders.h index 24758b0070..a300b722a9 100644 --- a/extras/Introjucer/Source/Application/jucer_CommonHeaders.h +++ b/extras/Introjucer/Source/Application/jucer_CommonHeaders.h @@ -36,9 +36,6 @@ #include "../Utility/jucer_PresetIDs.h" #include "jucer_CommandIDs.h" -//============================================================================== -extern ScopedPointer commandManager; - //============================================================================== const char* const projectItemDragType = "Project Items"; const char* const drawableItemDragType = "Drawable Items"; diff --git a/extras/Introjucer/Source/Application/jucer_MainWindow.cpp b/extras/Introjucer/Source/Application/jucer_MainWindow.cpp index 905fe84448..08b7f1649e 100644 --- a/extras/Introjucer/Source/Application/jucer_MainWindow.cpp +++ b/extras/Introjucer/Source/Application/jucer_MainWindow.cpp @@ -30,8 +30,6 @@ #include "../Project/jucer_NewProjectWizard.h" #include "../Utility/jucer_JucerTreeViewBase.h" -ScopedPointer commandManager; - //============================================================================== MainWindow::MainWindow() @@ -50,20 +48,22 @@ MainWindow::MainWindow() setResizable (true, false); centreWithSize (800, 600); + ApplicationCommandManager& commandManager = IntrojucerApp::getCommandManager(); + // Register all the app commands.. - commandManager->registerAllCommandsForTarget (this); - commandManager->registerAllCommandsForTarget (getProjectContentComponent()); + commandManager.registerAllCommandsForTarget (this); + commandManager.registerAllCommandsForTarget (getProjectContentComponent()); // update key mappings.. { - commandManager->getKeyMappings()->resetToDefaultMappings(); + commandManager.getKeyMappings()->resetToDefaultMappings(); ScopedPointer keys (getGlobalProperties().getXmlValue ("keyMappings")); if (keys != nullptr) - commandManager->getKeyMappings()->restoreFromXml (*keys); + commandManager.getKeyMappings()->restoreFromXml (*keys); - addKeyListener (commandManager->getKeyMappings()); + addKeyListener (commandManager.getKeyMappings()); } // don't want the window to take focus when the title-bar is clicked.. @@ -80,7 +80,7 @@ MainWindow::~MainWindow() setMenuBar (nullptr); #endif - removeKeyListener (commandManager->getKeyMappings()); + removeKeyListener (IntrojucerApp::getCommandManager().getKeyMappings()); // save the current size and position to our settings file.. getGlobalProperties().setValue ("lastMainWindowPos", getWindowStateAsString()); @@ -160,7 +160,7 @@ void MainWindow::setProject (Project* newProject) getProjectContentComponent()->setProject (newProject); currentProject = newProject; getProjectContentComponent()->updateMainWindowTitle(); - commandManager->commandStatusChanged(); + IntrojucerApp::getCommandManager().commandStatusChanged(); } void MainWindow::restoreWindowPosition() diff --git a/extras/Introjucer/Source/Application/jucer_OpenDocumentManager.cpp b/extras/Introjucer/Source/Application/jucer_OpenDocumentManager.cpp index 25a93b23ad..99214337c3 100644 --- a/extras/Introjucer/Source/Application/jucer_OpenDocumentManager.cpp +++ b/extras/Introjucer/Source/Application/jucer_OpenDocumentManager.cpp @@ -149,7 +149,7 @@ OpenDocumentManager::Document* OpenDocumentManager::openFile (Project* project, jassert (d != nullptr); // should always at least have been picked up by UnknownDocument documents.add (d); - commandManager->commandStatusChanged(); + IntrojucerApp::getCommandManager().commandStatusChanged(); return d; } @@ -199,7 +199,7 @@ bool OpenDocumentManager::closeDocument (int index, bool saveIfNeeded) listeners.getUnchecked(i)->documentAboutToClose (doc); documents.remove (index); - commandManager->commandStatusChanged(); + IntrojucerApp::getCommandManager().commandStatusChanged(); } return true; diff --git a/extras/Introjucer/Source/Code Editor/jucer_SourceCodeEditor.cpp b/extras/Introjucer/Source/Code Editor/jucer_SourceCodeEditor.cpp index 3ce061f5b3..8491e2e643 100644 --- a/extras/Introjucer/Source/Code Editor/jucer_SourceCodeEditor.cpp +++ b/extras/Introjucer/Source/Code Editor/jucer_SourceCodeEditor.cpp @@ -23,6 +23,7 @@ */ #include "jucer_SourceCodeEditor.h" +#include "../Application/jucer_Application.h" #include "../Application/jucer_OpenDocumentManager.h" @@ -208,7 +209,7 @@ GenericCodeEditorComponent::GenericCodeEditorComponent (const File& f, CodeDocum CodeTokeniser* tokeniser) : CodeEditorComponent (codeDocument, tokeniser), file (f) { - setCommandManager (commandManager); + setCommandManager (&IntrojucerApp::getCommandManager()); } GenericCodeEditorComponent::~GenericCodeEditorComponent() {} @@ -381,7 +382,7 @@ public: void textEditorReturnKeyPressed (TextEditor&) override { - commandManager->invokeDirectly (CommandIDs::findNext, true); + IntrojucerApp::getCommandManager().invokeDirectly (CommandIDs::findNext, true); } void textEditorEscapeKeyPressed (TextEditor&) override @@ -417,7 +418,7 @@ void GenericCodeEditorComponent::showFindPanel() if (findPanel == nullptr) { findPanel = new FindPanel(); - findPanel->setCommandManager (commandManager); + findPanel->setCommandManager (&IntrojucerApp::getCommandManager()); addAndMakeVisible (findPanel); resized(); diff --git a/extras/Introjucer/Source/ComponentEditor/components/jucer_ComponentTypeHandler.cpp b/extras/Introjucer/Source/ComponentEditor/components/jucer_ComponentTypeHandler.cpp index 3291f52316..2fba91b077 100644 --- a/extras/Introjucer/Source/ComponentEditor/components/jucer_ComponentTypeHandler.cpp +++ b/extras/Introjucer/Source/ComponentEditor/components/jucer_ComponentTypeHandler.cpp @@ -78,6 +78,8 @@ void ComponentTypeHandler::showPopupMenu (Component*, ComponentLayout&) { PopupMenu m; + ApplicationCommandManager* commandManager = &IntrojucerApp::getCommandManager(); + m.addCommandItem (commandManager, JucerCommandIDs::toFront); m.addCommandItem (commandManager, JucerCommandIDs::toBack); m.addSeparator(); diff --git a/extras/Introjucer/Source/ComponentEditor/jucer_JucerDocument.cpp b/extras/Introjucer/Source/ComponentEditor/jucer_JucerDocument.cpp index b3ebd8afe1..bf93dfe528 100644 --- a/extras/Introjucer/Source/ComponentEditor/jucer_JucerDocument.cpp +++ b/extras/Introjucer/Source/ComponentEditor/jucer_JucerDocument.cpp @@ -52,21 +52,21 @@ JucerDocument::JucerDocument (SourceCodeDocument* c) jassert (cpp != nullptr); resources.setDocument (this); - commandManager->commandStatusChanged(); + IntrojucerApp::getCommandManager().commandStatusChanged(); cpp->getCodeDocument().addListener (this); } JucerDocument::~JucerDocument() { cpp->getCodeDocument().removeListener (this); - commandManager->commandStatusChanged(); + IntrojucerApp::getCommandManager().commandStatusChanged(); } //============================================================================== void JucerDocument::changed() { sendChangeMessage(); - commandManager->commandStatusChanged(); + IntrojucerApp::getCommandManager().commandStatusChanged(); startTimer (800); } diff --git a/extras/Introjucer/Source/ComponentEditor/paintelements/jucer_PaintElement.cpp b/extras/Introjucer/Source/ComponentEditor/paintelements/jucer_PaintElement.cpp index 77010397c6..2a8656e47a 100644 --- a/extras/Introjucer/Source/ComponentEditor/paintelements/jucer_PaintElement.cpp +++ b/extras/Introjucer/Source/ComponentEditor/paintelements/jucer_PaintElement.cpp @@ -23,6 +23,7 @@ */ #include "../../jucer_Headers.h" +#include "../../Application/jucer_Application.h" #include "../jucer_PaintRoutine.h" #include "../jucer_UtilityFunctions.h" #include "../ui/jucer_JucerCommandIDs.h" @@ -462,6 +463,8 @@ void PaintElement::updateSiblingComps() void PaintElement::showPopupMenu() { + ApplicationCommandManager* commandManager = &IntrojucerApp::getCommandManager(); + PopupMenu m; m.addCommandItem (commandManager, JucerCommandIDs::toFront); diff --git a/extras/Introjucer/Source/ComponentEditor/ui/jucer_ComponentLayoutEditor.cpp b/extras/Introjucer/Source/ComponentEditor/ui/jucer_ComponentLayoutEditor.cpp index 59223e70ee..b728fb828c 100644 --- a/extras/Introjucer/Source/ComponentEditor/ui/jucer_ComponentLayoutEditor.cpp +++ b/extras/Introjucer/Source/ComponentEditor/ui/jucer_ComponentLayoutEditor.cpp @@ -23,6 +23,7 @@ */ #include "../../jucer_Headers.h" +#include "../../Application/jucer_Application.h" #include "jucer_ComponentLayoutEditor.h" #include "../ui/jucer_JucerCommandIDs.h" #include "../jucer_ObjectTypes.h" @@ -266,6 +267,8 @@ void ComponentLayoutEditor::mouseDown (const MouseEvent& e) { if (e.mods.isPopupMenu()) { + ApplicationCommandManager* commandManager = &IntrojucerApp::getCommandManager(); + PopupMenu m; m.addCommandItem (commandManager, JucerCommandIDs::editCompLayout); diff --git a/extras/Introjucer/Source/ComponentEditor/ui/jucer_JucerDocumentEditor.cpp b/extras/Introjucer/Source/ComponentEditor/ui/jucer_JucerDocumentEditor.cpp index af0e2f54a3..125dcd77a1 100644 --- a/extras/Introjucer/Source/ComponentEditor/ui/jucer_JucerDocumentEditor.cpp +++ b/extras/Introjucer/Source/ComponentEditor/ui/jucer_JucerDocumentEditor.cpp @@ -1075,7 +1075,7 @@ bool JucerDocumentEditor::keyPressed (const KeyPress& key) { if (key.isKeyCode (KeyPress::deleteKey) || key.isKeyCode (KeyPress::backspaceKey)) { - commandManager->invokeDirectly (StandardApplicationCommandIDs::del, true); + IntrojucerApp::getCommandManager().invokeDirectly (StandardApplicationCommandIDs::del, true); return true; } @@ -1085,7 +1085,7 @@ bool JucerDocumentEditor::keyPressed (const KeyPress& key) JucerDocumentEditor* JucerDocumentEditor::getActiveDocumentHolder() { ApplicationCommandInfo info (0); - ApplicationCommandTarget* target = commandManager->getTargetForCommand (JucerCommandIDs::editCompLayout, info); + ApplicationCommandTarget* target = IntrojucerApp::getCommandManager().getTargetForCommand (JucerCommandIDs::editCompLayout, info); return dynamic_cast (target); } @@ -1103,6 +1103,8 @@ const int snapSizes[] = { 2, 3, 4, 5, 6, 8, 10, 12, 16, 20, 24, 32 }; void createGUIEditorMenu (PopupMenu& menu) { + ApplicationCommandManager* commandManager = &IntrojucerApp::getCommandManager(); + menu.addCommandItem (commandManager, JucerCommandIDs::editCompLayout); menu.addCommandItem (commandManager, JucerCommandIDs::editCompGraphics); menu.addSeparator(); @@ -1190,5 +1192,5 @@ void handleGUIEditorMenuCommand (int menuItemID) void registerGUIEditorCommands() { JucerDocumentEditor dh (nullptr); - commandManager->registerAllCommandsForTarget (&dh); + IntrojucerApp::getCommandManager().registerAllCommandsForTarget (&dh); } diff --git a/extras/Introjucer/Source/ComponentEditor/ui/jucer_PaintRoutineEditor.cpp b/extras/Introjucer/Source/ComponentEditor/ui/jucer_PaintRoutineEditor.cpp index f0a80d018e..2deb6a5f89 100644 --- a/extras/Introjucer/Source/ComponentEditor/ui/jucer_PaintRoutineEditor.cpp +++ b/extras/Introjucer/Source/ComponentEditor/ui/jucer_PaintRoutineEditor.cpp @@ -23,6 +23,7 @@ */ #include "../../jucer_Headers.h" +#include "../../Application/jucer_Application.h" #include "../ui/jucer_JucerCommandIDs.h" #include "jucer_PaintRoutineEditor.h" #include "../jucer_ObjectTypes.h" @@ -200,6 +201,8 @@ void PaintRoutineEditor::mouseDown (const MouseEvent& e) { if (e.mods.isPopupMenu()) { + ApplicationCommandManager* commandManager = &IntrojucerApp::getCommandManager(); + PopupMenu m; m.addCommandItem (commandManager, JucerCommandIDs::editCompLayout); diff --git a/extras/Introjucer/Source/Project/jucer_ProjectContentComponent.cpp b/extras/Introjucer/Source/Project/jucer_ProjectContentComponent.cpp index 4184630bfd..3274231a9e 100644 --- a/extras/Introjucer/Source/Project/jucer_ProjectContentComponent.cpp +++ b/extras/Introjucer/Source/Project/jucer_ProjectContentComponent.cpp @@ -57,14 +57,16 @@ public: tree.getRootItem()->setSelected (true, true); #if JUCE_MAC || JUCE_WINDOWS + ApplicationCommandManager& commandManager = IntrojucerApp::getCommandManager(); + addAndMakeVisible (&openProjectButton); - openProjectButton.setCommandToTrigger (commandManager, CommandIDs::openInIDE, true); - openProjectButton.setButtonText (commandManager->getNameOfCommand (CommandIDs::openInIDE)); + openProjectButton.setCommandToTrigger (&commandManager, CommandIDs::openInIDE, true); + openProjectButton.setButtonText (commandManager.getNameOfCommand (CommandIDs::openInIDE)); openProjectButton.setColour (TextButton::buttonColourId, Colours::white.withAlpha (0.5f)); addAndMakeVisible (&saveAndOpenButton); - saveAndOpenButton.setCommandToTrigger (commandManager, CommandIDs::saveAndOpenInIDE, true); - saveAndOpenButton.setButtonText (commandManager->getNameOfCommand (CommandIDs::saveAndOpenInIDE)); + saveAndOpenButton.setCommandToTrigger (&commandManager, CommandIDs::saveAndOpenInIDE, true); + saveAndOpenButton.setButtonText (commandManager.getNameOfCommand (CommandIDs::saveAndOpenInIDE)); saveAndOpenButton.setColour (TextButton::buttonColourId, Colours::white.withAlpha (0.5f)); #endif } @@ -374,7 +376,7 @@ void ProjectContentComponent::hideEditor() currentDocument = nullptr; contentView = nullptr; updateMainWindowTitle(); - commandManager->commandStatusChanged(); + IntrojucerApp::getCommandManager().commandStatusChanged(); resized(); } @@ -401,7 +403,7 @@ bool ProjectContentComponent::setEditorComponent (Component* editor, resized(); updateMainWindowTitle(); - commandManager->commandStatusChanged(); + IntrojucerApp::getCommandManager().commandStatusChanged(); return true; } diff --git a/extras/Introjucer/Source/Utility/jucer_MiscUtilities.cpp b/extras/Introjucer/Source/Utility/jucer_MiscUtilities.cpp index 92f7e55bdb..79ff1ff5aa 100644 --- a/extras/Introjucer/Source/Utility/jucer_MiscUtilities.cpp +++ b/extras/Introjucer/Source/Utility/jucer_MiscUtilities.cpp @@ -23,7 +23,7 @@ */ #include "../jucer_Headers.h" - +#include "../Application/jucer_Application.h" //============================================================================== String createAlphaNumericUID() @@ -403,7 +403,7 @@ public: void timerCallback() override { stopTimer(); - commandManager->invoke (info, true); + IntrojucerApp::getCommandManager().invoke (info, true); delete this; } diff --git a/extras/Introjucer/Source/Utility/jucer_StoredSettings.cpp b/extras/Introjucer/Source/Utility/jucer_StoredSettings.cpp index 9d14378df7..e95cb27062 100644 --- a/extras/Introjucer/Source/Utility/jucer_StoredSettings.cpp +++ b/extras/Introjucer/Source/Utility/jucer_StoredSettings.cpp @@ -89,7 +89,7 @@ void StoredSettings::updateGlobalProps() props.removeValue ("keyMappings"); - if (commandManager != nullptr) + if (ApplicationCommandManager* commandManager = IntrojucerApp::getApp().commandManager) { const ScopedPointer keys (commandManager->getKeyMappings()->createXml (true));