bool PerspectivesPreferencePage::FindOpenInstance(const PerspectiveDescriptor::Pointer& desc)
{
  QList<IWorkbenchWindow::Pointer> windows = workbench->GetWorkbenchWindows();

  //find all active perspectives currently
  for (int i = 0; i < windows.size(); i++)
  {
    QList<IWorkbenchPage::Pointer> pages = windows[i]->GetPages();
    for (int j = 0; j < pages.size(); j++)
    {
      WorkbenchPage::Pointer page = pages[j].Cast<WorkbenchPage>();
      if (page->FindPerspective(desc).IsNotNull())
      {
        QMessageBox::StandardButton returnCode =
            QMessageBox::question(workbench->GetActiveWorkbenchWindow()->GetShell()->GetControl(),
                                  "Delete Perspective",
                                  QString("Are you sure you want to delete the \"%1\" perspective? It has open instances.").arg(desc->GetLabel()),
                                  QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
        return (returnCode != QMessageBox::Yes);
      }
    }
  }

  return false;
}
bool PerspectivesPreferencePage::PerformOk()
{
  // Set the default perspective
  if (defaultPerspectiveId != perspRegistry->GetDefaultPerspective())
  {
    perspRegistry->SetDefaultPerspective(defaultPerspectiveId);
  }

  //Delete the perspective
  if(perspectives.size() < perspRegistry->GetPerspectives().size())
  {
    QList<IWorkbenchWindow::Pointer> windows = workbench->GetWorkbenchWindows();

    // close any perspectives that are about to be deleted
    for (int i = 0; i < windows.size(); i++)
    {
      QList<IWorkbenchPage::Pointer> pages = windows[i]->GetPages();
      for (int j = 0; j < pages.size(); j++)
      {
        WorkbenchPage::Pointer page = pages[j].Cast<WorkbenchPage>();
        for (int k = 0; k < perspToDelete.size(); k++)
        {
          IPerspectiveDescriptor::Pointer desc(perspToDelete[k].GetPointer());
          if (page->FindPerspective(desc).IsNotNull())
          {
            page->ClosePerspective(desc, true, true);
          }
        }
      }
    }
    perspRegistry->DeletePerspectives(perspToDelete);
  }

  // Revert the perspectives
  perspRegistry->RevertPerspectives(perspToRevert);

  // store the open perspective mode setting
  preferences->PutInt(PreferenceConstants::OPEN_PERSP_MODE, openPerspMode);

  return true;
}
IWorkbenchPart::Pointer WorkbenchIntroManager::GetIntroAdapterPart() const
{
  QList<IWorkbenchWindow::Pointer> windows(this->workbench->GetWorkbenchWindows());
  for (int i = 0; i < windows.size(); i++)
  {
    IWorkbenchWindow::Pointer window = windows[i];
    WorkbenchPage::Pointer page = window->GetActivePage().Cast<WorkbenchPage>();
    if (!page)
    {
      continue;
    }

    if (IntroIsView())
    {
      QList<IPerspectiveDescriptor::Pointer> perspDescs(page->GetOpenPerspectives());
      for (int j = 0; j < perspDescs.size(); j++)
      {
        IPerspectiveDescriptor::Pointer descriptor = perspDescs[j];
        IViewReference::Pointer reference = page->FindPerspective(descriptor)->FindView(
            IntroConstants::INTRO_VIEW_ID);
        if (reference)
        {
          return reference->GetView(false);
        }
      }
    }
    else
    {
      QList<IEditorReference::Pointer> references(page->FindEditors(IEditorInput::Pointer(nullptr), IntroConstants::INTRO_EDITOR_ID, IWorkbenchPage::MATCH_ID));
      Q_ASSERT(references.size() < 2);
      if (references.size() == 1)
        return references.front()->GetEditor(false);
    }
  }
  return IWorkbenchPart::Pointer(nullptr);
}