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;
}
Object::Pointer ResetPerspectiveHandler::Execute(const SmartPointer<const ExecutionEvent>& event)
{

  IWorkbenchWindow::Pointer activeWorkbenchWindow = HandlerUtil::GetActiveWorkbenchWindow(event);
  if (activeWorkbenchWindow.IsNotNull())
  {
    WorkbenchPage::Pointer page = activeWorkbenchWindow->GetActivePage().Cast<WorkbenchPage>();
    if (page.IsNotNull())
    {
      IPerspectiveDescriptor::Pointer descriptor = page->GetPerspective();
      if (descriptor.IsNotNull())
      {
        bool offerRevertToBase = false;
        if (PerspectiveDescriptor::Pointer desc = descriptor.Cast<PerspectiveDescriptor>())
        {
          offerRevertToBase = desc->IsPredefined() && desc->HasCustomDefinition();
        }

        if (offerRevertToBase)
        {
          QString message = QString("Do you want to reset the current %1 perspective to its saved state?").arg(
                              descriptor->GetLabel());
//          bool toggleState = false;
//          MessageDialogWithToggle dialog = MessageDialogWithToggle.open(
//                                             MessageDialog.QUESTION, activeWorkbenchWindow.getShell(),
//                                             WorkbenchMessages.RevertPerspective_title, message,
//                                             WorkbenchMessages.RevertPerspective_option,
//                                             toggleState, null, null, SWT.SHEET);
//          if (dialog.getReturnCode() == IDialogConstants.YES_ID) {
//            if (dialog.getToggleState()) {
//              PerspectiveRegistry* reg = PlatformUI::GetWorkbench()->GetPerspectiveRegistry();
//              reg->RevertPerspective(descriptor);
//            }
//            page->ResetPerspective();
//          }
          qDebug() << "****** " << message;
        }
        else
        {
          QString message = QString("Do you want to reset the current %1 perspective to its defaults?").arg(
                                    descriptor->GetLabel());
          if (QMessageBox::question(activeWorkbenchWindow->GetShell()->GetControl(), "Reset Perspective",
                                    message, QMessageBox::Yes | QMessageBox::No, QMessageBox::No) ==
              QMessageBox::Yes)
          {
            page->ResetPerspective();
          }
        }
      }
    }
  }

  return Object::Pointer();
}
void WorkbenchWindowConfigurer::ConfigureEditorAreaDropListener(const IDropTargetListener::Pointer& listener)
{
  if (listener == 0) return;
  dropTargetListener = listener;

  WorkbenchPage::Pointer page = window.Lock()->GetActivePage().Cast<WorkbenchPage>();
  if (page)
  {
    QtDnDControlWidget* dropTarget =
        static_cast<QtDnDControlWidget*>(page->GetEditorPresentation()->GetLayoutPart().Cast<EditorSashContainer>()->GetParent());
    dropTarget->AddDropListener(listener.GetPointer());
  }
}
void WorkbenchWindowConfigurer::AddEditorAreaTransfer(const QStringList& transfers)
{
  if (transfers.isEmpty()) return;

  int oldSize = transferTypes.size();
  transferTypes.unite(QSet<QString>::fromList(transfers));

  if (transferTypes.size() == oldSize) return;

  WorkbenchPage::Pointer page = window.Lock()->GetActivePage().Cast<WorkbenchPage>();
  if (page)
  {
    QtDnDControlWidget* dropTarget =
        static_cast<QtDnDControlWidget*>(page->GetEditorPresentation()->GetLayoutPart().Cast<EditorSashContainer>()->GetParent());
    dropTarget->SetTransferTypes(transferTypes.toList());
  }
}
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;
}
Exemplo n.º 6
0
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);
}