diff --git a/extras/Projucer/Source/Application/jucer_Application.cpp b/extras/Projucer/Source/Application/jucer_Application.cpp index 0c69b0fba0..7d7b77b680 100644 --- a/extras/Projucer/Source/Application/jucer_Application.cpp +++ b/extras/Projucer/Source/Application/jucer_Application.cpp @@ -508,6 +508,8 @@ void ProjucerApplication::createColourSchemeItems (PopupMenu& menu) void ProjucerApplication::createWindowMenu (PopupMenu& menu) { + menu.addCommandItem (commandManager, CommandIDs::goToPreviousWindow); + menu.addCommandItem (commandManager, CommandIDs::goToNextWindow); menu.addCommandItem (commandManager, CommandIDs::closeWindow); menu.addSeparator(); diff --git a/extras/Projucer/Source/Application/jucer_CommandIDs.h b/extras/Projucer/Source/Application/jucer_CommandIDs.h index ce26fe241f..d97d6bd6ac 100644 --- a/extras/Projucer/Source/Application/jucer_CommandIDs.h +++ b/extras/Projucer/Source/Application/jucer_CommandIDs.h @@ -67,6 +67,8 @@ namespace CommandIDs goToNextDoc = 0x300043, goToCounterpart = 0x300044, deleteSelectedItem = 0x300045, + goToPreviousWindow = 0x300046, + goToNextWindow = 0x300047, showFindPanel = 0x300050, findSelection = 0x300051, diff --git a/extras/Projucer/Source/Application/jucer_MainWindow.cpp b/extras/Projucer/Source/Application/jucer_MainWindow.cpp index 5c5d62933b..d41b6972b4 100644 --- a/extras/Projucer/Source/Application/jucer_MainWindow.cpp +++ b/extras/Projucer/Source/Application/jucer_MainWindow.cpp @@ -132,7 +132,7 @@ bool MainWindow::closeProject (Project* project) project->getStoredProperties().setValue (getProjectWindowPosName(), getWindowStateAsString()); - if (ProjectContentComponent* const pcc = getProjectContentComponent()) + if (auto* pcc = getProjectContentComponent()) { pcc->saveTreeViewState(); pcc->saveOpenDocumentList(); @@ -142,7 +142,7 @@ bool MainWindow::closeProject (Project* project) if (! ProjucerApplication::getApp().openDocumentManager.closeAllDocumentsUsingProject (*project, true)) return false; - FileBasedDocument::SaveResult r = project->saveIfNeededAndUserAgrees(); + auto r = project->saveIfNeededAndUserAgrees(); if (r == FileBasedDocument::savedOk) { @@ -226,8 +226,8 @@ bool MainWindow::openFile (const File& file) bool MainWindow::isInterestedInFileDrag (const StringArray& filenames) { - for (int i = filenames.size(); --i >= 0;) - if (canOpenFile (File (filenames[i]))) + for (auto& filename : filenames) + if (canOpenFile (File (filename))) return true; return false; @@ -235,9 +235,9 @@ bool MainWindow::isInterestedInFileDrag (const StringArray& filenames) void MainWindow::filesDropped (const StringArray& filenames, int /*mouseX*/, int /*mouseY*/) { - for (int i = filenames.size(); --i >= 0;) + for (auto& filename : filenames) { - const File f (filenames[i]); + const File f (filename); if (canOpenFile (f) && openFile (f)) break; @@ -247,21 +247,21 @@ void MainWindow::filesDropped (const StringArray& filenames, int /*mouseX*/, int bool MainWindow::shouldDropFilesWhenDraggedExternally (const DragAndDropTarget::SourceDetails& sourceDetails, StringArray& files, bool& canMoveFiles) { - if (TreeView* tv = dynamic_cast (sourceDetails.sourceComponent.get())) + if (auto* tv = dynamic_cast (sourceDetails.sourceComponent.get())) { Array selected; for (int i = tv->getNumSelectedItems(); --i >= 0;) - if (JucerTreeViewBase* b = dynamic_cast (tv->getSelectedItem(i))) + if (auto* b = dynamic_cast (tv->getSelectedItem(i))) selected.add (b); - if (selected.size() > 0) + if (! selected.isEmpty()) { for (int i = selected.size(); --i >= 0;) { - if (JucerTreeViewBase* jtvb = selected.getUnchecked(i)) + if (auto* jtvb = selected.getUnchecked(i)) { - const File f (jtvb->getDraggableFile()); + auto f = jtvb->getDraggableFile(); if (f.existsAsFile()) files.add (f.getFullPathName()); @@ -269,7 +269,7 @@ bool MainWindow::shouldDropFilesWhenDraggedExternally (const DragAndDropTarget:: } canMoveFiles = false; - return files.size() > 0; + return ! files.isEmpty(); } } @@ -341,7 +341,12 @@ ApplicationCommandTarget* MainWindow::getNextCommandTarget() void MainWindow::getAllCommands (Array & commands) { - const CommandID ids[] = { CommandIDs::closeWindow }; + const CommandID ids[] = + { + CommandIDs::closeWindow, + CommandIDs::goToPreviousWindow, + CommandIDs::goToNextWindow + }; commands.addArray (ids, numElementsInArray (ids)); } @@ -355,6 +360,18 @@ void MainWindow::getCommandInfo (const CommandID commandID, ApplicationCommandIn result.defaultKeypresses.add (KeyPress ('w', ModifierKeys::commandModifier, 0)); break; + case CommandIDs::goToPreviousWindow: + result.setInfo ("Previous Window", "Activates the previous window", CommandCategories::general, 0); + result.setActive (ProjucerApplication::getApp().mainWindowList.windows.size() > 1); + result.defaultKeypresses.add (KeyPress (KeyPress::tabKey, ModifierKeys::shiftModifier | ModifierKeys::ctrlModifier, 0)); + break; + + case CommandIDs::goToNextWindow: + result.setInfo ("Next Window", "Activates the next window", CommandCategories::general, 0); + result.setActive (ProjucerApplication::getApp().mainWindowList.windows.size() > 1); + result.defaultKeypresses.add (KeyPress (KeyPress::tabKey, ModifierKeys::ctrlModifier, 0)); + break; + default: break; } @@ -368,6 +385,14 @@ bool MainWindow::perform (const InvocationInfo& info) closeButtonPressed(); break; + case CommandIDs::goToPreviousWindow: + ProjucerApplication::getApp().mainWindowList.goToSiblingWindow (this, -1); + break; + + case CommandIDs::goToNextWindow: + ProjucerApplication::getApp().mainWindowList.goToSiblingWindow (this, 1); + break; + default: return false; } @@ -434,15 +459,24 @@ void MainWindowList::closeWindow (MainWindow* w) } } +void MainWindowList::goToSiblingWindow (MainWindow* w, int delta) +{ + auto index = windows.indexOf (w); + + if (index >= 0) + if (auto* next = windows[(index + delta + windows.size()) % windows.size()]) + next->toFront (true); +} + void MainWindowList::openDocument (OpenDocumentManager::Document* doc, bool grabFocus) { - Desktop& desktop = Desktop::getInstance(); + auto& desktop = Desktop::getInstance(); for (int i = desktop.getNumComponents(); --i >= 0;) { - if (MainWindow* const mw = dynamic_cast (desktop.getComponent(i))) + if (auto* mw = dynamic_cast (desktop.getComponent(i))) { - if (ProjectContentComponent* pcc = mw->getProjectContentComponent()) + if (auto* pcc = mw->getProjectContentComponent()) { if (pcc->hasFileInRecentList (doc->getFile())) { @@ -459,10 +493,8 @@ void MainWindowList::openDocument (OpenDocumentManager::Document* doc, bool grab bool MainWindowList::openFile (const File& file, bool openInBackground) { - for (int i = windows.size(); --i >= 0;) + for (auto* w : windows) { - MainWindow* const w = windows.getUnchecked(i); - if (w->getProject() != nullptr && w->getProject()->getFile() == file) { w->toFront (true); @@ -474,7 +506,7 @@ bool MainWindowList::openFile (const File& file, bool openInBackground) { auto previousFrontWindow = getFrontmostWindow(); - MainWindow* const w = getOrCreateEmptyWindow(); + auto* w = getOrCreateEmptyWindow(); bool ok = w->openFile (file); w->makeVisible(); @@ -494,7 +526,7 @@ bool MainWindowList::openFile (const File& file, bool openInBackground) MainWindow* MainWindowList::createNewMainWindow() { - MainWindow* const w = new MainWindow(); + auto w = new MainWindow(); windows.add (w); w->restoreWindowPosition(); avoidSuperimposedWindows (w); @@ -503,11 +535,11 @@ MainWindow* MainWindowList::createNewMainWindow() MainWindow* MainWindowList::getFrontmostWindow (bool createIfNotFound) { - if (windows.size() == 0) + if (windows.isEmpty()) { if (createIfNotFound) { - MainWindow* w = createNewMainWindow(); + auto* w = createNewMainWindow(); avoidSuperimposedWindows (w); w->makeVisible(); return w; @@ -518,7 +550,8 @@ MainWindow* MainWindowList::getFrontmostWindow (bool createIfNotFound) for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;) { - MainWindow* mw = dynamic_cast (Desktop::getInstance().getComponent (i)); + auto* mw = dynamic_cast (Desktop::getInstance().getComponent (i)); + if (windows.contains (mw)) return mw; } @@ -533,7 +566,8 @@ MainWindow* MainWindowList::getOrCreateEmptyWindow() for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;) { - MainWindow* mw = dynamic_cast (Desktop::getInstance().getComponent (i)); + auto* mw = dynamic_cast (Desktop::getInstance().getComponent (i)); + if (windows.contains (mw) && mw->getProject() == nullptr) return mw; } @@ -545,10 +579,10 @@ void MainWindowList::avoidSuperimposedWindows (MainWindow* const mw) { for (int i = windows.size(); --i >= 0;) { - MainWindow* const other = windows.getUnchecked(i); + auto* other = windows.getUnchecked(i); - const Rectangle b1 (mw->getBounds()); - const Rectangle b2 (other->getBounds()); + auto b1 = mw->getBounds(); + auto b2 = other->getBounds(); if (mw != other && std::abs (b1.getX() - b2.getX()) < 3 @@ -569,12 +603,12 @@ void MainWindowList::avoidSuperimposedWindows (MainWindow* const mw) void MainWindowList::saveCurrentlyOpenProjectList() { Array projects; - Desktop& desktop = Desktop::getInstance(); + auto& desktop = Desktop::getInstance(); for (int i = 0; i < desktop.getNumComponents(); ++i) { - if (MainWindow* const mw = dynamic_cast (desktop.getComponent(i))) - if (Project* p = mw->getProject()) + if (auto* mw = dynamic_cast (desktop.getComponent(i))) + if (auto* p = mw->getProject()) projects.add (p->getFile()); } @@ -583,25 +617,23 @@ void MainWindowList::saveCurrentlyOpenProjectList() void MainWindowList::reopenLastProjects() { - Array projects (getAppSettings().getLastProjects()); - - for (int i = 0; i < projects.size(); ++ i) - openFile (projects.getReference(i), true); + for (auto& p : getAppSettings().getLastProjects()) + openFile (p, true); } void MainWindowList::sendLookAndFeelChange() { - for (int i = windows.size(); --i >= 0;) - windows.getUnchecked(i)->sendLookAndFeelChange(); + for (auto* w : windows) + w->sendLookAndFeelChange(); } Project* MainWindowList::getFrontmostProject() { - Desktop& desktop = Desktop::getInstance(); + auto& desktop = Desktop::getInstance(); for (int i = desktop.getNumComponents(); --i >= 0;) - if (MainWindow* const mw = dynamic_cast (desktop.getComponent(i))) - if (Project* p = mw->getProject()) + if (auto* mw = dynamic_cast (desktop.getComponent(i))) + if (auto* p = mw->getProject()) return p; return nullptr; diff --git a/extras/Projucer/Source/Application/jucer_MainWindow.h b/extras/Projucer/Source/Application/jucer_MainWindow.h index c38a6bf5e3..5224fba33a 100644 --- a/extras/Projucer/Source/Application/jucer_MainWindow.h +++ b/extras/Projucer/Source/Application/jucer_MainWindow.h @@ -96,6 +96,8 @@ public: bool askAllWindowsToClose(); void closeWindow (MainWindow*); + void goToSiblingWindow (MainWindow*, int delta); + void createWindowIfNoneAreOpen(); void openDocument (OpenDocumentManager::Document*, bool grabFocus); bool openFile (const File& file, bool openInBackground = false);