From d3cf0870d9bdf63dae0f77263a5cf183d06afc7b Mon Sep 17 00:00:00 2001 From: Julian Storer Date: Mon, 21 Jun 2010 17:34:27 +0100 Subject: [PATCH] Made the new jucer support multiple windows. --- .../Source/Application/jucer_Application.h | 380 +++++++++++++++++- .../Source/Application/jucer_CommandIDs.h | 8 + .../Source/Application/jucer_MainWindow.cpp | 280 ++----------- .../Source/Application/jucer_MainWindow.h | 21 +- .../Project/jucer_ProjectContentComponent.cpp | 8 +- .../Source/Utility/jucer_StoredSettings.cpp | 19 +- .../Source/Utility/jucer_StoredSettings.h | 4 +- juce_amalgamated.h | 2 +- src/core/juce_StandardHeader.h | 2 +- 9 files changed, 449 insertions(+), 275 deletions(-) diff --git a/extras/Jucer (experimental)/Source/Application/jucer_Application.h b/extras/Jucer (experimental)/Source/Application/jucer_Application.h index f39a428666..534169f963 100644 --- a/extras/Jucer (experimental)/Source/Application/jucer_Application.h +++ b/extras/Jucer (experimental)/Source/Application/jucer_Application.h @@ -28,8 +28,7 @@ #include "../jucer_Headers.h" #include "jucer_MainWindow.h" - -ApplicationCommandManager* commandManager = 0; +#include "../Project/jucer_NewProjectWizard.h" //============================================================================== @@ -57,22 +56,41 @@ public: commandManager = new ApplicationCommandManager(); commandManager->registerAllCommandsForTarget (this); - theMainWindow = new MainWindow(); + menuModel = new MainMenuModel(); + + MainWindow* main = createNewMainWindow (false); doExtraInitialisation(); ImageCache::setCacheTimeout (30 * 1000); if (commandLine.trim().isNotEmpty() && ! commandLine.trim().startsWithChar ('-')) + { anotherInstanceStarted (commandLine); + } + else + { + Array projects (StoredSettings::getInstance()->getLastProjects()); - theMainWindow->reloadLastProject(); + for (int i = 0; i < projects.size(); ++ i) + openFile (projects.getReference(i)); + } + +#if JUCE_MAC + MenuBarModel::setMacMainMenu (menuModel); +#endif - theMainWindow->getLookAndFeel().setColour (ColourSelector::backgroundColourId, Colours::transparentBlack); + main->setVisible (true); } void shutdown() { - theMainWindow = 0; +#if JUCE_MAC + MenuBarModel::setMacMainMenu (0); +#endif + menuModel = 0; + + StoredSettings::deleteInstance(); + mainWindows.clear(); OpenDocumentManager::deleteInstance(); deleteAndZero (commandManager); @@ -81,13 +99,28 @@ public: //============================================================================== void systemRequestedQuit() { - if (theMainWindow == 0 || theMainWindow->closeCurrentProject()) + while (mainWindows.size() > 0) { - theMainWindow = 0; - StoredSettings::deleteInstance(); + if (! mainWindows[0]->closeCurrentProject()) + return; - quit(); + mainWindows.remove (0); } + + quit(); + } + + void closeWindow (MainWindow* w) + { + jassert (mainWindows.contains (w)); + mainWindows.removeObject (w); + +#if ! JUCE_MAC + if (mainWindows.size() == 0) + systemRequestedQuit(); +#endif + + updateRecentProjectList(); } //============================================================================== @@ -112,14 +145,335 @@ public: void anotherInstanceStarted (const String& commandLine) { - if (theMainWindow != 0) - theMainWindow->openFile (commandLine.unquoted()); + openFile (commandLine.unquoted()); } virtual void doExtraInitialisation() {} + //============================================================================== + class MainMenuModel : public MenuBarModel + { + public: + MainMenuModel() + { + setApplicationCommandManagerToWatch (commandManager); + } + + const StringArray getMenuBarNames() + { + const char* const names[] = { "File", "Edit", "View", "Window", 0 }; + return StringArray ((const char**) names); + } + + const PopupMenu getMenuForIndex (int topLevelMenuIndex, const String& menuName) + { + PopupMenu menu; + + if (topLevelMenuIndex == 0) // "File" menu + { + menu.addCommandItem (commandManager, CommandIDs::newProject); + menu.addSeparator(); + menu.addCommandItem (commandManager, CommandIDs::open); + + PopupMenu recentFiles; + StoredSettings::getInstance()->recentFiles.createPopupMenuItems (recentFiles, 100, true, true); + menu.addSubMenu ("Open recent file", recentFiles); + + 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::openProjectInIDE); + + #if ! JUCE_MAC + menu.addSeparator(); + menu.addCommandItem (commandManager, StandardApplicationCommandIDs::quit); + #endif + } + else if (topLevelMenuIndex == 1) // "Edit" menu + { + menu.addCommandItem (commandManager, CommandIDs::undo); + menu.addCommandItem (commandManager, CommandIDs::redo); + menu.addSeparator(); + menu.addCommandItem (commandManager, StandardApplicationCommandIDs::cut); + menu.addCommandItem (commandManager, StandardApplicationCommandIDs::copy); + menu.addCommandItem (commandManager, StandardApplicationCommandIDs::paste); + menu.addCommandItem (commandManager, StandardApplicationCommandIDs::del); + menu.addCommandItem (commandManager, StandardApplicationCommandIDs::selectAll); + menu.addCommandItem (commandManager, StandardApplicationCommandIDs::deselectAll); + menu.addSeparator(); + menu.addCommandItem (commandManager, CommandIDs::toFront); + menu.addCommandItem (commandManager, CommandIDs::toBack); + menu.addSeparator(); + menu.addCommandItem (commandManager, CommandIDs::group); + menu.addCommandItem (commandManager, CommandIDs::ungroup); + menu.addSeparator(); + menu.addCommandItem (commandManager, CommandIDs::bringBackLostItems); + } + else if (topLevelMenuIndex == 2) // "View" menu + { + menu.addCommandItem (commandManager, CommandIDs::showProjectSettings); + menu.addSeparator(); + + menu.addCommandItem (commandManager, CommandIDs::test); + menu.addSeparator(); + + menu.addCommandItem (commandManager, CommandIDs::showGrid); + menu.addCommandItem (commandManager, CommandIDs::enableSnapToGrid); + + menu.addSeparator(); + menu.addCommandItem (commandManager, CommandIDs::zoomIn); + menu.addCommandItem (commandManager, CommandIDs::zoomOut); + menu.addCommandItem (commandManager, CommandIDs::zoomNormal); + + menu.addSeparator(); + menu.addCommandItem (commandManager, CommandIDs::useTabbedWindows); + } + else if (topLevelMenuIndex == 3) // "Window" menu + { + menu.addCommandItem (commandManager, CommandIDs::closeWindow); + menu.addSeparator(); + + const int numDocs = jmin (50, OpenDocumentManager::getInstance()->getNumOpenDocuments()); + + for (int i = 0; i < numDocs; ++i) + { + OpenDocumentManager::Document* doc = OpenDocumentManager::getInstance()->getOpenDocument(i); + + menu.addItem (300 + i, doc->getName()); + } + + menu.addSeparator(); + menu.addCommandItem (commandManager, CommandIDs::closeAllDocuments); + } + + return menu; + } + + void menuItemSelected (int menuItemID, int topLevelMenuIndex) + { + if (menuItemID >= 100 && menuItemID < 200) + { + // open a file from the "recent files" menu + const File file (StoredSettings::getInstance()->recentFiles.getFile (menuItemID - 100)); + + getApp()->openFile (file); + } + else if (menuItemID >= 300 && menuItemID < 400) + { + OpenDocumentManager::Document* doc = OpenDocumentManager::getInstance()->getOpenDocument (menuItemID - 300); + getApp()->getOrCreateFrontmostWindow (true)->getProjectContentComponent()->showDocument (doc); + } + } + + private: + JucerApplication* getApp() const + { + return static_cast (JUCEApplication::getInstance()); + } + }; + + //============================================================================== + void getAllCommands (Array & commands) + { + JUCEApplication::getAllCommands (commands); + + const CommandID ids[] = { CommandIDs::newProject, + CommandIDs::open, + CommandIDs::showPrefs, + CommandIDs::closeAllDocuments, + CommandIDs::saveAll }; + + commands.addArray (ids, numElementsInArray (ids)); + } + + void getCommandInfo (const CommandID commandID, ApplicationCommandInfo& result) + { + switch (commandID) + { + case CommandIDs::newProject: + result.setInfo ("New Project...", "Creates a new Jucer project", CommandCategories::general, 0); + result.defaultKeypresses.add (KeyPress ('o', ModifierKeys::commandModifier, 0)); + break; + + case CommandIDs::open: + result.setInfo ("Open...", "Opens a Jucer project", CommandCategories::general, 0); + result.defaultKeypresses.add (KeyPress ('o', ModifierKeys::commandModifier, 0)); + break; + + case CommandIDs::showPrefs: + result.setInfo ("Preferences...", "Shows the preferences panel.", CommandCategories::general, 0); + result.defaultKeypresses.add (KeyPress (',', ModifierKeys::commandModifier, 0)); + break; + + case CommandIDs::closeAllDocuments: + result.setInfo ("Close All Documents", "Closes all open documents", CommandCategories::general, 0); + result.setActive (OpenDocumentManager::getInstance()->getNumOpenDocuments() > 0); + break; + + case CommandIDs::saveAll: + result.setInfo ("Save All", "Saves all open documents", CommandCategories::general, 0); + result.setActive (OpenDocumentManager::getInstance()->anyFilesNeedSaving()); + break; + + default: + JUCEApplication::getCommandInfo (commandID, result); + break; + } + } + + bool perform (const InvocationInfo& info) + { + switch (info.commandID) + { + case CommandIDs::newProject: createNewProject(); break; + case CommandIDs::open: askUserToOpenFile(); break; + case CommandIDs::showPrefs: showPrefsPanel(); break; + case CommandIDs::saveAll: OpenDocumentManager::getInstance()->saveAll(); break; + case CommandIDs::closeAllDocuments: closeAllDocuments (true); break; + default: return JUCEApplication::perform (info); + } + + return true; + } + + //============================================================================== + void showPrefsPanel() + { + jassertfalse; + } + + void createNewProject() + { + MainWindow* mw = createNewMainWindow (false); + ScopedPointer newProj (NewProjectWizard::runNewProjectWizard (mw)); + + if (newProj != 0) + mw->setProject (newProj.release()); + else + closeWindow (mw); + + mw->setVisible (true); + } + + void askUserToOpenFile() + { + FileChooser fc ("Open File"); + + if (fc.browseForFileToOpen()) + openFile (fc.getResult()); + } + + bool openFile (const File& file) + { + if (file.hasFileExtension (Project::projectFileExtension)) + { + ScopedPointer newDoc (new Project (file)); + + if (file == File::nonexistent ? newDoc->loadFromUserSpecifiedFile (true) + : newDoc->loadFrom (file, true)) + { + MainWindow* w = getOrCreateEmptyWindow (false); + w->setProject (newDoc.release()); + w->restoreWindowPosition(); + w->setVisible (true); + return true; + } + } + else if (file.exists()) + { + return getOrCreateFrontmostWindow (true)->openFile (file); + } + + return false; + } + + bool closeAllDocuments (bool askUserToSave) + { + for (int i = OpenDocumentManager::getInstance()->getNumOpenDocuments(); --i >= 0;) + { + OpenDocumentManager::Document* doc = OpenDocumentManager::getInstance()->getOpenDocument (i); + + for (int j = mainWindows.size(); --j >= 0;) + mainWindows.getUnchecked(j)->getProjectContentComponent()->hideDocument (doc); + + if (! OpenDocumentManager::getInstance()->closeDocument (i, askUserToSave)) + return false; + } + + return true; + } + + void updateRecentProjectList() + { + Array projects; + + for (int i = 0; i < mainWindows.size(); ++i) + { + MainWindow* mw = mainWindows[i]; + + if (mw != 0 && mw->getProject() != 0) + projects.add (mw->getProject()->getFile()); + } + + StoredSettings::getInstance()->setLastProjects (projects); + } + private: - ScopedPointer theMainWindow; + OwnedArray mainWindows; + ScopedPointer menuModel; + + MainWindow* createNewMainWindow (bool makeVisible) + { + MainWindow* mw = new MainWindow(); + + for (int i = mainWindows.size(); --i >= 0;) + if (mw->getBounds() == mainWindows.getUnchecked(i)->getBounds()) + mw->setBounds (mw->getBounds().translated (20, 20)); + + mainWindows.add (mw); + + if (makeVisible) + mw->setVisible (true); + + mw->restoreWindowPosition(); + return mw; + } + + MainWindow* getOrCreateFrontmostWindow (bool makeVisible) + { + if (mainWindows.size() == 0) + return createNewMainWindow (makeVisible); + + for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;) + { + MainWindow* mw = dynamic_cast (Desktop::getInstance().getComponent (i)); + if (mainWindows.contains (mw)) + return mw; + } + + return mainWindows.getLast(); + } + + MainWindow* getOrCreateEmptyWindow (bool makeVisible) + { + if (mainWindows.size() == 0) + return createNewMainWindow (makeVisible); + + for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;) + { + MainWindow* mw = dynamic_cast (Desktop::getInstance().getComponent (i)); + if (mainWindows.contains (mw) && mw->getProject() == 0) + return mw; + } + + return createNewMainWindow (makeVisible); + } }; diff --git a/extras/Jucer (experimental)/Source/Application/jucer_CommandIDs.h b/extras/Jucer (experimental)/Source/Application/jucer_CommandIDs.h index 63ab660e41..a74b834af2 100644 --- a/extras/Jucer (experimental)/Source/Application/jucer_CommandIDs.h +++ b/extras/Jucer (experimental)/Source/Application/jucer_CommandIDs.h @@ -44,6 +44,7 @@ namespace CommandIDs static const int undo = 0x200090; static const int redo = 0x2000a0; + static const int closeWindow = 0x201001; static const int closeAllDocuments = 0x201000; static const int test = 0x202090; @@ -54,6 +55,13 @@ namespace CommandIDs static const int showOrHideMarkers = 0x2030b2; static const int toggleSnapping = 0x2030b3; + static const int makeLineSegment = 0x2030c0; + static const int makeCubicSegment = 0x2030c1; + static const int breakSegment = 0x2030c2; + static const int pointModeCorner = 0x2030c3; + static const int pointModeRounded = 0x2030c4; + static const int pointModeSymmetric = 0x2030c5; + static const int group = 0x202170; static const int ungroup = 0x202180; diff --git a/extras/Jucer (experimental)/Source/Application/jucer_MainWindow.cpp b/extras/Jucer (experimental)/Source/Application/jucer_MainWindow.cpp index a3141fb458..4883e036bc 100644 --- a/extras/Jucer (experimental)/Source/Application/jucer_MainWindow.cpp +++ b/extras/Jucer (experimental)/Source/Application/jucer_MainWindow.cpp @@ -24,11 +24,14 @@ */ #include "../jucer_Headers.h" +#include "jucer_Application.h" #include "jucer_MainWindow.h" #include "jucer_OpenDocumentManager.h" #include "../Code Editor/jucer_SourceCodeEditor.h" #include "../Project/jucer_NewProjectWizard.h" +ApplicationCommandManager* commandManager = 0; + //============================================================================== MainWindow::MainWindow() @@ -39,22 +42,15 @@ MainWindow::MainWindow() setUsingNativeTitleBar (true); setContentComponent (new ProjectContentComponent()); - setApplicationCommandManagerToWatch (commandManager); - -#if JUCE_MAC - setMacMainMenu (this); -#else - setMenuBar (this); +#if ! JUCE_MAC + JucerApplication* app = static_cast (JUCEApplication::getInstance()); + setMenuBar (app); #endif setResizable (true, false); centreWithSize (700, 600); - // restore the last size and position from our settings file.. - restoreWindowStateFromString (StoredSettings::getInstance()->getProps() - .getValue ("lastMainWindowPos")); - // Register all the app commands.. { commandManager->registerAllCommandsForTarget (this); @@ -80,15 +76,12 @@ MainWindow::MainWindow() setWantsKeyboardFocus (false); //getPeer()->setCurrentRenderingEngine (0); - - setVisible (true); + getLookAndFeel().setColour (ColourSelector::backgroundColourId, Colours::transparentBlack); } MainWindow::~MainWindow() { -#if JUCE_MAC - setMacMainMenu (0); -#else +#if ! JUCE_MAC setMenuBar (0); #endif @@ -109,7 +102,11 @@ ProjectContentComponent* MainWindow::getProjectContentComponent() const void MainWindow::closeButtonPressed() { - JUCEApplication::getInstance()->systemRequestedQuit(); + if (! closeCurrentProject()) + return; + + JucerApplication* jucer = static_cast (JUCEApplication::getInstance()); + jucer->closeWindow (this); } bool MainWindow::closeProject (Project* project) @@ -119,6 +116,9 @@ bool MainWindow::closeProject (Project* project) if (project == 0) return true; + StoredSettings::getInstance()->getProps() + .setValue (getProjectWindowPosName(), getWindowStateAsString()); + if (! OpenDocumentManager::getInstance()->closeAllDocumentsUsingProject (*project, true)) return false; @@ -138,41 +138,29 @@ bool MainWindow::closeCurrentProject() return currentProject == 0 || closeProject (currentProject); } -bool MainWindow::closeAllDocuments (bool askUserToSave) -{ - for (int i = OpenDocumentManager::getInstance()->getNumOpenDocuments(); --i >= 0;) - { - OpenDocumentManager::Document* doc = OpenDocumentManager::getInstance()->getOpenDocument (i); - getProjectContentComponent()->hideDocument (doc); - - if (! OpenDocumentManager::getInstance()->closeDocument (i, askUserToSave)) - return false; - } - - return true; -} - void MainWindow::setProject (Project* newProject) { - if (newProject != 0) - StoredSettings::getInstance()->setLastProject (newProject->getFile()); - getProjectContentComponent()->setProject (newProject); currentProject = newProject; commandManager->commandStatusChanged(); -} -void MainWindow::reloadLastProject() -{ - openFile (StoredSettings::getInstance()->getLastProject()); + // (mustn't do this when the project is 0, because that'll happen on shutdown, + // which will erase the list of recent projects) + if (newProject != 0) + static_cast (JUCEApplication::getInstance())->updateRecentProjectList(); } -void MainWindow::askUserToOpenFile() +void MainWindow::restoreWindowPosition() { - FileChooser fc ("Open File"); + String windowState; + + if (currentProject != 0) + windowState = StoredSettings::getInstance()->getProps().getValue (getProjectWindowPosName()); + + if (windowState.isEmpty()) + windowState = StoredSettings::getInstance()->getProps().getValue ("lastMainWindowPos"); - if (fc.browseForFileToOpen()) - openFile (fc.getResult()); + restoreWindowStateFromString (windowState); } bool MainWindow::canOpenFile (const File& file) const @@ -205,14 +193,6 @@ bool MainWindow::openFile (const File& file) return false; } -void MainWindow::createNewProject() -{ - ScopedPointer newProj (NewProjectWizard::runNewProjectWizard (this)); - - if (newProj != 0 && closeCurrentProject()) - setProject (newProj.release()); -} - bool MainWindow::isInterestedInFileDrag (const StringArray& filenames) { for (int i = filenames.size(); --i >= 0;) @@ -252,140 +232,6 @@ void MainWindow::updateTitle (const String& documentName) setName (name); } -//============================================================================== -const StringArray MainWindow::getMenuBarNames() -{ - const char* const names[] = { "File", "Edit", "View", "Window", 0 }; - return StringArray ((const char**) names); -} - -const PopupMenu MainWindow::getMenuForIndex (int topLevelMenuIndex, - const String& menuName) -{ - PopupMenu menu; - - if (topLevelMenuIndex == 0) - { - // "File" menu - - menu.addCommandItem (commandManager, CommandIDs::newProject); - menu.addSeparator(); - menu.addCommandItem (commandManager, CommandIDs::open); - - PopupMenu recentFiles; - StoredSettings::getInstance()->recentFiles.createPopupMenuItems (recentFiles, 100, true, true); - menu.addSubMenu ("Open recent file", recentFiles); - - 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::openProjectInIDE); - -#if ! JUCE_MAC - menu.addSeparator(); - menu.addCommandItem (commandManager, StandardApplicationCommandIDs::quit); -#endif - } - else if (topLevelMenuIndex == 1) - { - // "Edit" menu - - menu.addCommandItem (commandManager, CommandIDs::undo); - menu.addCommandItem (commandManager, CommandIDs::redo); - menu.addSeparator(); - menu.addCommandItem (commandManager, StandardApplicationCommandIDs::cut); - menu.addCommandItem (commandManager, StandardApplicationCommandIDs::copy); - menu.addCommandItem (commandManager, StandardApplicationCommandIDs::paste); - menu.addCommandItem (commandManager, StandardApplicationCommandIDs::del); - menu.addCommandItem (commandManager, StandardApplicationCommandIDs::selectAll); - menu.addCommandItem (commandManager, StandardApplicationCommandIDs::deselectAll); - menu.addSeparator(); - menu.addCommandItem (commandManager, CommandIDs::toFront); - menu.addCommandItem (commandManager, CommandIDs::toBack); - menu.addSeparator(); - menu.addCommandItem (commandManager, CommandIDs::group); - menu.addCommandItem (commandManager, CommandIDs::ungroup); - menu.addSeparator(); - menu.addCommandItem (commandManager, CommandIDs::bringBackLostItems); - } - else if (topLevelMenuIndex == 2) - { - // "View" menu - - menu.addCommandItem (commandManager, CommandIDs::showProjectSettings); - menu.addSeparator(); - - menu.addCommandItem (commandManager, CommandIDs::test); - menu.addSeparator(); - - menu.addCommandItem (commandManager, CommandIDs::showGrid); - menu.addCommandItem (commandManager, CommandIDs::enableSnapToGrid); - - menu.addSeparator(); - menu.addCommandItem (commandManager, CommandIDs::zoomIn); - menu.addCommandItem (commandManager, CommandIDs::zoomOut); - menu.addCommandItem (commandManager, CommandIDs::zoomNormal); - -/* menu.addSeparator(); - PopupMenu overlays; - overlays.addCommandItem (commandManager, CommandIDs::compOverlay0); - overlays.addCommandItem (commandManager, CommandIDs::compOverlay33); - overlays.addCommandItem (commandManager, CommandIDs::compOverlay66); - overlays.addCommandItem (commandManager, CommandIDs::compOverlay100); - menu.addSubMenu ("Component Overlay", overlays, - getActiveDocument() != 0 && getActiveDocument()->getComponentLayout() != 0);*/ - - menu.addSeparator(); - menu.addCommandItem (commandManager, CommandIDs::useTabbedWindows); - //menu.addSeparator(); - //menu.addCommandItem (commandManager, CommandIDs::showPrefs); - } - else if (topLevelMenuIndex == 3) - { - // "Window" menu - - const int numDocs = jmin (50, OpenDocumentManager::getInstance()->getNumOpenDocuments()); - - for (int i = 0; i < numDocs; ++i) - { - OpenDocumentManager::Document* doc = OpenDocumentManager::getInstance()->getOpenDocument(i); - - menu.addItem (300 + i, doc->getName()); - } - - menu.addSeparator(); - menu.addCommandItem (commandManager, CommandIDs::closeAllDocuments); - } - - return menu; -} - -void MainWindow::menuItemSelected (int menuItemID, - int topLevelMenuIndex) -{ - if (menuItemID >= 100 && menuItemID < 200) - { - // open a file from the "recent files" menu - const File file (StoredSettings::getInstance()->recentFiles.getFile (menuItemID - 100)); - - openFile (file); - } - else if (menuItemID == 201) - { - LookAndFeel::setDefaultLookAndFeel (0); - } - else if (menuItemID >= 300 && menuItemID < 400) - { - OpenDocumentManager::Document* doc = OpenDocumentManager::getInstance()->getOpenDocument (menuItemID - 300); - getProjectContentComponent()->showDocument (doc); - } -} //============================================================================== ApplicationCommandTarget* MainWindow::getNextCommandTarget() @@ -395,11 +241,7 @@ ApplicationCommandTarget* MainWindow::getNextCommandTarget() void MainWindow::getAllCommands (Array & commands) { - const CommandID ids[] = { CommandIDs::newProject, - CommandIDs::open, - CommandIDs::showPrefs, - CommandIDs::closeAllDocuments, - CommandIDs::saveAll }; + const CommandID ids[] = { CommandIDs::closeWindow }; commands.addArray (ids, numElementsInArray (ids)); } @@ -408,39 +250,9 @@ void MainWindow::getCommandInfo (const CommandID commandID, ApplicationCommandIn { switch (commandID) { - case CommandIDs::newProject: - result.setInfo ("New Project...", - "Creates a new Jucer project", - CommandCategories::general, 0); - result.defaultKeypresses.add (KeyPress ('o', ModifierKeys::commandModifier, 0)); - break; - - case CommandIDs::open: - result.setInfo ("Open...", - "Opens a Jucer project", - CommandCategories::general, 0); - result.defaultKeypresses.add (KeyPress ('o', ModifierKeys::commandModifier, 0)); - break; - - case CommandIDs::showPrefs: - result.setInfo ("Preferences...", - "Shows the preferences panel.", - CommandCategories::general, 0); - result.defaultKeypresses.add (KeyPress (',', ModifierKeys::commandModifier, 0)); - break; - - case CommandIDs::closeAllDocuments: - result.setInfo ("Close All Documents", - "Closes all open documents", - CommandCategories::general, 0); - result.setActive (OpenDocumentManager::getInstance()->getNumOpenDocuments() > 0); - break; - - case CommandIDs::saveAll: - result.setInfo ("Save All", - "Saves all open documents", - CommandCategories::general, 0); - result.setActive (OpenDocumentManager::getInstance()->anyFilesNeedSaving()); + case CommandIDs::closeWindow: + result.setInfo ("Close Window", "Closes the current window", CommandCategories::general, 0); + result.defaultKeypresses.add (KeyPress ('w', ModifierKeys::commandModifier, 0)); break; default: @@ -452,28 +264,12 @@ bool MainWindow::perform (const InvocationInfo& info) { switch (info.commandID) { - case CommandIDs::newProject: - createNewProject(); - break; - - case CommandIDs::open: - askUserToOpenFile(); - break; - - case CommandIDs::showPrefs: - // PrefsPanel::show(); - break; - - case CommandIDs::saveAll: - OpenDocumentManager::getInstance()->saveAll(); - break; - - case CommandIDs::closeAllDocuments: - closeAllDocuments (true); - break; + case CommandIDs::closeWindow: + closeButtonPressed(); + break; - default: - return false; + default: + return false; } return true; diff --git a/extras/Jucer (experimental)/Source/Application/jucer_MainWindow.h b/extras/Jucer (experimental)/Source/Application/jucer_MainWindow.h index 93f314def6..ed9051b786 100644 --- a/extras/Jucer (experimental)/Source/Application/jucer_MainWindow.h +++ b/extras/Jucer (experimental)/Source/Application/jucer_MainWindow.h @@ -34,7 +34,6 @@ The big top-level window where everything happens. */ class MainWindow : public DocumentWindow, - public MenuBarModel, public ApplicationCommandTarget, public FileDragAndDropTarget, public DragAndDropContainer @@ -48,16 +47,14 @@ public: void closeButtonPressed(); //============================================================================== - void askUserToOpenFile(); bool canOpenFile (const File& file) const; bool openFile (const File& file); - void createNewProject(); void setProject (Project* newProject); - void reloadLastProject(); + Project* getProject() const { return currentProject; } + void restoreWindowPosition(); bool closeProject (Project* project); bool closeCurrentProject(); - bool closeAllDocuments (bool askUserToSave); bool isInterestedInFileDrag (const StringArray& files); void filesDropped (const StringArray& filenames, int mouseX, int mouseY); @@ -66,10 +63,7 @@ public: void updateTitle (const String& documentName); - //============================================================================== - const StringArray getMenuBarNames(); - const PopupMenu getMenuForIndex (int topLevelMenuIndex, const String& menuName); - void menuItemSelected (int menuItemID, int topLevelMenuIndex); + ProjectContentComponent* getProjectContentComponent() const; //============================================================================== ApplicationCommandTarget* getNextCommandTarget(); @@ -83,7 +77,14 @@ public: private: ScopedPointer currentProject; - ProjectContentComponent* getProjectContentComponent() const; + const String getProjectWindowPosName() const + { + jassert (currentProject != 0); + if (currentProject == 0) + return String::empty; + + return "projectWindowPos_" + currentProject->getProjectUID(); + } }; diff --git a/extras/Jucer (experimental)/Source/Project/jucer_ProjectContentComponent.cpp b/extras/Jucer (experimental)/Source/Project/jucer_ProjectContentComponent.cpp index 335ec5cbcd..e0e018454e 100644 --- a/extras/Jucer (experimental)/Source/Project/jucer_ProjectContentComponent.cpp +++ b/extras/Jucer (experimental)/Source/Project/jucer_ProjectContentComponent.cpp @@ -281,8 +281,12 @@ bool ProjectContentComponent::perform (const InvocationInfo& info) break; case CommandIDs::closeProject: - if (((MainWindow*) getParentComponent())->closeCurrentProject()) - StoredSettings::getInstance()->setLastProject (File::nonexistent); + { + MainWindow* mw = Component::findParentComponentOfClass ((MainWindow*) 0); + + if (mw != 0) + mw->closeCurrentProject(); + } break; diff --git a/extras/Jucer (experimental)/Source/Utility/jucer_StoredSettings.cpp b/extras/Jucer (experimental)/Source/Utility/jucer_StoredSettings.cpp index cd3cef758c..5c810f0387 100644 --- a/extras/Jucer (experimental)/Source/Utility/jucer_StoredSettings.cpp +++ b/extras/Jucer (experimental)/Source/Utility/jucer_StoredSettings.cpp @@ -102,14 +102,25 @@ void StoredSettings::flush() } } -const File StoredSettings::getLastProject() const +const Array StoredSettings::getLastProjects() const { - return props->getValue ("lastProject"); + StringArray s; + s.addTokens (props->getValue ("lastProjects"), "|", ""); + + Array f; + for (int i = 0; i < s.size(); ++i) + f.add (File (s[i])); + + return f; } -void StoredSettings::setLastProject (const File& file) +void StoredSettings::setLastProjects (const Array& files) { - props->setValue ("lastProject", file.getFullPathName()); + StringArray s; + for (int i = 0; i < files.size(); ++i) + s.add (files.getReference(i).getFullPathName()); + + props->setValue ("lastProjects", s.joinIntoString ("|")); } const File StoredSettings::getLastKnownJuceFolder() const diff --git a/extras/Jucer (experimental)/Source/Utility/jucer_StoredSettings.h b/extras/Jucer (experimental)/Source/Utility/jucer_StoredSettings.h index ff8dfb09e8..d1ed22acc4 100644 --- a/extras/Jucer (experimental)/Source/Utility/jucer_StoredSettings.h +++ b/extras/Jucer (experimental)/Source/Utility/jucer_StoredSettings.h @@ -47,8 +47,8 @@ public: //============================================================================== RecentlyOpenedFilesList recentFiles; - const File getLastProject() const; - void setLastProject (const File& file); + const Array getLastProjects() const; + void setLastProjects (const Array& files); const File getLastKnownJuceFolder() const; void setLastKnownJuceFolder (const File& file); diff --git a/juce_amalgamated.h b/juce_amalgamated.h index 2526822e06..778864ac66 100644 --- a/juce_amalgamated.h +++ b/juce_amalgamated.h @@ -64,7 +64,7 @@ */ #define JUCE_MAJOR_VERSION 1 #define JUCE_MINOR_VERSION 52 -#define JUCE_BUILDNUMBER 28 +#define JUCE_BUILDNUMBER 29 /** Current Juce version number. diff --git a/src/core/juce_StandardHeader.h b/src/core/juce_StandardHeader.h index db822b8735..a1e9cb794a 100644 --- a/src/core/juce_StandardHeader.h +++ b/src/core/juce_StandardHeader.h @@ -33,7 +33,7 @@ */ #define JUCE_MAJOR_VERSION 1 #define JUCE_MINOR_VERSION 52 -#define JUCE_BUILDNUMBER 28 +#define JUCE_BUILDNUMBER 29 /** Current Juce version number.