bool MainWindowList::openFile (const File& file) { for (int i = windows.size(); --i >= 0;) { MainWindow* const w = windows.getUnchecked(i); if (w->getProject() != nullptr && w->getProject()->getFile() == file) { w->toFront (true); return true; } } if (file.hasFileExtension (Project::projectFileExtension)) { MainWindow* const w = getOrCreateEmptyWindow(); bool ok = w->openFile (file); w->makeVisible(); avoidSuperimposedWindows (w); return ok; } if (file.exists()) return getFrontmostWindow()->openFile (file); return false; }
MainWindow* MainWindowList::getFrontmostWindow (bool createIfNotFound) { if (windows.isEmpty()) { if (createIfNotFound) { auto* w = createNewMainWindow(); avoidSuperimposedWindows (w); w->makeVisible(); return w; } return nullptr; } for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;) { auto* mw = dynamic_cast<MainWindow*> (Desktop::getInstance().getComponent (i)); if (windows.contains (mw)) return mw; } return windows.getLast(); }
MainWindow* MainWindowList::createNewMainWindow() { MainWindow* const w = new MainWindow(); windows.add (w); w->restoreWindowPosition(); avoidSuperimposedWindows (w); return w; }
MainWindow* MainWindowList::getOrCreateFrontmostWindow() { if (windows.size() == 0) { MainWindow* w = createNewMainWindow(); avoidSuperimposedWindows (w); w->makeVisible(); return w; } for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;) { MainWindow* mw = dynamic_cast<MainWindow*> (Desktop::getInstance().getComponent (i)); if (windows.contains (mw)) return mw; } return windows.getLast(); }
bool MainWindowList::openFile (const File& file, bool openInBackground) { for (auto* w : windows) { if (w->getProject() != nullptr && w->getProject()->getFile() == file) { w->toFront (true); return true; } } if (file.hasFileExtension (Project::projectFileExtension)) { WeakReference<Component> previousFrontWindow (getFrontmostWindow()); auto* w = getOrCreateEmptyWindow(); bool ok = w->openFile (file); if (ok) { w->makeVisible(); avoidSuperimposedWindows (w); } else { closeWindow (w); } if (openInBackground && previousFrontWindow != nullptr) previousFrontWindow->toFront (true); return ok; } if (getFrontmostWindow()->tryToOpenPIP (file)) return true; if (! isPIPFile (file) && file.exists()) return getFrontmostWindow()->openFile (file); return false; }
bool MainWindowList::openFile (const File& file) { for (int i = windows.size(); --i >= 0;) { MainWindow* const w = windows.getUnchecked(i); if (w->getProject() != nullptr && w->getProject()->getFile() == file) { w->toFront (true); return true; } } if (file.hasFileExtension (Project::projectFileExtension)) { ScopedPointer<Project> newDoc (new Project (file)); if (newDoc->loadFrom (file, true)) { MainWindow* const w = getOrCreateEmptyWindow(); w->setProject (newDoc); newDoc.release()->setChangedFlag (false); w->makeVisible(); avoidSuperimposedWindows (w); jassert (w->getProjectContentComponent() != nullptr); w->getProjectContentComponent()->reloadLastOpenDocuments(); return true; } } else if (file.exists()) { MainWindow* const w = getOrCreateFrontmostWindow(); return w->openFile (file); } return false; }