void SavePerspectiveHandler::SaveNonSingleton(const IWorkbenchPage::Pointer& page,
                                              const PerspectiveDescriptor::Pointer& oldDesc) {
  // Get reg.
  PerspectiveRegistry* reg = static_cast<PerspectiveRegistry*>(
                               berry::WorkbenchPlugin::GetDefault()->GetPerspectiveRegistry());
  assert(reg != nullptr);

  // Get persp name.
  SavePerspectiveDialog dlg(*reg, page->GetWorkbenchWindow()->GetShell()->GetControl());
  // Look up the descriptor by id again to ensure it is still valid.
  IPerspectiveDescriptor::Pointer description = reg->FindPerspectiveWithId(oldDesc->GetId());
  dlg.SetInitialSelection(description);
  if (dlg.exec() != QDialog::Accepted)
  {
    return;
  }

  // Create descriptor.
  IPerspectiveDescriptor::Pointer newDesc = dlg.GetPersp();
  if (newDesc.IsNull())
  {
    QString name = dlg.GetPerspName();
    newDesc = reg->CreatePerspective(name, description);
    if (newDesc.IsNull())
    {
      QMessageBox::critical(&dlg,
                            "Cannot Save Perspective",
                            "Invalid Perspective Descriptor");
      return;
    }
  }

  // Save state.
  page->SavePerspectiveAs(newDesc);
}
Beispiel #2
0
void ShowViewHandler::OpenOther(IWorkbenchWindow::Pointer window)
{
  const IWorkbenchPage::Pointer page = window->GetActivePage();
  if (page.IsNull())
  {
    return;
  }

  QtShowViewDialog dialog(window.GetPointer(), WorkbenchPlugin::GetDefault()->GetViewRegistry());

  int returnCode = dialog.exec();

  if (returnCode == QDialog::Rejected)
  {
    return;
  }

  const QList<QString> descriptors = dialog.GetSelection();
  for (QString id : descriptors)
  {
    try
    {
      this->OpenView(id, QString(), window);
    }
    catch (const PartInitException& e)
    {
      BERRY_WARN << e.what();
//      StatusUtil.handleStatus(e.getStatus(),
//          WorkbenchMessages.ShowView_errorTitle
//          + ": " + e.getMessage(), //$NON-NLS-1$
//          StatusManager.SHOW);
    }
  }
}
void ShowViewHandler::OpenOther(IWorkbenchWindow::Pointer window)
{
  const IWorkbenchPage::Pointer page = window->GetActivePage();
  if (page.IsNull())
  {
    return;
  }

  IShowViewDialog::Pointer dialog = Tweaklets::Get(WorkbenchTweaklet::KEY)->CreateStandardDialog(WorkbenchTweaklet::DIALOG_ID_SHOW_VIEW).Cast<IShowViewDialog>();
  if (dialog.IsNull()) return;

  int returnCode = dialog->Open();

  if (returnCode == IDialog::CANCEL)
  {
    return;
  }

  const std::vector<IViewDescriptor::Pointer> descriptors =
      dialog->GetSelection();
  for (unsigned int i = 0; i < descriptors.size(); ++i)
  {
    try
    {
      this->OpenView(descriptors[i]->GetId(), window);
    }
    catch (PartInitException e)
    {
//      StatusUtil.handleStatus(e.getStatus(),
//          WorkbenchMessages.ShowView_errorTitle
//          + ": " + e.getMessage(), //$NON-NLS-1$
//          StatusManager.SHOW);
    }
  }
}
void WorkbenchIntroManager::CreateIntro(
    SmartPointer<IWorkbenchWindow> preferredWindow)
{
  IIntroDescriptor::Pointer descr = this->workbench->GetIntroDescriptor();
  if (!descr)
  {
    return;
  }

  IWorkbenchPage::Pointer workbenchPage = preferredWindow->GetActivePage();
  if (!workbenchPage)
  {
    return;
  }
  try
  {
    if (IntroIsView())
    {
      workbenchPage->ShowView(IntroConstants::INTRO_VIEW_ID);
    }
    else
    {
      IEditorInput::Pointer input(new NullEditorInput());
      workbenchPage->OpenEditor(input, IntroConstants::INTRO_EDITOR_ID);
    }
  } catch (PartInitException& e)
  {
    //TODO IStatus
//    WorkbenchPlugin::Log(IntroMessages.Intro_could_not_create_part, new Status(
//        IStatus.ERROR, WorkbenchPlugin.PI_WORKBENCH, IStatus.ERROR,
//        IntroMessages.Intro_could_not_create_part, e));
    WorkbenchPlugin::Log("Could not create intro part.", e);
  }
}
Object::Pointer SavePerspectiveHandler::Execute(const SmartPointer<const berry::ExecutionEvent>& event)
{

  IWorkbenchWindow::Pointer activeWorkbenchWindow = HandlerUtil::GetActiveWorkbenchWindow(event);
  if (activeWorkbenchWindow.IsNotNull())
  {
    IWorkbenchPage::Pointer page = activeWorkbenchWindow->GetActivePage();
    if (page.IsNotNull())
    {
      PerspectiveDescriptor::Pointer descriptor(page->GetPerspective().Cast<PerspectiveDescriptor>());
      if (descriptor.IsNotNull())
      {
        if (descriptor->IsSingleton())
        {
          SaveSingleton(page);
        }
        else
        {
          SaveNonSingleton(page, descriptor);
        }
      }
    }
  }
  return Object::Pointer();
}
Beispiel #6
0
QVariant DescriptorTreeItem::data(int role)
{
  if (role == Qt::DisplayRole)
  {
    return m_descriptor->GetLabel();
  }
  else if (role == Qt::DecorationRole)
  {
    return m_descriptor->GetImageDescriptor();
  }
  else if (role == Qt::ForegroundRole)
  {
    IWorkbenchPage::Pointer page = this->m_model->GetWorkbenchWindow()->GetActivePage();
    if (page.IsNotNull())
    {
      if (page->FindViewReference(m_descriptor->GetId()).IsNotNull())
      {
        return QBrush(QColor(Qt::gray));
      }
    }
  }
  else if (role == ViewTreeModel::Description)
  {
    return m_descriptor->GetDescription();
  }
  else if (role == ViewTreeModel::Id)
  {
    return m_descriptor->GetId();
  }
  return ViewTreeItem::data(role);
}
Beispiel #7
0
bool DefaultSaveable::Show(IWorkbenchPage::Pointer page)
{
  IWorkbenchPart::Pointer _part(part);
  IWorkbenchPartReference::Pointer reference = page->GetReference(_part);
  if (reference != 0)
  {
    page->Activate(_part);
    return true;
  }
  if (_part.Cast<IViewPart> () != 0)
  {
    IViewPart::Pointer viewPart = _part.Cast<IViewPart> ();
    try
    {
      page->ShowView(viewPart->GetViewSite()->GetId(),
                     viewPart->GetViewSite()->GetSecondaryId(),
                     IWorkbenchPage::VIEW_ACTIVATE);
    } catch (const PartInitException& /*e*/)
    {
      return false;
    }
    return true;
  }
  return false;
}
PagePartSelectionTracker::~PagePartSelectionTracker()
{
    IWorkbenchPage::Pointer page = GetPage();
    page->GetWorkbenchWindow()->RemovePerspectiveListener(perspListener.data());
    page->RemovePartListener(partListener.data());
    this->SetPart(IWorkbenchPart::Pointer(nullptr), false);
    this->SetPage(nullptr);
}
ISelection::ConstPointer WindowPartSelectionTracker::GetSelection()
{
  IWorkbenchPage::Pointer page = GetWindow()->GetActivePage();
  if (page)
  {
    return page->GetSelection(GetPartId());
  }
  return ISelection::ConstPointer(0);
}
Beispiel #10
0
void ShowViewHandler::OpenView(const QString& viewId, const QString& secondaryId, IWorkbenchWindow::Pointer activeWorkbenchWindow)
{
  const IWorkbenchPage::Pointer activePage = activeWorkbenchWindow->GetActivePage();
  if (activePage.IsNull())
  {
    return;
  }

  activePage->ShowView(viewId, secondaryId, IWorkbenchPage::VIEW_ACTIVATE);
}
void ShowViewHandler::OpenView(const std::string& viewId, IWorkbenchWindow::Pointer activeWorkbenchWindow)
{
  const IWorkbenchPage::Pointer activePage = activeWorkbenchWindow->GetActivePage();
  if (activePage.IsNull())
  {
    return;
  }

  activePage->ShowView(viewId);
}
void SavePerspectiveHandler::SaveSingleton(const IWorkbenchPage::Pointer& page)
{
  QMessageBox::StandardButton btn =
      QMessageBox::question(page->GetWorkbenchWindow()->GetShell()->GetControl(),
                            "Overwrite perspective",
                            "The current perspective can only be opened once and cannot be saved using a new name. "
                            "Do you want to overwrite?",
                            QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Cancel);
  if (btn == QMessageBox::Ok)
  {
    page->SavePerspective();
  }
}
IIntroPart::Pointer WorkbenchIntroManager::ShowIntro(SmartPointer<
    IWorkbenchWindow> preferredWindow, bool standby)
{
  if (!preferredWindow)
  {
    preferredWindow = this->workbench->GetActiveWorkbenchWindow();
  }

  if (!preferredWindow)
  {
    return IIntroPart::Pointer(nullptr);
  }

  IWorkbenchPart::Pointer part = GetIntroAdapterPart();
  if (!part)
  {
    CreateIntro(preferredWindow);
  }
  else
  {
    try
    {
      IWorkbenchPage::Pointer page = part->GetSite()->GetPage();
      IWorkbenchWindow::Pointer window = page->GetWorkbenchWindow();
      if (window != preferredWindow)
      {
        window->GetShell()->SetActive();
      }

      if (IntroIsView())
      {
        page->ShowView(IntroConstants::INTRO_VIEW_ID);
      }
      else
      {
        IEditorInput::Pointer input(new NullEditorInput());
        page->OpenEditor(input, IntroConstants::INTRO_EDITOR_ID);
      }
    } catch (PartInitException& e)
    {
      //TODO IStatus
//      WorkbenchPlugin::Log("Could not open intro", new Status(IStatus.ERROR,
//          WorkbenchPlugin.PI_WORKBENCH, IStatus.ERROR, "Could not open intro",
//          e)); //$NON-NLS-1$ //$NON-NLS-2$
      WorkbenchPlugin::Log("Could not open intro", e);
    }
  }
  SetIntroStandby(introPart, standby);
  return introPart;
}
bool WorkbenchIntroManager::CloseIntro(IIntroPart::Pointer part)
{
  if (!introPart || introPart != part)
  {
    return false;
  }

  IWorkbenchPart::Pointer introView = GetIntroAdapterPart();
  if (introView)
  {
    //assumption is that there is only ever one intro per workbench
    //if we ever support one per window then this will need revisiting
    IWorkbenchPage::Pointer page = introView->GetSite()->GetPage();
    if (IntroIsView())
    {
      IViewReference::Pointer reference = page->FindViewReference(
          IntroConstants::INTRO_VIEW_ID);
      page->HideView(introView.Cast<IViewPart>());
      if (!reference || reference->GetPart(false) == 0)
      {
        introPart = nullptr;
        return true;
      }
      return 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.empty())
        return false;

      if (page->CloseEditors(references, false))
      {
        introPart = nullptr;
        return true;
      }
      return false;
    }
  }

  // if there is no part then null our reference
  introPart = nullptr;

  return true;
}