From cf61037ea4d124ae20128e3b334b2ff3c9d530e5 Mon Sep 17 00:00:00 2001 From: ed Date: Wed, 7 Feb 2018 12:57:16 +0000 Subject: [PATCH] Projucer: Added an option to clear the recent files list and added some more menu items for managing the currently open windows --- .../Source/Application/jucer_Application.cpp | 94 ++++++++++++++++--- .../Source/Application/jucer_Application.h | 3 + .../Source/Application/jucer_CommandIDs.h | 16 ++-- 3 files changed, 92 insertions(+), 21 deletions(-) diff --git a/extras/Projucer/Source/Application/jucer_Application.cpp b/extras/Projucer/Source/Application/jucer_Application.cpp index 379517c7db..184ed68efd 100644 --- a/extras/Projucer/Source/Application/jucer_Application.cpp +++ b/extras/Projucer/Source/Application/jucer_Application.cpp @@ -329,7 +329,8 @@ ApplicationCommandManager& ProjucerApplication::getCommandManager() enum { recentProjectsBaseID = 100, - activeDocumentsBaseID = 300, + openWindowsBaseID = 300, + activeDocumentsBaseID = 400, colourSchemeBaseID = 1000, codeEditorColourSchemeBaseID = 2000, }; @@ -341,18 +342,19 @@ MenuBarModel* ProjucerApplication::getMenuModel() StringArray ProjucerApplication::getMenuNames() { - return { "File", "Edit", "View", "Build", "Window", "GUI Editor", "Tools", "Help" }; + return { "File", "Edit", "View", "Build", "Window", "Document", "GUI Editor", "Tools", "Help" }; } void ProjucerApplication::createMenu (PopupMenu& menu, const String& menuName) { - if (menuName == "File") createFileMenu (menu); - else if (menuName == "Edit") createEditMenu (menu); - else if (menuName == "View") createViewMenu (menu); - else if (menuName == "Build") createBuildMenu (menu); - else if (menuName == "Window") createWindowMenu (menu); - else if (menuName == "Tools") createToolsMenu (menu); - else if (menuName == "Help") createHelpMenu (menu); + if (menuName == "File") createFileMenu (menu); + else if (menuName == "Edit") createEditMenu (menu); + else if (menuName == "View") createViewMenu (menu); + else if (menuName == "Build") createBuildMenu (menu); + else if (menuName == "Window") createWindowMenu (menu); + else if (menuName == "Document") createDocumentMenu (menu); + else if (menuName == "Tools") createToolsMenu (menu); + else if (menuName == "Help") createHelpMenu (menu); else if (menuName == "GUI Editor") createGUIEditorMenu (menu); else jassertfalse; // names have changed? } @@ -363,9 +365,19 @@ void ProjucerApplication::createFileMenu (PopupMenu& menu) menu.addSeparator(); menu.addCommandItem (commandManager, CommandIDs::open); - PopupMenu recentFiles; - settings->recentFiles.createPopupMenuItems (recentFiles, recentProjectsBaseID, true, true); - menu.addSubMenu ("Open Recent", recentFiles); + { + PopupMenu recentFiles; + + settings->recentFiles.createPopupMenuItems (recentFiles, recentProjectsBaseID, true, true); + + if (recentFiles.getNumItems() > 0) + { + recentFiles.addSeparator(); + recentFiles.addCommandItem (commandManager, CommandIDs::clearRecentFiles); + } + + menu.addSubMenu ("Open Recent", recentFiles); + } menu.addSeparator(); menu.addCommandItem (commandManager, CommandIDs::closeDocument); @@ -485,12 +497,28 @@ void ProjucerApplication::createWindowMenu (PopupMenu& menu) menu.addCommandItem (commandManager, CommandIDs::closeWindow); menu.addSeparator(); + int counter = 0; + for (auto* window : mainWindowList.windows) + { + if (window != nullptr) + { + if (auto* project = window->getProject()) + menu.addItem (openWindowsBaseID + counter++, project->getProjectNameString()); + } + } + + menu.addSeparator(); + menu.addCommandItem (commandManager, CommandIDs::closeAllWindows); +} + +void ProjucerApplication::createDocumentMenu (PopupMenu& menu) +{ menu.addCommandItem (commandManager, CommandIDs::goToPreviousDoc); menu.addCommandItem (commandManager, CommandIDs::goToNextDoc); menu.addCommandItem (commandManager, CommandIDs::goToCounterpart); menu.addSeparator(); - const int numDocs = jmin (50, openDocumentManager.getNumOpenDocuments()); + auto numDocs = jmin (50, openDocumentManager.getNumOpenDocuments()); for (int i = 0; i < numDocs; ++i) { @@ -533,9 +561,14 @@ void ProjucerApplication::handleMainMenuCommand (int menuItemID) // open a file from the "recent files" menu openFile (settings->recentFiles.getFile (menuItemID - recentProjectsBaseID)); } + else if (menuItemID >= openWindowsBaseID && menuItemID < (openWindowsBaseID + 100)) + { + if (auto* window = mainWindowList.windows.getUnchecked (menuItemID - openWindowsBaseID)) + window->toFront (true); + } else if (menuItemID >= activeDocumentsBaseID && menuItemID < (activeDocumentsBaseID + 200)) { - if (OpenDocumentManager::Document* doc = openDocumentManager.getOpenDocument (menuItemID - activeDocumentsBaseID)) + if (auto* doc = openDocumentManager.getOpenDocument (menuItemID - activeDocumentsBaseID)) mainWindowList.openDocument (doc, true); else jassertfalse; @@ -566,7 +599,9 @@ void ProjucerApplication::getAllCommands (Array & commands) const CommandID ids[] = { CommandIDs::newProject, CommandIDs::open, + CommandIDs::closeAllWindows, CommandIDs::closeAllDocuments, + CommandIDs::clearRecentFiles, CommandIDs::saveAll, CommandIDs::showGlobalPathsWindow, CommandIDs::showUTF8Tool, @@ -602,11 +637,21 @@ void ProjucerApplication::getCommandInfo (CommandID commandID, ApplicationComman CommandCategories::general, 0); break; + case CommandIDs::closeAllWindows: + result.setInfo ("Close All Windows", "Closes all open windows", CommandCategories::general, 0); + result.setActive (mainWindowList.windows.size() > 0); + break; + case CommandIDs::closeAllDocuments: result.setInfo ("Close All Documents", "Closes all open documents", CommandCategories::general, 0); result.setActive (openDocumentManager.getNumOpenDocuments() > 0); break; + case CommandIDs::clearRecentFiles: + result.setInfo ("Clear Recent Files", "Clears all recent files from the menu", CommandCategories::general, 0); + result.setActive (settings->recentFiles.getNumFiles() > 0); + break; + case CommandIDs::saveAll: result.setInfo ("Save All", "Saves all open documents", CommandCategories::general, 0); result.defaultKeypresses.add (KeyPress ('s', ModifierKeys::commandModifier | ModifierKeys::altModifier, 0)); @@ -676,7 +721,9 @@ bool ProjucerApplication::perform (const InvocationInfo& info) case CommandIDs::newProject: createNewProject(); break; case CommandIDs::open: askUserToOpenFile(); break; case CommandIDs::saveAll: openDocumentManager.saveAll(); break; + case CommandIDs::closeAllWindows: closeAllMainWindowsAndQuitIfNeeded(); break; case CommandIDs::closeAllDocuments: closeAllDocuments (true); break; + case CommandIDs::clearRecentFiles: clearRecentFiles(); break; case CommandIDs::showUTF8Tool: showUTF8ToolWindow(); break; case CommandIDs::showSVGPathTool: showSVGPathDataToolWindow(); break; case CommandIDs::showGlobalPathsWindow: showPathsWindow(); break; @@ -729,6 +776,25 @@ bool ProjucerApplication::closeAllMainWindows() return server != nullptr || mainWindowList.askAllWindowsToClose(); } +void ProjucerApplication::closeAllMainWindowsAndQuitIfNeeded() +{ + if (closeAllMainWindows()) + { + #if ! JUCE_MAC + if (mainWindowList.windows.size() == 0) + systemRequestedQuit(); + #endif + } +} + +void ProjucerApplication::clearRecentFiles() +{ + settings->recentFiles.clear(); + settings->recentFiles.clearRecentFilesNatively(); + settings->flush(); + menuModel->menuItemsChanged(); +} + //============================================================================== void ProjucerApplication::showUTF8ToolWindow() { diff --git a/extras/Projucer/Source/Application/jucer_Application.h b/extras/Projucer/Source/Application/jucer_Application.h index fd7cd4c420..d79dd9c203 100644 --- a/extras/Projucer/Source/Application/jucer_Application.h +++ b/extras/Projucer/Source/Application/jucer_Application.h @@ -75,6 +75,7 @@ public: void createBuildMenu (PopupMenu&); void createColourSchemeItems (PopupMenu&); void createWindowMenu (PopupMenu&); + void createDocumentMenu (PopupMenu&); void createToolsMenu (PopupMenu&); void createHelpMenu (PopupMenu&); void createExtraAppleMenuItems (PopupMenu&); @@ -92,6 +93,8 @@ public: bool openFile (const File&); bool closeAllDocuments (bool askUserToSave); bool closeAllMainWindows(); + void closeAllMainWindowsAndQuitIfNeeded(); + void clearRecentFiles(); PropertiesFile::Options getPropertyFileOptionsFor (const String& filename, bool isProjectSettings); diff --git a/extras/Projucer/Source/Application/jucer_CommandIDs.h b/extras/Projucer/Source/Application/jucer_CommandIDs.h index d4935bc84b..b74c3540a1 100644 --- a/extras/Projucer/Source/Application/jucer_CommandIDs.h +++ b/extras/Projucer/Source/Application/jucer_CommandIDs.h @@ -62,13 +62,15 @@ namespace CommandIDs showExporterSettings = 0x300036, closeWindow = 0x300040, - closeAllDocuments = 0x300041, - goToPreviousDoc = 0x300042, - goToNextDoc = 0x300043, - goToCounterpart = 0x300044, - deleteSelectedItem = 0x300045, - goToPreviousWindow = 0x300046, - goToNextWindow = 0x300047, + closeAllWindows = 0x300041, + closeAllDocuments = 0x300042, + goToPreviousDoc = 0x300043, + goToNextDoc = 0x300044, + goToCounterpart = 0x300045, + deleteSelectedItem = 0x300046, + goToPreviousWindow = 0x300047, + goToNextWindow = 0x300048, + clearRecentFiles = 0x300049, showFindPanel = 0x300050, findSelection = 0x300051,