Beispiel #1
0
//  for dynamic UI
IMemento::Pointer ViewFactory::SaveViewState(IMemento::Pointer memento,
    IViewReference::Pointer ref, bool& res)
{
  //final MultiStatus result = res;
  bool& result = res;

  IMemento::Pointer viewMemento = memento->CreateChild(
      WorkbenchConstants::TAG_VIEW);
  viewMemento->PutString(WorkbenchConstants::TAG_ID, ViewFactory::GetKey(ref));
  if (ViewReference::Pointer viewRef = ref.Cast<ViewReference>())
  {
    viewMemento->PutString(WorkbenchConstants::TAG_PART_NAME,
        viewRef->GetPartName());
  }
  const IViewReference::Pointer viewRef = ref;
  const IViewPart::Pointer view = ref->GetPart(false).Cast<IViewPart> ();
  if (view)
  {
    ISafeRunnable::Pointer runnable(new SaveViewRunnable(view, viewMemento,
        result));
    SafeRunner::Run(runnable);
  }
  else
  {
    IMemento::Pointer mem;
    IMemento::Pointer props;

    // if we've created the reference once, any previous workbench
    // state memento is there.  After once, there is no previous
    // session state, so it should be null.
    if (ref.Cast<ViewReference> ())
    {
      mem = ref.Cast<ViewReference> ()->GetMemento();
      if (mem)
      {
        props = mem->GetChild(WorkbenchConstants::TAG_PROPERTIES);
        mem = mem->GetChild(WorkbenchConstants::TAG_VIEW_STATE);
      }
    }
    if (props)
    {
      viewMemento->CreateChild(WorkbenchConstants::TAG_PROPERTIES) ->PutMemento(
          props);
    }
    if (mem)
    {
      IMemento::Pointer child = viewMemento ->CreateChild(
          WorkbenchConstants::TAG_VIEW_STATE);
      child->PutMemento(mem);
    }
  }
  return viewMemento;
}
Beispiel #2
0
IMemento::Pointer ViewFactory::GetViewState(const QString& key)
{
  IMemento::Pointer memento = mementoTable[key];

  if (!memento)
    return IMemento::Pointer(nullptr);

  return memento->GetChild(WorkbenchConstants::TAG_VIEW_STATE);
}
SmartPointer<const IStatus> EditorHistoryItem::RestoreState()
{
  Q_ASSERT_X(!IsRestored(), "RestoreState", "already restored");

  IStatus::ConstPointer result = Status::OK_STATUS(BERRY_STATUS_LOC);
  IMemento::Pointer memento = this->memento;
  this->memento = nullptr;

  QString factoryId;
  memento->GetString(WorkbenchConstants::TAG_FACTORY_ID, factoryId);
  if (factoryId.isEmpty())
  {
    WorkbenchPlugin::Log("Unable to restore mru list - no input factory ID.");
    return result;
  }
  QScopedPointer<IElementFactory> factory(
        PlatformUI::GetWorkbench()->GetElementFactory(factoryId));
  if (!factory)
  {
    return result;
  }
  IMemento::Pointer persistableMemento = memento->GetChild(WorkbenchConstants::TAG_PERSISTABLE);
  if (persistableMemento.IsNull())
  {
    WorkbenchPlugin::Log("Unable to restore mru list - no input element state: " + factoryId);
    return result;
  }
  QScopedPointer<IAdaptable> adaptable(factory->CreateElement(persistableMemento));
  if (adaptable == nullptr || dynamic_cast<IEditorInput*>(adaptable.data()) == nullptr)
  {
    return result;
  }
  input = dynamic_cast<IEditorInput*>(adaptable.data());
  // Get the editor descriptor.
  QString editorId;
  memento->GetString(WorkbenchConstants::TAG_ID, editorId);
  if (!editorId.isEmpty())
  {
    IEditorRegistry* registry = WorkbenchPlugin::GetDefault()->GetEditorRegistry();
    descriptor = registry->FindEditor(editorId);
  }
  return result;
}