void DetachedPlaceHolder::RestoreState(IMemento::Pointer memento)
{
  // Read the bounds.
  int x = 0;
  memento->GetInteger(WorkbenchConstants::TAG_X, x);
  int y = 0;
  memento->GetInteger(WorkbenchConstants::TAG_Y, y);
  int width = 0;
  memento->GetInteger(WorkbenchConstants::TAG_WIDTH, width);
  int height = 0;
  memento->GetInteger(WorkbenchConstants::TAG_HEIGHT, height);

  bounds = Rectangle(x, y, width, height);

  // Restore the placeholders.
  std::vector<IMemento::Pointer> childrenMem(memento
         ->GetChildren(WorkbenchConstants::TAG_VIEW));
  for (std::size_t i = 0; i < childrenMem.size(); i++) {
     std::string id;
     childrenMem[i]->GetString(WorkbenchConstants::TAG_ID, id);
     PartPlaceholder::Pointer holder(new PartPlaceholder(id));
     holder->SetContainer(ILayoutContainer::Pointer(this));
     children.push_back(holder);
  }
}
Example #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);
}
Example #3
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;
}
void LeftToRightTabOrder::SaveState(IPresentationSerializer* context,
    IMemento::Pointer memento)
{
  std::vector<IPresentablePart::Pointer> parts(list->GetPartList());

  for (std::vector<IPresentablePart::Pointer>::iterator iter = parts.begin();
       iter != parts.end(); ++iter)
  {
    IMemento::Pointer childMem = memento->CreateChild(WorkbenchConstants::TAG_PART);
    childMem->PutString(WorkbenchConstants::TAG_ID, context->GetId(*iter));
  }
}
void DetachedPlaceHolder::SaveState(IMemento::Pointer memento)
{
  // Save the bounds.
  memento->PutInteger(WorkbenchConstants::TAG_X, bounds.x);
  memento->PutInteger(WorkbenchConstants::TAG_Y, bounds.y);
  memento->PutInteger(WorkbenchConstants::TAG_WIDTH, bounds.width);
  memento->PutInteger(WorkbenchConstants::TAG_HEIGHT, bounds.height);

  // Save the views.
  for (std::list<LayoutPart::Pointer>::iterator i = children.begin();
      i != children.end(); ++i) {
     IMemento::Pointer childMem = memento
             ->CreateChild(WorkbenchConstants::TAG_VIEW);
     childMem->PutString(WorkbenchConstants::TAG_ID, (*i)->GetID());
  }
}
Example #6
0
  void Run() override
  {

    const QHash<QString, QString>& properties =
        view->GetPartProperties();
    if (!properties.empty())
    {
      IMemento::Pointer propBag = viewMemento ->CreateChild(
          WorkbenchConstants::TAG_PROPERTIES);
      for (QHash<QString, QString>::const_iterator i =
          properties.begin(); i != properties.end(); ++i)
      {
        IMemento::Pointer p = propBag->CreateChild(
            WorkbenchConstants::TAG_PROPERTY, i.key());
        p->PutTextData(i.value());
      }
    }

    view->SaveState(viewMemento ->CreateChild(
        WorkbenchConstants::TAG_VIEW_STATE));
  }
Example #7
0
bool ViewFactory::RestoreState(IMemento::Pointer memento)
{
  QList<IMemento::Pointer> mem(memento->GetChildren(
      WorkbenchConstants::TAG_VIEW));
  for (int i = 0; i < mem.size(); i++)
  {
    //for dynamic UI - add the next line to replace subsequent code that is commented out
    RestoreViewState(mem[i]);
  }
  //  return new Status(IStatus.OK, PlatformUI.PLUGIN_ID, 0, "", null); //$NON-NLS-1$
  return true;
}
Example #8
0
  void Run()
  {

    const std::map<std::string, std::string>& properties =
        view->GetPartProperties();
    if (!properties.empty())
    {
      IMemento::Pointer propBag = viewMemento ->CreateChild(
          WorkbenchConstants::TAG_PROPERTIES);
      for (std::map<std::string, std::string>::const_iterator i =
          properties.begin(); i != properties.end(); ++i)
      {
        IMemento::Pointer p = propBag->CreateChild(
            WorkbenchConstants::TAG_PROPERTY, i->first);
        p->PutTextData(i->second);
      }
    }

    view->SaveState(viewMemento ->CreateChild(
        WorkbenchConstants::TAG_VIEW_STATE));
  }
void LeftToRightTabOrder::RestoreState(IPresentationSerializer* serializer,
    IMemento::Pointer savedState)
{
  std::vector<IMemento::Pointer> parts = savedState->GetChildren(
      WorkbenchConstants::TAG_PART);

  for (std::size_t idx = 0; idx < parts.size(); idx++)
  {
    std::string id;
    parts[idx]->GetString(WorkbenchConstants::TAG_ID, id);

    if (!id.empty())
    {
      IPresentablePart::Pointer part = serializer->GetPart(id);

      if (part)
      {
        this->AddInitial(part);
      }
    }
  }
}
Example #10
0
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;
}
Example #11
0
// for dynamic UI
void ViewFactory::RestoreViewState(IMemento::Pointer memento)
{
  QString compoundId;
  memento->GetString(WorkbenchConstants::TAG_ID, compoundId);
  mementoTable.insert(compoundId, memento);
}