diff --git a/BlueBerry/Bundles/org.blueberry.ui/files.cmake b/BlueBerry/Bundles/org.blueberry.ui/files.cmake index 433eb9869e..ef7feb71b7 100644 --- a/BlueBerry/Bundles/org.blueberry.ui/files.cmake +++ b/BlueBerry/Bundles/org.blueberry.ui/files.cmake @@ -1,305 +1,302 @@ set(MOC_H_FILES src/internal/berryWorkbenchPlugin.h src/internal/intro/berryEditorIntroAdapterPart.h src/berryWorkbenchPart.h src/berryEditorPart.h src/berryViewPart.h src/intro/berryIntroPart.h ) set(CACHED_RESOURCE_FILES plugin.xml ) set(SRC_CPP_FILES berryAbstractSourceProvider.cpp berryAbstractUIPlugin.cpp berryAbstractUICTKPlugin.cpp berryConstants.cpp berryDisplay.cpp berryEditorPart.cpp berryFileEditorInput.cpp berryGeometry.cpp berryIDropTargetListener.cpp berryIEditorDescriptor.cpp berryIEditorInput.cpp berryIEditorMatchingStrategy.cpp berryIEditorPart.cpp berryIEditorReference.cpp berryIEditorRegistry.cpp berryIEditorSite.cpp berryIFileEditorMapping.cpp berryIFolderLayout.cpp berryImageDescriptor.cpp berryIMemento.cpp berryINullSelectionListener.cpp berryIPageLayout.cpp berryIPartListener.cpp berryIPageService.cpp berryIPartService.cpp berryIPathEditorInput.cpp berryIPerspectiveDescriptor.cpp berryIPerspectiveFactory.cpp berryIPerspectiveListener.cpp berryIPerspectiveRegistry.cpp berryIPlaceholderFolderLayout.cpp berryIPostSelectionProvider.cpp berryIPreferencePage.cpp berryIPropertyChangeListener.cpp berryIReusableEditor.cpp berryISaveablePart.cpp berryISaveablesLifecycleListener.cpp berryISaveablesSource.cpp berryISelection.cpp berryISelectionChangedListener.cpp berryISelectionListener.cpp berryISelectionProvider.cpp berryISelectionService.cpp berryIShellListener.cpp berryIShellProvider.cpp berryISizeProvider.cpp berryISourceProvider.cpp berryISourceProviderListener.cpp berryISources.cpp berryIStickyViewDescriptor.cpp berryIStructuredSelection.cpp berryIViewCategory.cpp berryIViewDescriptor.cpp berryIViewLayout.cpp berryIViewPart.cpp berryIViewReference.cpp berryIViewRegistry.cpp berryIViewSite.cpp berryIWindowListener.cpp berryIWorkbench.cpp berryIWorkbenchListener.cpp berryIWorkbenchPage.cpp berryIWorkbenchPart.cpp berryIWorkbenchPartConstants.cpp berryIWorkbenchPartDescriptor.cpp berryIWorkbenchPartReference.cpp berryIWorkbenchPartSite.cpp berryIWorkbenchSite.cpp berryIWorkbenchWindow.cpp berryPlatformUI.cpp berryPoint.cpp berryPropertyChangeEvent.cpp berryRectangle.cpp berrySameShellProvider.cpp berrySaveable.cpp berrySaveablesLifecycleEvent.cpp berrySelectionChangedEvent.cpp berryShell.cpp berryShellEvent.cpp berryUIException.cpp berryViewPart.cpp berryWindow.cpp berryWorkbenchPart.cpp berryWorkbenchPreferenceConstants.cpp berryXMLMemento.cpp #application application/berryActionBarAdvisor.cpp application/berryIActionBarConfigurer.cpp application/berryIWorkbenchConfigurer.cpp application/berryIWorkbenchWindowConfigurer.cpp application/berryWorkbenchAdvisor.cpp application/berryWorkbenchWindowAdvisor.cpp #commands #commands/berryAbstractContributionFactory.cpp #commands/berryCommandContributionItem.cpp #commands/berryCommandContributionItemParameter.cpp #commands/berryContributionItem.cpp #commands/berryContributionManager.cpp #commands/berryICommandImageService.cpp #commands/berryICommandService.cpp #commands/berryIContributionManagerOverrides.cpp #commands/berryIMenuItem.cpp #commands/berryIMenuItemListener.cpp #commands/berryIMenuListener.cpp #commands/berryIToolItemListener.cpp #commands/berryIUIElementListener.cpp #commands/berryMenuManager.cpp #commands/berrySubContributionItem.cpp #commands/berryUIElement.cpp #dialogs dialogs/berryIDialog.cpp dialogs/berryIShowViewDialog.cpp dialogs/berryMessageDialog.cpp #guitk guitk/berryGuiTkControlEvent.cpp guitk/berryGuiTkEvent.cpp guitk/berryGuiTkIControlListener.cpp guitk/berryGuiTkIMenuListener.cpp guitk/berryGuiTkISelectionListener.cpp guitk/berryGuiTkSelectionEvent.cpp #handlers handlers/berryHandlerUtil.cpp handlers/berryIHandlerActivation.cpp handlers/berryIHandlerService.cpp handlers/berryShowViewHandler.cpp #src intro/berryIIntroManager.cpp intro/berryIntroPart.cpp intro/berryIIntroPart.cpp intro/berryIIntroSite.cpp #services services/berryIDisposable.cpp services/berryINestable.cpp services/berryIServiceFactory.cpp services/berryIServiceLocator.cpp services/berryIServiceWithSources.cpp #tweaklets tweaklets/berryDnDTweaklet.cpp tweaklets/berryGuiWidgetsTweaklet.cpp tweaklets/berryImageTweaklet.cpp tweaklets/berryMessageDialogTweaklet.cpp tweaklets/berryITracker.cpp tweaklets/berryWorkbenchPageTweaklet.cpp tweaklets/berryWorkbenchTweaklet.cpp #presentations presentations/berryIPresentablePart.cpp presentations/berryIPresentationFactory.cpp presentations/berryIPresentationSerializer.cpp presentations/berryIStackPresentationSite.cpp presentations/berryStackDropResult.cpp presentations/berryStackPresentation.cpp #testing testing/berryTestableObject.cpp #util util/berryISafeRunnableRunner.cpp util/berrySafeRunnable.cpp ) set(INTERNAL_CPP_FILES #intro intro/berryEditorIntroAdapterPart.cpp intro/berryIIntroDescriptor.cpp intro/berryIIntroRegistry.cpp intro/berryIntroConstants.cpp intro/berryIntroDescriptor.cpp intro/berryIntroPartAdapterSite.cpp intro/berryIntroRegistry.cpp intro/berryViewIntroAdapterPart.cpp intro/berryWorkbenchIntroManager.cpp berryAbstractPartSelectionTracker.cpp berryAbstractSelectionService.cpp berryBundleUtility.cpp berryContainerPlaceholder.cpp berryDetachedPlaceHolder.cpp berryDefaultSaveable.cpp berryDefaultStackPresentationSite.cpp berryDetachedWindow.cpp berryDragUtil.cpp berryEditorAreaHelper.cpp berryEditorDescriptor.cpp berryEditorManager.cpp berryEditorReference.cpp berryEditorRegistry.cpp berryEditorRegistryReader.cpp berryEditorSashContainer.cpp berryEditorSite.cpp berryErrorViewPart.cpp berryFileEditorMapping.cpp berryFolderLayout.cpp berryIDragOverListener.cpp berryIDropTarget.cpp berryIEvaluationResultCache.cpp berryIEvaluationResultCache.cpp berryILayoutContainer.cpp - berryILayoutContainer.cpp berryIServiceLocatorCreator.cpp - berryIStackableContainer.cpp berryIStickyViewManager.cpp berryIWorkbenchLocationService.cpp berryIWorkbenchLocationService.cpp berryLayoutHelper.cpp berryLayoutPart.cpp berryLayoutPartSash.cpp berryLayoutTree.cpp berryLayoutTreeNode.cpp berryNullEditorInput.cpp berryPageLayout.cpp berryPagePartSelectionTracker.cpp berryPageSelectionService.cpp berryPartList.cpp berryPartPane.cpp berryPartPlaceholder.cpp berryPartSashContainer.cpp berryPartService.cpp berryPartSite.cpp berryPartStack.cpp berryPartTester.cpp berryPerspective.cpp berryPerspectiveDescriptor.cpp berryPerspectiveExtensionReader.cpp berryPerspectiveHelper.cpp berryPerspectiveRegistry.cpp berryPerspectiveRegistryReader.cpp berryPlaceholderFolderLayout.cpp berryPreferenceConstants.cpp berryPresentablePart.cpp berryPresentationFactoryUtil.cpp berryPresentationSerializer.cpp berryQtControlWidget.cpp berryQtDnDControlWidget.cpp berryQtWidgetController.cpp berryRegistryReader.cpp berrySaveablesList.cpp berryServiceLocator.cpp berryServiceLocatorCreator.cpp berryShellPool.cpp berrySourcePriorityNameMapping.cpp - berryStackablePart.cpp berryStickyViewDescriptor.cpp berryStickyViewManager.cpp berryTweaklets.cpp berryViewDescriptor.cpp berryViewFactory.cpp berryViewLayout.cpp berryViewReference.cpp berryViewRegistry.cpp berryViewRegistryReader.cpp berryViewSashContainer.cpp berryViewSite.cpp berryWorkbenchPage.cpp berryWindowManager.cpp berryWindowPartSelectionTracker.cpp berryWindowSelectionService.cpp berryWorkbench.cpp berryWorkbenchConfigurer.cpp berryWorkbenchConstants.cpp berryWorkbenchPagePartList.cpp berryWorkbenchPartReference.cpp berryWorkbenchPlugin.cpp berryWorkbenchRegistryConstants.cpp berryWorkbenchServiceRegistry.cpp berryWorkbenchTestable.cpp berryWorkbenchWindow.cpp berryWorkbenchWindowConfigurer.cpp berryWWinPartService.cpp ) set(CPP_FILES ) foreach(file ${SRC_CPP_FILES}) set(CPP_FILES ${CPP_FILES} src/${file}) endforeach(file ${SRC_CPP_FILES}) foreach(file ${INTERNAL_CPP_FILES}) set(CPP_FILES ${CPP_FILES} src/internal/${file}) endforeach(file ${INTERNAL_CPP_FILES}) diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryContainerPlaceholder.cpp b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryContainerPlaceholder.cpp index 3974e0e32d..fbe8abdb95 100644 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryContainerPlaceholder.cpp +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryContainerPlaceholder.cpp @@ -1,142 +1,132 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "berryContainerPlaceholder.h" #include "berryPartPlaceholder.h" #include "berryILayoutContainer.h" namespace berry { int ContainerPlaceholder::nextId = 0; ContainerPlaceholder::ContainerPlaceholder(const std::string& id) : - LayoutPart(id == "" ? "Container Placeholder " + nextId++ : id) + PartPlaceholder(id == "" ? "Container Placeholder " + nextId++ : id) { } -void ContainerPlaceholder::CreateControl(void* /*parent*/) -{ - -} - -void* ContainerPlaceholder::GetControl() -{ - return 0; -} - -void ContainerPlaceholder::Add(StackablePart::Pointer child) +void ContainerPlaceholder::Add(LayoutPart::Pointer child) { if (child.Cast() == 0) { return; } realContainer->Add(child); } -bool ContainerPlaceholder::AllowsAdd(StackablePart::Pointer /*toAdd*/) +bool ContainerPlaceholder::AllowsAdd(LayoutPart::Pointer /*toAdd*/) { return false; } -std::list ContainerPlaceholder::GetChildren() const +std::list ContainerPlaceholder::GetChildren() const { return realContainer->GetChildren(); } std::string ContainerPlaceholder::GetID() const { return LayoutPart::GetID(); } -IStackableContainer::Pointer ContainerPlaceholder::GetRealContainer() +LayoutPart::Pointer ContainerPlaceholder::GetRealContainer() { - return realContainer; + return realContainer.Cast(); } -void ContainerPlaceholder::Remove(StackablePart::Pointer child) +void ContainerPlaceholder::Remove(LayoutPart::Pointer child) { if (child.Cast () == 0) { return; } realContainer->Remove(child); } -void ContainerPlaceholder::Replace(StackablePart::Pointer oldChild, - StackablePart::Pointer newChild) +void ContainerPlaceholder::Replace(LayoutPart::Pointer oldChild, + LayoutPart::Pointer newChild) { if (oldChild.Cast() == 0 && newChild.Cast() == 0) { return; } realContainer->Replace(oldChild, newChild); } void ContainerPlaceholder::SetRealContainer( - IStackableContainer::Pointer container) + ILayoutContainer::Pointer container) { if (container == 0) { // set the parent container of the children back to the real container if (realContainer != 0) { - std::list children = realContainer->GetChildren(); - for (std::list::iterator iter = children.begin(); iter + std::list children = realContainer->GetChildren(); + for (std::list::iterator iter = children.begin(); iter != children.end(); ++iter) { (*iter)->SetContainer(realContainer); } } } else { // replace the real container with this place holder - std::list children = container->GetChildren(); - for (std::list::iterator iter = children.begin(); iter + std::list children = container->GetChildren(); + for (std::list::iterator iter = children.begin(); iter != children.end(); ++iter) { - (*iter)->SetContainer(IStackableContainer::Pointer(this)); + (*iter)->SetContainer(ILayoutContainer::Pointer(this)); } } this->realContainer = container; } -void ContainerPlaceholder::FindSashes(PartPane::Sashes& sashes) +void ContainerPlaceholder::FindSashes(LayoutPart::Pointer /*part*/, PartPane::Sashes& sashes) { ILayoutContainer::Pointer container = this->GetContainer(); if (container != 0) { container->FindSashes(LayoutPart::Pointer(this), sashes); } } -void ContainerPlaceholder::ResizeChild(StackablePart::Pointer /*childThatChanged*/) +void ContainerPlaceholder::ResizeChild(LayoutPart::Pointer /*childThatChanged*/) { } bool ContainerPlaceholder::AllowsAutoFocus() { return false; } } diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryContainerPlaceholder.h b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryContainerPlaceholder.h index 849a6149fd..d8cad3d9b4 100644 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryContainerPlaceholder.h +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryContainerPlaceholder.h @@ -1,112 +1,102 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef BERRYCONTAINERPLACEHOLDER_H_ #define BERRYCONTAINERPLACEHOLDER_H_ -#include "berryIStackableContainer.h" -#include "berryLayoutPart.h" +#include "berryILayoutContainer.h" +#include "berryPartPlaceholder.h" #include #include namespace berry { /** * \ingroup org_blueberry_ui_internal * */ -class ContainerPlaceholder : public LayoutPart, public IStackableContainer { +class ContainerPlaceholder : public PartPlaceholder, public ILayoutContainer { private: static int nextId; - IStackableContainer::Pointer realContainer; + ILayoutContainer::Pointer realContainer; public: berryObjectMacro(ContainerPlaceholder); /** * ContainerPlaceholder constructor comment. * @param id java.lang.String * @param label java.lang.String */ ContainerPlaceholder(const std::string& id); - /** - * Creates the SWT control - */ - void CreateControl(void* parent); - - /** - * Get the part control. This method may return null. - */ - void* GetControl(); - /** * add method comment. */ - void Add(StackablePart::Pointer child); + void Add(LayoutPart::Pointer child); - bool AllowsAdd(StackablePart::Pointer toAdd); + bool AllowsAdd(LayoutPart::Pointer toAdd); /** * getChildren method comment. */ - std::list GetChildren() const; + std::list GetChildren() const; std::string GetID() const; /** * getFocus method comment. */ - IStackableContainer::Pointer GetRealContainer(); + LayoutPart::Pointer GetRealContainer(); /** * remove method comment. */ - void Remove(StackablePart::Pointer child); + void Remove(LayoutPart::Pointer child); /** * replace method comment. */ - void Replace(StackablePart::Pointer oldChild, StackablePart::Pointer newChild); + void Replace(LayoutPart::Pointer oldChild, LayoutPart::Pointer newChild); - void SetRealContainer(IStackableContainer::Pointer container); + void SetRealContainer(ILayoutContainer::Pointer container); - void FindSashes(PartPane::Sashes& sashes); + void FindSashes(LayoutPart::Pointer part, PartPane::Sashes& sashes); - void ResizeChild(StackablePart::Pointer childThatChanged); + void ResizeChild(LayoutPart::Pointer childThatChanged); /* (non-Javadoc) * @see org.blueberry.ui.internal.ILayoutContainer#allowsAutoFocus() */ bool AllowsAutoFocus(); /* (non-Javadoc) * @see org.blueberry.ui.internal.ILayoutContainer#isZoomed(org.blueberry.ui.internal.LayoutPart) */ // bool childIsZoomed(LayoutPart toTest) { // return false; // } }; } #endif /*BERRYCONTAINERPLACEHOLDER_H_*/ diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryDetachedPlaceHolder.cpp b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryDetachedPlaceHolder.cpp index 82cc1a3e7c..61a96847a1 100755 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryDetachedPlaceHolder.cpp +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryDetachedPlaceHolder.cpp @@ -1,124 +1,144 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "berryDetachedPlaceHolder.h" #include "berryILayoutContainer.h" #include "berryPartPlaceholder.h" #include "berryWorkbenchConstants.h" namespace berry { DetachedPlaceHolder::DetachedPlaceHolder(const std::string& id, const Rectangle& b) : - ContainerPlaceholder(id), bounds(b) + PartPlaceholder(id), bounds(b) { } -void DetachedPlaceHolder::Add(StackablePart::Pointer newPart) +void DetachedPlaceHolder::Add(LayoutPart::Pointer newPart) { if (newPart.Cast () == 0) { return; } children.push_back(newPart); } bool DetachedPlaceHolder::AllowsBorder() { return false; } +bool DetachedPlaceHolder::AllowsAdd(LayoutPart::Pointer toAdd) +{ + return PartPlaceholder::AllowsAdd(toAdd); +} + +bool DetachedPlaceHolder::AllowsAutoFocus() +{ + return PartPlaceholder::AllowsAutoFocus(); +} + Rectangle DetachedPlaceHolder::GetBounds() { return bounds; } -std::list DetachedPlaceHolder::GetChildren() +std::list DetachedPlaceHolder::GetChildren() { return children; } -void DetachedPlaceHolder::Remove(StackablePart::Pointer part) +void DetachedPlaceHolder::Remove(LayoutPart::Pointer part) { children.remove(part); } -void DetachedPlaceHolder::Replace(StackablePart::Pointer oldPart, - StackablePart::Pointer newPart) +void DetachedPlaceHolder::Replace(LayoutPart::Pointer oldPart, + LayoutPart::Pointer newPart) { this->Remove(oldPart); this->Add(newPart); } 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 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(IStackableContainer::Pointer(this)); + holder->SetContainer(ILayoutContainer::Pointer(this)); children.push_back(holder); } } 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::iterator i = children.begin(); + for (std::list::iterator i = children.begin(); i != children.end(); ++i) { IMemento::Pointer childMem = memento ->CreateChild(WorkbenchConstants::TAG_VIEW); - childMem->PutString(WorkbenchConstants::TAG_ID, (*i)->GetId()); + childMem->PutString(WorkbenchConstants::TAG_ID, (*i)->GetID()); } } void DetachedPlaceHolder::FindSashes(LayoutPart::Pointer /*part*/, PartPane::Sashes& sashes) { ILayoutContainer::Pointer container = this->GetContainer(); if (container != 0) { container->FindSashes(LayoutPart::Pointer(this), sashes); } } +ILayoutContainer::ChildrenType DetachedPlaceHolder::GetChildren() const +{ + return children; +} + +void DetachedPlaceHolder::ResizeChild(LayoutPart::Pointer childThatChanged) +{ + PartPlaceholder::ResizeChild(childThatChanged); +} + } diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryDetachedPlaceHolder.h b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryDetachedPlaceHolder.h index ce3672ce89..df67faceb0 100755 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryDetachedPlaceHolder.h +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryDetachedPlaceHolder.h @@ -1,103 +1,112 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef BERRYDETACHEDPLACEHOLDER_H_ #define BERRYDETACHEDPLACEHOLDER_H_ -#include "berryContainerPlaceholder.h" +#include "berryPartPlaceholder.h" +#include "berryILayoutContainer.h" #include "berryIMemento.h" #include "berryRectangle.h" #include namespace berry { /** * DetachedPlaceHolder is the placeholder for detached views. * */ -class DetachedPlaceHolder : public ContainerPlaceholder +class DetachedPlaceHolder : public PartPlaceholder, public ILayoutContainer { private: - std::list children; + std::list children; Rectangle bounds; public: berryObjectMacro(DetachedPlaceHolder); /** * DetachedPlaceHolder constructor comment. * @param id java.lang.String * @param bounds the size of the placeholder */ DetachedPlaceHolder(const std::string& id, const Rectangle& b); /** * Add a child to the container. */ - void Add(StackablePart::Pointer newPart); + void Add(LayoutPart::Pointer newPart); /** * Return true if the container allows its * parts to show a border if they choose to, * else false if the container does not want * its parts to show a border. * @return boolean */ bool AllowsBorder(); + bool AllowsAdd(LayoutPart::Pointer toAdd); + + bool AllowsAutoFocus(); + Rectangle GetBounds(); /** * Returns a list of layout children. */ - std::list GetChildren(); + std::list GetChildren(); /** * Remove a child from the container. */ - void Remove(StackablePart::Pointer part); + void Remove(LayoutPart::Pointer part); /** * Replace one child with another */ - void Replace(StackablePart::Pointer oldPart, StackablePart::Pointer newPart); + void Replace(LayoutPart::Pointer oldPart, LayoutPart::Pointer newPart); /** * Restore the state from the memento. * @param memento */ void RestoreState(IMemento::Pointer memento); /** * Save state to the memento. * @param memento */ void SaveState(IMemento::Pointer memento); void FindSashes(LayoutPart::Pointer part, PartPane::Sashes& sashes); + ILayoutContainer::ChildrenType GetChildren() const; + + void ResizeChild(LayoutPart::Pointer childThatChanged); + }; } #endif /* BERRYDETACHEDPLACEHOLDER_H_ */ diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryDetachedWindow.cpp b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryDetachedWindow.cpp index f55c3c36c1..8b6cf975f0 100755 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryDetachedWindow.cpp +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryDetachedWindow.cpp @@ -1,544 +1,544 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "berryDetachedWindow.h" #include "berryIWorkbenchPartConstants.h" #include "berryISaveablePart.h" #include "berryWorkbenchWindow.h" #include "tweaklets/berryGuiWidgetsTweaklet.h" #include "berryWorkbenchConstants.h" #include "berryEditorManager.h" #include "berryDragUtil.h" namespace berry { DetachedWindow::ShellListener::ShellListener(DetachedWindow* wnd) : window(wnd) { } void DetachedWindow::ShellListener::ShellClosed(ShellEvent::Pointer e) { // hold on to a reference of the DetachedWindow instance // (otherwise, wnd->HandleClose() woulde delete the DetachedWindow // instance too early, trying to write to members afterwards) DetachedWindow::Pointer wnd(window); // only continue to close if the handleClose // wasn't canceled e->doit = wnd->HandleClose(); } DetachedWindow::ShellControlListener::ShellControlListener(DetachedWindow* wnd) : window(wnd) { } GuiTk::IControlListener::Events::Types DetachedWindow::ShellControlListener::GetEventTypes() const { return Events::RESIZED; } void DetachedWindow::ShellControlListener::ControlResized( GuiTk::ControlEvent::Pointer e) { window->folder->SetBounds( Tweaklets::Get(GuiWidgetsTweaklet::KEY)->GetClientArea(e->item)); } DetachedWindow::DetachedWindow(WorkbenchPage* workbenchPage) { shellListener = new ShellListener(this); resizeListener = new ShellControlListener(this); this->page = workbenchPage; hideViewsOnClose = true; folder = new PartStack(page, false); } void DetachedWindow::PropertyChange(Object::Pointer /*source*/, int propId) { if (propId == IWorkbenchPartConstants::PROP_TITLE) { this->UpdateTitle(); } else if (propId == PartStack::PROP_SELECTION) { this->ActivePartChanged(this->GetPartReference(folder->GetSelection())); } } Shell::Pointer DetachedWindow::GetShell() { return windowShell; } void DetachedWindow::Create() { folder->AddListener(IPropertyChangeListener::Pointer(this)); windowShell = page->GetWorkbenchWindow().Cast () ->GetDetachedWindowPool()->AllocateShell( shellListener); windowShell->SetData(Object::Pointer(this)); windowShell->SetText(""); //$NON-NLS-1$ DragUtil::AddDragTarget(windowShell->GetControl(), IDragOverListener::Pointer(this)); hideViewsOnClose = true; if (bounds.IsEmpty()) { Rectangle windowRect = page->GetWorkbenchWindow()->GetShell()->GetBounds(); Point center(windowRect.x + windowRect.width / 2, windowRect.y - windowRect.height / 2); bounds = Rectangle(center.x - 150, center.y + 100, 300, 200); } // Force the rect into the current display Rectangle dispBounds = Tweaklets::Get(GuiWidgetsTweaklet::KEY)->GetAvailableScreenSize(); if (bounds.width > dispBounds.width) bounds.width = dispBounds.width; if (bounds.height > dispBounds.height) bounds.height = dispBounds.height; if (bounds.x + bounds.width > dispBounds.width) bounds.x = dispBounds.width - bounds.width; if (bounds.y + bounds.height > dispBounds.height) bounds.y = dispBounds.height - bounds.height; this->GetShell()->SetBounds(bounds); this->ConfigureShell(windowShell); this->CreateContents(windowShell->GetControl()); //windowShell->Layout(true); //folder->SetBounds(Tweaklets::Get(GuiWidgetsTweaklet::KEY)->GetClientArea(windowShell->GetControl())); } -void DetachedWindow::Add(StackablePart::Pointer part) +void DetachedWindow::Add(LayoutPart::Pointer part) { Shell::Pointer shell = this->GetShell(); if (shell != 0) { part->Reparent(shell->GetControl()); } folder->Add(part); this->UpdateMinimumSize(); } bool DetachedWindow::BelongsToWorkbenchPage( IWorkbenchPage::Pointer workbenchPage) { return (workbenchPage == this->page); } bool DetachedWindow::Close() { hideViewsOnClose = false; Shell::Pointer shell = this->GetShell(); if (shell != 0) { shell->Close(); } return true; } IDropTarget::Pointer DetachedWindow::Drag(void* /*currentControl*/, Object::Pointer draggedObject, const Point& position, const Rectangle& /*dragRectangle*/) { if (draggedObject.Cast () == 0) { return IDropTarget::Pointer(0); } PartPane::Pointer sourcePart = draggedObject.Cast (); if (sourcePart->GetWorkbenchWindow() != page->GetWorkbenchWindow()) { return IDropTarget::Pointer(0); } // Only handle the event if the source part is acceptable to the particular PartStack IDropTarget::Pointer target; if (folder->AllowsDrop(sourcePart)) { target = folder->GetDropTarget(draggedObject, position); if (target == 0) { Rectangle displayBounds = DragUtil::GetDisplayBounds(folder->GetControl()); if (displayBounds.Contains(position)) { StackDropResult::Pointer stackDropResult(new StackDropResult( displayBounds, Object::Pointer(0))); target = folder->CreateDropTarget(sourcePart, stackDropResult); } else { return IDropTarget::Pointer(0); } } } return target; } -IStackableContainer::ChildrenType DetachedWindow::GetChildren() const +ILayoutContainer::ChildrenType DetachedWindow::GetChildren() const { return folder->GetChildren(); } WorkbenchPage::Pointer DetachedWindow::GetWorkbenchPage() { return WorkbenchPage::Pointer(this->page); } void DetachedWindow::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); // memento->GetInteger(WorkbenchConstants::TAG_FLOAT); // Set the bounds. bounds = Rectangle(x, y, width, height); if (GetShell()) { GetShell()->SetBounds(bounds); } // Create the folder. IMemento::Pointer childMem = memento->GetChild(WorkbenchConstants::TAG_FOLDER); if (childMem) { folder->RestoreState(childMem); } } void DetachedWindow::SaveState(IMemento::Pointer memento) { if (GetShell()) { bounds = GetShell()->GetBounds(); } // 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. IMemento::Pointer childMem = memento->CreateChild( WorkbenchConstants::TAG_FOLDER); folder->SaveState(childMem); } void* DetachedWindow::GetControl() { return folder->GetControl(); } int DetachedWindow::Open() { if (this->GetShell() == 0) { this->Create(); } Rectangle bounds = this->GetShell()->GetBounds(); if (!(bounds == this->GetShell()->GetBounds())) { this->GetShell()->SetBounds(bounds); } this->GetShell()->SetVisible(true); folder->SetBounds(Tweaklets::Get(GuiWidgetsTweaklet::KEY)->GetClientArea(this->GetShell()->GetControl())); return 0; } void DetachedWindow::ActivePartChanged( IWorkbenchPartReference::Pointer partReference) { if (activePart == partReference) { return; } if (activePart != 0) { activePart->RemovePropertyListener(IPropertyChangeListener::Pointer(this)); } activePart = partReference; if (partReference != 0) { partReference->AddPropertyListener(IPropertyChangeListener::Pointer(this)); } this->UpdateTitle(); } void DetachedWindow::ConfigureShell(Shell::Pointer shell) { this->UpdateTitle(); Tweaklets::Get(GuiWidgetsTweaklet::KEY)->AddControlListener( shell->GetControl(), resizeListener); //shell.addListener(SWT.Activate, activationListener); //shell.addListener(SWT.Deactivate, activationListener); //TODO DetachedWindow key bindings // // Register this detached view as a window (for key bindings). // IContextService contextService = (IContextService) getWorkbenchPage() // .getWorkbenchWindow().getWorkbench().getService(IContextService.class); // contextService.registerShell(shell, IContextService.TYPE_WINDOW); // // page.getWorkbenchWindow().getWorkbench().getHelpSystem().setHelp(shell, // IWorkbenchHelpContextIds.DETACHED_WINDOW); } void* DetachedWindow::CreateContents(void* parent) { // Create the tab folder. folder->CreateControl(parent); // Reparent each view in the tab folder. std::list detachedChildren; this->CollectViewPanes(detachedChildren, this->GetChildren()); for (std::list::iterator itr = detachedChildren.begin(); itr != detachedChildren.end(); ++itr) { PartPane::Pointer part = *itr; part->Reparent(parent); } //TODO DetachedWindow listen to folder events (update size?) // if (folder->GetPresentation() // instanceof TabbedStackPresentation) // { // TabbedStackPresentation stack = (TabbedStackPresentation) folder.getPresentation(); // AbstractTabFolder tabFolder = stack.getTabFolder(); // tabFolder.addListener(new TabFolderListener() // { // public void handleEvent(TabFolderEvent e) // { // switch (e.type) // { // case TabFolderEvent.EVENT_CLOSE: // { // updateMinimumSize(); // break; // } // case TabFolderEvent.EVENT_PREFERRED_SIZE: // { // updateMinimumSize(); // break; // } // } // } // }); // } // Return tab folder control. return folder->GetControl(); } void DetachedWindow::UpdateTitle() { if (activePart != 0) { // Uncomment to set the shell title to match the title of the active part // String text = activePart.getTitle(); // // if (!text.equals(s.getText())) { // s.setText(text); // } } } void DetachedWindow::UpdateMinimumSize() { // // We can only do this for 'Tabbed' stacked presentations. // if (folder.getPresentation().Cast() != 0) // { // TabbedStackPresentation stack = (TabbedStackPresentation) folder.getPresentation(); // // if (stack->GetPartList().size() == 1) // { // // Get the minimum space required for the part // int width = stack->ComputePreferredSize(true, Constants::INF, Constants::INF, 0); // int height = stack->ComputePreferredSize(false, Constants::INF, Constants::INF, 0); // // // Take the current shell 'trim' into account // int shellHeight = windowShell->GetBounds().height - windowShell->GetClientArea().height; // int shellWidth = windowShell->GetBounds().width - windowShell->GetClientArea().width; // // windowShell->SetMinimumSize(width + shellWidth, height + shellHeight); // } // } } IWorkbenchPartReference::Pointer DetachedWindow::GetPartReference( - StackablePart::Pointer pane) + LayoutPart::Pointer pane) { if (pane == 0 || pane.Cast () == 0) { return IWorkbenchPartReference::Pointer(0); } return pane.Cast ()->GetPartReference(); } bool DetachedWindow::HandleClose() { if (hideViewsOnClose) { std::list views; this->CollectViewPanes(views, this->GetChildren()); // Save any dirty views if (!this->HandleSaves(views)) { return false; // User canceled the save } // OK, go on with the closing for (std::list::iterator itr = views.begin(); itr != views.end(); ++itr) { PartPane::Pointer child = *itr; // Only close if closable... if (child->IsCloseable()) { page->HideView(child->GetPartReference().Cast ()); // Was the close cancelled? if (child->GetContainer() != 0) return false; } else { page->AttachView(child->GetPartReference().Cast ()); } } } if (folder != 0) { folder->Dispose(); } if (windowShell != 0) { Tweaklets::Get(GuiWidgetsTweaklet::KEY)->RemoveControlListener( windowShell->GetControl(), resizeListener); // windowShell.removeListener(SWT.Activate, activationListener); // windowShell.removeListener(SWT.Deactivate, activationListener); DragUtil::RemoveDragTarget(windowShell->GetControl(), IDragOverListener::Pointer(this)); bounds = windowShell->GetBounds(); //TODO DetachedWindow unregister key bindings // // Unregister this detached view as a window (for key bindings). // final IContextService contextService = (IContextService) getWorkbenchPage().getWorkbenchWindow().getWorkbench().getService(IContextService.class); // contextService.unregisterShell(windowShell); windowShell->SetData(Object::Pointer(0)); windowShell = 0; } return true; } bool DetachedWindow::HandleSaves(std::list views) { std::vector dirtyViews; for (std::list::iterator iterator = views.begin(); iterator != views.end(); ++iterator) { PartPane::Pointer pane = *iterator; IViewReference::Pointer ref = pane->GetPartReference().Cast (); IViewPart::Pointer part = ref->GetView(false); if (part.Cast () != 0) { ISaveablePart::Pointer saveable = part.Cast (); if (saveable->IsDirty() && saveable->IsSaveOnCloseNeeded()) { dirtyViews.push_back(part); } } } // If there are any prompt to save -before- any closing happens // FIXME: This code will result in a double prompt if the user // decides not to save a particular view at this stage they'll // get a second one from the 'hideView' call... if (dirtyViews.size() > 0) { IWorkbenchWindow::Pointer window = page->GetWorkbenchWindow(); bool success = EditorManager::SaveAll(dirtyViews, true, true, false, window); if (!success) { return false; // the user canceled. } } return true; } void DetachedWindow::CollectViewPanes(std::list& result, - const std::list& parts) + const std::list& parts) { - for (std::list::const_iterator iter = parts.begin(); iter + for (std::list::const_iterator iter = parts.begin(); iter != parts.end(); ++iter) { - StackablePart::Pointer part = *iter; + LayoutPart::Pointer part = *iter; if (part.Cast () != 0) { result.push_back(part.Cast ()); } } } } diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryDetachedWindow.h b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryDetachedWindow.h index 99000dd580..5e9e15c7b3 100755 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryDetachedWindow.h +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryDetachedWindow.h @@ -1,198 +1,198 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef BERRYDETACHEDWINDOW_H_ #define BERRYDETACHEDWINDOW_H_ #include "berryPartStack.h" #include "berryWorkbenchPage.h" #include "berryLayoutPart.h" #include "berryIDragOverListener.h" #include "berryIShellListener.h" #include "guitk/berryGuiTkIControlListener.h" #include "berryRectangle.h" #include "berryShell.h" namespace berry { /** * TODO: Drag from detached to fast view bar back to detached causes NPE * * @since 3.1 */ class DetachedWindow: public IPropertyChangeListener, public IDragOverListener { public: berryObjectMacro(DetachedWindow); private: PartStack::Pointer folder; WorkbenchPage* page; Rectangle bounds; Shell::Pointer windowShell; bool hideViewsOnClose; struct ShellListener: public IShellListener { ShellListener(DetachedWindow* wnd); void ShellClosed(ShellEvent::Pointer e); private: DetachedWindow* window; }; IShellListener::Pointer shellListener; struct ShellControlListener: public GuiTk::IControlListener { ShellControlListener(DetachedWindow* wnd); Events::Types GetEventTypes() const; void ControlResized(GuiTk::ControlEvent::Pointer e); private: DetachedWindow* window; }; GuiTk::IControlListener::Pointer resizeListener; // Listener activationListener = new Listener() { // public void handleEvent(Event event) { // switch (event.type) { // case SWT.Activate: // page.window.liftRestrictions(); // break; // case SWT.Deactivate: // page.window.imposeRestrictions(); // break; // } // } // }; IWorkbenchPartReference::Pointer activePart; public: /** * Create a new FloatingWindow. */ DetachedWindow(WorkbenchPage* workbenchPage); void PropertyChange(Object::Pointer source, int propId); Shell::Pointer GetShell(); void Create(); /** * Adds a visual part to this window. * Supports reparenting. */ - void Add(StackablePart::Pointer part); + void Add(LayoutPart::Pointer part); bool BelongsToWorkbenchPage(IWorkbenchPage::Pointer workbenchPage); bool Close(); /* * @see org.blueberry.ui.internal.IDragOverListener#Drag(void*, Object::Pointer, const Point&, const Rectangle& ) */ IDropTarget::Pointer Drag(void* currentControl, Object::Pointer draggedObject, const Point& position, const Rectangle& dragRectangle); - IStackableContainer::ChildrenType GetChildren() const; + ILayoutContainer::ChildrenType GetChildren() const; WorkbenchPage::Pointer GetWorkbenchPage(); /** * @see IPersistablePart */ void RestoreState(IMemento::Pointer memento); /** * @see IPersistablePart */ void SaveState(IMemento::Pointer memento); void* GetControl(); /** * Opens the detached window. */ int Open(); protected: void ActivePartChanged(IWorkbenchPartReference::Pointer partReference); /** * This method will be called to initialize the given Shell's layout */ void ConfigureShell(Shell::Pointer shell); /** * Override this method to create the widget tree that is used as the window's contents. */ void* CreateContents(void* parent); private: void UpdateTitle(); /** * Ensure that the shell's minimum size is equal to the minimum size * of the first part added to the shell. */ void UpdateMinimumSize(); static IWorkbenchPartReference::Pointer GetPartReference( - StackablePart::Pointer pane); + LayoutPart::Pointer pane); /** * Closes this window and disposes its shell. */ bool HandleClose(); /** * Prompts for and handles the saving of dirty, saveable views * @param views The list of ViewPanes * @return true unless the user cancels the save(s) */ bool HandleSaves(std::list views); /** * Answer a list of the view panes. */ void CollectViewPanes(std::list& result, - const std::list& parts); + const std::list& parts); }; } #endif /* BERRYDETACHEDWINDOW_H_ */ diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryEditorAreaHelper.cpp b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryEditorAreaHelper.cpp index 2ce24cbfaa..94c46c3410 100755 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryEditorAreaHelper.cpp +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryEditorAreaHelper.cpp @@ -1,267 +1,267 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "berryEditorAreaHelper.h" #include "berryEditorSashContainer.h" #include "berryPartSite.h" #include "berryIPageLayout.h" #include "berryPartPane.h" namespace berry { void EditorAreaHelper::CloseEditor(PartPane::Pointer pane) { if (pane != 0) { editorArea->RemoveEditor(pane); } } void EditorAreaHelper::AddToLayout(PartPane::Pointer pane, PartStack::Pointer stack) { //EditorStack stack = editorArea.getActiveWorkbook(); pane->SetContainer(stack); editorArea->AddEditor(pane, stack); } EditorAreaHelper::EditorAreaHelper(WorkbenchPage* page) { this->editorArea = new EditorSashContainer(IPageLayout::ID_EDITOR_AREA, page, page->GetClientComposite()); this->editorArea->CreateControl(page->GetClientComposite()); this->editorArea->SetActive(true); } void EditorAreaHelper::DisplayEditorList() { PartStack::Pointer activeWorkbook = editorArea->GetActiveWorkbook(); if (activeWorkbook != 0) { activeWorkbook->ShowPartList(); } } void EditorAreaHelper::CloseEditor(IEditorReference::Pointer ref) { PartPane::Pointer pane = ref.Cast()->GetPane(); this->CloseEditor(pane); } void EditorAreaHelper::CloseEditor(IEditorPart::Pointer part) { PartPane::Pointer pane = part->GetSite().Cast()->GetPane(); this->CloseEditor(pane); } -void EditorAreaHelper::DerefPart(StackablePart::Pointer part) +void EditorAreaHelper::DerefPart(LayoutPart::Pointer part) { // Get vital part stats before reparenting. - IStackableContainer::Pointer oldContainer = part->GetContainer(); + ILayoutContainer::Pointer oldContainer = part->GetContainer(); // Reparent the part back to the main window //part.reparent(editorArea.getParent()); // Update container. if (oldContainer == 0) { return; } oldContainer->Remove(part); - std::list children = oldContainer->GetChildren(); + std::list children = oldContainer->GetChildren(); if (children.empty()) { // There are no more children in this container, so get rid of it if (oldContainer.Cast()) { LayoutPart::Pointer parent = oldContainer.Cast(); ILayoutContainer::Pointer parentContainer = parent->GetContainer(); if (parentContainer != 0) { parentContainer->Remove(parent); parent->Dispose(); } } } } EditorAreaHelper::~EditorAreaHelper() { if (editorArea != 0) { editorArea->SetActive(false); editorArea->Dispose(); } } std::string EditorAreaHelper::GetActiveEditorWorkbookID() { return editorArea->GetActiveWorkbookID(); } PartStack::Pointer EditorAreaHelper::GetActiveWorkbook() { return editorArea->GetActiveWorkbook(); } LayoutPart::Pointer EditorAreaHelper::GetLayoutPart() { LayoutPart::Pointer layoutPart = editorArea.Cast(); return layoutPart; } IEditorReference::Pointer EditorAreaHelper::GetVisibleEditor() { PartStack::Pointer activeWorkbook = editorArea->GetActiveWorkbook(); PartPane::Pointer pane = activeWorkbook->GetSelection().Cast(); if (pane != 0) { IEditorReference::Pointer result = pane->GetPartReference().Cast(); return result; } return IEditorReference::Pointer(0); } void EditorAreaHelper::MoveEditor(IEditorPart::Pointer /*part*/, int /*position*/) { ///*EditorPane pane = (EditorPane)*/((EditorSite) part.getSite()).getPane(); //TODO commented this out during presentations works //pane.getWorkbook().reorderTab(pane, position); } void EditorAreaHelper::AddEditor(EditorReference::Pointer ref, const std::string& workbookId) { std::list refs = editorArea->GetPage()->GetEditorReferences(); for (std::list::iterator iter = refs.begin(); iter != refs.end(); ++iter) { if (ref == (*iter)) { return; } } PartStack::Pointer stack = this->GetWorkbookFromID(workbookId); if (stack == 0) { stack = this->GetActiveWorkbook(); } this->AddToLayout(ref->GetPane(), stack); editorArea->GetPage()->PartAdded(ref); } bool EditorAreaHelper::RestoreState(IMemento::Pointer memento) { // Restore the editor area workbooks layout/relationship return editorArea->RestoreState(memento); } bool EditorAreaHelper::RestorePresentationState(IMemento::Pointer areaMem) { return editorArea->RestorePresentationState(areaMem); } bool EditorAreaHelper::SaveState(IMemento::Pointer memento) { // Save the editor area workbooks layout/relationship return editorArea->SaveState(memento); } void EditorAreaHelper::SetActiveEditorWorkbookFromID(const std::string& id) { editorArea->SetActiveWorkbookFromID(id); } void EditorAreaHelper::SetActiveWorkbook(PartStack::Pointer workbook, bool hasFocus) { editorArea->SetActiveWorkbook(workbook, hasFocus); } bool EditorAreaHelper::SetVisibleEditor(IEditorReference::Pointer ref, bool setFocus) { IEditorReference::Pointer visibleEditor = this->GetVisibleEditor(); if (ref != visibleEditor) { IWorkbenchPart::Pointer part = ref->GetPart(true); PartPane::Pointer pane; if (part != 0) { pane = part->GetSite().Cast()->GetPane(); } if (pane != 0) { pane->GetContainer().Cast()->SetSelection(pane); if (setFocus) { part->SetFocus(); } return true; } } return false; } std::list EditorAreaHelper::GetWorkbooks() { return editorArea->GetEditorWorkbooks(); } std::list EditorAreaHelper::GetEditors() { std::list result; std::list workbooks = editorArea->GetEditorWorkbooks(); for (std::list::iterator iter = workbooks.begin(); iter != workbooks.end(); ++iter) { PartStack::Pointer stack = *iter; - std::list children = stack->GetChildren(); + std::list children = stack->GetChildren(); - for (std::list::iterator childIter = children.begin(); + for (std::list::iterator childIter = children.begin(); childIter != children.end(); ++childIter) { - StackablePart::Pointer part = *childIter; + LayoutPart::Pointer part = *childIter; result.push_back(part.Cast()->GetPartReference().Cast()); } } return result; } PartStack::Pointer EditorAreaHelper::GetWorkbookFromID(const std::string& workbookId) { return editorArea->GetWorkbookFromID(workbookId); } void EditorAreaHelper::UpdateStackButtons() { editorArea->UpdateStackButtons(); } } diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryEditorAreaHelper.h b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryEditorAreaHelper.h index d4fb5ee0d6..c8893db2d1 100755 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryEditorAreaHelper.h +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryEditorAreaHelper.h @@ -1,175 +1,175 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef BERRYEDITORAREAHELPER_H_ #define BERRYEDITORAREAHELPER_H_ #include "berryLayoutPart.h" -#include "berryStackablePart.h" +#include "berryLayoutPart.h" #include "berryEditorReference.h" #include #include namespace berry { class EditorSashContainer; class WorkbenchPage; class PartPane; class PartStack; /** * EditorAreaHelper is a wrapper for PartTabworkbook. */ class EditorAreaHelper { //private ArrayList editorTable = new ArrayList(4); private: SmartPointer editorArea; /** * Closes an editor. * * @param part the editor to close */ void CloseEditor(SmartPointer pane); void AddToLayout(SmartPointer pane, SmartPointer stack); public: /** * Creates a new EditorAreaHelper. */ EditorAreaHelper(WorkbenchPage* page); /** * Displays a list of open editors */ void DisplayEditorList(); /** * Closes an editor. * * @param part the editor to close */ void CloseEditor(IEditorReference::Pointer ref); /** * Closes an editor. * * @param part the editor to close */ void CloseEditor(IEditorPart::Pointer part); /** * Deref a given part. Deconstruct its container as required. * Do not remove drag listeners. */ - static void DerefPart(StackablePart::Pointer part); + static void DerefPart(LayoutPart::Pointer part); /** * Dispose of the editor presentation. */ ~EditorAreaHelper(); /** * @see IEditorPresentation */ std::string GetActiveEditorWorkbookID(); SmartPointer GetActiveWorkbook(); /** * Returns the editor area. */ LayoutPart::Pointer GetLayoutPart(); /** * Returns the active editor in this perspective. If the editors appear * in a workbook this will be the visible editor. If the editors are * scattered around the workbench this will be the most recent editor * to hold focus. * * @return the active editor, or null if no editor is active */ IEditorReference::Pointer GetVisibleEditor(); void MoveEditor(IEditorPart::Pointer part, int position); /** * Main entry point for adding an editor. Adds the editor to the layout in the given * stack, and notifies the workbench page when done. * * @param ref editor to add * @param workbookId workbook that will contain the editor (or null if the editor * should be added to the default workbook) */ void AddEditor(EditorReference::Pointer ref, const std::string& workbookId); /** * @see IPersistablePart */ bool RestoreState(IMemento::Pointer memento); /** * Restore the presentation * @param areaMem * @return */ bool RestorePresentationState(IMemento::Pointer areaMem); /** * @see IPersistablePart */ bool SaveState(IMemento::Pointer memento); /** * @see IEditorPresentation */ void SetActiveEditorWorkbookFromID(const std::string& id); void SetActiveWorkbook(SmartPointer workbook, bool hasFocus); /** * Brings an editor to the front and optionally gives it focus. * * @param part the editor to make visible * @param setFocus whether to give the editor focus * @return true if the visible editor was changed, false if not. */ bool SetVisibleEditor(IEditorReference::Pointer ref, bool setFocus); /** * Method getWorkbooks. * @return ArrayList */ std::list > GetWorkbooks(); std::list GetEditors(); SmartPointer GetWorkbookFromID(const std::string& workbookId); void UpdateStackButtons(); }; } #endif /* BERRYEDITORAREAHELPER_H_ */ diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryEditorManager.cpp b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryEditorManager.cpp index 0711758e21..fe07e209bc 100644 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryEditorManager.cpp +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryEditorManager.cpp @@ -1,1295 +1,1295 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "berryEditorManager.h" #include "berryIWorkbenchPart.h" #include "berryIWorkbenchWindow.h" #include "berryIEditorRegistry.h" #include "berryUIException.h" #include "berryWorkbenchWindow.h" #include "berryWorkbenchPage.h" #include "berryEditorSite.h" #include "berryEditorReference.h" #include "berryWorkbenchPlugin.h" #include "berryWorkbenchConstants.h" #include "berryNullEditorInput.h" #include "berryEditorAreaHelper.h" #include "berryPartStack.h" #include namespace berry { const std::string EditorManager::PIN_EDITOR_KEY = "PIN_EDITOR"; const std::string EditorManager::RESOURCES_TO_SAVE_MESSAGE = "Select resources to save:"; const std::string EditorManager::SAVE_RESOURCES_TITLE = "Save Resources"; EditorManager::EditorManager(WorkbenchWindow::Pointer wind, WorkbenchPage::Pointer workbenchPage, EditorAreaHelper* pres) : editorPresentation(pres), window(wind.GetPointer()), page(workbenchPage.GetPointer()) { poco_check_ptr(editorPresentation); poco_assert(window != 0); poco_assert(page != 0); //page.getExtensionTracker().registerHandler(this, null); } void EditorManager::CheckDeleteEditorResources() { // // get the current number of editors // IEditorReference[] editors = page.getEditorReferences(); // // If there are no editors // if (editors.length == 0) // { // if (editorPropChangeListnener != null) // { // // remove property change listener for editors // IPreferenceStore prefStore = WorkbenchPlugin.getDefault() // .getPreferenceStore(); // prefStore // .removePropertyChangeListener(editorPropChangeListnener); // editorPropChangeListnener = null; // } // if (pinEditorHandlerActivation != null) // { // // remove pin editor keyboard shortcut handler // final IHandlerService handlerService = (IHandlerService) window.getWorkbench().getService(IHandlerService.class); // handlerService.deactivateHandler(pinEditorHandlerActivation); // pinEditorHandlerActivation = null; // } // } } //void EditorManager::CheckCreateEditorPropListener() //{ // if (editorPropChangeListnener == null) // { // // Add a property change listener for closing editors automatically // // preference // // Add or remove the pin icon accordingly // editorPropChangeListnener = new IPropertyChangeListener() // { // public void propertyChange(PropertyChangeEvent event) // { // if (event.getProperty().equals( // IPreferenceConstants.REUSE_EDITORS_BOOLEAN)) // { // IEditorReference[] editors = getEditors(); // for (int i = 0; i < editors.length; i++) // { // ((EditorReference) editors[i]).pinStatusUpdated(); // } // } // } // }; // WorkbenchPlugin.getDefault().getPreferenceStore() // .addPropertyChangeListener(editorPropChangeListnener); // } //} //void EditorManager::CheckCreatePinEditorShortcutKeyHandler() //{ // if (pinEditorHandlerActivation == null) // { // final Shell shell = window.getShell(); // final IHandler pinEditorHandler = new AbstractHandler() // { // public final Object execute(final ExecutionEvent event) // { // // check if the "Close editors automatically" preference is // // set // IPreferenceStore store = WorkbenchPlugin.getDefault().getPreferenceStore(); // if (store // .getBoolean(IPreferenceConstants.REUSE_EDITORS_BOOLEAN) // || ((TabBehaviour)Tweaklets.get(TabBehaviour.KEY)).alwaysShowPinAction()) // { // // IWorkbenchPartReference ref = editorPresentation // .getVisibleEditor(); // if (ref instanceof WorkbenchPartReference) // { // WorkbenchPartReference concreteRef = (WorkbenchPartReference) ref; // // concreteRef.setPinned(concreteRef.isPinned()); // } // } // return null; // } // }; // // // Assign the handler for the pin editor keyboard shortcut. // final IHandlerService handlerService = (IHandlerService) window.getWorkbench().getService(IHandlerService.class); // pinEditorHandlerActivation = handlerService.activateHandler( // "org.blueberry.ui.window.pinEditor", pinEditorHandler, //$NON-NLS-1$ // new ActiveShellExpression(shell)); // } //} std::vector EditorManager::CollectDirtyEditors() { std::vector result; std::list editors(page->GetEditorReferences()); for (std::list::iterator i = editors.begin(); i != editors.end(); ++i) { IEditorPart::Pointer part = (*i)->GetPart(false).Cast(); if (part.IsNotNull() && part->IsDirty()) { result.push_back(part); } } return result; } bool EditorManager::ContainsEditor(IEditorReference::Pointer ref) { std::list editors(page->GetEditorReferences()); return std::find(editors.begin(), editors.end(), ref) != editors.end(); } //EditorActionBars* EditorManager::CreateEditorActionBars( // EditorDescriptor::Pointer desc, IEditorSite::Pointer site) //{ // // Get the editor type. // String type = desc.getId(); // // // If an action bar already exists for this editor type return it. // EditorActionBars actionBars = (EditorActionBars) actionCache.get(type); // if (actionBars != null) // { // actionBars.addRef(); // return actionBars; // } // // // Create a new action bar set. // actionBars = new EditorActionBars(page, site.getWorkbenchWindow(), type); // actionBars.addRef(); // actionCache.put(type, actionBars); // // // Read base contributor. // IEditorActionBarContributor contr = desc.createActionBarContributor(); // if (contr != null) // { // actionBars.setEditorContributor(contr); // contr.init(actionBars, page); // } // // // Read action extensions. // EditorActionBuilder builder = new EditorActionBuilder(); // contr = builder.readActionExtensions(desc); // if (contr != null) // { // actionBars.setExtensionContributor(contr); // contr.init(actionBars, page); // } // // // Return action bars. // return actionBars; //} //EditorActionBars* EditorManager::CreateEmptyEditorActionBars( // IEditorSite::Pointer site) //{ // // Get the editor type. // String type = String.valueOf(System.currentTimeMillis()); // // // Create a new action bar set. // // Note: It is an empty set. // EditorActionBars actionBars = new EditorActionBars(page, site.getWorkbenchWindow(), type); // actionBars.addRef(); // actionCache.put(type, actionBars); // // // Return action bars. // return actionBars; //} //void EditorManager::DisposeEditorActionBars(EditorActionBars* actionBars) //{ // actionBars.removeRef(); // if (actionBars.getRef() <= 0) // { // String type = actionBars.getEditorType(); // actionCache.remove(type); // // refresh the cool bar manager before disposing of a cool item // ICoolBarManager2 coolBar = (ICoolBarManager2) window.getCoolBarManager2(); // if (coolBar != null) // { // coolBar.refresh(); // } // actionBars.dispose(); // } //} IEditorPart::Pointer EditorManager::FindEditor(IEditorInput::Pointer input) { return this->FindEditor("", input, IWorkbenchPage::MATCH_INPUT); } IEditorPart::Pointer EditorManager::FindEditor(const std::string& editorId, IEditorInput::Pointer input, int matchFlags) { std::vector refs(this->FindEditors(input, editorId, matchFlags)); if (refs.size() == 0) { return IEditorPart::Pointer(); } return refs[0]->GetEditor(true); } std::vector EditorManager::FindEditors( IEditorInput::Pointer input, const std::string& editorId, int matchFlags) { if (matchFlags == IWorkbenchPage::MATCH_NONE) { return std::vector(); } std::vector result; std::list othersList(page->GetEditorReferences()); if (!othersList.empty()) { IEditorReference::Pointer active = page->GetActiveEditorReference(); if (active.IsNotNull()) { othersList.remove(active); std::list activeList; activeList.push_back(active); this->FindEditors(activeList, input, editorId, matchFlags, result); } this->FindEditors(othersList, input, editorId, matchFlags, result); } return result; } void EditorManager::FindEditors( std::list& editorList, IEditorInput::Pointer input, const std::string& editorId, int matchFlags, std::vector& result) { if (matchFlags == IWorkbenchPage::MATCH_NONE) { return; } // Phase 0: Remove editors whose ids don't match (if matching by id) if (((matchFlags & IWorkbenchPage::MATCH_ID) != 0) && !editorId.empty()) { for (std::list::iterator i = editorList.begin(); i != editorList.end();) { if (editorId != (*i)->GetId()) { i = editorList.erase(i); continue; } ++i; } } // If not matching on editor input, just return the remaining editors. // In practice, this case is never used. if ((matchFlags & IWorkbenchPage::MATCH_INPUT) == 0) { result.insert(result.end(), editorList.begin(), editorList.end()); return; } // Phase 1: check editors that have their own matching strategy for (std::list::iterator i = editorList.begin(); i != editorList.end();) { EditorReference::Pointer editor = i->Cast(); IEditorDescriptor::Pointer desc = editor->GetDescriptor(); if (desc.IsNotNull()) { IEditorMatchingStrategy::Pointer matchingStrategy = desc ->GetEditorMatchingStrategy(); if (matchingStrategy.IsNotNull()) { i = editorList.erase(i); // We're handling this one here, so remove it // from the list. if (matchingStrategy->Matches(editor, input)) { result.push_back(editor); } continue; } } ++i; } // Phase 2: check materialized editors (without their own matching // strategy) for (std::list::iterator i = editorList.begin(); i != editorList.end();) { EditorReference::Pointer editor = i->Cast(); IEditorPart::Pointer part = editor->GetPart(false).Cast(); if (part.IsNotNull()) { i = editorList.erase(i); // We're handling this one here, so remove it from // the list. if (part->GetEditorInput().IsNotNull() && part->GetEditorInput() == input) { result.push_back(editor); } } else ++i; } // Phase 3: check unmaterialized editors for input equality, // delaying plug-in activation further by only restoring the editor // input // if the editor reference's factory id and name match. // std::string name = input->GetName(); // IPersistableElement persistable = input.getPersistable(); // if (name == null || persistable == null) // { // return; // } // String id = persistable.getFactoryId(); // if (id == null) // { // return; // } // for (Iterator i = editorList.iterator(); i.hasNext();) // { // EditorReference editor = (EditorReference) i.next(); // if (name.equals(editor.getName()) && id.equals(editor.getFactoryId())) // { // IEditorInput restoredInput; // try // { // restoredInput = editor.getEditorInput(); // if (Util.equals(restoredInput, input)) // { // result.add(editor); // } // } // catch (PartInitException e1) // { // WorkbenchPlugin.log(e1); // } // } // } } std::size_t EditorManager::GetEditorCount() { return page->GetEditorReferences().size(); } IEditorRegistry* EditorManager::GetEditorRegistry() { return WorkbenchPlugin::GetDefault()->GetEditorRegistry(); } std::vector EditorManager::GetDirtyEditors() { return this->CollectDirtyEditors(); } std::list EditorManager::GetEditors() { return page->GetEditorReferences(); } IEditorPart::Pointer EditorManager::GetVisibleEditor() { IEditorReference::Pointer ref = editorPresentation->GetVisibleEditor(); if (ref.IsNull()) { return IEditorPart::Pointer(0); } return ref->GetPart(true).Cast(); } bool EditorManager::IsSaveAllNeeded() { std::list editors(page->GetEditorReferences()); for (std::list::iterator i = editors.begin(); i != editors.end(); ++i) { if ((*i)->IsDirty()) { return true; } } return false; } IEditorReference::Pointer EditorManager::FindReusableEditor( EditorDescriptor::Pointer /*desc*/) { //return ((TabBehaviour)Tweaklets.get(TabBehaviour.KEY)).findReusableEditor(page); return IEditorReference::Pointer(0); } IEditorReference::Pointer EditorManager::OpenEditor( const std::string& editorId, IEditorInput::Pointer input, bool /*setVisible*/, IMemento::Pointer editorState) { if (input.IsNull()) { throw Poco::InvalidArgumentException(); } IEditorRegistry* reg = this->GetEditorRegistry(); EditorDescriptor::Pointer desc = reg->FindEditor(editorId).Cast(); if (desc.IsNull()) { throw PartInitException("Unable to open editor, unknown editor id", editorId); } return this->OpenEditorFromDescriptor(desc, input, editorState); } IEditorReference::Pointer EditorManager::OpenEditorFromDescriptor( EditorDescriptor::Pointer desc, IEditorInput::Pointer input, IMemento::Pointer editorState) { IEditorReference::Pointer result; if (desc->IsInternal()) { result = this->ReuseInternalEditor(desc, input); if (result.IsNull()) { result = new EditorReference(this, input, desc, editorState); } } // else if (desc->GetId() == IEditorRegistry::SYSTEM_INPLACE_EDITOR_ID) // { // if (ComponentSupport.inPlaceEditorSupported()) // { // result = new EditorReference(this, input, desc); // } // } // else if (desc->GetId() == IEditorRegistry::SYSTEM_EXTERNAL_EDITOR_ID) // { // IPathEditorInput pathInput = getPathEditorInput(input); // if (pathInput != null) // { // result = openSystemExternalEditor(pathInput.getPath()); // } // else // { // throw new PartInitException( // WorkbenchMessages.EditorManager_systemEditorError); // } // } // else if (desc->IsOpenExternal()) // { // result = openExternalEditor(desc, input); // } else { // this should never happen throw PartInitException("Invalid editor descriptor for id", desc->GetId()); } if (result.IsNotNull()) { this->CreateEditorTab(result.Cast(), ""); //$NON-NLS-1$ } // Workbench wb = (Workbench) window.getWorkbench(); // wb.getEditorHistory().add(input, desc); return result; } //IEditorReference::Pointer EditorManager::OpenExternalEditor( // EditorDescriptor::Pointer desc, IEditorInput::Pointer input) //{ // final CoreException ex[] = new CoreException[1]; // // final IPathEditorInput pathInput = getPathEditorInput(input); // if (pathInput != null && pathInput.getPath() != null) // { // BusyIndicator.showWhile(getDisplay(), new Runnable() // { // public void run() // { // try // { // if (desc.getLauncher() != null) // { // // open using launcher // Object launcher = WorkbenchPlugin.createExtension( // desc.getConfigurationElement(), "launcher"); //$NON-NLS-1$ // ((IEditorLauncher) launcher).open(pathInput // .getPath()); // } // else // { // // open using command // ExternalEditor oEditor = new ExternalEditor( // pathInput.getPath(), desc); // oEditor.open(); // } // } // catch (CoreException e) // { // ex[0] = e; // } // } // } // ); // } // else // { // throw new PartInitException(NLS.bind( // WorkbenchMessages.EditorManager_errorOpeningExternalEditor, // desc.getFileName(), desc.getId())); // } // // if (ex[0] != null) // { // throw new PartInitException(NLS.bind( // WorkbenchMessages.EditorManager_errorOpeningExternalEditor, // desc.getFileName(), desc.getId()), ex[0]); // } // // // we do not have an editor part for external editors // return null; //} void EditorManager::CreateEditorTab(EditorReference::Pointer ref, const std::string& workbookId) { editorPresentation->AddEditor(ref, workbookId); } EditorSite::Pointer EditorManager::CreateSite(IEditorReference::Pointer ref, IEditorPart::Pointer part, EditorDescriptor::Pointer desc, IEditorInput::Pointer input) const { EditorSite::Pointer site(new EditorSite(ref, part, page, desc)); if (desc.IsNotNull()) { //site.setActionBars(createEditorActionBars(desc, site)); } else { //site.setActionBars(createEmptyEditorActionBars(site)); } const std::string label = part->GetPartName(); // debugging only try { part->Init(site, input); // Sanity-check the site if (!(part->GetSite() == site) || !(part->GetEditorSite() == site)) { throw PartInitException("Editor initialization failed: " + desc->GetId() + ". Site is incorrect."); } } catch (PartInitException e) { throw e; } catch (std::exception e) { throw PartInitException("An exception was thrown during initialization", e.what()); } return site; } IEditorReference::Pointer EditorManager::ReuseInternalEditor( EditorDescriptor::Pointer /*desc*/, IEditorInput::Pointer /*input*/) { // poco_assert(desc.IsNotNull()); // "descriptor must not be null"); //$NON-NLS-1$ // poco_assert(input.IsNotNull()); // "input must not be null"); //$NON-NLS-1$ // // IEditorReference::Pointer reusableEditorRef = this->FindReusableEditor(desc); // if (reusableEditorRef.IsNotNull()) // { // return this->ReuseInternalEditor(page, this, editorPresentation, desc, input, // reusableEditorRef); // } return IEditorReference::Pointer(0); } IEditorPart::Pointer EditorManager::CreatePart(EditorDescriptor::Pointer desc) const { // try // { IEditorPart::Pointer result = desc->CreateEditor(); // IConfigurationElement element = desc.getConfigurationElement(); // if (element != null) // { // page.getExtensionTracker().registerObject( // element.getDeclaringExtension(), result, // IExtensionTracker.REF_WEAK); // } return result; // } // catch (CoreException e) // { // throw PartInitException(StatusUtil.newStatus( // desc.getPluginID(), // WorkbenchMessages.EditorManager_instantiationError, e)); // } } //IEditorReference::Pointer EditorManager::OpenSystemExternalEditor( // Poco::Path location) //{ // if (location == null) // { // throw new IllegalArgumentException(); // } // // final boolean result[] = // { false}; // BusyIndicator.showWhile(getDisplay(), new Runnable() // { // public void run() // { // if (location != null) // { // result[0] = Program.launch(location.toOSString()); // } // } // } // ); // // if (!result[0]) // { // throw new PartInitException(NLS.bind( // WorkbenchMessages.EditorManager_unableToOpenExternalEditor, // location)); // } // // // We do not have an editor part for external editors // return null; // } // ImageDescriptor EditorManager::FindImage(EditorDescriptor::Pointer desc, // Poco::Path path) // { // if (desc == null) // { // // @issue what should be the default image? // return ImageDescriptor.getMissingImageDescriptor(); // } // // if (desc.isOpenExternal() && path != null) // { // return PlatformUI.getWorkbench().getEditorRegistry() // .getImageDescriptor(path.toOSString()); // } // // return desc.getImageDescriptor(); // } bool EditorManager::RestoreState(IMemento::Pointer memento) { // Restore the editor area workbooks layout/relationship // MultiStatus result = new MultiStatus(PlatformUI.PLUGIN_ID, // IStatus.OK, // WorkbenchMessages.EditorManager_problemsRestoringEditors, null); bool result = true; std::string activeWorkbookID; std::vector visibleEditors; std::vector activeEditor; IMemento::Pointer areaMem = memento->GetChild(WorkbenchConstants::TAG_AREA); if (areaMem) { //result.add(editorPresentation.restoreState(areaMem)); editorPresentation->RestoreState(areaMem); areaMem->GetString(WorkbenchConstants::TAG_ACTIVE_WORKBOOK, activeWorkbookID); } // Loop through the editors. std::vector editorMems(memento->GetChildren(WorkbenchConstants::TAG_EDITOR)); for (std::size_t x = 0; x < editorMems.size(); x++) { // for dynamic UI - call restoreEditorState to replace code which is // commented out RestoreEditorState(editorMems[x], visibleEditors, activeEditor); //, result); } // restore the presentation if (areaMem) { //result.add(editorPresentation.restorePresentationState(areaMem)); result &= editorPresentation->RestorePresentationState(areaMem); } try { // StartupThreading.runWithThrowable(new StartupRunnable() // { // // public void runWithException() throws Throwable // { // Update each workbook with its visible editor. for (std::size_t i = 0; i < visibleEditors.size(); i++) { SetVisibleEditor(visibleEditors[i], false); } // Update the active workbook if (!activeWorkbookID.empty()) { editorPresentation->SetActiveEditorWorkbookFromID(activeWorkbookID); } if (!activeEditor.empty() && activeEditor[0]) { IWorkbenchPart::Pointer editor = activeEditor[0]->GetPart(true); if (editor) { page->Activate(editor); } } // }}); } catch (...) { // The exception is already logged. // result // .add(new Status( // IStatus.ERR, // PlatformUI.PLUGIN_ID, // 0, // WorkbenchMessages.EditorManager_exceptionRestoringEditor, // t)); result &= false; } return result; } bool EditorManager::SaveAll(bool confirm, bool closing, bool addNonPartSources) { // Get the list of dirty editors and views. If it is // empty just return. std::vector parts(page->GetDirtyParts()); if (parts.empty()) { return true; } std::vector wbParts; for (std::vector::const_iterator i = parts.begin(); i != parts.end(); ++i) { if (IWorkbenchPart::Pointer part = i->Cast()) { wbParts.push_back(part); } } // If confirmation is required .. return this->SaveAll(wbParts, confirm, closing, addNonPartSources, IWorkbenchWindow::Pointer(window)); } bool EditorManager::SaveAll( const std::vector& /*dirtyParts*/, bool /*confirm*/, bool /*closing*/, bool /*addNonPartSources*/, SmartPointer /*window*/) { // // clone the input list // dirtyParts = new ArrayList(dirtyParts); // List modelsToSave; // if (confirm) { // boolean saveable2Processed = false; // // Process all parts that implement ISaveablePart2. // // These parts are removed from the list after saving // // them. We then need to restore the workbench to // // its previous state, for now this is just last // // active perspective. // // Note that the given parts may come from multiple // // windows, pages and perspectives. // ListIterator listIterator = dirtyParts.listIterator(); // // WorkbenchPage currentPage = null; // Perspective currentPageOriginalPerspective = null; // while (listIterator.hasNext()) { // IWorkbenchPart part = (IWorkbenchPart) listIterator.next(); // if (part instanceof ISaveablePart2) { // WorkbenchPage page = (WorkbenchPage) part.getSite() // .getPage(); // if (!Util.equals(currentPage, page)) { // if (currentPage != null // && currentPageOriginalPerspective != null) { // if (!currentPageOriginalPerspective // .equals(currentPage.getActivePerspective())) { // currentPage // .setPerspective(currentPageOriginalPerspective // .getDesc()); // } // } // currentPage = page; // currentPageOriginalPerspective = page // .getActivePerspective(); // } // if (confirm) { // if (part instanceof IViewPart) { // Perspective perspective = page // .getFirstPerspectiveWithView((IViewPart) part); // if (perspective != null) { // page.setPerspective(perspective.getDesc()); // } // } // // show the window containing the page? // IWorkbenchWindow partsWindow = page // .getWorkbenchWindow(); // if (partsWindow != partsWindow.getWorkbench() // .getActiveWorkbenchWindow()) { // Shell shell = partsWindow.getShell(); // if (shell.getMinimized()) { // shell.setMinimized(false); // } // shell.setActive(); // } // page.bringToTop(part); // } // // try to save the part // int choice = SaveableHelper.savePart((ISaveablePart2) part, // page.getWorkbenchWindow(), confirm); // if (choice == ISaveablePart2.CANCEL) { // // If the user cancels, don't restore the previous // // workbench state, as that will // // be an unexpected switch from the current state. // return false; // } else if (choice != ISaveablePart2.DEFAULT) { // saveable2Processed = true; // listIterator.remove(); // } // } // } // // // try to restore the workbench to its previous state // if (currentPage != null && currentPageOriginalPerspective != null) { // if (!currentPageOriginalPerspective.equals(currentPage // .getActivePerspective())) { // currentPage.setPerspective(currentPageOriginalPerspective // .getDesc()); // } // } // // // if processing a ISaveablePart2 caused other parts to be // // saved, remove them from the list presented to the user. // if (saveable2Processed) { // listIterator = dirtyParts.listIterator(); // while (listIterator.hasNext()) { // ISaveablePart part = (ISaveablePart) listIterator.next(); // if (!part.isDirty()) { // listIterator.remove(); // } // } // } // // modelsToSave = convertToSaveables(dirtyParts, closing, addNonPartSources); // // // If nothing to save, return. // if (modelsToSave.isEmpty()) { // return true; // } // boolean canceled = SaveableHelper.waitForBackgroundSaveJobs(modelsToSave); // if (canceled) { // return false; // } // // Use a simpler dialog if there's only one // if (modelsToSave.size() == 1) { // Saveable model = (Saveable) modelsToSave.get(0); // String message = NLS.bind(WorkbenchMessages.EditorManager_saveChangesQuestion, model.getName()); // // Show a dialog. // String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }; // MessageDialog d = new MessageDialog( // shellProvider.getShell(), WorkbenchMessages.Save_Resource, // null, message, MessageDialog.QUESTION, buttons, 0); // // int choice = SaveableHelper.testGetAutomatedResponse(); // if (SaveableHelper.testGetAutomatedResponse() == SaveableHelper.USER_RESPONSE) { // choice = d.open(); // } // // // Branch on the user choice. // // The choice id is based on the order of button labels // // above. // switch (choice) { // case ISaveablePart2.YES: // yes // break; // case ISaveablePart2.NO: // no // return true; // default: // case ISaveablePart2.CANCEL: // cancel // return false; // } // } // else { // ListSelectionDialog dlg = new ListSelectionDialog( // shellProvider.getShell(), modelsToSave, // new ArrayContentProvider(), // new WorkbenchPartLabelProvider(), RESOURCES_TO_SAVE_MESSAGE); // dlg.setInitialSelections(modelsToSave.toArray()); // dlg.setTitle(SAVE_RESOURCES_TITLE); // // // this "if" statement aids in testing. // if (SaveableHelper.testGetAutomatedResponse()==SaveableHelper.USER_RESPONSE) { // int result = dlg.open(); // //Just return false to prevent the operation continuing // if (result == IDialogConstants.CANCEL_ID) { // return false; // } // // modelsToSave = Arrays.asList(dlg.getResult()); // } // } // } // else { // modelsToSave = convertToSaveables(dirtyParts, closing, addNonPartSources); // } // // // If the editor list is empty return. // if (modelsToSave.isEmpty()) { // return true; // } // // // Create save block. // final List finalModels = modelsToSave; // IRunnableWithProgress progressOp = new IRunnableWithProgress() { // public void run(IProgressMonitor monitor) { // IProgressMonitor monitorWrap = new EventLoopProgressMonitor( // monitor); // monitorWrap.beginTask("", finalModels.size()); //$NON-NLS-1$ // for (Iterator i = finalModels.iterator(); i.hasNext();) { // Saveable model = (Saveable) i.next(); // // handle case where this model got saved as a result of saving another // if (!model.isDirty()) { // monitor.worked(1); // continue; // } // SaveableHelper.doSaveModel(model, new SubProgressMonitor(monitorWrap, 1), shellProvider, closing || confirm); // if (monitorWrap.isCanceled()) { // break; // } // } // monitorWrap.done(); // } // }; // // // Do the save. // return SaveableHelper.runProgressMonitorOperation( // WorkbenchMessages.Save_All, progressOp, runnableContext, shellProvider); return true; } bool EditorManager::SavePart(ISaveablePart::Pointer /*saveable*/, IWorkbenchPart::Pointer /*part*/, bool /*confirm*/) { //TODO EditorManager save part (SaveableHelper) //return SaveableHelper.savePart(saveable, part, window, confirm); return true; } bool EditorManager::SaveState(const IMemento::Pointer memento) { // final MultiStatus result = new MultiStatus(PlatformUI.PLUGIN_ID, // IStatus.OK, // WorkbenchMessages.EditorManager_problemsSavingEditors, null); bool result = true; // Save the editor area workbooks layout/relationship IMemento::Pointer editorAreaMem = memento->CreateChild(WorkbenchConstants::TAG_AREA); //result.add(editorPresentation.saveState(editorAreaMem)); result &= editorPresentation->SaveState(editorAreaMem); // Save the active workbook id editorAreaMem->PutString(WorkbenchConstants::TAG_ACTIVE_WORKBOOK, editorPresentation->GetActiveEditorWorkbookID()); // Get each workbook std::list workbooks(editorPresentation->GetWorkbooks()); for (std::list::iterator iter = workbooks.begin(); iter != workbooks.end(); ++iter) { PartStack::Pointer workbook = *iter; // Use the list of editors found in EditorStack; fix for 24091 - std::list editorPanes(workbook->GetChildren()); + std::list editorPanes(workbook->GetChildren()); - for (std::list::iterator i = editorPanes.begin(); + for (std::list::iterator i = editorPanes.begin(); i != editorPanes.end(); ++i) { // Save each open editor. EditorReference::Pointer editorReference = i->Cast()->GetPartReference().Cast(); IEditorPart::Pointer editor = editorReference->GetEditor(false); if (!editor) { if (editorReference->GetMemento()) { IMemento::Pointer editorMem = memento ->CreateChild(WorkbenchConstants::TAG_EDITOR); editorMem->PutMemento(editorReference->GetMemento()); } continue; } // for dynamic UI - add the next line to replace the subsequent // code which is commented out SaveEditorState(memento, editorReference); //, result); } } return result; } bool EditorManager::SetVisibleEditor(IEditorReference::Pointer newEd, bool setFocus) { return editorPresentation->SetVisibleEditor(newEd, setFocus); } IPathEditorInput::Pointer EditorManager::GetPathEditorInput( IEditorInput::Pointer input) { if (input.Cast().IsNotNull()) { return input.Cast(); } // return (IPathEditorInput) // Util.getAdapter(input, IPathEditorInput.class); return IPathEditorInput::Pointer(0); } void EditorManager::RestoreEditorState(IMemento::Pointer /*editorMem*/, std::vector& /*visibleEditors*/, std::vector& /*activeEditor*/) { // MultiStatus result) { //TODO Restore editor state // String strFocus = editorMem.getString(IWorkbenchConstants.TAG_FOCUS); // boolean visibleEditor = "true".equals(strFocus); //$NON-NLS-1$ // EditorReference::Pointer e = new EditorReference(this, editorMem); // // try // { // StartupThreading.runWithPartInitExceptions(new StartupRunnable () // { // // public void runWithException() throws Throwable // { // createEditorTab(e, workbookID); // }}); // // } // catch (PartInitException ex) // { // result.add(ex.getStatus()); // } // // String strActivePart = editorMem // .getString(IWorkbenchConstants.TAG_ACTIVE_PART); // if ("true".equals(strActivePart)) // { //$NON-NLS-1$ // activeEditor[0] = e; // } // // String strFocus = editorMem.getString(IWorkbenchConstants.TAG_FOCUS); // boolean visibleEditor = "true".equals(strFocus); //$NON-NLS-1$ // if (visibleEditor) // { // visibleEditors.add(e); // } } void EditorManager::SaveEditorState(IMemento::Pointer /*mem*/, IEditorReference::Pointer /*ed*/) { //TODO Save editor state // final EditorReference editorRef = (EditorReference) ed; // final IEditorPart editor = ed.getEditor(false); // final IMemento memento = mem; // final MultiStatus result = res; // if (!(editor.getEditorSite() instanceof EditorSite)) // { // return; // } // final EditorSite site = (EditorSite) editor.getEditorSite(); // if (site.getPane() instanceof MultiEditorInnerPane) // { // return; // } // // SafeRunner.run(new SafeRunnable() // { // public void run() // { // // Get the input. // IEditorInput input = editor.getEditorInput(); // if (!input.exists()) // { // return; // } // IPersistableElement persistable = input.getPersistable(); // if (persistable == null) // { // return; // } // // // Save editor. // IMemento editorMem = memento // .createChild(IWorkbenchConstants.TAG_EDITOR); // editorMem.putString(IWorkbenchConstants.TAG_TITLE, editorRef // .getTitle()); // editorMem.putString(IWorkbenchConstants.TAG_NAME, editorRef // .getName()); // editorMem.putString(IWorkbenchConstants.TAG_ID, editorRef // .getId()); // editorMem.putString(IWorkbenchConstants.TAG_TOOLTIP, editorRef // .getTitleToolTip()); // // editorMem.putString(IWorkbenchConstants.TAG_PART_NAME, // editorRef.getPartName()); // // if (editor instanceof IWorkbenchPart3) // { // Map properties = ((IWorkbenchPart3) editor) // .getPartProperties(); // if (!properties.isEmpty()) // { // IMemento propBag = editorMem // .createChild(IWorkbenchConstants.TAG_PROPERTIES); // Iterator i = properties.entrySet().iterator(); // while (i.hasNext()) // { // Map.Entry entry = (Map.Entry) i.next(); // IMemento p = propBag.createChild( // IWorkbenchConstants.TAG_PROPERTY, // (String) entry.getKey()); // p.putTextData((String) entry.getValue()); // } // } // } // // if (editorRef.isPinned()) // { // editorMem.putString(IWorkbenchConstants.TAG_PINNED, "true"); //$NON-NLS-1$ // } // // EditorPane editorPane = (EditorPane) ((EditorSite) editor // .getEditorSite()).getPane(); // editorMem.putString(IWorkbenchConstants.TAG_WORKBOOK, // editorPane.getWorkbook().getID()); // // if (editor == page.getActivePart()) // { // editorMem.putString(IWorkbenchConstants.TAG_ACTIVE_PART, // "true"); //$NON-NLS-1$ // } // // if (editorPane == editorPane.getWorkbook().getSelection()) // { // editorMem.putString(IWorkbenchConstants.TAG_FOCUS, "true"); //$NON-NLS-1$ // } // // if (input instanceof IPathEditorInput) // { // IPath path = ((IPathEditorInput) input).getPath(); // if (path != null) // { // editorMem.putString(IWorkbenchConstants.TAG_PATH, path // .toString()); // } // } // // // Save input. // IMemento inputMem = editorMem // .createChild(IWorkbenchConstants.TAG_INPUT); // inputMem.putString(IWorkbenchConstants.TAG_FACTORY_ID, // persistable.getFactoryId()); // persistable.saveState(inputMem); // // // any editors that want to persist state // if (editor instanceof IPersistableEditor) // { // IMemento editorState = editorMem // .createChild(IWorkbenchConstants.TAG_EDITOR_STATE); // ((IPersistableEditor) editor).saveState(editorState); // } // } // // public void handleException(Throwable e) // { // result // .add(new Status( // IStatus.ERR, // PlatformUI.PLUGIN_ID, // 0, // NLS // .bind( // WorkbenchMessages.EditorManager_unableToSaveEditor, // editorRef.getTitle()), e)); // } // } // ); } IMemento::Pointer EditorManager::GetMemento(IEditorReference::Pointer e) { if (e.Cast().IsNotNull()) { return e.Cast()->GetMemento(); } return IMemento::Pointer(0); } IEditorReference::Pointer EditorManager::OpenEmptyTab() { IEditorInput::Pointer input(new NullEditorInput()); EditorDescriptor::Pointer desc = (dynamic_cast(this->GetEditorRegistry())) ->FindEditor(EditorRegistry::EMPTY_EDITOR_ID).Cast(); EditorReference::Pointer result(new EditorReference(this, input, desc)); try { this->CreateEditorTab(result, ""); //$NON-NLS-1$ return result; } catch (PartInitException e) { // StatusManager.getManager().handle( // StatusUtil.newStatus(WorkbenchPlugin.PI_WORKBENCH, e)); BERRY_ERROR << e.displayText() << std::endl; } return IEditorReference::Pointer(0); } bool EditorManager::UseIPersistableEditor() { // IPreferenceStore store = WorkbenchPlugin.getDefault() // .getPreferenceStore(); // return store.getBoolean(IPreferenceConstants.USE_IPERSISTABLE_EDITORS); return false; } } diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryEditorSashContainer.cpp b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryEditorSashContainer.cpp index e1fd834cad..1c37f950d3 100755 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryEditorSashContainer.cpp +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryEditorSashContainer.cpp @@ -1,609 +1,609 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "berryEditorSashContainer.h" #include "berryPresentationSerializer.h" #include "berryWorkbenchConstants.h" #include "berryWorkbenchPlugin.h" #include "berryLayoutTree.h" #include "berryWorkbenchWindowConfigurer.h" #include "berryWorkbenchWindow.h" #include "berryQtDnDControlWidget.h" #include "tweaklets/berryGuiWidgetsTweaklet.h" #include #include namespace berry { const std::string EditorSashContainer::DEFAULT_WORKBOOK_ID = "DefaultEditorWorkbook"; void EditorSashContainer::AddChild(const RelationshipInfo& info) { PartSashContainer::AddChild(info); this->UpdateStackButtons(); } void EditorSashContainer::ChildAdded(LayoutPart::Pointer child) { PartSashContainer::ChildAdded(child); if (child.Cast () != 0) { editorWorkbooks.push_back(child.Cast ()); } } void EditorSashContainer::ChildRemoved(LayoutPart::Pointer child) { PartSashContainer::ChildRemoved(child); if (child.Cast () != 0) { editorWorkbooks.remove(child.Cast()); if (activeEditorWorkbook == child) { this->SetActiveWorkbook(PartStack::Pointer(0), false); } this->UpdateStackButtons(); } } PartStack::Pointer EditorSashContainer::CreateDefaultWorkbook() { PartStack::Pointer newWorkbook = this->NewEditorWorkbook(); newWorkbook->SetID(DEFAULT_WORKBOOK_ID); this->Add(newWorkbook); return newWorkbook; } void EditorSashContainer::AddDropSupport() { WorkbenchWindowConfigurer::Pointer winConfigurer = page->GetWorkbenchWindow().Cast()->GetWindowConfigurer(); QtDnDControlWidget* dropWidget = static_cast(GetParent()); dropWidget->SetTransferTypes(winConfigurer->GetTransfers()); dropWidget->AddDropListener(winConfigurer->GetDropTargetListener().GetPointer()); } PartStack::Pointer EditorSashContainer::NewEditorWorkbook() { PartStack::Pointer newWorkbook(new PartStack(page, true, PresentationFactoryUtil::ROLE_EDITOR)); std::stringstream buf; buf << newWorkbook->GetClassName() << newWorkbook.GetPointer(); newWorkbook->SetID(buf.str()); return newWorkbook; } void* EditorSashContainer::CreateParent(void* parentWidget) { //return Tweaklets::Get(GuiWidgetsTweaklet::KEY)->CreateComposite(parentWidget); return new QtDnDControlWidget(static_cast(parentWidget)); } void EditorSashContainer::DisposeParent() { this->parent = 0; } bool EditorSashContainer::IsActiveWorkbook(PartStack::Pointer workbook) { return activeEditorWorkbook == workbook; } PartStack::Pointer EditorSashContainer::CreateStack() { return this->NewEditorWorkbook(); } void EditorSashContainer::SetVisiblePart( - IStackableContainer::Pointer container, PartPane::Pointer visiblePart) + ILayoutContainer::Pointer container, PartPane::Pointer visiblePart) { PartStack::Pointer stack = container.Cast(); if (stack == 0) return; stack->GetContainer().Cast()->SetActiveWorkbook(stack, true); stack->SetSelection(visiblePart); } -StackablePart::Pointer EditorSashContainer::GetVisiblePart( - IStackableContainer::Pointer container) +LayoutPart::Pointer EditorSashContainer::GetVisiblePart( + ILayoutContainer::Pointer container) { PartStack::Pointer refPart = container.Cast(); return refPart->GetSelection(); } EditorSashContainer::EditorSashContainer(const std::string& editorId, WorkbenchPage* page, void* parent) : PartSashContainer(editorId, page, parent) { this->CreateDefaultWorkbook(); } bool EditorSashContainer::AllowsAdd(LayoutPart::Pointer layoutPart) { return LayoutPart::AllowsAdd(layoutPart); } void EditorSashContainer::AddEditor(PartPane::Pointer pane, PartStack::Pointer stack) { //EditorStack workbook = getActiveWorkbook(); stack->Add(pane); } void EditorSashContainer::UpdateStackButtons() { // // This is applicable only when the new // // min/max behaviour is being used // Perspective persp = getPage().getActivePerspective(); // if (!Perspective.useNewMinMax(persp)) // return; // // // Find the upper Right editor stack // LayoutPart[] stacks = getChildren(); // EditorStack winner = getUpperRightEditorStack(stacks); // // // Now hide the buttons for all but the upper right stack // for (int i = 0; i < stacks.length; i++) // { // if (!(stacks[i] instanceof EditorStack) // ) // continue; // ((EditorStack) stacks[i]).showMinMax(stacks[i] == winner); // } // // // Force the stack's presentation state to match its perspective // persp.refreshEditorAreaVisibility(); } PartStack::Pointer EditorSashContainer::GetUpperRightEditorStack() { return this->GetUpperRightEditorStack(this->GetChildren()); } PartStack::Pointer EditorSashContainer::GetUpperRightEditorStack( const ILayoutContainer::ChildrenType& stacks) { // Find the upper Right editor stack PartStack::Pointer winner; Rectangle winnerRect; for (ILayoutContainer::ChildrenType::const_iterator iter = stacks.begin(); iter != stacks.end(); ++iter) { LayoutPart::Pointer part = *iter; if (part.Cast() == 0) continue; PartStack::Pointer stack = part.Cast(); Rectangle bb = stack->GetBounds(); if (iter == stacks.begin() || bb.y < winnerRect.y || (bb.y == winnerRect.y && bb.x > winnerRect.x)) { winner = stack; winnerRect = bb; } } return winner; } PartStack::Pointer EditorSashContainer::GetActiveWorkbook() { if (activeEditorWorkbook == 0) { if (editorWorkbooks.size() < 1) { this->SetActiveWorkbook(this->CreateDefaultWorkbook(), false); } else { this->SetActiveWorkbook(editorWorkbooks.front(), false); } } return activeEditorWorkbook; } std::string EditorSashContainer::GetActiveWorkbookID() { return this->GetActiveWorkbook()->GetID(); } std::list EditorSashContainer::GetEditorWorkbooks() { return editorWorkbooks; } std::size_t EditorSashContainer::GetEditorWorkbookCount() { return editorWorkbooks.size(); } void EditorSashContainer::FindSashes(LayoutPart::Pointer pane, PartPane::Sashes& sashes) { //Find the sashes around the current editor and //then the sashes around the editor area. PartSashContainer::FindSashes(pane, sashes); ILayoutContainer::Pointer container = this->GetContainer(); if (container != 0) { container->FindSashes(LayoutPart::Pointer(this), sashes); } } void EditorSashContainer::RemoveAllEditors() { PartStack::Pointer currentWorkbook = this->GetActiveWorkbook(); // Iterate over a copy so the original can be modified. std::list workbooks(editorWorkbooks); for (std::list::iterator iter = workbooks.begin(); iter != workbooks.end(); ++iter) { PartStack::Pointer workbook = *iter; - std::list children = workbook->GetChildren(); - for (std::list::iterator childIter = children.begin(); + std::list children = workbook->GetChildren(); + for (std::list::iterator childIter = children.begin(); childIter != children.end(); ++childIter) { workbook->Remove(*childIter); } if (workbook != currentWorkbook) { this->Remove(workbook); workbook->Dispose(); } } } void EditorSashContainer::RemoveEditor(PartPane::Pointer pane) { PartStack::Pointer workbook = pane->GetContainer().Cast(); if (workbook == 0) { return; } workbook->Remove(pane); // remove the editor workbook if empty if (workbook->GetItemCount() < 1 /* && editorWorkbooks.size() > 1*/) { // // If the user closes the last editor and the editor area // // is maximized, restore it // Perspective persp = getPage().getActivePerspective(); // if (Perspective.useNewMinMax(persp)) // { // if (persp.getPresentation().getMaximizedStack() instanceof EditorStack) // persp.getPresentation().getMaximizedStack(). // setState(IStackPresentationSite.STATE_RESTORED); // } this->Remove(workbook); workbook->Dispose(); } } bool EditorSashContainer::RestoreState(IMemento::Pointer memento) { //TODO EditorSashContainer restore state // MultiStatus // result = // new MultiStatus(PlatformUI.PLUGIN_ID, IStatus.OK, WorkbenchMessages.RootLayoutContainer_problemsRestoringPerspective, 0); bool result = true; // Remove the default editor workbook that is // initialy created with the editor area. // StartupThreading.runWithoutExceptions(new StartupRunnable() // { // // public void runWithException() throws Throwable // { PartStack::Pointer defaultWorkbook; for (ILayoutContainer::ChildrenType::iterator i = children.begin(); i != children.end(); ++i) { LayoutPart::Pointer child = *i; if (child->GetID() == DEFAULT_WORKBOOK_ID) { defaultWorkbook = child.Cast(); if (defaultWorkbook->GetItemCount() > 0) { defaultWorkbook = 0; } } } if (defaultWorkbook) { Remove(defaultWorkbook); } // }} // ); // Restore the relationship/layout std::vector infos(memento->GetChildren(WorkbenchConstants::TAG_INFO)); Poco::HashMap mapIDtoPart(infos.size()); for (std::size_t i = 0; i < infos.size(); i++) { // Get the info details. IMemento::Pointer childMem = infos[i]; std::string partID; childMem->GetString(WorkbenchConstants::TAG_PART, partID); std::string relativeID; childMem->GetString(WorkbenchConstants::TAG_RELATIVE, relativeID); int relationship = 0; int left = 0, right = 0; if (!relativeID.empty()) { childMem->GetInteger(WorkbenchConstants::TAG_RELATIONSHIP, relationship); childMem->GetInteger(WorkbenchConstants::TAG_RATIO_LEFT, left); childMem->GetInteger(WorkbenchConstants::TAG_RATIO_RIGHT, right); } PartStack::Pointer workbook; // StartupThreading.runWithoutExceptions(new StartupRunnable() // { // // public void runWithException() throws Throwable // { // Create the part. workbook = NewEditorWorkbook(); workbook->SetID(partID); // 1FUN70C: ITPUI:WIN - Shouldn't set Container when not active workbook->SetContainer(ILayoutContainer::Pointer(this)); // }} // ); IMemento::Pointer workbookMemento = childMem->GetChild( WorkbenchConstants::TAG_FOLDER); if (workbookMemento) { //result.add(workbook[0].restoreState(workbookMemento)); result &= workbook->RestoreState(workbookMemento); } const int myLeft = left, myRight = right, myRelationship = relationship; // StartupThreading.runWithoutExceptions(new StartupRunnable() // { // // public void runWithException() throws Throwable // { // Add the part to the layout if (relativeID.empty()) { Add(workbook); } else { LayoutPart::Pointer refPart = mapIDtoPart[relativeID]; if (refPart) { Add(workbook, myRelationship, myLeft, myRight, refPart); } else { WorkbenchPlugin::Log("Unable to find part for ID: " + relativeID); } } // }} // ); mapIDtoPart[partID] = workbook; } return result; } bool EditorSashContainer::SaveState(IMemento::Pointer memento) { std::vector relationships(ComputeRelation()); // MultiStatus // result = // new MultiStatus(PlatformUI.PLUGIN_ID, IStatus.OK, WorkbenchMessages.RootLayoutContainer_problemsSavingPerspective, 0); bool result = true; for (std::size_t i = 0; i < relationships.size(); i++) { // Save the relationship info .. // private LayoutPart part; // private int relationship; // private float ratio; // private LayoutPart relative; const RelationshipInfo& info = relationships[i]; IMemento::Pointer childMem = memento->CreateChild( WorkbenchConstants::TAG_INFO); childMem->PutString(WorkbenchConstants::TAG_PART, info.part->GetID()); PartStack::Pointer stack = info.part.Cast(); if (stack) { IMemento::Pointer folderMem = childMem->CreateChild( WorkbenchConstants::TAG_FOLDER); //result.add(stack.saveState(folderMem)); result &= stack->SaveState(folderMem); } if (info.relative != 0) { childMem->PutString(WorkbenchConstants::TAG_RELATIVE, info.relative->GetID()); childMem->PutInteger(WorkbenchConstants::TAG_RELATIONSHIP, info.relationship); childMem->PutInteger(WorkbenchConstants::TAG_RATIO_LEFT, info.left); childMem->PutInteger(WorkbenchConstants::TAG_RATIO_RIGHT, info.right); } } return result; } void EditorSashContainer::SetActiveWorkbook(PartStack::Pointer newWorkbook, bool hasFocus) { if (newWorkbook != 0) { if (std::find(editorWorkbooks.begin(), editorWorkbooks.end(), newWorkbook) == editorWorkbooks.end()) { return; } } PartStack::Pointer oldWorkbook = activeEditorWorkbook; activeEditorWorkbook = newWorkbook; if (oldWorkbook != 0 && oldWorkbook != newWorkbook) { oldWorkbook->SetActive(StackPresentation::AS_INACTIVE); } if (newWorkbook != 0) { if (hasFocus) { newWorkbook->SetActive(StackPresentation::AS_ACTIVE_FOCUS); } else { newWorkbook->SetActive(StackPresentation::AS_ACTIVE_NOFOCUS); } } this->UpdateTabList(); } void EditorSashContainer::SetActiveWorkbookFromID(const std::string& id) { for (std::list::iterator iter = editorWorkbooks.begin(); iter != editorWorkbooks.end(); ++iter) { PartStack::Pointer workbook = *iter; if (workbook->GetID() == id) { this->SetActiveWorkbook(workbook, false); } } } PartStack::Pointer EditorSashContainer::GetWorkbookFromID(const std::string& id) { for (std::list::iterator iter = editorWorkbooks.begin(); iter != editorWorkbooks.end(); ++iter) { PartStack::Pointer workbook = *iter; if (workbook->GetID() == id) { return workbook; } } return PartStack::Pointer(0); } void EditorSashContainer::UpdateTabList() { void* parent = this->GetParent(); if (parent != 0) { // parent may be 0 on startup PartStack::Pointer wb(this->GetActiveWorkbook()); //TODO EditorSashContainer update tab list // if (wb == 0) // { // parent.setTabList(new Control[0]); // } // else // { // parent.setTabList(wb.getTabList()); // } } } void EditorSashContainer::CreateControl(void* parent) { PartSashContainer::CreateControl(parent); ///let the user drop files/editor input on the editor area this->AddDropSupport(); } bool EditorSashContainer::IsCompressible() { //Added for bug 19524 return true; } -bool EditorSashContainer::IsStackType(IStackableContainer::Pointer toTest) +bool EditorSashContainer::IsStackType(ILayoutContainer::Pointer toTest) { if (toTest.Cast() == 0) return false; return (toTest.Cast ()->GetAppearance() == PresentationFactoryUtil::ROLE_EDITOR); } -bool EditorSashContainer::IsPaneType(StackablePart::Pointer toTest) +bool EditorSashContainer::IsPaneType(LayoutPart::Pointer toTest) { if (toTest.Cast() == 0) return false; return (toTest.Cast ()->GetPartReference().Cast () != 0); } bool EditorSashContainer::RestorePresentationState(IMemento::Pointer /*areaMem*/) { std::list workbooks = this->GetEditorWorkbooks(); for (std::list::iterator iter = workbooks.begin(); iter != workbooks.end(); ++iter) { PartStack::Pointer workbook = *iter; IMemento::Pointer memento = workbook->GetSavedPresentationState(); if (memento == 0) { continue; } std::list listParts = workbook->GetPresentableParts(); std::vector parts(listParts.begin(), listParts.end()); PresentationSerializer serializer(parts); //StartupThreading.runWithoutExceptions(new StartupRunnable() // { // public void runWithException() throws Throwable // { workbook->GetPresentation()->RestoreState(&serializer, memento); // }} // ); } //return new Status(IStatus.OK, PlatformUI.PLUGIN_ID, 0, "", 0); //$NON-NLS-1$ return true; } } diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryEditorSashContainer.h b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryEditorSashContainer.h index adffa13e59..dc39a87545 100755 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryEditorSashContainer.h +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryEditorSashContainer.h @@ -1,253 +1,253 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef BERRYEDITORSASHCONTAINER_H_ #define BERRYEDITORSASHCONTAINER_H_ #include "berryPartSashContainer.h" #include "berryPartStack.h" #include namespace berry { /** * Represents the area set aside for editor workbooks. * This container only accepts editor stacks (PartStack) and PartSash * as layout parts. * * Note no views are allowed within this container. */ class EditorSashContainer: public PartSashContainer { public: berryObjectMacro(EditorSashContainer); private: std::list editorWorkbooks; PartStack::Pointer activeEditorWorkbook; // DropTarget dropTarget; void AddDropSupport(); PartStack::Pointer NewEditorWorkbook(); protected: /* (non-Javadoc) * @see org.blueberry.ui.internal.PartSashContainer#addChild(org.blueberry.ui.internal.PartSashContainer.RelationshipInfo) */ void AddChild(const RelationshipInfo& info); /** * Notification that a child layout part has been * added to the container. Subclasses may override * this method to perform any container specific * work. */ void ChildAdded(LayoutPart::Pointer child); /** * Notification that a child layout part has been * removed from the container. Subclasses may override * this method to perform any container specific * work. */ void ChildRemoved(LayoutPart::Pointer child); PartStack::Pointer CreateDefaultWorkbook(); /** * Subclasses override this method to specify * the composite to use to parent all children * layout parts it contains. */ void* CreateParent(void* parentWidget); /** * Subclasses override this method to dispose * of any swt resources created during createParent. */ void DisposeParent(); /** * Return true is the workbook specified * is the active one. */ bool IsActiveWorkbook(PartStack::Pointer workbook); //TODO DND // /* package */DropTarget getDropTarget() { // return dropTarget; // } /* (non-Javadoc) * @see org.blueberry.ui.internal.PartSashContainer#createStack(org.blueberry.ui.internal.LayoutPart) */ PartStack::Pointer CreateStack(); /* (non-Javadoc) * @see org.blueberry.ui.internal.PartSashContainer#setVisiblePart(org.blueberry.ui.internal.ILayoutContainer, org.blueberry.ui.internal.LayoutPart) */ - void SetVisiblePart(IStackableContainer::Pointer container, + void SetVisiblePart(ILayoutContainer::Pointer container, PartPane::Pointer visiblePart); /* (non-Javadoc) * @see org.blueberry.ui.internal.PartSashContainer#getVisiblePart(org.blueberry.ui.internal.ILayoutContainer) */ - StackablePart::Pointer GetVisiblePart(IStackableContainer::Pointer container); + LayoutPart::Pointer GetVisiblePart(ILayoutContainer::Pointer container); public: static const std::string DEFAULT_WORKBOOK_ID; EditorSashContainer(const std::string& editorId, WorkbenchPage* page, void* parent); bool AllowsAdd(LayoutPart::Pointer layoutPart); /** * Add an editor to the active workbook. */ void AddEditor(PartPane::Pointer pane, PartStack::Pointer stack); /** * Hides the min/max buttons for all editor stacks * -except- for the upper/left one. */ void UpdateStackButtons(); /** * @param stacks * @return the EditorStack in the upper right position */ PartStack::Pointer GetUpperRightEditorStack(); /** * @param stacks * @return the EditorStack in the upper right position */ PartStack::Pointer GetUpperRightEditorStack( const ILayoutContainer::ChildrenType& stacks); /** * Return the editor workbook which is active. */ PartStack::Pointer GetActiveWorkbook(); /** * Return the editor workbook id which is active. */ std::string GetActiveWorkbookID(); /** * Return the all the editor workbooks. */ std::list GetEditorWorkbooks(); /** * Return the all the editor workbooks. */ std::size_t GetEditorWorkbookCount(); /** * Find the sashes around the specified part. */ void FindSashes(LayoutPart::Pointer pane, PartPane::Sashes& sashes); /** * Remove all the editors */ void RemoveAllEditors(); /** * Remove an editor from its' workbook. */ void RemoveEditor(PartPane::Pointer pane); /** * @see IPersistablePart */ bool RestoreState(IMemento::Pointer memento); /** * @see IPersistablePart */ bool SaveState(IMemento::Pointer memento); /** * Set the editor workbook which is active. */ void SetActiveWorkbook(PartStack::Pointer newWorkbook, bool hasFocus); /** * Set the editor workbook which is active. */ void SetActiveWorkbookFromID(const std::string& id); PartStack::Pointer GetWorkbookFromID(const std::string& id); /** * Updates the editor area's tab list to include the active * editor and its tab. */ void UpdateTabList(); /** * @see org.blueberry.ui.internal.LayoutPart#createControl(org.blueberry.swt.widgets.Composite) */ void CreateControl(void* parent); /** * @see org.blueberry.ui.internal.LayoutPart#getImportance() */ bool IsCompressible(); /* (non-Javadoc) * @see org.blueberry.ui.internal.PartSashContainer#isStackType(org.blueberry.ui.internal.LayoutPart) */ - bool IsStackType(IStackableContainer::Pointer toTest); + bool IsStackType(ILayoutContainer::Pointer toTest); /* (non-Javadoc) * @see org.blueberry.ui.internal.PartSashContainer#isPaneType(org.blueberry.ui.internal.LayoutPart) */ - bool IsPaneType(StackablePart::Pointer toTest); + bool IsPaneType(LayoutPart::Pointer toTest); /* (non-Javadoc) * @see org.blueberry.ui.internal.PartSashContainer#pickPartToZoom() */ // LayoutPart pickPartToZoom() { // return getActiveWorkbook(); // } /** * Restore the presentation state. Loop over the workbooks, create the appropriate serializer and pass to the presentation. * * @param areaMem the memento containing presentation * @return the restoration status */ bool RestorePresentationState(IMemento::Pointer areaMem); }; } #endif /* BERRYEDITORSASHCONTAINER_H_ */ diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryFolderLayout.cpp b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryFolderLayout.cpp index 0511d7ac95..ba037886e6 100644 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryFolderLayout.cpp +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryFolderLayout.cpp @@ -1,97 +1,97 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "berryFolderLayout.h" #include "berryPartPlaceholder.h" #include "berryWorkbenchPlugin.h" #include "berryPageLayout.h" #include "berryLayoutHelper.h" #include "berryUIException.h" namespace berry { FolderLayout::FolderLayout(PageLayout::Pointer pageLayout, PartStack::Pointer folder, ViewFactory* viewFactory) { this->folder = folder; this->viewFactory = viewFactory; this->pageLayout = pageLayout; } void FolderLayout::AddPlaceholder(const std::string& viewId) { if (!pageLayout->CheckValidPlaceholderId(viewId)) { return; } // Create the placeholder. - StackablePart::Pointer newPart(new PartPlaceholder(viewId)); + LayoutPart::Pointer newPart(new PartPlaceholder(viewId)); this->LinkPartToPageLayout(viewId, newPart); // Add it to the folder layout. folder->Add(newPart); } void FolderLayout::AddView(const std::string& viewId) { if (pageLayout->CheckPartInLayout(viewId)) { return; } try { IViewDescriptor::Pointer descriptor = viewFactory->GetViewRegistry()->Find( ViewFactory::ExtractPrimaryId(viewId)); if (descriptor == 0) { throw PartInitException("View descriptor not found: " + viewId); //$NON-NLS-1$ } PartPane::Pointer newPart = LayoutHelper::CreateView(pageLayout->GetViewFactory(), viewId); this->LinkPartToPageLayout(viewId, newPart); folder->Add(newPart); } catch (PartInitException& e) { // cannot safely open the dialog so log the problem WorkbenchPlugin::Log(this->GetClassName(), "AddView(const std::string&)", e); //$NON-NLS-1$ } } std::string FolderLayout::GetProperty(const std::string& id) { return folder->GetProperty(id); } void FolderLayout::SetProperty(const std::string& id, const std::string& value) { folder->SetProperty(id, value); } void FolderLayout::LinkPartToPageLayout(const std::string& viewId, - StackablePart::Pointer newPart) + LayoutPart::Pointer newPart) { pageLayout->SetRefPart(viewId, newPart); pageLayout->SetFolderPart(viewId, folder); // force creation of the view layout rec pageLayout->GetViewLayoutRec(viewId, true); } } diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryFolderLayout.h b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryFolderLayout.h index bd2d64ca06..f94bdf9a25 100644 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryFolderLayout.h +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryFolderLayout.h @@ -1,96 +1,96 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef BERRYFOLDERLAYOUT_H_ #define BERRYFOLDERLAYOUT_H_ #include "berryIFolderLayout.h" #include "berryPartStack.h" #include "berryViewFactory.h" namespace berry { class PageLayout; /** * \ingroup org_blueberry_ui_internal * * This layout is used to define the initial set of views and placeholders * in a folder. *

* Views are added to the folder by ID. This id is used to identify * a view descriptor in the view registry, and this descriptor is used to * instantiate the IViewPart. *

*/ class FolderLayout : public IFolderLayout { public: berryObjectMacro(FolderLayout) private: PartStack::Pointer folder; SmartPointer pageLayout; ViewFactory* viewFactory; public: /** * Create an instance of a FolderLayout belonging to a * PageLayout. */ FolderLayout(SmartPointer pageLayout, PartStack::Pointer folder, ViewFactory* viewFactory); /* (non-Javadoc) * @see org.blueberry.ui.IPlaceholderFolderLayout#addPlaceholder(java.lang.String) */ void AddPlaceholder(const std::string& viewId); /* (non-Javadoc) * @see org.blueberry.ui.IFolderLayout#addView(java.lang.String) */ void AddView(const std::string& viewId); /* (non-Javadoc) * @see org.blueberry.ui.IPlaceholderFolderLayout#getProperty(java.lang.String) */ std::string GetProperty(const std::string& id); /* (non-Javadoc) * @see org.blueberry.ui.IPlaceholderFolderLayout#setProperty(java.lang.String, java.lang.String) */ void SetProperty(const std::string& id, const std::string& value); private: /** * Inform the page layout of the new part created * and the folder the part belongs to. */ - void LinkPartToPageLayout(const std::string& viewId, StackablePart::Pointer newPart); + void LinkPartToPageLayout(const std::string& viewId, LayoutPart::Pointer newPart); }; } #endif /*BERRYFOLDERLAYOUT_H_*/ diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryILayoutContainer.h b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryILayoutContainer.h index 4f270c567f..5d0b6161d6 100644 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryILayoutContainer.h +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryILayoutContainer.h @@ -1,122 +1,122 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef BERRYILAYOUTCONTAINER_H_ #define BERRYILAYOUTCONTAINER_H_ #include "berryLayoutPart.h" #include "berryPartPane.h" #include namespace berry { /** * \ingroup org_blueberry_ui_internal * */ struct BERRY_UI ILayoutContainer : virtual public Object { berryObjectMacro(ILayoutContainer); ~ILayoutContainer(); typedef std::list ChildrenType; virtual bool AllowsAdd(LayoutPart::Pointer toAdd) = 0; /** * Add a child to the container. */ virtual void Add(LayoutPart::Pointer newPart) = 0; /** * Returns a list of layout children. */ - virtual ChildrenType GetChildren() = 0; + virtual ChildrenType GetChildren() const = 0; /** * Remove a child from the container. */ virtual void Remove(LayoutPart::Pointer part) = 0; /** * Replace one child with another */ virtual void Replace(LayoutPart::Pointer oldPart, LayoutPart::Pointer newPart) = 0; virtual void FindSashes(LayoutPart::Pointer toFind, PartPane::Sashes& result) = 0; /** * When a layout part closes, focus will return to the previously active part. * This method determines whether the parts in this container should participate * in this behavior. If this method returns true, its parts may automatically be * given focus when another part is closed. * * @return true iff the parts in this container may be given focus when the active * part is closed */ virtual bool AllowsAutoFocus() = 0; /** * Called by child parts to request a zoom in, given an immediate child * * @param toZoom * @since 3.1 */ //public void childRequestZoomIn(LayoutPart toZoom); /** * Called by child parts to request a zoom out * * @since 3.1 */ //public void childRequestZoomOut(); /** * Returns true iff the given child is obscured due to the fact that the container is zoomed into * another part. * * @param toTest * @return * @since 3.1 */ //public boolean childObscuredByZoom(LayoutPart toTest); /** * Returns true iff we are zoomed into the given part, given an immediate child of this container. * * @param toTest * @return * @since 3.1 */ //public boolean childIsZoomed(LayoutPart toTest); /** * Called when the preferred size of the given child has changed, requiring a * layout to be triggered. * * @param childThatChanged the child that triggered the new layout */ virtual void ResizeChild(LayoutPart::Pointer childThatChanged) = 0; }; } #endif /*BERRYILAYOUTCONTAINER_H_*/ diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryIStackableContainer.cpp b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryIStackableContainer.cpp deleted file mode 100644 index 96f6705e08..0000000000 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryIStackableContainer.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/*=================================================================== - -BlueBerry Platform - -Copyright (c) German Cancer Research Center, -Division of Medical and Biological Informatics. -All rights reserved. - -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR -A PARTICULAR PURPOSE. - -See LICENSE.txt or http://www.mitk.org for details. - -===================================================================*/ - -#include "berryIStackableContainer.h" - - -namespace berry { - -IStackableContainer::~IStackableContainer() -{ -} - -} diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryIStackableContainer.h b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryIStackableContainer.h deleted file mode 100755 index 08d78f52a8..0000000000 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryIStackableContainer.h +++ /dev/null @@ -1,127 +0,0 @@ -/*=================================================================== - -BlueBerry Platform - -Copyright (c) German Cancer Research Center, -Division of Medical and Biological Informatics. -All rights reserved. - -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR -A PARTICULAR PURPOSE. - -See LICENSE.txt or http://www.mitk.org for details. - -===================================================================*/ - - -#ifndef BERRYISTACKABLECONTAINER_H_ -#define BERRYISTACKABLECONTAINER_H_ - -#include "berryStackablePart.h" - -#include "berryPartPane.h" - -#include - -namespace berry { - -/** - * \ingroup org_blueberry_ui_internal - * - */ -struct BERRY_UI IStackableContainer : virtual public Object { - - berryObjectMacro(IStackableContainer); - - typedef std::list ChildrenType; - - ~IStackableContainer(); - - virtual bool AllowsAdd(StackablePart::Pointer toAdd) = 0; - - /** - * Add a child to the container. - */ - virtual void Add(StackablePart::Pointer newPart) = 0; - - /** - * Returnd the id for this stackable container - */ - virtual std::string GetID() const = 0; - - /** - * Returns a list of layout children. - */ - virtual ChildrenType GetChildren() const = 0; - - /** - * Remove a child from the container. - */ - virtual void Remove(StackablePart::Pointer part) = 0; - - /** - * Replace one child with another - */ - virtual void Replace(StackablePart::Pointer oldPart, StackablePart::Pointer newPart) = 0; - - virtual void FindSashes(PartPane::Sashes& result) = 0; - - /** - * When a layout part closes, focus will return to the previously active part. - * This method determines whether the parts in this container should participate - * in this behavior. If this method returns true, its parts may automatically be - * given focus when another part is closed. - * - * @return true iff the parts in this container may be given focus when the active - * part is closed - */ - virtual bool AllowsAutoFocus() = 0; - - /** - * Called by child parts to request a zoom in, given an immediate child - * - * @param toZoom - * @since 3.1 - */ - //public void childRequestZoomIn(LayoutPart toZoom); - - /** - * Called by child parts to request a zoom out - * - * @since 3.1 - */ - //public void childRequestZoomOut(); - - /** - * Returns true iff the given child is obscured due to the fact that the container is zoomed into - * another part. - * - * @param toTest - * @return - * @since 3.1 - */ - //public boolean childObscuredByZoom(LayoutPart toTest); - - /** - * Returns true iff we are zoomed into the given part, given an immediate child of this container. - * - * @param toTest - * @return - * @since 3.1 - */ - //public boolean childIsZoomed(LayoutPart toTest); - - /** - * Called when the preferred size of the given child has changed, requiring a - * layout to be triggered. - * - * @param childThatChanged the child that triggered the new layout - */ - virtual void ResizeChild(StackablePart::Pointer childThatChanged) = 0; - -}; - -} - -#endif /* BERRYISTACKABLECONTAINER_H_ */ diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryLayoutPart.cpp b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryLayoutPart.cpp index f0b6116ff8..610da95b7e 100644 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryLayoutPart.cpp +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryLayoutPart.cpp @@ -1,337 +1,346 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "berryLayoutPart.h" #include "berryILayoutContainer.h" #include "berryDetachedWindow.h" #include "tweaklets/berryGuiWidgetsTweaklet.h" #include "berryIWorkbenchWindow.h" #include "berryConstants.h" namespace berry { const std::string LayoutPart::PROP_VISIBILITY = "PROP_VISIBILITY"; //$NON-NLS-1$ LayoutPart::LayoutPart(const std::string& id_) : id(id_), deferCount(0) { } LayoutPart::~LayoutPart() { } bool LayoutPart::AllowsAutoFocus() { if (container != 0) { return container->AllowsAutoFocus(); } return true; } void LayoutPart::Dispose() { } Rectangle LayoutPart::GetBounds() { if (this->GetControl() == 0) return Rectangle(); return Tweaklets::Get(GuiWidgetsTweaklet::KEY)->GetBounds(this->GetControl()); } ILayoutContainer::Pointer LayoutPart::GetContainer() { return container; } +bool LayoutPart::IsPlaceHolder() const +{ + return false; +} + std::string LayoutPart::GetID() const { return id; } bool LayoutPart::IsCompressible() { return false; } Point LayoutPart::GetSize() { Rectangle r = this->GetBounds(); Point ptSize(r.width, r.height); return ptSize; } int LayoutPart::GetSizeFlags(bool /*horizontal*/) { return Constants::MIN; } int LayoutPart::ComputePreferredSize(bool /*width*/, int /*availableParallel*/, int /*availablePerpendicular*/, int preferredParallel) { return preferredParallel; } IDropTarget::Pointer LayoutPart::GetDropTarget(Object::Pointer /*draggedObject*/, const Point& /*displayCoordinates*/) { return IDropTarget::Pointer(0); } bool LayoutPart::IsDocked() { Shell::Pointer s = this->GetShell(); if (s == 0) { return false; } return s->GetData().Cast() != 0; } Shell::Pointer LayoutPart::GetShell() { void* ctrl = this->GetControl(); if (ctrl) { return Tweaklets::Get(GuiWidgetsTweaklet::KEY)->GetShell(ctrl); } return Shell::Pointer(0); } IWorkbenchWindow::Pointer LayoutPart::GetWorkbenchWindow() { Shell::Pointer s = this->GetShell(); if (s == 0) { return IWorkbenchWindow::Pointer(0); } Object::Pointer data = s->GetData(); if (data.Cast() != 0) { return data.Cast(); } else if (data.Cast() != 0) { return data.Cast()->GetWorkbenchPage()->GetWorkbenchWindow(); } return IWorkbenchWindow::Pointer(0); } void LayoutPart::MoveAbove(void* /*refControl*/) { } void LayoutPart::Reparent(void* newParent) { void* control = this->GetControl(); GuiWidgetsTweaklet* guiTweaklet = Tweaklets::Get(GuiWidgetsTweaklet::KEY); if ((control == 0) || (guiTweaklet->GetParent(control) == newParent)) { return; } if (guiTweaklet->IsReparentable(control)) { // make control small in case it is not resized with other controls //control.setBounds(0, 0, 0, 0); // By setting the control to disabled before moving it, // we ensure that the focus goes away from the control and its children // and moves somewhere else bool enabled = guiTweaklet->GetEnabled(control); guiTweaklet->SetEnabled(control, false); guiTweaklet->SetParent(control, newParent); guiTweaklet->SetEnabled(control, enabled); guiTweaklet->MoveAbove(control, 0); } } bool LayoutPart::GetVisible() { void* ctrl = this->GetControl(); if (ctrl) { return Tweaklets::Get(GuiWidgetsTweaklet::KEY)->GetVisible(ctrl); } return false; } bool LayoutPart::IsVisible() { void* ctrl = this->GetControl(); if (ctrl) { return Tweaklets::Get(GuiWidgetsTweaklet::KEY)->IsVisible(ctrl); } return false; } void LayoutPart::SetVisible(bool makeVisible) { void* ctrl = this->GetControl(); if (ctrl != 0) { if (makeVisible == Tweaklets::Get(GuiWidgetsTweaklet::KEY)->GetVisible(ctrl)) { return; } // if (!makeVisible && this->IsFocusAncestor(ctrl)) // { // // Workaround for Bug 60970 [EditorMgmt] setActive() called on an editor when it does not have focus. // // Force focus on the shell so that when ctrl is hidden, // // SWT does not try to send focus elsewhere, which may cause // // some other part to be activated, which affects the part // // activation order and can cause flicker. // ctrl.getShell().forceFocus(); // } Tweaklets::Get(GuiWidgetsTweaklet::KEY)->SetVisible(ctrl, makeVisible); } } bool LayoutPart::IsFocusAncestor(void* /*ctrl*/) { // Control f = ctrl.getDisplay().getFocusControl(); // while (f != null && f != ctrl) // { // f = f.getParent(); // } // return f == ctrl; return false; } void LayoutPart::SetBounds(const Rectangle& r) { void* ctrl = this->GetControl(); if (ctrl) { return Tweaklets::Get(GuiWidgetsTweaklet::KEY)->SetBounds(ctrl, r); } } void LayoutPart::SetContainer(ILayoutContainer::Pointer container) { this->container = container; //TODO Zoom // if (container != 0) // { // setZoomed(container.childIsZoomed(this)); -// } + // } +} + +void LayoutPart::SetFocus() +{ } void LayoutPart::SetID(const std::string& str) { id = str; } LayoutPart::Pointer LayoutPart::GetPart() { return LayoutPart::Pointer(this); } void LayoutPart::DeferUpdates(bool shouldDefer) { if (shouldDefer) { if (deferCount == 0) { this->StartDeferringEvents(); } deferCount++; } else { if (deferCount> 0) { deferCount--; if (deferCount == 0) { this->HandleDeferredEvents(); } } } } void LayoutPart::StartDeferringEvents() { } void LayoutPart::HandleDeferredEvents() { } bool LayoutPart::IsDeferred() { return deferCount> 0; } void LayoutPart::DescribeLayout(std::string& /*buf*/) const { } std::string LayoutPart::GetPlaceHolderId() { return this->GetID(); } void LayoutPart::ResizeChild(LayoutPart::Pointer /*childThatChanged*/) { } void LayoutPart::FlushLayout() { ILayoutContainer::Pointer container = this->GetContainer(); if (container != 0) { container->ResizeChild(LayoutPart::Pointer(this)); } } bool LayoutPart::AllowsAdd(LayoutPart::Pointer /*toAdd*/) { return false; } std::string LayoutPart::ToString() { return ""; } void LayoutPart::TestInvariants() { } } diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryLayoutPart.h b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryLayoutPart.h index 6ba840a7be..c2e4d0268e 100644 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryLayoutPart.h +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryLayoutPart.h @@ -1,297 +1,305 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef BERRYLAYOUTPART_H_ #define BERRYLAYOUTPART_H_ #include #include "berryIDropTarget.h" #include "berryISizeProvider.h" #include "berryRectangle.h" #include "berryPoint.h" #include "berryShell.h" namespace berry { struct ILayoutContainer; struct IWorkbenchWindow; /** * \ingroup org_blueberry_ui_internal * * A presentation part is used to build the presentation for the * workbench. Common subclasses are pane and folder. */ -class LayoutPart : virtual public Object { //, public ISizeProvider { +class LayoutPart : virtual public Object, public virtual ISizeProvider +{ public: berryObjectMacro(LayoutPart); protected: SmartPointer container; protected: std::string id; public: static const std::string PROP_VISIBILITY;// = "PROP_VISIBILITY"; //$NON-NLS-1$ /** * Number of times deferUpdates(true) has been called without a corresponding * deferUpdates(false) */ private: int deferCount; /** * PresentationPart constructor comment. */ public: LayoutPart(const std::string& id); public: virtual ~LayoutPart(); /** * When a layout part closes, focus will return to a previously active part. * This method determines whether this part should be considered for activation * when another part closes. If a group of parts are all closing at the same time, * they will all return false from this method while closing to ensure that the * parent does not activate a part that is in the process of closing. Parts will * also return false from this method if they are minimized, closed fast views, * obscured by zoom, etc. * * @return true iff the parts in this container may be given focus when the active * part is closed */ public: virtual bool AllowsAutoFocus(); /** * Creates the GUI control */ public: virtual void CreateControl(void* parent) = 0; /** * Disposes the GUI control * * This can be used to execute cleanup code or notify listeners * when a LayoutPart is no longer used, but is still referenced * by a SmartPointer (instead of putting the code in the LayoutPart * destructor). */ public: virtual void Dispose(); /** * Gets the presentation bounds. */ public: Rectangle GetBounds(); /** * Gets the parent for this part. *

* In general, this is non-null if the object has been added to a container and the * container's widgetry exists. The exception to this rule is PartPlaceholders * created when restoring a ViewStack using restoreState, which point to the * ViewStack even if its widgetry doesn't exist yet. Returns null in the remaining * cases. *

*

* TODO: change the semantics of this method to always point to the parent container, * regardless of whether its widgetry exists. Locate and refactor code that is currently * depending on the special cases. *

*/ public: virtual SmartPointer GetContainer(); /** * Get the part control. This method may return null. */ public: virtual void* GetControl() = 0; + public: virtual bool IsPlaceHolder() const; + /** * Gets the ID for this part. */ public: virtual std::string GetID() const; public: virtual bool IsCompressible(); /** * Gets the presentation size. */ public: virtual Point GetSize(); /** * @see org.blueberry.ui.presentations.StackPresentation#getSizeFlags(boolean) * * @since 3.1 */ public: virtual int GetSizeFlags(bool horizontal); /** * @see org.blueberry.ui.presentations.StackPresentation#computePreferredSize(boolean, int, int, int) * * @since 3.1 */ public: virtual int ComputePreferredSize(bool width, int availableParallel, int availablePerpendicular, int preferredParallel); public: virtual IDropTarget::Pointer GetDropTarget(Object::Pointer draggedObject, const Point& displayCoordinates); public: bool IsDocked(); public: virtual Shell::Pointer GetShell(); /** * Returns the workbench window window for a part. * * @return the workbench window, or null if there's no window * associated with this part. */ public: virtual SmartPointer GetWorkbenchWindow(); /** * Move the control over another one. */ public: virtual void MoveAbove(void* refControl); /** * Reparent a part. */ public: virtual void Reparent(void* newParent); /** * Returns true if this part was set visible. This returns whatever was last passed into * setVisible, but does not necessarily indicate that the part can be seen (ie: one of its * ancestors may be invisible) */ public: virtual bool GetVisible(); /** * Returns true if this part can be seen. Returns false if the part or any of its ancestors * are invisible. */ public: virtual bool IsVisible(); /** * Shows the receiver if visible is true otherwise hide it. */ public: virtual void SetVisible(bool makeVisible); /** * Returns true if the given control or any of its descendents has focus. */ private: virtual bool IsFocusAncestor(void* ctrl); /** * Sets the presentation bounds. */ public: virtual void SetBounds(const Rectangle& r); /** * Sets the parent for this part. */ public: virtual void SetContainer(SmartPointer container); + /** + * Sets focus to this part. + */ + public: virtual void SetFocus(); + /** * Sets the part ID. */ public: virtual void SetID(const std::string& str); /* (non-Javadoc) * @see org.blueberry.ui.internal.IWorkbenchDragDropPart#getPart() */ public: virtual LayoutPart::Pointer GetPart(); /** * deferUpdates(true) disables widget updates until a corresponding call to * deferUpdates(false). Exactly what gets deferred is the decision * of each LayoutPart, however the part may only defer operations in a manner * that does not affect the final result. * That is, the state of the receiver after the final call to deferUpdates(false) * must be exactly the same as it would have been if nothing had been deferred. * * @param shouldDefer true iff events should be deferred */ public: void DeferUpdates(bool shouldDefer); /** * This is called when deferUpdates(true) causes UI events for this * part to be deferred. Subclasses can overload to initialize any data * structures that they will use to collect deferred events. */ protected: virtual void StartDeferringEvents(); /** * Immediately processes all UI events which were deferred due to a call to * deferUpdates(true). This is called when the last call is made to * deferUpdates(false). Subclasses should overload this method if they * defer some or all UI processing during deferUpdates. */ protected: virtual void HandleDeferredEvents(); /** * Subclasses can call this method to determine whether UI updates should * be deferred. Returns true iff there have been any calls to deferUpdates(true) * without a corresponding call to deferUpdates(false). Any operation which is * deferred based on the result of this method should be performed later within * handleDeferredEvents(). * * @return true iff updates should be deferred. */ protected: bool IsDeferred(); /** * Writes a description of the layout to the given string buffer. * This is used for drag-drop test suites to determine if two layouts are the * same. Like a hash code, the description should compare as equal iff the * layouts are the same. However, it should be user-readable in order to * help debug failed tests. Although these are english readable strings, * they do not need to be translated. * * @param buf */ public: virtual void DescribeLayout(std::string& buf) const; /** * Returns an id representing this part, suitable for use in a placeholder. * * @since 3.0 */ public: virtual std::string GetPlaceHolderId(); public: virtual void ResizeChild(LayoutPart::Pointer childThatChanged); public: void FlushLayout(); /** * Returns true iff the given part can be added to this ILayoutContainer * @param toAdd * @return * @since 3.1 */ public: virtual bool AllowsAdd(LayoutPart::Pointer toAdd); /** * Tests the integrity of this object. Throws an exception if the object's state * is not internally consistent. For use in test suites. */ public: virtual void TestInvariants(); public: virtual std::string ToString(); }; } #endif /*BERRYLAYOUTPART_H_*/ diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryLayoutTree.cpp b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryLayoutTree.cpp index 884f982829..0fb669f6af 100644 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryLayoutTree.cpp +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryLayoutTree.cpp @@ -1,481 +1,480 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "berryLayoutTree.h" #include "berryLayoutTreeNode.h" #include "berryLayoutPartSash.h" -#include "berryContainerPlaceholder.h" #include "berryConstants.h" namespace berry { int LayoutTree::minCacheHits = 0; int LayoutTree::minCacheMisses = 0; int LayoutTree::maxCacheHits = 0; int LayoutTree::maxCacheMisses = 0; LayoutTree::LayoutTree(LayoutPart::Pointer part) : parent(0), cachedMinimumWidthHint(Constants::DEFAULT), cachedMinimumWidth(Constants::DEFAULT), cachedMinimumHeightHint(Constants::DEFAULT), cachedMinimumHeight(Constants::DEFAULT), cachedMaximumWidthHint(Constants::DEFAULT), cachedMaximumWidth(Constants::DEFAULT), cachedMaximumHeightHint(Constants::DEFAULT), cachedMaximumHeight(Constants::DEFAULT), forceLayout(true), sizeFlagsDirty(true), widthSizeFlags(0), heightSizeFlags(0) { this->part = part; } LayoutPart::Pointer LayoutTree::ComputeRelation( std::list& /*relations*/) { return part; } LayoutPart::Pointer LayoutTree::FindPart(const Point& /*toFind*/) { return part; } void LayoutTree::DisposeSashes() { } LayoutTree::Pointer LayoutTree::Find(LayoutPart::Pointer child) { if (part != child) { return LayoutTree::Pointer(0); } return LayoutTree::Pointer(this); } void LayoutTree::FindSashes(PartPane::Sashes sashes) { if (this->GetParent() == 0) { return; } this->GetParent()->FindSashes(LayoutTree::Pointer(this), sashes); } LayoutPart::Pointer LayoutTree::FindBottomRight() { return part; } LayoutTreeNode::Pointer LayoutTree::FindSash(LayoutPartSash::Pointer /*sash*/) { return LayoutTreeNode::Pointer(0); } Rectangle LayoutTree::GetBounds() { return currentBounds; } int LayoutTree::Subtract(int a, int b) { poco_assert(b >= 0 && b < INF); return Add(a, -b); } int LayoutTree::Add(int a, int b) { if (a == INF || b == INF) { return INF; } return a + b; } void LayoutTree::AssertValidSize(int toCheck) { poco_assert(toCheck >= 0 && (toCheck == INF || toCheck < INF / 2)); } int LayoutTree::ComputePreferredSize(bool width, int availableParallel, int availablePerpendicular, int preferredParallel) { this->AssertValidSize(availableParallel); this->AssertValidSize(availablePerpendicular); this->AssertValidSize(preferredParallel); if (!this->IsVisible()) { return 0; } if (availableParallel == 0) { return 0; } if (preferredParallel == 0) { return std::min(availableParallel, this->ComputeMinimumSize(width, availablePerpendicular)); } else if (preferredParallel == INF && availableParallel == INF) { return this->ComputeMaximumSize(width, availablePerpendicular); } // Optimization: if this subtree doesn't have any size preferences beyond its minimum and maximum // size, simply return the preferred size if (!this->HasSizeFlag(width, Constants::FILL)) { return preferredParallel; } int result = this->DoComputePreferredSize(width, availableParallel, availablePerpendicular, preferredParallel); return result; } int LayoutTree::DoGetSizeFlags(bool width) { return part->GetSizeFlags(width); } int LayoutTree::DoComputePreferredSize(bool width, int availableParallel, int availablePerpendicular, int preferredParallel) { int result = std::min(availableParallel, part->ComputePreferredSize(width, availableParallel, availablePerpendicular, preferredParallel)); this->AssertValidSize(result); return result; } int LayoutTree::ComputeMinimumSize(bool width, int availablePerpendicular) { this->AssertValidSize(availablePerpendicular); // Optimization: if this subtree has no minimum size, then always return 0 as its // minimum size. if (!this->HasSizeFlag(width, Constants::MIN)) { return 0; } // If this subtree doesn't contain any wrapping controls (ie: they don't care // about their perpendicular size) then force the perpendicular // size to be INF. This ensures that we will get a cache hit // every time for non-wrapping controls. if (!this->HasSizeFlag(width, Constants::WRAP)) { availablePerpendicular = INF; } if (width) { // Check if we have a cached width measurement (we can only return a cached // value if we computed it for the same height) if (cachedMinimumWidthHint == availablePerpendicular) { minCacheHits++; return cachedMinimumWidth; } // Recompute the minimum width and store it in the cache minCacheMisses++; int result = this->DoComputeMinimumSize(width, availablePerpendicular); cachedMinimumWidth = result; cachedMinimumWidthHint = availablePerpendicular; return result; } else { // Check if we have a cached height measurement (we can only return a cached // value if we computed it for the same width) if (cachedMinimumHeightHint == availablePerpendicular) { minCacheHits++; return cachedMinimumHeight; } // Recompute the minimum width and store it in the cache minCacheMisses++; int result = this->DoComputeMinimumSize(width, availablePerpendicular); cachedMinimumHeight = result; cachedMinimumHeightHint = availablePerpendicular; return result; } } void LayoutTree::PrintCacheStatistics() { BERRY_INFO << "minimize cache " << minCacheHits << " / " << (minCacheHits + minCacheMisses) << " hits " << (minCacheHits * 100 / (minCacheHits + minCacheMisses)) << "%\n"; BERRY_INFO << "maximize cache " << maxCacheHits << " / " << (maxCacheHits + maxCacheMisses) << " hits" << (maxCacheHits * 100 / (maxCacheHits + maxCacheMisses)) << "%\n"; } int LayoutTree::DoComputeMinimumSize(bool width, int availablePerpendicular) { int result = this->DoComputePreferredSize(width, INF, availablePerpendicular, 0); this->AssertValidSize(result); return result; } int LayoutTree::ComputeMaximumSize(bool width, int availablePerpendicular) { this->AssertValidSize(availablePerpendicular); // Optimization: if this subtree has no maximum size, then always return INF as its // maximum size. if (!this->HasSizeFlag(width, Constants::MAX)) { return INF; } // If this subtree doesn't contain any wrapping controls (ie: they don't care // about their perpendicular size) then force the perpendicular // size to be INF. This ensures that we will get a cache hit // every time. if (!this->HasSizeFlag(width, Constants::WRAP)) { availablePerpendicular = INF; } if (width) { // Check if we have a cached width measurement (we can only return a cached // value if we computed it for the same height) if (cachedMaximumWidthHint == availablePerpendicular) { maxCacheHits++; return cachedMaximumWidth; } maxCacheMisses++; // Recompute the maximum width and store it in the cache int result = this->DoComputeMaximumSize(width, availablePerpendicular); cachedMaximumWidth = result; cachedMaximumWidthHint = availablePerpendicular; return result; } else { // Check if we have a cached height measurement if (cachedMaximumHeightHint == availablePerpendicular) { maxCacheHits++; return cachedMaximumHeight; } maxCacheMisses++; // Recompute the maximum height and store it in the cache int result = this->DoComputeMaximumSize(width, availablePerpendicular); cachedMaximumHeight = result; cachedMaximumHeightHint = availablePerpendicular; return result; } } int LayoutTree::DoComputeMaximumSize(bool width, int availablePerpendicular) { return this->DoComputePreferredSize(width, INF, availablePerpendicular, INF); } void LayoutTree::FlushNode() { // Clear cached sizes cachedMinimumWidthHint = Constants::DEFAULT; cachedMinimumWidth = Constants::DEFAULT; cachedMinimumHeightHint = Constants::DEFAULT; cachedMinimumHeight = Constants::DEFAULT; cachedMaximumWidthHint = Constants::DEFAULT; cachedMaximumWidth = Constants::DEFAULT; cachedMaximumHeightHint = Constants::DEFAULT; cachedMaximumHeight = Constants::DEFAULT; // Flags may have changed. Ensure that they are recomputed the next time around sizeFlagsDirty = true; // The next setBounds call should trigger a layout even if set to the same bounds since // one of the children has changed. forceLayout = true; } void LayoutTree::FlushChildren() { this->FlushNode(); } void LayoutTree::FlushCache() { this->FlushNode(); if (parent != 0) { parent->FlushCache(); } } int LayoutTree::GetSizeFlags(bool width) { if (sizeFlagsDirty) { widthSizeFlags = this->DoGetSizeFlags(true); heightSizeFlags = this->DoGetSizeFlags(false); sizeFlagsDirty = false; } return width ? widthSizeFlags : heightSizeFlags; } LayoutTreeNode* LayoutTree::GetParent() const { return parent; } LayoutTree::Pointer LayoutTree::Insert(LayoutPart::Pointer child, bool left, LayoutPartSash::Pointer sash, LayoutPart::Pointer relative) { LayoutTree::Pointer relativeChild = this->Find(relative); LayoutTreeNode::Pointer node(new LayoutTreeNode(sash)); if (relativeChild == 0) { //Did not find the relative part. Insert beside the root. node->SetChild(left, child); node->SetChild(!left, LayoutTree::Pointer(this)); return node; } else { LayoutTreeNode* oldParent = relativeChild->GetParent(); node->SetChild(left, child); node->SetChild(!left, relativeChild); if (oldParent == 0) { //It was the root. Return a new root. return node; } oldParent->ReplaceChild(relativeChild, node); return LayoutTree::Pointer(this); } } bool LayoutTree::IsCompressible() { //Added for bug 19524 return part->IsCompressible(); } bool LayoutTree::IsVisible() { - return part.Cast().IsNull(); + return !part->IsPlaceHolder(); } void LayoutTree::RecomputeRatio() { } LayoutTree::Pointer LayoutTree::Remove(LayoutPart::Pointer child) { LayoutTree::Pointer tree = this->Find(child); if (tree == 0) { return LayoutTree::Pointer(this); } LayoutTreeNode::Pointer oldParent(tree->GetParent()); if (oldParent == 0) { //It was the root and the only child of this tree return LayoutTree::Pointer(0); } if (oldParent->GetParent() == 0) { return oldParent->Remove(tree); } oldParent->Remove(tree); return LayoutTree::Pointer(this); } void LayoutTree::SetBounds(const Rectangle& bounds) { if (!(bounds == currentBounds) || forceLayout) { currentBounds = bounds; this->DoSetBounds(currentBounds); forceLayout = false; } } void LayoutTree::DoSetBounds(const Rectangle& bounds) { part->SetBounds(bounds); } void LayoutTree::SetParent(LayoutTreeNode* parent) { this->parent = parent; } void LayoutTree::SetPart(LayoutPart::Pointer part) { this->part = part; this->FlushCache(); } std::string LayoutTree::ToString() { return "(" + part->ToString() + ")";//$NON-NLS-2$//$NON-NLS-1$ } void LayoutTree::CreateControl(void* /*parent*/) { } void LayoutTree::DescribeLayout(std::string& buf) const { part->DescribeLayout(buf); } bool LayoutTree::HasSizeFlag(bool width, int flag) { return (this->GetSizeFlags(width) & flag) != 0; } } diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPageLayout.cpp b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPageLayout.cpp index 61c087d3c4..8e5f61d28d 100644 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPageLayout.cpp +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPageLayout.cpp @@ -1,689 +1,673 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "berryPageLayout.h" #include "berryWorkbenchPlugin.h" #include "berryLayoutHelper.h" #include "berryViewLayout.h" #include "berryPresentationFactoryUtil.h" #include "berryFolderLayout.h" #include "berryPlaceholderFolderLayout.h" #include "berryUIException.h" #include "berryConstants.h" namespace berry { PageLayout::PageLayout() : editorVisible(true) { //no-op } PageLayout::PageLayout(ViewSashContainer::Pointer container, ViewFactory* viewFactory, LayoutPart::Pointer editorFolder, IPerspectiveDescriptor::Pointer descriptor) : editorVisible(true) { this->viewFactory = viewFactory; this->rootLayoutContainer = container; this->editorFolder = editorFolder; this->descriptor = descriptor; this->Prefill(); } void PageLayout::AddEditorArea() { try { // Create the part. -// StackablePart::Pointer newPart = this->CreateView(ID_EDITOR_AREA); -// if (newPart == 0) -// { -// // this should never happen as long as newID is the editor ID. -// return; -// } -// - // this->SetFolderPart(ID_EDITOR_AREA, editorFolder.Cast()); + LayoutPart::Pointer newPart = this->CreateView(ID_EDITOR_AREA); + if (newPart == 0) + { + // this should never happen as long as newID is the editor ID. + return; + } + + this->SetRefPart(ID_EDITOR_AREA, newPart); // Add it to the layout. - rootLayoutContainer->Add(editorFolder); + rootLayoutContainer->Add(newPart); } catch (PartInitException& e) { WorkbenchPlugin::Log(this->GetClassName(), "AddEditorArea()", e); //$NON-NLS-1$ } } ViewLayoutRec::Pointer PageLayout::GetViewLayoutRec(const std::string& id, bool create) { ViewLayoutRec::Pointer rec = mapIDtoViewLayoutRec[id]; if (rec == 0 && create) { rec = new ViewLayoutRec(); // set up the view layout appropriately if the page layout is fixed if (this->IsFixed()) { rec->isCloseable = false; rec->isMoveable = false; } mapIDtoViewLayoutRec[id] = rec; } return rec; } -void PageLayout::AddStack(IStackableContainer::Pointer newPart, +void PageLayout::AddPart(LayoutPart::Pointer newPart, const std::string& partId, int relationship, float ratio, const std::string& refId) { - //this->SetRefPart(partId, newPart); - this->SetFolderPart(partId, newPart); + this->SetRefPart(partId, newPart); // If the referenced part is inside a folder, // then use the folder as the reference part. - IStackableContainer::Pointer refPart = this->GetFolderPart(refId); - - // if (refPart == 0) -// { -// refPart = this->GetRefPart(refId); -// } + LayoutPart::Pointer refPart = this->GetFolderPart(refId); + if (refPart == 0) + { + refPart = this->GetRefPart(refId); + } // Add it to the layout. if (refPart != 0) { ratio = this->NormalizeRatio(ratio); - rootLayoutContainer->Add(newPart.Cast(), this->GetPartSashConst(relationship), ratio, - refPart.Cast()); - } - else if (refId == ID_EDITOR_AREA) - { - ratio = this->NormalizeRatio(ratio); - rootLayoutContainer->Add(newPart.Cast(), this->GetPartSashConst(relationship), ratio, - this->editorFolder.Cast()); + rootLayoutContainer->Add(newPart, this->GetPartSashConst(relationship), ratio, refPart); } else { WorkbenchPlugin::Log("Reference part does not exist yet: " + refId); - rootLayoutContainer->Add(newPart.Cast()); + rootLayoutContainer->Add(newPart); } } void PageLayout::AddPerspectiveShortcut(const std::string& id) { if (std::find(perspectiveShortcuts.begin(), perspectiveShortcuts.end(), id) == perspectiveShortcuts.end()) { perspectiveShortcuts.push_back(id); } } void PageLayout::AddPlaceholder(const std::string& viewId, int relationship, float ratio, const std::string& refId) { if (!this->CheckValidPlaceholderId(viewId)) { return; } - // Create a folder. - ContainerPlaceholder::Pointer folder(new ContainerPlaceholder(viewId)); - folder->SetContainer(rootLayoutContainer); - folder->SetRealContainer(PartStack::Pointer(new PartStack(rootLayoutContainer->page))); - //folder->SetId(folderId); // Create the placeholder. PartPlaceholder::Pointer newPart(new PartPlaceholder(viewId)); - folder->Add(newPart); - this->AddStack(folder, viewId, relationship, ratio, refId); + this->AddPart(newPart, viewId, relationship, ratio, refId); // force creation of the view layout rec this->GetViewLayoutRec(viewId, true); } bool PageLayout::CheckValidPlaceholderId(const std::string& id) { // Check that view is not already in layout. // This check is done even if the id has a wildcard, since it's incorrect to create // multiple placeholders with the same id, wildcard or not. if (this->CheckPartInLayout(id)) { return false; } // check that primary view id is valid, but only if it has no wildcard std::string primaryId = ViewFactory::ExtractPrimaryId(id); if (!ViewFactory::HasWildcard(primaryId)) { IViewRegistry* reg = WorkbenchPlugin::GetDefault()->GetViewRegistry(); IViewDescriptor::Pointer desc = reg->Find(primaryId); if (desc == 0) { // cannot safely open the dialog so log the problem WorkbenchPlugin::Log("Unable to find view with id: " + primaryId + ", when creating perspective " + this->GetDescriptor()->GetId()); //$NON-NLS-1$ //$NON-NLS-2$ return false; } } return true; } void PageLayout::AddShowInPart(const std::string& id) { if (std::find(showInPartIds.begin(), showInPartIds.end(), id) == showInPartIds.end()) { showInPartIds.push_back(id); } } void PageLayout::AddShowViewShortcut(const std::string& id) { if (std::find(showViewShortcuts.begin(), showViewShortcuts.end(), id) == showInPartIds.end()) { showViewShortcuts.push_back(id); } } void PageLayout::AddView(const std::string& viewId, int relationship, float ratio, const std::string& refId) { this->AddView(viewId, relationship, ratio, refId, false, false, true); } void PageLayout::AddView(const std::string& viewId, int relationship, float ratio, const std::string& refId, bool minimized) { this->AddView(viewId, relationship, ratio, refId, minimized, false, true); } void PageLayout::AddView(const std::string& viewId, int relationship, float ratio, const std::string& refId, bool /*minimized*/, bool standalone, bool showTitle) { if (this->CheckPartInLayout(viewId)) { return; } try { // Create the part. - StackablePart::Pointer newPart = this->CreateView(viewId); + LayoutPart::Pointer newPart = this->CreateView(viewId); if (newPart == 0) { this->AddPlaceholder(viewId, relationship, ratio, refId); - //TODO ViewActivator for IIdentifier - //LayoutHelper::AddViewActivator(this, viewId); + LayoutHelper::AddViewActivator(PageLayout::Pointer(this), viewId); } else { int appearance = PresentationFactoryUtil::ROLE_VIEW; if (standalone) { if (showTitle) { appearance = PresentationFactoryUtil::ROLE_STANDALONE; } else { appearance = PresentationFactoryUtil::ROLE_STANDALONE_NOTITLE; } } // PartStack for views PartStack::Pointer newFolder(new PartStack(rootLayoutContainer->page, true, appearance, 0)); newFolder->Add(newPart); this->SetFolderPart(viewId, newFolder); - this->AddStack(newFolder, viewId, relationship, ratio, refId); + this->AddPart(newFolder, viewId, relationship, ratio, refId); // force creation of the view layout rec this->GetViewLayoutRec(viewId, true); // Capture any minimized stacks // if (minimized) // { // // Remember the minimized stacks so we can // // move them to the trim when the Perspective // // activates... // minimizedStacks.add(newFolder); // } } } catch (PartInitException& e) { WorkbenchPlugin::Log(this->GetClassName(), "AddView()", e); //$NON-NLS-1$ } } // List getMinimizedStacks() { // return minimizedStacks; // } bool PageLayout::CheckPartInLayout(const std::string& partId) { if (partId == ID_EDITOR_AREA) return true; if (this->GetRefPart(partId) != 0) // || this->IsFastViewId(partId)) { WorkbenchPlugin::Log("Part already exists in page layout: " + partId); return true; } if (this->GetFolderPart(partId) != 0) // || this->IsFastViewId(partId)) { WorkbenchPlugin::Log("Part already exists in page layout: " + partId); return true; } return false; } IFolderLayout::Pointer PageLayout::CreateFolder(const std::string& folderId, int relationship, float ratio, const std::string& refId) { if (this->CheckPartInLayout(folderId)) { - IStackableContainer::Pointer folder = this->GetFolderPart(folderId); + ILayoutContainer::Pointer folder = this->GetFolderPart(folderId); return mapFolderToFolderLayout[folder].Cast(); } // Create the folder. PartStack::Pointer folder(new PartStack(rootLayoutContainer->page)); folder->SetID(folderId); - this->AddStack(folder, folderId, relationship, ratio, refId); + this->AddPart(folder, folderId, relationship, ratio, refId); // Create a wrapper. FolderLayout::Pointer layout(new FolderLayout(PageLayout::Pointer(this), folder, viewFactory)); mapFolderToFolderLayout.insert(std::make_pair(folder, layout)); return layout; } IPlaceholderFolderLayout::Pointer PageLayout::CreatePlaceholderFolder( const std::string& folderId, int relationship, float ratio, const std::string& refId) { if (this->CheckPartInLayout(folderId)) { ContainerPlaceholder::Pointer folder = this->GetRefPart(folderId).Cast(); return mapFolderToFolderLayout[folder]; } // Create the folder. ContainerPlaceholder::Pointer folder(new ContainerPlaceholder("")); folder->SetContainer(rootLayoutContainer); - folder->SetRealContainer(IStackableContainer::Pointer(new PartStack(rootLayoutContainer->page))); + folder->SetRealContainer(ILayoutContainer::Pointer(new PartStack(rootLayoutContainer->page))); folder->SetID(folderId); - this->AddStack(folder, folderId, relationship, ratio, refId); + this->AddPart(folder, folderId, relationship, ratio, refId); // Create a wrapper. IPlaceholderFolderLayout::Pointer layout(new PlaceholderFolderLayout(PageLayout::Pointer(this), folder)); mapFolderToFolderLayout.insert(std::make_pair(folder, layout)); return layout; } -StackablePart::Pointer PageLayout::CreateView(const std::string& partID) +LayoutPart::Pointer PageLayout::CreateView(const std::string& partID) { -// if (partID == ID_EDITOR_AREA) -// { -// return editorFolder; -// } + if (partID == ID_EDITOR_AREA) + { + return editorFolder; + } - IViewDescriptor::Pointer viewDescriptor = viewFactory->GetViewRegistry() - ->Find(ViewFactory::ExtractPrimaryId(partID)); +// IViewDescriptor::Pointer viewDescriptor = viewFactory->GetViewRegistry() +// ->Find(ViewFactory::ExtractPrimaryId(partID)); // if (WorkbenchActivityHelper.filterItem(viewDescriptor)) // { // return null; // } return LayoutHelper::CreateView(this->GetViewFactory(), partID); } IPerspectiveDescriptor::Pointer PageLayout::GetDescriptor() { return descriptor; } std::string PageLayout::GetEditorArea() { return ID_EDITOR_AREA; } -IStackableContainer::Pointer PageLayout::GetFolderPart(const std::string& viewId) +PartStack::Pointer PageLayout::GetFolderPart(const std::string& viewId) { - return mapIDtoFolder[viewId]; + return mapIDtoFolder[viewId].Cast(); } int PageLayout::GetPartSashConst(int nRelationship) { return nRelationship; } std::vector PageLayout::GetPerspectiveShortcuts() { return perspectiveShortcuts; } -StackablePart::Pointer PageLayout::GetRefPart(const std::string& partID) +LayoutPart::Pointer PageLayout::GetRefPart(const std::string& partID) { return mapIDtoPart[partID]; } PartSashContainer::Pointer PageLayout::GetRootLayoutContainer() { return rootLayoutContainer; } std::vector PageLayout::GetShowInPartIds() { return showInPartIds; } std::vector PageLayout::GetShowViewShortcuts() { return showViewShortcuts; } ViewFactory* PageLayout::GetViewFactory() { return viewFactory; } bool PageLayout::IsEditorAreaVisible() { return editorVisible; } float PageLayout::NormalizeRatio(float in) { if (in < RATIO_MIN) { in = RATIO_MIN; } if (in > RATIO_MAX) { in = RATIO_MAX; } return in; } void PageLayout::Prefill() { this->AddEditorArea(); //TODO action sets // Add default action sets. // ActionSetRegistry reg = WorkbenchPlugin.getDefault() // .getActionSetRegistry(); // IActionSetDescriptor[] array = reg.getActionSets(); // int count = array.length; // for (int nX = 0; nX < count; nX++) // { // IActionSetDescriptor desc = array[nX]; // if (desc.isInitiallyVisible()) // { // addActionSet(desc.getId()); // } // } } void PageLayout::SetEditorAreaVisible(bool showEditorArea) { editorVisible = showEditorArea; } void PageLayout::SetFixed(bool fixed) { this->fixed = fixed; } bool PageLayout::IsFixed() { return fixed; } void PageLayout::SetFolderPart(const std::string& viewId, ContainerPlaceholder::Pointer container) { - IStackableContainer::Pointer tabFolder = container->GetRealContainer(); - mapIDtoFolder[viewId] = tabFolder; + LayoutPart::Pointer tabFolder = container->GetRealContainer(); + mapIDtoFolder[viewId] = tabFolder.Cast(); } void PageLayout::SetFolderPart(const std::string& viewId, PartStack::Pointer folder) { - mapIDtoFolder[viewId] = folder.Cast(); + mapIDtoFolder[viewId] = folder.Cast(); } void PageLayout::SetFolderPart(const std::string& viewId, - IStackableContainer::Pointer folder) + ILayoutContainer::Pointer folder) { mapIDtoFolder[viewId] = folder; } -void PageLayout::SetRefPart(const std::string& partID, StackablePart::Pointer part) +void PageLayout::SetRefPart(const std::string& partID, LayoutPart::Pointer part) { mapIDtoPart[partID] = part; } -void PageLayout::StackPart(StackablePart::Pointer newPart, +void PageLayout::StackPart(LayoutPart::Pointer newPart, const std::string& viewId, const std::string& refId) { this->SetRefPart(viewId, newPart); // force creation of the view layout rec this->GetViewLayoutRec(viewId, true); // If ref part is in a folder than just add the // new view to that folder. PartStack::Pointer folder = this->GetFolderPart(refId).Cast(); if (folder != 0) { folder->Add(newPart); this->SetFolderPart(viewId, folder); return; } // parts are now always contained in folders // // If the ref part is in the page layout then create // // a new folder and add the new view. -// StackablePart::Pointer refPart = this->GetRefPart(refId); +// LayoutPart::Pointer refPart = this->GetRefPart(refId); // if (refPart != 0) // && (refPart instanceof PartPane || refPart instanceof PartPlaceholder)) // { // PartStack::Pointer newFolder(new PartStack(rootLayoutContainer->page)); // rootLayoutContainer->Replace(refPart, newFolder); // newFolder->Add(refPart); // newFolder->Add(newPart); // this->SetFolderPart(refId, newFolder); // this->SetFolderPart(viewId, newFolder); // return; // } // If ref part is not found then just do add. WorkbenchPlugin::Log("Referenced part does not exist yet: " + refId); PartStack::Pointer newFolder(new PartStack(rootLayoutContainer->page)); newFolder->Add(newPart); this->SetFolderPart(viewId, newFolder); rootLayoutContainer->Add(newFolder); } void PageLayout::StackPlaceholder(const std::string& viewId, const std::string& refId) { if (this->CheckPartInLayout(viewId)) { return; } // Create the placeholder. PartPlaceholder::Pointer newPart(new PartPlaceholder(viewId)); - StackablePart::Pointer refPart = this->GetRefPart(refId); + LayoutPart::Pointer refPart = this->GetRefPart(refId); if (refPart != 0) { newPart->SetContainer(refPart->GetContainer()); } this->StackPart(newPart, viewId, refId); } void PageLayout::StackView(const std::string& viewId, const std::string& refId) { if (this->CheckPartInLayout(viewId)) { return; } // Create the new part. try { - StackablePart::Pointer newPart = this->CreateView(viewId); + LayoutPart::Pointer newPart = this->CreateView(viewId); if (newPart == 0) { this->StackPlaceholder(viewId, refId); LayoutHelper::AddViewActivator(PageLayout::Pointer(this), viewId); } else { this->StackPart(newPart, viewId, refId); } } catch (PartInitException& e) { WorkbenchPlugin::Log(this->GetClassName(), "StackView", e); //$NON-NLS-1$ } } int PageLayout::ConstantToLayoutPosition(int constant) { if (constant == Constants::TOP) return IPageLayout::TOP; if (constant == Constants::BOTTOM) return IPageLayout::BOTTOM; if (constant == Constants::RIGHT) return IPageLayout::RIGHT; if (constant == Constants::LEFT) return IPageLayout::LEFT; return -1; } void PageLayout::AddStandaloneView(const std::string& viewId, bool showTitle, int relationship, float ratio, const std::string& refId) { this->AddView(viewId, relationship, ratio, refId, false, true, showTitle); ViewLayoutRec::Pointer rec = this->GetViewLayoutRec(viewId, true); rec->isStandalone = true; rec->showTitle = showTitle; } void PageLayout::AddStandaloneViewPlaceholder(const std::string& viewId, int relationship, float ratio, const std::string& refId, bool showTitle) { std::string stackId = viewId + ".standalonefolder"; //$NON-NLS-1$ // Check to see if the view is already in the layout if (!this->CheckValidPlaceholderId(viewId)) { return; } // Create the folder. ContainerPlaceholder::Pointer folder(new ContainerPlaceholder("")); folder->SetContainer(rootLayoutContainer); int appearance = PresentationFactoryUtil::ROLE_STANDALONE; if (!showTitle) { appearance = PresentationFactoryUtil::ROLE_STANDALONE_NOTITLE; } - folder->SetRealContainer(IStackableContainer::Pointer(new PartStack(rootLayoutContainer->page, true, + folder->SetRealContainer(ILayoutContainer::Pointer(new PartStack(rootLayoutContainer->page, true, appearance, 0))); folder->SetID(stackId); - this->AddStack(folder, stackId, relationship, ratio, refId); + this->AddPart(folder, stackId, relationship, ratio, refId); // Create a wrapper. PlaceholderFolderLayout::Pointer placeHolder(new PlaceholderFolderLayout(PageLayout::Pointer(this), folder)); // Add the standalone view immediately placeHolder->AddPlaceholder(viewId); ViewLayoutRec::Pointer rec = this->GetViewLayoutRec(viewId, true); rec->isStandalone = true; rec->showTitle = showTitle; } IViewLayout::Pointer PageLayout::GetViewLayout(const std::string& viewId) { ViewLayoutRec::Pointer rec = this->GetViewLayoutRec(viewId, true); if (rec == 0) { return IViewLayout::Pointer(0); } return IViewLayout::Pointer(new ViewLayout(PageLayout::Pointer(this), rec)); } std::map PageLayout::GetIDtoViewLayoutRecMap() { return mapIDtoViewLayoutRec; } void PageLayout::RemovePlaceholder(const std::string& id) { - StackablePart::Pointer part = this->GetRefPart(id); + LayoutPart::Pointer part = this->GetRefPart(id); if (part->IsPlaceHolder()) { - IStackableContainer::Pointer stack = this->GetFolderPart(id); + ILayoutContainer::Pointer stack = this->GetFolderPart(id); if (stack != 0) { stack->Remove(part); } else { //rootLayoutContainer->Remove(part); WorkbenchPlugin::Log("Not removing placeholder: Folder for placeholder " + id + " not found"); } mapIDtoPart.erase(id); mapIDtoFolder.erase(id); mapIDtoViewLayoutRec.erase(id); } } IPlaceholderFolderLayout::Pointer PageLayout::GetFolderForView( const std::string& viewId) { if (mapIDtoFolder[viewId] == 0) return IPlaceholderFolderLayout::Pointer(0); - IStackableContainer::Pointer folder = mapIDtoFolder[viewId]; + ILayoutContainer::Pointer folder = mapIDtoFolder[viewId]; IPlaceholderFolderLayout::Pointer layout; if (mapFolderToFolderLayout[folder] == 0) { layout = new FolderLayout(PageLayout::Pointer(this), folder.Cast(), viewFactory); mapFolderToFolderLayout[folder] = layout; } else { layout = mapFolderToFolderLayout[folder]; } return layout; } } diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPageLayout.h b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPageLayout.h index 8a62c39cec..75a2004c33 100644 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPageLayout.h +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPageLayout.h @@ -1,586 +1,586 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef BERRYPAGELAYOUT_H_ #define BERRYPAGELAYOUT_H_ #include "berryIPageLayout.h" #include "berryViewLayoutRec.h" #include "berryContainerPlaceholder.h" #include "berryViewSashContainer.h" #include "berryPartStack.h" namespace berry { /** * \ingroup org_blueberry_ui_internal * * This factory is used to define the initial layout of a part sash container. *

* Design notes: The design of IPageLayout is a reflection of * three requirements: *

    *
  1. A mechanism is required to define the initial layout for a page.
  2. *
  3. The views and editors within a page will be persisted between * sessions.
  4. *
  5. The view and editor lifecycle for (1) and (2) should be identical.
  6. *
*

*

* In reflection of these requirements, the following strategy has been * implemented for layout definition. *

    *
  1. A view extension is added to the workbench registry for the view. * This extension defines the extension id and extension class.
  2. *
  3. A view is added to a page by invoking one of the add methods * in IPageLayout. The type of view is passed as an * extension id, rather than a handle. The page layout will map * the extension id to a view class, create an instance of the class, * and then add the view to the page.
  4. *
*

*/ class PageLayout : public IPageLayout { public: berryObjectMacro(PageLayout); private: //ArrayList actionSets = new ArrayList(3); IPerspectiveDescriptor::Pointer descriptor; LayoutPart::Pointer editorFolder; bool editorVisible; bool fixed; - typedef std::map IDToFolderMap; + typedef std::map IDToFolderMap; IDToFolderMap mapIDtoFolder; - typedef std::map IDToPartMap; + typedef std::map IDToPartMap; IDToPartMap mapIDtoPart; typedef std::map IDToViewLayoutRecMap; IDToViewLayoutRecMap mapIDtoViewLayoutRec; - typedef std::map FolderToFolderLayoutMap; + typedef std::map FolderToFolderLayoutMap; FolderToFolderLayoutMap mapFolderToFolderLayout; std::vector perspectiveShortcuts; ViewSashContainer::Pointer rootLayoutContainer; std::vector showInPartIds; std::vector showViewShortcuts; ViewFactory* viewFactory; /** * Constructs a new PageLayout for other purposes. */ public: PageLayout(); /** * Constructs a new PageLayout for the normal case of creating a new * perspective. */ public: PageLayout(ViewSashContainer::Pointer container, ViewFactory* viewFactory, LayoutPart::Pointer editorFolder, IPerspectiveDescriptor::Pointer descriptor); /** * Adds the editor to a layout. */ private: void AddEditorArea(); /** * Adds an action set to the page. * * @param actionSetID Identifies the action set extension to use. It must * exist within the workbench registry. */ // public: void addActionSet(String actionSetID) { // if (!actionSets.contains(actionSetID)) { // actionSets.add(actionSetID); // } // } /* (non-Javadoc) * @see org.blueberry.ui.IPageLayout#addFastView(java.lang.String) */ // public: void addFastView(String id) { // addFastView(id, INVALID_RATIO); // } /* (non-Javadoc) * @see org.blueberry.ui.IPageLayout#addFastView(java.lang.String, float) */ // public: void addFastView(String id, float ratio) { // if (checkPartInLayout(id)) { // return; // } // if (id != null) { // try { // IViewDescriptor viewDescriptor = viewFactory.getViewRegistry() // .find(ViewFactory.extractPrimaryId(id)); // if (!WorkbenchActivityHelper.filterItem(viewDescriptor)) { // IViewReference ref = viewFactory.createView(ViewFactory // .extractPrimaryId(id), ViewFactory // .extractSecondaryId(id)); // fastViews.add(ref); // // // force creation of the view layout rec // ViewLayoutRec rec = getViewLayoutRec(id, true); // // // remember the ratio, if valid // if (ratio >= IPageLayout.RATIO_MIN // && ratio <= IPageLayout.RATIO_MAX) { // rec.fastViewWidthRatio = ratio; // } // } // } catch (PartInitException e) { // WorkbenchPlugin.log(getClass(), "addFastView", e); //$NON-NLS-1$ // } // } // } /** * Check to see if the partId represents a fast view's id. * * @param partId * The part's id. * @return true if the partId is a fast view id. */ // private: boolean isFastViewId(String partId) { // for (int i = 0; i < fastViews.size(); i++) { // IViewReference ref = (IViewReference) fastViews.get(i); // String secondaryId = ref.getSecondaryId(); // String refId = (secondaryId == null ? ref.getId() : ref.getId() // + ":" + secondaryId); //$NON-NLS-1$ // if (refId.equals(partId)) { // return true; // } // } // return false; // } /** * Returns the view layout record for the given view id, or null if not * found. If create is true, the record is created if it doesn't already * exist. * * @since 3.0 */ public: ViewLayoutRec::Pointer GetViewLayoutRec(const std::string& id, bool create); /** * Adds a creation wizard to the File New menu. * The id must name a new wizard extension contributed to the * workbench's extension point (named "org.blueberry.ui.newWizards"). * * @param id the wizard id */ // public: void addNewWizardShortcut(String id) { // if (!newWizardShortcuts.contains(id)) { // newWizardShortcuts.add(id); // } // } /** * Add the layout part to the page's layout */ private: - void AddStack(IStackableContainer::Pointer newPart, const std::string& partId, - int relationship, float ratio, const std::string& refId); + void AddPart(LayoutPart::Pointer newPart, const std::string& partId, + int relationship, float ratio, const std::string& refId); /** * Adds a perspective shortcut to the Perspective menu. * The id must name a perspective extension contributed to the * workbench's extension point (named "org.blueberry.ui.perspectives"). * * @param id the perspective id */ public: void AddPerspectiveShortcut(const std::string& id); /* (non-Javadoc) * @see org.blueberry.ui.IPageLayout#addPlaceholder(java.lang.String, int, float, java.lang.String) */ public: void AddPlaceholder(const std::string& viewId, int relationship, float ratio, const std::string& refId); /** * Checks whether the given id is a valid placeholder id. * A placeholder id may be simple or compound, and can optionally contain a wildcard. * * @param id the placeholder id * @return true if the given id is a valid placeholder id, false otherwise */ bool CheckValidPlaceholderId(const std::string& id); /* (non-Javadoc) * @see org.blueberry.ui.IPageLayout#addShowInPart(java.lang.String) */ public: void AddShowInPart(const std::string& id); /** * Adds a view to the Show View menu. The id must name a view extension * contributed to the workbench's extension point (named "org.blueberry.ui.views"). * * @param id the view id */ public: void AddShowViewShortcut(const std::string& id); /* (non-Javadoc) * @see org.blueberry.ui.IPageLayout#addView(java.lang.String, int, float, java.lang.String) */ public: void AddView(const std::string& viewId, int relationship, float ratio, const std::string& refId); /** * Convenience method to allow setting the initial minimized * state if a new stack is created. Used by the 'perspectiveExtension' * reader. * * @since 3.3 */ public: void AddView(const std::string& viewId, int relationship, float ratio, const std::string& refId, bool minimized); /* (non-Javadoc) * @see org.blueberry.ui.IPageLayout#addView(java.lang.String, int, float, java.lang.String) */ private: void AddView(const std::string& viewId, int relationship, float ratio, const std::string& refId, bool minimized, bool standalone, bool showTitle); // public: List getMinimizedStacks() { // return minimizedStacks; // } /** * Verify that the part is already present in the layout * and cannot be added again. Log a warning message. */ public: bool CheckPartInLayout(const std::string& partId); /* (non-Javadoc) * @see org.blueberry.ui.IPageLayout#createFolder(java.lang.String, int, float, java.lang.String) */ public: IFolderLayout::Pointer CreateFolder(const std::string& folderId, int relationship, float ratio, const std::string& refId); /* (non-Javadoc) * @see org.blueberry.ui.IPageLayout#createPlaceholderFolder(java.lang.String, int, float, java.lang.String) */ public: IPlaceholderFolderLayout::Pointer CreatePlaceholderFolder( const std::string& folderId, int relationship, float ratio, const std::string& refId); /** * Create a new LayoutPart. * * @param partID the id of the part to create. * @return the LayoutPart, or null if it should not be * created because of activity filtering. * @throws PartInitException thrown if there is a problem creating the part. */ private: - StackablePart::Pointer CreateView(const std::string& partID); + LayoutPart::Pointer CreateView(const std::string& partID); /** * @return the action set list for the page. This is List of * Strings. */ // public: ArrayList getActionSets() { // return actionSets; // } /* (non-Javadoc) * @see org.blueberry.ui.IPageLayout#getDescriptor() */ public: IPerspectiveDescriptor::Pointer GetDescriptor(); /** * @return an identifier for the editor area. The editor area is * automatically added to each layout before any other part. It should be * used as a reference part for other views. */ public: std::string GetEditorArea(); /* (non-Javadoc) * @see org.blueberry.ui.IPageLayout#getEditorReuseThreshold() */ // public: int getEditorReuseThreshold() { // return -1; // } /** * @return ArrayList */ // public: ArrayList getFastViews() { // return fastViews; // } /** * @return the folder part containing the given view ID or null * if none (i.e. part of the page layout instead of a folder layout). */ private: - IStackableContainer::Pointer GetFolderPart(const std::string& viewId); + PartStack::Pointer GetFolderPart(const std::string& viewId); /** * @return the new wizard shortcuts associated with the page. This is a List of * Strings. */ // public: ArrayList getNewWizardShortcuts() { // return newWizardShortcuts; // } /** * @return the part sash container const for a layout value. */ private: int GetPartSashConst(int nRelationship); /** * @return the perspective shortcuts associated with the page. This is a List of * Strings. */ public: std::vector GetPerspectiveShortcuts(); /** * @return the part for a given ID. */ /*package*/ - StackablePart::Pointer GetRefPart(const std::string& partID); + LayoutPart::Pointer GetRefPart(const std::string& partID); /** * @return the top level layout container. */ public: PartSashContainer::Pointer GetRootLayoutContainer(); /** * @return the ids of the parts to list in the Show In... prompter. This is * a List of Strings. */ public: std::vector GetShowInPartIds(); /** * @return the show view shortcuts associated with the page. This is a List of * Strings. */ public: std::vector GetShowViewShortcuts(); /** * @return the ViewFactory for this PageLayout. * @since 3.0 */ /* package */ ViewFactory* GetViewFactory(); /* (non-Javadoc) * @see org.blueberry.ui.IPageLayout#isEditorAreaVisible() */ public: bool IsEditorAreaVisible(); /** * Trim the ratio so that direct manipulation of parts is easy. * * @param in the initial ratio. * @return the normalized ratio. */ private: float NormalizeRatio(float in); /** * Prefill the layout with required parts. */ private: void Prefill(); /* (non-Javadoc) * @see org.blueberry.ui.IPageLayout#setEditorAreaVisible(boolean) */ public: void SetEditorAreaVisible(bool showEditorArea); /* (non-Javadoc) * @see org.blueberry.ui.IPageLayout#setEditorReuseThreshold(int) */ // public: void setEditorReuseThreshold(int openEditors) { // //no-op // } /* (non-Javadoc) * @see org.blueberry.ui.IPageLayout#setFixed(boolean) */ public: void SetFixed(bool fixed); /* (non-Javadoc) * @see org.blueberry.ui.IPageLayout#getFixed() */ public: bool IsFixed(); /** * Map the folder part containing the given view ID. * * @param viewId the part ID. * @param container the ContainerPlaceholder. */ /*package*/ void SetFolderPart(const std::string& viewId, - ContainerPlaceholder::Pointer container); + ContainerPlaceholder::Pointer container); /** * Map the folder part containing the given view ID. * * @param viewId the part ID. * @param folder the ViewStack. */ /*package*/ void SetFolderPart(const std::string& viewId, PartStack::Pointer folder); - void SetFolderPart(const std::string& viewId, IStackableContainer::Pointer folder); + void SetFolderPart(const std::string& viewId, ILayoutContainer::Pointer folder); /** * Map an ID to a part. * * @param partId the part ID. * @param part the LayoutPart. */ /*package*/ - void SetRefPart(const std::string& partID, StackablePart::Pointer part); + void SetRefPart(const std::string& partID, LayoutPart::Pointer part); /** * Stack a part on top of another. * * @param newPart the new part. * @param viewId the view ID. * @param refId the reference ID. */ private: - void StackPart(StackablePart::Pointer newPart, const std::string& viewId, + void StackPart(LayoutPart::Pointer newPart, const std::string& viewId, const std::string& refId); /** * Stack a placeholder on top of another. * * @param viewId the view ID. * @param refId the reference ID. */ public: void StackPlaceholder(const std::string& viewId, const std::string& refId); // stackView(String, String) modified by dan_rubel@instantiations.com /** * Stack one view on top of another. * * @param viewId the view ID. * @param refId the reference ID. */ public: void StackView(const std::string& viewId, const std::string& refId); /** * Converts common position constants into layout position constants. * * @param one of Constants::TOP, Constants::BOTTOM, Constants::LEFT, or Constants::RIGHT * @return one of IPageLayout::TOP, IPageLayout::BOTTOM, IPageLayout::LEFT, IPageLayout::RIGHT, or -1 indicating an * invalid input * * @since 3.0 */ public: static int ConstantToLayoutPosition(int constant); /* (non-Javadoc) * @see org.blueberry.ui.IPageLayout#addStandaloneView(java.lang.String, boolean, int, float, java.lang.String) * @since 3.0 */ public: void AddStandaloneView(const std::string& viewId, bool showTitle, int relationship, float ratio, const std::string& refId); /* (non-Javadoc) * @see org.blueberry.ui.IPageLayout#addStandaloneViewPlaceholder(java.lang.String, int, float, java.lang.String, boolean) */ public: void AddStandaloneViewPlaceholder(const std::string& viewId, int relationship, float ratio, const std::string& refId, bool showTitle); /* * (non-Javadoc) * * @see org.blueberry.ui.IPageLayout#getViewLayout(java.lang.String) * @since 3.0 */ public: IViewLayout::Pointer GetViewLayout(const std::string& viewId); /** * @since 3.0 */ public: std::map GetIDtoViewLayoutRecMap(); /** * Removes any existing placeholder with the given id. * * @param id the id for the placeholder * @since 3.1 */ public: void RemovePlaceholder(const std::string& id); /* (non-Javadoc) * @see org.blueberry.ui.IPageLayout#getFolderForView(java.lang.String) */ public: IPlaceholderFolderLayout::Pointer GetFolderForView(const std::string& viewId); }; } #endif /*BERRYPAGELAYOUT_H_*/ diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartList.cpp b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartList.cpp index 65a7419a8f..569f70f7ca 100644 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartList.cpp +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartList.cpp @@ -1,367 +1,367 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "berryPartList.h" #include "berrySaveablesList.h" #include "berryPartPane.h" #include "berryIWorkbenchPartConstants.h" #include "berryIWorkbenchPartSite.h" #include namespace berry { void PartList::PropertyChange(Object::Pointer source, int propId) { WorkbenchPartReference::Pointer ref = source.Cast< WorkbenchPartReference> (); if (propId == IWorkbenchPartConstants::PROP_OPENED) { this->PartOpened(ref); } else if (propId == IWorkbenchPartConstants::PROP_CLOSED) { this->PartClosed(ref); } else if (propId == IWorkbenchPartConstants::PROP_VISIBLE) { if (ref->GetVisible()) { this->PartVisible(ref); } else { this->PartHidden(ref); } } else if (propId == IWorkbenchPartConstants::PROP_INPUT) { this->PartInputChanged(ref); } } IWorkbenchPartReference::Pointer PartList::GetActivePartReference() { return activePartReference.Lock(); } IEditorReference::Pointer PartList::GetActiveEditorReference() { return activeEditorReference.Lock(); } IEditorPart::Pointer PartList::GetActiveEditor() { return activeEditorReference.Expired() ? IEditorPart::Pointer(0) : activeEditorReference.Lock()->GetEditor( false); } IWorkbenchPart::Pointer PartList::GetActivePart() { return activePartReference.Expired() ? IWorkbenchPart::Pointer(0) : activePartReference.Lock()->GetPart(false); } //std::vector PartList::GetEditors() //{ // std::vector result; // for (std::deque::iterator iter = // parts.begin(); iter != parts.end(); ++iter) // { // if (iter->Cast () != 0) // result.push_back(iter->Cast ()); // } // // return result; //} void PartList::AddPart(WorkbenchPartReference::Pointer ref) { poco_assert(ref.IsNotNull()); ref->AddPropertyListener(IPropertyChangeListener::Pointer(this)); // if (!this->Contains(ref)) // { // parts.push_back(ref); // } // parts.add(ref); this->FirePartAdded(ref); // If this part is already open, fire the "part opened" event // immediately if (ref->GetPart(false).IsNotNull()) { this->PartOpened(ref); } // If this part is already visible, fire the visibility event // immediately if (ref->GetVisible()) { this->PartVisible(ref); } } void PartList::SetActivePart(IWorkbenchPartReference::Pointer ref) { if (activePartReference.Lock() == ref) { return; } IWorkbenchPartReference::Pointer oldPart = activePartReference.Lock(); // A part can't be activated until it is added //poco_assert(ref == 0 || this->Contains(ref)); //std::remove(parts.begin(), parts.end(), ref); //parts.push_front(ref); activePartReference = ref; this->FireActivePartChanged(oldPart, ref); } void PartList::SetActiveEditor(IEditorReference::Pointer ref) { if (activeEditorReference.Lock() == ref) { return; } // A part can't be activated until it is added //poco_assert(ref == 0 || this->Contains(ref)); activeEditorReference = ref; //std::remove(parts.begin(), parts.end(), ref); //parts.push_front(ref); this->FireActiveEditorChanged(ref); } void PartList::RemovePart(WorkbenchPartReference::Pointer ref) { poco_assert(ref.IsNotNull()); // It is an error to remove a part that isn't in the list //poco_assert(this->Contains(ref)); // We're not allowed to remove the active part. We must deactivate it // first. poco_assert(activePartReference.Lock() != ref); // We're not allowed to remove the active editor. We must deactivate it // first. if (ref.Cast()) { poco_assert(activeEditorReference.Lock() != ref.Cast()); } if (ref->GetVisible()) { ref->SetVisible(false); } // If this part is currently open, fire the "part closed" event before // removal if (ref->GetPart(false).IsNotNull()) { this->PartClosed(ref); } //std::remove(parts.begin(), parts.end(), ref); ref->RemovePropertyListener(IPropertyChangeListener::Pointer(this)); this->FirePartRemoved(ref); } //int PartList::IndexOf(const IWorkbenchPartReference::Pointer ref) const //{ // std::deque::const_iterator result = std::find(parts.begin(), parts.end(), ref); // if (result == parts.end()) return -1; // else return result - parts.begin(); //} //void PartList::BringToTop(IWorkbenchPartReference::Pointer ref) //{ -// IStackableContainer::Pointer targetContainer; +// ILayoutContainer::Pointer targetContainer; // if (ref != 0) // { // PartPane::Pointer pane = ref.Cast()->GetPane(); // if (pane != 0) // { // targetContainer = pane->GetContainer(); // } // } // // std::deque::iterator newIndex = this->LastIndexOfContainer(targetContainer); // // // //New index can be -1 if there is no last index // // if (newIndex >= 0 && ref == parts.get(newIndex)) // // return; // // std::remove(parts.begin(), parts.end(), ref); // if(newIndex != parts.end()) // { // parts.insert(newIndex, ref); // } // else // parts.push_front(ref); //} //std::vector //PartList::GetParts(const std::vector& views) //{ // std::vector resultList; // for (std::deque::iterator partIter = parts.begin(); // partIter != parts.end(); ++partIter) // { // IWorkbenchPartReference::Pointer ref = *partIter; // if (ref.Cast() != 0) // { // //Filter views from other perspectives // for (unsigned int i = 0; i < views.size(); i++) // { // if (ref == views[i]) // { // resultList.push_back(ref); // break; // } // } // } // else // { // resultList.push_back(ref); // } // } // return resultList; //} //std::deque::iterator -//PartList::LastIndexOfContainer(IStackableContainer::Pointer container) +//PartList::LastIndexOfContainer(ILayoutContainer::Pointer container) //{ // for (std::deque::iterator iter = parts.begin(); // iter != parts.end(); ++iter) // { // IWorkbenchPartReference::Pointer ref = *iter; // -// IStackableContainer::Pointer cnt; +// ILayoutContainer::Pointer cnt; // PartPane::Pointer pane = ref.Cast()->GetPane(); // if (pane != 0) // { // cnt = pane->GetContainer(); // } // if (cnt == container) // { // return iter; // } // } // // return parts.end(); //} //bool PartList::Contains(IWorkbenchPartReference::Pointer ref) //{ // return std::find(parts.begin(), parts.end(), ref) != parts.end(); //} void PartList::PartInputChanged(WorkbenchPartReference::Pointer ref) { this->FirePartInputChanged(ref); } void PartList::PartHidden(WorkbenchPartReference::Pointer ref) { // Part should not be null poco_assert(ref.IsNotNull()); // This event should only be fired if the part is actually visible poco_assert(!ref->GetVisible()); // We shouldn't be receiving events from parts until they are in the // list //poco_assert(this->Contains(ref)); this->FirePartHidden(ref); } void PartList::PartOpened(WorkbenchPartReference::Pointer ref) { poco_assert(ref.IsNotNull()); IWorkbenchPart::Pointer actualPart = ref->GetPart(false); // We're firing the event that says "the part was just created"... so // there better be a part there. poco_assert(actualPart.IsNotNull()); // Must be called after the part is inserted into the part list //poco_assert(this->Contains(ref)); // The active part must be opened before it is activated, so we should // never get an open event for a part that is already active. // (This either indicates that a redundant // open event was fired or that a closed part was somehow activated) poco_assert(activePartReference.Lock() != ref); // The active editor must be opened before it is activated, so we should // never get an open event for an editor that is already active. // (This either indicates that a redundant // open event was fired or that a closed editor was somehow activated) poco_assert((void*)activeEditorReference.Lock().GetPointer() != (void*)ref.GetPointer()); SaveablesList::Pointer modelManager = actualPart ->GetSite()->GetService(ISaveablesLifecycleListener::GetManifestName()).Cast(); modelManager->PostOpen(actualPart); // Fire the "part opened" event this->FirePartOpened(ref); } void PartList::PartClosed(WorkbenchPartReference::Pointer ref) { poco_assert(ref.IsNotNull()); IWorkbenchPart::Pointer actualPart = ref->GetPart(false); // Called before the part is disposed, so the part should still be // there. poco_assert(actualPart.IsNotNull()); // Must be called before the part is actually removed from the part list // poco_assert(this->Contains(ref)); // Not allowed to close the active part. The part must be deactivated // before it may be closed. poco_assert(activePartReference.Lock() != ref); // Not allowed to close the active editor. The editor must be // deactivated before it may be closed. if (ref.Cast()) { poco_assert(activeEditorReference.Lock() != ref.Cast()); } this->FirePartClosed(ref); } void PartList::PartVisible(WorkbenchPartReference::Pointer ref) { // Part should not be null poco_assert(ref.IsNotNull()); // This event should only be fired if the part is actually visible poco_assert(ref->GetVisible()); // We shouldn't be receiving events from parts until they are in the // list //poco_assert(this->Contains(ref)); // Part must be open before it can be made visible poco_assert(ref->GetPart(false).IsNotNull()); this->FirePartVisible(ref); } } diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartList.h b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartList.h index 81dc477dcc..2610cde6dc 100644 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartList.h +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartList.h @@ -1,189 +1,189 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef BERRYPARTLIST_H_ #define BERRYPARTLIST_H_ #include "berryWorkbenchPartReference.h" -#include "berryIStackableContainer.h" +#include "berryILayoutContainer.h" #include "berryIEditorReference.h" #include "berryIViewReference.h" #include namespace berry { class PartList : public IPropertyChangeListener { private: // list of parts in the activation order (oldest last) //std::deque parts; IWorkbenchPartReference::WeakPtr activePartReference; IEditorReference::WeakPtr activeEditorReference; public: void PropertyChange(Object::Pointer source, int propId); IWorkbenchPartReference::Pointer GetActivePartReference(); IEditorReference::Pointer GetActiveEditorReference(); IEditorPart::Pointer GetActiveEditor(); IWorkbenchPart::Pointer GetActivePart(); //std::vector GetEditors(); void AddPart(WorkbenchPartReference::Pointer ref); /** * Sets the active part. * * @param ref */ void SetActivePart(IWorkbenchPartReference::Pointer ref); void SetActiveEditor(IEditorReference::Pointer ref); /** * In order to remove a part, it must first be deactivated. */ void RemovePart(WorkbenchPartReference::Pointer ref); //int IndexOf(const IWorkbenchPartReference::Pointer ref) const; /* * Ensures that the given part appears AFTER any other part in the same * container. */ //void BringToTop(IWorkbenchPartReference::Pointer ref); /* * Return a list with all parts (editors and views). */ //std::vector GetParts(const std::vector& views); private: /* * Returns the last (most recent) index of the given container in the activation list, or returns * -1 if the given container does not appear in the activation list. */ //std::deque::iterator - // LastIndexOfContainer(IStackableContainer::Pointer container); + // LastIndexOfContainer(ILayoutContainer::Pointer container); void PartInputChanged(WorkbenchPartReference::Pointer ref); void PartHidden(WorkbenchPartReference::Pointer ref); void PartOpened(WorkbenchPartReference::Pointer ref); /** * Called when a concrete part is about to be destroyed. This is called * BEFORE disposal happens, so the part should still be accessable from the * part reference. * * @param ref */ void PartClosed(WorkbenchPartReference::Pointer ref); void PartVisible(WorkbenchPartReference::Pointer ref); //bool Contains(IWorkbenchPartReference::Pointer ref); protected: /** * Fire the event indicating that a part reference was just realized. That * is, the concrete IWorkbenchPart has been attached to the part reference. * * @param part * the reference that was create */ virtual void FirePartOpened(IWorkbenchPartReference::Pointer part) = 0; /** * Fire the event indicating that a part reference was just realized. That * is, the concrete IWorkbenchPart has been attached to the part reference. * * @param part * the reference that was create */ virtual void FirePartClosed(IWorkbenchPartReference::Pointer part) = 0; /** * Indicates that a new part reference was added to the list. * * @param part */ virtual void FirePartAdded(IWorkbenchPartReference::Pointer part) = 0; /** * Indicates that a part reference was removed from the list * * @param part */ virtual void FirePartRemoved(IWorkbenchPartReference::Pointer part) = 0; /** * Indicates that the active editor changed * * @param part * active part reference or null if none */ virtual void FireActiveEditorChanged(IWorkbenchPartReference::Pointer ref) = 0; /** * Indicates that the active part has changed * * @param part * active part reference or null if none */ virtual void FireActivePartChanged( IWorkbenchPartReference::Pointer oldPart, IWorkbenchPartReference::Pointer newPart) = 0; /** * Indicates that the part has been made visible * * @param ref */ virtual void FirePartVisible(IWorkbenchPartReference::Pointer ref) = 0; /** * Indicates that the part has been hidden * * @param ref */ virtual void FirePartHidden(IWorkbenchPartReference::Pointer ref) = 0; /** * Indicates that the part input has changed * * @param ref */ virtual void FirePartInputChanged(IWorkbenchPartReference::Pointer ref) = 0; virtual void FirePartBroughtToTop(IWorkbenchPartReference::Pointer ref) = 0; }; } #endif /*BERRYPARTLIST_H_*/ diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartPane.cpp b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartPane.cpp index cea52b7fba..53e0d48699 100644 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartPane.cpp +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartPane.cpp @@ -1,466 +1,461 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "berryPartPane.h" #include "tweaklets/berryGuiWidgetsTweaklet.h" #include "tweaklets/berryWorkbenchPageTweaklet.h" #include "berryWorkbenchPage.h" #include "berryPartStack.h" #include "berryEditorAreaHelper.h" #include "berryPerspective.h" #include "berryPartStack.h" #include "berryDragUtil.h" namespace berry { PartPane::Sashes::Sashes() : left(0), right(0), top(0), bottom(0) { } PartPane::PartPane(IWorkbenchPartReference::Pointer partReference, WorkbenchPage* workbenchPage) - : StackablePart(partReference->GetId()), + : LayoutPart(partReference->GetId()), control(0), inLayout(true), busy(false), hasFocus(false) { //super(partReference.getId()); this->partReference = partReference; this->page = workbenchPage; } void PartPane::CreateControl(void* parent) { if (this->GetControl() != 0) { return; } partReference.Lock()->AddPropertyListener(IPropertyChangeListener::Pointer(this)); // Create view form. control = Tweaklets::Get(WorkbenchPageTweaklet::KEY)->CreatePaneControl(parent); // the part should never be visible by default. It will be made visible // by activation. This allows us to have views appear in tabs without // becoming active by default. Tweaklets::Get(GuiWidgetsTweaklet::KEY)->SetVisible(control, false); Tweaklets::Get(GuiWidgetsTweaklet::KEY)->MoveAbove(control, 0); // Create a title bar. //this->CreateTitleBar(); // When the pane or any child gains focus, notify the workbench. Tweaklets::Get(GuiWidgetsTweaklet::KEY)->AddControlListener(control, GuiTk::IControlListener::Pointer(this)); //control.addTraverseListener(traverseListener); } -bool PartPane::IsPlaceHolder() -{ - return false; -} - PartPane::~PartPane() { // super.dispose(); // this->Register(); if (control != 0) { BERRY_DEBUG << "Deleting PartPane control"; Tweaklets::Get(GuiWidgetsTweaklet::KEY)->RemoveControlListener(control, GuiTk::IControlListener::Pointer(this)); // control.removeTraverseListener(traverseListener); Tweaklets::Get(GuiWidgetsTweaklet::KEY)->Dispose(control); control = 0; } // if ((paneMenuManager != null)) // { // paneMenuManager.dispose(); // paneMenuManager = null; // } // if (!partReference.Expired()) { partReference.Lock()->RemovePropertyListener(IPropertyChangeListener::Pointer(this)); } // partReference.removePartPropertyListener(this); this->UnRegister(false); } void PartPane::DoHide() { if (partReference.Lock().Cast() != 0) { this->GetPage()->HideView(partReference.Lock().Cast()); } else if (partReference.Lock().Cast() != 0) { this->GetPage()->CloseEditor(partReference.Lock().Cast(), true); } } Rectangle PartPane::GetParentBounds() { void* ctrl = this->GetControl(); if (this->GetContainer() != 0 && this->GetContainer().Cast() != 0) { LayoutPart::Pointer part = this->GetContainer().Cast(); if (part->GetControl() != 0) { ctrl = part->GetControl(); } } return DragUtil::GetDisplayBounds(ctrl); } void* PartPane::GetControl() { return control; } IWorkbenchPartReference::Pointer PartPane::GetPartReference() const { return partReference.Lock(); } void PartPane::ControlActivated(GuiTk::ControlEvent::Pointer /*e*/) { if (inLayout) { this->RequestActivation(); } } GuiTk::IControlListener::Events::Types PartPane::GetEventTypes() const { return GuiTk::IControlListener::Events::ACTIVATED; } void PartPane::MoveAbove(void* refControl) { if (this->GetControl() != 0) { Tweaklets::Get(GuiWidgetsTweaklet::KEY)->MoveAbove(this->GetControl(), refControl); } } void PartPane::RequestActivation() { IWorkbenchPart::Pointer part = partReference.Lock()->GetPart(true); this->page->RequestActivation(part); } //PartStack::Pointer PartPane::GetStack() //{ // return partStack; //} PartPane::Sashes PartPane::FindSashes() { Sashes result; - IStackableContainer::Pointer container = this->GetContainer(); + ILayoutContainer::Pointer container = this->GetContainer(); if (container == 0) { return result; } - container->FindSashes(result); + container->FindSashes(LayoutPart::Pointer(this), result); return result; } WorkbenchPage::Pointer PartPane::GetPage() { return WorkbenchPage::Pointer(page); } -void PartPane::SetContainer(IStackableContainer::Pointer container) +void PartPane::SetContainer(ILayoutContainer::Pointer container) { if (hasFocus) { - IStackableContainer::Pointer oldContainer = this->GetContainer(); + ILayoutContainer::Pointer oldContainer = this->GetContainer(); if (PartStack::Pointer oldStack = oldContainer.Cast()) { oldStack->SetActive(StackPresentation::AS_INACTIVE); } if (PartStack::Pointer newContainer = container.Cast()) { newContainer->SetActive(StackPresentation::AS_ACTIVE_FOCUS); } } void* containerControl = container == 0 ? 0 : container.Cast()->GetControl(); if (containerControl != 0) { void* control = this->GetControl(); void* newParent = Tweaklets::Get(GuiWidgetsTweaklet::KEY)->GetParent(containerControl); if (control != 0 && newParent != Tweaklets::Get(GuiWidgetsTweaklet::KEY)->GetParent(control)) { this->Reparent(newParent); } } - StackablePart::SetContainer(container); + LayoutPart::SetContainer(container); } void PartPane::Reparent(void* newParent) { void* control = this->GetControl(); GuiWidgetsTweaklet* guiTweaklet = Tweaklets::Get(GuiWidgetsTweaklet::KEY); if ((control == 0) || (guiTweaklet->GetParent(control) == newParent)) { return; } if (guiTweaklet->IsReparentable(control)) { // make control small in case it is not resized with other controls //control.setBounds(0, 0, 0, 0); // By setting the control to disabled before moving it, // we ensure that the focus goes away from the control and its children // and moves somewhere else bool enabled = guiTweaklet->GetEnabled(control); guiTweaklet->SetEnabled(control, false); guiTweaklet->SetParent(control, newParent); guiTweaklet->SetEnabled(control, enabled); guiTweaklet->MoveAbove(control, 0); } } void PartPane::ShowFocus(bool inFocus) { if (partReference.Lock().Cast() != 0) { hasFocus = inFocus; } if (PartStack::Pointer stack = this->GetContainer().Cast()) { if (partReference.Lock().Cast() != 0) { stack->SetActive(inFocus ? StackPresentation::AS_ACTIVE_FOCUS : StackPresentation::AS_INACTIVE); } else if (partReference.Lock().Cast() != 0) { if (inFocus) { page->GetEditorPresentation()->SetActiveWorkbook(stack, true); } else { stack->SetActive(page->GetEditorPresentation()->GetActiveWorkbook() == stack ? StackPresentation::AS_ACTIVE_NOFOCUS : StackPresentation::AS_INACTIVE); } } } } PartStack::Pointer PartPane::GetStack() { - IStackableContainer::Pointer container = this->GetContainer(); + ILayoutContainer::Pointer container = this->GetContainer(); return container.Cast(); } void PartPane::SetVisible(bool makeVisible) { // Avoid redundant visibility changes if (makeVisible == this->GetVisible()) { return; } if (makeVisible) { partReference.Lock()->GetPart(true); } if (this->GetControl() != 0) Tweaklets::Get(GuiWidgetsTweaklet::KEY)->SetVisible(this->GetControl(), makeVisible); partReference.Lock().Cast()->FireVisibilityChange(); } bool PartPane::GetVisible() { if (this->GetControl() != 0) return Tweaklets::Get(GuiWidgetsTweaklet::KEY)->GetVisible(this->GetControl()); return false; } void PartPane::SetFocus() { this->RequestActivation(); IWorkbenchPart::Pointer part = partReference.Lock()->GetPart(true); if (part.IsNotNull()) { // Control control = getControl(); // if (!SwtUtil.isFocusAncestor(control)) // { // First try to call part.setFocus part->SetFocus(); //} } } void PartPane::SetWorkbenchPage(WorkbenchPage::Pointer workbenchPage) { this->page = workbenchPage.GetPointer(); } void PartPane::DoDock() { // do nothing } void PartPane::SetBusy(bool isBusy) { if (isBusy != busy) { busy = isBusy; //firePropertyChange(IPresentablePart.PROP_BUSY); } } void PartPane::ShowHighlight() { //No nothing by default } void* PartPane::GetToolBar() { return 0; } bool PartPane::HasViewMenu() { return false; } bool PartPane::IsBusy() { return busy; } void PartPane::DescribeLayout(std::string& buf) const { IWorkbenchPartReference::Pointer part = this->GetPartReference(); if (part.IsNotNull()) { buf.append(part->GetPartName()); return; } } bool PartPane::IsCloseable() { if (partReference.Lock().Cast() != 0) { Perspective::Pointer perspective = page->GetActivePerspective(); if (perspective == 0) { // Shouldn't happen -- can't have a ViewStack without a // perspective return true; } return perspective->IsCloseable(partReference.Lock().Cast()); } return true; } void PartPane::SetInLayout(bool inLayout) { this->inLayout = inLayout; } bool PartPane::GetInLayout() { return inLayout; } bool PartPane::AllowsAutoFocus() { if (!inLayout) { return false; } //return super.allowsAutoFocus(); return true; } void PartPane::RemoveContributions() { } void PartPane::AddPropertyListener(IPropertyChangeListener::Pointer listener) { propertyChangeEvents.AddListener(listener); } void PartPane::RemovePropertyListener(IPropertyChangeListener::Pointer listener) { propertyChangeEvents.RemoveListener(listener); } void PartPane::FirePropertyChange(PropertyChangeEvent::Pointer event) { propertyChangeEvents.propertyChange(event); } void PartPane::PropertyChange(PropertyChangeEvent::Pointer event) { this->FirePropertyChange(event); } int PartPane::ComputePreferredSize(bool width, int availableParallel, int availablePerpendicular, int preferredParallel) { return partReference.Lock().Cast()->ComputePreferredSize(width, availableParallel, availablePerpendicular, preferredParallel); } int PartPane::GetSizeFlags(bool horizontal) { return partReference.Lock().Cast()->GetSizeFlags(horizontal); } void PartPane::ShellActivated() { } void PartPane::ShellDeactivated() { } } diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartPane.h b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartPane.h index e0a0c5b30b..67eaf6583e 100644 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartPane.h +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartPane.h @@ -1,436 +1,434 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef BERRYPARTPANE_H_ #define BERRYPARTPANE_H_ #include "berryWorkbenchPartReference.h" -#include "berryStackablePart.h" +#include "berryLayoutPart.h" #include "berryRectangle.h" #include "berryIPropertyChangeListener.h" #include "guitk/berryGuiTkIControlListener.h" namespace berry { class WorkbenchPage; class PartStack; -struct IStackableContainer; +struct ILayoutContainer; /** * Provides the common behavior for both views * and editor panes. * */ -class PartPane : public StackablePart, +class PartPane : public LayoutPart, public IPropertyChangeListener, public GuiTk::IControlListener { public: berryObjectMacro(PartPane); friend class PartSashContainer; friend class EditorSashContainer; friend class WorkbenchPage; - friend struct IStackableContainer; friend struct ILayoutContainer; friend class PartStack; friend class ContainerPlaceholder; friend class LayoutTree; friend class LayoutTreeNode; friend class DetachedPlaceHolder; friend class PerspectiveHelper; // private: MenuManager paneMenuManager; // private: ListenerList listeners = new ListenerList(); // private: ListenerList partListeners = new ListenerList(); private: IPropertyChangeListener::Events propertyChangeEvents; protected: IWorkbenchPartReference::WeakPtr partReference; protected: WorkbenchPage* page; protected: void* control; private: bool inLayout; // private: TraverseListener traverseListener = new TraverseListener() { // /* (non-Javadoc) // * @see org.blueberry.swt.events.TraverseListener#keyTraversed(org.blueberry.swt.events.TraverseEvent) // */ // public: void keyTraversed(TraverseEvent e) { // // Hack: Currently, SWT sets focus whenever we call Control.traverse. This doesn't // // cause too much of a problem for ctrl-pgup and ctrl-pgdn, but it is seriously unexpected // // for other traversal events. When (and if) it becomes possible to call traverse() without // // forcing a focus change, this if statement should be removed and ALL events should be // // forwarded to the container. // if (e.detail == SWT.TRAVERSE_PAGE_NEXT // || e.detail == SWT.TRAVERSE_PAGE_PREVIOUS) { // ILayoutContainer container = getContainer(); // if (container != null && container instanceof LayoutPart) { // LayoutPart parent = (LayoutPart) container; // Control parentControl = parent.getControl(); // if (parentControl != null && !parentControl.isDisposed()) { // e.doit = parentControl.traverse(e.detail); // if (e.doit) { // e.detail = SWT.TRAVERSE_NONE; // } // } // } // } // } // // }; private: bool busy; private: bool hasFocus; //private: SmartPointer partStack; protected: /*static*/ class Sashes { public: Sashes(); /*Sash*/ void* left; /*Sash*/ void* right; /*Sash*/ void* top; /*Sash*/ void* bottom; }; /** * Construct a pane for a part. */ public: PartPane(IWorkbenchPartReference::Pointer partReference, WorkbenchPage* workbenchPage); // public: void addSizeMenuItem(Menu menu, int index) { // //Add size menu // MenuItem item = new MenuItem(menu, SWT.CASCADE, index); // item.setText(WorkbenchMessages.PartPane_size); // Menu sizeMenu = new Menu(menu); // item.setMenu(sizeMenu); // addSizeItems(sizeMenu); // } /** * * Creates the GUI-dependent container control * for the part widgets. This is passed to * IWorkbenchPart::CreatePartControl(void*) */ public: virtual void CreateControl(void* parent); //public: virtual void SetControlEnabled(bool enabled) = 0; /** * Create a title bar for the pane if required. */ // protected: virtual void CreateTitleBar() = 0; - public: bool IsPlaceHolder(); /** * @private: */ public: virtual ~PartPane(); /** * User has requested to close the pane. * Take appropriate action depending on type. */ public: void DoHide(); protected: Rectangle GetParentBounds(); /** * Get the control. */ public: void* GetControl(); /** * Answer the part child. */ public: IWorkbenchPartReference::Pointer GetPartReference() const; /** * @see GuiTk::IControlListener */ public: void ControlActivated(GuiTk::ControlEvent::Pointer e); /** * @see GuiTk::IControlListener */ public: GuiTk::IControlListener::Events::Types GetEventTypes() const; /** * Move the control over another one. */ public: void MoveAbove(void* refControl); /** * Notify the workbook page that the part pane has * been activated by the user. */ public: void RequestActivation(); /** * Shows the receiver if visible is true otherwise hide it. */ public: void SetVisible(bool makeVisible); public: virtual bool GetVisible(); /** * Sets focus to this part. */ public: void SetFocus(); /** * Sets the workbench page of the view. */ public: void SetWorkbenchPage(SmartPointer workbenchPage); public: void Reparent(void* newParent); /** * Indicate focus in part. */ public: void ShowFocus(bool inFocus); /** * @see IPartDropTarget::targetPartFor */ // public: LayoutPart targetPartFor(LayoutPart dragSource) { // return this; // } /** * Returns the PartStack that contains this PartPane, or null if none. * * @return */ public: SmartPointer GetStack(); - public: void SetContainer(SmartPointer stack); + public: void SetContainer(SmartPointer stack); /** * Show a title label menu for this pane. */ // public: void ShowPaneMenu() { // PartStack folder = getStack(); // // if (folder != null) { // folder.showPaneMenu(); // } // } /** * Show the context menu for this part. */ // public: void showSystemMenu() { // PartStack folder = getStack(); // // if (folder != null) { // folder.showSystemMenu(); // } // } /** * Finds and return the sashes around this part. */ protected: Sashes FindSashes(); /** * Enable the user to resize this part using * the keyboard to move the specified sash */ // protected: void moveSash(final Sash sash) { // moveSash(sash, this); // } // public: static void moveSash(final Sash sash, // final LayoutPart toGetFocusWhenDone) { // final KeyListener listener = new KeyAdapter() { // public: void keyPressed(KeyEvent e) { // if (e.character == SWT.ESC || e.character == '\r') { // if (toGetFocusWhenDone != null) { // toGetFocusWhenDone.setFocus(); // } // } // } // }; // sash.addFocusListener(new FocusAdapter() { // public: void focusGained(FocusEvent e) { // sash.setBackground(sash.getDisplay().getSystemColor( // SWT.COLOR_LIST_SELECTION)); // sash.addKeyListener(listener); // } // // public: void focusLost(FocusEvent e) { // sash.setBackground(null); // sash.removeKeyListener(listener); // } // }); // sash.setFocus(); // // } /** * Add a menu item to the Size Menu */ // protected: void addSizeItem(Menu sizeMenu, String labelMessage, // final Sash sash) { // MenuItem item = new MenuItem(sizeMenu, SWT.NONE); // item.setText(labelMessage); // item.addSelectionListener(new SelectionAdapter() { // public: void widgetSelected(SelectionEvent e) { // moveSash(sash); // } // }); // item.setEnabled(!isZoomed() && sash != null); // } /** * Returns the workbench page of this pane. */ public: SmartPointer GetPage(); /** * Add the Left,Right,Up,Botton menu items to the Size menu. */ // protected: void addSizeItems(Menu sizeMenu) { // Sashes sashes = findSashes(); // addSizeItem(sizeMenu, // WorkbenchMessages.PartPane_sizeLeft, sashes.left); // addSizeItem(sizeMenu, // WorkbenchMessages.PartPane_sizeRight, sashes.right); // addSizeItem(sizeMenu, // WorkbenchMessages.PartPane_sizeTop, sashes.top); // addSizeItem(sizeMenu, WorkbenchMessages.PartPane_sizeBottom, sashes.bottom); // } /** * Pin this part. */ protected: virtual void DoDock(); /** * Set the busy state of the pane. */ public: virtual void SetBusy(bool isBusy); /** * Show a highlight for the receiver if it is * not currently the part in the front of its * presentation. * */ public: virtual void ShowHighlight(); /** * @return */ public: virtual void* GetToolBar(); /** * @return */ public: bool HasViewMenu(); /** * @param location */ // public: void ShowViewMenu(Point location) { // // } public: bool IsBusy(); /** * Writes a description of the layout to the given string buffer. * This is used for drag-drop test suites to determine if two layouts are the * same. Like a hash code, the description should compare as equal iff the * layouts are the same. However, it should be user-readable in order to * help debug failed tests. Although these are english readable strings, * they do not need to be translated. * * @param buf */ public: void DescribeLayout(std::string& buf) const; /** * @return * @since 3.1 */ public: bool IsCloseable(); public: void SetInLayout(bool inLayout); public: bool GetInLayout(); public: bool AllowsAutoFocus(); /** * Clears all contribution items from the contribution managers (this is done separately * from dispose() since it is done after the part is disposed). This is a bit of a hack. * Really, the contribution managers should be part of the site, not the PartPane. If these * were moved elsewhere, then disposal of the PartPane would be atomic and this method could * be removed. */ public: virtual void RemoveContributions(); public: void AddPropertyListener(IPropertyChangeListener::Pointer listener); public: void RemovePropertyListener(IPropertyChangeListener::Pointer listener); public: void FirePropertyChange(PropertyChangeEvent::Pointer event); /* (non-Javadoc) * @see IPropertyChangeListener#PropertyChange(PropertyChangeEvent::Pointer) */ public: void PropertyChange(PropertyChangeEvent::Pointer event); /* (non-Javadoc) * @see org.blueberry.ui.internal.LayoutPart#computePreferredSize(boolean, int, int, int) */ public: int ComputePreferredSize(bool width, int availableParallel, int availablePerpendicular, int preferredParallel); /* (non-Javadoc) * @see org.blueberry.ui.internal.LayoutPart#getSizeFlags(boolean) */ public: int GetSizeFlags(bool horizontal); /** * Informs the pane that it's window shell has * been activated. */ public: virtual void ShellActivated(); /** * Informs the pane that it's window shell has * been deactivated. */ public: virtual void ShellDeactivated(); }; } #endif /*BERRYPARTPANE_H_*/ diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartPlaceholder.cpp b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartPlaceholder.cpp index 7232eef7b9..216279d6c5 100644 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartPlaceholder.cpp +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartPlaceholder.cpp @@ -1,52 +1,52 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "berryPartPlaceholder.h" #include "berryPartStack.h" namespace berry { const std::string PartPlaceholder::WILD_CARD = "*"; //$NON-NLS-1$ PartPlaceholder::PartPlaceholder(const std::string& id) : - StackablePart(id) + LayoutPart(id) { } void PartPlaceholder::CreateControl(void* /*parent*/) { // do nothing } void* PartPlaceholder::GetControl() { return 0; } bool PartPlaceholder::HasWildCard() { - return this->GetId().find_first_of(WILD_CARD) != std::string::npos; + return this->GetID().find_first_of(WILD_CARD) != std::string::npos; } bool PartPlaceholder::IsPlaceHolder() const { return true; } } diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartPlaceholder.h b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartPlaceholder.h index ce57dd9abc..c4ebd79dd1 100644 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartPlaceholder.h +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartPlaceholder.h @@ -1,66 +1,66 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef BERRYPARTPLACEHOLDER_H_ #define BERRYPARTPLACEHOLDER_H_ -#include "berryStackablePart.h" +#include "berryLayoutPart.h" namespace berry { /** * \ingroup org_blueberry_ui_internal * * A PlaceHolder is a non-visible stand-in for a layout part. */ -class PartPlaceholder : public StackablePart { +class PartPlaceholder : public LayoutPart { public: berryObjectMacro(PartPlaceholder); /** * Placeholder ids may contain wildcards. This is the wildcard string. * * @since 3.0 */ static const std::string WILD_CARD; // = "*"; //$NON-NLS-1$ PartPlaceholder(const std::string& id); /** * Creates the SWT control */ void CreateControl(void* parent); /** * Get the part control. This method may return null. */ void* GetControl(); /** * Returns whether this placeholder has a wildcard. * * @since 3.0 */ bool HasWildCard(); bool IsPlaceHolder() const; }; } #endif /*BERRYPARTPLACEHOLDER_H_*/ diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartSashContainer.cpp b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartSashContainer.cpp index 355af00612..e6b21d6a7c 100755 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartSashContainer.cpp +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartSashContainer.cpp @@ -1,1282 +1,1270 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "berryPartSashContainer.h" #include "berryLayoutTree.h" #include "berryLayoutTreeNode.h" #include "berryPartStack.h" #include "berryPageLayout.h" #include "berryPerspective.h" #include "berryPerspectiveHelper.h" #include "berryDragUtil.h" #include "berryWorkbenchPlugin.h" #include "berryWorkbenchPreferenceConstants.h" #include "berryGeometry.h" #include "berryPartPane.h" #include "tweaklets/berryGuiWidgetsTweaklet.h" #include "berryConstants.h" namespace berry { bool PartSashContainer::leftToRight = true; PartSashContainer::ControlListener::ControlListener( PartSashContainer* container) : partSashContainer(container) { } GuiTk::IControlListener::Events::Types PartSashContainer::ControlListener::GetEventTypes() const { return Events::RESIZED; } void PartSashContainer::ControlListener::ControlResized( GuiTk::ControlEvent::Pointer /*e*/) { partSashContainer->ResizeSashes(); } PartSashContainer::SashContainerDropTarget::SashContainerDropTarget( PartSashContainer* partSashContainer, Object::Pointer sourcePart, int side, int cursor, Object::Pointer targetPart) : partSashContainer(partSashContainer) { this->SetTarget(sourcePart, side, cursor, targetPart); } void PartSashContainer::SashContainerDropTarget::SetTarget( Object::Pointer sourcePart, int side, int cursor, Object::Pointer targetPart) { this->side = side; this->targetPart = targetPart; this->sourcePart = sourcePart; this->cursor = cursor; } void PartSashContainer::SashContainerDropTarget::Drop() { if (side != Constants::NONE) { - StackablePart::Pointer visiblePart = sourcePart.Cast (); + LayoutPart::Pointer visiblePart = sourcePart.Cast (); - if (sourcePart.Cast () != 0) + if (sourcePart.Cast () != 0) { visiblePart = partSashContainer->GetVisiblePart(sourcePart.Cast< - IStackableContainer> ()); + ILayoutContainer> ()); } partSashContainer->DropObject( partSashContainer->GetVisibleParts(sourcePart), visiblePart, targetPart, side); } } void PartSashContainer::DropObject(const std::vector& toDrop, - StackablePart::Pointer visiblePart, Object::Pointer targetPart, int side) + LayoutPart::Pointer visiblePart, Object::Pointer targetPart, int side) { //getControl().setRedraw(false); // Targetpart is null if there isn't a part under the cursor (all the parts are // hidden or the container is empty). In this case, the actual side doesn't really // since we'll be the only visible container and will fill the entire space. However, // we can't leave it as Constants::CENTER since we can't stack if we don't have something // to stack on. In this case, we pick Constants::BOTTOM -- this will insert the new pane // below any currently-hidden parts. if (targetPart == 0 && side == Constants::CENTER) { side = Constants::BOTTOM; } PartStack::Pointer targetStack = targetPart.Cast (); if (targetStack == 0 && targetPart.Cast() != 0) { targetStack = targetPart.Cast ()->GetStack(); } LayoutPart::Pointer targetLayoutPart = targetStack; // if targetLayoutPart == 0 then we normally got a EditorSashContainer if (targetLayoutPart == 0) targetLayoutPart = targetPart.Cast(); if (side == Constants::CENTER) { if (this->IsStackType(targetStack)) { for (unsigned int idx = 0; idx < toDrop.size(); idx++) { - StackablePart::Pointer next = toDrop[idx]; + LayoutPart::Pointer next = toDrop[idx]; this->Stack(next, targetStack); } } } else { PartStack::Pointer newPart = this->CreateStack(); // if the toDrop array has 1 item propagate the stack // appearance if (toDrop.size() == 1 && toDrop[0]->GetStack() != 0) { toDrop[0]->GetStack()->CopyAppearanceProperties(newPart); } for (unsigned int idx = 0; idx < toDrop.size(); idx++) { - StackablePart::Pointer next = toDrop[idx]; + LayoutPart::Pointer next = toDrop[idx]; this->Stack(next, newPart); } this->AddEnhanced(newPart, side, this->GetDockingRatio(newPart, targetStack), targetLayoutPart); } if (visiblePart != 0) { this->SetVisiblePart(visiblePart->GetContainer(), visiblePart.Cast ()); } //getControl().setRedraw(true); if (visiblePart != 0) { visiblePart->SetFocus(); } } DnDTweaklet::CursorType PartSashContainer::SashContainerDropTarget::GetCursor() { return DnDTweaklet::PositionToCursorType(cursor); } Rectangle PartSashContainer::SashContainerDropTarget::GetSnapRectangle() { Rectangle targetBounds; if (targetPart.Cast () != 0) { targetBounds = DragUtil::GetDisplayBounds( targetPart.Cast ()->GetControl()); } - else if (targetPart.Cast () != 0) + else if (targetPart.Cast () != 0) { targetBounds = DragUtil::GetDisplayBounds( - targetPart.Cast ()->GetControl()); + targetPart.Cast ()->GetControl()); } else { targetBounds = DragUtil::GetDisplayBounds(partSashContainer->GetParent()); } if (side == Constants::CENTER || side == Constants::NONE) { return targetBounds; } int distance = Geometry::GetDimension(targetBounds, !Geometry::IsHorizontal( side)); - IStackableContainer::Pointer stack = targetPart.Cast (); - if (stack == 0 && targetPart.Cast () != 0) + ILayoutContainer::Pointer stack = targetPart.Cast (); + if (stack == 0 && targetPart.Cast () != 0) { - stack = targetPart.Cast ()->GetContainer(); + stack = targetPart.Cast ()->GetContainer(); } return Geometry::GetExtrudedEdge(targetBounds, (int) (distance * partSashContainer->GetDockingRatio(sourcePart, stack)), side); } PartSashContainer::PartSashContainer(const std::string& id, WorkbenchPage* _page, void* _parentWidget) : LayoutPart(id), parentWidget(_parentWidget), parent(0), page(_page), active( false), layoutDirty(false) { resizeListener = new ControlListener(this); std::string layout = WorkbenchPlugin::GetDefault()->GetPreferencesService()-> GetSystemPreferences()->Get(WorkbenchPreferenceConstants::PREFERRED_SASH_LAYOUT, WorkbenchPreferenceConstants::LEFT); if (layout == WorkbenchPreferenceConstants::RIGHT) { leftToRight = false; } } std::vector PartSashContainer::GetVisibleParts( Object::Pointer pane) { std::vector parts; if (pane.Cast ().IsNotNull()) { parts.push_back(pane.Cast ()); } else if (pane.Cast ().IsNotNull()) { PartStack::Pointer stack = pane.Cast (); - std::list children = stack->GetChildren(); - for (std::list::iterator iter = children.begin(); iter + std::list children = stack->GetChildren(); + for (std::list::iterator iter = children.begin(); iter != children.end(); ++iter) { if (iter->Cast () != 0) { parts.push_back(iter->Cast ()); } } } return parts; } PartSashContainer::~PartSashContainer() { } void PartSashContainer::FindSashes(LayoutPart::Pointer pane, PartPane::Sashes& sashes) { if (root == 0) { return; } LayoutTree::Pointer part = root->Find(pane); if (part == 0) { return; } part->FindSashes(sashes); } void PartSashContainer::Add(LayoutPart::Pointer child) { if (child.IsNull()) { return; } this->AddEnhanced(child, Constants::RIGHT, 0.5f, this->FindBottomRight()); } -void PartSashContainer::AddPart(StackablePart::Pointer child) +void PartSashContainer::AddPart(LayoutPart::Pointer child) { if (child.IsNull()) { return; } PartStack::Pointer newFolder = this->CreateStack(); newFolder->Add(child); this->AddEnhanced(newFolder, Constants::RIGHT, 0.5f, this->FindBottomRight()); } void PartSashContainer::AddEnhanced(LayoutPart::Pointer child, int directionConstant, float ratioForNewPart, LayoutPart::Pointer relative) { int relativePosition = PageLayout::ConstantToLayoutPosition(directionConstant); float ratioForUpperLeftPart; if (relativePosition == IPageLayout::RIGHT || relativePosition == IPageLayout::BOTTOM) { ratioForUpperLeftPart = 1.0f - ratioForNewPart; } else { ratioForUpperLeftPart = ratioForNewPart; } this->Add(child, relativePosition, ratioForUpperLeftPart, relative); } void PartSashContainer::Add(LayoutPart::Pointer child, int relationship, float ratio, LayoutPart::Pointer relative) { bool isHorizontal = (relationship == IPageLayout::LEFT || relationship == IPageLayout::RIGHT); LayoutTree::Pointer node; if (root != 0 && relative != 0) { node = root->Find(relative); } Rectangle bounds; if (this->GetParent() == 0) { void* control = this->GetPage()->GetClientComposite(); if (control != 0) { bounds = Tweaklets::Get(GuiWidgetsTweaklet::KEY)->GetBounds(control); } else { bounds = Rectangle(0, 0, 800, 600); } bounds.x = 0; bounds.y = 0; } else { bounds = this->GetBounds(); } int totalSize = this->MeasureTree(bounds, node, isHorizontal); int left = (int) (totalSize * ratio); int right = totalSize - left; this->Add(child, relationship, left, right, relative); } int PartSashContainer::MeasureTree(const Rectangle& outerBounds, LayoutTree::ConstPointer toMeasure, bool horizontal) { if (toMeasure == 0) { return outerBounds.GetDimension(horizontal); } LayoutTreeNode* parent = toMeasure->GetParent(); if (parent == 0) { return outerBounds.GetDimension(horizontal); } if (parent->GetSash()->IsHorizontal() == horizontal) { return MeasureTree(outerBounds, LayoutTree::ConstPointer(parent), horizontal); } bool isLeft = parent->IsLeftChild(toMeasure); LayoutTree::Pointer otherChild = parent->GetChild(!isLeft); if (otherChild->IsVisible()) { int left = parent->GetSash()->GetLeft(); int right = parent->GetSash()->GetRight(); int childSize = isLeft ? left : right; int bias = parent->GetCompressionBias(); // Normalize bias: 1 = we're fixed, -1 = other child is fixed if (isLeft) { bias = -bias; } if (bias == 1) { // If we're fixed, return the fixed size return childSize; } else if (bias == -1) { // If the other child is fixed, return the size of the parent minus the fixed size of the // other child return MeasureTree(outerBounds, LayoutTree::ConstPointer(parent), horizontal) - (left + right - childSize); } // Else return the size of the parent, scaled appropriately return MeasureTree(outerBounds, LayoutTree::ConstPointer(parent), horizontal) * childSize / (left + right); } return MeasureTree(outerBounds, LayoutTree::ConstPointer(parent), horizontal); } void PartSashContainer::AddChild(const RelationshipInfo& info) { LayoutPart::Pointer child = info.part; children.push_back(child); if (root == 0) { root = new LayoutTree(child); } else { //Add the part to the tree. int vertical = (info.relationship == IPageLayout::LEFT || info.relationship == IPageLayout::RIGHT) ? Constants::VERTICAL : Constants::HORIZONTAL; bool left = info.relationship == IPageLayout::LEFT || info.relationship == IPageLayout::TOP; LayoutPartSash::Pointer sash(new LayoutPartSash(this, vertical)); sash->SetSizes(info.left, info.right); if ((parent != 0) && child.Cast ().IsNull()) { sash->CreateControl(parent); } LayoutTree::Pointer newroot = root->Insert(child, left, sash, info.relative); root = newroot; } this->ChildAdded(child); if (active) { child->CreateControl(parent); child->SetVisible(true); child->SetContainer(ILayoutContainer::Pointer(this)); this->ResizeChild(child); } } void PartSashContainer::AddChildForPlaceholder(LayoutPart::Pointer child, LayoutPart::Pointer placeholder) { RelationshipInfo newRelationshipInfo; newRelationshipInfo.part = child; if (root != 0) { newRelationshipInfo.relationship = IPageLayout::RIGHT; newRelationshipInfo.relative = root->FindBottomRight(); newRelationshipInfo.left = 200; newRelationshipInfo.right = 200; } // find the relationship info for the placeholder std::vector relationships = this->ComputeRelation(); for (unsigned int i = 0; i < relationships.size(); i++) { RelationshipInfo info = relationships[i]; if (info.part == placeholder) { newRelationshipInfo.left = info.left; newRelationshipInfo.right = info.right; newRelationshipInfo.relationship = info.relationship; newRelationshipInfo.relative = info.relative; } } this->AddChild(newRelationshipInfo); this->FlushLayout(); } bool PartSashContainer::AllowsBorder() { return true; } void PartSashContainer::ChildAdded(LayoutPart::Pointer child) { if (this->IsDeferred()) { child->DeferUpdates(true); } } void PartSashContainer::ChildRemoved(LayoutPart::Pointer child) { if (this->IsDeferred()) { child->DeferUpdates(false); } } std::vector PartSashContainer::ComputeRelation() { LayoutTree::Pointer treeRoot = root; std::list list; if (treeRoot == 0) { return std::vector(); } RelationshipInfo r; r.part = treeRoot->ComputeRelation(list); list.push_front(r); std::vector result(list.begin(), list.end()); return result; } void PartSashContainer::SetActive(bool isActive) { if (isActive == active) { return; } active = isActive; ILayoutContainer::ChildrenType children = this->children; for (ILayoutContainer::ChildrenType::iterator childIter = children.begin(); childIter != children.end(); ++childIter) { if (childIter->Cast ().IsNotNull()) { PartStack::Pointer stack = childIter->Cast (); stack->SetActive(isActive); } } if (isActive) { this->CreateControl(parentWidget); Tweaklets::Get(GuiWidgetsTweaklet::KEY)->AddControlListener(parent, resizeListener); DragUtil::AddDragTarget(parent, IDragOverListener::Pointer(this)); DragUtil::AddDragTarget(Tweaklets::Get(GuiWidgetsTweaklet::KEY)->GetShell(parent)->GetControl(), IDragOverListener::Pointer(this)); ILayoutContainer::ChildrenType children = this->children; for (ILayoutContainer::ChildrenType::iterator childIter = children.begin(); childIter != children.end(); ++childIter) { LayoutPart::Pointer child = *childIter; child->SetContainer(ILayoutContainer::Pointer(this)); child->SetVisible(true); //zoomedPart == null || child == zoomedPart); if (child.Cast ().IsNull()) { if (root != 0) { LayoutTree::Pointer node = root->Find(child); if (node != 0) { node->FlushCache(); } } } } if (root != 0) { //root.flushChildren(); //if (!isZoomed()) { root->CreateControl(parent); } } this->ResizeSashes(); } else { DragUtil::RemoveDragTarget(parent, IDragOverListener::Pointer(this)); DragUtil::RemoveDragTarget(Tweaklets::Get(GuiWidgetsTweaklet::KEY)->GetShell(parent)->GetControl(), IDragOverListener::Pointer(this)); // remove all Listeners if (resizeListener != 0 && parent != 0) { Tweaklets::Get(GuiWidgetsTweaklet::KEY)->RemoveControlListener(parent, resizeListener); } for (ILayoutContainer::ChildrenType::iterator iter = children.begin(); iter != children.end(); ++iter) { LayoutPart::Pointer child = *iter; child->SetContainer(ILayoutContainer::Pointer(0)); if (child.Cast ().IsNotNull()) { child->SetVisible(false); } } this->DisposeSashes(); //dispose(); } } void PartSashContainer::CreateControl(void* parentWidget) { if (this->parent != 0) { return; } parent = this->CreateParent(parentWidget); ILayoutContainer::ChildrenType children = this->children; for (ILayoutContainer::ChildrenType::iterator childIter = children.begin(); childIter != children.end(); ++childIter) { (*childIter)->CreateControl(parent); } } void PartSashContainer::Dispose() { if (parent == 0) { return; } for (ILayoutContainer::ChildrenType::iterator iter = children.begin(); iter != children.end(); ++iter) { // In PartSashContainer dispose really means deactivate, so we // only dispose PartTabFolders. if (iter->Cast() != 0) { (*iter)->Dispose(); } } this->DisposeParent(); this->parent = 0; } void PartSashContainer::DisposeSashes() { if (root != 0) { root->DisposeSashes(); } } void PartSashContainer::SetVisible(bool makeVisible) { if (makeVisible == this->GetVisible()) { return; } //if (!SwtUtil.isDisposed(this.parent)) //{ Tweaklets::Get(GuiWidgetsTweaklet::KEY)->SetEnabled(this->parent, makeVisible); //} LayoutPart::SetVisible(makeVisible); ILayoutContainer::ChildrenType children = this->children; for (ILayoutContainer::ChildrenType::iterator childIter = children.begin(); childIter != children.end(); ++childIter) { (*childIter)->SetVisible(makeVisible); // && (zoomedPart == null || child == zoomedPart)); } } LayoutPart::Pointer PartSashContainer::FindBottomRight() { if (root == 0) { return LayoutPart::Pointer(0); } return root->FindBottomRight(); } Rectangle PartSashContainer::GetBounds() { return Tweaklets::Get(GuiWidgetsTweaklet::KEY)->GetBounds(this->parent); } -ILayoutContainer::ChildrenType PartSashContainer::GetChildren() +ILayoutContainer::ChildrenType PartSashContainer::GetChildren() const { return children; } void* PartSashContainer::GetControl() { return this->parent; } LayoutTree::Pointer PartSashContainer::GetLayoutTree() { return root; } WorkbenchPage::Pointer PartSashContainer::GetPage() { return WorkbenchPage::Pointer(page); } void* PartSashContainer::GetParent() { return parent; } bool PartSashContainer::IsChild(LayoutPart::Pointer part) { return std::find(children.begin(), children.end(), part) != children.end(); } void PartSashContainer::ResizeChild(LayoutPart::Pointer childThatChanged) { if (root != 0) { LayoutTree::Pointer tree = root->Find(childThatChanged); if (tree != 0) { tree->FlushCache(); } } this->FlushLayout(); } void PartSashContainer::Remove(LayoutPart::Pointer child) { // if (child == getZoomedPart()) // { // childRequestZoomOut(); // } if (!this->IsChild(child)) { return; } children.remove(child); if (root != 0) { root = root->Remove(child); } this->ChildRemoved(child); if (active) { child->SetVisible(false); child->SetContainer(ILayoutContainer::Pointer(0)); this->FlushLayout(); } } void PartSashContainer::FlushLayout() { layoutDirty = true; LayoutPart::FlushLayout(); if (layoutDirty) { this->ResizeSashes(); } } void PartSashContainer::Replace(LayoutPart::Pointer oldChild, - LayoutPart::Pointer newChild) + LayoutPart::Pointer newChild) { if (!this->IsChild(oldChild)) { return; } // if (oldChild == getZoomedPart()) // { // if (newChild.Cast ().IsNotNull()) // { // childRequestZoomOut(); // } // else // { // zoomedPart.setZoomed(false); // zoomedPart = newChild; // zoomedPart.setZoomed(true); // } // } children.erase(std::find(children.begin(), children.end(), oldChild)); children.push_back(newChild); this->ChildAdded(newChild); if (root != 0) { LayoutTree::Pointer leaf; leaf = root->Find(oldChild); if (leaf != 0) { leaf->SetPart(newChild); } } this->ChildRemoved(oldChild); if (active) { oldChild->SetVisible(false); oldChild->SetContainer(ILayoutContainer::Pointer(0)); newChild->CreateControl(parent); newChild->SetContainer(ILayoutContainer::Pointer(this)); newChild->SetVisible(true); //zoomedPart == null || zoomedPart == newChild); this->ResizeChild(newChild); } } void PartSashContainer::ResizeSashes() { layoutDirty = false; if (!active) { return; } // if (isZoomed()) // { // getZoomedPart().setBounds(parent.getClientArea()); // } // else { if (root != 0) { root->SetBounds(Tweaklets::Get(GuiWidgetsTweaklet::KEY)->GetClientArea( parent)); } } } int PartSashContainer::ComputePreferredSize(bool width, int availableParallel, int availablePerpendicular, int preferredParallel) { // if (isZoomed()) // { // return getZoomedPart().computePreferredSize(width, availableParallel, // availablePerpendicular, preferredParallel); // } if (root != 0) { return root->ComputePreferredSize(width, availableParallel, availablePerpendicular, preferredParallel); } return preferredParallel; } int PartSashContainer::GetSizeFlags(bool width) { // if (isZoomed()) // { // return getZoomedPart().getSizeFlags(width); // } if (root != 0) { return root->GetSizeFlags(width); } return 0; } void PartSashContainer::SetBounds(const Rectangle& r) { Tweaklets::Get(GuiWidgetsTweaklet::KEY)->SetBounds(this->parent, r); } IDropTarget::Pointer PartSashContainer::Drag(void* /*currentControl*/, Object::Pointer draggedObject, const Point& position, const Rectangle& /*dragRectangle*/) { if (!(draggedObject.Cast () != 0 || draggedObject.Cast () != 0)) { return IDropTarget::Pointer(0); } PartPane::Pointer sourcePart = draggedObject.Cast (); PartStack::Pointer sourceContainer = draggedObject.Cast (); if (sourceContainer == 0) { sourceContainer = sourcePart->GetStack(); } if (!this->IsStackType(sourceContainer) && !this->IsPaneType(sourcePart)) { return IDropTarget::Pointer(0); } IWorkbenchWindow::Pointer window = sourcePart ? sourcePart->GetWorkbenchWindow() : sourceContainer->GetWorkbenchWindow(); bool differentWindows = window != this->GetWorkbenchWindow(); bool editorDropOK = ((sourceContainer->GetAppearance() == PresentationFactoryUtil::ROLE_EDITOR) && window->GetWorkbench() == this->GetWorkbenchWindow()->GetWorkbench()); if (differentWindows && !editorDropOK) { return IDropTarget::Pointer(0); } Rectangle containerBounds = DragUtil::GetDisplayBounds(parent); LayoutPart::Pointer targetPart; // If this container has no visible children if (this->GetVisibleChildrenCount(ILayoutContainer::Pointer(this)) == 0) { return this->CreateDropTarget(draggedObject, Constants::CENTER, Constants::CENTER, Object::Pointer(0)); } if (containerBounds.Contains(position)) { if (root != 0) { targetPart = root->FindPart( Tweaklets::Get(GuiWidgetsTweaklet::KEY)->ToControl(parent, position)); } if (targetPart != 0) { void* targetControl = targetPart->GetControl(); Rectangle targetBounds = DragUtil::GetDisplayBounds(targetControl); int side = Geometry::GetClosestSide(targetBounds, position); int distance = Geometry::GetDistanceFromEdge(targetBounds, position, side); // is the source coming from a standalone part bool standalone = (this->IsStackType(sourceContainer) && sourceContainer->IsStandalone()) || (this->IsPaneType(sourcePart) && sourcePart->GetStack()->IsStandalone()); // Only allow dropping onto an existing stack from different windows if (differentWindows && targetPart.Cast () != 0 && targetPart.Cast ()->GetAppearance() == PresentationFactoryUtil::ROLE_EDITOR) { IDropTarget::Pointer target = targetPart->GetDropTarget(draggedObject, position); return target; } // Reserve the 5 pixels around the edge of the part for the drop-on-edge cursor if (distance >= 5 && !standalone) { // Otherwise, ask the part if it has any special meaning for this drop location IDropTarget::Pointer target = targetPart->GetDropTarget(draggedObject, position); if (target != 0) { return target; } } if (distance > 30 && this->IsStackType(targetPart.Cast ()) && !standalone) { PartStack::Pointer targetContainer = targetPart.Cast (); if (targetContainer->AllowsAdd(sourcePart)) { side = Constants::CENTER; } } // If the part doesn't want to override this drop location then drop on the edge // A "pointless drop" would be one that will put the dragged object back where it started. // Note that it should be perfectly valid to drag an object back to where it came from -- however, // the drop should be ignored. bool pointlessDrop = false; // = isZoomed(); if (!sourcePart && sourceContainer == targetPart) { pointlessDrop = true; } if ((sourceContainer != 0) && (sourceContainer == targetPart) - && this->GetVisibleChildrenCount(sourceContainer.Cast()) <= 1) + && this->GetVisibleChildrenCount(sourceContainer.Cast()) <= 1) { pointlessDrop = true; } if (side == Constants::CENTER && sourceContainer == targetPart) { pointlessDrop = true; } int cursor = side; if (pointlessDrop) { side = Constants::NONE; cursor = Constants::CENTER; } if (sourcePart) return this->CreateDropTarget(sourcePart, side, cursor, targetPart); else return this->CreateDropTarget(sourceContainer, side, cursor, targetPart); } } else { // We only allow dropping into a stack, not creating one if (differentWindows) return IDropTarget::Pointer(0); int side = Geometry::GetClosestSide(containerBounds, position); bool pointlessDrop = false; // = isZoomed(); if (/*(this->IsStackType(sourceContainer) && sourceContainer == this) ||*/ (this->IsPaneType(sourcePart) && this->GetVisibleChildrenCount( - sourceContainer.Cast()) <= 1) && sourceContainer->GetContainer() == this) + sourceContainer.Cast()) <= 1) && sourceContainer->GetContainer() == this) { if (root == 0 || this->GetVisibleChildrenCount(ILayoutContainer::Pointer(this)) <= 1) { pointlessDrop = true; } } int cursor = Geometry::GetOppositeSide(side); if (pointlessDrop) { side = Constants::NONE; } if (sourcePart) return this->CreateDropTarget(sourcePart, side, cursor, Object::Pointer(0)); else return this->CreateDropTarget(sourceContainer, side, cursor, Object::Pointer(0)); } return IDropTarget::Pointer(0); } PartSashContainer::SashContainerDropTarget::Pointer PartSashContainer::CreateDropTarget( Object::Pointer sourcePart, int side, int cursor, Object::Pointer targetPart) { if (dropTarget == 0) { dropTarget = new SashContainerDropTarget(this, sourcePart, side, cursor, targetPart); } else { dropTarget->SetTarget(sourcePart, side, cursor, targetPart); } return dropTarget; } -void PartSashContainer::Stack(StackablePart::Pointer newPart, - IStackableContainer::Pointer container) +void PartSashContainer::Stack(LayoutPart::Pointer newPart, + ILayoutContainer::Pointer container) { //this->GetControl().setRedraw(false); // Only deref the part if it is being referenced in -this- perspective Perspective::Pointer persp = page->GetActivePerspective(); PerspectiveHelper* pres = (persp != 0) ? persp->GetPresentation() : 0; if (pres != 0 && container.Cast()->GetAppearance() != PresentationFactoryUtil::ROLE_EDITOR) { IWorkbenchPartReference::Pointer newPartRef = newPart.Cast ()->GetPartReference(); IViewReference::Pointer vRef = newPartRef.Cast (); if (vRef != 0) { - StackablePart::Pointer fpp = pres->FindPart(vRef->GetId(), + LayoutPart::Pointer fpp = pres->FindPart(vRef->GetId(), vRef->GetSecondaryId()); if (fpp != 0) { // Remove the part from old container. this->DerefPart(newPart); } } } else { // Remove the part from old container. this->DerefPart(newPart); } // Reparent part and add it to the workbook newPart->Reparent(this->GetParent()); container->Add(newPart); //getControl().setRedraw(true); } -void PartSashContainer::DerefPart(StackablePart::Pointer sourcePart) +void PartSashContainer::DerefPart(LayoutPart::Pointer sourcePart) { - IStackableContainer::Pointer container = sourcePart->GetContainer(); + ILayoutContainer::Pointer container = sourcePart->GetContainer(); if (container != 0) { container->Remove(sourcePart); if (this->IsStackType(container) && container.Cast () != 0) { if (container->GetChildren().size() == 0) { LayoutPart::Pointer stack = container.Cast (); this->Remove(stack); stack->Dispose(); } } } } std::size_t PartSashContainer::GetVisibleChildrenCount( - IStackableContainer::Pointer container) + ILayoutContainer::Pointer container) { // Treat null as an empty container if (container == 0) { return 0; } - IStackableContainer::ChildrenType children = container->GetChildren(); + ILayoutContainer::ChildrenType children = container->GetChildren(); std::size_t count = 0; - for (IStackableContainer::ChildrenType::iterator iter = children.begin(); iter + for (ILayoutContainer::ChildrenType::iterator iter = children.begin(); iter != children.end(); ++iter) { if (!(*iter)->IsPlaceHolder()) { count++; } } return count; } -std::size_t PartSashContainer::GetVisibleChildrenCount( - ILayoutContainer::Pointer container) -{ - // Treat null as an empty container - if (container == 0) - { - return 0; - } - - return container->GetChildren().size(); -} - float PartSashContainer::GetDockingRatio(Object::Pointer /*dragged*/, - IStackableContainer::Pointer /*target*/) + ILayoutContainer::Pointer /*target*/) { return 0.5f; } void PartSashContainer::DescribeLayout(std::string& buf) const { if (root == 0) { return; } // if (isZoomed()) // { // buf.append("zoomed "); //$NON-NLS-1$ // root.describeLayout(buf); // } // else { buf.append("layout "); //$NON-NLS-1$ root->DescribeLayout(buf); } } void PartSashContainer::Add(LayoutPart::Pointer child, int relationship, int left, int right, LayoutPart::Pointer relative) { if (child == 0) { return; } if (relative != 0 && !this->IsChild(relative)) { return; } if (relationship < IPageLayout::LEFT || relationship > IPageLayout::BOTTOM) { relationship = IPageLayout::LEFT; } // store info about relative positions RelationshipInfo info; info.part = child; info.relationship = relationship; info.left = left; info.right = right; info.relative = relative; this->AddChild(info); } bool PartSashContainer::AllowsAutoFocus() { return true; } void PartSashContainer::StartDeferringEvents() { LayoutPart::StartDeferringEvents(); ILayoutContainer::ChildrenType deferredChildren = children; for (ILayoutContainer::ChildrenType::iterator iter = deferredChildren.begin(); iter != deferredChildren.end(); ++iter) { (*iter)->DeferUpdates(true); } } void PartSashContainer::HandleDeferredEvents() { LayoutPart::HandleDeferredEvents(); ILayoutContainer::ChildrenType deferredChildren = children; for (ILayoutContainer::ChildrenType::iterator iter = deferredChildren.begin(); iter != deferredChildren.end(); ++iter) { (*iter)->DeferUpdates(false); } } void PartSashContainer::TestInvariants() { LayoutPart::TestInvariants(); // If we have a parent container, ensure that we are displaying the zoomed appearance iff // our parent is zoomed in on us // if (this->GetContainer() != 0) // { // Assert.isTrue((getZoomedPart() != null) == (getContainer().childIsZoomed( // this))); // } ILayoutContainer::ChildrenType childArray = this->GetChildren(); for (ILayoutContainer::ChildrenType::iterator iter = childArray.begin(); iter != childArray.end(); ++iter) { (*iter)->TestInvariants(); } // If we're zoomed, ensure that we're actually zoomed into one of our children // if (isZoomed()) // { // Assert.isTrue(children.contains(zoomedPart)); // } } } diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartSashContainer.h b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartSashContainer.h index f3ce56c941..7a09ac9ea5 100644 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartSashContainer.h +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartSashContainer.h @@ -1,703 +1,702 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef BERRYPARTSASHCONTAINER_H_ #define BERRYPARTSASHCONTAINER_H_ #include "berryLayoutPart.h" #include "berryILayoutContainer.h" -#include "berryIStackableContainer.h" +#include "berryILayoutContainer.h" #include "berryIDragOverListener.h" #include "berryAbstractDropTarget.h" #include "tweaklets/berryDnDTweaklet.h" #include "berryRectangle.h" #include "guitk/berryGuiTkIControlListener.h" namespace berry { class WorkbenchPage; class PartPane; class LayoutTree; class PartStack; /** * \ingroup org_blueberry_ui_internal * * Abstract container that groups various layout * parts (possibly other containers) together as * a unit. Manages the placement and size of these * layout parts based on the location of sashes within * the container. * * GUI specializations must override the following methods * (read their documentation for implementation details): * *
    *
  • PartSashContainer */ class PartSashContainer: public LayoutPart, public ILayoutContainer, public IDragOverListener { public: berryObjectMacro(PartSashContainer); friend class LayoutTree; friend class LayoutTreeNode; friend class PageLayout; private: void* parentWidget; //LayoutPart::Pointer zoomedPart; /* Indicates if the children of a sash container should be aligned from left to right * or the other way around. This is important if one child does * not occupy all of the available space. Then the empty space * is either on the left, or on the right side. */ bool static leftToRight; protected: struct ControlListener : public GuiTk::IControlListener { ControlListener(PartSashContainer* partSashContainer); Events::Types GetEventTypes() const; void ControlResized(GuiTk::ControlEvent::Pointer e); private: PartSashContainer* partSashContainer; }; void* parent; GuiTk::IControlListener::Pointer resizeListener; SmartPointer root; WorkbenchPage* page; bool active; bool layoutDirty; /* Array of LayoutPart */ ILayoutContainer::ChildrenType children; protected: struct RelationshipInfo { LayoutPart::Pointer part; LayoutPart::Pointer relative; int relationship; /** * Preferred size for the left child (this would be the size, in pixels of the child * at the time the sash was last moved) */ int left; /** * Preferred size for the right child (this would be the size, in pixels of the child * at the time the sash was last moved) */ int right; }; private: class SashContainerDropTarget : public AbstractDropTarget { private: int side; int cursor; - // This is a IStackablePart or IStackableContainer + // This is a ILayoutPart or ILayoutContainer Object::Pointer targetPart; - // This is a IStackablePart or IStackableContainer + // This is a ILayoutPart or ILayoutContainer Object::Pointer sourcePart; PartSashContainer* partSashContainer; public: berryObjectMacro(SashContainerDropTarget); SashContainerDropTarget(PartSashContainer* partSashContainer, Object::Pointer sourcePart, int side, int cursor, Object::Pointer targetPart); void SetTarget(Object::Pointer sourcePart, int side, int cursor, Object::Pointer targetPart); void Drop(); DnDTweaklet::CursorType GetCursor(); Rectangle GetSnapRectangle(); }; SashContainerDropTarget::Pointer dropTarget; public: /** * Constructs a PartSashContainer with the given id under the given page * and parentWidget. * * GUI specializations must hook */ PartSashContainer(const std::string& id, WorkbenchPage* page, void* parentWidget); ~PartSashContainer(); /* (non-Javadoc) * @see org.blueberry.ui.internal.ILayoutContainer#obscuredByZoom(org.blueberry.ui.internal.LayoutPart) */ // public: bool childObscuredByZoom(LayoutPart toTest) { // LayoutPart zoomPart = getZoomedPart(); // // if (zoomPart != null && toTest != zoomPart) { // return true; // } // return isObscuredByZoom(); // } /** * Given an object associated with a drag (a PartPane or PartStack), this returns * the actual PartPanes being dragged. * * @param pane * @return */ private: std::vector > GetVisibleParts(Object::Pointer pane); /** * Find the sashs around the specified part. */ public: void FindSashes(LayoutPart::Pointer pane, PartPane::Sashes& sashes); public: /** * Add a part. */ virtual void Add(LayoutPart::Pointer child); - virtual void AddPart(StackablePart::Pointer child); + virtual void AddPart(LayoutPart::Pointer child); /** * Add a part relative to another. For compatibility only. New code should use * addEnhanced, above. * * @param child the new part to add * @param relationship one of PageLayout.TOP, PageLayout.BOTTOM, PageLayout.LEFT, or PageLayout.RIGHT * @param ratio a value between 0.0 and 1.0, indicating how much space will be allocated to the UPPER-LEFT pane * @param relative part where the new part will be attached */ virtual void Add(LayoutPart::Pointer child, int relationship, float ratio, LayoutPart::Pointer relative); protected: virtual void DropObject(const std::vector& toDrop, - StackablePart::Pointer visiblePart, + LayoutPart::Pointer visiblePart, Object::Pointer targetPart, int side); /** * Add a new part relative to another. This should be used in place of add. * It differs as follows: *
      *
    • relationships are specified using SWT direction constants
    • *
    • the ratio applies to the newly added child -- not the upper-left child
    • *
    * * @param child new part to add to the layout * @param swtDirectionConstant one of SWT.TOP, SWT.BOTTOM, SWT.LEFT, or SWT.RIGHT * @param ratioForNewPart a value between 0.0 and 1.0 specifying how much space will be allocated for the newly added part * @param relative existing part indicating where the new child should be attached * @since 3.0 */ protected: virtual void AddEnhanced(LayoutPart::Pointer child, int swtDirectionConstant, float ratioForNewPart, LayoutPart::Pointer relative); protected: static int MeasureTree(const Rectangle& outerBounds, SmartPointer toMeasure, bool horizontal); protected: virtual void AddChild(const RelationshipInfo& info); /** * Adds the child using ratio and position attributes * from the specified placeholder without replacing * the placeholder * * FIXME: I believe there is a bug in computeRelation() * when a part is positioned relative to the editorarea. * We end up with a null relative and 0.0 for a ratio. */ -protected: +public: virtual void AddChildForPlaceholder(LayoutPart::Pointer child, LayoutPart::Pointer placeholder); /** * See ILayoutContainer#allowBorder */ public: virtual bool AllowsBorder(); /** * Notification that a child layout part has been * added to the container. Subclasses may override * this method to perform any container specific * work. */ protected: virtual void ChildAdded(LayoutPart::Pointer child); /** * Notification that a child layout part has been * removed from the container. Subclasses may override * this method to perform any container specific * work. */ protected: virtual void ChildRemoved(LayoutPart::Pointer child); /** * Returns an array with all the relation ship between the * parts. */ public: virtual std::vector ComputeRelation(); public: virtual void SetActive(bool isActive); /** * @see LayoutPart#getControl */ public: void CreateControl(void* parentWidget); /** * Subclasses override this method to specify * the composite to use to parent all children * layout parts it contains. */ protected: virtual void* CreateParent(void* parentWidget) = 0; /** * @see LayoutPart#dispose */ public: virtual void Dispose(); /** * Subclasses override this method to dispose * of any swt resources created during createParent. */ protected: virtual void DisposeParent() = 0; /** * Dispose all sashs used in this perspective. */ public: virtual void DisposeSashes(); /* (non-Javadoc) * @see org.blueberry.ui.internal.LayoutPart#setVisible(boolean) */ public: void SetVisible(bool makeVisible); /** * Return the most bottom right part or null if none. */ public: virtual LayoutPart::Pointer FindBottomRight(); /** * @see LayoutPart#getBounds */ public: Rectangle GetBounds(); /** * @see ILayoutContainer#getChildren */ public: - ChildrenType GetChildren(); + ChildrenType GetChildren() const; /** * @see LayoutPart#getControl */ public: void* GetControl(); public: virtual SmartPointer GetLayoutTree(); /** * For themes. * * @return the current WorkbenchPage. */ public: virtual SmartPointer GetPage(); /** * Returns the composite used to parent all the * layout parts contained within. */ public: virtual void* GetParent(); protected: virtual bool IsChild(LayoutPart::Pointer part); /** * Returns whether this container is zoomed. */ // public: bool IsZoomed() { // return (zoomedPart != null); // } /* (non-Javadoc) * @see org.blueberry.ui.internal.LayoutPart#forceLayout(org.blueberry.ui.internal.LayoutPart) */ public: void ResizeChild(LayoutPart::Pointer childThatChanged); /** * Remove a part. */ public: void Remove(LayoutPart::Pointer child); /* (non-Javadoc) * @see org.blueberry.ui.internal.LayoutPart#forceLayout() */ public: void FlushLayout(); /** * Replace one part with another. */ public: void Replace(LayoutPart::Pointer oldChild, LayoutPart::Pointer newChild); private: void ResizeSashes(); /** * Returns the maximum size that can be utilized by this part if the given width and * height are available. Parts can overload this if they have a quantized set of preferred * sizes. * * @param width available horizontal space (pixels) * @return returns a new point where point.x is <= availableWidth and point.y is <= availableHeight */ public: virtual int ComputePreferredSize(bool width, int availableParallel, int availablePerpendicular, int preferredParallel); public: int GetSizeFlags(bool width); /** * @see LayoutPart#setBounds */ public: void SetBounds(const Rectangle& r); /** * Zoom in on a particular layout part. * * The implementation of zoom is quite simple. When zoom occurs we create * a zoom root which only contains the zoom part. We store the old * root in unzoomRoot and then active the zoom root. When unzoom occurs * we restore the unzoomRoot and dispose the zoom root. * * Note: Method assumes we are active. */ // private: void zoomIn(LayoutPart part) { // // Sanity check. // if (isZoomed()) { // return; // } // // // Hide the sashes // root.disposeSashes(); // // // Make all parts invisible except for the zoomed part // LayoutPart[] children = getChildren(); // for (int i = 0; i < children.length; i++) { // LayoutPart child = children[i]; // child.setVisible(child == part); // } // // zoomedPart = part; // // // Notify the part that it has been zoomed // part.setZoomed(true); // // // Remember that we need to trigger a layout // layoutDirty = true; // } /** * Returns the currently zoomed part or null if none * * @return the currently zoomed part or null if none * @since 3.1 */ // public: LayoutPart getZoomedPart() { // return zoomedPart; // } // public: void childRequestZoomIn(LayoutPart toZoom) { // if (!SwtUtil.isDisposed(this.parent)) { // this.parent.setRedraw(false); // } // try { // zoomIn(toZoom); // // requestZoomIn(); // // if (layoutDirty) { // resizeSashes(); // } // } finally { // if (!SwtUtil.isDisposed(this.parent)) { // this.parent.setRedraw(true); // } // } // } // public: void childRequestZoomOut() { // if (!SwtUtil.isDisposed(this.parent)) { // this.parent.setRedraw(false); // } // try { // zoomOut(); // // requestZoomOut(); // // if (layoutDirty) { // resizeSashes(); // } // } finally { // if (!SwtUtil.isDisposed(this.parent)) { // this.parent.setRedraw(true); // } // } // } /* (non-Javadoc) * @see org.blueberry.ui.internal.LayoutPart#setZoomed(boolean) */ // public: void setZoomed(boolean isZoomed) { // if (!isZoomed) { // zoomOut(); // } else { // if (!isZoomed()) { // LayoutPart toZoom = pickPartToZoom(); // // if (toZoom != null) { // zoomIn(toZoom); // } // } // } // super.setZoomed(isZoomed); // } // public: LayoutPart pickPartToZoom() { // return findBottomRight(); // } /** * Zoom out. * * See zoomIn for implementation details. * * Note: Method assumes we are active. */ // private: void zoomOut() { // // Sanity check. // if (!isZoomed()) { // return; // } // // LayoutPart zoomedPart = this.zoomedPart; // this.zoomedPart = null; // // Inform the part that it is no longer zoomed // zoomedPart.setZoomed(false); // // // Make all children visible // LayoutPart[] children = getChildren(); // for (int i = 0; i < children.length; i++) { // LayoutPart child = children[i]; // // child.setVisible(true); // } // // // Recreate the sashes // root.createControl(getParent()); // // // Ensure that the part being un-zoomed will have its size refreshed. // LayoutTree node = root.find(zoomedPart); // node.flushCache(); // // layoutDirty = true; // } /* (non-Javadoc) * @see org.blueberry.ui.internal.dnd.IDragOverListener#drag(org.blueberry.swt.widgets.Control, java.lang.Object, org.blueberry.swt.graphics.Point, org.blueberry.swt.graphics.Rectangle) */ public: IDropTarget::Pointer Drag(void* currentControl, Object::Pointer draggedObject, const Point& position, const Rectangle& dragRectangle); /** * @param sourcePart * @param targetPart * @param side * @param cursor * @return * @since 3.1 */ private: SashContainerDropTarget::Pointer CreateDropTarget(Object::Pointer sourcePart, int side, int cursor, Object::Pointer targetPart); /** * Returns true iff this PartSashContainer allows its parts to be stacked onto the given * container. * * @param container * @return */ public: - virtual bool IsStackType(IStackableContainer::Pointer toTest) = 0; + virtual bool IsStackType(ILayoutContainer::Pointer toTest) = 0; public: - virtual bool IsPaneType(StackablePart::Pointer toTest) = 0; + virtual bool IsPaneType(LayoutPart::Pointer toTest) = 0; protected: virtual SmartPointer CreateStack() = 0; public: - virtual void Stack(StackablePart::Pointer newPart, SmartPointer container); + virtual void Stack(LayoutPart::Pointer newPart, SmartPointer container); /** * @param container * @param visiblePart */ protected: - virtual void SetVisiblePart(IStackableContainer::Pointer container, + virtual void SetVisiblePart(ILayoutContainer::Pointer container, SmartPointer visiblePart) = 0; /** * @param container * @return */ protected: - virtual StackablePart::Pointer GetVisiblePart( - IStackableContainer::Pointer container) = 0; + virtual LayoutPart::Pointer GetVisiblePart( + ILayoutContainer::Pointer container) = 0; /** * @param sourcePart */ protected: - virtual void DerefPart(StackablePart::Pointer sourcePart); + virtual void DerefPart(LayoutPart::Pointer sourcePart); protected: - virtual std::size_t GetVisibleChildrenCount(IStackableContainer::Pointer container); virtual std::size_t GetVisibleChildrenCount(ILayoutContainer::Pointer container); protected: virtual float - GetDockingRatio(Object::Pointer dragged, IStackableContainer::Pointer target); + GetDockingRatio(Object::Pointer dragged, ILayoutContainer::Pointer target); /** * Writes a description of the layout to the given string buffer. * This is used for drag-drop test suites to determine if two layouts are the * same. Like a hash code, the description should compare as equal iff the * layouts are the same. However, it should be user-readable in order to * help debug failed tests. Although these are english readable strings, * they should not be translated or equality tests will fail. * * @param buf */ public: void DescribeLayout(std::string& buf) const; /** * Adds a new child to the container relative to some part * * @param child * @param relationship * @param left preferred pixel size of the left/top child * @param right preferred pixel size of the right/bottom child * @param relative relative part */ protected: virtual void Add(LayoutPart::Pointer child, int relationship, int left, int right, LayoutPart::Pointer relative); /* (non-Javadoc) * @see org.blueberry.ui.internal.ILayoutContainer#isZoomed(org.blueberry.ui.internal.LayoutPart) */ // public: bool childIsZoomed(LayoutPart toTest) { // return toTest == getZoomedPart(); // } /* (non-Javadoc) * @see org.blueberry.ui.internal.ILayoutContainer#allowsAutoFocus() */ public: bool AllowsAutoFocus(); /* (non-Javadoc) * @see org.blueberry.ui.internal.LayoutPart#startDeferringEvents() */ protected: void StartDeferringEvents(); /* (non-Javadoc) * @see org.blueberry.ui.internal.LayoutPart#handleDeferredEvents() */ protected: void HandleDeferredEvents(); /* (non-Javadoc) * @see org.blueberry.ui.internal.LayoutPart#testInvariants() */ public: void TestInvariants(); }; } #endif /*BERRYPARTSASHCONTAINER_H_*/ diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartStack.cpp b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartStack.cpp index 79682ce230..672cfca4ea 100644 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartStack.cpp +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartStack.cpp @@ -1,1607 +1,1610 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "berryPartStack.h" #include "berryPerspective.h" #include "berryPresentationFactoryUtil.h" #include "berryWorkbenchPlugin.h" #include "berryPresentationSerializer.h" #include "berryDragUtil.h" #include "berryEditorAreaHelper.h" #include "berryPerspectiveHelper.h" #include "berryWorkbenchConstants.h" #include "berryXMLMemento.h" #include "berryIWorkbenchPartConstants.h" #include "berryGeometry.h" #include "tweaklets/berryGuiWidgetsTweaklet.h" #include #include namespace berry { const int PartStack::PROP_SELECTION = 0x42; PartStack::PartStackDropResult::Pointer PartStack::dropResult( new PartStack::PartStackDropResult()); void PartStack::PartStackDropResult::SetTarget(PartStack::Pointer stack, PartPane::Pointer pane, StackDropResult::Pointer result) { this->pane = pane; this->dropResult = result; this->stack = stack; } void PartStack::PartStackDropResult::Drop() { // If we're dragging a pane over itself do nothing //if (dropResult.getInsertionPoint() == pane.getPresentablePart()) { return; }; Object::Pointer cookie; if (dropResult != 0) { cookie = dropResult->GetCookie(); } PartPane::Pointer pane(this->pane); PartStack::Pointer stack(this->stack); // Handle cross window drops by opening a new editor if (pane->GetPartReference().Cast () != 0) { IEditorReference::Pointer editorRef = pane->GetPartReference().Cast< IEditorReference> (); if (pane->GetWorkbenchWindow() != stack->GetWorkbenchWindow()) { try { IEditorInput::Pointer input = editorRef->GetEditorInput(); // Close the old editor and capture the actual closed state incase of a 'cancel' bool editorClosed = pane->GetPage()->CloseEditor(editorRef, true); // Only open open the new editor if the old one closed if (editorClosed) stack->GetPage()->OpenEditor(input, editorRef->GetId()); return; } catch (PartInitException& e) { //e.printStackTrace(); BERRY_ERROR << e.displayText(); } } } if (pane->GetContainer() != stack) { // Moving from another stack stack->DerefPart(pane); pane->Reparent(stack->GetParent()); stack->Add(pane, cookie); stack->SetSelection(pane); pane->SetFocus(); } else if (cookie != 0) { // Rearranging within this stack stack->GetPresentation()->MovePart(stack->GetPresentablePart(pane), cookie); } } DnDTweaklet::CursorType PartStack::PartStackDropResult::GetCursor() { return DnDTweaklet::CURSOR_CENTER; } Rectangle PartStack::PartStackDropResult::GetSnapRectangle() { if (dropResult == 0) { return DragUtil::GetDisplayBounds(stack.Lock()->GetControl()); } return dropResult->GetSnapRectangle(); } PartStack::MyStackPresentationSite::MyStackPresentationSite(PartStack* stack) : partStack(stack) { } void PartStack::MyStackPresentationSite::Close(IPresentablePart::Pointer part) { partStack->Close(part); } void PartStack::MyStackPresentationSite::Close(const std::vector< IPresentablePart::Pointer>& parts) { partStack->Close(parts); } void PartStack::MyStackPresentationSite::DragStart( IPresentablePart::Pointer beingDragged, Point& initialLocation, bool keyboard) { partStack->DragStart(beingDragged, initialLocation, keyboard); } void PartStack::MyStackPresentationSite::DragStart(Point& initialLocation, bool keyboard) { partStack->DragStart(IPresentablePart::Pointer(0), initialLocation, keyboard); } bool PartStack::MyStackPresentationSite::IsPartMoveable( IPresentablePart::Pointer part) { return partStack->IsMoveable(part); } void PartStack::MyStackPresentationSite::SelectPart( IPresentablePart::Pointer toSelect) { partStack->PresentationSelectionChanged(toSelect); } bool PartStack::MyStackPresentationSite::SupportsState(int state) { return partStack->SupportsState(state); } void PartStack::MyStackPresentationSite::SetState(int newState) { partStack->SetState(newState); } IPresentablePart::Pointer PartStack::MyStackPresentationSite::GetSelectedPart() { return partStack->GetSelectedPart(); } // void AddSystemActions(IMenuManager menuManager) { // PartStack.this.addSystemActions(menuManager); // } bool PartStack::MyStackPresentationSite::IsStackMoveable() { return partStack->CanMoveFolder(); } void PartStack::MyStackPresentationSite::FlushLayout() { partStack->FlushLayout(); } PartStack::PresentableVector PartStack::MyStackPresentationSite::GetPartList() { return partStack->GetPresentableParts(); } std::string PartStack::MyStackPresentationSite::GetProperty( const std::string& id) { return partStack->GetProperty(id); } PartStack::PartStack(WorkbenchPage* p, bool allowsStateChanges, int appear, IPresentationFactory* fac) : LayoutPart("PartStack"), page(p), isActive(true), allowStateChanges( allowsStateChanges), appearance(appear), ignoreSelectionChanges(false), factory(fac) { std::stringstream buf; buf << "PartStack@" << this; this->SetID(buf.str()); presentationSite = new MyStackPresentationSite(this); } bool PartStack::IsMoveable(IPresentablePart::Pointer part) { PartPane::Pointer pane = this->GetPaneFor(part); Perspective::Pointer perspective = this->GetPage()->GetActivePerspective(); if (perspective == 0) { // Shouldn't happen -- can't have a ViewStack without a // perspective return true; } IWorkbenchPartReference::Pointer partRef = pane->GetPartReference(); if (partRef.Cast () != 0) return perspective->IsMoveable(partRef.Cast ()); return true; } bool PartStack::SupportsState(int /*newState*/) { if (page->IsFixedLayout()) { return false; } return allowStateChanges; } bool PartStack::CanMoveFolder() { if (appearance == PresentationFactoryUtil::ROLE_EDITOR) return true; Perspective::Pointer perspective = this->GetPage()->GetActivePerspective(); if (perspective == 0) { // Shouldn't happen -- can't have a ViewStack without a // perspective return false; } // We need to search if one of the presentations is not moveable // if that's the case the whole folder should not be moveable IStackPresentationSite::Pointer presenationSite; if ((presenationSite = this->GetPresentationSite()) != 0) { std::list parts = presenationSite->GetPartList(); for (std::list::iterator iter = parts.begin(); iter != parts.end(); ++iter) { if (!presenationSite->IsPartMoveable(*iter)) { return false; } } } return !perspective->IsFixedLayout(); } -void PartStack::DerefPart(StackablePart::Pointer toDeref) +void PartStack::DerefPart(LayoutPart::Pointer toDeref) { if (appearance == PresentationFactoryUtil::ROLE_EDITOR) EditorAreaHelper::DerefPart(toDeref); else this->GetPage()->GetActivePerspective()->GetPresentation()->DerefPart( toDeref); } bool PartStack::AllowsDrop(PartPane::Pointer part) { PartStack::Pointer stack = part->GetContainer().Cast (); if (stack != 0) { if (stack->appearance == this->appearance) return true; } return false; } void PartStack::AddListener(IPropertyChangeListener::Pointer listener) { propEvents.AddListener(listener); } void PartStack::RemoveListener(IPropertyChangeListener::Pointer listener) { propEvents.RemoveListener(listener); } int PartStack::GetAppearance() const { return appearance; } std::string PartStack::GetID() const { return LayoutPart::GetID(); } bool PartStack::IsStandalone() { return (appearance == PresentationFactoryUtil::ROLE_STANDALONE || appearance == PresentationFactoryUtil::ROLE_STANDALONE_NOTITLE); } IPresentablePart::Pointer PartStack::GetSelectedPart() { return presentationCurrent.Cast (); } IStackPresentationSite::Pointer PartStack::GetPresentationSite() { return presentationSite; } void PartStack::TestInvariants() { void* focusControl = Tweaklets::Get(GuiWidgetsTweaklet::KEY)->GetFocusControl(); bool currentFound = false; ChildVector children = this->GetChildren(); for (ChildVector::iterator iter = children.begin(); iter != children.end(); ++iter) { - StackablePart::Pointer child = *iter; + LayoutPart::Pointer child = *iter; // No 0 children allowed poco_assert(child != 0) ; // "0 children are not allowed in PartStack" // Ensure that all the PartPanes have an associated presentable part IPresentablePart::Pointer part = this->GetPresentablePart(child); if (!child->IsPlaceHolder()) { poco_assert(part != 0); // "All PartPanes must have a non-0 IPresentablePart" } // Ensure that the child's backpointer points to this stack - IStackableContainer::Pointer childContainer = child->GetContainer(); + ILayoutContainer::Pointer childContainer = child->GetContainer(); // Disable tests for placeholders -- PartPlaceholder backpointers don't // obey the usual rules -- they sometimes point to a container placeholder // for this stack instead of the real stack. if (!child->IsPlaceHolder()) { // If the widgetry exists, the child's backpointer must point to us poco_assert(childContainer.GetPointer() == this); // "PartStack has a child that thinks it has a different parent" // If this child has focus, then ensure that it is selected and that we have // the active appearance. if (focusControl && Tweaklets::Get(GuiWidgetsTweaklet::KEY)->IsChild(child->GetControl(), focusControl)) { poco_assert(child == current); // "The part with focus is not the selected part" // focus check commented out since it fails when focus workaround in LayoutPart.setVisible is not present // Assert.isTrue(getActive() == StackPresentation.AS_ACTIVE_FOCUS); } } // Ensure that "current" points to a valid child if (child == current) { currentFound = true; } // Test the child's internal state child->TestInvariants(); } // If we have at least one child, ensure that the "current" pointer points to one of them if (this->GetPresentableParts().size()> 0) { poco_assert(currentFound); StackPresentation::Pointer presentation = this->GetPresentation(); // If the presentation controls have focus, ensure that we have the active appearance if (focusControl && Tweaklets::Get(GuiWidgetsTweaklet::KEY)->IsChild(presentation->GetControl(), focusControl)) { poco_assert(this->GetActive() == StackPresentation::AS_ACTIVE_FOCUS); // "The presentation has focus but does not have the active appearance" } } // Check to that we're displaying the zoomed icon iff we're actually maximized //poco_assert((this->GetState() == IStackPresentationSite::STATE_MAXIMIZED) // == (this->GetContainer() != 0 && this->GetContainer()->ChildIsZoomed(this))); } void PartStack::DescribeLayout(std::string& buf) const { int activeState = this->GetActive(); if (activeState == StackPresentation::AS_ACTIVE_FOCUS) { buf.append("active "); //$NON-NLS-1$ } else if (activeState == StackPresentation::AS_ACTIVE_NOFOCUS) { buf.append("active_nofocus "); //$NON-NLS-1$ } buf.append("("); //$NON-NLS-1$ ChildVector children = this->GetChildren(); int visibleChildren = 0; for (ChildVector::iterator iter = children.begin(); iter != children.end(); ++iter) { - StackablePart::Pointer next = *iter; + LayoutPart::Pointer next = *iter; if (!next->IsPlaceHolder()) { if (iter != children.begin()) { buf.append(", "); //$NON-NLS-1$ } if (next == requestedCurrent) { buf.append("*"); //$NON-NLS-1$ } next->DescribeLayout(buf); visibleChildren++; } } buf.append(")"); //$NON-NLS-1$ } -void PartStack::Add(StackablePart::Pointer child) +void PartStack::Add(LayoutPart::Pointer child) { this->Add(child, Object::Pointer(0)); } -void PartStack::Add(StackablePart::Pointer newChild, Object::Pointer cookie) +void PartStack::Add(LayoutPart::Pointer newChild, Object::Pointer cookie) { children.push_back(newChild); // Fix for bug 78470: if(newChild->GetContainer().Cast() == 0) { - newChild->SetContainer(IStackableContainer::Pointer(this)); + newChild->SetContainer(ILayoutContainer::Pointer(this)); } this->ShowPart(newChild, cookie); } -bool PartStack::AllowsAdd(StackablePart::Pointer /*toAdd*/) +bool PartStack::AllowsAdd(LayoutPart::Pointer /*toAdd*/) { return !this->IsStandalone(); } bool PartStack::AllowsAutoFocus() { if (presentationSite->GetState() == IStackPresentationSite::STATE_MINIMIZED) { return false; } return LayoutPart::AllowsAutoFocus(); } void PartStack::Close(const std::vector& parts) { for (unsigned int idx = 0; idx < parts.size(); idx++) { IPresentablePart::Pointer part = parts[idx]; this->Close(part); } } void PartStack::Close(IPresentablePart::Pointer part) { if (!presentationSite->IsCloseable(part)) { return; } PartPane::Pointer pane = this->GetPaneFor(part); if (pane != 0) { pane->DoHide(); } } IPresentationFactory* PartStack::GetFactory() { if (factory != 0) { return factory; } return WorkbenchPlugin::GetDefault()->GetPresentationFactory(); } void PartStack::CreateControl(void* parent) { if (this->GetPresentation() != 0) { return; } IPresentationFactory* factory = this->GetFactory(); PresentableVector partList = this->GetPresentableParts(); std::vector partVec(partList.begin(), partList.end()); PresentationSerializer serializer(partVec); StackPresentation::Pointer presentation = PresentationFactoryUtil ::CreatePresentation(factory, appearance, parent, presentationSite, &serializer, savedPresentationState); this->CreateControl(parent, presentation); Tweaklets::Get(GuiWidgetsTweaklet::KEY)->MoveBelow(this->GetControl(), 0); } IDropTarget::Pointer PartStack::GetDropTarget(Object::Pointer draggedObject, const Point& position) { if (draggedObject.Cast() == 0) { return IDropTarget::Pointer(0); } PartPane::Pointer pane = draggedObject.Cast(); if (this->IsStandalone() || !this->AllowsDrop(pane)) { return IDropTarget::Pointer(0); } // Don't allow views to be dragged between windows bool differentWindows = pane->GetWorkbenchWindow() != this->GetWorkbenchWindow(); bool editorDropOK = ((pane->GetPartReference().Cast() != 0) && pane->GetWorkbenchWindow()->GetWorkbench() == this->GetWorkbenchWindow()->GetWorkbench()); if (differentWindows && !editorDropOK) { return IDropTarget::Pointer(0); } StackDropResult::Pointer dropResult = this->GetPresentation()->DragOver( this->GetControl(), position); if (dropResult == 0) { return IDropTarget::Pointer(0); } return this->CreateDropTarget(pane, dropResult); } void PartStack::SetBounds(const Rectangle& r) { if (this->GetPresentation() != 0) { this->GetPresentation()->SetBounds(r); } } IDropTarget::Pointer PartStack::CreateDropTarget(PartPane::Pointer pane, StackDropResult::Pointer result) { dropResult->SetTarget(PartStack::Pointer(this), pane, result); return dropResult; } void PartStack::SetActive(bool isActive) { this->isActive = isActive; // Add all visible children to the presentation for(ChildVector::iterator iter = children.begin(); iter != children.end(); ++iter) { - (*iter)->SetContainer(isActive ? IStackableContainer::Pointer(this) : IStackableContainer::Pointer(0)); + (*iter)->SetContainer(isActive ? ILayoutContainer::Pointer(this) : ILayoutContainer::Pointer(0)); } for (PresentableVector::iterator iter = presentableParts.begin(); iter != presentableParts.end(); ++iter) { PresentablePart::Pointer next = iter->Cast(); next->EnableInputs(isActive); next->EnableOutputs(isActive); } } void PartStack::CreateControl(void* /*parent*/, StackPresentation::Pointer presentation) { poco_assert(this->GetPresentation() == 0); if (presentationSite->GetPresentation() != 0) { return; } presentationSite->SetPresentation(presentation); // Add all visible children to the presentation // Use a copy of the current set of children to avoid a ConcurrentModificationException // if a part is added to the same stack while iterating over the children (bug 78470) ChildVector childParts(children); for (ChildVector::iterator iter = childParts.begin(); iter != childParts.end(); ++iter) { this->ShowPart(*iter, Object::Pointer(0)); } if (savedPresentationState != 0) { PresentableVector partList = this->GetPresentableParts(); std::vector partVec(partList.begin(), partList.end()); PresentationSerializer serializer(partVec); presentation->RestoreState(&serializer, savedPresentationState); } //void* ctrl = this->GetPresentation()->GetControl(); //TODO control setData ? //ctrl.setData(this); // We should not have a placeholder selected once we've created the widgetry if (requestedCurrent != 0 && requestedCurrent->IsPlaceHolder()) { requestedCurrent = 0; this->UpdateContainerVisibleTab(); } this->RefreshPresentationSelection(); } void PartStack::SavePresentationState() { if (this->GetPresentation() == 0) { return; } {// Save the presentation's state before disposing it XMLMemento::Pointer memento = XMLMemento ::CreateWriteRoot(WorkbenchConstants::TAG_PRESENTATION); memento->PutString(WorkbenchConstants::TAG_ID, this->GetFactory()->GetId()); std::list parts(this->GetPresentableParts()); PresentationSerializer serializer(std::vector(parts.begin(), parts.end())); this->GetPresentation()->SaveState(&serializer, memento); // Store the memento in savedPresentationState savedPresentationState = memento; } } PartStack::~PartStack() { //BERRY_INFO << "DELETING PARTSTACK"; } void PartStack::Dispose() { if (this->GetPresentation() == 0) { return; } this->SavePresentationState(); // for (PresentableVector::iterator iter = presentableParts.begin(); // iter != presentableParts.end(); ++iter) // { // iter->Cast()->Dispose(); // } presentableParts.clear(); presentationCurrent = 0; current = 0; this->FireInternalPropertyChange(PROP_SELECTION); } -void PartStack::FindSashes(PartPane::Sashes& sashes) +void PartStack::FindSashes(LayoutPart::Pointer /*toFind*/, PartPane::Sashes& sashes) { ILayoutContainer::Pointer container = this->GetContainer(); if (container != 0) { container->FindSashes(LayoutPart::Pointer(this), sashes); } } Rectangle PartStack::GetBounds() { if (this->GetPresentation() == 0) { return Rectangle(0, 0, 0, 0); } return Tweaklets::Get(GuiWidgetsTweaklet::KEY)->GetBounds(this->GetPresentation()->GetControl()); } -std::list PartStack::GetChildren() const +std::list PartStack::GetChildren() const { return children; } void* PartStack::GetControl() { StackPresentation::Pointer presentation = this->GetPresentation(); if (presentation == 0) { return 0; } return presentation->GetControl(); } /** * Answer the number of children. */ PartStack::ChildVector::size_type PartStack::GetItemCount() { if (this->GetPresentation() == 0) { return children.size(); } return this->GetPresentableParts().size(); } PartPane::Pointer PartStack::GetPaneFor(IPresentablePart::Pointer part) { if (part == 0 || part.Cast() == 0) { return PartPane::Pointer(0); } return part.Cast()->GetPane(); } void* PartStack::GetParent() { return Tweaklets::Get(GuiWidgetsTweaklet::KEY)->GetParent(this->GetControl()); } PartStack::PresentableVector PartStack::GetPresentableParts() { return presentableParts; } -PresentablePart::Pointer PartStack::GetPresentablePart(StackablePart::Pointer pane) +PresentablePart::Pointer PartStack::GetPresentablePart(LayoutPart::Pointer pane) { for (PresentableVector::iterator iter = presentableParts.begin(); iter != presentableParts.end(); ++iter) { PresentablePart::Pointer part = iter->Cast(); if (part->GetPane() == pane) { return part; } } return PresentablePart::Pointer(0); } StackPresentation::Pointer PartStack::GetPresentation() { return presentationSite->GetPresentation(); } -StackablePart::Pointer PartStack::GetSelection() +PartPane::Pointer PartStack::GetSelection() { - return current; + if (PartPane::Pointer partPane = current.Cast()) + { + return partPane; + } + return PartPane::Pointer(0); } void PartStack::PresentationSelectionChanged(IPresentablePart::Pointer newSelection) { // Ignore selection changes that occur as a result of removing a part if (ignoreSelectionChanges) { return; } PartPane::Pointer newPart = this->GetPaneFor(newSelection); // This method should only be called on objects that are already in the layout poco_assert(newPart != 0); if (newPart == requestedCurrent) { return; } this->SetSelection(newPart); if (newPart != 0) { newPart->SetFocus(); } } -void PartStack::Remove(StackablePart::Pointer child) +void PartStack::Remove(LayoutPart::Pointer child) { IPresentablePart::Pointer presentablePart = this->GetPresentablePart(child); // Need to remove it from the list of children before notifying the presentation // since it may setVisible(false) on the part, leading to a partHidden notification, // during which findView must not find the view being removed. See bug 60039. children.remove(child); StackPresentation::Pointer presentation = this->GetPresentation(); if (presentablePart != 0 && presentation != 0) { ignoreSelectionChanges = true; presentableParts.remove(presentablePart); presentation->RemovePart(presentablePart); presentablePart = 0; ignoreSelectionChanges = false; } if (this->GetPresentation() != 0) { - child->SetContainer(IStackableContainer::Pointer(0)); + child->SetContainer(ILayoutContainer::Pointer(0)); } if (child == requestedCurrent) { this->UpdateContainerVisibleTab(); } } void PartStack::Reparent(void* newParent) { void* control = this->GetControl(); GuiWidgetsTweaklet* tweaklet = Tweaklets::Get(GuiWidgetsTweaklet::KEY); if ((control == 0) || (tweaklet->GetParent(control) == newParent) || !tweaklet->IsReparentable(control)) { return; } LayoutPart::Reparent(newParent); for(ChildVector::iterator iter = children.begin(); iter != children.end(); ++iter) { (*iter)->Reparent(newParent); } } -void PartStack::Replace(StackablePart::Pointer oldChild, StackablePart::Pointer newChild) +void PartStack::Replace(LayoutPart::Pointer oldChild, LayoutPart::Pointer newChild) { ChildVector::iterator loc = std::find(children.begin(), children.end(), oldChild); int idx = 0; int numPlaceholders = 0; //subtract the number of placeholders still existing in the list //before this one - they wont have parts. for (ChildVector::iterator iter = children.begin(); iter != loc; ++iter, ++idx) { if ((*iter)->IsPlaceHolder()) { numPlaceholders++; } } ObjectInt::Pointer cookie(new ObjectInt(idx - numPlaceholders)); children.insert(loc, newChild); this->ShowPart(newChild, cookie); if (oldChild == requestedCurrent && newChild.Cast() != 0) { this->SetSelection(newChild.Cast()); } this->Remove(oldChild); } int PartStack::ComputePreferredSize(bool width, int availableParallel, int availablePerpendicular, int preferredParallel) { return this->GetPresentation()->ComputePreferredSize(width, availableParallel, availablePerpendicular, preferredParallel); } int PartStack::GetSizeFlags(bool horizontal) { StackPresentation::Pointer presentation = this->GetPresentation(); if (presentation != 0) { return presentation->GetSizeFlags(horizontal); } return 0; } bool PartStack::RestoreState(IMemento::Pointer memento) { // Read the active tab. std::string activeTabID; memento->GetString(WorkbenchConstants::TAG_ACTIVE_PAGE_ID, activeTabID); // Read the page elements. std::vector children = memento->GetChildren(WorkbenchConstants::TAG_PAGE); // Loop through the page elements. for (std::size_t i = 0; i < children.size(); i++) { // Get the info details. IMemento::Pointer childMem = children[i]; std::string partID; childMem->GetString(WorkbenchConstants::TAG_CONTENT, partID); // Create the part. - StackablePart::Pointer part(new PartPlaceholder(partID)); - part->SetContainer(IStackableContainer::Pointer(this)); + LayoutPart::Pointer part(new PartPlaceholder(partID)); + part->SetContainer(ILayoutContainer::Pointer(this)); this->Add(part); //1FUN70C: ITPUI:WIN - Shouldn't set Container when not active //part.setContainer(this); if (partID == activeTabID) { this->SetSelection(part); // Mark this as the active part. //current = part; } } //IPreferenceStore preferenceStore = PrefUtil.getAPIPreferenceStore(); //boolean useNewMinMax = preferenceStore.getBoolean(IWorkbenchPreferenceConstants.ENABLE_NEW_MIN_MAX); int expanded; if (memento->GetInteger(WorkbenchConstants::TAG_EXPANDED, expanded)) { //StartupThreading.runWithoutExceptions(new StartupRunnable() // { // void runWithException() throws Throwable // { SetState(expanded != IStackPresentationSite::STATE_MINIMIZED ? IStackPresentationSite::STATE_RESTORED : IStackPresentationSite::STATE_MINIMIZED); // } // }); } else { SetState(IStackPresentationSite::STATE_RESTORED); } int appearance; if (memento->GetInteger(WorkbenchConstants::TAG_APPEARANCE, appearance)) { this->appearance = appearance; } // Determine if the presentation has saved any info here savedPresentationState = 0; std::vector presentationMementos(memento ->GetChildren(WorkbenchConstants::TAG_PRESENTATION)); for (std::size_t idx = 0; idx < presentationMementos.size(); idx++) { IMemento::Pointer child = presentationMementos[idx]; std::string id; child->GetString(WorkbenchConstants::TAG_ID, id); if (id == GetFactory()->GetId()) { savedPresentationState = child; break; } } IMemento::Pointer propertiesState = memento->GetChild(WorkbenchConstants::TAG_PROPERTIES); if (propertiesState) { std::vector props(propertiesState->GetChildren(WorkbenchConstants::TAG_PROPERTY)); for (std::size_t i = 0; i < props.size(); i++) { std::string id = props[i]->GetID(); properties.insert(std::make_pair(id, props[i]->GetTextData())); } } //return new Status(IStatus.OK, PlatformUI.PLUGIN_ID, 0, "", 0); //$NON-NLS-1$ return true; } void PartStack::SetVisible(bool makeVisible) { void* ctrl = this->GetControl(); bool useShortcut = makeVisible || !isActive; if (ctrl != 0 && useShortcut) { if (makeVisible == Tweaklets::Get(GuiWidgetsTweaklet::KEY)->GetVisible(ctrl)) { return; } } if (makeVisible) { for (PresentableVector::iterator iter = presentableParts.begin(); iter != presentableParts.end(); ++iter) { PresentablePart::Pointer next = iter->Cast(); next->EnableInputs(isActive); next->EnableOutputs(isActive); } } LayoutPart::SetVisible(makeVisible); StackPresentation::Pointer presentation = this->GetPresentation(); if (presentation != 0) { presentation->SetVisible(makeVisible); } if (!makeVisible) { for (PresentableVector::iterator iter = presentableParts.begin(); iter != presentableParts.end(); ++iter) { PresentablePart::Pointer next = iter->Cast(); next->EnableInputs(false); } } } bool PartStack::SaveState(IMemento::Pointer memento) { if (GetAppearance() != PresentationFactoryUtil::ROLE_EDITOR) { // Save the active tab. if (requestedCurrent) { - memento->PutString(WorkbenchConstants::TAG_ACTIVE_PAGE_ID, requestedCurrent - ->GetCompoundId()); + memento->PutString(WorkbenchConstants::TAG_ACTIVE_PAGE_ID, requestedCurrent->GetID()); } // Write out the presentable parts (in order) Poco::HashSet cachedIds; PartStack::PresentableVector pparts(GetPresentableParts()); for (PartStack::PresentableVector::iterator ppIter = pparts.begin(); ppIter != pparts.end(); ++ppIter) { PresentablePart::Pointer presPart = ppIter->Cast(); IMemento::Pointer childMem = memento->CreateChild(WorkbenchConstants::TAG_PAGE); PartPane::Pointer part = presPart->GetPane(); std::string tabText = part->GetPartReference()->GetPartName(); childMem->PutString(WorkbenchConstants::TAG_LABEL, tabText); childMem->PutString(WorkbenchConstants::TAG_CONTENT, presPart->GetPane()->GetPlaceHolderId()); // Cache the id so we don't write it out later cachedIds.insert(presPart->GetPane()->GetPlaceHolderId()); } for (ChildVector::iterator iter = children.begin(); iter != children.end(); ++iter) { - StackablePart::Pointer next = *iter; + LayoutPart::Pointer next = *iter; PartPane::Pointer part; if (part = next.Cast()) { // Have we already written it out? if (cachedIds.find(part->GetPlaceHolderId()) != cachedIds.end()) continue; } IMemento::Pointer childMem = memento ->CreateChild(WorkbenchConstants::TAG_PAGE); std::string tabText = "LabelNotFound"; if (part) { tabText = part->GetPartReference()->GetPartName(); } childMem->PutString(WorkbenchConstants::TAG_LABEL, tabText); - childMem->PutString(WorkbenchConstants::TAG_CONTENT, next->GetId()); + childMem->PutString(WorkbenchConstants::TAG_CONTENT, next->GetID()); } } // IPreferenceStore preferenceStore = PrefUtil.getAPIPreferenceStore(); // boolean useNewMinMax = preferenceStore.getBoolean(IWorkbenchPreferenceConstants.ENABLE_NEW_MIN_MAX); // if (useNewMinMax) // { memento->PutInteger(WorkbenchConstants::TAG_EXPANDED, presentationSite->GetState()); // } // else // { // memento // .putInteger( // IWorkbenchConstants.TAG_EXPANDED, // (presentationSite.getState() == IStackPresentationSite.STATE_MINIMIZED) ? IStackPresentationSite.STATE_MINIMIZED // : IStackPresentationSite.STATE_RESTORED); // } memento->PutInteger(WorkbenchConstants::TAG_APPEARANCE, appearance); this->SavePresentationState(); if (savedPresentationState) { IMemento::Pointer presentationState = memento ->CreateChild(WorkbenchConstants::TAG_PRESENTATION); presentationState->PutMemento(savedPresentationState); } if (!properties.empty()) { IMemento::Pointer propertiesState = memento->CreateChild(WorkbenchConstants::TAG_PROPERTIES); for (std::map::iterator iterator = properties.begin(); iterator != properties.end(); ++iterator) { if (iterator->second.empty()) continue; IMemento::Pointer prop = propertiesState->CreateChild(WorkbenchConstants::TAG_PROPERTY, iterator->first); prop->PutTextData(iterator->second); } } //return new Status(IStatus.OK, PlatformUI.PLUGIN_ID, 0, "", 0); return true; } WorkbenchPage::Pointer PartStack::GetPage() { // WorkbenchWindow::Pointer window = this->GetWorkbenchWindow().Cast(); // // if (window == 0) // { // return 0; // } // // return window->GetActivePage().Cast(); return WorkbenchPage::Pointer(page); } void PartStack::SetActive(int activeState) { // if (activeState == StackPresentation::AS_ACTIVE_FOCUS && isMinimized) // { // setMinimized(false); // } presentationSite->SetActive(activeState); } int PartStack::GetActive() const { return presentationSite->GetActive(); } -void PartStack::SetSelection(StackablePart::Pointer part) +void PartStack::SetSelection(LayoutPart::Pointer part) { if (part == requestedCurrent) { return; } requestedCurrent = part; this->RefreshPresentationSelection(); } void PartStack::UpdateActions(PresentablePart::Pointer /*current*/) { } void PartStack::HandleDeferredEvents() { LayoutPart::HandleDeferredEvents(); this->RefreshPresentationSelection(); } void PartStack::RefreshPresentationSelection() { // If deferring UI updates, exit. if (this->IsDeferred()) { return; } // If the presentation is already displaying the desired part, then there's nothing // to do. if (current == requestedCurrent) { return; } StackPresentation::Pointer presentation = this->GetPresentation(); if (presentation != 0) { presentationCurrent = this->GetPresentablePart(requestedCurrent); // this->UupdateActions(presentationCurrent); if (presentationCurrent != 0 && presentation != 0) { requestedCurrent->CreateControl(this->GetParent()); GuiWidgetsTweaklet* tweaklet = Tweaklets::Get(GuiWidgetsTweaklet::KEY); if (tweaklet->GetParent(requestedCurrent->GetControl()) != tweaklet->GetParent(this->GetControl())) { requestedCurrent->Reparent(tweaklet->GetParent(this->GetControl())); } presentation->SelectPart(presentationCurrent); } // Update the return value of getVisiblePart current = requestedCurrent; this->FireInternalPropertyChange(PROP_SELECTION); } } int PartStack::GetState() { return presentationSite->GetState(); } void PartStack::SetState(const int newState) { int oldState = presentationSite->GetState(); if (!this->SupportsState(newState) || newState == oldState) { return; } // WorkbenchWindow::Pointer wbw = this->GetPage()->GetWorkbenchWindow().Cast(); // if (wbw == 0 || wbw->GetShell() == 0 || wbw->GetActivePage() == 0) // return; // // WorkbenchPage::Pointer page = wbw->GetActivePage(); // // bool useNewMinMax = Perspective::UseNewMinMax(page->GetActivePerspective()); // // // we have to fiddle with the zoom behavior to satisfy Intro req's // // by usning the old zoom behavior for its stack // if (newState == IStackPresentationSite::STATE_MAXIMIZED) // useNewMinMax = useNewMinMax; // && !this->IsIntroInStack(); // else if (newState == IStackPresentationSite::STATE_RESTORED) // { // PartStack::Pointer maxStack = page->GetActivePerspective()->GetPresentation()->GetMaximizedStack(); // useNewMinMax = useNewMinMax && maxStack == this; // } // // if (useNewMinMax) // { // //StartupThreading.runWithoutExceptions(new StartupRunnable() // // { // // void runWithException() throws Throwable // // { // wbw->GetPageComposite()->SetRedraw(false); // try // { // if (newState == IStackPresentationSite::STATE_MAXIMIZED) // { // smartZoom(); // } // else if (oldState == IStackPresentationSite::STATE_MAXIMIZED) // { // smartUnzoom(); // } // // if (newState == IStackPresentationSite::STATE_MINIMIZED) // { // setMinimized(true); // } // // wbw.getPageComposite().setRedraw(true); // // // Force a redraw (fixes Mac refresh) // wbw.getShell().redraw(); // // } // catch (...) // { // wbw.getPageComposite().setRedraw(true); // // // Force a redraw (fixes Mac refresh) // wbw.getShell().redraw(); // } // // this->SetPresentationState(newState); // // } // // }); // } // else // { //// bool minimized = (newState == IStackPresentationSite::STATE_MINIMIZED); //// this->SetMinimized(minimized); //// //// if (newState == IStackPresentationSite::STATE_MAXIMIZED) //// { //// requestZoomIn(); //// } //// else if (oldState == IStackPresentationSite::STATE_MAXIMIZED) //// { //// requestZoomOut(); //// //// if (newState == IStackPresentationSite::STATE_MINIMIZED) //// setMinimized(true); //// } // } } -void PartStack::ShowPart(StackablePart::Pointer part, Object::Pointer cookie) +void PartStack::ShowPart(LayoutPart::Pointer part, Object::Pointer cookie) { if (this->GetPresentation() == 0) { return; } if (part->IsPlaceHolder()) { - part->SetContainer(IStackableContainer::Pointer(this)); + part->SetContainer(ILayoutContainer::Pointer(this)); return; } if (part.Cast() == 0) { - WorkbenchPlugin::Log("Incorrect part " + part->GetId() + "contained in a part stack"); + WorkbenchPlugin::Log("Incorrect part " + part->GetID() + "contained in a part stack"); return; } PartPane::Pointer pane = part.Cast(); PresentablePart::Pointer presentablePart(new PresentablePart(pane, Tweaklets::Get(GuiWidgetsTweaklet::KEY)->GetParent(this->GetControl()))); presentableParts.push_back(presentablePart); if (isActive) { - part->SetContainer(IStackableContainer::Pointer(this)); + part->SetContainer(ILayoutContainer::Pointer(this)); // The active part should always be enabled if (part->GetControl() != 0) Tweaklets::Get(GuiWidgetsTweaklet::KEY)->SetEnabled(part->GetControl(), true); } presentationSite->GetPresentation()->AddPart(presentablePart, cookie); if (requestedCurrent == 0) { this->SetSelection(pane); } // if (childObscuredByZoom(part)) // { // presentablePart.enableInputs(false); // } } void PartStack::UpdateContainerVisibleTab() { ChildVector parts = this->GetChildren(); if (parts.size() < 1) { - this->SetSelection(StackablePart::Pointer(0)); + this->SetSelection(LayoutPart::Pointer(0)); return; } PartPane::Pointer selPart; int topIndex = 0; WorkbenchPage::Pointer page = this->GetPage(); if (page != 0) { std::vector sortedParts = page->GetSortedParts(); for (ChildVector::iterator partIter = parts.begin(); partIter != parts.end(); ++partIter) { if (partIter->Cast() != 0) { IWorkbenchPartReference::Pointer part = partIter->Cast() ->GetPartReference(); int index = static_cast(std::find(sortedParts.begin(), sortedParts.end(), part) - sortedParts.begin()); if (index >= topIndex) { topIndex = index; selPart = partIter->Cast(); } } } } if (selPart == 0) { PresentableVector presentableParts = this->GetPresentableParts(); if (presentableParts.size() != 0) { IPresentablePart::Pointer part = presentableParts.front(); selPart = this->GetPaneFor(part); } } this->SetSelection(selPart); } void PartStack::ShowSystemMenu() { //this->GetPresentation()->ShowSystemMenu(); } void PartStack::ShowPaneMenu() { //this->GetPresentation()->ShowPaneMenu(); } void PartStack::ShowPartList() { this->GetPresentation()->ShowPartList(); } -std::vector PartStack::GetTabList(StackablePart::Pointer part) +std::vector PartStack::GetTabList(LayoutPart::Pointer part) { if (part != 0) { IPresentablePart::Pointer presentablePart = this->GetPresentablePart(part); StackPresentation::Pointer presentation = this->GetPresentation(); if (presentablePart != 0 && presentation != 0) { return presentation->GetTabList(presentablePart); } } return std::vector(); } void PartStack::DragStart(IPresentablePart::Pointer beingDragged, Point& initialLocation, bool keyboard) { if (beingDragged == 0) { this->PaneDragStart(PartPane::Pointer(0), initialLocation, keyboard); } else { if (presentationSite->IsPartMoveable(beingDragged)) { PartPane::Pointer pane = this->GetPaneFor(beingDragged); if (pane != 0) { this->PaneDragStart(pane, initialLocation, keyboard); } } } } void PartStack::PaneDragStart(PartPane::Pointer pane, Point& initialLocation, bool keyboard) { if (pane == 0) { if (this->CanMoveFolder()) { if (presentationSite->GetState() == IStackPresentationSite::STATE_MAXIMIZED) { // Calculate where the initial location was BEFORE the 'restore'...as a percentage Rectangle bounds = Geometry::ToDisplay(this->GetParent(), Tweaklets::Get(GuiWidgetsTweaklet::KEY)->GetBounds(this->GetPresentation()->GetControl())); float xpct = (initialLocation.x - bounds.x) / (float)(bounds.width); float ypct = (initialLocation.y - bounds.y) / (float)(bounds.height); // Only restore if we're dragging views/view stacks if (this->GetAppearance() != PresentationFactoryUtil::ROLE_EDITOR) this->SetState(IStackPresentationSite::STATE_RESTORED); // Now, adjust the initial location to be within the bounds of the restored rect bounds = Geometry::ToDisplay(this->GetParent(), Tweaklets::Get(GuiWidgetsTweaklet::KEY)->GetBounds(this->GetPresentation()->GetControl())); initialLocation.x = (int) (bounds.x + (xpct * bounds.width)); initialLocation.y = (int) (bounds.y + (ypct * bounds.height)); } DragUtil::PerformDrag(Object::Pointer(this), Geometry::ToDisplay(this->GetParent(), Tweaklets::Get(GuiWidgetsTweaklet::KEY)->GetBounds(this->GetPresentation()->GetControl())), initialLocation, !keyboard); } } else { if (presentationSite->GetState() == IStackPresentationSite::STATE_MAXIMIZED) { // Calculate where the initial location was BEFORE the 'restore'...as a percentage Rectangle bounds = Geometry::ToDisplay(this->GetParent(), Tweaklets::Get(GuiWidgetsTweaklet::KEY)->GetBounds(this->GetPresentation()->GetControl())); float xpct = (initialLocation.x - bounds.x) / (float)(bounds.width); float ypct = (initialLocation.y - bounds.y) / (float)(bounds.height); // Only restore if we're dragging views/view stacks if (this->GetAppearance() != PresentationFactoryUtil::ROLE_EDITOR) this->SetState(IStackPresentationSite::STATE_RESTORED); // Now, adjust the initial location to be within the bounds of the restored rect // See bug 100908 bounds = Geometry::ToDisplay(this->GetParent(), Tweaklets::Get(GuiWidgetsTweaklet::KEY)->GetBounds(this->GetPresentation()->GetControl())); initialLocation.x = (int) (bounds.x + (xpct * bounds.width)); initialLocation.y = (int) (bounds.y + (ypct * bounds.height)); } DragUtil::PerformDrag(pane, Geometry::ToDisplay(this->GetParent(), Tweaklets::Get(GuiWidgetsTweaklet::KEY)->GetBounds(this->GetPresentation()->GetControl())), initialLocation, !keyboard); } } IMemento::Pointer PartStack::GetSavedPresentationState() { return savedPresentationState; } void PartStack::FireInternalPropertyChange(int id) { ObjectInt::Pointer val(new ObjectInt(id)); Object::Pointer source(this); PropertyChangeEvent::Pointer event(new PropertyChangeEvent(source, IWorkbenchPartConstants::INTEGER_PROPERTY, val, val)); propEvents.propertyChange(event); } std::string PartStack::GetProperty(const std::string& id) { return properties[id]; } void PartStack::SetProperty(const std::string& id, const std::string& value) { if (value == "") { properties.erase(id); } else { properties.insert(std::make_pair(id, value)); } } void PartStack::CopyAppearanceProperties(PartStack::Pointer copyTo) { copyTo->appearance = this->appearance; if (!properties.empty()) { for (std::map::iterator iter = properties.begin(); iter != properties.end(); ++iter) { copyTo->SetProperty(iter->first, iter->second); } } } -void PartStack::ResizeChild(StackablePart::Pointer /*childThatChanged*/) +void PartStack::ResizeChild(LayoutPart::Pointer /*childThatChanged*/) { } } diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartStack.h b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartStack.h index 5683ffbc8b..5c46551ba1 100644 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartStack.h +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartStack.h @@ -1,762 +1,762 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef BERRYPARTSTACK_H_ #define BERRYPARTSTACK_H_ #include "berryLayoutPart.h" -#include "berryIStackableContainer.h" +#include "berryILayoutContainer.h" #include "berryWorkbenchPage.h" #include "berryPresentablePart.h" #include "berryPartPlaceholder.h" #include "berryDefaultStackPresentationSite.h" #include "berryPresentationFactoryUtil.h" #include "berryAbstractDropTarget.h" #include "berryPartPane.h" #include "berryIMemento.h" #include "presentations/berryIPresentationFactory.h" #include #include #include namespace berry { /** * \ingroup org_blueberry_ui_internal * * Implements the common behavior for stacks of Panes (ie: EditorStack and ViewStack) * This layout container has PartPanes as children and belongs to a PartSashContainer. * * @since 3.0 */ -class PartStack : public LayoutPart, public IStackableContainer { +class PartStack : public LayoutPart, public ILayoutContainer { friend class EditorSashContainer; friend class PartSashContainer; friend class DetachedWindow; public: berryObjectMacro(PartStack); public: static const int PROP_SELECTION; // = 0x42; - private: typedef std::list ChildVector; + private: typedef std::list ChildVector; private: ChildVector children; private: WorkbenchPage* page; private: bool isActive; private: bool allowStateChanges; private: typedef std::list PresentableVector; private: PresentableVector presentableParts; private: std::map properties; protected: int appearance; /** * Stores the last value passed to setSelection. If UI updates are being deferred, * this may be significantly different from the other current pointers. Once UI updates * are re-enabled, the stack will update the presentation selection to match the requested * current pointer. */ - private: StackablePart::Pointer requestedCurrent; + private: LayoutPart::Pointer requestedCurrent; /** * Stores the current part for the stack. Whenever the outside world asks a PartStack * for the current part, this is what gets returned. This pointer is only updated after * the presentation selection has been restored and the stack has finished updating its * internal state. If the stack is still in the process of updating the presentation, * it will still point to the previous part until the presentation is up-to-date. */ - private: StackablePart::Pointer current; + private: LayoutPart::Pointer current; /** * Stores the presentable part sent to the presentation. Whenever the presentation * asks for the current part, this is what gets returned. This is updated before sending * the part to the presentation, and it is not updated while UI updates are disabled. * When UI updates are enabled, the stack first makes presentationCurrent match * requestedCurrent. Once the presentation is displaying the correct part, the "current" * pointer on PartStack is updated. */ private: PresentablePart::Pointer presentationCurrent; private: bool ignoreSelectionChanges; protected: IMemento::Pointer savedPresentationState; protected: class MyStackPresentationSite : public DefaultStackPresentationSite { private: PartStack* partStack; public: MyStackPresentationSite(PartStack* stack); void Close(IPresentablePart::Pointer part); void Close(const std::vector& parts); void DragStart(IPresentablePart::Pointer beingDragged, Point& initialLocation, bool keyboard); void DragStart(Point& initialLocation, bool keyboard); bool IsPartMoveable(IPresentablePart::Pointer part); void SelectPart(IPresentablePart::Pointer toSelect); bool SupportsState(int state); void SetState(int newState); IPresentablePart::Pointer GetSelectedPart(); // void AddSystemActions(IMenuManager menuManager) { // PartStack.this.addSystemActions(menuManager); // } bool IsStackMoveable(); void FlushLayout(); PresentableVector GetPartList(); std::string GetProperty(const std::string& id); }; DefaultStackPresentationSite::Pointer presentationSite; private: class PartStackDropResult : public AbstractDropTarget { private: PartPane::WeakPtr pane; // Result of the presentation's dragOver method or null if we are stacking over the // client area of the pane. StackDropResult::Pointer dropResult; PartStack::WeakPtr stack; public: berryObjectMacro(PartStackDropResult); /** * Resets the target of this drop result (allows the same drop result object to be * reused) * * @param stack * @param pane * @param result result of the presentation's dragOver method, or null if we are * simply stacking anywhere. * @since 3.1 */ void SetTarget(PartStack::Pointer stack, PartPane::Pointer pane, StackDropResult::Pointer result); void Drop(); DnDTweaklet::CursorType GetCursor(); Rectangle GetSnapRectangle(); }; private: static PartStackDropResult::Pointer dropResult; // protected: bool isMinimized; private: IPropertyChangeListener::Events propEvents; /** * Custom presentation factory to use for this stack, or null to * use the default */ private: IPresentationFactory* factory; // private: boolean smartZoomed = false; // private: boolean doingUnzoom = false; protected: virtual bool IsMoveable(IPresentablePart::Pointer part); // protected: abstract void addSystemActions(IMenuManager menuManager); protected: virtual bool SupportsState(int newState); protected: virtual bool CanMoveFolder(); - protected: virtual void DerefPart(StackablePart::Pointer toDeref); + protected: virtual void DerefPart(LayoutPart::Pointer toDeref); protected: virtual bool AllowsDrop(PartPane::Pointer part); // protected: static void appendToGroupIfPossible(IMenuManager m, // String groupId, ContributionItem item) { // try { // m.appendToGroup(groupId, item); // } catch (IllegalArgumentException e) { // m.add(item); // } // } /** * Creates a new part stack that uses the given custom presentation factory * @param appearance * @param factory custom factory to use (or null to use the default) */ public: PartStack(WorkbenchPage* page, bool allowsStateChanges = true, int appearance = PresentationFactoryUtil::ROLE_VIEW, IPresentationFactory* factory = 0); /** * Adds a property listener to this stack. The listener will receive a PROP_SELECTION * event whenever the result of getSelection changes * * @param listener */ public: void AddListener(IPropertyChangeListener::Pointer listener); public: void RemoveListener(IPropertyChangeListener::Pointer listener); public: int GetAppearance() const; public: std::string GetID() const; protected: bool IsStandalone(); /** * Returns the currently selected IPresentablePart, or null if none * * @return */ protected: IPresentablePart::Pointer GetSelectedPart(); protected: IStackPresentationSite::Pointer GetPresentationSite(); /** * Tests the integrity of this object. Throws an exception if the object's state * is invalid. For use in test suites. */ public: void TestInvariants(); /* (non-Javadoc) * @see org.blueberry.ui.internal.LayoutPart#describeLayout(java.lang.StringBuffer) */ public: void DescribeLayout(std::string& buf) const; /** * See IVisualContainer#add */ - public: void Add(StackablePart::Pointer child); + public: void Add(LayoutPart::Pointer child); /** * Add a part at a particular position */ - protected: void Add(StackablePart::Pointer newChild, Object::Pointer cookie); + protected: void Add(LayoutPart::Pointer newChild, Object::Pointer cookie); - public: bool AllowsAdd(StackablePart::Pointer toAdd); + public: bool AllowsAdd(LayoutPart::Pointer toAdd); /* * (non-Javadoc) * * @see org.blueberry.ui.internal.ILayoutContainer#allowsAutoFocus() */ public: bool AllowsAutoFocus(); /** * @param parts */ protected: void Close(const std::vector& parts); /** * @param part */ protected: void Close(IPresentablePart::Pointer part); protected: IPresentationFactory* GetFactory(); public: void CreateControl(void* parent); /* (non-Javadoc) * @see org.blueberry.ui.internal.LayoutPart#getDropTarget(java.lang.Object, org.blueberry.swt.graphics.Point) */ public: IDropTarget::Pointer GetDropTarget(Object::Pointer draggedObject, const Point& position); public: void SetActive(bool isActive); public: IDropTarget::Pointer CreateDropTarget(PartPane::Pointer pane, StackDropResult::Pointer result); /** * Saves the current state of the presentation to savedPresentationState, if the * presentation exists. */ protected: void SavePresentationState(); public: ~PartStack(); /** * See LayoutPart#Dispose */ public: void Dispose(); - public: void FindSashes(PartPane::Sashes& sashes); + public: void FindSashes(LayoutPart::Pointer toFind, PartPane::Sashes& sashes); /** * Gets the presentation bounds. */ public: Rectangle GetBounds(); /** * See IVisualContainer#getChildren */ public: ChildVector GetChildren() const; public: void* GetControl(); /** * Answer the number of children. */ public: ChildVector::size_type GetItemCount(); /** * Returns the LayoutPart for the given IPresentablePart, or null if the given * IPresentablePart is not in this stack. Returns null if given a null argument. * * @param part to locate or null * @return */ protected: PartPane::Pointer GetPaneFor(IPresentablePart::Pointer part); /** * Get the parent control. */ public: void* GetParent(); /** * Returns a list of IPresentablePart * * @return */ public: PresentableVector GetPresentableParts(); - private: PresentablePart::Pointer GetPresentablePart(StackablePart::Pointer pane); + private: PresentablePart::Pointer GetPresentablePart(LayoutPart::Pointer pane); protected: StackPresentation::Pointer GetPresentation(); /** * Returns the visible child. * @return the currently visible part, or null if none */ - public: StackablePart::Pointer GetSelection(); + public: PartPane::Pointer GetSelection(); private: void PresentationSelectionChanged(IPresentablePart::Pointer newSelection); /** * See IVisualContainer#remove */ - public: void Remove(StackablePart::Pointer child); + public: void Remove(LayoutPart::Pointer child); /** * Reparent a part. Also reparent visible children... */ public: void Reparent(void* newParent); /** * See IVisualContainer#replace */ - public: void Replace(StackablePart::Pointer oldChild, StackablePart::Pointer newChild); + public: void Replace(LayoutPart::Pointer oldChild, LayoutPart::Pointer newChild); /* (non-Javadoc) * @see org.blueberry.ui.internal.LayoutPart#computePreferredSize(boolean, int, int, int) */ public: int ComputePreferredSize(bool width, int availableParallel, int availablePerpendicular, int preferredParallel); /* (non-Javadoc) * @see org.blueberry.ui.internal.LayoutPart#getSizeFlags(boolean) */ public: int GetSizeFlags(bool horizontal); /** * @see IPersistable */ public: bool RestoreState(IMemento::Pointer memento); /* (non-Javadoc) * @see org.blueberry.ui.internal.LayoutPart#setVisible(boolean) */ public: void SetVisible(bool makeVisible); /** * @see IPersistable */ public: bool SaveState(IMemento::Pointer memento); protected: WorkbenchPage::Pointer GetPage(); /** * Set the active appearence on the tab folder. * * @param active */ public: void SetActive(int activeState); public: int GetActive() const; public: void CreateControl(void* parent, StackPresentation::Pointer presentation); /** * Sets the presentation bounds. */ public: void SetBounds(const Rectangle& r); - public: void SetSelection(StackablePart::Pointer part); + public: void SetSelection(LayoutPart::Pointer part); /** * Updates the enablement state of actions */ protected: virtual void UpdateActions(PresentablePart::Pointer current); /* (non-Javadoc) * @see org.blueberry.ui.internal.LayoutPart#handleDeferredEvents() */ protected: void HandleDeferredEvents(); private: void RefreshPresentationSelection(); public: int GetState(); /** * Sets the minimized state for this stack. The part may call this method to * minimize or restore itself. The minimized state only affects the view * when unzoomed in the 3.0 presentation (in 3.3 it's handled by the * ViewStack directly and works as expected). */ // public: void setMinimized(boolean minimized) { // if (minimized != isMinimized) { // isMinimized = minimized; // // refreshPresentationState(); // } // } /* (non-Javadoc) * @see org.blueberry.ui.internal.ILayoutContainer#obscuredByZoom(org.blueberry.ui.internal.LayoutPart) */ // public: boolean childObscuredByZoom(LayoutPart toTest) { // return isObscuredByZoom(); // } /* (non-Javadoc) * @see org.blueberry.ui.internal.LayoutPart#requestZoom(org.blueberry.ui.internal.LayoutPart) */ // public: void childRequestZoomIn(LayoutPart toZoom) { // super.childRequestZoomIn(toZoom); // // requestZoomIn(); // } /* (non-Javadoc) * @see org.blueberry.ui.internal.LayoutPart#requestZoomOut() */ // public: void childRequestZoomOut() { // super.childRequestZoomOut(); // // requestZoomOut(); // } /* (non-Javadoc) * @see org.blueberry.ui.internal.ILayoutContainer#isZoomed(org.blueberry.ui.internal.LayoutPart) */ // public: boolean childIsZoomed(LayoutPart toTest) { // return isZoomed(); // } /** * This is a hack that allows us to preserve the old * min/max behavior for the stack containing the IntroPart. * This is required to have the initial Intro (Welcome) * pane to show correctly but will induce strange * effects should a user re-locate the part to * stacks other that its initial one... * * @return true if the stack contains the intro * as a ViewPane (not if it's only a placeholder) */ // private: boolean isIntroInStack() { // LayoutPart[] kids = getChildren(); // for (int i = 0; i < kids.length; i++) { // if (kids[i] instanceof ViewPane) { // ViewPane vp = (ViewPane) kids[i]; // if (vp.getID().equals(IIntroConstants.INTRO_VIEW_ID)) // return true; // } // } // return false; // } // private: void smartZoom() { // WorkbenchWindow wbw = (WorkbenchWindow) getPage().getWorkbenchWindow(); // if (wbw == null || wbw.getShell() == null) // return; // // Perspective perspective = getPage().getActivePerspective(); // FastViewManager fvm = perspective.getFastViewManager(); // // fvm.deferUpdates(true); // // // Cache the layout bounds // perspective.getPresentation().updateBoundsMap(); // // LayoutPart[] children = perspective.getPresentation().getLayout().getChildren(); // for (int i = 0; i < children.length; i++) { // if (children[i] != this) { // if (children[i] instanceof ViewStack) { // ((ViewStack) children[i]).setMinimized(true); // ViewStackTrimToolBar vstb = fvm // .getViewStackTrimToolbar(children[i] // .getID()); // vstb.setRestoreOnUnzoom(true); // } // else if (children[i] instanceof EditorSashContainer && !(this instanceof EditorStack)) { // perspective.setEditorAreaState(IStackPresentationSite.STATE_MINIMIZED); // perspective.setEditorAreaRestoreOnUnzoom(true); // } // } // } // // // If the editor area has changed state tell the perspective // if (this instanceof EditorStack) // perspective.setEditorAreaState(IStackPresentationSite.STATE_MAXIMIZED); // // // Clear the boundsMap // perspective.getPresentation().resetBoundsMap(); // // // We're done batching... // fvm.deferUpdates(false); // // perspective.getPresentation().setMaximizedStack(this); // smartZoomed = true; // } // protected: void smartUnzoom() { // // Prevent recursion through 'setMinimized' // if (doingUnzoom) // return; // doingUnzoom = true; // // WorkbenchWindow wbw = (WorkbenchWindow) getPage().getWorkbenchWindow(); // if (wbw == null || wbw.getShell() == null) // return; // // ITrimManager tbm = wbw.getTrimManager(); // Perspective perspective = getPage().getActivePerspective(); // FastViewManager fvm = perspective.getFastViewManager(); // // ILayoutContainer root = getContainer(); // // // We go up one more level when maximizing an editor stack // // so that we 'zoom' the editor area // boolean restoringEditorArea = false; // if (root instanceof EditorSashContainer) { // root = ((EditorSashContainer) root).getContainer(); // restoringEditorArea = true; // } // // // This is a compound operation // fvm.deferUpdates(true); // // LayoutPart[] children = root.getChildren(); // for (int i = 0; i < children.length; i++) { // if (children[i] != this) { // IWindowTrim trim = tbm.getTrim(children[i].getID()); // if (trim == null) // continue; // // if (trim instanceof ViewStackTrimToolBar) { // ViewStackTrimToolBar vstb = (ViewStackTrimToolBar) trim; // if (vstb.restoreOnUnzoom() // && children[i] instanceof ContainerPlaceholder) { // // In the current presentation its a // // container placeholder // ViewStack realStack = (ViewStack) ((ContainerPlaceholder) children[i]) // .getRealContainer(); // realStack.setMinimized(false); // // vstb.setRestoreOnUnzoom(false); // } // } else if (trim instanceof EditorAreaTrimToolBar) { // if (perspective.getEditorAreaRestoreOnUnzoom()) // perspective.setEditorAreaState(IStackPresentationSite.STATE_RESTORED); // } // } // } // // // If the editor area has changed state tell the perspective // if (restoringEditorArea) // perspective.setEditorAreaState(IStackPresentationSite.STATE_RESTORED); // // perspective.getPresentation().setMaximizedStack(null); // // fvm.deferUpdates(false); // smartZoomed = false; // // doingUnzoom = false; // } protected: void SetState(const int newState); /** * Called by the workbench page to notify this part that it has been zoomed or unzoomed. * The PartStack should not call this method itself -- it must request zoom changes by * talking to the WorkbenchPage. */ // public: void setZoomed(boolean isZoomed) { // // super.setZoomed(isZoomed); // // LayoutPart[] children = getChildren(); // // for (int i = 0; i < children.length; i++) { // LayoutPart next = children[i]; // // next.setZoomed(isZoomed); // } // // refreshPresentationState(); // } // public: boolean isZoomed() { // ILayoutContainer container = getContainer(); // // if (container != null) { // return container.childIsZoomed(this); // } // // return false; // } // protected: void refreshPresentationState() { // if (isZoomed() || smartZoomed) { // presentationSite.setPresentationState(IStackPresentationSite.STATE_MAXIMIZED); // } else { // // boolean wasMinimized = (presentationSite.getState() == IStackPresentationSite.STATE_MINIMIZED); // // if (isMinimized) { // presentationSite.setPresentationState(IStackPresentationSite.STATE_MINIMIZED); // } else { // presentationSite.setPresentationState(IStackPresentationSite.STATE_RESTORED); // } // // if (isMinimized != wasMinimized) { // flushLayout(); // // if (isMinimized) { // WorkbenchPage page = getPage(); // // if (page != null) { // page.refreshActiveView(); // } // } // } // } // } /** * Makes the given part visible in the presentation. * @param part the part to add to the stack * @param cookie other information */ - private: void ShowPart(StackablePart::Pointer part, Object::Pointer cookie); + private: void ShowPart(LayoutPart::Pointer part, Object::Pointer cookie); /** * Update the container to show the correct visible tab based on the * activation list. */ private: void UpdateContainerVisibleTab(); /** * */ public: void ShowSystemMenu(); public: void ShowPaneMenu(); public: void ShowPartList(); - public: std::vector GetTabList(StackablePart::Pointer part); + public: std::vector GetTabList(LayoutPart::Pointer part); /** * * @param beingDragged * @param initialLocation * @param keyboard */ private: void DragStart(IPresentablePart::Pointer beingDragged, Point& initialLocation, bool keyboard); public: void PaneDragStart(PartPane::Pointer pane, Point& initialLocation, bool keyboard); /** * @return Returns the savedPresentationState. */ public: IMemento::Pointer GetSavedPresentationState(); private: void FireInternalPropertyChange(int id); // TrimStack Support /** * Explicitly sets the presentation state. This is used by the * new min/max code to force the CTabFolder to show the proper * state without going through the 'setState' code (which causes * nasty side-effects. * @param newState The state to set the presentation to */ // public: void setPresentationState(int newState) { // presentationSite.setPresentationState(newState); // } // // Support for passing perspective layout properties to the presentation public: std::string GetProperty(const std::string& id); public: void SetProperty(const std::string& id, const std::string& value); /** * Copies all appearance related data from this stack to the given stack. */ public: void CopyAppearanceProperties(PartStack::Pointer copyTo); - public: void ResizeChild(StackablePart::Pointer childThatChanged); + public: void ResizeChild(LayoutPart::Pointer childThatChanged); }; } #endif /*BERRYPARTSTACK_H_*/ diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPerspective.cpp b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPerspective.cpp index ee7d5a7f32..1de0d5e9db 100644 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPerspective.cpp +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPerspective.cpp @@ -1,1764 +1,1763 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "tweaklets/berryGuiWidgetsTweaklet.h" #include "berryPerspective.h" #include "berryPerspectiveHelper.h" #include "berryWorkbenchPlugin.h" #include "berryWorkbenchConstants.h" #include "berryPerspectiveExtensionReader.h" #include "berryEditorSashContainer.h" #include "berryPartSite.h" #include "berryViewSite.h" #include "berryEditorAreaHelper.h" #include "intro/berryIntroConstants.h" #include "dialogs/berryMessageDialog.h" #include "berryWorkbenchWindow.h" #include "presentations/berryIStackPresentationSite.h" namespace berry { const std::string Perspective::VERSION_STRING = "0.016"; Perspective::Perspective(PerspectiveDescriptor::Pointer desc, WorkbenchPage::Pointer page) : descriptor(desc) { this->Init(page); if (desc.IsNotNull()) { this->CreatePresentation(desc); } } Perspective::Perspective(WorkbenchPage::Pointer page) { this->Init(page); } void Perspective::Init(WorkbenchPage::Pointer page) { editorHidden = false; editorAreaState = IStackPresentationSite::STATE_RESTORED; fixed = false; presentation = 0; shouldHideEditorsOnActivate = false; this->page = page.GetPointer(); this->editorArea = page->GetEditorPresentation()->GetLayoutPart(); this->viewFactory = page->GetViewFactory(); } bool Perspective::BringToTop(IViewReference::Pointer ref) { return presentation->BringPartToTop(this->GetPane(ref)); } bool Perspective::ContainsView(IViewPart::Pointer view) { IViewSite::Pointer site = view->GetViewSite(); IViewReference::Pointer ref = this->FindView(site->GetId(), site->GetSecondaryId()); if (ref.IsNull()) { return false; } return (view.Cast() == ref->GetPart(false)); } void Perspective::CreatePresentation(PerspectiveDescriptor::Pointer persp) { if (persp->HasCustomDefinition()) { this->LoadCustomPersp(persp); } else { this->LoadPredefinedPersp(persp); } } Perspective::~Perspective() { // Get rid of presentation. if (presentation == 0) { DisposeViewRefs(); return; } presentation->Deactivate(); // Release each view. std::vector refs(this->GetViewReferences()); for (std::vector::size_type i = 0, length = refs.size(); i < length; i++) { this->GetViewFactory()->ReleaseView(refs[i]); } mapIDtoViewLayoutRec.clear(); } void Perspective::DisposeViewRefs() { if (!memento) { return; } std::vector views(memento->GetChildren(WorkbenchConstants::TAG_VIEW)); for (std::size_t x = 0; x < views.size(); x++) { // Get the view details. IMemento::Pointer childMem = views[x]; std::string id; childMem->GetString(WorkbenchConstants::TAG_ID, id); // skip creation of the intro reference - it's handled elsewhere. if (id == IntroConstants::INTRO_VIEW_ID) { continue; } std::string secondaryId = ViewFactory::ExtractSecondaryId(id); if (!secondaryId.empty()) { id = ViewFactory::ExtractPrimaryId(id); } std::string removed; childMem->GetString(WorkbenchConstants::TAG_REMOVED, removed); if (removed != "true") { IViewReference::Pointer ref = viewFactory->GetView(id, secondaryId); if (ref) { viewFactory->ReleaseView(ref); } } } } IViewReference::Pointer Perspective::FindView(const std::string& viewId) { return this->FindView(viewId, ""); } IViewReference::Pointer Perspective::FindView(const std::string& id, const std::string& secondaryId) { std::vector refs(this->GetViewReferences()); for (unsigned int i = 0; i < refs.size(); i++) { IViewReference::Pointer ref = refs[i]; if (id == ref->GetId() && (secondaryId == ref->GetSecondaryId())) { return ref; } } return IViewReference::Pointer(0); } void* Perspective::GetClientComposite() { return page->GetClientComposite(); } IPerspectiveDescriptor::Pointer Perspective::GetDesc() { return descriptor; } PartPane::Pointer Perspective::GetPane(IViewReference::Pointer ref) { return ref.Cast()->GetPane(); } std::vector Perspective::GetPerspectiveShortcuts() { return perspectiveShortcuts; } PerspectiveHelper* Perspective::GetPresentation() const { return presentation; } std::vector Perspective::GetShowViewShortcuts() { return showViewShortcuts; } ViewFactory* Perspective::GetViewFactory() { return viewFactory; } std::vector Perspective::GetViewReferences() { // Get normal views. if (presentation == 0) { return std::vector(); } std::vector panes; presentation->CollectViewPanes(panes); std::vector result; // List fastViews = (fastViewManager != 0) ? // fastViewManager.getFastViews(0) // : new ArrayList(); // IViewReference[] resultArray = new IViewReference[panes.size() // + fastViews.size()]; // // // Copy fast views. // int nView = 0; // for (int i = 0; i < fastViews.size(); i++) // { // resultArray[nView] = (IViewReference) fastViews.get(i); // ++nView; // } // Copy normal views. for (std::vector::iterator iter = panes.begin(); iter != panes.end(); ++iter) { PartPane::Pointer pane = *iter; result.push_back(pane->GetPartReference().Cast()); } return result; } void Perspective::HideEditorArea() { if (!this->IsEditorAreaVisible()) { return; } // Show the editor in the appropriate location if (this->UseNewMinMax(Perspective::Pointer(this))) { // If it's the currently maximized part we have to restore first // if (this->GetPresentation().getMaximizedStack().Cast() != 0) // { // getPresentation().getMaximizedStack().setState(IStackPresentationSite.STATE_RESTORED); // } bool isMinimized = editorAreaState == IStackPresentationSite::STATE_MINIMIZED; if (!isMinimized) this->HideEditorAreaLocal(); //else // this->SetEditorAreaTrimVisibility(false); } else { this->HideEditorAreaLocal(); } editorHidden = true; } void Perspective::HideEditorAreaLocal() { if (editorHolder != 0) { return; } // Replace the editor area with a placeholder so we // know where to put it back on show editor area request. - editorHolder = new ContainerPlaceholder(editorArea->GetID()); + editorHolder = new PartPlaceholder(editorArea->GetID()); presentation->GetLayout()->Replace(editorArea, editorHolder); } bool Perspective::HideView(IViewReference::Pointer ref) { // If the view is locked just return. PartPane::Pointer pane = this->GetPane(ref); presentation->RemovePart(pane); // Dispose view if ref count == 0. this->GetViewFactory()->ReleaseView(ref); return true; } bool Perspective::IsEditorAreaVisible() { return !editorHidden; } ViewLayoutRec::Pointer Perspective::GetViewLayoutRec(IViewReference::Pointer ref, bool create) { ViewLayoutRec::Pointer result = this->GetViewLayoutRec(ViewFactory::GetKey(ref), create); if (result.IsNull() && create==false) { result = this->GetViewLayoutRec(ref->GetId(), false); } return result; } ViewLayoutRec::Pointer Perspective::GetViewLayoutRec(const std::string& viewId, bool create) { ViewLayoutRec::Pointer rec = mapIDtoViewLayoutRec[viewId]; if (rec.IsNull() && create) { rec = new ViewLayoutRec(); mapIDtoViewLayoutRec[viewId] = rec; } return rec; } bool Perspective::IsFixedLayout() { //@issue is there a difference between a fixed //layout and a fixed perspective?? If not the API //may need some polish, WorkbenchPage, PageLayout //and Perspective all have isFixed methods. //PageLayout and Perspective have their own fixed //attribute, we are assuming they are always in sync. //WorkbenchPage delegates to the perspective. return fixed; } bool Perspective::IsStandaloneView(IViewReference::Pointer ref) { ViewLayoutRec::Pointer rec = this->GetViewLayoutRec(ref, false); return rec.IsNotNull() && rec->isStandalone; } bool Perspective::GetShowTitleView(IViewReference::Pointer ref) { ViewLayoutRec::Pointer rec = this->GetViewLayoutRec(ref, false); return rec.IsNotNull() && rec->showTitle; } void Perspective::LoadCustomPersp(PerspectiveDescriptor::Pointer persp) { //get the layout from the registry PerspectiveRegistry* perspRegistry = dynamic_cast(WorkbenchPlugin::GetDefault()->GetPerspectiveRegistry()); try { IMemento::Pointer memento = perspRegistry->GetCustomPersp(persp->GetId()); // Restore the layout state. // MultiStatus status = new MultiStatus( // PlatformUI.PLUGIN_ID, // IStatus.OK, // NLS.bind(WorkbenchMessages.Perspective_unableToRestorePerspective, persp.getLabel()), // 0); // status.merge(restoreState(memento)); // status.merge(restoreState()); bool okay = true; okay &= this->RestoreState(memento); okay &= this->RestoreState(); if (!okay) { this->UnableToOpenPerspective(persp, "Unable to open perspective: " + persp->GetLabel()); } } //catch (IOException e) //{ // unableToOpenPerspective(persp, 0); //} catch (WorkbenchException& e) { this->UnableToOpenPerspective(persp, e.displayText()); } } void Perspective::UnableToOpenPerspective(PerspectiveDescriptor::Pointer persp, const std::string& status) { PerspectiveRegistry* perspRegistry = dynamic_cast(WorkbenchPlugin ::GetDefault()->GetPerspectiveRegistry()); perspRegistry->DeletePerspective(persp); // If this is a predefined perspective, we will not be able to delete // the perspective (we wouldn't want to). But make sure to delete the // customized portion. persp->DeleteCustomDefinition(); std::string title = "Restoring problems"; std::string msg = "Unable to read workbench state."; if (status == "") { MessageDialog::OpenError(Shell::Pointer(0), title, msg); } else { //TODO error dialog //ErrorDialog.openError((Shell) 0, title, msg, status); MessageDialog::OpenError(Shell::Pointer(0), title, msg + "\n" + status); } } void Perspective::LoadPredefinedPersp(PerspectiveDescriptor::Pointer persp) { // Create layout engine. IPerspectiveFactory::Pointer factory; try { factory = persp->CreateFactory(); } catch (CoreException& /*e*/) { throw WorkbenchException("Unable to load perspective: " + persp->GetId()); } /* * IPerspectiveFactory#createFactory() can return 0 */ if (factory == 0) { throw WorkbenchException("Unable to load perspective: " + persp->GetId()); } // Create layout factory. ViewSashContainer::Pointer container(new ViewSashContainer(page, this->GetClientComposite())); layout = new PageLayout(container, this->GetViewFactory(), editorArea, descriptor); layout->SetFixed(descriptor->GetFixed()); // // add the placeholders for the sticky folders and their contents IPlaceholderFolderLayout::Pointer stickyFolderRight, stickyFolderLeft, stickyFolderTop, stickyFolderBottom; std::vector descs(WorkbenchPlugin::GetDefault() ->GetViewRegistry()->GetStickyViews()); for (std::size_t i = 0; i < descs.size(); i++) { IStickyViewDescriptor::Pointer stickyViewDescriptor = descs[i]; std::string id = stickyViewDescriptor->GetId(); int location = stickyViewDescriptor->GetLocation(); if (location == IPageLayout::RIGHT) { if (stickyFolderRight == 0) { stickyFolderRight = layout ->CreatePlaceholderFolder( StickyViewDescriptor::STICKY_FOLDER_RIGHT, IPageLayout::RIGHT, .75f, IPageLayout::ID_EDITOR_AREA); } stickyFolderRight->AddPlaceholder(id); } else if (location == IPageLayout::LEFT) { if (stickyFolderLeft == 0) { stickyFolderLeft = layout->CreatePlaceholderFolder( StickyViewDescriptor::STICKY_FOLDER_LEFT, IPageLayout::LEFT, .25f, IPageLayout::ID_EDITOR_AREA); } stickyFolderLeft->AddPlaceholder(id); } else if (location == IPageLayout::TOP) { if (stickyFolderTop == 0) { stickyFolderTop = layout->CreatePlaceholderFolder( StickyViewDescriptor::STICKY_FOLDER_TOP, IPageLayout::TOP, .25f, IPageLayout::ID_EDITOR_AREA); } stickyFolderTop->AddPlaceholder(id); } else if (location == IPageLayout::BOTTOM) { if (stickyFolderBottom == 0) { stickyFolderBottom = layout->CreatePlaceholderFolder( StickyViewDescriptor::STICKY_FOLDER_BOTTOM, IPageLayout::BOTTOM, .75f, IPageLayout::ID_EDITOR_AREA); } stickyFolderBottom->AddPlaceholder(id); } //should never be 0 as we've just added the view above IViewLayout::Pointer viewLayout = layout->GetViewLayout(id); viewLayout->SetCloseable(stickyViewDescriptor->IsCloseable()); viewLayout->SetMoveable(stickyViewDescriptor->IsMoveable()); } // Run layout engine. factory->CreateInitialLayout(layout); PerspectiveExtensionReader extender; extender.ExtendLayout(descriptor->GetId(), layout); // Retrieve view layout info stored in the page layout. std::map layoutInfo = layout->GetIDtoViewLayoutRecMap(); mapIDtoViewLayoutRec.insert(layoutInfo.begin(), layoutInfo.end()); //TODO Perspective action sets // Create action sets. //List temp = new ArrayList(); //this->CreateInitialActionSets(temp, layout.getActionSets()); // IContextService service = 0; // if (page != 0) // { // service = (IContextService) page.getWorkbenchWindow().getService( // IContextService.class); // } // try // { // if (service!=0) // { // service.activateContext(ContextAuthority.DEFER_EVENTS); // } // for (Iterator iter = temp.iterator(); iter.hasNext();) // { // IActionSetDescriptor descriptor = (IActionSetDescriptor) iter // .next(); // addAlwaysOn(descriptor); // } // }finally // { // if (service!=0) // { // service.activateContext(ContextAuthority.SEND_EVENTS); // } // } // newWizardShortcuts = layout.getNewWizardShortcuts(); // showViewShortcuts = layout.getShowViewShortcuts(); // perspectiveShortcuts = layout.getPerspectiveShortcuts(); // showInPartIds = layout.getShowInPartIds(); // // // Retrieve fast views // if (fastViewManager != 0) // { // ArrayList fastViews = layout.getFastViews(); // for (Iterator fvIter = fastViews.iterator(); fvIter.hasNext();) // { // IViewReference ref = (IViewReference) fvIter.next(); // fastViewManager.addViewReference(FastViewBar.FASTVIEWBAR_ID, -1, ref, // !fvIter.hasNext()); // } // } // Is the layout fixed fixed = layout->IsFixed(); // Create presentation. presentation = new PerspectiveHelper(page, container, Perspective::Pointer(this)); // Hide editor area if requested by factory if (!layout->IsEditorAreaVisible()) { this->HideEditorArea(); } } void Perspective::OnActivate() { // Update editor area state. if (editorArea->GetControl() != 0) { bool visible = this->IsEditorAreaVisible(); bool inTrim = editorAreaState == IStackPresentationSite::STATE_MINIMIZED; editorArea->SetVisible(visible && !inTrim); } // // Update fast views. // // Make sure the control for the fastviews are created so they can // // be activated. // if (fastViewManager != 0) // { // List fastViews = fastViewManager.getFastViews(0); // for (int i = 0; i < fastViews.size(); i++) // { // ViewPane pane = getPane((IViewReference) fastViews.get(i)); // if (pane != 0) // { // Control ctrl = pane.getControl(); // if (ctrl == 0) // { // pane.createControl(getClientComposite()); // ctrl = pane.getControl(); // } // ctrl.setEnabled(false); // Remove focus support. // } // } // } // // Set the visibility of all fast view pins // setAllPinsVisible(true); // Trim Stack Support bool useNewMinMax = Perspective::UseNewMinMax(Perspective::Pointer(this)); bool hideEditorArea = shouldHideEditorsOnActivate || (editorHidden && editorHolder == 0); // We have to set the editor area's stack state -before- // activating the presentation since it's used there to determine // size of the resulting stack if (useNewMinMax && !hideEditorArea) { this->RefreshEditorAreaVisibility(); } // Show the layout presentation->Activate(this->GetClientComposite()); // if (useNewMinMax) // { // fastViewManager.activate(); // // // Move any minimized extension stacks to the trim // if (layout != 0) // { // // Turn aimations off // IPreferenceStore preferenceStore = PrefUtil.getAPIPreferenceStore(); // bool useAnimations = preferenceStore // .getbool(IWorkbenchPreferenceConstants.ENABLE_ANIMATIONS); // preferenceStore.setValue(IWorkbenchPreferenceConstants.ENABLE_ANIMATIONS, false); // // List minStacks = layout.getMinimizedStacks(); // for (Iterator msIter = minStacks.iterator(); msIter.hasNext();) // { // ViewStack vs = (ViewStack) msIter.next(); // vs.setMinimized(true); // } // // // Restore the animation pref // preferenceStore.setValue(IWorkbenchPreferenceConstants.ENABLE_ANIMATIONS, useAnimations); // // // this is a one-off deal...set during the extension reading // minStacks.clear(); // layout = 0; // } // } // else // { // // Update the FVB only if not using the new min/max // // // WorkbenchWindow wbw = (WorkbenchWindow) page.getWorkbenchWindow(); //// if (wbw != 0) //// { //// ITrimManager tbm = wbw.getTrimManager(); //// if (tbm != 0) //// { //// IWindowTrim fvb = tbm.getTrim(FastViewBar.FASTVIEWBAR_ID); //// if (fvb instanceof FastViewBar) //// { //// ((FastViewBar)fvb).update(true); //// } //// } //// } // } // // If we are -not- using the new min/max then ensure that there // // are no stacks in the trim. This can happen when a user switches // // back to the 3.0 presentation... // if (!Perspective.useNewMinMax(this) && fastViewManager != 0) // { // bool stacksWereRestored = fastViewManager.restoreAllTrimStacks(); // setEditorAreaTrimVisibility(false); // // // Restore any 'maximized' view stack since we've restored // // the minimized stacks // if (stacksWereRestored && presentation.getMaximizedStack().Cast() != 0) // { // ViewStack vs = (ViewStack) presentation.getMaximizedStack(); // vs.setPresentationState(IStackPresentationSite.STATE_RESTORED); // presentation.setMaximizedStack(0); // } // } // We hide the editor area -after- the presentation activates if (hideEditorArea) { // We do this here to ensure that createPartControl is called on the // top editor // before it is hidden. See bug 20166. this->HideEditorArea(); shouldHideEditorsOnActivate = false; // // this is an override so it should handle both states // if (useNewMinMax) // setEditorAreaTrimVisibility(editorAreaState == IStackPresentationSite.STATE_MINIMIZED); } layout = 0; } void Perspective::OnDeactivate() { presentation->Deactivate(); //setActiveFastView(0); //setAllPinsVisible(false); // // Update fast views. // if (fastViewManager != 0) // { // List fastViews = fastViewManager.getFastViews(0); // for (int i = 0; i < fastViews.size(); i++) // { // ViewPane pane = getPane((IViewReference) fastViews.get(i)); // if (pane != 0) // { // Control ctrl = pane.getControl(); // if (ctrl != 0) // { // ctrl.setEnabled(true); // Add focus support. // } // } // } // // fastViewManager.deActivate(); // } // // // Ensure that the editor area trim is hidden as well // setEditorAreaTrimVisibility(false); } void Perspective::PartActivated(IWorkbenchPart::Pointer /*activePart*/) { // // If a fastview is open close it. // if (activeFastView != 0 // && activeFastView.getPart(false) != activePart) // { // setActiveFastView(0); // } } void Perspective::PerformedShowIn(const std::string& /*partId*/) { //showInTimes.insert(std::make_pair(partId, new Long(System.currentTimeMillis()))); } bool Perspective::RestoreState(IMemento::Pointer memento) { // MultiStatus result = new MultiStatus( // PlatformUI.PLUGIN_ID, // IStatus.OK, // WorkbenchMessages.Perspective_problemsRestoringPerspective, 0); bool result = true; // Create persp descriptor. descriptor = new PerspectiveDescriptor("", "", PerspectiveDescriptor::Pointer(0)); //result.add(descriptor.restoreState(memento)); result &= descriptor->RestoreState(memento); PerspectiveDescriptor::Pointer desc = WorkbenchPlugin::GetDefault()-> GetPerspectiveRegistry()->FindPerspectiveWithId(descriptor->GetId()).Cast(); if (desc) { descriptor = desc; } this->memento = memento; // Add the visible views. std::vector views(memento->GetChildren(WorkbenchConstants::TAG_VIEW)); //result.merge(createReferences(views)); result &= this->CreateReferences(views); memento = memento->GetChild(WorkbenchConstants::TAG_FAST_VIEWS); if (memento) { views = memento->GetChildren(WorkbenchConstants::TAG_VIEW); //result.merge(createReferences(views)); result &= this->CreateReferences(views); } return result; } bool Perspective::CreateReferences(const std::vector& views) { // MultiStatus result = new MultiStatus(PlatformUI.PLUGIN_ID, IStatus.OK, // WorkbenchMessages.Perspective_problemsRestoringViews, 0); bool result = true; for (std::size_t x = 0; x < views.size(); x++) { // Get the view details. IMemento::Pointer childMem = views[x]; std::string id; childMem->GetString(WorkbenchConstants::TAG_ID, id); // skip creation of the intro reference - it's handled elsewhere. if (id == IntroConstants::INTRO_VIEW_ID) { continue; } std::string secondaryId(ViewFactory::ExtractSecondaryId(id)); if (!secondaryId.empty()) { id = ViewFactory::ExtractPrimaryId(id); } // Create and open the view. try { std::string rm; childMem->GetString(WorkbenchConstants::TAG_REMOVED, rm); if (rm != "true") { viewFactory->CreateView(id, secondaryId); } } catch (const PartInitException& e) { childMem->PutString(WorkbenchConstants::TAG_REMOVED, "true"); // result.add(StatusUtil.newStatus(IStatus.ERR, // e.getMessage() == 0 ? "" : e.getMessage(), //$NON-NLS-1$ // e)); WorkbenchPlugin::Log(e.displayText(), e); result &= true; } } return result; } bool Perspective::RestoreState() { if (this->memento == 0) { //return new Status(IStatus.OK, PlatformUI.PLUGIN_ID, 0, "", 0); //$NON-NLS-1$ return true; } // MultiStatus result = new MultiStatus( // PlatformUI.PLUGIN_ID, // IStatus.OK, // WorkbenchMessages.Perspective_problemsRestoringPerspective, 0); bool result = true; IMemento::Pointer memento = this->memento; this->memento = 0; const IMemento::Pointer boundsMem(memento->GetChild(WorkbenchConstants::TAG_WINDOW)); if (boundsMem) { Rectangle r(0, 0, 0, 0); boundsMem->GetInteger(WorkbenchConstants::TAG_X, r.x); boundsMem->GetInteger(WorkbenchConstants::TAG_Y, r.y); boundsMem->GetInteger(WorkbenchConstants::TAG_HEIGHT, r.height); boundsMem->GetInteger(WorkbenchConstants::TAG_WIDTH, r.width); //StartupThreading.runWithoutExceptions(new StartupRunnable() // { // void runWithException() throws Throwable // { if (page->GetWorkbenchWindow()->GetActivePage() == 0) { page->GetWorkbenchWindow()->GetShell()->SetBounds(r); } // } // }); } // Create an empty presentation.. PerspectiveHelper* pres; //StartupThreading.runWithoutExceptions(new StartupRunnable() // { // void runWithException() throws Throwable // { ViewSashContainer::Pointer mainLayout(new ViewSashContainer(page, this->GetClientComposite())); pres = new PerspectiveHelper(page, mainLayout, Perspective::Pointer(this)); // }}); // Read the layout. // result.merge(pres.restoreState(memento // .getChild(IWorkbenchConstants.TAG_LAYOUT))); result &= pres->RestoreState(memento->GetChild(WorkbenchConstants::TAG_LAYOUT)); //StartupThreading.runWithoutExceptions(new StartupRunnable() // { // void runWithException() throws Throwable // { // Add the editor workbook. Do not hide it now. pres->ReplacePlaceholderWithPart(editorArea); // }}); // Add the visible views. std::vector views(memento->GetChildren(WorkbenchConstants::TAG_VIEW)); for (std::size_t x = 0; x < views.size(); x++) { // Get the view details. IMemento::Pointer childMem = views[x]; std::string id; childMem->GetString(WorkbenchConstants::TAG_ID, id); std::string secondaryId(ViewFactory::ExtractSecondaryId(id)); if (!secondaryId.empty()) { id = ViewFactory::ExtractPrimaryId(id); } // skip the intro as it is restored higher up in workbench. if (id == IntroConstants::INTRO_VIEW_ID) { continue; } // Create and open the view. IViewReference::Pointer viewRef = viewFactory->GetView(id, secondaryId); WorkbenchPartReference::Pointer ref = viewRef.Cast(); // report error if (ref == 0) { std::string key = ViewFactory::GetKey(id, secondaryId); // result.add(new Status(IStatus.ERR, PlatformUI.PLUGIN_ID, 0, // NLS.bind(WorkbenchMessages.Perspective_couldNotFind, key ), 0)); WorkbenchPlugin::Log("Could not find view: " + key); continue; } - bool willPartBeVisible = pres->WillPartBeVisible(ref->GetId(), - secondaryId); + bool willPartBeVisible = pres->WillPartBeVisible(ref->GetId(), secondaryId); if (willPartBeVisible) { IViewPart::Pointer view = ref->GetPart(true).Cast(); if (view) { ViewSite::Pointer site = view->GetSite().Cast(); - pres->ReplacePlaceholderWithPart(site->GetPane().Cast()); + pres->ReplacePlaceholderWithPart(site->GetPane().Cast()); } } else { - pres->ReplacePlaceholderWithPart(ref->GetPane().Cast()); + pres->ReplacePlaceholderWithPart(ref->GetPane()); } } // // Load the fast views // if (fastViewManager != 0) // fastViewManager.restoreState(memento, result); // Load the view layout recs std::vector recMementos(memento ->GetChildren(WorkbenchConstants::TAG_VIEW_LAYOUT_REC)); for (std::size_t i = 0; i < recMementos.size(); i++) { IMemento::Pointer recMemento = recMementos[i]; std::string compoundId; if (recMemento->GetString(WorkbenchConstants::TAG_ID, compoundId)) { ViewLayoutRec::Pointer rec = GetViewLayoutRec(compoundId, true); std::string closeablestr; recMemento->GetString(WorkbenchConstants::TAG_CLOSEABLE, closeablestr); if (WorkbenchConstants::FALSE_VAL == closeablestr) { rec->isCloseable = false; } std::string moveablestr; recMemento->GetString(WorkbenchConstants::TAG_MOVEABLE, moveablestr); if (WorkbenchConstants::FALSE_VAL == moveablestr) { rec->isMoveable = false; } std::string standalonestr; recMemento->GetString(WorkbenchConstants::TAG_STANDALONE, standalonestr); if (WorkbenchConstants::TRUE_VAL == standalonestr) { rec->isStandalone = true; std::string showstr; recMemento->GetString(WorkbenchConstants::TAG_SHOW_TITLE, showstr); rec->showTitle = WorkbenchConstants::FALSE_VAL != showstr; } } } //final IContextService service = (IContextService)page.getWorkbenchWindow().getService(IContextService.class); try { // one big try block, don't kill me here // // defer context events // if (service != 0) // { // service.activateContext(ContextAuthority.DEFER_EVENTS); // } // // HashSet knownActionSetIds = new HashSet(); // // // Load the always on action sets. std::vector actions; // = memento // .getChildren(IWorkbenchConstants.TAG_ALWAYS_ON_ACTION_SET); // for (int x = 0; x < actions.length; x++) // { // String actionSetID = actions[x] // .getString(IWorkbenchConstants.TAG_ID); // final IActionSetDescriptor d = WorkbenchPlugin.getDefault() // .getActionSetRegistry().findActionSet(actionSetID); // if (d != 0) // { // StartupThreading // .runWithoutExceptions(new StartupRunnable() // { // void runWithException() throws Throwable // { // addAlwaysOn(d); // } // }); // // knownActionSetIds.add(actionSetID); // } // } // // // Load the always off action sets. // actions = memento // .getChildren(IWorkbenchConstants.TAG_ALWAYS_OFF_ACTION_SET); // for (int x = 0; x < actions.length; x++) // { // String actionSetID = actions[x] // .getString(IWorkbenchConstants.TAG_ID); // final IActionSetDescriptor d = WorkbenchPlugin.getDefault() // .getActionSetRegistry().findActionSet(actionSetID); // if (d != 0) // { // StartupThreading // .runWithoutExceptions(new StartupRunnable() // { // void runWithException() throws Throwable // { // addAlwaysOff(d); // } // }); // knownActionSetIds.add(actionSetID); // } // } // Load "show view actions". actions = memento->GetChildren(WorkbenchConstants::TAG_SHOW_VIEW_ACTION); for (std::size_t x = 0; x < actions.size(); x++) { std::string id; actions[x]->GetString(WorkbenchConstants::TAG_ID, id); showViewShortcuts.push_back(id); } // // Load "show in times". // actions = memento.getChildren(IWorkbenchConstants.TAG_SHOW_IN_TIME); // for (int x = 0; x < actions.length; x++) // { // String id = actions[x].getString(IWorkbenchConstants.TAG_ID); // String timeStr = actions[x] // .getString(IWorkbenchConstants.TAG_TIME); // if (id != 0 && timeStr != 0) // { // try // { // long time = Long.parseLong(timeStr); // showInTimes.put(id, new Long(time)); // } // catch (NumberFormatException e) // { // // skip this one // } // } // } // Load "show in parts" from registry, not memento showInPartIds = this->GetShowInIdsFromRegistry(); // // Load "new wizard actions". // actions = memento // .getChildren(IWorkbenchConstants.TAG_NEW_WIZARD_ACTION); // newWizardShortcuts = new ArrayList(actions.length); // for (int x = 0; x < actions.length; x++) // { // String id = actions[x].getString(IWorkbenchConstants.TAG_ID); // newWizardShortcuts.add(id); // } // Load "perspective actions". actions = memento->GetChildren(WorkbenchConstants::TAG_PERSPECTIVE_ACTION); for (std::size_t x = 0; x < actions.size(); x++) { std::string id; actions[x]->GetString(WorkbenchConstants::TAG_ID, id); perspectiveShortcuts.push_back(id); } // ArrayList extActionSets = getPerspectiveExtensionActionSets(); // for (int i = 0; i < extActionSets.size(); i++) // { // String actionSetID = (String) extActionSets.get(i); // if (knownActionSetIds.contains(actionSetID)) // { // continue; // } // final IActionSetDescriptor d = WorkbenchPlugin.getDefault() // .getActionSetRegistry().findActionSet(actionSetID); // if (d != 0) // { // StartupThreading // .runWithoutExceptions(new StartupRunnable() // { // void runWithException() throws Throwable // { // addAlwaysOn(d); // } // }); // knownActionSetIds.add(d.getId()); // } // } // // Add the visible set of action sets to our knownActionSetIds // // Now go through the registry to ensure we pick up any new action // // sets // // that have been added but not yet considered by this perspective. // ActionSetRegistry reg = WorkbenchPlugin.getDefault() // .getActionSetRegistry(); // IActionSetDescriptor[] array = reg.getActionSets(); // int count = array.length; // for (int i = 0; i < count; i++) // { // IActionSetDescriptor desc = array[i]; // if ((!knownActionSetIds.contains(desc.getId())) // && (desc.isInitiallyVisible())) // { // addActionSet(desc); // } // } } catch (...) { // // restart context changes // if (service != 0) // { // StartupThreading.runWithoutExceptions(new StartupRunnable() // { // void runWithException() throws Throwable // { // service.activateContext(ContextAuthority.SEND_EVENTS); // } // }); // } } // Save presentation. presentation = pres; // Hide the editor area if needed. Need to wait for the // presentation to be fully setup first. int areaVisible = 0; bool areaVisibleExists = memento->GetInteger(WorkbenchConstants::TAG_AREA_VISIBLE, areaVisible); // Rather than hiding the editors now we must wait until after their // controls // are created. This ensures that if an editor is instantiated, // createPartControl // is also called. See bug 20166. shouldHideEditorsOnActivate = (areaVisibleExists && areaVisible == 0); // // Restore the trim state of the editor area // IPreferenceStore preferenceStore = PrefUtil.getAPIPreferenceStore(); // bool useNewMinMax = preferenceStore.getbool(IWorkbenchPreferenceConstants.ENABLE_NEW_MIN_MAX); // if (useNewMinMax) // { // Integer trimStateInt = memento.getInteger(IWorkbenchConstants.TAG_AREA_TRIM_STATE); // if (trimStateInt != 0) // { // editorAreaState = trimStateInt.intValue() & 0x3; // low order two bits contain the state // editorAreaRestoreOnUnzoom = (trimStateInt.intValue() & 4) != 0; // } // } // restore the fixed state int isFixed = 0; fixed = (memento->GetInteger(WorkbenchConstants::TAG_FIXED, isFixed) && isFixed == 1); return true; } std::vector Perspective::GetShowInIdsFromRegistry() { PerspectiveExtensionReader reader; std::vector tags; tags.push_back(WorkbenchRegistryConstants::TAG_SHOW_IN_PART); reader.SetIncludeOnlyTags(tags); PageLayout::Pointer layout(new PageLayout()); reader.ExtendLayout(descriptor->GetOriginalId(), layout); return layout->GetShowInPartIds(); } void Perspective::SaveDesc() { this->SaveDescAs(descriptor); } void Perspective::SaveDescAs(IPerspectiveDescriptor::Pointer /*desc*/) { //TODO Perspective SaveDescAs // PerspectiveDescriptor::Pointer realDesc = desc.Cast(); // //get the layout from the registry // PerspectiveRegistry* perspRegistry = dynamic_cast(WorkbenchPlugin // ::GetDefault()->GetPerspectiveRegistry()); // // Capture the layout state. // XMLMemento memento = XMLMemento.createWriteRoot("perspective");//$NON-NLS-1$ // IStatus status = saveState(memento, realDesc, false); // if (status.getSeverity() == IStatus.ERR) // { // ErrorDialog.openError((Shell) 0, WorkbenchMessages.Perspective_problemSavingTitle, // WorkbenchMessages.Perspective_problemSavingMessage, // status); // return; // } // //save it to the preference store // try // { // perspRegistry.saveCustomPersp(realDesc, memento); // descriptor = realDesc; // } // catch (IOException e) // { // perspRegistry.deletePerspective(realDesc); // MessageDialog.openError((Shell) 0, WorkbenchMessages.Perspective_problemSavingTitle, // WorkbenchMessages.Perspective_problemSavingMessage); // } } bool Perspective::SaveState(IMemento::Pointer memento) { // MultiStatus result = new MultiStatus( // PlatformUI.PLUGIN_ID, // IStatus.OK, // WorkbenchMessages.Perspective_problemsSavingPerspective, 0); // // result.merge(saveState(memento, descriptor, true)); bool result = true; result &= this->SaveState(memento, descriptor, true); return result; } bool Perspective::SaveState(IMemento::Pointer memento, PerspectiveDescriptor::Pointer p, bool saveInnerViewState) { // MultiStatus result = new MultiStatus( // PlatformUI.PLUGIN_ID, // IStatus.OK, // WorkbenchMessages.Perspective_problemsSavingPerspective, 0); bool result = true; if (this->memento) { memento->PutMemento(this->memento); return result; } // Save the version number. memento->PutString(WorkbenchConstants::TAG_VERSION, VERSION_STRING); //result.add(p.saveState(memento)); result &= p->SaveState(memento); if (!saveInnerViewState) { Rectangle bounds(page->GetWorkbenchWindow()->GetShell()->GetBounds()); IMemento::Pointer boundsMem = memento ->CreateChild(WorkbenchConstants::TAG_WINDOW); boundsMem->PutInteger(WorkbenchConstants::TAG_X, bounds.x); boundsMem->PutInteger(WorkbenchConstants::TAG_Y, bounds.y); boundsMem->PutInteger(WorkbenchConstants::TAG_HEIGHT, bounds.height); boundsMem->PutInteger(WorkbenchConstants::TAG_WIDTH, bounds.width); } // // Save the "always on" action sets. // Iterator itr = alwaysOnActionSets.iterator(); // while (itr.hasNext()) // { // IActionSetDescriptor desc = (IActionSetDescriptor) itr.next(); // IMemento child = memento // .createChild(IWorkbenchConstants.TAG_ALWAYS_ON_ACTION_SET); // child.putString(IWorkbenchConstants.TAG_ID, desc.getId()); // } // // Save the "always off" action sets. // itr = alwaysOffActionSets.iterator(); // while (itr.hasNext()) // { // IActionSetDescriptor desc = (IActionSetDescriptor) itr.next(); // IMemento child = memento // .createChild(IWorkbenchConstants.TAG_ALWAYS_OFF_ACTION_SET); // child.putString(IWorkbenchConstants.TAG_ID, desc.getId()); // } // Save "show view actions" for (std::vector::iterator itr = showViewShortcuts.begin(); itr != showViewShortcuts.end(); ++itr) { IMemento::Pointer child = memento ->CreateChild(WorkbenchConstants::TAG_SHOW_VIEW_ACTION); child->PutString(WorkbenchConstants::TAG_ID, *itr); } // // Save "show in times" // itr = showInTimes.keySet().iterator(); // while (itr.hasNext()) // { // String id = (String) itr.next(); // Long time = (Long) showInTimes.get(id); // IMemento child = memento // .createChild(IWorkbenchConstants.TAG_SHOW_IN_TIME); // child.putString(IWorkbenchConstants.TAG_ID, id); // child.putString(IWorkbenchConstants.TAG_TIME, time.toString()); // } // // Save "new wizard actions". // itr = newWizardShortcuts.iterator(); // while (itr.hasNext()) // { // String str = (String) itr.next(); // IMemento child = memento // .createChild(IWorkbenchConstants.TAG_NEW_WIZARD_ACTION); // child.putString(IWorkbenchConstants.TAG_ID, str); // } // Save "perspective actions". for (std::vector::iterator itr = perspectiveShortcuts.begin(); itr != perspectiveShortcuts.end(); ++itr) { IMemento::Pointer child = memento ->CreateChild(WorkbenchConstants::TAG_PERSPECTIVE_ACTION); child->PutString(WorkbenchConstants::TAG_ID, *itr); } // Get visible views. std::vector viewPanes; presentation->CollectViewPanes(viewPanes); // Save the views. for (std::vector::iterator itr = viewPanes.begin(); itr != viewPanes.end(); ++itr) { IWorkbenchPartReference::Pointer ref((*itr)->GetPartReference()); IViewDescriptor::Pointer desc = page->GetViewFactory()->GetViewRegistry() ->Find(ref->GetId()); if(desc && desc->IsRestorable()) { IMemento::Pointer viewMemento = memento ->CreateChild(WorkbenchConstants::TAG_VIEW); viewMemento->PutString(WorkbenchConstants::TAG_ID, ViewFactory::GetKey(ref.Cast())); } } // // save all fastview state // if (fastViewManager != 0) // fastViewManager.saveState(memento); // Save the view layout recs. for (std::map::iterator i = mapIDtoViewLayoutRec.begin(); i != mapIDtoViewLayoutRec.end(); ++i) { std::string compoundId(i->first); ViewLayoutRec::Pointer rec(i->second); if (rec && (!rec->isCloseable || !rec->isMoveable || rec->isStandalone)) { IMemento::Pointer layoutMemento(memento ->CreateChild(WorkbenchConstants::TAG_VIEW_LAYOUT_REC)); layoutMemento->PutString(WorkbenchConstants::TAG_ID, compoundId); if (!rec->isCloseable) { layoutMemento->PutString(WorkbenchConstants::TAG_CLOSEABLE, WorkbenchConstants::FALSE_VAL); } if (!rec->isMoveable) { layoutMemento->PutString(WorkbenchConstants::TAG_MOVEABLE, WorkbenchConstants::FALSE_VAL); } if (rec->isStandalone) { layoutMemento->PutString(WorkbenchConstants::TAG_STANDALONE, WorkbenchConstants::TRUE_VAL); layoutMemento->PutString(WorkbenchConstants::TAG_SHOW_TITLE, rec->showTitle ? WorkbenchConstants::TRUE_VAL : WorkbenchConstants::FALSE_VAL); } } } // Save the layout. IMemento::Pointer childMem(memento->CreateChild(WorkbenchConstants::TAG_LAYOUT)); //result.add(presentation.saveState(childMem)); result &= presentation->SaveState(childMem); // Save the editor visibility state if (this->IsEditorAreaVisible()) { memento->PutInteger(WorkbenchConstants::TAG_AREA_VISIBLE, 1); } else { memento->PutInteger(WorkbenchConstants::TAG_AREA_VISIBLE, 0); } // // Save the trim state of the editor area if using the new min/max // IPreferenceStore preferenceStore = PrefUtil.getAPIPreferenceStore(); // bool useNewMinMax = preferenceStore.getbool(IWorkbenchPreferenceConstants.ENABLE_NEW_MIN_MAX); // if (useNewMinMax) // { // int trimState = editorAreaState; // trimState |= editorAreaRestoreOnUnzoom ? 4 : 0; // memento.putInteger(IWorkbenchConstants.TAG_AREA_TRIM_STATE, trimState); // } // Save the fixed state if (fixed) { memento->PutInteger(WorkbenchConstants::TAG_FIXED, 1); } else { memento->PutInteger(WorkbenchConstants::TAG_FIXED, 0); } return result; } void Perspective::SetPerspectiveActionIds(const std::vector& list) { perspectiveShortcuts = list; } void Perspective::SetShowInPartIds(const std::vector& list) { showInPartIds = list; } void Perspective::SetShowViewActionIds(const std::vector& list) { showViewShortcuts = list; } void Perspective::ShowEditorArea() { if (this->IsEditorAreaVisible()) { return; } editorHidden = false; // Show the editor in the appropriate location if (this->UseNewMinMax(Perspective::Pointer(this))) { bool isMinimized = editorAreaState == IStackPresentationSite::STATE_MINIMIZED; if (!isMinimized) { // If the editor area is going to show then we have to restore // if (getPresentation().getMaximizedStack() != 0) // getPresentation().getMaximizedStack().setState(IStackPresentationSite.STATE_RESTORED); this->ShowEditorAreaLocal(); } // else // setEditorAreaTrimVisibility(true); } else { this->ShowEditorAreaLocal(); } } void Perspective::ShowEditorAreaLocal() { if (editorHolder == 0 || editorHidden) { return; } // Replace the part holder with the editor area. presentation->GetLayout()->Replace(editorHolder, editorArea); editorHolder = 0; } void Perspective::SetEditorAreaState(int newState) { if (newState == editorAreaState) return; editorAreaState = newState; // // reset the restore flag if we're not minimized // if (newState != IStackPresentationSite::STATE_MINIMIZED) // editorAreaRestoreOnUnzoom = false; this->RefreshEditorAreaVisibility(); } int Perspective::GetEditorAreaState() { return editorAreaState; } void Perspective::RefreshEditorAreaVisibility() { // Nothing shows up if the editor area isn't visible at all if (editorHidden) { this->HideEditorAreaLocal(); //setEditorAreaTrimVisibility(false); return; } PartStack::Pointer editorStack = editorArea.Cast()->GetUpperRightEditorStack(); if (editorStack == 0) return; // Whatever we're doing, make the current editor stack match it //editorStack->SetStateLocal(editorAreaState); // If it's minimized then it's in the trim if (editorAreaState == IStackPresentationSite::STATE_MINIMIZED) { // Hide the editor area and show its trim this->HideEditorAreaLocal(); //setEditorAreaTrimVisibility(true); } else { // Show the editor area and hide its trim //setEditorAreaTrimVisibility(false); this->ShowEditorAreaLocal(); // if (editorAreaState == IStackPresentationSite::STATE_MAXIMIZED) // getPresentation().setMaximizedStack(editorStack); } } IViewReference::Pointer Perspective::GetViewReference(const std::string& viewId, const std::string& secondaryId) { IViewReference::Pointer ref = page->FindViewReference(viewId, secondaryId); if (ref == 0) { ViewFactory* factory = this->GetViewFactory(); try { ref = factory->CreateView(viewId, secondaryId); } catch (PartInitException& /*e*/) { // IStatus status = StatusUtil.newStatus(IStatus.ERR, // e.getMessage() == 0 ? "" : e.getMessage(), //$NON-NLS-1$ // e); // StatusUtil.handleStatus(status, "Failed to create view: id=" + viewId, //$NON-NLS-1$ // StatusManager.LOG); //TODO Perspective status message WorkbenchPlugin::Log("Failed to create view: id=" + viewId); } } return ref; } IViewPart::Pointer Perspective::ShowView(const std::string& viewId, const std::string& secondaryId) { ViewFactory* factory = this->GetViewFactory(); IViewReference::Pointer ref = factory->CreateView(viewId, secondaryId); IViewPart::Pointer part = ref->GetPart(true).Cast(); if (part == 0) { throw PartInitException("Could not create view: " + ref->GetId()); } PartSite::Pointer site = part->GetSite().Cast(); PartPane::Pointer pane = site->GetPane(); //TODO Perspective preference store // IPreferenceStore store = WorkbenchPlugin.getDefault() // .getPreferenceStore(); // int openViewMode = store.getInt(IPreferenceConstants.OPEN_VIEW_MODE); // // if (openViewMode == IPreferenceConstants.OVM_FAST && // fastViewManager != 0) // { // fastViewManager.addViewReference(FastViewBar.FASTVIEWBAR_ID, -1, ref, true); // setActiveFastView(ref); // } // else if (openViewMode == IPreferenceConstants.OVM_FLOAT // && presentation.canDetach()) // { // presentation.addDetachedPart(pane); // } // else // { if (this->UseNewMinMax(Perspective::Pointer(this))) { // Is this view going to show in the trim? // LayoutPart vPart = presentation.findPart(viewId, secondaryId); // Determine if there is a trim stack that should get the view std::string trimId; // // If we can locate the correct trim stack then do so // if (vPart != 0) // { // String id = 0; // ILayoutContainer container = vPart.getContainer(); // if (container.Cast() != 0) // id = ((ContainerPlaceholder)container).getID(); // else if (container.Cast() != 0) // id = ((ViewStack)container).getID(); // // // Is this place-holder in the trim? // if (id != 0 && fastViewManager.getFastViews(id).size()> 0) // { // trimId = id; // } // } // // // No explicit trim found; If we're maximized then we either have to find an // // arbitrary stack... // if (trimId == 0 && presentation.getMaximizedStack() != 0) // { // if (vPart == 0) // { // ViewStackTrimToolBar blTrimStack = fastViewManager.getBottomRightTrimStack(); // if (blTrimStack != 0) // { // // OK, we've found a trim stack to add it to... // trimId = blTrimStack.getId(); // // // Since there was no placeholder we have to add one // LayoutPart blPart = presentation.findPart(trimId, 0); // if (blPart.Cast() != 0) // { // ContainerPlaceholder cph = (ContainerPlaceholder) blPart; // if (cph.getRealContainer().Cast() != 0) // { // ViewStack vs = (ViewStack) cph.getRealContainer(); // // // Create a 'compound' id if this is a multi-instance part // String compoundId = ref.getId(); // if (ref.getSecondaryId() != 0) // compoundId = compoundId + ':' + ref.getSecondaryId(); // // // Add the new placeholder // vs.add(new PartPlaceholder(compoundId)); // } // } // } // } // } // // // If we have a trim stack located then add the view to it // if (trimId != "") // { // fastViewManager.addViewReference(trimId, -1, ref, true); // } // else // { // bool inMaximizedStack = vPart != 0 && vPart.getContainer() == presentation.getMaximizedStack(); // Do the default behavior presentation->AddPart(pane); // // Now, if we're maximized then we have to minimize the new stack // if (presentation.getMaximizedStack() != 0 && !inMaximizedStack) // { // vPart = presentation.findPart(viewId, secondaryId); // if (vPart != 0 && vPart.getContainer().Cast() != 0) // { // ViewStack vs = (ViewStack)vPart.getContainer(); // vs.setState(IStackPresentationSite.STATE_MINIMIZED); // // // setting the state to minimized will create the trim toolbar // // so we don't need a 0 pointer check here... // fastViewManager.getViewStackTrimToolbar(vs.getID()).setRestoreOnUnzoom(true); // } // } // } } else { presentation->AddPart(pane); } //} // Ensure that the newly showing part is enabled if (pane != 0 && pane->GetControl() != 0) Tweaklets::Get(GuiWidgetsTweaklet::KEY)->SetEnabled(pane->GetControl(), true); return part; } IWorkbenchPartReference::Pointer Perspective::GetOldPartRef() { return oldPartRef; } void Perspective::SetOldPartRef(IWorkbenchPartReference::Pointer oldPartRef) { this->oldPartRef = oldPartRef; } bool Perspective::IsCloseable(IViewReference::Pointer reference) { ViewLayoutRec::Pointer rec = this->GetViewLayoutRec(reference, false); if (rec != 0) { return rec->isCloseable; } return true; } bool Perspective::IsMoveable(IViewReference::Pointer reference) { ViewLayoutRec::Pointer rec = this->GetViewLayoutRec(reference, false); if (rec != 0) { return rec->isMoveable; } return true; } void Perspective::DescribeLayout(std::string& buf) const { // std::vector fastViews = getFastViews(); // // if (fastViews.length != 0) // { // buf.append("fastviews ("); //$NON-NLS-1$ // for (int idx = 0; idx < fastViews.length; idx++) // { // IViewReference ref = fastViews[idx]; // // if (idx> 0) // { // buf.append(", "); //$NON-NLS-1$ // } // // buf.append(ref.getPartName()); // } // buf.append("), "); //$NON-NLS-1$ // } this->GetPresentation()->DescribeLayout(buf); } void Perspective::TestInvariants() { this->GetPresentation()->GetLayout()->TestInvariants(); } bool Perspective::UseNewMinMax(Perspective::Pointer activePerspective) { // We need to have an active perspective if (activePerspective == 0) return false; // We need to have a trim manager (if we don't then we // don't create a FastViewManager because it'd be useless) // if (activePerspective->GetFastViewManager() == 0) // return false; // Make sure we don't NPE anyplace WorkbenchWindow::Pointer wbw = activePerspective->page->GetWorkbenchWindow().Cast(); if (wbw == 0) return false; // WorkbenchWindowConfigurer* configurer = wbw->GetWindowConfigurer(); // if (configurer == 0) // return false; IPresentationFactory* factory = WorkbenchPlugin::GetDefault()->GetPresentationFactory(); if (factory == 0) return false; // Ok, we should be good to go, return the pref //IPreferenceStore preferenceStore = PrefUtil.getAPIPreferenceStore(); //bool useNewMinMax = preferenceStore.getbool(IWorkbenchPreferenceConstants.ENABLE_NEW_MIN_MAX); return true; } } diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPerspective.h b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPerspective.h index 1dc1a29f44..fd87dc46c1 100644 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPerspective.h +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPerspective.h @@ -1,628 +1,628 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef BERRYPERSPECTIVE_H_ #define BERRYPERSPECTIVE_H_ #include #include "berryPerspectiveDescriptor.h" #include "berryPartPlaceholder.h" #include "berryViewLayoutRec.h" #include "berryWorkbenchPage.h" #include "berryLayoutPart.h" #include "berryPageLayout.h" #include "berryPartPane.h" #include "berryIWorkbenchPartReference.h" #include "berryIViewReference.h" #include "berryIViewPart.h" #include #include #include namespace berry { class ViewFactory; class PerspectiveHelper; /** * \ingroup org_blueberry_ui_internal * */ class Perspective : public Object { public: berryObjectMacro(Perspective); friend class WorkbenchPage; private: ViewFactory* viewFactory; std::map mapIDtoViewLayoutRec; static const std::string VERSION_STRING; // = "0.016";//$NON-NLS-1$ /** * Reference to the part that was previously active * when this perspective was deactivated. */ IWorkbenchPartReference::Pointer oldPartRef; protected: PerspectiveDescriptor::Pointer descriptor; WorkbenchPage* page; // Editor Area management LayoutPart::Pointer editorArea; - ContainerPlaceholder::Pointer editorHolder; + PartPlaceholder::Pointer editorHolder; bool editorHidden; int editorAreaState; //ArrayList alwaysOnActionSets; //ArrayList alwaysOffActionSets; std::vector showViewShortcuts; std::vector perspectiveShortcuts; bool fixed; std::vector showInPartIds; //HashMap showInTimes; IMemento::Pointer memento; PerspectiveHelper* presentation; bool shouldHideEditorsOnActivate; PageLayout::Pointer layout; /** * ViewManager constructor comment. */ public: Perspective(PerspectiveDescriptor::Pointer desc, WorkbenchPage::Pointer page); /** * ViewManager constructor comment. */ protected: Perspective(WorkbenchPage::Pointer page); protected: void Init(WorkbenchPage::Pointer page); /** * Moves a part forward in the Z order of a perspective so it is visible. * * @param part the part to bring to move forward * @return true if the part was brought to top, false if not. */ public: bool BringToTop(IViewReference::Pointer ref); /** * Returns whether a view exists within the perspective. */ public: bool ContainsView(IViewPart::Pointer view); /** * Create the initial list of action sets. */ // protected: void CreateInitialActionSets(List outputList, List stringList) { // ActionSetRegistry reg = WorkbenchPlugin.getDefault() // .getActionSetRegistry(); // Iterator iter = stringList.iterator(); // while (iter.hasNext()) { // String id = (String) iter.next(); // IActionSetDescriptor desc = reg.findActionSet(id); // if (desc != null) { // outputList.add(desc); // } else { // WorkbenchPlugin.log("Unable to find Action Set: " + id);//$NON-NLS-1$ // } // } // } /** * Create a presentation for a perspective. */ private: void CreatePresentation(PerspectiveDescriptor::Pointer persp); /** * Dispose the perspective and all views contained within. */ public: ~Perspective(); private: void DisposeViewRefs(); /** * Finds the view with the given ID that is open in this page, or null * if not found. * * @param viewId the view ID */ public: IViewReference::Pointer FindView(const std::string& viewId); /** * Finds the view with the given id and secondary id that is open in this page, * or null if not found. * * @param viewId the view ID * @param secondaryId the secondary ID */ public: IViewReference::Pointer FindView(const std::string& id, const std::string& secondaryId); /** * Returns the window's client composite widget * which views and editor area will be parented. */ public: void* GetClientComposite(); /** * Returns the perspective. */ public: IPerspectiveDescriptor::Pointer GetDesc(); /** * Returns the pane for a view reference. */ protected: PartPane::Pointer GetPane(IViewReference::Pointer ref); /** * Returns the perspective shortcuts associated with this perspective. * * @return an array of perspective identifiers */ public: std::vector GetPerspectiveShortcuts(); /** * Returns the presentation. */ public: PerspectiveHelper* GetPresentation() const; /** * Returns the show view shortcuts associated with this perspective. * * @return an array of view identifiers */ public: std::vector GetShowViewShortcuts(); /** * Returns the view factory. */ public: ViewFactory* GetViewFactory(); /** * See IWorkbenchPage. */ public: std::vector GetViewReferences(); /** * Hide the editor area if visible */ protected: void HideEditorArea(); /** * Hide the editor area if visible */ protected: void HideEditorAreaLocal(); public: bool HideView(IViewReference::Pointer ref); /* * Return whether the editor area is visible or not. */ protected: bool IsEditorAreaVisible(); /** * Returns the view layout rec for the given view reference, * or null if not found. If create is true, it creates the record * if not already created. */ public: ViewLayoutRec::Pointer GetViewLayoutRec(IViewReference::Pointer ref, bool create); /** * Returns the view layout record for the given view id * or null if not found. If create is true, it creates the record * if not already created. */ private: ViewLayoutRec::Pointer GetViewLayoutRec(const std::string& viewId, bool create); /** * Returns true if a layout or perspective is fixed. */ public: bool IsFixedLayout(); /** * Returns true if a view is standalone. * * @since 3.0 */ public: bool IsStandaloneView(IViewReference::Pointer ref); /** * Returns whether the title for a view should * be shown. This applies only to standalone views. * * @since 3.0 */ public: bool GetShowTitleView(IViewReference::Pointer ref); /** * Creates a new presentation from a persistence file. * Note: This method should not modify the current state of the perspective. */ private: void LoadCustomPersp(PerspectiveDescriptor::Pointer persp); private: void UnableToOpenPerspective(PerspectiveDescriptor::Pointer persp, const std::string& status); /** * Create a presentation for a perspective. * Note: This method should not modify the current state of the perspective. */ protected: void LoadPredefinedPersp(PerspectiveDescriptor::Pointer persp); // private: void RemoveAlwaysOn(IActionSetDescriptor::Pointer descriptor) { // if (descriptor == null) { // return; // } // if (!alwaysOnActionSets.contains(descriptor)) { // return; // } // // alwaysOnActionSets.remove(descriptor); // if (page != null) { // page.perspectiveActionSetChanged(this, descriptor, ActionSetManager.CHANGE_HIDE); // } // } // protected: void AddAlwaysOff(IActionSetDescriptor descriptor) { // if (descriptor == null) { // return; // } // if (alwaysOffActionSets.contains(descriptor)) { // return; // } // alwaysOffActionSets.add(descriptor); // if (page != null) { // page.perspectiveActionSetChanged(this, descriptor, ActionSetManager.CHANGE_MASK); // } // removeAlwaysOn(descriptor); // } // protected: void AddAlwaysOn(IActionSetDescriptor descriptor) { // if (descriptor == null) { // return; // } // if (alwaysOnActionSets.contains(descriptor)) { // return; // } // alwaysOnActionSets.add(descriptor); // if (page != null) { // page.perspectiveActionSetChanged(this, descriptor, ActionSetManager.CHANGE_SHOW); // } // removeAlwaysOff(descriptor); // } // private: void RemoveAlwaysOff(IActionSetDescriptor descriptor) { // if (descriptor == null) { // return; // } // if (!alwaysOffActionSets.contains(descriptor)) { // return; // } // alwaysOffActionSets.remove(descriptor); // if (page != null) { // page.perspectiveActionSetChanged(this, descriptor, ActionSetManager.CHANGE_UNMASK); // } // } /** * activate. */ protected: void OnActivate(); /** * deactivate. */ protected: void OnDeactivate(); /** * Notifies that a part has been activated. */ public: void PartActivated(IWorkbenchPart::Pointer activePart); /** * The user successfully performed a Show In... action on the specified part. * Update the history. */ public: void PerformedShowIn(const std::string& partId); /** * Fills a presentation with layout data. * Note: This method should not modify the current state of the perspective. */ public: bool RestoreState(IMemento::Pointer memento); bool CreateReferences(const std::vector& views); /** * Fills a presentation with layout data. * Note: This method should not modify the current state of the perspective. */ public: bool RestoreState(); /** * Returns the ActionSets read from perspectiveExtensions in the registry. */ // protected: ArrayList GetPerspectiveExtensionActionSets() { // PerspectiveExtensionReader reader = new PerspectiveExtensionReader(); // reader // .setIncludeOnlyTags(new String[] { IWorkbenchRegistryConstants.TAG_ACTION_SET }); // PageLayout layout = new PageLayout(); // reader.extendLayout(null, descriptor.getOriginalId(), layout); // return layout.getActionSets(); // } /** * Returns the Show In... part ids read from the registry. */ protected: std::vector GetShowInIdsFromRegistry(); /** * Save the layout. */ public: void SaveDesc(); /** * Save the layout. */ public: void SaveDescAs(IPerspectiveDescriptor::Pointer desc); /** * Save the layout. */ public: bool SaveState(IMemento::Pointer memento); /** * Save the layout. */ private: bool SaveState(IMemento::Pointer memento, PerspectiveDescriptor::Pointer p, bool saveInnerViewState); // public: void turnOnActionSets(IActionSetDescriptor[] newArray) { // for (int i = 0; i < newArray.length; i++) { // IActionSetDescriptor descriptor = newArray[i]; // // addAlwaysOn(descriptor); // } // } // public: void turnOffActionSets(IActionSetDescriptor[] toDisable) { // for (int i = 0; i < toDisable.length; i++) { // IActionSetDescriptor descriptor = toDisable[i]; // // turnOffActionSet(descriptor); // } // } // public: void turnOffActionSet(IActionSetDescriptor toDisable) { // addAlwaysOff(toDisable); // } /** * Sets the perspective actions for this page. * This is List of Strings. */ public: void SetPerspectiveActionIds(const std::vector& list); /** * Sets the ids of the parts to list in the Show In... prompter. * This is a List of Strings. */ public: void SetShowInPartIds(const std::vector& list); /** * Sets the ids of the views to list in the Show View shortcuts. * This is a List of Strings. */ public: void SetShowViewActionIds(const std::vector& list); /** * Show the editor area if not visible */ protected: void ShowEditorArea(); /** * Show the editor area if not visible */ protected: void ShowEditorAreaLocal(); public: void SetEditorAreaState(int newState); public: int GetEditorAreaState(); /** * */ public: void RefreshEditorAreaVisibility(); /** * Resolves a view's id into its reference, creating the * view if necessary. * * @param viewId The primary id of the view (must not be * null * @param secondaryId The secondary id of a multiple-instance view * (may be null). * * @return The reference to the specified view. This may be null if the * view fails to create (i.e. thrown a PartInitException) */ public: IViewReference::Pointer GetViewReference(const std::string& viewId, const std::string& secondaryId); /** * Shows the view with the given id and secondary id. */ public: IViewPart::Pointer ShowView(const std::string& viewId, const std::string& secondaryId); /** * Returns the old part reference. * Returns null if there was no previously active part. * * @return the old part reference or null */ public: IWorkbenchPartReference::Pointer GetOldPartRef(); /** * Sets the old part reference. * * @param oldPartRef The old part reference to set, or null */ public: void SetOldPartRef(IWorkbenchPartReference::Pointer oldPartRef); // //for dynamic UI // protected: void AddActionSet(IActionSetDescriptor newDesc) { // IContextService service = (IContextService)page.getWorkbenchWindow().getService(IContextService.class); // try { // service.activateContext(ContextAuthority.DEFER_EVENTS); // for (int i = 0; i < alwaysOnActionSets.size(); i++) { // IActionSetDescriptor desc = (IActionSetDescriptor) alwaysOnActionSets // .get(i); // if (desc.getId().equals(newDesc.getId())) { // removeAlwaysOn(desc); // removeAlwaysOff(desc); // break; // } // } // addAlwaysOn(newDesc); // } finally { // service.activateContext(ContextAuthority.SEND_EVENTS); // } // } // // for dynamic UI // /* package */void removeActionSet(String id) { // IContextService service = (IContextService)page.getWorkbenchWindow().getService(IContextService.class); // try { // service.activateContext(ContextAuthority.DEFER_EVENTS); // for (int i = 0; i < alwaysOnActionSets.size(); i++) { // IActionSetDescriptor desc = (IActionSetDescriptor) alwaysOnActionSets // .get(i); // if (desc.getId().equals(id)) { // removeAlwaysOn(desc); // break; // } // } // // for (int i = 0; i < alwaysOffActionSets.size(); i++) { // IActionSetDescriptor desc = (IActionSetDescriptor) alwaysOffActionSets // .get(i); // if (desc.getId().equals(id)) { // removeAlwaysOff(desc); // break; // } // } // } finally { // service.activateContext(ContextAuthority.SEND_EVENTS); // } // } // void removeActionSet(IActionSetDescriptor toRemove) { // removeAlwaysOn(toRemove); // removeAlwaysOff(toRemove); // } /** * Returns whether the given view is closeable in this perspective. * * @since 3.0 */ public: bool IsCloseable(IViewReference::Pointer reference); /** * Returns whether the given view is moveable in this perspective. * * @since 3.0 */ public: bool IsMoveable(IViewReference::Pointer reference); /** * Writes a description of the layout to the given string buffer. * This is used for drag-drop test suites to determine if two layouts are the * same. Like a hash code, the description should compare as equal iff the * layouts are the same. However, it should be user-readable in order to * help debug failed tests. Although these are english readable strings, * they should not be translated or equality tests will fail. *

    * This is only intended for use by test suites. *

    * * @param buf */ public: void DescribeLayout(std::string& buf) const; /** * Sanity-checks the LayoutParts in this perspective. Throws an Assertation exception * if an object's internal state is invalid. */ public: void TestInvariants(); // public: IActionSetDescriptor[] getAlwaysOnActionSets() { // return (IActionSetDescriptor[]) alwaysOnActionSets.toArray(new IActionSetDescriptor[alwaysOnActionSets.size()]); // } // public: IActionSetDescriptor[] getAlwaysOffActionSets() { // return (IActionSetDescriptor[]) alwaysOffActionSets.toArray(new IActionSetDescriptor[alwaysOffActionSets.size()]); // } /** * Used to restrict the use of the new min/max behavior to envoronments * in which it has a chance of working... * * @param activePerspective We pass this in as an arg so others won't have * to check it for 'null' (which is one of the failure cases) * */ public: static bool UseNewMinMax(Perspective::Pointer activePerspective); }; } #endif /*BERRYPERSPECTIVE_H_*/ diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPerspectiveHelper.cpp b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPerspectiveHelper.cpp index 8b27ed2eb1..f8042a2d38 100755 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPerspectiveHelper.cpp +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPerspectiveHelper.cpp @@ -1,1673 +1,1495 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "tweaklets/berryGuiWidgetsTweaklet.h" #include "berryPerspectiveHelper.h" #include "berryLayoutTree.h" #include "berryEditorSashContainer.h" #include "berryDragUtil.h" #include "berryPresentationFactoryUtil.h" #include "berryWorkbenchConstants.h" #include #include namespace berry { const int PerspectiveHelper::MIN_DETACH_WIDTH = 150; const int PerspectiveHelper::MIN_DETACH_HEIGHT = 250; PerspectiveHelper::DragOverListener::DragOverListener(PerspectiveHelper* perspHelper) : perspHelper(perspHelper) { } IDropTarget::Pointer PerspectiveHelper::DragOverListener::Drag( void* /*currentControl*/, Object::Pointer draggedObject, const Point& /*position*/, const Rectangle& dragRectangle) { if (draggedObject.Cast() != 0) { PartPane::Pointer part = draggedObject.Cast(); if (part->GetContainer().Cast()->GetAppearance() == PresentationFactoryUtil::ROLE_EDITOR) return IDropTarget::Pointer(0); // Views that haven't been shown yet have no 'control' which causes // 'GetWorkbenchWindow' to return 'null' so check explicitly if (part->GetPage() != perspHelper->page) return IDropTarget::Pointer(0); else if (part->GetWorkbenchWindow() != perspHelper->page->GetWorkbenchWindow()) return IDropTarget::Pointer(0); if (perspHelper->dropTarget == 0) perspHelper->dropTarget = new ActualDropTarget(perspHelper, part, dragRectangle); else perspHelper->dropTarget->SetTarget(part, dragRectangle); } else if (draggedObject.Cast() != 0) { PartStack::Pointer stack = draggedObject.Cast(); if (stack->GetAppearance() == PresentationFactoryUtil::ROLE_EDITOR) return IDropTarget::Pointer(0); if (stack->GetWorkbenchWindow() != perspHelper->page->GetWorkbenchWindow()) return IDropTarget::Pointer(0); if (perspHelper->dropTarget == 0) perspHelper->dropTarget = new ActualDropTarget(perspHelper, stack, dragRectangle); else perspHelper->dropTarget->SetTarget(stack, dragRectangle); } return perspHelper->dropTarget; } void PerspectiveHelper::ActualDropTarget::SetTarget(PartPane::Pointer part, const Rectangle& dragRectangle) { this->stack = 0; this->part = part; this->dragRectangle = dragRectangle; } void PerspectiveHelper::ActualDropTarget::SetTarget(PartStack::Pointer stack, const Rectangle& dragRectangle) { this->stack = stack; this->part = 0; this->dragRectangle = dragRectangle; } PerspectiveHelper::ActualDropTarget::ActualDropTarget(PerspectiveHelper* perspHelper, PartPane::Pointer part, const Rectangle& dragRectangle) : AbstractDropTarget(), perspHelper(perspHelper) { this->SetTarget(part, dragRectangle); } PerspectiveHelper::ActualDropTarget::ActualDropTarget(PerspectiveHelper* perspHelper, PartStack::Pointer stack, const Rectangle& dragRectangle) : AbstractDropTarget(), perspHelper(perspHelper) { this->SetTarget(stack, dragRectangle); } void PerspectiveHelper::ActualDropTarget::Drop() { if (part != 0) { Shell::Pointer shell = part->GetShell(); if (shell->GetData().Cast () != 0) { // if only one view in tab folder then do a window move - IStackableContainer::Pointer container = part->GetContainer(); + ILayoutContainer::Pointer container = part->GetContainer(); if (container.Cast () != 0) { if (container.Cast()->GetItemCount() == 1) { shell->SetLocation(dragRectangle.x, dragRectangle.y); return; } } } // // If layout is modified always zoom out. // if (isZoomed()) // { // zoomOut(); // } // do a normal part detach perspHelper->DetachPart(part, dragRectangle.x, dragRectangle.y); } else if (stack != 0) { Shell::Pointer shell = stack->GetShell(); if (shell->GetData().Cast () != 0) { // only one tab folder in a detach window, so do window // move shell->SetLocation(dragRectangle.x, dragRectangle.y); return; } // // If layout is modified always zoom out. // if (isZoomed()) // { // zoomOut(); // } // do a normal part detach perspHelper->Detach(stack, dragRectangle.x, dragRectangle.y); } } DnDTweaklet::CursorType PerspectiveHelper::ActualDropTarget::GetCursor() { return DnDTweaklet::CURSOR_OFFSCREEN; } PerspectiveHelper::MatchingPart::MatchingPart(const std::string& pid, - const std::string& sid, StackablePart::Pointer part) + const std::string& sid, LayoutPart::Pointer part) { this->pid = pid; this->sid = sid; this->part = part; this->len = pid.size() + sid.size(); this->hasWildcard = (pid.find_first_of(PartPlaceholder::WILD_CARD) != std::string::npos) || (sid.find_first_of(PartPlaceholder::WILD_CARD) != std::string::npos); } bool PerspectiveHelper::CompareMatchingParts::operator()(const MatchingPart& m1, const MatchingPart& m2) const { // specific ids always outweigh ids with wildcards if (m1.hasWildcard && !m2.hasWildcard) { return true; } if (!m1.hasWildcard && m2.hasWildcard) { return false; } // if both are specific or both have wildcards, simply compare based on length return m1.len > m2.len; } PerspectiveHelper::PerspectiveHelper(WorkbenchPage* workbenchPage, ViewSashContainer::Pointer mainLayout, Perspective::Pointer persp) : page(workbenchPage), perspective(persp), mainLayout(mainLayout), detachable(false), active(false) { // Views can be detached if the feature is enabled (true by default, // use the plug-in customization file to disable), and if the platform // supports detaching. this->dragTarget = new DragOverListener(this); //TODO preference store // IPreferenceStore store = PlatformUI.getPreferenceStore(); // this.detachable = store.getBoolean( // IWorkbenchPreferenceConstants.ENABLE_DETACHED_VIEWS); this->detachable = true; if (this->detachable) { // Check if some arbitrary Composite supports reparenting. If it // doesn't, views cannot be detached. void* client = workbenchPage->GetClientComposite(); if (client == 0) { // The workbench page is not initialized. I don't think this can happen, // but if it does, silently set detachable to false. this->detachable = false; } else { this->detachable = Tweaklets::Get(GuiWidgetsTweaklet::KEY)->IsReparentable(client); } } } void PerspectiveHelper::Activate(void* parent) { if (active) { return; } parentWidget = parent; // Activate main layout // make sure all the views have been properly parented std::vector children; this->CollectViewPanes(children, mainLayout->GetChildren()); for (std::vector::iterator iter = children.begin(); iter != children.end(); ++iter) { PartPane::Pointer part = *iter; part->Reparent(parent); } mainLayout->CreateControl(parent); mainLayout->SetActive(true); // Open the detached windows. for (DetachedWindowsType::iterator iter = detachedWindowList.begin(); iter != detachedWindowList.end(); ++iter) { (*iter)->Open(); } this->EnableAllDrag(); // // Ensure that the maximized stack's presentation state is correct // if (maximizedStackId != 0) // { // LayoutPart part = this->FindPart(maximizedStackId); // if (part.Cast() != 0) // { // maximizedStack = (PartStack) part; // maximizedStackId = 0; // } // } // // // NOTE: we only handle ViewStacks here; Editor Stacks are handled by the // // perspective // if (maximizedStack instanceof ViewStack) // { // maximizedStack.setPresentationState(IStackPresentationSite.STATE_MAXIMIZED); // } active = true; } -void PerspectiveHelper::AddPart(StackablePart::Pointer part) +void PerspectiveHelper::AddPart(LayoutPart::Pointer part) { // Look for a placeholder. PartPlaceholder::Pointer placeholder; - StackablePart::Pointer testPart; - std::string primaryId = part->GetId(); + LayoutPart::Pointer testPart; + std::string primaryId = part->GetID(); std::string secondaryId; IViewReference::Pointer ref; if (part.Cast () != 0) { PartPane::Pointer pane = part.Cast (); ref = pane->GetPartReference().Cast (); if (ref != 0) secondaryId = ref->GetSecondaryId(); } if (secondaryId != "") { testPart = this->FindPart(primaryId, secondaryId); } else { testPart = this->FindPart(primaryId); } // validate the testPart if (testPart != 0 && testPart.Cast() != 0) { placeholder = testPart.Cast (); } // If there is no placeholder do a simple add. Otherwise, replace the // placeholder if its not a pattern matching placholder if (placeholder == 0) { part->Reparent(mainLayout->GetParent()); LayoutPart::Pointer relative = mainLayout->FindBottomRight(); - if (relative != 0 && relative.Cast() != 0) + if (relative != 0 && relative.Cast() != 0) { - IStackableContainer::Pointer stack = - relative.Cast (); + ILayoutContainer::Pointer stack = + relative.Cast (); if (stack->AllowsAdd(part)) { mainLayout->Stack(part, stack); } else { mainLayout->AddPart(part); } } else { mainLayout->AddPart(part); } } else { - IStackableContainer::Pointer container = placeholder->GetContainer(); + ILayoutContainer::Pointer container = placeholder->GetContainer(); if (container != 0) { if (container.Cast () != 0) { //Create a detached window add the part on it. DetachedPlaceHolder::Pointer holder = container.Cast(); detachedPlaceHolderList.remove(holder); container->Remove(testPart); DetachedWindow::Pointer window(new DetachedWindow(page)); detachedWindowList.push_back(window); window->Create(); part->CreateControl(window->GetShell()->GetControl()); // Open window. window->GetShell()->SetBounds(holder->GetBounds()); window->Open(); // add part to detached window. PartPane::Pointer pane = part.Cast(); window->Add(pane); - std::list otherChildren = holder->GetChildren(); - for (std::list::iterator iter = otherChildren.begin(); + std::list otherChildren = holder->GetChildren(); + for (std::list::iterator iter = otherChildren.begin(); iter != otherChildren.end(); ++iter) { part->GetContainer()->Add(*iter); } } else { // show parent if necessary if (container.Cast () != 0) { ContainerPlaceholder::Pointer containerPlaceholder = - container.Cast(); + container.Cast(); ILayoutContainer::Pointer parentContainer = - containerPlaceholder->GetContainer(); - container = containerPlaceholder->GetRealContainer(); + containerPlaceholder->GetContainer(); + if (parentContainer == 0) return; + + container = containerPlaceholder->GetRealContainer().Cast(); if (container.Cast () != 0) { parentContainer->Replace(containerPlaceholder, container.Cast()); } - containerPlaceholder->SetRealContainer(IStackableContainer::Pointer(0)); + containerPlaceholder->SetRealContainer(ILayoutContainer::Pointer(0)); } - // reparent part. - //if (!(container instanceof ViewStack)) - // { - // We don't need to reparent children of PartTabFolders since they will automatically - // reparent their children when they become visible. This if statement used to be - // part of an else branch. Investigate if it is still necessary. - // part.reparent(mainLayout.getParent()); - // } +// // reparent part. +// if (container.Cast() == 0) +// { +// // We don't need to reparent children of PartTabFolders since they will automatically +// // reparent their children when they become visible. This if statement used to be +// // part of an else branch. Investigate if it is still necessary. +// part->Reparent(mainLayout->GetParent()); +// } // see if we should replace the placeholder if (placeholder->HasWildCard()) { - // if (container instanceof PartSashContainer) - // { - // ((PartSashContainer) container) .addChildForPlaceholder(part, - // placeholder); - // } - // else - // { - container->Add(part); - // } + if (PartSashContainer::Pointer sashContainer = container.Cast()) + { + sashContainer->AddChildForPlaceholder(part, placeholder); + } + else + { + container->Add(part); + } } else { container->Replace(placeholder, part); } } } } } void PerspectiveHelper::AttachPart(IViewReference::Pointer ref) { PartPane::Pointer pane = ref.Cast()->GetPane(); // Restore any maximized part before re-attaching. // Note that 'getMaximizedStack != 0' implies 'useNewMinMax' // if (getMaximizedStack() != 0) // { // getMaximizedStack().setState(IStackPresentationSite.STATE_RESTORED); // } this->DerefPart(pane); this->AddPart(pane); this->BringPartToTop(pane); pane->SetFocus(); } bool PerspectiveHelper::CanDetach() { return detachable; } -bool PerspectiveHelper::BringPartToTop(StackablePart::Pointer part) +bool PerspectiveHelper::BringPartToTop(LayoutPart::Pointer part) { - IStackableContainer::Pointer container = part->GetContainer(); + ILayoutContainer::Pointer container = part->GetContainer(); if (container != 0 && container.Cast () != 0) { PartStack::Pointer folder = container.Cast (); if (folder->GetSelection() != part) { folder->SetSelection(part); return true; } } return false; } bool PerspectiveHelper::IsPartVisible(IWorkbenchPartReference::Pointer partRef) { - StackablePart::Pointer foundPart; + LayoutPart::Pointer foundPart; if (partRef.Cast () != 0) { foundPart = this->FindPart(partRef->GetId(), partRef.Cast()->GetSecondaryId()); } else { foundPart = this->FindPart(partRef->GetId()); } if (foundPart == 0) { return false; } if (foundPart.Cast () != 0) { return false; } - IStackableContainer::Pointer container = foundPart->GetContainer(); + ILayoutContainer::Pointer container = foundPart->GetContainer(); if (container.Cast () != 0) { return false; } if (container.Cast () != 0) { PartStack::Pointer folder = container.Cast(); - StackablePart::Pointer visiblePart = folder->GetSelection(); + LayoutPart::Pointer visiblePart = folder->GetSelection(); if (visiblePart == 0) { return false; } return partRef == visiblePart.Cast()->GetPartReference(); } return true; } bool PerspectiveHelper::WillPartBeVisible(const std::string& partId) { return this->WillPartBeVisible(partId, 0); } bool PerspectiveHelper::WillPartBeVisible(const std::string& partId, const std::string& secondaryId) { - StackablePart::Pointer part = this->FindPart(partId, secondaryId); + LayoutPart::Pointer part = this->FindPart(partId, secondaryId); if (part == 0) { return false; } - IStackableContainer::Pointer container = part->GetContainer(); + ILayoutContainer::Pointer container = part->GetContainer(); if (container != 0 && container.Cast () != 0) { - container - = container.Cast()->GetRealContainer(); + container = container.Cast()->GetRealContainer().Cast(); } if (container != 0 && container.Cast () != 0) { PartStack::Pointer folder = container.Cast(); if (folder->GetSelection() == 0) { return false; } - return part->GetCompoundId() == folder->GetSelection().Cast()->GetCompoundId(); + return part->GetID() == folder->GetSelection()->GetID(); } return true; } std::vector PerspectiveHelper::CollectPlaceholders() { // Scan the main window. std::vector results = this->CollectPlaceholders( mainLayout->GetChildren()); // Scan each detached window. if (detachable) { for (DetachedWindowsType::iterator winIter = detachedWindowList.begin(); winIter != detachedWindowList.end(); ++winIter) { DetachedWindow::Pointer win = *winIter; - std::list moreResults = win->GetChildren(); + std::list moreResults = win->GetChildren(); if (moreResults.size()> 0) { - for (std::list::iterator iter = moreResults.begin(); + for (std::list::iterator iter = moreResults.begin(); iter != moreResults.end(); ++iter) { if (iter->Cast() != 0) results.push_back(iter->Cast()); } } } } return results; } std::vector PerspectiveHelper::CollectPlaceholders( const std::list& parts) { std::vector result; for (std::list::const_iterator iter = parts.begin(); iter != parts.end(); ++iter) { LayoutPart::Pointer part = *iter; - if (part.Cast () != 0) + if (ILayoutContainer::Pointer container = part.Cast()) { // iterate through sub containers to find sub-parts std::vector newParts = this->CollectPlaceholders( - part.Cast()->GetChildren()); - result.insert(result.end(), newParts.begin(), newParts.end()); - } - else if (part.Cast () != 0) - { - std::list children = part.Cast()->GetChildren(); - for (std::list::iterator partIter = children.begin(); - partIter != children.end(); ++partIter) - { - if (partIter->Cast() != 0) - result.push_back(partIter->Cast()); - } - } - } - - return result; -} - -std::vector PerspectiveHelper::CollectContainerPlaceholders() -{ - // Scan the main window. - std::vector results(this->CollectContainerPlaceholders( - mainLayout->GetChildren())); - -// // Scan each detached window. -// if (detachable) -// { -// for (DetachedWindowsType::iterator winIter = detachedWindowList.begin(); -// winIter != detachedWindowList.end(); ++winIter) -// { -// DetachedWindow::Pointer win = *winIter; -// std::list moreResults = win->GetChildren(); -// if (moreResults.size()> 0) -// { -// for (std::list::iterator iter = moreResults.begin(); -// iter != moreResults.end(); ++iter) -// { -// if (iter->Cast() != 0) -// results.push_back(iter->Cast()); -// } -// } -// } -// } - return results; -} - -std::vector PerspectiveHelper::CollectContainerPlaceholders( - const std::list& parts) -{ - std::vector result; - - for (std::list::const_iterator iter = parts.begin(); - iter != parts.end(); ++iter) - { - LayoutPart::Pointer part = *iter; - if (part.Cast () != 0) - { - // iterate through sub containers to find sub-parts - std::vector newParts = this->CollectContainerPlaceholders( - part.Cast()->GetChildren()); + container->GetChildren()); result.insert(result.end(), newParts.begin(), newParts.end()); } - else if (part.Cast () != 0) + else if (PartPlaceholder::Pointer placeholder = part.Cast()) { - result.push_back(part.Cast()); + result.push_back(placeholder); } } return result; } void PerspectiveHelper::CollectViewPanes(std::vector& result) { // Scan the main window. this->CollectViewPanes(result, mainLayout->GetChildren()); // Scan each detached window. if (detachable) { for (DetachedWindowsType::iterator winIter = detachedWindowList.begin(); winIter != detachedWindowList.end(); ++winIter) { DetachedWindow::Pointer win = *winIter; - std::list moreResults = win->GetChildren(); - for (std::list::iterator iter = moreResults.begin(); - iter != moreResults.end(); ++iter) - { - if (iter->Cast() != 0) - result.push_back(iter->Cast()); - } + CollectViewPanes(result, win->GetChildren()); } } } void PerspectiveHelper::CollectViewPanes(std::vector& result, const std::list& parts) { for (std::list::const_iterator iter = parts.begin(); iter != parts.end(); ++iter) { LayoutPart::Pointer part = *iter; - if (part.Cast () != 0 && part.Cast()->GetAppearance() != PresentationFactoryUtil::ROLE_EDITOR) + if (PartPane::Pointer partPane = part.Cast()) { - std::list children = part.Cast()->GetChildren(); - for (std::list::iterator partIter = children.begin(); - partIter != children.end(); ++partIter) + if(partPane->GetPartReference().Cast()) { - if (partIter->Cast() != 0) - result.push_back(partIter->Cast()); + result.push_back(partPane); } } - else if (part.Cast () != 0) + else if (ILayoutContainer::Pointer container = part.Cast ()) { - this->CollectViewPanes(result, part.Cast()->GetChildren()); + this->CollectViewPanes(result, container->GetChildren()); } } } void PerspectiveHelper::Deactivate() { if (!active) { return; } this->DisableAllDrag(); // Reparent all views to the main window void* parent = mainLayout->GetParent(); std::vector children; this->CollectViewPanes(children, mainLayout->GetChildren()); for (DetachedWindowsType::iterator winIter = detachedWindowList.begin(); winIter != detachedWindowList.end(); ++winIter) { DetachedWindow::Pointer window = *winIter; - std::list moreResults = window->GetChildren(); - for (std::list::iterator iter = moreResults.begin(); - iter != moreResults.end(); ++iter) - { - if (iter->Cast() != 0) - children.push_back(iter->Cast()); - } + CollectViewPanes(children, window->GetChildren()); } // *** Do we even need to do this if detached windows not supported? for (std::vector::iterator itr = children.begin(); itr != children.end(); ++itr) { PartPane::Pointer part = *itr; part->Reparent(parent); } // Dispose main layout. mainLayout->SetActive(false); // Dispose the detached windows for (DetachedWindowsType::iterator iter = detachedWindowList.begin(); iter != detachedWindowList.end(); ++iter) { (*iter)->Close(); } active = false; } PerspectiveHelper::~PerspectiveHelper() { mainLayout->Dispose(); mainLayout->DisposeSashes(); } void PerspectiveHelper::DescribeLayout(std::string& buf) const { if (detachable) { if (detachedWindowList.size() != 0) { buf.append("detachedWindows ("); //$NON-NLS-1$ for (DetachedWindowsType::const_iterator winIter = detachedWindowList.begin(); winIter != detachedWindowList.end(); ++winIter) { DetachedWindow::ConstPointer window = *winIter; - std::list children = window->GetChildren(); + std::list children = window->GetChildren(); unsigned int j = 0; if (children.size() != 0) { buf.append("dWindow ("); //$NON-NLS-1$ - for (std::list::iterator partIter = children.begin(); + for (std::list::iterator partIter = children.begin(); partIter != children.end(); ++partIter, ++j) { if (partIter->Cast() != 0) buf.append(partIter->Cast()->GetPlaceHolderId()); else if (partIter->Cast() != 0) buf.append( partIter->Cast()->GetPartReference()->GetPartName()); if (j < (children.size() - 1)) { buf.append(", "); //$NON-NLS-1$ } } buf.append(")"); //$NON-NLS-1$ } } buf.append("), "); //$NON-NLS-1$ } } this->GetLayout()->DescribeLayout(buf); } -void PerspectiveHelper::DerefPart(StackablePart::Pointer part) +void PerspectiveHelper::DerefPart(LayoutPart::Pointer part) { // if (part.Cast () != 0) // { // IViewReference::Pointer ref = ((ViewPane) part).getViewReference(); // if (perspective.isFastView(ref)) // { // // Special check: if it's a fast view then it's actual ViewStack // // may only contain placeholders and the stack is represented in // // the presentation by a container placeholder...make sure the // // PartPlaceHolder for 'ref' is removed from the ViewStack // String id = perspective.getFastViewManager().getIdForRef(ref); // LayoutPart parentPart = findPart(id, 0); // if (parentPart.Cast () != 0) // { // ViewStack vs = // (ViewStack) ((ContainerPlaceholder) parentPart).getRealContainer(); // std::vector kids = vs.getChildren(); // for (int i = 0; i < kids.length; i++) // { // if (kids[i].Cast () != 0) // { // if (ref.getId().equals(kids[i].id)) // vs.remove(kids[i]); // } // } // } // perspective.getFastViewManager().removeViewReference(ref, true, true); // } // } // Get vital part stats before reparenting. - IStackableContainer::Pointer oldContainer = part->GetContainer(); + ILayoutContainer::Pointer oldContainer = part->GetContainer(); bool wasDocked = part->IsDocked(); Shell::Pointer oldShell = part->GetShell(); // Reparent the part back to the main window part->Reparent(mainLayout->GetParent()); // Update container. if (oldContainer == 0) { return; } oldContainer->Remove(part); - IStackableContainer::ChildrenType children = oldContainer->GetChildren(); + ILayoutContainer::ChildrenType children = oldContainer->GetChildren(); if (wasDocked) { bool hasChildren = (children.size()> 0); if (hasChildren) { // make sure one is at least visible int childVisible = 0; - for (IStackableContainer::ChildrenType::iterator iter = children.begin(); + for (ILayoutContainer::ChildrenType::iterator iter = children.begin(); iter != children.end(); ++iter) { if ((*iter)->GetControl() != 0) { childVisible++; } } // none visible, then reprarent and remove container if (oldContainer.Cast () != 0) { PartStack::Pointer folder = oldContainer.Cast(); // Is the part in the trim? bool inTrim = false; // // Safety check...there may be no FastViewManager // if (perspective.getFastViewManager() != 0) // inTrim // = perspective.getFastViewManager().getFastViews(folder.getID()).size() // > 0; if (childVisible == 0 && !inTrim) { ILayoutContainer::Pointer parentContainer = folder->GetContainer(); hasChildren = folder->GetChildren().size()> 0; // We maintain the stack as a place-holder if it has children // (which at this point would represent view place-holders) if (hasChildren) { folder->Dispose(); // replace the real container with a ContainerPlaceholder ContainerPlaceholder::Pointer placeholder( new ContainerPlaceholder(folder->GetID())); placeholder->SetRealContainer(folder); parentContainer->Replace(folder, placeholder); } } else if (childVisible == 1) { LayoutTree::Pointer layout = mainLayout->GetLayoutTree(); layout = layout->Find(folder); layout->SetBounds(layout->GetBounds()); } } } if (!hasChildren) { // There are no more children in this container, so get rid of // it if (oldContainer.Cast () != 0) { //BERRY_INFO << "No children left, removing container\n"; LayoutPart::Pointer parent = oldContainer.Cast(); ILayoutContainer::Pointer parentContainer = parent->GetContainer(); if (parentContainer != 0) { parentContainer->Remove(parent); parent->Print(std::cout); parent->Dispose(); } } } } else if (!wasDocked) { if (children.empty()) { // There are no more children in this container, so get rid of // it // Turn on redraw again just in case it was off. //oldShell.setRedraw(true); DetachedWindow::Pointer w = oldShell->GetData().Cast(); oldShell->Close(); detachedWindowList.remove(w); } else { // There are children. If none are visible hide detached // window. bool allInvisible = true; - for (IStackableContainer::ChildrenType::iterator iter = children.begin(); + for (ILayoutContainer::ChildrenType::iterator iter = children.begin(); iter != children.end(); ++iter) { if (iter->Cast () == 0) { allInvisible = false; break; } } if (allInvisible) { DetachedPlaceHolder::Pointer placeholder(new DetachedPlaceHolder("", oldShell->GetBounds())); - for (IStackableContainer::ChildrenType::iterator iter = children.begin(); + for (ILayoutContainer::ChildrenType::iterator iter = children.begin(); iter != children.end(); ++iter) { oldContainer->Remove(*iter); (*iter)->SetContainer(placeholder); placeholder->Add(*iter); } detachedPlaceHolderList.push_back(placeholder); DetachedWindow::Pointer w = oldShell->GetData().Cast(); oldShell->Close(); detachedWindowList.remove(w); } } } } void PerspectiveHelper::Detach(LayoutPart::Pointer part, int x, int y) { // Detaching is disabled on some platforms .. if (!detachable) { return; } // Calculate detached window size. Point size = part->GetSize(); if (size.x == 0 || size.y == 0) { ILayoutContainer::Pointer container = part->GetContainer(); if (container.Cast () != 0) { size = container.Cast()->GetSize(); } } int width = std::max(size.x, MIN_DETACH_WIDTH); int height = std::max(size.y, MIN_DETACH_HEIGHT); // Create detached window. DetachedWindow::Pointer window(new DetachedWindow(page)); detachedWindowList.push_back(window); // Open window. window->Create(); window->GetShell()->SetBounds(x, y, width, height); window->Open(); if (part.Cast () != 0) { //window.getShell().setRedraw(false); //parentWidget.setRedraw(false); PartStack::Pointer stack = part.Cast(); - StackablePart::Pointer visiblePart = stack->GetSelection(); - IStackableContainer::ChildrenType children = stack->GetChildren(); - for (IStackableContainer::ChildrenType::iterator iter = children.begin(); + LayoutPart::Pointer visiblePart = stack->GetSelection(); + ILayoutContainer::ChildrenType children = stack->GetChildren(); + for (ILayoutContainer::ChildrenType::iterator iter = children.begin(); iter != children.end(); ++iter) { - if (!(*iter)->IsPlaceHolder()) + if (PartPane::Pointer partPane = iter->Cast() + // && check it is a view? + ) { // remove the part from its current container this->DerefPart(*iter); // add part to detached window. window->Add(*iter); } } if (visiblePart != 0) { this->BringPartToTop(visiblePart); visiblePart->SetFocus(); } //window.getShell().setRedraw(true); //parentWidget.setRedraw(true); } } -void PerspectiveHelper::DetachPart(StackablePart::Pointer part, int x, int y) +void PerspectiveHelper::DetachPart(LayoutPart::Pointer part, int x, int y) { // Detaching is disabled on some platforms .. if (!detachable) { return; } // Calculate detached window size. Point size = part->GetSize(); if (size.x == 0 || size.y == 0) { - IStackableContainer::Pointer container = part->GetContainer(); + ILayoutContainer::Pointer container = part->GetContainer(); if (container.Cast () != 0) { size = container.Cast()->GetSize(); } } int width = std::max(size.x, MIN_DETACH_WIDTH); int height = std::max(size.y, MIN_DETACH_HEIGHT); // Create detached window. DetachedWindow::Pointer window(new DetachedWindow(page)); detachedWindowList.push_back(window); // Open window. window->Create(); window->GetShell()->SetBounds(x, y, width, height); window->Open(); // remove the part from its current container this->DerefPart(part); // add part to detached window. window->Add(part); part->SetFocus(); } void PerspectiveHelper::DetachPart(IViewReference::Pointer ref) { PartPane::Pointer pane = ref.Cast()->GetPane(); if (this->CanDetach() && pane != 0) { // if (getMaximizedStack() != 0) // getMaximizedStack().setState(IStackPresentationSite.STATE_RESTORED); Rectangle bounds = pane->GetParentBounds(); this->DetachPart(pane, bounds.x, bounds.y); } } -void PerspectiveHelper::AddDetachedPart(StackablePart::Pointer part) +void PerspectiveHelper::AddDetachedPart(LayoutPart::Pointer part) { // Calculate detached window size. Rectangle bounds = Tweaklets::Get(GuiWidgetsTweaklet::KEY)->GetShell(parentWidget)->GetBounds(); bounds.x = bounds.x + (bounds.width - 300) / 2; bounds.y = bounds.y + (bounds.height - 300) / 2; this->AddDetachedPart(part, bounds); } -void PerspectiveHelper::AddDetachedPart(StackablePart::Pointer part, +void PerspectiveHelper::AddDetachedPart(LayoutPart::Pointer part, const Rectangle& bounds) { // Detaching is disabled on some platforms .. if (!detachable) { this->AddPart(part); return; } // Create detached window. DetachedWindow::Pointer window(new DetachedWindow(page)); detachedWindowList.push_back(window); window->Create(); // add part to detached window. part->CreateControl(window->GetShell()->GetControl()); window->Add(part); // Open window. window->GetShell()->SetBounds(bounds.x, bounds.y, bounds.width, bounds.height); window->Open(); part->SetFocus(); } void PerspectiveHelper::DisableAllDrag() { DragUtil::RemoveDragTarget(0, dragTarget); } void PerspectiveHelper::EnableAllDrag() { DragUtil::AddDragTarget(0, dragTarget); } -StackablePart::Pointer PerspectiveHelper::FindPart(const std::string& id) +LayoutPart::Pointer PerspectiveHelper::FindPart(const std::string& id) { return this->FindPart(id, ""); } -StackablePart::Pointer PerspectiveHelper::FindPart(const std::string& primaryId, +LayoutPart::Pointer PerspectiveHelper::FindPart(const std::string& primaryId, const std::string& secondaryId) { //BERRY_INFO << "Looking for part: " << primaryId << ":" << secondaryId << std::endl; // check main window. std::vector matchingParts; - StackablePart::Pointer part = (secondaryId != "") ? this->FindPart(primaryId, secondaryId, + LayoutPart::Pointer part = (secondaryId != "") ? this->FindPart(primaryId, secondaryId, mainLayout->GetChildren(), matchingParts) : this->FindPart(primaryId, mainLayout->GetChildren(), matchingParts); if (part != 0) { return part; } // check each detached windows. for (DetachedWindowsType::iterator iter = detachedWindowList.begin(); iter != detachedWindowList.end(); ++iter) { DetachedWindow::Pointer window = *iter; part = (secondaryId != "") ? this->FindPart(primaryId, secondaryId, window->GetChildren(), matchingParts) : this->FindPart(primaryId, window->GetChildren(), matchingParts); if (part != 0) { return part; } } for (DetachedPlaceHoldersType::iterator iter = detachedPlaceHolderList.begin(); iter != detachedPlaceHolderList.end(); ++iter) { DetachedPlaceHolder::Pointer holder = *iter; part = (secondaryId != "") ? this->FindPart(primaryId, secondaryId, holder->GetChildren(), matchingParts) : this->FindPart(primaryId, holder->GetChildren(), matchingParts); if (part != 0) { return part; } } //BERRY_INFO << "Looking through the matched parts (count: " << matchingParts.size() << ")\n"; // sort the matching parts if (matchingParts.size()> 0) { std::partial_sort(matchingParts.begin(), (matchingParts.begin()), matchingParts.end(), CompareMatchingParts()); const MatchingPart& mostSignificantPart = matchingParts.front(); return mostSignificantPart.part; } // Not found. - return StackablePart::Pointer(0); -} - -StackablePart::Pointer PerspectiveHelper::FindPart(const std::string& id, - const std::list& parts, - std::vector& matchingParts) -{ - - //BERRY_INFO << "Looking for part " << id << " in a list of layout parts with size " << parts.size() << std::endl; - for (std::list::const_iterator iter = parts.begin(); - iter != parts.end(); ++iter) - { - LayoutPart::Pointer part = *iter; - if (part.Cast () != 0) - { - StackablePart::Pointer result = this->FindPart(id, part.Cast()->GetChildren(), - matchingParts); - if (result != 0) return result; - } - else if (part.Cast() != 0) - { - StackablePart::Pointer result = this->FindPart(id, part.Cast()->GetChildren(), - matchingParts); - if (result != 0) return result; - } - } - //BERRY_INFO << "Returning 0\n"; - return StackablePart::Pointer(0); + return LayoutPart::Pointer(0); } -LayoutPart::Pointer PerspectiveHelper::FindLayoutPart(const std::string& id, +LayoutPart::Pointer PerspectiveHelper::FindPart(const std::string& id, const std::list& parts, std::vector& matchingParts) { for (std::list::const_iterator iter = parts.begin(); iter != parts.end(); ++iter) { LayoutPart::Pointer part = *iter; // check for part equality, parts with secondary ids fail if (part->GetID() == id) - { - return part; - } - else if (part.Cast() != 0) - { - // Skip. - } - else if (part.Cast () != 0) - { - part = this->FindLayoutPart(id, part.Cast()->GetChildren(), - matchingParts); - return part; - } - } - return LayoutPart::Pointer(0); -} - -StackablePart::Pointer PerspectiveHelper::FindPart(const std::string& id, - const std::list& parts, - std::vector& matchingParts) -{ - //BERRY_INFO << "Looking for part " << id << " in a list of stackable parts with size " << parts.size() << std::endl; - for (std::list::const_iterator iter = parts.begin(); - iter != parts.end(); ++iter) - { - StackablePart::Pointer part = *iter; - // check for part equality, parts with secondary ids fail - if (part->GetId() == id) { if (part.Cast () != 0) { PartPane::Pointer pane = part.Cast(); IViewReference::Pointer ref = pane->GetPartReference().Cast(); if (ref->GetSecondaryId() != "") { continue; } } return part; } // check pattern matching placeholders - else if (part.Cast() != 0 - && part.Cast()->HasWildCard()) + else if (part->IsPlaceHolder() + && part.Cast()->HasWildCard()) { Poco::RegularExpression re(id, Poco::RegularExpression::RE_CASELESS); - if (re.match(part->GetId())) + if (re.match(part->GetID())) { - matchingParts.push_back(MatchingPart(part->GetId(), "", part)); + matchingParts.push_back(MatchingPart(part->GetID(), "", part)); } // StringMatcher sm = new StringMatcher(part.getID(), true, false); // if (sm.match(id)) // { // matchingParts .add(new MatchingPart(part.getID(), 0, part)); // } } + else if (ILayoutContainer::Pointer layoutContainer = part.Cast()) + { + part = FindPart(id, layoutContainer->GetChildren(), + matchingParts); + if (part) + { + return part; + } + } } //BERRY_INFO << "Returning 0\n"; - return StackablePart::Pointer(0); + return LayoutPart::Pointer(0); } -StackablePart::Pointer PerspectiveHelper::FindPart(const std::string& primaryId, +LayoutPart::Pointer PerspectiveHelper::FindPart(const std::string& primaryId, const std::string& secondaryId, const std::list& parts, std::vector& matchingParts) { for (std::list::const_iterator iter = parts.begin(); iter != parts.end(); ++iter) { LayoutPart::Pointer part = *iter; // check containers first - if (part.Cast() != 0) + if (ILayoutContainer::Pointer layoutContainer = part.Cast()) { - // skip - } - else if (part.Cast () != 0) - { - StackablePart::Pointer testPart = this->FindPart(primaryId, secondaryId, - part.Cast()->GetChildren(), matchingParts); - if (testPart != 0) + LayoutPart::Pointer testPart = FindPart(primaryId, secondaryId, + layoutContainer->GetChildren(), matchingParts); + if (testPart) { return testPart; } } - } - return StackablePart::Pointer(0); -} - -StackablePart::Pointer PerspectiveHelper::FindPart(const std::string& primaryId, - const std::string& secondaryId, - const std::list& parts, - std::vector& matchingParts) -{ - for (std::list::const_iterator iter = parts.begin(); - iter != parts.end(); ++iter) - { - StackablePart::Pointer part = *iter; // check for view part equality if (part.Cast () != 0) { PartPane::Pointer pane = part.Cast(); IViewReference::Pointer ref = pane->GetPartReference().Cast(); if (ref->GetId() == primaryId && ref->GetSecondaryId() == secondaryId) { return part; } } // check placeholders else if (part.Cast () != 0) { - std::string id = part->GetId(); + std::string id = part->GetID(); // optimization: don't bother parsing id if it has no separator -- it can't match std::string phSecondaryId = ViewFactory::ExtractSecondaryId(id); if (phSecondaryId == "") { // but still need to check for wildcard case if (id == PartPlaceholder::WILD_CARD) { matchingParts.push_back(MatchingPart(id, "", part)); } continue; } std::string phPrimaryId = ViewFactory::ExtractPrimaryId(id); // perfect matching pair if (phPrimaryId == primaryId && phSecondaryId == secondaryId) { return part; } // check for partial matching pair Poco::RegularExpression pre(phPrimaryId, Poco::RegularExpression::RE_CASELESS); if (pre.match(primaryId)) { Poco::RegularExpression sre(phSecondaryId, Poco::RegularExpression::RE_CASELESS); if (sre.match(secondaryId)) { matchingParts.push_back(MatchingPart(phPrimaryId, phSecondaryId, part)); } } } } - return StackablePart::Pointer(0); + return LayoutPart::Pointer(0); } bool PerspectiveHelper::HasPlaceholder(const std::string& id) { return this->HasPlaceholder(id, 0); } bool PerspectiveHelper::HasPlaceholder(const std::string& primaryId, const std::string& secondaryId) { - StackablePart::Pointer testPart; + LayoutPart::Pointer testPart; if (secondaryId == "") { testPart = this->FindPart(primaryId); } else { testPart = this->FindPart(primaryId, secondaryId); } return (testPart != 0 && testPart.Cast () != 0); } PartSashContainer::Pointer PerspectiveHelper::GetLayout() const { return mainLayout; } bool PerspectiveHelper::IsActive() { return active; } -float PerspectiveHelper::GetDockingRatio(StackablePart::Pointer source, +float PerspectiveHelper::GetDockingRatio(LayoutPart::Pointer source, LayoutPart::Pointer target) { if ((source.Cast () != 0 || source.Cast () != 0) && target.Cast () != 0) { return 0.25f; } return 0.5f; } -void PerspectiveHelper::RemovePart(StackablePart::Pointer part) +void PerspectiveHelper::RemovePart(LayoutPart::Pointer part) { // Reparent the part back to the main window void* parent = mainLayout->GetParent(); part->Reparent(parent); // Replace part with a placeholder - IStackableContainer::Pointer container = part->GetContainer(); + ILayoutContainer::Pointer container = part->GetContainer(); if (container != 0) { std::string placeHolderId = part->GetPlaceHolderId(); - container->Replace(part, StackablePart::Pointer(new PartPlaceholder(placeHolderId))); + container->Replace(part, LayoutPart::Pointer(new PartPlaceholder(placeHolderId))); // // If the parent is root we're done. Do not try to replace // // it with placeholder. // if (container == mainLayout) // { // return; // } // If the parent is empty replace it with a placeholder. - std::list children = container->GetChildren(); + std::list children = container->GetChildren(); bool allInvisible = true; - for (std::list::iterator childIter = children.begin(); + for (std::list::iterator childIter = children.begin(); childIter != children.end(); ++childIter) { if (childIter->Cast () == 0) { allInvisible = false; break; } } if (allInvisible && (container.Cast () != 0)) { // what type of window are we in? LayoutPart::Pointer cPart = container.Cast(); //Window oldWindow = cPart.getWindow(); bool wasDocked = cPart->IsDocked(); Shell::Pointer oldShell = cPart->GetShell(); if (wasDocked) { // PR 1GDFVBY: ViewStack not disposed when page // closed. if (container.Cast () != 0) { container.Cast()->Dispose(); } // replace the real container with a // ContainerPlaceholder ILayoutContainer::Pointer parentContainer = cPart->GetContainer(); ContainerPlaceholder::Pointer placeholder( new ContainerPlaceholder(cPart->GetID())); placeholder->SetRealContainer(container); parentContainer->Replace(cPart, placeholder); } else { DetachedPlaceHolder::Pointer placeholder( new DetachedPlaceHolder("", oldShell->GetBounds())); //$NON-NLS-1$ - for (std::list::iterator childIter2 = children.begin(); + for (std::list::iterator childIter2 = children.begin(); childIter2 != children.end(); ++childIter2) { (*childIter2)->GetContainer()->Remove(*childIter2); (*childIter2)->SetContainer(placeholder); placeholder->Add(*childIter2); } detachedPlaceHolderList.push_back(placeholder); DetachedWindow::Pointer w = oldShell->GetData().Cast(); oldShell->Close(); detachedWindowList.remove(w); } } } } -void PerspectiveHelper::ReplacePlaceholderWithPart(StackablePart::Pointer part) +void PerspectiveHelper::ReplacePlaceholderWithPart(LayoutPart::Pointer part) { // Look for a PartPlaceholder that will tell us how to position this // object std::vector placeholders = this->CollectPlaceholders(); for (unsigned int i = 0; i < placeholders.size(); i++) { - if (placeholders[i]->GetCompoundId() == part->GetCompoundId()) + if (placeholders[i]->GetID() == part->GetID()) { // found a matching placeholder which we can replace with the // new View - IStackableContainer::Pointer container = placeholders[i]->GetContainer(); + ILayoutContainer::Pointer container = placeholders[i]->GetContainer(); if (container != 0) { - if (container.Cast () != 0) + if (ContainerPlaceholder::Pointer containerPlaceholder = container.Cast ()) { // One of the children is now visible so replace the // ContainerPlaceholder with the real container - ContainerPlaceholder::Pointer containerPlaceholder = - container.Cast(); ILayoutContainer::Pointer parentContainer = - containerPlaceholder->GetContainer(); - container - = containerPlaceholder->GetRealContainer(); - if (container.Cast () != 0) + containerPlaceholder->GetContainer(); + container = containerPlaceholder->GetRealContainer().Cast(); + if (LayoutPart::Pointer layoutPart = container.Cast ()) { - parentContainer->Replace(containerPlaceholder, - container.Cast()); + parentContainer->Replace(containerPlaceholder, layoutPart); } - containerPlaceholder->SetRealContainer(IStackableContainer::Pointer(0)); + containerPlaceholder->SetRealContainer(ILayoutContainer::Pointer(0)); } container->Replace(placeholders[i], part); return; } } } - -} - -void PerspectiveHelper::ReplacePlaceholderWithPart(LayoutPart::Pointer part) -{ - // Look for a ContainerPlaceholder that will tell us how to position this - // object - std::vector placeholders(this->CollectContainerPlaceholders()); - for (std::size_t i = 0; i < placeholders.size(); i++) - { - if (placeholders[i]->GetID() == part->GetID()) - { - // found a matching placeholder which we can replace with the - // new container - ILayoutContainer::Pointer container = placeholders[i]->GetContainer(); - if (container != 0) - { -// if (container.Cast () != 0) -// { -// // One of the children is now visible so replace the -// // ContainerPlaceholder with the real container -// ContainerPlaceholder::Pointer containerPlaceholder = -// container.Cast(); -// ILayoutContainer::Pointer parentContainer = -// containerPlaceholder->GetContainer(); -// container -// = containerPlaceholder->GetRealContainer(); -// if (container.Cast () != 0) -// { -// parentContainer->Replace(containerPlaceholder, -// container.Cast()); -// } -// containerPlaceholder->SetRealContainer(IStackableContainer::Pointer(0)); -// } - container->Replace(placeholders[i], part); - return; - } - } - } } bool PerspectiveHelper::RestoreState(IMemento::Pointer memento) { // Restore main window. IMemento::Pointer childMem = memento->GetChild(WorkbenchConstants::TAG_MAIN_WINDOW); //IStatus r = mainLayout->RestoreState(childMem); bool r = mainLayout->RestoreState(childMem); // Restore each floating window. if (detachable) { std::vector detachedWindows(memento->GetChildren( WorkbenchConstants::TAG_DETACHED_WINDOW)); for (std::vector::iterator iter = detachedWindows.begin(); iter != detachedWindows.end(); ++iter) { DetachedWindow::Pointer win(new DetachedWindow(page)); detachedWindowList.push_back(win); win->RestoreState(*iter); } std::vector childrenMem(memento->GetChildren( WorkbenchConstants::TAG_HIDDEN_WINDOW)); for (std::vector::iterator iter = childrenMem.begin(); iter != childrenMem.end(); ++iter) { DetachedPlaceHolder::Pointer holder( new DetachedPlaceHolder("", Rectangle(0, 0, 0, 0))); holder->RestoreState(*iter); detachedPlaceHolderList.push_back(holder); } } // Get the cached id of the currently maximized stack //maximizedStackId = childMem.getString(IWorkbenchConstants.TAG_MAXIMIZED); return r; } bool PerspectiveHelper::SaveState(IMemento::Pointer memento) { // Persist main window. IMemento::Pointer childMem = memento->CreateChild(WorkbenchConstants::TAG_MAIN_WINDOW); //IStatus r = mainLayout->SaveState(childMem); bool r = mainLayout->SaveState(childMem); if (detachable) { // Persist each detached window. for (DetachedWindowsType::iterator iter = detachedWindowList.begin(); iter != detachedWindowList.end(); ++iter) { childMem = memento->CreateChild(WorkbenchConstants::TAG_DETACHED_WINDOW); (*iter)->SaveState(childMem); } for (DetachedPlaceHoldersType::iterator iter = detachedPlaceHolderList.begin(); iter != detachedPlaceHolderList.end(); ++iter) { childMem = memento->CreateChild(WorkbenchConstants::TAG_HIDDEN_WINDOW); (*iter)->SaveState(childMem); } } // Write out the id of the maximized (View) stack (if any) // NOTE: we only write this out if it's a ViewStack since the // Editor Area is handled by the perspective // if (maximizedStack.Cast () != 0) // { // childMem.putString(IWorkbenchConstants.TAG_MAXIMIZED, // maximizedStack.getID()); // } // else if (maximizedStackId != 0) // { // // Maintain the cache if the perspective has never been activated // childMem.putString(IWorkbenchConstants.TAG_MAXIMIZED, maximizedStackId); // } return r; } void PerspectiveHelper::UpdateBoundsMap() { boundsMap.clear(); // Walk the layout gathering the current bounds of each stack // and the editor area std::list kids = mainLayout->GetChildren(); for (std::list::iterator iter = kids.begin(); iter != kids.end(); ++iter) { if (iter->Cast () != 0) { PartStack::Pointer vs = iter->Cast(); boundsMap.insert(std::make_pair(vs->GetID(), vs->GetBounds())); } else if (iter->Cast () != 0) { EditorSashContainer::Pointer esc = iter->Cast(); boundsMap.insert(std::make_pair(esc->GetID(), esc->GetBounds())); } } } void PerspectiveHelper::ResetBoundsMap() { boundsMap.clear(); } Rectangle PerspectiveHelper::GetCachedBoundsFor(const std::string& id) { return boundsMap[id]; } } diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPerspectiveHelper.h b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPerspectiveHelper.h index b2c872d5d8..ad8e74c3da 100755 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPerspectiveHelper.h +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPerspectiveHelper.h @@ -1,594 +1,573 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef BERRYPERSPECTIVEHELPER_H_ #define BERRYPERSPECTIVEHELPER_H_ #include "berryWorkbenchPage.h" #include "berryPartPlaceholder.h" #include "berryPerspective.h" #include "berryViewSashContainer.h" #include "berryPartPlaceholder.h" #include "berryDetachedWindow.h" #include "berryDetachedPlaceHolder.h" #include "berryIDragOverListener.h" #include "berryAbstractDropTarget.h" #include "berryPartPane.h" namespace berry { class WorkbenchPage; /** * A perspective presentation is a collection of parts with a layout. Each part * is parented to a main window, so you can create more than one presentation * on a set of parts and change the layout just by activating / deactivating a * presentation. * * In addition, the user can change the position of any part by mouse * manipulation (drag & drop). If a part is removed, we leave a placeholder * behind to indicate where it goes should the part be added back. */ class PerspectiveHelper { friend class PartStack; friend class ViewSashContainer; private: WorkbenchPage* page; protected: Perspective::Pointer perspective; protected: void* parentWidget; private: ViewSashContainer::Pointer mainLayout; //private: PartStack maximizedStack; /** * If there is a ViewStack maximized on shutdown the id is * cached and restored into this field on 'restoreState'. * This is then used to bash the ViewStack's presentation state * into the correct value on activation (the startup life-cycle * is such that we have to use this 'latch' because the window * state isn't valid until the activate happens. */ //private: String maximizedStackId; private: typedef std::list DetachedWindowsType; DetachedWindowsType detachedWindowList; private: typedef std::list DetachedPlaceHoldersType; DetachedPlaceHoldersType detachedPlaceHolderList; /** * Maps a stack's id to its current bounds * this is used to capture the current bounds of all * stacks -before- starting a maximize (since the * iterative 'minimize' calls cause the intial stack's * bounds to change. */ private: std::map boundsMap; private: bool detachable; protected: bool active; // key is the LayoutPart object, value is the PartDragDrop object //private: IPartDropListener partDropListener; private: static const int MIN_DETACH_WIDTH; private: static const int MIN_DETACH_HEIGHT; struct DragOverListener: public IDragOverListener { DragOverListener(PerspectiveHelper* perspHelper); IDropTarget::Pointer Drag(void* currentControl, Object::Pointer draggedObject, const Point& position, const Rectangle& dragRectangle); private: PerspectiveHelper* perspHelper; }; IDragOverListener::Pointer dragTarget; struct ActualDropTarget: public AbstractDropTarget { berryObjectMacro(ActualDropTarget) /** * @param part * @param dragRectangle * @since 3.1 */ void SetTarget(PartPane::Pointer part, const Rectangle& dragRectangle); /** * @param part * @param dragRectangle * @since 3.1 */ void SetTarget(PartStack::Pointer part, const Rectangle& dragRectangle); ActualDropTarget(PerspectiveHelper* perspHelper, PartPane::Pointer part, const Rectangle& dragRectangle); ActualDropTarget(PerspectiveHelper* perspHelper, PartStack::Pointer part, const Rectangle& dragRectangle); void Drop(); DnDTweaklet::CursorType GetCursor(); private: PartPane::Pointer part; PartStack::Pointer stack; Rectangle dragRectangle; PerspectiveHelper* perspHelper; }; ActualDropTarget::Pointer dropTarget; private: struct MatchingPart { std::string pid; std::string sid; - StackablePart::Pointer part; + LayoutPart::Pointer part; bool hasWildcard; std::string::size_type len; MatchingPart(const std::string& pid, const std::string& sid, - StackablePart::Pointer part); + LayoutPart::Pointer part); }; struct CompareMatchingParts: public std::binary_function { bool operator()(const MatchingPart& m1, const MatchingPart& m2) const; }; /** * Constructs a new object. */ public: PerspectiveHelper(WorkbenchPage* workbenchPage, ViewSashContainer::Pointer mainLayout, Perspective::Pointer perspective); /** * Show the presentation. */ public: void Activate(void* parent); /** * Adds a part to the presentation. If a placeholder exists for the part * then swap the part in. Otherwise, add the part in the bottom right * corner of the presentation. */ public: - void AddPart(StackablePart::Pointer part); + void AddPart(LayoutPart::Pointer part); /** * Attaches a part that was previously detached to the mainLayout. * * @param ref */ public: void AttachPart(IViewReference::Pointer ref); /** * Return whether detachable parts can be supported. */ public: bool CanDetach(); /** * Bring a part forward so it is visible. * * @return true if the part was brought to top, false if not. */ public: - bool BringPartToTop(StackablePart::Pointer part); + bool BringPartToTop(LayoutPart::Pointer part); /** * Returns true if the given part is visible. * A part is visible if it's top-level (not in a tab folder) or if it is the top one * in a tab folder. */ public: bool IsPartVisible(IWorkbenchPartReference::Pointer partRef); /** * Returns true is not in a tab folder or if it is the top one in a tab * folder. */ public: bool WillPartBeVisible(const std::string& partId); public: bool WillPartBeVisible(const std::string& partId, const std::string& secondaryId); /** * Answer a list of the PartPlaceholder objects. */ private: std::vector CollectPlaceholders(); -private: - std::vector CollectContainerPlaceholders(); - /** * Answer a list of the PartPlaceholder objects. */ private: std::vector CollectPlaceholders( const std::list& parts); -private: - std::vector CollectContainerPlaceholders( - const std::list& parts); - /** * Answer a list of the view panes. */ public: void CollectViewPanes(std::vector& result); /** * Answer a list of the view panes. */ private: void CollectViewPanes(std::vector& result, const std::list& parts); /** * Hide the presentation. */ public: void Deactivate(); public: ~PerspectiveHelper(); /** * Writes a description of the layout to the given string buffer. * This is used for drag-drop test suites to determine if two layouts are the * same. Like a hash code, the description should compare as equal iff the * layouts are the same. However, it should be user-readable in order to * help debug failed tests. Although these are english readable strings, * they should not be translated or equality tests will fail. *

    * This is only intended for use by test suites. *

    * * @param buf */ public: void DescribeLayout(std::string& buf) const; /** * Deref a given part. Deconstruct its container as required. Do not remove * drag listeners. */ protected: - /* package */void DerefPart(StackablePart::Pointer part); + /* package */void DerefPart(LayoutPart::Pointer part); /** * Create a detached window containing a part. */ private: - void DetachPart(StackablePart::Pointer source, int x, int y); + void DetachPart(LayoutPart::Pointer source, int x, int y); private: void Detach(LayoutPart::Pointer source, int x, int y); /** * Detached a part from the mainLayout. Presently this does not use placeholders * since the current implementation is not robust enough to remember a view's position * in more than one root container. For now the view is simply derefed and will dock * in the default position when attachPart is called. * * By default parts detached this way are set to float on top of the workbench * without docking. It is assumed that people that want to drag a part back onto * the WorkbenchWindow will detach it via drag and drop. * * @param ref */ public: void DetachPart(IViewReference::Pointer ref); /** * Create a detached window containing a part. */ public: - void AddDetachedPart(StackablePart::Pointer part); + void AddDetachedPart(LayoutPart::Pointer part); public: - void AddDetachedPart(StackablePart::Pointer part, const Rectangle& bounds); + void AddDetachedPart(LayoutPart::Pointer part, const Rectangle& bounds); /** * disableDragging. */ private: void DisableAllDrag(); /** * enableDragging. */ private: void EnableAllDrag(); /** * Find the first part with a given ID in the presentation. * Wild cards now supported. */ private: - StackablePart::Pointer FindPart(const std::string& id); + LayoutPart::Pointer FindPart(const std::string& id); /** * Find the first part that matches the specified * primary and secondary id pair. Wild cards * are supported. */ public: - StackablePart::Pointer FindPart(const std::string& primaryId, + LayoutPart::Pointer FindPart(const std::string& primaryId, const std::string& secondaryId); /** * Find the first part with a given ID in the presentation. */ private: - StackablePart::Pointer FindPart(const std::string& id, + LayoutPart::Pointer FindPart(const std::string& id, const std::list& parts, std::vector& matchingParts); - LayoutPart::Pointer FindLayoutPart(const std::string& id, - const std::list& parts, - std::vector& matchingParts); - - StackablePart::Pointer FindPart(const std::string& id, - const std::list& parts, - std::vector& matchingParts); - /** * Find the first part that matches the specified * primary and secondary id pair. Wild cards * are supported. */ private: - StackablePart::Pointer FindPart(const std::string& primaryId, + LayoutPart::Pointer FindPart(const std::string& primaryId, const std::string& secondaryId, const std::list& parts, std::vector& matchingParts); - StackablePart::Pointer FindPart(const std::string& primaryId, - const std::string& secondaryId, - const std::list& parts, - std::vector& matchingParts); - /** * Returns true if a placeholder exists for a given ID. */ public: bool HasPlaceholder(const std::string& id); /** * Returns true if a placeholder exists for a given ID. * @since 3.0 */ public: bool HasPlaceholder(const std::string& primaryId, const std::string& secondaryId); /** * Returns the layout container. */ public: PartSashContainer::Pointer GetLayout() const; /** * Gets the active state. */ public: bool IsActive(); /** * Returns whether the presentation is zoomed. * * NOTE: As of 3.3 this method should always return 'false' * when using the new min/max behavior. It is only used for * legacy 'zoom' handling. */ // public: bool IsZoomed() { // return mainLayout.getZoomedPart() != null; // } /** * @return The currently maxmized stack (if any) */ // public: PartStack::Pointer GetMaximizedStack() { // return maximizedStack; // } /** * Sets the currently maximized stack. Used for query * and 'unZoom' purposes in the 3.3 presentation. * * @param stack The newly maximized stack */ // public: void SetMaximizedStack(PartStack::Pointer stack) { // if (stack == maximizedStack) // return; // // maximizedStack = stack; // } /** * Returns the ratio that should be used when docking the given source * part onto the given target * * @param source newly added part * @param target existing part being dragged over * @return the final size of the source part (wrt the current size of target) * after it is docked */ public: - static float GetDockingRatio(StackablePart::Pointer source, + static float GetDockingRatio(LayoutPart::Pointer source, LayoutPart::Pointer target); /** * Returns whether changes to a part will affect zoom. There are a few * conditions for this .. - we are zoomed. - the part is contained in the * main window. - the part is not the zoom part - the part is not a fast * view - the part and the zoom part are not in the same editor workbook * - the part and the zoom part are not in the same view stack. */ // public: bool PartChangeAffectsZoom(LayoutPart::Pointer pane) { // return pane.isObscuredByZoom(); // } /** * Remove all references to a part. */ public: - void RemovePart(StackablePart::Pointer part); + void RemovePart(LayoutPart::Pointer part); /** * Add a part to the presentation. * * Note: unlike all other LayoutParts, PartPlaceholders will still point to * their parent container even when it is inactive. This method relies on this * fact to locate the parent. */ public: - void ReplacePlaceholderWithPart(StackablePart::Pointer part); - void ReplacePlaceholderWithPart(LayoutPart::Pointer container); + void ReplacePlaceholderWithPart(LayoutPart::Pointer part); /** * @see org.blueberry.ui.IPersistable */ public: bool RestoreState(IMemento::Pointer memento); /** * @see org.blueberry.ui.IPersistable */ public: bool SaveState(IMemento::Pointer memento); /** * Zoom in on a particular layout part. */ // public: void zoomIn(IWorkbenchPartReference ref) { // PartPane pane = ((WorkbenchPartReference) ref).getPane(); // // // parentWidget.setRedraw(false); // try { // pane.requestZoomIn(); // } finally { // parentWidget.setRedraw(true); // } // } /** * Zoom out. */ // public: void zoomOut() { // // New 3.3 behavior // if (Perspective.useNewMinMax(perspective)) { // if (maximizedStack != null) // maximizedStack.setState(IStackPresentationSite.STATE_RESTORED); // return; // } // // LayoutPart zoomPart = mainLayout.getZoomedPart(); // if (zoomPart != null) { // zoomPart.requestZoomOut(); // } // } /** * Forces the perspective to have no zoomed or minimized parts. * This is used when switching to the 3.3 presentation... */ // public: void forceNoZoom() { // // Ensure that nobody's zoomed // zoomOut(); // // // Now, walk the layout ensuring that nothing is minimized // LayoutPart[] kids = mainLayout.getChildren(); // for (int i = 0; i < kids.length; i++) { // if (kids[i] instanceof ViewStack) { // ((ViewStack)kids[i]).setMinimized(false); // } // else if (kids[i] instanceof EditorSashContainer) { // LayoutPart[] editorStacks = ((EditorSashContainer)kids[i]).getChildren(); // for (int j = 0; j < editorStacks.length; j++) { // if (editorStacks[j] instanceof EditorStack) { // ((EditorStack)editorStacks[j]).setMinimized(false); // } // } // } // } // } /** * Captures the current bounds of all ViewStacks and the editor * area and puts them into an ID -> Rectangle map. This info is * used to cache the bounds so that we can correctly place minimized * stacks during a 'maximized' operation (where the iterative min's * affect the current layout while being performed. */ public: void UpdateBoundsMap(); /** * Resets the bounds map so that it won't interfere with normal minimize * operations */ public: void ResetBoundsMap(); public: Rectangle GetCachedBoundsFor(const std::string& id); }; } #endif /* BERRYPERSPECTIVEHELPER_H_ */ diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPlaceholderFolderLayout.cpp b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPlaceholderFolderLayout.cpp index 1aa329dd65..65782f9459 100644 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPlaceholderFolderLayout.cpp +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPlaceholderFolderLayout.cpp @@ -1,78 +1,78 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "berryPlaceholderFolderLayout.h" namespace berry { PlaceholderFolderLayout::PlaceholderFolderLayout( PageLayout::Pointer pageLayout, ContainerPlaceholder::Pointer folder) { this->placeholder = folder; this->pageLayout = pageLayout; } void PlaceholderFolderLayout::AddPlaceholder(const std::string& viewId) { if (!pageLayout->CheckValidPlaceholderId(viewId)) { return; } // Create the placeholder. - StackablePart::Pointer newPart(new PartPlaceholder(viewId)); + LayoutPart::Pointer newPart(new PartPlaceholder(viewId)); this->LinkPartToPageLayout(viewId, newPart); // Add it to the placeholder layout. placeholder->Add(newPart); } std::string PlaceholderFolderLayout::GetProperty(const std::string& id) { - IStackableContainer::Pointer folder = placeholder->GetRealContainer(); + LayoutPart::Pointer folder = placeholder->GetRealContainer(); if (folder.Cast() != 0) { return folder.Cast()->GetProperty(id); } //throw not supported? return ""; } void PlaceholderFolderLayout::SetProperty(const std::string& id, const std::string& value) { - IStackableContainer::Pointer folder = placeholder->GetRealContainer(); + LayoutPart::Pointer folder = placeholder->GetRealContainer(); if (folder.Cast() != 0) { folder.Cast()->SetProperty(id, value); } //throw not supported? } void PlaceholderFolderLayout::LinkPartToPageLayout(const std::string& viewId, - StackablePart::Pointer newPart) + LayoutPart::Pointer newPart) { pageLayout->SetRefPart(viewId, newPart); // force creation of the view layout rec pageLayout->GetViewLayoutRec(viewId, true); pageLayout->SetFolderPart(viewId, placeholder); newPart->SetContainer(placeholder); } } diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPlaceholderFolderLayout.h b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPlaceholderFolderLayout.h index a588a8e07a..b6349697f5 100644 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPlaceholderFolderLayout.h +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPlaceholderFolderLayout.h @@ -1,84 +1,84 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef BERRYPLACEHOLDERFOLDERLAYOUT_H_ #define BERRYPLACEHOLDERFOLDERLAYOUT_H_ #include "berryIPlaceholderFolderLayout.h" -#include "berryStackablePart.h" +#include "berryLayoutPart.h" #include "berryPageLayout.h" namespace berry { /** * \ingroup org_blueberry_ui_internal * * This layout is used to define the initial set of placeholders * in a placeholder. *

    * Views are added to the placeholder by ID. This id is used to identify * a view descriptor in the view registry, and this descriptor is used to * instantiate the IViewPart. *

    */ class PlaceholderFolderLayout : public IPlaceholderFolderLayout { public: berryObjectMacro(PlaceholderFolderLayout) private: PageLayout::Pointer pageLayout; ContainerPlaceholder::Pointer placeholder; public: PlaceholderFolderLayout(PageLayout::Pointer pageLayout, ContainerPlaceholder::Pointer folder); /** * @see IPlaceholderFolderLayout */ void AddPlaceholder(const std::string& viewId); /* (non-Javadoc) * @see org.blueberry.ui.IPlaceholderFolderLayout#getProperty(java.lang.String) */ std::string GetProperty(const std::string& id); /* (non-Javadoc) * @see org.blueberry.ui.IPlaceholderFolderLayout#setProperty(java.lang.String, java.lang.String) */ void SetProperty(const std::string& id, const std::string& value); private: /** * Inform the page layout of the new part created * and the placeholder the part belongs to. */ void LinkPartToPageLayout(const std::string& viewId, - StackablePart::Pointer newPart); + LayoutPart::Pointer newPart); }; } #endif /*BERRYPLACEHOLDERFOLDERLAYOUT_H_*/ diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryStackablePart.cpp b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryStackablePart.cpp deleted file mode 100755 index 8c5d6ee118..0000000000 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryStackablePart.cpp +++ /dev/null @@ -1,171 +0,0 @@ -/*=================================================================== - -BlueBerry Platform - -Copyright (c) German Cancer Research Center, -Division of Medical and Biological Informatics. -All rights reserved. - -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR -A PARTICULAR PURPOSE. - -See LICENSE.txt or http://www.mitk.org for details. - -===================================================================*/ - -#include "berryStackablePart.h" - -#include "berryIStackableContainer.h" -#include "berryDetachedWindow.h" -#include "berryIWorkbenchWindow.h" -#include "tweaklets/berryGuiWidgetsTweaklet.h" -#include "berryImageDescriptor.h" - -namespace berry -{ - -StackablePart::StackablePart(std::string id_) -: id(id_) -{ - -} - -IStackableContainer::Pointer StackablePart::GetContainer() const -{ - return container; -} - -void StackablePart::SetContainer(IStackableContainer::Pointer container) -{ - this->container = container; -} - -void StackablePart::Reparent(void* newParent) -{ - void* control = this->GetControl(); - - GuiWidgetsTweaklet* guiTweaklet = Tweaklets::Get(GuiWidgetsTweaklet::KEY); - if ((control == 0) || (guiTweaklet->GetParent(control) == newParent)) - { - return; - } - - if (guiTweaklet->IsReparentable(control)) - { - // make control small in case it is not resized with other controls - //control.setBounds(0, 0, 0, 0); - // By setting the control to disabled before moving it, - // we ensure that the focus goes away from the control and its children - // and moves somewhere else - bool enabled = guiTweaklet->GetEnabled(control); - guiTweaklet->SetEnabled(control, false); - guiTweaklet->SetParent(control, newParent); - guiTweaklet->SetEnabled(control, enabled); - guiTweaklet->MoveAbove(control, 0); - } -} - -void StackablePart::DescribeLayout(std::string& /*description*/) const -{ - -} - -std::string StackablePart::GetPlaceHolderId() const -{ - return this->GetId(); -} - -std::string StackablePart::GetId() const -{ - return id; -} - -void StackablePart::SetId(const std::string& id) -{ - this->id = id; -} - -void StackablePart::SetFocus() -{ - -} - -void StackablePart::SetBounds(const Rectangle& r) -{ - void* ctrl = this->GetControl(); - if (ctrl) - { - return Tweaklets::Get(GuiWidgetsTweaklet::KEY)->SetBounds(ctrl, r); - } -} - -Rectangle StackablePart::GetBounds() -{ - return Rectangle(); -} - -Point StackablePart::GetSize() -{ - Rectangle r = this->GetBounds(); - Point ptSize(r.width, r.height); - return ptSize; -} - -bool StackablePart::IsDocked() -{ - Shell::Pointer s = this->GetShell(); - if (s == 0) - { - return false; - } - - return s->GetData().Cast() != 0; -} - -Shell::Pointer StackablePart::GetShell() -{ - void* ctrl = this->GetControl(); - if (ctrl) - { - return Tweaklets::Get(GuiWidgetsTweaklet::KEY)->GetShell(ctrl); - } - return Shell::Pointer(0); -} - -IWorkbenchWindow::Pointer StackablePart::GetWorkbenchWindow() -{ - Shell::Pointer s = this->GetShell(); - if (s == 0) - { - return IWorkbenchWindow::Pointer(0); - } - Object::Pointer data = s->GetData(); - if (data.Cast() != 0) - { - return data.Cast(); - } - else if (data.Cast() != 0) - { - return data.Cast()->GetWorkbenchPage()->GetWorkbenchWindow(); - } - - return IWorkbenchWindow::Pointer(0); -} - -std::string StackablePart::GetCompoundId() -{ - return this->GetId(); -} - -bool StackablePart::IsPlaceHolder() const -{ - return false; -} - -void StackablePart::TestInvariants() -{ - -} - -} diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryStackablePart.h b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryStackablePart.h deleted file mode 100755 index 91d5750f0e..0000000000 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryStackablePart.h +++ /dev/null @@ -1,97 +0,0 @@ -/*=================================================================== - -BlueBerry Platform - -Copyright (c) German Cancer Research Center, -Division of Medical and Biological Informatics. -All rights reserved. - -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR -A PARTICULAR PURPOSE. - -See LICENSE.txt or http://www.mitk.org for details. - -===================================================================*/ - - -#ifndef BERRYSTACKABLEPART_H_ -#define BERRYSTACKABLEPART_H_ - -#include - -#include "berryShell.h" - -#include "berryPoint.h" -#include "berryRectangle.h" - -#include - -namespace berry { - -struct IStackableContainer; -struct IWorkbenchWindow; - -class StackablePart : public virtual Object -{ - -public: - - berryObjectMacro(StackablePart); - - StackablePart(std::string id); - - virtual void CreateControl(void* parent) = 0; - virtual void* GetControl() = 0; - - virtual SmartPointer GetContainer() const; - virtual void SetContainer(SmartPointer container); - - virtual void Reparent(void* newParent); - - virtual void DescribeLayout(std::string& description) const; - - virtual std::string GetPlaceHolderId() const; - - virtual std::string GetId() const; - - virtual void SetId(const std::string& id); - - /** - * Sets focus to this part. - */ - virtual void SetFocus(); - - virtual void SetBounds(const Rectangle& bounds); - virtual Rectangle GetBounds(); - - virtual Point GetSize(); - - virtual bool IsDocked(); - - virtual Shell::Pointer GetShell(); - - SmartPointer GetWorkbenchWindow(); - - /** - * Returns the compound ID for this part. - * The compound ID is of the form: primaryId [':' + secondaryId] - * - * @return the compound ID for this part. - */ - virtual std::string GetCompoundId(); - - virtual bool IsPlaceHolder() const; - - virtual void TestInvariants(); - -private: - - std::string id; - SmartPointer container; - -}; - -} - -#endif /* BERRYSTACKABLEPART_H_ */ diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryViewSashContainer.cpp b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryViewSashContainer.cpp index d9dfd485a0..b2bb2a194f 100755 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryViewSashContainer.cpp +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryViewSashContainer.cpp @@ -1,298 +1,296 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "berryViewSashContainer.h" #include "berryPerspective.h" #include "berryPerspectiveHelper.h" #include "berryLayoutTree.h" #include "berryWorkbenchConstants.h" #include "berryWorkbenchPlugin.h" #include "berryImageDescriptor.h" #include namespace berry { ViewSashContainer::ViewSashContainer(WorkbenchPage* page, void* parent) : PartSashContainer("root layout container", page, parent) { } ViewSashContainer::Pointer ViewSashContainer::GetRootContainer() { return ViewSashContainer::Pointer(this); } void* ViewSashContainer::GetControl() { return this->parent; } bool ViewSashContainer::RestoreState(IMemento::Pointer memento) { //TODO ViewSashContainer restore state // MultiStatus // result = // new MultiStatus(PlatformUI.PLUGIN_ID, IStatus.OK, WorkbenchMessages.RootLayoutContainer_problemsRestoringPerspective, null); // bool result = true; // Read the info elements. std::vector children(memento->GetChildren(WorkbenchConstants::TAG_INFO)); // Create a part ID to part hashtable. Poco::HashMap mapIDtoPart(children.size()); // Loop through the info elements. for (std::size_t i = 0; i < children.size(); i++) { // Get the info details. IMemento::Pointer childMem = children[i]; std::string partID; childMem->GetString(WorkbenchConstants::TAG_PART, partID); std::string relativeID; childMem->GetString(WorkbenchConstants::TAG_RELATIVE, relativeID); int relationship = 0; int left = 0, right = 0; if (!relativeID.empty()) { childMem->GetInteger(WorkbenchConstants::TAG_RELATIONSHIP, relationship); childMem->GetInteger(WorkbenchConstants::TAG_RATIO_LEFT, left); childMem->GetInteger(WorkbenchConstants::TAG_RATIO_RIGHT, right); } std::string strFolder; childMem->GetString(WorkbenchConstants::TAG_FOLDER, strFolder); // Create the part. LayoutPart::Pointer part; if (strFolder.empty()) { // this is the editor area - ContainerPlaceholder::Pointer placeholder(new ContainerPlaceholder(partID)); - part = placeholder; + part = new PartPlaceholder(partID); } else { PartStack::Pointer folder(new PartStack(page)); folder->SetID(partID); //result.add(folder->RestoreState(childMem->GetChild(WorkbenchConstants::TAG_FOLDER))); result &= folder->RestoreState(childMem->GetChild(WorkbenchConstants::TAG_FOLDER)); ContainerPlaceholder::Pointer placeholder(new ContainerPlaceholder(partID)); placeholder->SetRealContainer(folder); part = placeholder; } // 1FUN70C: ITPUI:WIN - Shouldn't set Container when not active part->SetContainer(ILayoutContainer::Pointer(this)); const int myLeft = left, myRight = right, myRelationship = relationship; LayoutPart::Pointer myPart = part; // StartupThreading.runWithoutExceptions(new StartupRunnable() // { // // public void runWithException() throws Throwable // { // Add the part to the layout if (relativeID.empty()) { this->Add(myPart); } else { LayoutPart::Pointer refPart = mapIDtoPart[relativeID]; if (refPart) { this->Add(myPart, myRelationship, myLeft, myRight, refPart); } else { WorkbenchPlugin::Log("Unable to find part for ID: " + relativeID); } } // }} // ); mapIDtoPart[partID] = part; } return result; } bool ViewSashContainer::SaveState(IMemento::Pointer memento) { std::vector relationships = this->ComputeRelation(); bool result = true; // MultiStatus // result = // new MultiStatus(PlatformUI.PLUGIN_ID, IStatus.OK, WorkbenchMessages.RootLayoutContainer_problemsSavingPerspective, null); // Loop through the relationship array. for (std::size_t i = 0; i < relationships.size(); ++i) { // Save the relationship info .. // private LayoutPart part; // private int relationship; // private float ratio; // private LayoutPart relative; RelationshipInfo& info = relationships[i]; IMemento::Pointer childMem = memento->CreateChild(WorkbenchConstants::TAG_INFO); childMem->PutString(WorkbenchConstants::TAG_PART, info.part->GetID()); if (info.relative) { childMem->PutString(WorkbenchConstants::TAG_RELATIVE, info.relative->GetID()); childMem->PutInteger(WorkbenchConstants::TAG_RELATIONSHIP, info.relationship); childMem->PutInteger(WorkbenchConstants::TAG_RATIO_LEFT, info.left); childMem->PutInteger(WorkbenchConstants::TAG_RATIO_RIGHT, info.right); } // Is this part a folder or a placeholder for one? PartStack::Pointer folder(info.part.Cast()); if (!folder && info.part.Cast()) { - IStackableContainer::Pointer part = info.part.Cast()->GetRealContainer(); + LayoutPart::Pointer part = info.part.Cast()->GetRealContainer(); folder = part.Cast(); } // If this is a folder (PartStack) save the contents. if (folder) { childMem->PutString(WorkbenchConstants::TAG_FOLDER, "true"); IMemento::Pointer folderMem(childMem->CreateChild(WorkbenchConstants::TAG_FOLDER)); //result.add(folder.saveState(folderMem)); result = folder->SaveState(folderMem); } } return result; } -bool ViewSashContainer::IsStackType(IStackableContainer::Pointer toTest) +bool ViewSashContainer::IsStackType(ILayoutContainer::Pointer toTest) { if (toTest.Cast () == 0) return false; return (toTest.Cast ()->GetAppearance() != PresentationFactoryUtil::ROLE_EDITOR); } -bool ViewSashContainer::IsPaneType(StackablePart::Pointer toTest) +bool ViewSashContainer::IsPaneType(LayoutPart::Pointer toTest) { if (toTest.Cast () == 0) return false; return (toTest.Cast ()->GetPartReference().Cast () != 0); } bool ViewSashContainer::AllowsAdd(LayoutPart::Pointer layoutPart) { return LayoutPart::AllowsAdd(layoutPart); } -// void ViewSashContainer::Replace(StackablePart::Pointer oldChild, -// StackablePart::Pointer newChild) -// { -// if (!this->IsChild(oldChild)) -// { -// return; -// } -// -// // Nasty hack: ensure that all views end up inside a tab folder. -// // Since the view title is provided by the tab folder, this ensures -// // that views don't get created without a title tab. -// if (newChild instanceof ViewPane) -// { -// ViewStack folder = new ViewStack(page); -// folder.add(newChild); -// newChild = folder; -// } -// -// super.replace(oldChild, newChild); -// } +void ViewSashContainer::Replace(LayoutPart::Pointer oldChild, LayoutPart::Pointer newChild) +{ + if (!this->IsChild(oldChild)) + { + return; + } + + // Nasty hack: ensure that all views end up inside a tab folder. + // Since the view title is provided by the tab folder, this ensures + // that views don't get created without a title tab. + if (newChild.Cast()) + { + PartStack::Pointer folder(new PartStack(page)); + folder->Add(newChild); + newChild = folder; + } + + PartSashContainer::Replace(oldChild, newChild); +} void* ViewSashContainer::CreateParent(void* parentWidget) { return parentWidget; } void ViewSashContainer::DisposeParent() { // do nothing } float ViewSashContainer::GetDockingRatio(Object::Pointer dragged, - IStackableContainer::Pointer target) + ILayoutContainer::Pointer target) { if (this->IsStackType(target)) { return PartSashContainer::GetDockingRatio(dragged, target); } else { return 0.25f; } } PartStack::Pointer ViewSashContainer::CreateStack() { PartStack::Pointer result(new PartStack(page)); return result; } -void ViewSashContainer::SetVisiblePart(IStackableContainer::Pointer container, +void ViewSashContainer::SetVisiblePart(ILayoutContainer::Pointer container, PartPane::Pointer visiblePart) { if (container.Cast () != 0) { PartStack::Pointer tabFolder = container.Cast (); tabFolder->SetSelection(visiblePart); } } -StackablePart::Pointer ViewSashContainer::GetVisiblePart( - IStackableContainer::Pointer container) +LayoutPart::Pointer ViewSashContainer::GetVisiblePart( + ILayoutContainer::Pointer container) { return container.Cast ()->GetSelection(); } -void ViewSashContainer::DerefPart(StackablePart::Pointer sourcePart) +void ViewSashContainer::DerefPart(LayoutPart::Pointer sourcePart) { page->GetActivePerspective()->GetPresentation()->DerefPart(sourcePart); } // void ViewSashContainer::AddChild(const RelationshipInfo& info) // { // LayoutPart child = info.part; // // // Nasty hack: ensure that all views end up inside a tab folder. // // Since the view title is provided by the tab folder, this ensures // // that views don't get created without a title tab. // if (child instanceof ViewPane) // { // ViewStack folder = new ViewStack(page); // folder.add(child); // info.part = folder; // } // // super.addChild(info); // } } diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryViewSashContainer.h b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryViewSashContainer.h index 34203b3146..aa626c31c0 100755 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryViewSashContainer.h +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryViewSashContainer.h @@ -1,125 +1,127 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef BERRYVIEWSASHCONTAINER_H_ #define BERRYVIEWSASHCONTAINER_H_ #include "berryPartSashContainer.h" #include "berryPartStack.h" namespace berry { /** * Represents the top level container. */ class ViewSashContainer : public PartSashContainer { public: berryObjectMacro(ViewSashContainer); ViewSashContainer(WorkbenchPage* page, void* parent); /** * Gets root container for this part. */ ViewSashContainer::Pointer GetRootContainer(); /** * Get the part control. This method may return null. */ void* GetControl(); /** * @see IPersistablePart */ bool RestoreState(IMemento::Pointer memento); /** * @see IPersistablePart */ bool SaveState(IMemento::Pointer memento); /* (non-Javadoc) * @see org.blueberry.ui.internal.PartSashContainer#isStackType(org.blueberry.ui.internal.LayoutPart) */ - bool IsStackType(IStackableContainer::Pointer toTest); + bool IsStackType(ILayoutContainer::Pointer toTest); /* (non-Javadoc) * @see org.blueberry.ui.internal.PartSashContainer#isPaneType(org.blueberry.ui.internal.LayoutPart) */ - bool IsPaneType(StackablePart::Pointer toTest); + bool IsPaneType(LayoutPart::Pointer toTest); /* (non-Javadoc) * @see org.blueberry.ui.internal.ILayoutContainer#replace(org.blueberry.ui.internal.LayoutPart, org.blueberry.ui.internal.LayoutPart) */ //void Replace(LayoutPart::Pointer oldChild, LayoutPart::Pointer newChild); bool AllowsAdd(LayoutPart::Pointer layoutPart); + void Replace(LayoutPart::Pointer oldChild, LayoutPart::Pointer newChild); + protected: /** * Subclasses override this method to specify * the composite to use to parent all children * layout parts it contains. */ void* CreateParent(void* parentWidget); /** * Subclasses override this method to dispose * of any swt resources created during createParent. */ void DisposeParent(); /* (non-Javadoc) * @see org.blueberry.ui.internal.PartSashContainer#getDockingRatio(org.blueberry.ui.internal.LayoutPart, org.blueberry.ui.internal.LayoutPart) */ - float GetDockingRatio(Object::Pointer dragged, IStackableContainer::Pointer target); + float GetDockingRatio(Object::Pointer dragged, ILayoutContainer::Pointer target); /* (non-Javadoc) * @see org.blueberry.ui.internal.PartSashContainer#createStack(org.blueberry.ui.internal.LayoutPart) */ PartStack::Pointer CreateStack(); /* (non-Javadoc) * @see org.blueberry.ui.internal.PartSashContainer#setVisiblePart(org.blueberry.ui.internal.ILayoutContainer, org.blueberry.ui.internal.LayoutPart) */ - void SetVisiblePart(IStackableContainer::Pointer container, + void SetVisiblePart(ILayoutContainer::Pointer container, PartPane::Pointer visiblePart); /* (non-Javadoc) * @see org.blueberry.ui.internal.PartSashContainer#getVisiblePart(org.blueberry.ui.internal.ILayoutContainer) */ - StackablePart::Pointer GetVisiblePart(IStackableContainer::Pointer container); + LayoutPart::Pointer GetVisiblePart(ILayoutContainer::Pointer container); /* (non-Javadoc) * @see org.blueberry.ui.internal.PartSashContainer#derefPart(org.blueberry.ui.internal.LayoutPart) */ - void DerefPart(StackablePart::Pointer sourcePart); + void DerefPart(LayoutPart::Pointer sourcePart); /* (non-Javadoc) * @see org.blueberry.ui.internal.PartSashContainer#addChild(org.blueberry.ui.internal.PartSashContainer.RelationshipInfo) */ //void AddChild(const RelationshipInfo& info); }; } #endif /* BERRYVIEWSASHCONTAINER_H_ */ diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryWorkbench.h b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryWorkbench.h index be2f9e58f4..c203549ec6 100644 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryWorkbench.h +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryWorkbench.h @@ -1,601 +1,601 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef BERRYWORKBENCH_H_ #define BERRYWORKBENCH_H_ #include "berryIViewPart.h" #include "berryIWorkbench.h" #include "berryWorkbenchWindow.h" #include "berryIWorkbenchPage.h" #include "berryIWorkbenchPartReference.h" #include "berryXMLMemento.h" #include "berryPartPane.h" #include "berryEditorAreaHelper.h" #include "berryWindowManager.h" #include "berryWorkbenchConfigurer.h" #include "application/berryWorkbenchAdvisor.h" #include "berryWorkbenchTestable.h" #include "intro/berryIntroDescriptor.h" #include "intro/berryWorkbenchIntroManager.h" -#include "berryIStackableContainer.h" +#include "berryILayoutContainer.h" #include "berryServiceLocator.h" #include #include namespace berry { class ViewRegistry; class EditorRegistry; class WorkbenchWindowConfigurer; /** * \ingroup org_blueberry_ui * * The workbench class represents the top of the BlueBerry user interface. Its * primary responsibility is the management of workbench windows, dialogs, * wizards, and other workbench-related windows. *

    * Note that any code that is run during the creation of a workbench instance * should not required access to the display. */ class BERRY_UI Workbench : public IWorkbench { public: berryObjectMacro(Workbench); friend class RestoreStateRunnable; /** * Creates the workbench and associates it with the the given display and * workbench advisor, and runs the workbench UI. This entails processing and * dispatching events until the workbench is closed or restarted. *

    * This method is intended to be called by PlatformUI. Fails * if the workbench UI has already been created. *

    *

    * The display passed in must be the default display. *

    * * @param display * the display to be used for all UI interactions with the * workbench * @param advisor * the application-specific advisor that configures and * specializes the workbench * @return return code {@link PlatformUI#RETURN_OK RETURN_OK}for normal * exit; {@link PlatformUI#RETURN_RESTART RETURN_RESTART}if the * workbench was terminated with a call to * {@link IWorkbench#restart IWorkbench.restart}; other values * reserved for future use */ static int CreateAndRunWorkbench(Display* display, WorkbenchAdvisor* advisor); /** * Creates the Display to be used by the workbench. * * @return the display */ static Display* CreateDisplay(); /** * Returns the one and only instance of the workbench, if there is one. * * @return the workbench, or null if the workbench has not * been created, or has been created and already completed */ static Workbench* GetInstance(); virtual ~Workbench(); /* * (non-Javadoc) * * @see org.blueberry.ui.services.IServiceLocator#getService(java.lang.Object) */ Object::Pointer GetService(const std::string& key); /* * (non-Javadoc) * * @see org.blueberry.ui.services.IServiceLocator#hasService(java.lang.Object) */ bool HasService(const std::string& key) const; /* * Method declared on IWorkbench. */ bool Close(); /** * Returns the testable object facade, for use by the test harness. * * @return the testable object facade * @since 3.0 */ static WorkbenchTestable::Pointer GetWorkbenchTestable(); /* * Method declared on IWorkbench. */ void AddWorkbenchListener(IWorkbenchListener::Pointer listener); /* * Method declared on IWorkbench. */ void RemoveWorkbenchListener(IWorkbenchListener::Pointer listener); /* * Method declared on IWorkbench. */ IWorkbenchListener::Events& GetWorkbenchEvents(); /* * Method declared on IWorkbench. */ void AddWindowListener(IWindowListener::Pointer l); /* * Method declared on IWorkbench. */ void RemoveWindowListener(IWindowListener::Pointer l); /* * Method declared on IWorkbench. */ IWindowListener::Events& GetWindowEvents(); IWorkbenchWindow::Pointer GetActiveWorkbenchWindow(); IViewRegistry* GetViewRegistry(); IEditorRegistry* GetEditorRegistry(); IPerspectiveRegistry* GetPerspectiveRegistry(); std::size_t GetWorkbenchWindowCount(); std::vector GetWorkbenchWindows(); IWorkbenchWindow::Pointer OpenWorkbenchWindow(const std::string& perspectiveId, IAdaptable* input); IWorkbenchWindow::Pointer OpenWorkbenchWindow(IAdaptable* input); IWorkbenchPage::Pointer ShowPerspective(const std::string& perspectiveId, IWorkbenchWindow::Pointer window); IWorkbenchPage::Pointer ShowPerspective(const std::string& perspectiveId, IWorkbenchWindow::Pointer window, IAdaptable* input); bool SaveAllEditors(bool confirm); IIntroManager* GetIntroManager(); /** * @return the workbench intro manager */ WorkbenchIntroManager* GetWorkbenchIntroManager(); /** * @return the intro extension for this workbench. */ IntroDescriptor::Pointer GetIntroDescriptor() const; /** * This method exists as a test hook. This method should NEVER * be called by clients. * * @param descriptor * The intro descriptor to use. */ void SetIntroDescriptor(IntroDescriptor::Pointer descriptor); /** * Returns true if the workbench is running, * false if it has been terminated. * * @return true if the workbench is running, * false if it has been terminated. */ bool IsRunning(); /** * Returns true if the Workbench is in the process of starting. * * @return true if the Workbench is starting, but not yet * running the event loop. */ bool IsStarting(); bool IsClosing(); /** * Returns the default perspective id, which may be null. * * @return the default perspective id, or null */ std::string GetDefaultPerspectiveId(); /** * Returns the default workbench window page input. * * @return the default window page input or null if none */ IAdaptable* GetDefaultPageInput(); /** * Return the presentation ID specified by the preference or the default ID * if undefined. * * @return the presentation ID * @see IWorkbenchPreferenceConstants#PRESENTATION_FACTORY_ID */ std::string GetPresentationId(); void UpdateTheme(); /** *

    * Indicates the start of a large update within the workbench. This is used * to disable CPU-intensive, change-sensitive services that were temporarily * disabled in the midst of large changes. This method should always be * called in tandem with largeUpdateEnd, and the event loop * should not be allowed to spin before that method is called. *

    *

    * Important: always use with largeUpdateEnd! *

    */ void LargeUpdateStart(); /** *

    * Indicates the end of a large update within the workbench. This is used to * re-enable services that were temporarily disabled in the midst of large * changes. This method should always be called in tandem with * largeUpdateStart, and the event loop should not be * allowed to spin before this method is called. *

    *

    * Important: always protect this call by using finally! *

    */ void LargeUpdateEnd(); protected: friend class PlatformUI; friend class WorkbenchConfigurer; friend class WorkbenchWindowConfigurer; friend class WorkbenchWindow; friend struct WorkbenchWindow::ShellActivationListener; int RunUI(); void OpenFirstTimeWindow(); IWorkbenchWindow::Pointer RestoreWorkbenchWindow(IMemento::Pointer memento); bool Init(); /* * Restores the workbench UI from the workbench state file (workbench.xml). * * @return a status object indicating OK if a window was opened, * RESTORE_CODE_RESET if no window was opened but one should be, and * RESTORE_CODE_EXIT if the workbench should close immediately */ /* package */ bool RestoreState(); /** * Closes the workbench, returning the given return code from the run * method. If forced, the workbench is closed no matter what. * * @param returnCode * {@link PlatformUI#RETURN_OK RETURN_OK}for normal exit; * {@link PlatformUI#RETURN_RESTART RETURN_RESTART}if the * workbench was terminated with a call to * {@link IWorkbench#restart IWorkbench.restart}; * {@link PlatformUI#RETURN_EMERGENCY_CLOSE} for an emergency * shutdown * {@link PlatformUI#RETURN_UNSTARTABLE RETURN_UNSTARTABLE}if * the workbench could not be started; other values reserved for * future use * * @param force * true to force the workbench close, and false for a "soft" * close that can be canceled * @return true if the close was successful, and false if the close was * canceled */ /* package */ bool Close(int returnCode, bool force); /** * Returns the unique object that applications use to configure the * workbench. *

    * IMPORTANT This method is declared protected to prevent regular * plug-ins from downcasting IWorkbench to Workbench and getting hold of the * workbench configurer that would allow them to tamper with the workbench. * The workbench configurer is available only to the application. *

    */ WorkbenchConfigurer::Pointer GetWorkbenchConfigurer(); /** * Returns the workbench advisor that created this workbench. *

    * IMPORTANT This method is declared protected to prevent regular * plug-ins from downcasting IWorkbench to Workbench and getting hold of the * workbench advisor that would allow them to tamper with the workbench. The * workbench advisor is internal to the application. *

    */ WorkbenchAdvisor* GetAdvisor(); /* * Returns the workbench window which was last known being the active one, * or null . */ SmartPointer GetActivatedWindow(); /* * Sets the workbench window which was last known being the active one, or * null . */ void SetActivatedWindow(SmartPointer window); /** * Fire workbench preShutdown event, stopping at the first one to veto * * @param forced * flag indicating whether the shutdown is being forced * @return true to allow the workbench to proceed with * shutdown, false to veto a non-forced shutdown * @since 3.2 */ bool FirePreShutdown(bool forced); /** * Fire workbench postShutdown event. * * @since 3.2 */ void FirePostShutdown(); /** * Fire window opened event. * * @param window * The window which just opened; should not be null. */ void FireWindowOpened(IWorkbenchWindow::Pointer window); /** * Fire window closed event. * * @param window * The window which just closed; should not be null. */ void FireWindowClosed(IWorkbenchWindow::Pointer window); /** * Fire window activated event. * * @param window * The window which was just activated; should not be * null. */ void FireWindowActivated(IWorkbenchWindow::Pointer window); /** * Fire window deactivated event. * * @param window * The window which was just deactivated; should not be * null. */ void FireWindowDeactivated(IWorkbenchWindow::Pointer window); private: /** * Holds onto the only instance of Workbench. */ static Workbench* instance; /** * The testable object facade. */ static WorkbenchTestable::Pointer testableObject; static const unsigned int VERSION_STRING_COUNT; // = 1; static const std::string VERSION_STRING[1]; static const std::string DEFAULT_WORKBENCH_STATE_FILENAME; // = "workbench.xml"; IWorkbenchListener::Events workbenchEvents; IWindowListener::Events windowEvents; WorkbenchAdvisor* advisor; WorkbenchConfigurer::Pointer workbenchConfigurer; /** * The service locator maintained by the workbench. These services are * initialized during workbench during the init method. */ ServiceLocator::Pointer serviceLocator; /** * A count of how many plug-ins were loaded while restoring the workbench * state. Initially -1 for unknown number. */ int progressCount; /** * A field to hold the workbench windows that have been restored. In the * event that not all windows have been restored, this field allows the * openWindowsAfterRestore method to open some windows. */ std::vector createdWindows; struct ServiceLocatorOwner : public IDisposable { ServiceLocatorOwner(Workbench* workbench); void Dispose(); private: Workbench* workbench; }; friend struct ServiceLocatorOwner; IDisposable::Pointer serviceLocatorOwner; /** * A count of how many large updates are going on. This tracks nesting of * requests to disable services during a large update -- similar to the * setRedraw functionality on Control. When * this value becomes greater than zero, services are disabled. When this * value becomes zero, services are enabled. Please see * largeUpdateStart() and largeUpdateEnd(). */ int largeUpdates; /** * The display used for all UI interactions with this workbench. */ Display* display; WindowManager windowManager; SmartPointer activatedWindow; WorkbenchIntroManager* introManager; /** * The descriptor for the intro extension that is valid for this workspace, * null if none. */ IntroDescriptor::Pointer introDescriptor; bool isStarting; bool isClosing; int returnCode; std::string factoryID; /** * Creates a new workbench. * * @param display * the display to be used for all UI interactions with the * workbench * @param advisor * the application-specific advisor that configures and * specializes this workbench instance */ Workbench(Display*, WorkbenchAdvisor* advisor); /** * see IWorkbench#GetDisplay */ Display* GetDisplay(); /* * Creates a new workbench window. * * @return the new workbench window */ SmartPointer NewWorkbenchWindow(); void OpenWindowsAfterRestore(); /* * Returns the number for a new window. This will be the first number > 0 * which is not used to identify another window in the workbench. */ int GetNewWindowNumber(); /** * Initializes all of the default services for the workbench. For * initializing the command-based services, this also parses the registry * and hooks up all the required listeners. */ void InitializeDefaultServices(); /** * Closes the workbench. Assumes that the busy cursor is active. * * @param force * true if the close is mandatory, and false if the close is * allowed to fail * @return true if the close succeeded, and false otherwise */ bool BusyClose(bool force); /* * Record the workbench UI in a document */ XMLMemento::Pointer RecordWorkbenchState(); /* * Restores the state of the previously saved workbench */ bool RestoreState(IMemento::Pointer memento); void DoRestoreState(IMemento::Pointer memento, bool& result); /* * Saves the current state of the workbench so it can be restored later on */ bool SaveState(IMemento::Pointer memento); /* * Save the workbench UI in a persistence file. */ bool SaveMementoToFile(XMLMemento::Pointer memento); /* * Answer the workbench state file. */ bool GetWorkbenchStateFile(Poco::File& file); /* * Shuts down the application. */ void Shutdown(); /** * Opens a new workbench window and page with a specific perspective. * * Assumes that busy cursor is active. */ IWorkbenchWindow::Pointer BusyOpenWorkbenchWindow(const std::string& perspID, IAdaptable* input); }; } // namespace berry #endif /*BERRYWORKBENCH_H_*/ diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryWorkbenchPage.cpp b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryWorkbenchPage.cpp index de8dcd70a1..dc7eca49d6 100644 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryWorkbenchPage.cpp +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryWorkbenchPage.cpp @@ -1,4111 +1,4111 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "berryLog.h" #include "tweaklets/berryGuiWidgetsTweaklet.h" #include "tweaklets/berryWorkbenchPageTweaklet.h" #include "berryWorkbenchPage.h" #include "berryPartSite.h" #include "berryWorkbenchRegistryConstants.h" #include "berryPerspective.h" #include "berryLayoutPartSash.h" #include "berryWorkbenchPlugin.h" #include "berryEditorAreaHelper.h" #include "berrySaveablesList.h" #include "berryPerspectiveHelper.h" #include "berryLayoutTreeNode.h" #include "berryWorkbench.h" #include "berryWorkbenchConstants.h" #include "berryPartService.h" #include "berryStickyViewManager.h" #include "intro/berryIntroConstants.h" #include "intro/berryViewIntroAdapterPart.h" #include "dialogs/berryMessageDialog.h" #include "berryWorkbenchWindow.h" #include "berryUIException.h" #include "berryPlatformUI.h" #include "berryPartPane.h" #include "berryImageDescriptor.h" #include #include namespace berry { WorkbenchPage::ActivationOrderPred::ActivationOrderPred( WorkbenchPage::ActivationList* al) : activationList(al) { } bool WorkbenchPage::ActivationOrderPred::operator()( const IViewReference::Pointer o1, const IViewReference::Pointer o2) const { WorkbenchPage::ActivationList::PartListIter pos1 = activationList->IndexOf( o1.Cast ()); WorkbenchPage::ActivationList::PartListIter pos2 = activationList->IndexOf( o2.Cast ()); return pos1 < pos2; } void WorkbenchPage::PerspectiveList::UpdateActionSets( Perspective::Pointer /*oldPersp*/, Perspective::Pointer /*newPersp*/) { //TODO WorkbenchPage action sets // // Update action sets // // IContextService service = (IContextService) window // .getService(IContextService.class); // try { // service.activateContext(ContextAuthority.DEFER_EVENTS); // if (newPersp != 0) { // IActionSetDescriptor[] newAlwaysOn = newPersp // .getAlwaysOnActionSets(); // for (int i = 0; i < newAlwaysOn.length; i++) { // IActionSetDescriptor descriptor = newAlwaysOn[i]; // // actionSets.showAction(descriptor); // } // // IActionSetDescriptor[] newAlwaysOff = newPersp // .getAlwaysOffActionSets(); // for (int i = 0; i < newAlwaysOff.length; i++) { // IActionSetDescriptor descriptor = newAlwaysOff[i]; // // actionSets.maskAction(descriptor); // } // } // // if (oldPersp != 0) { // IActionSetDescriptor[] newAlwaysOn = oldPersp // .getAlwaysOnActionSets(); // for (int i = 0; i < newAlwaysOn.length; i++) { // IActionSetDescriptor descriptor = newAlwaysOn[i]; // // actionSets.hideAction(descriptor); // } // // IActionSetDescriptor[] newAlwaysOff = oldPersp // .getAlwaysOffActionSets(); // for (int i = 0; i < newAlwaysOff.length; i++) { // IActionSetDescriptor descriptor = newAlwaysOff[i]; // // actionSets.unmaskAction(descriptor); // } // } // } finally { // service.activateContext(ContextAuthority.SEND_EVENTS); // } } WorkbenchPage::PerspectiveList::PerspectiveList() { } void WorkbenchPage::PerspectiveList::Reorder( IPerspectiveDescriptor::Pointer perspective, int newLoc) { PerspectiveListType::iterator oldLocation = openedList.end(); Perspective::Pointer movedPerspective; for (PerspectiveListType::iterator iterator = openedList.begin(); iterator != openedList.end(); ++iterator) { Perspective::Pointer openPerspective = *iterator; if (openPerspective->GetDesc() == perspective) { oldLocation = std::find(openedList.begin(), openedList.end(), openPerspective); movedPerspective = openPerspective; } } PerspectiveListType::iterator newLocation = openedList.begin(); for (int i = 0; i < newLoc; ++i, ++newLocation) ; if (oldLocation == newLocation) { return; } openedList.erase(oldLocation); openedList.insert(newLocation, movedPerspective); } WorkbenchPage::PerspectiveList::PerspectiveListType WorkbenchPage::PerspectiveList::GetSortedPerspectives() { return usedList; } bool WorkbenchPage::PerspectiveList::Add(Perspective::Pointer perspective) { openedList.push_back(perspective); usedList.push_front(perspective); //It will be moved to top only when activated. return true; } WorkbenchPage::PerspectiveList::PerspectiveListType::iterator WorkbenchPage::PerspectiveList::Begin() { return openedList.begin(); } WorkbenchPage::PerspectiveList::PerspectiveListType::iterator WorkbenchPage::PerspectiveList::End() { return openedList.end(); } WorkbenchPage::PerspectiveList::PerspectiveListType WorkbenchPage::PerspectiveList::GetOpenedPerspectives() { return openedList; } bool WorkbenchPage::PerspectiveList::Remove(Perspective::Pointer perspective) { if (active == perspective) { this->UpdateActionSets(active, Perspective::Pointer(0)); active = 0; } usedList.remove(perspective); PerspectiveListType::size_type origSize = openedList.size(); openedList.remove(perspective); return openedList.size() != origSize; } void WorkbenchPage::PerspectiveList::Swap(Perspective::Pointer oldPerspective, Perspective::Pointer newPerspective) { PerspectiveListType::iterator oldIter = std::find(openedList.begin(), openedList.end(), oldPerspective); PerspectiveListType::iterator newIter = std::find(openedList.begin(), openedList.end(), newPerspective); if (oldIter == openedList.end() || newIter == openedList.end()) { return; } std::iter_swap(oldIter, newIter); } bool WorkbenchPage::PerspectiveList::IsEmpty() { return openedList.empty(); } Perspective::Pointer WorkbenchPage::PerspectiveList::GetActive() { return active; } Perspective::Pointer WorkbenchPage::PerspectiveList::GetNextActive() { if (active == 0) { if (usedList.empty()) { return Perspective::Pointer(0); } else { return usedList.back(); } } else { if (usedList.size() < 2) { return Perspective::Pointer(0); } else { return *(++usedList.rbegin()); } } } WorkbenchPage::PerspectiveList::PerspectiveListType::size_type WorkbenchPage::PerspectiveList::Size() { return openedList.size(); } void WorkbenchPage::PerspectiveList::SetActive(Perspective::Pointer perspective) { if (perspective == active) { return; } this->UpdateActionSets(active, perspective); active = perspective; if (perspective != 0) { usedList.remove(perspective); usedList.push_back(perspective); } } WorkbenchPage::ActivationList::ActivationList(WorkbenchPage* page) : page(page) { } void WorkbenchPage::ActivationList::SetActive(SmartPointer part) { if (parts.empty()) { return; } IWorkbenchPartReference::Pointer ref(page->GetReference(part)); if (ref) { if (ref == parts.back()) { return; } parts.erase(std::find(parts.begin(), parts.end(), ref)); parts.push_back(ref); } } void WorkbenchPage::ActivationList::BringToTop(SmartPointer< IWorkbenchPartReference> ref) { - IStackableContainer::Pointer targetContainer(page->GetContainer(ref)); + ILayoutContainer::Pointer targetContainer(page->GetContainer(ref)); PartListIter newIndex = this->LastIndexOfContainer(targetContainer); if (newIndex != parts.end() && ref == *newIndex) { return; } if (newIndex == parts.end()) { parts.push_back(ref); } else { PartListType::size_type index = newIndex - parts.begin(); parts.erase(std::find(parts.begin(), parts.end(), ref)); PartListIter insertIndex = parts.begin() + index; parts.insert(insertIndex, ref); } } WorkbenchPage::ActivationList::PartListIter WorkbenchPage::ActivationList::LastIndexOfContainer( - SmartPointer container) + SmartPointer container) { PartListReverseIter i = parts.rbegin(); while (i != parts.rend()) { IWorkbenchPartReference::Pointer ref(*i); - IStackableContainer::Pointer cnt(page->GetContainer(ref)); + ILayoutContainer::Pointer cnt(page->GetContainer(ref)); if (cnt == container) { return --i.base(); } ++i; } return parts.end(); } void WorkbenchPage::ActivationList::SetActive(SmartPointer< IWorkbenchPartReference> ref) { this->SetActive(ref->GetPart(true)); } void WorkbenchPage::ActivationList::Add( SmartPointer ref) { if (std::find(parts.begin(), parts.end(), ref) != parts.end()) { return; } ref->GetPart(false); parts.push_front(ref); } SmartPointer WorkbenchPage::ActivationList::GetActive() { if (parts.empty()) { return IWorkbenchPart::Pointer(0); } return this->GetActive(parts.end()); } SmartPointer WorkbenchPage::ActivationList::GetPreviouslyActive() { if (parts.size() < 2) { return IWorkbenchPart::Pointer(0); } return this->GetActive(--parts.end()); } SmartPointer WorkbenchPage::ActivationList::GetActiveReference( bool editorsOnly) { return this->GetActiveReference(parts.end(), editorsOnly); } WorkbenchPage::ActivationList::PartListIter WorkbenchPage::ActivationList::IndexOf( SmartPointer part) { IWorkbenchPartReference::Pointer ref(page->GetReference(part)); if (ref == 0) { return parts.end(); } return std::find(parts.begin(), parts.end(), ref); } WorkbenchPage::ActivationList::PartListIter WorkbenchPage::ActivationList::IndexOf( SmartPointer ref) { return std::find(parts.begin(), parts.end(), ref); } bool WorkbenchPage::ActivationList::Remove( SmartPointer ref) { bool contains = std::find(parts.begin(), parts.end(), ref) != parts.end(); parts.erase(std::find(parts.begin(), parts.end(), ref)); return contains; } SmartPointer WorkbenchPage::ActivationList::GetTopEditor() { IEditorReference::Pointer editor = this->GetActiveReference(parts.end(), true).Cast (); if (editor == 0) { return IEditorPart::Pointer(0); } return editor->GetEditor(true); } SmartPointer WorkbenchPage::ActivationList::GetActive( PartListIter start) { IWorkbenchPartReference::Pointer ref(this->GetActiveReference(start, false)); if (!ref) { return IWorkbenchPart::Pointer(0); } return ref->GetPart(true); } SmartPointer WorkbenchPage::ActivationList::GetActiveReference( PartListIter start, bool editorsOnly) { // First look for parts that aren't obscured by the current zoom state IWorkbenchPartReference::Pointer nonObscured = this->GetActiveReference( start, editorsOnly, true); if (nonObscured) { return nonObscured; } // Now try all the rest of the parts return this->GetActiveReference(start, editorsOnly, false); } SmartPointer WorkbenchPage::ActivationList::GetActiveReference( PartListIter start, bool editorsOnly, bool /*skipPartsObscuredByZoom*/) { std::vector views = page->GetViewReferences(); PartListReverseIter i(start); while (i != parts.rend()) { WorkbenchPartReference::Pointer ref(i->Cast ()); if (editorsOnly && (ref.Cast () == 0)) { ++i; continue; } // Skip parts whose containers have disabled auto-focus PartPane::Pointer pane(ref->GetPane()); if (pane) { if (!pane->AllowsAutoFocus()) { ++i; continue; } // if (skipPartsObscuredByZoom) { // if (pane.isObscuredByZoom()) { // continue; // } // } } // Skip fastviews (unless overridden) if (IViewReference::Pointer viewRef = ref.Cast()) { //if (ref == getActiveFastView() || !((IViewReference) ref).isFastView()) { for (unsigned int j = 0; j < views.size(); j++) { if (views[j] == viewRef) { return viewRef.Cast (); } } //} } else { return ref.Cast (); } ++i; } return IWorkbenchPartReference::Pointer(0); } std::vector > WorkbenchPage::ActivationList::GetEditors() { std::vector editors; for (PartListIter i = parts.begin(); i != parts.end(); ++i) { if (IEditorReference::Pointer part = i->Cast()) { editors.push_back(part); } } return editors; } std::vector > WorkbenchPage::ActivationList::GetParts() { std::vector views(page->GetViewReferences()); std::vector resultList; for (PartListIter iterator = parts.begin(); iterator != parts.end(); ++iterator) { if (IViewReference::Pointer ref = iterator->Cast()) { //Filter views from other perspectives for (unsigned int i = 0; i < views.size(); i++) { if (ref == views[i]) { resultList.push_back(ref); break; } } } else { resultList.push_back(*iterator); } } return resultList; } void WorkbenchPage::ActionSwitcher::UpdateActivePart( IWorkbenchPart::Pointer newPart) { IWorkbenchPart::Pointer _activePart = this->activePart.Lock(); IEditorPart::Pointer _topEditor = this->topEditor.Lock(); if (_activePart == newPart) { return; } bool isNewPartAnEditor = newPart.Cast ().IsNotNull(); if (isNewPartAnEditor) { std::string oldId; if (_topEditor) { oldId = _topEditor->GetSite()->GetId(); } std::string newId = newPart->GetSite()->GetId(); // if the active part is an editor and the new editor // is the same kind of editor, then we don't have to do // anything if (activePart == topEditor && newId == oldId) { activePart = newPart; topEditor = newPart.Cast (); return; } // remove the contributions of the old editor // if it is a different kind of editor if (oldId != newId) { this->DeactivateContributions(_topEditor, true); } // if a view was the active part, disable its contributions if (_activePart && _activePart != _topEditor) { this->DeactivateContributions(_activePart, true); } // show (and enable) the contributions of the new editor // if it is a different kind of editor or if the // old active part was a view if (newId != oldId || _activePart != _topEditor) { this->ActivateContributions(newPart, true); } } else if (newPart.IsNull()) { if (_activePart) { // remove all contributions this->DeactivateContributions(_activePart, true); } } else { // new part is a view // if old active part is a view, remove all contributions, // but if old part is an editor only disable if (_activePart) { this->DeactivateContributions(_activePart, _activePart.Cast ().IsNotNull()); } this->ActivateContributions(newPart, true); } //TODO WorkbenchPage action sets // ArrayList newActionSets = 0; // if (isNewPartAnEditor || (activePart == topEditor && newPart == 0)) // { // newActionSets = calculateActionSets(newPart, 0); // } // else // { // newActionSets = calculateActionSets(newPart, topEditor); // } // // if (!updateActionSets(newActionSets)) // { // updateActionBars(); // } if (isNewPartAnEditor) { topEditor = newPart.Cast (); } else if (activePart == topEditor && newPart.IsNull()) { // since we removed all the contributions, we clear the top // editor topEditor.Reset(); } activePart = newPart; } void WorkbenchPage::ActionSwitcher::UpdateTopEditor( IEditorPart::Pointer newEditor) { if (topEditor.Lock() == newEditor) { return; } if (activePart == topEditor) { this->UpdateActivePart(newEditor); return; } std::string oldId; if (!topEditor.Expired()) { oldId = topEditor.Lock()->GetSite()->GetId(); } std::string newId; if (newEditor.IsNotNull()) { newId = newEditor->GetSite()->GetId(); } if (oldId == newId) { // we don't have to change anything topEditor = newEditor; return; } // Remove the contributions of the old editor if (!topEditor.Expired()) { this->DeactivateContributions(topEditor.Lock(), true); } // Show (disabled) the contributions of the new editor if (newEditor.IsNotNull()) { this->ActivateContributions(newEditor, false); } // ArrayList newActionSets = calculateActionSets(activePart, newEditor); // if (!updateActionSets(newActionSets)) // { // updateActionBars(); // } topEditor = newEditor; } void WorkbenchPage::ActionSwitcher::ActivateContributions( IWorkbenchPart::Pointer /*part*/, bool /*enable*/) { //PartSite::Pointer site = part->GetSite().Cast (); //site->ActivateActionBars(enable); } void WorkbenchPage::ActionSwitcher::DeactivateContributions( IWorkbenchPart::Pointer /*part*/, bool /*remove*/) { //PartSite::Pointer site = part->GetSite().Cast (); //site->DeactivateActionBars(remove); } const IExtensionPoint* WorkbenchPage::GetPerspectiveExtensionPoint() { return Platform::GetExtensionPointService()->GetExtensionPoint( PlatformUI::PLUGIN_ID + "." + WorkbenchRegistryConstants::PL_PERSPECTIVE_EXTENSIONS); } WorkbenchPage::WorkbenchPage(WorkbenchWindow* w, const std::string& layoutID, IAdaptable* input) { if (layoutID == "") { throw WorkbenchException("Perspective ID is undefined"); } this->Register(); this->Init(w, layoutID, input, true); this->UnRegister(false); } WorkbenchPage::WorkbenchPage(WorkbenchWindow* w, IAdaptable* input) { this->Register(); this->Init(w, "", input, false); this->UnRegister(false); } void WorkbenchPage::Activate(IWorkbenchPart::Pointer part) { // Sanity check. if (!this->CertifyPart(part)) { return; } if (window->IsClosing()) { return; } // if (composite!=0 && composite.isVisible() && !((GrabFocus)Tweaklets.get(GrabFocus.KEY)).grabFocusAllowed(part)) // { // return; // } // Activate part. //if (window.getActivePage() == this) { IWorkbenchPartReference::Pointer ref = this->GetReference(part); this->InternalBringToTop(ref); this->SetActivePart(part); } void WorkbenchPage::ActivatePart(const IWorkbenchPart::Pointer part) { // Platform.run(new SafeRunnable(WorkbenchMessages.WorkbenchPage_ErrorActivatingView) // { // public void WorkbenchPage::run() // { if (part.IsNotNull()) { //part.setFocus(); PartPane::Pointer pane = this->GetPane(part); pane->SetFocus(); PartSite::Pointer site = part->GetSite().Cast (); pane->ShowFocus(true); //this->UpdateTabList(part); //SubActionBars bars = (SubActionBars) site.getActionBars(); //bars.partChanged(part); } // } // } // ); } void WorkbenchPage::AddPartListener(IPartListener::Pointer l) { partList->GetPartService()->AddPartListener(l); } void WorkbenchPage::AddSelectionListener(ISelectionListener::Pointer listener) { selectionService->AddSelectionListener(listener); } void WorkbenchPage::AddSelectionListener(const std::string& partId, ISelectionListener::Pointer listener) { selectionService->AddSelectionListener(partId, listener); } void WorkbenchPage::AddPostSelectionListener( ISelectionListener::Pointer listener) { selectionService->AddPostSelectionListener(listener); } void WorkbenchPage::AddPostSelectionListener(const std::string& partId, ISelectionListener::Pointer listener) { selectionService->AddPostSelectionListener(partId, listener); } -IStackableContainer::Pointer WorkbenchPage::GetContainer( +ILayoutContainer::Pointer WorkbenchPage::GetContainer( IWorkbenchPart::Pointer part) { PartPane::Pointer pane = this->GetPane(part); if (pane == 0) { - return IStackableContainer::Pointer(0); + return ILayoutContainer::Pointer(0); } return pane->GetContainer(); } -IStackableContainer::Pointer WorkbenchPage::GetContainer( +ILayoutContainer::Pointer WorkbenchPage::GetContainer( IWorkbenchPartReference::Pointer part) { PartPane::Pointer pane = this->GetPane(part); if (pane == 0) { - return IStackableContainer::Pointer(0); + return ILayoutContainer::Pointer(0); } return pane->GetContainer(); } PartPane::Pointer WorkbenchPage::GetPane(IWorkbenchPart::Pointer part) { if (part.IsNull()) { return PartPane::Pointer(0); } return this->GetPane(this->GetReference(part)); } PartPane::Pointer WorkbenchPage::GetPane(IWorkbenchPartReference::Pointer part) { if (part.IsNull()) { return PartPane::Pointer(0); } return part.Cast ()->GetPane(); } bool WorkbenchPage::InternalBringToTop(IWorkbenchPartReference::Pointer part) { bool broughtToTop = false; // Move part. if (part.Cast ().IsNotNull()) { - IStackableContainer::Pointer container = this->GetContainer(part); + ILayoutContainer::Pointer container = this->GetContainer(part); if (container.Cast () != 0) { PartStack::Pointer stack = container.Cast (); PartPane::Pointer newPart = this->GetPane(part); if (stack->GetSelection() != newPart) { stack->SetSelection(newPart); } broughtToTop = true; } } else if (part.Cast ().IsNotNull()) { Perspective::Pointer persp = this->GetActivePerspective(); if (persp != 0) { broughtToTop = persp->BringToTop(part.Cast ()); } } // Ensure that this part is considered the most recently activated part // in this stack activationList->BringToTop(part); return broughtToTop; } void WorkbenchPage::BringToTop(IWorkbenchPart::Pointer part) { // Sanity check. Perspective::Pointer persp = this->GetActivePerspective(); if (persp == 0 || !this->CertifyPart(part)) { return; } // if (!((GrabFocus)Tweaklets.get(GrabFocus.KEY)).grabFocusAllowed(part)) // { // return; // } // std::string label; // debugging only // if (UIStats.isDebugging(UIStats.BRING_PART_TO_TOP)) // { // label = part != 0 ? part.getTitle() : "none"; //$NON-NLS-1$ // } IWorkbenchPartReference::Pointer ref = this->GetReference(part); - IStackableContainer::Pointer activeEditorContainer = this->GetContainer( + ILayoutContainer::Pointer activeEditorContainer = this->GetContainer( this->GetActiveEditor().Cast ()); - IStackableContainer::Pointer activePartContainer = this->GetContainer( + ILayoutContainer::Pointer activePartContainer = this->GetContainer( this->GetActivePart()); - IStackableContainer::Pointer newPartContainer = this->GetContainer(part); + ILayoutContainer::Pointer newPartContainer = this->GetContainer(part); if (newPartContainer == activePartContainer) { this->MakeActive(ref); } else if (newPartContainer == activeEditorContainer) { if (ref.Cast () != 0) { if (part != 0) { IWorkbenchPartSite::Pointer site = part->GetSite(); if (site.Cast () != 0) { ref = site.Cast ()->GetPane()->GetPartReference(); } } this->MakeActiveEditor(ref.Cast ()); } else { this->MakeActiveEditor(IEditorReference::Pointer(0)); } } else { this->InternalBringToTop(ref); if (ref != 0) { partList->FirePartBroughtToTop(ref); } } } void WorkbenchPage::BusyResetPerspective() { ViewIntroAdapterPart::Pointer introViewAdapter = dynamic_cast (GetWorkbenchWindow() ->GetWorkbench()->GetIntroManager())->GetIntroAdapterPart().Cast< ViewIntroAdapterPart> (); // PartPane introPane = 0; // boolean introFullScreen = false; // if (introViewAdapter != 0) // { // introPane = ((PartSite) introViewAdapter.getSite()).getPane(); // introViewAdapter.setHandleZoomEvents(false); // introFullScreen = introPane.isZoomed(); // } // //try to prevent intro flicker. // if (introFullScreen) // { // window.getShell().setRedraw(false); // } // try // { // // Always unzoom // if (isZoomed()) // { // zoomOut(); // } // Get the current perspective. // This describes the working layout of the page and differs from // the original template. Perspective::Pointer oldPersp = this->GetActivePerspective(); // Map the current perspective to the original template. // If the original template cannot be found then it has been deleted. // In that case just return. (PR#1GDSABU). IPerspectiveRegistry* reg = WorkbenchPlugin::GetDefault() ->GetPerspectiveRegistry(); PerspectiveDescriptor::Pointer desc = reg->FindPerspectiveWithId( oldPersp->GetDesc()->GetId()).Cast (); if (desc == 0) { desc = reg->FindPerspectiveWithId(oldPersp ->GetDesc().Cast< PerspectiveDescriptor> ()->GetOriginalId()).Cast< PerspectiveDescriptor> (); } if (desc == 0) { return; } // Notify listeners that we are doing a reset. window->FirePerspectiveChanged(IWorkbenchPage::Pointer(this), desc, CHANGE_RESET); // Create new persp from original template. // Suppress the perspectiveOpened and perspectiveClosed events otherwise it looks like two // instances of the same perspective are open temporarily (see bug 127470). Perspective::Pointer newPersp = this->CreatePerspective(desc, false); if (newPersp == 0) { // We're not going through with the reset, so it is complete. window->FirePerspectiveChanged(IWorkbenchPage::Pointer(this), desc, CHANGE_RESET_COMPLETE); return; } // Update the perspective list and shortcut perspList.Swap(oldPersp, newPersp); // Install new persp. this->SetPerspective(newPersp); // Destroy old persp. this->DisposePerspective(oldPersp, false); // Update the Coolbar layout. this->ResetToolBarLayout(); // restore the maximized intro if (introViewAdapter) { try { // ensure that the intro is visible in the new perspective ShowView(IntroConstants::INTRO_VIEW_ID); // if (introFullScreen) // { // toggleZoom(introPane.getPartReference()); // } } catch (PartInitException& e) { //TODO IStatus WorkbenchPlugin::Log("Could not restore intro", e); // WorkbenchPlugin.getStatus(e)); } // finally // { // // we want the intro back to a normal state before we fire the event // introViewAdapter.setHandleZoomEvents(true); // } } // Notify listeners that we have completed our reset. window->FirePerspectiveChanged(IWorkbenchPage::Pointer(this), desc, CHANGE_RESET_COMPLETE); // } // finally // { // // reset the handling of zoom events (possibly for the second time) in case there was // // an exception thrown // if (introViewAdapter != 0) // { // introViewAdapter.setHandleZoomEvents(true); // } // // if (introFullScreen) // { // window.getShell().setRedraw(true); // } // } } void WorkbenchPage::BusySetPerspective(IPerspectiveDescriptor::Pointer desc) { // Create new layout. std::string label = desc->GetId(); // debugging only Perspective::Pointer newPersp; //try //{ //UIStats.start(UIStats.SWITCH_PERSPECTIVE, label); PerspectiveDescriptor::Pointer realDesc = desc.Cast (); newPersp = this->FindPerspective(realDesc); if (newPersp == 0) { newPersp = this->CreatePerspective(realDesc, true); if (newPersp == 0) { return; } } // Change layout. this->SetPerspective(newPersp); // } // catch (std::exception& e) // { // UIStats.end(UIStats.SWITCH_PERSPECTIVE, desc.getId(), label); // throw e; // } } IViewPart::Pointer WorkbenchPage::BusyShowView(const std::string& viewID, const std::string& secondaryID, int mode) { Perspective::Pointer persp = this->GetActivePerspective(); if (persp == 0) { return IViewPart::Pointer(0); } // If this view is already visible just return. IViewReference::Pointer ref = persp->FindView(viewID, secondaryID); IViewPart::Pointer view; if (ref != 0) { view = ref->GetView(true); } if (view != 0) { this->BusyShowView(view, mode); return view; } // Show the view. view = persp->ShowView(viewID, secondaryID); if (view != 0) { this->BusyShowView(view, mode); IWorkbenchPartReference::Pointer partReference = this->GetReference(view); PartPane::Pointer partPane = this->GetPane(partReference); partPane->SetInLayout(true); IWorkbenchPage::Pointer thisPage(this); window->FirePerspectiveChanged(thisPage, GetPerspective(), partReference, CHANGE_VIEW_SHOW); window->FirePerspectiveChanged(thisPage, GetPerspective(), CHANGE_VIEW_SHOW); } return view; } void WorkbenchPage::BusyShowView(IViewPart::Pointer part, int mode) { // if (!((GrabFocus) Tweaklets.get(GrabFocus.KEY)).grabFocusAllowed(part)) // { // return; // } if (mode == VIEW_ACTIVATE) { this->Activate(part); } else if (mode == VIEW_VISIBLE) { IWorkbenchPartReference::Pointer ref = this->GetActivePartReference(); // if there is no active part or it's not a view, bring to top if (ref == 0 || ref.Cast () == 0) { this->BringToTop(part); } else { // otherwise check to see if the we're in the same stack as the active view IViewReference::Pointer activeView = ref.Cast (); std::vector viewStack = this->GetViewReferenceStack(part); for (unsigned int i = 0; i < viewStack.size(); i++) { if (viewStack[i] == activeView) { return; } } this->BringToTop(part); } } } bool WorkbenchPage::CertifyPart(IWorkbenchPart::Pointer part) { //Workaround for bug 22325 if (part != 0 && part->GetSite().Cast () == 0) { return false; } if (part.Cast () != 0) { IEditorReference::Pointer ref = this->GetReference(part).Cast< IEditorReference> (); return ref != 0 && this->GetEditorManager()->ContainsEditor(ref); } if (part.Cast () != 0) { Perspective::Pointer persp = this->GetActivePerspective(); return persp != 0 && persp->ContainsView(part.Cast ()); } return false; } bool WorkbenchPage::Close() { bool ret; //BusyIndicator.showWhile(0, new Runnable() // { // public void WorkbenchPage::run() // { ret = window->ClosePage(IWorkbenchPage::Pointer(this), true); // } // }); return ret; } bool WorkbenchPage::CloseAllSavedEditors() { // get the Saved editors std::list editors = this->GetEditorReferences(); std::list savedEditors; for (std::list::iterator iter = editors.begin(); iter != editors.end(); ++iter) { IEditorReference::Pointer editor = *iter; if (!editor->IsDirty()) { savedEditors.push_back(editor); } } //there are no unsaved editors if (savedEditors.empty()) { return true; } return this->CloseEditors(savedEditors, false); } bool WorkbenchPage::CloseAllEditors(bool save) { return this->CloseEditors(this->GetEditorReferences(), save); } void WorkbenchPage::UpdateActivePart() { if (this->IsDeferred()) { return; } IWorkbenchPartReference::Pointer oldActivePart = partList->GetActivePartReference(); IWorkbenchPartReference::Pointer oldActiveEditor = partList->GetActiveEditorReference(); IWorkbenchPartReference::Pointer newActivePart; IEditorReference::Pointer newActiveEditor; if (!window->IsClosing()) { // If an editor is active, try to keep an editor active if (oldActiveEditor && oldActivePart == oldActiveEditor) { newActiveEditor = activationList->GetActiveReference(true).Cast< IEditorReference> (); newActivePart = newActiveEditor; if (newActivePart == 0) { // Only activate a non-editor if there's no editors left newActivePart = activationList->GetActiveReference(false); } } else { // If a non-editor is active, activate whatever was activated most recently newActivePart = activationList->GetActiveReference(false); if (newActivePart.Cast () != 0) { // If that happens to be an editor, make it the active editor as well newActiveEditor = newActivePart.Cast (); } else { // Otherwise, select whatever editor was most recently active newActiveEditor = activationList->GetActiveReference(true).Cast< IEditorReference> (); } } } if (oldActiveEditor != newActiveEditor) { this->MakeActiveEditor(newActiveEditor); } if (newActivePart != oldActivePart) { this->MakeActive(newActivePart); } } void WorkbenchPage::MakeActive(IWorkbenchPartReference::Pointer ref) { if (ref == 0) { this->SetActivePart(IWorkbenchPart::Pointer(0)); } else { IWorkbenchPart::Pointer newActive = ref->GetPart(true); if (newActive == 0) { this->SetActivePart(IWorkbenchPart::Pointer(0)); } else { this->Activate(newActive); } } } void WorkbenchPage::MakeActiveEditor(IEditorReference::Pointer ref) { if (ref == this->GetActiveEditorReference()) { return; } IEditorPart::Pointer part = (ref == 0) ? IEditorPart::Pointer(0) : ref->GetEditor(true); if (part) { editorMgr->SetVisibleEditor(ref, false); //navigationHistory.MarkEditor(part); } actionSwitcher.UpdateTopEditor(part); if (ref) { activationList->BringToTop(this->GetReference(part)); } partList->SetActiveEditor(ref); } bool WorkbenchPage::CloseEditors( const std::list& refArray, bool save) { if (refArray.empty()) { return true; } IWorkbenchPage::Pointer thisPage(this); // Check if we're being asked to close any parts that are already closed or cannot // be closed at this time std::vector editorRefs; for (std::list::const_iterator iter = refArray.begin(); iter != refArray.end(); ++iter) { IEditorReference::Pointer reference = *iter; // If we're in the middle of creating this part, this is a programming error. Abort the entire // close operation. This usually occurs if someone tries to open a dialog in a method that // isn't allowed to do so, and a *syncExec tries to close the part. If this shows up in a log // file with a dialog's event loop on the stack, then the code that opened the dialog is usually // at fault. if (partBeingActivated == reference) { Poco::RuntimeException re( "WARNING: Blocked recursive attempt to close part " //$NON-NLS-1$ + partBeingActivated->GetId() + " while still in the middle of activating it"); WorkbenchPlugin::Log(re); return false; } // if (reference.Cast () != 0) // { // WorkbenchPartReference::Pointer ref = reference.Cast(); // // // If we're being asked to close a part that is disposed (ie: already closed), // // skip it and proceed with closing the remaining parts. // if (ref.isDisposed()) // { // continue; // } // } editorRefs.push_back(reference); } // notify the model manager before the close std::list partsToClose; for (unsigned int i = 0; i < editorRefs.size(); i++) { IWorkbenchPart::Pointer refPart = editorRefs[i]->GetPart(false); if (refPart != 0) { partsToClose.push_back(refPart); } } SaveablesList::Pointer modelManager; SaveablesList::PostCloseInfo::Pointer postCloseInfo; if (partsToClose.size() > 0) { modelManager = this->GetWorkbenchWindow()->GetService( ISaveablesLifecycleListener::GetManifestName()).Cast (); // this may prompt for saving and return 0 if the user canceled: postCloseInfo = modelManager->PreCloseParts(partsToClose, save, this->GetWorkbenchWindow()); if (postCloseInfo == 0) { return false; } } // Fire pre-removal changes for (unsigned int i = 0; i < editorRefs.size(); i++) { IEditorReference::Pointer ref = editorRefs[i]; // Notify interested listeners before the close window->FirePerspectiveChanged(thisPage, this->GetPerspective(), ref, CHANGE_EDITOR_CLOSE); } this->DeferUpdates(true); try { if (modelManager != 0) { modelManager->PostClose(postCloseInfo); } // Close all editors. for (unsigned int i = 0; i < editorRefs.size(); i++) { IEditorReference::Pointer ref = editorRefs[i]; // Remove editor from the presentation editorPresentation->CloseEditor(ref); this->PartRemoved(ref.Cast ()); } } catch (...) { } this->DeferUpdates(false); // Notify interested listeners after the close window->FirePerspectiveChanged(thisPage, this->GetPerspective(), CHANGE_EDITOR_CLOSE); // Return true on success. return true; } void WorkbenchPage::DeferUpdates(bool shouldDefer) { if (shouldDefer) { if (deferCount == 0) { this->StartDeferring(); } deferCount++; } else { deferCount--; if (deferCount == 0) { this->HandleDeferredEvents(); } } } void WorkbenchPage::StartDeferring() { //editorPresentation.getLayoutPart().deferUpdates(true); } void WorkbenchPage::HandleDeferredEvents() { editorPresentation->GetLayoutPart()->DeferUpdates(false); this->UpdateActivePart(); std::vector disposals = pendingDisposals; pendingDisposals.clear(); for (unsigned int i = 0; i < disposals.size(); i++) { this->DisposePart(disposals[i]); } } bool WorkbenchPage::IsDeferred() { return deferCount > 0; } bool WorkbenchPage::CloseEditor(IEditorReference::Pointer editorRef, bool save) { std::list list; list.push_back(editorRef); return this->CloseEditors(list, save); } bool WorkbenchPage::CloseEditor(IEditorPart::Pointer editor, bool save) { IWorkbenchPartReference::Pointer ref = this->GetReference(editor); if (ref.Cast ().IsNotNull()) { std::list list; list.push_back(ref.Cast ()); return this->CloseEditors(list, save); } return false; } void WorkbenchPage::ClosePerspective(IPerspectiveDescriptor::Pointer desc, bool saveParts, bool closePage) { Perspective::Pointer persp = this->FindPerspective(desc); if (persp != 0) { this->ClosePerspective(persp, saveParts, closePage); } } void WorkbenchPage::ClosePerspective(Perspective::Pointer persp, bool saveParts, bool closePage) { // // Always unzoom // if (isZoomed()) // { // zoomOut(); // } std::vector partsToSave; std::list viewsToClose; // collect views that will go away and views that are dirty std::vector viewReferences = persp->GetViewReferences(); for (unsigned int i = 0; i < viewReferences.size(); i++) { IViewReference::Pointer reference = viewReferences[i]; if (this->GetViewFactory()->GetReferenceCount(reference) == 1) { IViewPart::Pointer viewPart = reference->GetView(false); if (viewPart != 0) { viewsToClose.push_back(viewPart); if (saveParts && reference->IsDirty()) { partsToSave.push_back(viewPart); } } } } if (saveParts && perspList.Size() == 1) { // collect editors that are dirty std::list editorReferences = this->GetEditorReferences(); for (std::list::iterator refIter = editorReferences.begin(); refIter != editorReferences.end(); ++refIter) { IEditorReference::Pointer reference = *refIter; if (reference->IsDirty()) { IEditorPart::Pointer editorPart = reference->GetEditor(false); if (editorPart != 0) { partsToSave.push_back(editorPart); } } } } if (saveParts && !partsToSave.empty()) { if (!EditorManager::SaveAll(partsToSave, true, true, false, IWorkbenchWindow::Pointer(window))) { // user canceled return; } } // Close all editors on last perspective close if (perspList.Size() == 1 && this->GetEditorManager()->GetEditorCount() > 0) { // Close all editors if (!this->CloseAllEditors(false)) { return; } } // closeAllEditors already notified the saveables list about the editors. SaveablesList::Pointer saveablesList = this->GetWorkbenchWindow()->GetWorkbench()->GetService( ISaveablesLifecycleListener::GetManifestName()).Cast< SaveablesList> (); // we took care of the saving already, so pass in false (postCloseInfo will be non-0) SaveablesList::PostCloseInfo::Pointer postCloseInfo = saveablesList->PreCloseParts(viewsToClose, false, this->GetWorkbenchWindow()); saveablesList->PostClose(postCloseInfo); // Dispose of the perspective bool isActive = (perspList.GetActive() == persp); if (isActive) { this->SetPerspective(perspList.GetNextActive()); } this->DisposePerspective(persp, true); if (closePage && perspList.Size() == 0) { this->Close(); } } void WorkbenchPage::CloseAllPerspectives(bool saveEditors, bool closePage) { if (perspList.IsEmpty()) { return; } // // Always unzoom // if (isZoomed()) // { // zoomOut(); // } if (saveEditors) { if (!this->SaveAllEditors(true)) { return; } } // Close all editors if (!this->CloseAllEditors(false)) { return; } // Deactivate the active perspective and part this->SetPerspective(Perspective::Pointer(0)); // Close each perspective in turn PerspectiveList oldList = perspList; perspList = PerspectiveList(); for (PerspectiveList::iterator itr = oldList.Begin(); itr != oldList.End(); ++itr) { this->ClosePerspective(*itr, false, false); } if (closePage) { this->Close(); } } void WorkbenchPage::CreateClientComposite() { void* parent = window->GetPageComposite(); // StartupThreading.runWithoutExceptions(new StartupRunnable() // { // // public void WorkbenchPage::runWithException() // { composite = Tweaklets::Get(WorkbenchPageTweaklet::KEY)->CreateClientComposite( parent); Tweaklets::Get(GuiWidgetsTweaklet::KEY)->SetVisible(composite, false); // Make visible on activate. // force the client composite to be layed out // parent.layout(); // } // }); } Perspective::Pointer WorkbenchPage::CreatePerspective( PerspectiveDescriptor::Pointer desc, bool notify) { std::string label = desc->GetId(); // debugging only try { //UIStats.start(UIStats.CREATE_PERSPECTIVE, label); WorkbenchPage::Pointer thisPage(this); Perspective::Pointer persp(new Perspective(desc, thisPage)); perspList.Add(persp); if (notify) { window->FirePerspectiveOpened(thisPage, desc); } //if the perspective is fresh and uncustomzied then it is not dirty //no reset will be prompted for if (!desc->HasCustomDefinition()) { dirtyPerspectives.erase(desc->GetId()); } return persp; } catch (WorkbenchException& /*e*/) { if (!window->GetWorkbenchImpl()->IsStarting()) { MessageDialog::OpenError(window->GetShell(), "Error", "Problems opening perspective \"" + desc->GetId() + "\""); } return Perspective::Pointer(0); } // finally // { // UIStats.end(UIStats.CREATE_PERSPECTIVE, desc.getId(), label); // } } void WorkbenchPage::PartAdded(WorkbenchPartReference::Pointer ref) { activationList->Add(ref); partList->AddPart(ref); this->UpdateActivePart(); } void WorkbenchPage::PartRemoved(WorkbenchPartReference::Pointer ref) { activationList->Remove(ref); this->DisposePart(ref); } void WorkbenchPage::DisposePart(WorkbenchPartReference::Pointer ref) { if (this->IsDeferred()) { pendingDisposals.push_back(ref); } else { partList->RemovePart(ref); ref->Dispose(); } } void WorkbenchPage::DeactivatePart(IWorkbenchPart::Pointer part) { if (part.IsNotNull()) { PartSite::Pointer site = part->GetSite().Cast (); site->GetPane()->ShowFocus(false); } } void WorkbenchPage::DetachView(IViewReference::Pointer ref) { Perspective::Pointer persp = this->GetActivePerspective(); if (persp == 0) { return; } PerspectiveHelper* presentation = persp->GetPresentation(); presentation->DetachPart(ref); } void WorkbenchPage::AttachView(IViewReference::Pointer ref) { PerspectiveHelper* presentation = this->GetPerspectivePresentation(); presentation->AttachPart(ref); } WorkbenchPage::~WorkbenchPage() { // increment reference count to prevent recursive deletes this->Register(); { { this->MakeActiveEditor(IEditorReference::Pointer(0)); this->MakeActive(IWorkbenchPartReference::Pointer(0)); // Close and dispose the editors. this->CloseAllEditors(false); // Need to make sure model data is cleaned up when the page is // disposed. Collect all the views on the page and notify the // saveable list of a pre/post close. This will free model data. std::vector partsToClose = this->GetOpenParts(); std::list dirtyParts; for (unsigned int i = 0; i < partsToClose.size(); i++) { IWorkbenchPart::Pointer part = partsToClose[i]->GetPart(false); if (part != 0 && part.Cast () != 0) { dirtyParts.push_back(part); } } SaveablesList::Pointer saveablesList = this->GetWorkbenchWindow()->GetWorkbench()->GetService( ISaveablesLifecycleListener::GetManifestName()).Cast< SaveablesList> (); SaveablesList::PostCloseInfo::Pointer postCloseInfo = saveablesList->PreCloseParts(dirtyParts, false, this->GetWorkbenchWindow()); saveablesList->PostClose(postCloseInfo); IWorkbenchPage::Pointer thisPage(this); // Get rid of perspectives. This will close the views for (PerspectiveList::iterator itr = perspList.Begin(); itr != perspList.End(); ++itr) { Perspective::Pointer perspective = *itr; window->FirePerspectiveClosed(thisPage, perspective->GetDesc()); //perspective->Dispose(); } perspList = PerspectiveList(); // Capture views. std::vector refs = viewFactory->GetViews(); // if (refs.size() > 0) // { // // Dispose views. // for (unsigned int i = 0; i < refs.size(); i++) // { // WorkbenchPartReference::Pointer ref = refs[i].Cast(); // //partList.RemovePart(ref); // //this->FirePartClosed(refs[i]); // // Platform.run(new SafeRunnable() { // // public void run() { // // // WorkbenchPlugin.log(new Status(IStatus.WARNING, WorkbenchPlugin.PI_WORKBENCH, // // // Status.OK, "WorkbenchPage leaked a refcount for view " + ref.getId(), 0)); //$NON-NLS-1$//$NON-NLS-2$ // // ref.dispose(); // // } // // // public void handleException(Throwable e) { // // } // // }); // } // } // Get rid of editor presentation. //editorPresentation->Dispose(); // Get rid of composite. //composite.dispose(); //navigationHistory.dispose(); //stickyViewMan.clear(); // if (tracker != 0) // { // tracker.close(); // } // // if we're destroying a window in a non-shutdown situation then we should // // clean up the working set we made. // if (!window->GetWorkbench()->IsClosing()) // { // if (aggregateWorkingSet != 0) // { // PlatformUI.getWorkbench().getWorkingSetManager().removeWorkingSet( // aggregateWorkingSet); // } // } } partBeingActivated = 0; pendingDisposals.clear(); stickyViewMan = 0; delete viewFactory; delete editorPresentation; delete editorMgr; delete activationList; deferredActivePersp = 0; dirtyPerspectives.clear(); delete selectionService; partList = 0; } // decrement reference count again, without explicit deletion this->UnRegister(false); } void WorkbenchPage::DisposePerspective(Perspective::Pointer persp, bool notify) { // Get rid of perspective. perspList.Remove(persp); if (notify) { IWorkbenchPage::Pointer thisPage(this); window->FirePerspectiveClosed(thisPage, persp->GetDesc()); } //persp->Dispose(); stickyViewMan->Remove(persp->GetDesc()->GetId()); } Perspective::Pointer WorkbenchPage::FindPerspective( IPerspectiveDescriptor::Pointer desc) { for (PerspectiveList::iterator itr = perspList.Begin(); itr != perspList.End(); ++itr) { Perspective::Pointer mgr = *itr; if (desc->GetId() == mgr->GetDesc()->GetId()) { return mgr; } } return Perspective::Pointer(0); } IViewPart::Pointer WorkbenchPage::FindView(const std::string& id) { IViewReference::Pointer ref = this->FindViewReference(id); if (ref == 0) { return IViewPart::Pointer(0); } return ref->GetView(true); } IViewReference::Pointer WorkbenchPage::FindViewReference( const std::string& viewId) { return this->FindViewReference(viewId, ""); } IViewReference::Pointer WorkbenchPage::FindViewReference( const std::string& viewId, const std::string& secondaryId) { Perspective::Pointer persp = this->GetActivePerspective(); if (persp == 0) { return IViewReference::Pointer(0); } return persp->FindView(viewId, secondaryId); } IEditorPart::Pointer WorkbenchPage::GetActiveEditor() { return partList->GetActiveEditor(); } IEditorReference::Pointer WorkbenchPage::GetActiveEditorReference() { return partList->GetActiveEditorReference(); } IWorkbenchPart::Pointer WorkbenchPage::GetActivePart() { return partList->GetActivePart(); } IWorkbenchPartReference::Pointer WorkbenchPage::GetActivePartReference() { return partList->GetActivePartReference(); } Perspective::Pointer WorkbenchPage::GetActivePerspective() { return perspList.GetActive(); } void* WorkbenchPage::GetClientComposite() { return composite; } EditorManager* WorkbenchPage::GetEditorManager() { return editorMgr; } PerspectiveHelper* WorkbenchPage::GetPerspectivePresentation() { if (this->GetActivePerspective() != 0) { return this->GetActivePerspective()->GetPresentation(); } return 0; } /** * Answer the editor presentation. */ EditorAreaHelper* WorkbenchPage::GetEditorPresentation() { return editorPresentation; } std::vector WorkbenchPage::GetEditors() { std::list refs = this->GetEditorReferences(); std::vector result; //Display d = getWorkbenchWindow().getShell().getDisplay(); //Must be backward compatible. // d.syncExec(new Runnable() // { // public void WorkbenchPage::run() // { for (std::list::iterator iter = refs.begin(); iter != refs.end(); ++iter) { IEditorPart::Pointer part = (*iter)->GetEditor(true); if (part != 0) { result.push_back(part); } } // } // }); return result; } std::vector WorkbenchPage::GetDirtyEditors() { return this->GetEditorManager()->GetDirtyEditors(); } std::vector WorkbenchPage::GetDirtyParts() { std::vector result; std::vector allParts = this->GetAllParts(); for (unsigned int i = 0; i < allParts.size(); i++) { IWorkbenchPartReference::Pointer reference = allParts[i]; IWorkbenchPart::Pointer part = reference->GetPart(false); if (part != 0 && part.Cast () != 0) { ISaveablePart::Pointer saveable = part.Cast (); if (saveable->IsDirty()) { result.push_back(saveable); } } } return result; } IEditorPart::Pointer WorkbenchPage::FindEditor(IEditorInput::Pointer input) { return this->GetEditorManager()->FindEditor(input); } std::vector WorkbenchPage::FindEditors( IEditorInput::Pointer input, const std::string& editorId, int matchFlags) { return this->GetEditorManager()->FindEditors(input, editorId, matchFlags); } std::list WorkbenchPage::GetEditorReferences() { return editorPresentation->GetEditors(); } IAdaptable* WorkbenchPage::GetInput() { return input; } std::string WorkbenchPage::GetLabel() { std::string label = ""; // IWorkbenchAdapter adapter = (IWorkbenchAdapter) Util.getAdapter(input, // IWorkbenchAdapter.class); // if (adapter != 0) // { // label = adapter.getLabel(input); // } Perspective::Pointer persp = this->GetActivePerspective(); if (persp != 0) { label = label + " - " + persp->GetDesc()->GetLabel(); } else if (deferredActivePersp != 0) { label = label + " - " + deferredActivePersp->GetLabel(); } return label; } IPerspectiveDescriptor::Pointer WorkbenchPage::GetPerspective() { if (deferredActivePersp != 0) { return deferredActivePersp; } Perspective::Pointer persp = this->GetActivePerspective(); if (persp != 0) { return persp->GetDesc(); } else { return IPerspectiveDescriptor::Pointer(0); } } ISelection::ConstPointer WorkbenchPage::GetSelection() const { return selectionService->GetSelection(); } ISelection::ConstPointer WorkbenchPage::GetSelection(const std::string& partId) { return selectionService->GetSelection(partId); } //ISelectionService::SelectionEvents& WorkbenchPage::GetSelectionEvents(const std::string& partId) //{ // return selectionService->GetSelectionEvents(partId); //} ViewFactory* WorkbenchPage::GetViewFactory() { if (viewFactory == 0) { viewFactory = new ViewFactory(this, WorkbenchPlugin::GetDefault()->GetViewRegistry()); } return viewFactory; } std::vector WorkbenchPage::GetViewReferences() { Perspective::Pointer persp = this->GetActivePerspective(); if (persp != 0) { return persp->GetViewReferences(); } else { return std::vector(); } } std::vector WorkbenchPage::GetViews() { return this->GetViews(Perspective::Pointer(0), true); } std::vector WorkbenchPage::GetViews( Perspective::Pointer persp, bool restore) { if (persp == 0) { persp = this->GetActivePerspective(); } std::vector parts; if (persp != 0) { std::vector refs = persp->GetViewReferences(); for (unsigned int i = 0; i < refs.size(); i++) { IViewPart::Pointer part = refs[i]->GetPart(restore).Cast (); if (part != 0) { parts.push_back(part); } } } return parts; } IWorkbenchWindow::Pointer WorkbenchPage::GetWorkbenchWindow() { return IWorkbenchWindow::Pointer(window); } void WorkbenchPage::HideView(IViewReference::Pointer ref) { // Sanity check. if (ref == 0) { return; } Perspective::Pointer persp = this->GetActivePerspective(); if (persp == 0) { return; } bool promptedForSave = false; IViewPart::Pointer view = ref->GetView(false); if (view != 0) { if (!this->CertifyPart(view)) { return; } // Confirm. if (view.Cast () != 0) { ISaveablePart::Pointer saveable = view.Cast (); if (saveable->IsSaveOnCloseNeeded()) { IWorkbenchWindow::Pointer window = view->GetSite()->GetWorkbenchWindow(); std::vector partsToSave; partsToSave.push_back(view); bool success = EditorManager::SaveAll(partsToSave, true, true, false, window); if (!success) { // the user cancelled. return; } promptedForSave = true; } } } int refCount = this->GetViewFactory()->GetReferenceCount(ref); SaveablesList::Pointer saveablesList; SaveablesList::PostCloseInfo::Pointer postCloseInfo; if (refCount == 1) { IWorkbenchPart::Pointer actualPart = ref->GetPart(false); if (actualPart != 0) { saveablesList = actualPart->GetSite()->GetService( ISaveablesLifecycleListener::GetManifestName()).Cast< SaveablesList> (); std::list partsToClose; partsToClose.push_back(actualPart); postCloseInfo = saveablesList->PreCloseParts(partsToClose, !promptedForSave, this->GetWorkbenchWindow()); if (postCloseInfo == 0) { // cancel return; } } } IWorkbenchPage::Pointer thisPage(this); // Notify interested listeners before the hide window->FirePerspectiveChanged(thisPage, persp->GetDesc(), ref, CHANGE_VIEW_HIDE); PartPane::Pointer pane = this->GetPane(ref.Cast ()); pane->SetInLayout(false); this->UpdateActivePart(); if (saveablesList != 0) { saveablesList->PostClose(postCloseInfo); } // Hide the part. persp->HideView(ref); // Notify interested listeners after the hide window->FirePerspectiveChanged(thisPage, this->GetPerspective(), CHANGE_VIEW_HIDE); } void WorkbenchPage::RefreshActiveView() { this->UpdateActivePart(); } void WorkbenchPage::HideView(IViewPart::Pointer view) { this->HideView(this->GetReference(view).Cast ()); } void WorkbenchPage::Init(WorkbenchWindow* w, const std::string& layoutID, IAdaptable* input, bool openExtras) { // Save args. this->window = w; this->input = input; this->composite = 0; this->viewFactory = 0; this->activationList = new ActivationList(this); this->selectionService = new PageSelectionService(this); this->partList = new WorkbenchPagePartList(this->selectionService); this->stickyViewMan = new StickyViewManager(this); //actionSets = new ActionSetManager(w); deferCount = 0; // Create presentation. this->CreateClientComposite(); editorPresentation = new EditorAreaHelper(this); editorMgr = new EditorManager(WorkbenchWindow::Pointer(window), WorkbenchPage::Pointer(this), editorPresentation); //TODO WorkbenchPage perspective reorder listener? // // add this page as a client to be notified when the UI has re-ordered perspectives // // so that the order can be properly maintained in the receiver. // // E.g. a UI might support drag-and-drop and will need to make this known to ensure // // #saveState and #restoreState do not lose this re-ordering // w.addPerspectiveReorderListener(new IReorderListener() // { // public void WorkbenchPage::reorder(Object perspective, int newLoc) // { // perspList.reorder((IPerspectiveDescriptor)perspective, newLoc); // } // }); if (openExtras) { this->OpenPerspectiveExtras(); } // Get perspective descriptor. if (layoutID != "") { PerspectiveDescriptor::Pointer desc = WorkbenchPlugin::GetDefault()->GetPerspectiveRegistry()->FindPerspectiveWithId( layoutID).Cast (); if (desc == 0) { throw WorkbenchException("Unable to create Perspective " + layoutID + ". There is no corresponding perspective extension."); } Perspective::Pointer persp = this->FindPerspective(desc); if (persp == 0) { persp = this->CreatePerspective(desc, true); } perspList.SetActive(persp); window->FirePerspectiveActivated(IWorkbenchPage::Pointer(this), desc); } // getExtensionTracker() .registerHandler(perspectiveChangeHandler, // ExtensionTracker .createExtensionPointFilter( // getPerspectiveExtensionPoint())); } void WorkbenchPage::OpenPerspectiveExtras() { //TODO WorkbenchPage perspectice extras std::string extras = ""; //PrefUtil.getAPIPreferenceStore().getString( // IWorkbenchPreferenceConstants.PERSPECTIVE_BAR_EXTRAS); Poco::StringTokenizer tok(extras, ", ", Poco::StringTokenizer::TOK_TRIM | Poco::StringTokenizer::TOK_IGNORE_EMPTY); //$NON-NLS-1$ std::vector descs; for (Poco::StringTokenizer::Iterator itr = tok.begin(); itr != tok.end(); ++itr) { std::string id = *itr; IPerspectiveDescriptor::Pointer desc = WorkbenchPlugin::GetDefault()->GetPerspectiveRegistry()->FindPerspectiveWithId( id); if (desc != 0) { descs.push_back(desc); } } // HACK: The perspective switcher currently adds the button for a new perspective to the beginning of the list. // So, we process the extra perspectives in reverse order here to have their buttons appear in the order declared. for (int i = (int) descs.size(); --i >= 0;) { PerspectiveDescriptor::Pointer desc = descs[i].Cast (); if (this->FindPerspective(desc) == 0) { this->CreatePerspective(desc, true); } } } bool WorkbenchPage::IsPartVisible(IWorkbenchPart::Pointer part) { PartPane::Pointer pane = this->GetPane(part); return pane != 0 && pane->GetVisible(); } bool WorkbenchPage::IsEditorAreaVisible() { Perspective::Pointer persp = this->GetActivePerspective(); if (persp == 0) { return false; } return persp->IsEditorAreaVisible(); } bool WorkbenchPage::IsFastView(IViewReference::Pointer /*ref*/) { Perspective::Pointer persp = this->GetActivePerspective(); if (persp != 0) { //return persp->IsFastView(ref); return false; } else { return false; } } bool WorkbenchPage::IsCloseable(IViewReference::Pointer ref) { Perspective::Pointer persp = this->GetActivePerspective(); if (persp != 0) { return persp->IsCloseable(ref); } return false; } bool WorkbenchPage::IsMoveable(IViewReference::Pointer ref) { Perspective::Pointer persp = this->GetActivePerspective(); if (persp != 0) { return persp->IsMoveable(ref); } return false; } bool WorkbenchPage::IsFixedLayout() { Perspective::Pointer persp = this->GetActivePerspective(); if (persp != 0) { return persp->IsFixedLayout(); } else { return false; } } bool WorkbenchPage::IsSaveNeeded() { return this->GetEditorManager()->IsSaveAllNeeded(); } void WorkbenchPage::OnActivate() { Tweaklets::Get(GuiWidgetsTweaklet::KEY)->SetVisible(composite, true); Perspective::Pointer persp = this->GetActivePerspective(); if (persp != 0) { persp->OnActivate(); this->UpdateVisibility(Perspective::Pointer(0), persp); } } void WorkbenchPage::OnDeactivate() { this->MakeActiveEditor(IEditorReference::Pointer(0)); this->MakeActive(IWorkbenchPartReference::Pointer(0)); if (this->GetActivePerspective() != 0) { this->GetActivePerspective()->OnDeactivate(); } Tweaklets::Get(GuiWidgetsTweaklet::KEY)->SetVisible(composite, false); } void WorkbenchPage::ReuseEditor(IReusableEditor::Pointer editor, IEditorInput::Pointer input) { // Rather than calling editor.setInput on the editor directly, we do it through the part reference. // This case lets us detect badly behaved editors that are not firing a PROP_INPUT event in response // to the input change... but if all editors obeyed their API contract, the "else" branch would be // sufficient. IWorkbenchPartReference::Pointer ref = this->GetReference(editor); if (ref.Cast () != 0) { EditorReference::Pointer editorRef = ref.Cast (); editorRef->SetInput(input); } else { editor->SetInput(input); } //navigationHistory.markEditor(editor); } IEditorPart::Pointer WorkbenchPage::OpenEditor(IEditorInput::Pointer input, const std::string& editorID) { return this->OpenEditor(input, editorID, true, MATCH_INPUT); } IEditorPart::Pointer WorkbenchPage::OpenEditor(IEditorInput::Pointer input, const std::string& editorID, bool activate) { return this->OpenEditor(input, editorID, activate, MATCH_INPUT); } IEditorPart::Pointer WorkbenchPage::OpenEditor( const IEditorInput::Pointer input, const std::string& editorID, bool activate, int matchFlags) { return this->OpenEditor(input, editorID, activate, matchFlags, IMemento::Pointer(0)); } IEditorPart::Pointer WorkbenchPage::OpenEditor( const IEditorInput::Pointer input, const std::string& editorID, bool activate, int matchFlags, IMemento::Pointer editorState) { if (input == 0 || editorID == "") { throw Poco::InvalidArgumentException(); } // BusyIndicator.showWhile(window.getWorkbench().getDisplay(), // new Runnable() // { // public void WorkbenchPage::run() // { return this->BusyOpenEditor(input, editorID, activate, matchFlags, editorState); } IEditorPart::Pointer WorkbenchPage::OpenEditorFromDescriptor( IEditorInput::Pointer input, IEditorDescriptor::Pointer editorDescriptor, bool activate, IMemento::Pointer editorState) { if (input == 0 || !(editorDescriptor.Cast () != 0)) { throw Poco::InvalidArgumentException(); } // BusyIndicator.showWhile(window.getWorkbench().getDisplay(), // new Runnable() // { // public void WorkbenchPage::run() // { return this->BusyOpenEditorFromDescriptor(input, editorDescriptor.Cast< EditorDescriptor> (), activate, editorState); // } // }); } IEditorPart::Pointer WorkbenchPage::BusyOpenEditor(IEditorInput::Pointer input, const std::string& editorID, bool activate, int matchFlags, IMemento::Pointer editorState) { Workbench* workbench = this->GetWorkbenchWindow().Cast ()->GetWorkbenchImpl(); workbench->LargeUpdateStart(); IEditorPart::Pointer result; try { result = this->BusyOpenEditorBatched(input, editorID, activate, matchFlags, editorState); } catch (std::exception& e) { workbench->LargeUpdateEnd(); throw e; } workbench->LargeUpdateEnd(); return result; } IEditorPart::Pointer WorkbenchPage::BusyOpenEditorFromDescriptor( IEditorInput::Pointer input, EditorDescriptor::Pointer editorDescriptor, bool activate, IMemento::Pointer editorState) { Workbench* workbench = this->GetWorkbenchWindow().Cast ()->GetWorkbenchImpl(); workbench->LargeUpdateStart(); IEditorPart::Pointer result; try { result = this->BusyOpenEditorFromDescriptorBatched(input, editorDescriptor, activate, editorState); } catch (std::exception& e) { workbench->LargeUpdateEnd(); throw e; } workbench->LargeUpdateEnd(); return result; } IEditorPart::Pointer WorkbenchPage::BusyOpenEditorBatched( IEditorInput::Pointer input, const std::string& editorID, bool activate, int matchFlags, IMemento::Pointer editorState) { // If an editor already exists for the input, use it. IEditorPart::Pointer editor; // Reuse an existing open editor, unless we are in "new editor tab management" mode editor = this->GetEditorManager()->FindEditor(editorID, input, matchFlags); if (editor != 0) { if (IEditorRegistry::SYSTEM_EXTERNAL_EDITOR_ID == editorID) { if (editor->IsDirty()) { std::vector dlgLabels; dlgLabels.push_back("Yes"); dlgLabels.push_back("No"); dlgLabels.push_back("Cancel"); IDialog::Pointer dialog = MessageDialog::CreateMessageDialog( this->GetWorkbenchWindow()->GetShell(), "Save", (void*) 0, // accept the default window icon "\"" + input->GetName() + "\" is opened and has unsaved changes. Do you want to save it?", IDialog::QUESTION, dlgLabels, 0); int saveFile = dialog->Open(); if (saveFile == 0) { // try // { IEditorPart::Pointer editorToSave = editor; // getWorkbenchWindow().run(false, false, // new IRunnableWithProgress() // { // public void WorkbenchPage::run(IProgressMonitor monitor) // throws InvocationTargetException, // InterruptedException // { //TODO progress monitor editorToSave->DoSave();//monitor); // } // }); // } // catch (InvocationTargetException& e) // { // throw(RuntimeException) e->GetTargetException(); // } // catch (InterruptedException& e) // { // return 0; // } } else if (saveFile == 2) { return IEditorPart::Pointer(0); } } } else { // // do the IShowEditorInput notification before showing the editor // // to reduce flicker // if (editor.Cast () != 0) // { // ((IShowEditorInput) editor).showEditorInput(input); // } this->ShowEditor(activate, editor); return editor; } } // Otherwise, create a new one. This may cause the new editor to // become the visible (i.e top) editor. IEditorReference::Pointer ref = this->GetEditorManager()->OpenEditor( editorID, input, true, editorState); if (ref != 0) { editor = ref->GetEditor(true); } if (editor != 0) { this->SetEditorAreaVisible(true); if (activate) { this->Activate(editor); } else { this->BringToTop(editor); } IWorkbenchPage::Pointer thisPage(this); window->FirePerspectiveChanged(thisPage, this->GetPerspective(), ref, CHANGE_EDITOR_OPEN); window->FirePerspectiveChanged(thisPage, this->GetPerspective(), CHANGE_EDITOR_OPEN); } return editor; } /* * Added to fix Bug 178235 [EditorMgmt] DBCS 3.3 - Cannot open file with external program. * See openEditorFromDescriptor(). */ IEditorPart::Pointer WorkbenchPage::BusyOpenEditorFromDescriptorBatched( IEditorInput::Pointer input, EditorDescriptor::Pointer editorDescriptor, bool activate, IMemento::Pointer editorState) { IEditorPart::Pointer editor; // Create a new one. This may cause the new editor to // become the visible (i.e top) editor. IEditorReference::Pointer ref; ref = this->GetEditorManager()->OpenEditorFromDescriptor(editorDescriptor, input, editorState); if (ref != 0) { editor = ref->GetEditor(true); } if (editor != 0) { this->SetEditorAreaVisible(true); if (activate) { this->Activate(editor); } else { this->BringToTop(editor); } IWorkbenchPage::Pointer thisPage(this); window->FirePerspectiveChanged(thisPage, this->GetPerspective(), ref, CHANGE_EDITOR_OPEN); window->FirePerspectiveChanged(thisPage, this->GetPerspective(), CHANGE_EDITOR_OPEN); } return editor; } void WorkbenchPage::OpenEmptyTab() { IEditorPart::Pointer editor; EditorReference::Pointer ref; ref = this->GetEditorManager()->OpenEmptyTab().Cast (); if (ref != 0) { editor = ref->GetEmptyEditor( dynamic_cast (WorkbenchPlugin::GetDefault()->GetEditorRegistry())->FindEditor( EditorRegistry::EMPTY_EDITOR_ID).Cast ()); } if (editor != 0) { this->SetEditorAreaVisible(true); this->Activate(editor); IWorkbenchPage::Pointer thisPage(this); window->FirePerspectiveChanged(thisPage, this->GetPerspective(), ref, CHANGE_EDITOR_OPEN); window->FirePerspectiveChanged(thisPage, this->GetPerspective(), CHANGE_EDITOR_OPEN); } } void WorkbenchPage::ShowEditor(bool activate, IEditorPart::Pointer editor) { this->SetEditorAreaVisible(true); if (activate) { //zoomOutIfNecessary(editor); this->Activate(editor); } else { this->BringToTop(editor); } } bool WorkbenchPage::IsEditorPinned(IEditorPart::Pointer editor) { WorkbenchPartReference::Pointer ref = this->GetReference(editor).Cast< WorkbenchPartReference> (); return ref != 0 && ref->IsPinned(); } /** * Removes an IPartListener from the part service. */ void WorkbenchPage::RemovePartListener(IPartListener::Pointer l) { partList->GetPartService()->RemovePartListener(l); } /** * Implements IWorkbenchPage * * @see org.blueberry.ui.IWorkbenchPage#removePropertyChangeListener(IPropertyChangeListener) * @since 2.0 * @deprecated individual views should store a working set if needed and * register a property change listener directly with the * working set manager to receive notification when the view * working set is removed. */ // void WorkbenchPage::RemovePropertyChangeListener(IPropertyChangeListener listener) { // propertyChangeListeners.remove(listener); // } void WorkbenchPage::RemoveSelectionListener( ISelectionListener::Pointer listener) { selectionService->RemoveSelectionListener(listener); } void WorkbenchPage::RemoveSelectionListener(const std::string& partId, ISelectionListener::Pointer listener) { selectionService->RemoveSelectionListener(partId, listener); } void WorkbenchPage::RemovePostSelectionListener( ISelectionListener::Pointer listener) { selectionService->RemovePostSelectionListener(listener); } void WorkbenchPage::RemovePostSelectionListener(const std::string& partId, ISelectionListener::Pointer listener) { selectionService->RemovePostSelectionListener(partId, listener); } void WorkbenchPage::RequestActivation(IWorkbenchPart::Pointer part) { // Sanity check. if (!this->CertifyPart(part)) { return; } // Real work. this->SetActivePart(part); } /** * Resets the layout for the perspective. The active part in the old layout * is activated in the new layout for consistent user context. */ void WorkbenchPage::ResetPerspective() { // Run op in busy cursor. // Use set redraw to eliminate the "flash" that can occur in the // coolbar as the perspective is reset. // ICoolBarManager2 mgr = (ICoolBarManager2) window.getCoolBarManager2(); // try // { // mgr.getControl2().setRedraw(false); // BusyIndicator.showWhile(0, new Runnable() // { // public void WorkbenchPage::run() // { this->BusyResetPerspective(); // } // }); // }finally // { // mgr.getControl2().setRedraw(true); // } } bool WorkbenchPage::RestoreState(IMemento::Pointer memento, const IPerspectiveDescriptor::Pointer activeDescriptor) { // StartupThreading.runWithoutExceptions(new StartupRunnable() // { // // public void WorkbenchPage::runWithException() throws Throwable // { this->DeferUpdates(true); // }}); try { // Restore working set std::string pageName; memento->GetString(WorkbenchConstants::TAG_LABEL, pageName); // String label = 0; // debugging only // if (UIStats.isDebugging(UIStats.RESTORE_WORKBENCH)) // { // label = pageName == 0 ? "" : "::" + pageName; //$NON-NLS-1$ //$NON-NLS-2$ // } try { //UIStats.start(UIStats.RESTORE_WORKBENCH, "WorkbenchPage" + label); //$NON-NLS-1$ // MultiStatus result = // new MultiStatus(PlatformUI.PLUGIN_ID, IStatus.OK, NLS.bind( // WorkbenchMessages.WorkbenchPage_unableToRestorePerspective, // pageName), 0); bool result = true; // String workingSetName = memento .getString( // IWorkbenchConstants.TAG_WORKING_SET); // if (workingSetName != 0) // { // AbstractWorkingSetManager // workingSetManager = // (AbstractWorkingSetManager) getWorkbenchWindow() .getWorkbench().getWorkingSetManager(); // setWorkingSet(workingSetManager.getWorkingSet(workingSetName)); // } // // IMemento workingSetMem = memento .getChild( // IWorkbenchConstants.TAG_WORKING_SETS); // if (workingSetMem != 0) // { // std::vector workingSetChildren = // workingSetMem .getChildren(IWorkbenchConstants.TAG_WORKING_SET); // List workingSetList = new ArrayList(workingSetChildren.length); // for (int i = 0; i < workingSetChildren.length; i++) // { // IWorkingSet // set = // getWorkbenchWindow().getWorkbench() .getWorkingSetManager().getWorkingSet( // workingSetChildren[i].getID()); // if (set != 0) // { // workingSetList.add(set); // } // } // // workingSets = (IWorkingSet[]) workingSetList .toArray( // new IWorkingSet[workingSetList.size()]); // } // // aggregateWorkingSetId = memento.getString(ATT_AGGREGATE_WORKING_SET_ID); // // IWorkingSet setWithId = // window.getWorkbench().getWorkingSetManager().getWorkingSet( // aggregateWorkingSetId); // // // check to see if the set has already been made and assign it if it has // if (setWithId.Cast () != 0) // { // aggregateWorkingSet = (AggregateWorkingSet) setWithId; // } // Restore editor manager. IMemento::Pointer childMem = memento->GetChild( WorkbenchConstants::TAG_EDITORS); //result.merge(getEditorManager().restoreState(childMem)); result &= this->GetEditorManager()->RestoreState(childMem); childMem = memento->GetChild(WorkbenchConstants::TAG_VIEWS); if (childMem) { //result.merge(getViewFactory().restoreState(childMem)); result &= this->GetViewFactory()->RestoreState(childMem); } // Get persp block. childMem = memento->GetChild(WorkbenchConstants::TAG_PERSPECTIVES); std::string activePartID; childMem->GetString(WorkbenchConstants::TAG_ACTIVE_PART, activePartID); std::string activePartSecondaryID; if (!activePartID.empty()) { activePartSecondaryID = ViewFactory::ExtractSecondaryId(activePartID); if (!activePartSecondaryID.empty()) { activePartID = ViewFactory::ExtractPrimaryId(activePartID); } } std::string activePerspectiveID; childMem->GetString(WorkbenchConstants::TAG_ACTIVE_PERSPECTIVE, activePerspectiveID); // Restore perspectives. std::vector perspMems(childMem->GetChildren( WorkbenchConstants::TAG_PERSPECTIVE)); Perspective::Pointer activePerspective; for (std::size_t i = 0; i < perspMems.size(); i++) { IMemento::Pointer current = perspMems[i]; // StartupThreading // .runWithoutExceptions(new StartupRunnable() // { // // public void WorkbenchPage::runWithException() throws Throwable // { Perspective::Pointer persp(new Perspective( PerspectiveDescriptor::Pointer(0), WorkbenchPage::Pointer(this))); //result.merge(persp.restoreState(current)); result &= persp->RestoreState(current); IPerspectiveDescriptor::Pointer desc = persp->GetDesc(); if (desc == activeDescriptor) { activePerspective = persp; } else if ((activePerspective == 0) && desc->GetId() == activePerspectiveID) { activePerspective = persp; } perspList.Add(persp); window->FirePerspectiveOpened(WorkbenchPage::Pointer(this), desc); // } // }); } bool restoreActivePerspective = false; if (!activeDescriptor) { restoreActivePerspective = true; } else if (activePerspective && activePerspective->GetDesc() == activeDescriptor) { restoreActivePerspective = true; } else { restoreActivePerspective = false; activePerspective = this->CreatePerspective(activeDescriptor.Cast< PerspectiveDescriptor> (), true); if (activePerspective == 0) { // result .merge( // new Status(IStatus.ERR, PlatformUI.PLUGIN_ID, 0, NLS.bind( // WorkbenchMessages.Workbench_showPerspectiveError, // activeDescriptor.getId()), 0)); result &= false; } } perspList.SetActive(activePerspective); // Make sure we have a valid perspective to work with, // otherwise return. activePerspective = perspList.GetActive(); if (activePerspective == 0) { activePerspective = perspList.GetNextActive(); perspList.SetActive(activePerspective); } if (activePerspective && restoreActivePerspective) { //result.merge(activePerspective.restoreState()); result &= activePerspective->RestoreState(); } if (activePerspective) { Perspective::Pointer myPerspective = activePerspective; std::string myActivePartId = activePartID; std::string mySecondaryId = activePartSecondaryID; // StartupThreading.runWithoutExceptions(new StartupRunnable() // { // // public void WorkbenchPage::runWithException() throws Throwable // { window->FirePerspectiveActivated(WorkbenchPage::Pointer(this), myPerspective->GetDesc()); // Restore active part. if (!myActivePartId.empty()) { IWorkbenchPartReference::Pointer ref = myPerspective->FindView( myActivePartId, mySecondaryId); if (ref) { activationList->SetActive(ref); } } // }}); } // childMem = memento->GetChild(WorkbenchConstants::TAG_NAVIGATION_HISTORY); // if (childMem) // { // navigationHistory.restoreState(childMem); // } // else if (GetActiveEditor()) // { // navigationHistory.markEditor(getActiveEditor()); // } // // restore sticky view state stickyViewMan->Restore(memento); // std::string blame = activeDescriptor == 0 ? pageName // : activeDescriptor.getId(); // UIStats.end(UIStats.RESTORE_WORKBENCH, blame, "WorkbenchPage" + label); //$NON-NLS-1$ // StartupThreading.runWithoutExceptions(new StartupRunnable() // { // public void WorkbenchPage::runWithException() throws Throwable // { DeferUpdates(false); // } // }); return result; } catch (...) { // std::string blame = activeDescriptor == 0 ? pageName // : activeDescriptor.getId(); // UIStats.end(UIStats.RESTORE_WORKBENCH, blame, "WorkbenchPage" + label); //$NON-NLS-1$ throw ; } } catch (...) { // StartupThreading.runWithoutExceptions(new StartupRunnable() // { // public void WorkbenchPage::runWithException() throws Throwable // { DeferUpdates(false); // } // }); throw; } } bool WorkbenchPage::SaveAllEditors(bool confirm) { return this->SaveAllEditors(confirm, false); } bool WorkbenchPage::SaveAllEditors(bool confirm, bool addNonPartSources) { return this->GetEditorManager()->SaveAll(confirm, false, addNonPartSources); } bool WorkbenchPage::SavePart(ISaveablePart::Pointer saveable, IWorkbenchPart::Pointer part, bool confirm) { // Do not certify part do allow editors inside a multipageeditor to // call this. return this->GetEditorManager()->SavePart(saveable, part, confirm); } bool WorkbenchPage::SaveEditor(IEditorPart::Pointer editor, bool confirm) { return this->SavePart(editor, editor, confirm); } /** * Saves the current perspective. */ void WorkbenchPage::SavePerspective() { Perspective::Pointer persp = this->GetActivePerspective(); if (persp == 0) { return; } // // Always unzoom. // if (isZoomed()) // { // zoomOut(); // } persp->SaveDesc(); } /** * Saves the perspective. */ void WorkbenchPage::SavePerspectiveAs(IPerspectiveDescriptor::Pointer newDesc) { Perspective::Pointer persp = this->GetActivePerspective(); if (persp == 0) { return; } IPerspectiveDescriptor::Pointer oldDesc = persp->GetDesc(); // // Always unzoom. // if (isZoomed()) // { // zoomOut(); // } persp->SaveDescAs(newDesc); window->FirePerspectiveSavedAs(IWorkbenchPage::Pointer(this), oldDesc, newDesc); } /** * Save the state of the page. */ bool WorkbenchPage::SaveState(IMemento::Pointer memento) { // // We must unzoom to get correct layout. // if (isZoomed()) // { // zoomOut(); // } // MultiStatus // result = // new MultiStatus(PlatformUI.PLUGIN_ID, IStatus.OK, NLS.bind( // WorkbenchMessages.WorkbenchPage_unableToSavePerspective, // getLabel()), 0); bool result = true; // Save editor manager. IMemento::Pointer childMem = memento->CreateChild(WorkbenchConstants::TAG_EDITORS); //result.merge(editorMgr.saveState(childMem)); result &= editorMgr->SaveState(childMem); childMem = memento->CreateChild(WorkbenchConstants::TAG_VIEWS); //result.merge(getViewFactory().saveState(childMem)); result &= this->GetViewFactory()->SaveState(childMem); // Create persp block. childMem = memento->CreateChild(WorkbenchConstants::TAG_PERSPECTIVES); if (this->GetPerspective()) { childMem->PutString(WorkbenchConstants::TAG_ACTIVE_PERSPECTIVE, this->GetPerspective()->GetId()); } if (this->GetActivePart() != 0) { if (this->GetActivePart().Cast ()) { IViewReference::Pointer ref = this->GetReference(this->GetActivePart()).Cast(); if (ref) { childMem->PutString(WorkbenchConstants::TAG_ACTIVE_PART, ViewFactory::GetKey(ref)); } } else { childMem->PutString(WorkbenchConstants::TAG_ACTIVE_PART, this->GetActivePart()->GetSite()->GetId()); } } // Save each perspective in opened order for (PerspectiveList::PerspectiveListType::iterator itr = perspList.Begin(); itr != perspList.End(); ++itr) { IMemento::Pointer gChildMem = childMem->CreateChild( WorkbenchConstants::TAG_PERSPECTIVE); //result.merge(persp.saveState(gChildMem)); result &= (*itr)->SaveState(gChildMem); } // // Save working set if set // if (workingSet != 0) // { // memento.putString(IWorkbenchConstants.TAG_WORKING_SET, // workingSet .getName()); // } // // IMemento workingSetMem = memento .createChild( // IWorkbenchConstants.TAG_WORKING_SETS); // for (int i = 0; i < workingSets.length; i++) // { // workingSetMem.createChild(IWorkbenchConstants.TAG_WORKING_SET, // workingSets[i].getName()); // } // // if (aggregateWorkingSetId != 0) // { // memento.putString(ATT_AGGREGATE_WORKING_SET_ID, aggregateWorkingSetId); // } // // navigationHistory.saveState(memento .createChild( // IWorkbenchConstants.TAG_NAVIGATION_HISTORY)); // // save the sticky activation state stickyViewMan->Save(memento); return result; } std::string WorkbenchPage::GetId(IWorkbenchPart::Pointer part) { return this->GetId(this->GetReference(part)); } std::string WorkbenchPage::GetId(IWorkbenchPartReference::Pointer ref) { if (ref == 0) { return "0"; //$NON-NLS-1$ } return ref->GetId(); } void WorkbenchPage::SetActivePart(IWorkbenchPart::Pointer newPart) { // Optimize it. if (this->GetActivePart() == newPart) { return; } if (partBeingActivated != 0) { if (partBeingActivated->GetPart(false) != newPart) { WorkbenchPlugin::Log(Poco::RuntimeException( "WARNING: Prevented recursive attempt to activate part " + this->GetId(newPart) + " while still in the middle of activating part " + this->GetId( partBeingActivated))); } return; } //No need to change the history if the active editor is becoming the // active part // String label = 0; // debugging only // if (UIStats.isDebugging(UIStats.ACTIVATE_PART)) // { // label = newPart != 0 ? newPart.getTitle() : "none"; //$NON-NLS-1$ // } try { IWorkbenchPartReference::Pointer partref = this->GetReference(newPart); IWorkbenchPartReference::Pointer realPartRef; if (newPart != 0) { IWorkbenchPartSite::Pointer site = newPart->GetSite(); if (site.Cast () != 0) { realPartRef = site.Cast ()->GetPane()->GetPartReference(); } } partBeingActivated = realPartRef; //UIStats.start(UIStats.ACTIVATE_PART, label); // Notify perspective. It may deactivate fast view. Perspective::Pointer persp = this->GetActivePerspective(); if (persp != 0) { persp->PartActivated(newPart); } // Deactivate old part IWorkbenchPart::Pointer oldPart = this->GetActivePart(); if (oldPart != 0) { this->DeactivatePart(oldPart); } // Set active part. if (newPart != 0) { activationList->SetActive(newPart); if (newPart.Cast () != 0) { this->MakeActiveEditor(realPartRef.Cast ()); } } this->ActivatePart(newPart); actionSwitcher.UpdateActivePart(newPart); partList->SetActivePart(partref); } catch (std::exception& e) { partBeingActivated = 0; // Object blame = newPart == 0 ? (Object) this : newPart; // UIStats.end(UIStats.ACTIVATE_PART, blame, label); throw e; } partBeingActivated = 0; } void WorkbenchPage::SetEditorAreaVisible(bool showEditorArea) { Perspective::Pointer persp = this->GetActivePerspective(); if (persp == 0) { return; } if (showEditorArea == persp->IsEditorAreaVisible()) { return; } // // If parts change always update zoom. // if (isZoomed()) // { // zoomOut(); // } // Update editor area visibility. IWorkbenchPage::Pointer thisPage(this); if (showEditorArea) { persp->ShowEditorArea(); window->FirePerspectiveChanged(thisPage, this->GetPerspective(), CHANGE_EDITOR_AREA_SHOW); } else { persp->HideEditorArea(); this->UpdateActivePart(); window->FirePerspectiveChanged(thisPage, this->GetPerspective(), CHANGE_EDITOR_AREA_HIDE); } } /** * Sets the layout of the page. Assumes the new perspective is not 0. * Keeps the active part if possible. Updates the window menubar and * toolbar if necessary. */ void WorkbenchPage::SetPerspective(Perspective::Pointer newPersp) { // Don't do anything if already active layout Perspective::Pointer oldPersp = this->GetActivePerspective(); if (oldPersp == newPersp) { return; } window->LargeUpdateStart(); std::exception exc; bool exceptionOccured = false; try { IWorkbenchPage::Pointer thisPage(this); if (oldPersp != 0) { // fire the pre-deactivate window->FirePerspectivePreDeactivate(thisPage, oldPersp->GetDesc()); } if (newPersp != 0) { bool status = newPersp->RestoreState(); if (!status) { std::string title = "Restoring problems"; std::string msg = "Unable to read workbench state."; MessageDialog::OpenError(this->GetWorkbenchWindow()->GetShell(), title, msg); } } // Deactivate the old layout if (oldPersp != 0) { oldPersp->OnDeactivate(); // Notify listeners of deactivation window->FirePerspectiveDeactivated(thisPage, oldPersp->GetDesc()); } // Activate the new layout perspList.SetActive(newPersp); if (newPersp != 0) { newPersp->OnActivate(); // Notify listeners of activation window->FirePerspectiveActivated(thisPage, newPersp->GetDesc()); } this->UpdateVisibility(oldPersp, newPersp); // Update the window //TODO action sets //window->UpdateActionSets(); // Update sticky views stickyViewMan->Update(oldPersp, newPersp); } catch (std::exception& e) { exc = e; exceptionOccured = true; } window->LargeUpdateEnd(); if (newPersp == 0) { return; } IPerspectiveDescriptor::Pointer desc = newPersp->GetDesc(); if (desc == 0) { return; } if (dirtyPerspectives.erase(desc->GetId())) { this->SuggestReset(); } if (exceptionOccured) throw exc; } void WorkbenchPage::UpdateVisibility(Perspective::Pointer oldPersp, Perspective::Pointer newPersp) { // Flag all parts in the old perspective std::vector oldRefs; if (oldPersp != 0) { oldRefs = oldPersp->GetViewReferences(); for (unsigned int i = 0; i < oldRefs.size(); i++) { PartPane::Pointer pane = oldRefs[i].Cast ()->GetPane(); pane->SetInLayout(false); } } PerspectiveHelper* pres = 0; // Make parts in the new perspective visible if (newPersp != 0) { pres = newPersp->GetPresentation(); std::vector newRefs = newPersp->GetViewReferences(); for (unsigned int i = 0; i < newRefs.size(); i++) { WorkbenchPartReference::Pointer ref = newRefs[i].Cast< WorkbenchPartReference> (); PartPane::Pointer pane = ref->GetPane(); if (pres->IsPartVisible(ref)) { activationList->BringToTop(ref); } pane->SetInLayout(true); } } this->UpdateActivePart(); // Hide any parts in the old perspective that are no longer visible for (unsigned int i = 0; i < oldRefs.size(); i++) { WorkbenchPartReference::Pointer ref = oldRefs[i].Cast< WorkbenchPartReference> (); PartPane::Pointer pane = ref->GetPane(); if (pres == 0 || !pres->IsPartVisible(ref)) { pane->SetVisible(false); } } } /** * Sets the perspective. * * @param desc * identifies the new perspective. */ void WorkbenchPage::SetPerspective(IPerspectiveDescriptor::Pointer desc) { if (this->GetPerspective() == desc) { return; } // // Going from multiple to single rows can make the coolbar // // and its adjacent views appear jumpy as perspectives are // // switched. Turn off redraw to help with this. // ICoolBarManager2 mgr = (ICoolBarManager2) window.getCoolBarManager2(); std::exception exc; bool exceptionOccured = false; try { //mgr.getControl2().setRedraw(false); //getClientComposite().setRedraw(false); // Run op in busy cursor. // BusyIndicator.showWhile(0, new Runnable() // { // public void WorkbenchPage::run() // { this->BusySetPerspective(desc); // } // }); } catch (std::exception& e) { exc = e; exceptionOccured = true; } // getClientComposite().setRedraw(true); // mgr.getControl2().setRedraw(true); IWorkbenchPart::Pointer part = this->GetActivePart(); if (part != 0) { part->SetFocus(); } if (exceptionOccured) throw exc; } PartService* WorkbenchPage::GetPartService() { return dynamic_cast (partList->GetPartService()); } void WorkbenchPage::ResetToolBarLayout() { // ICoolBarManager2 mgr = (ICoolBarManager2) window.getCoolBarManager2(); // mgr.resetItemOrder(); } IViewPart::Pointer WorkbenchPage::ShowView(const std::string& viewID) { return this->ShowView(viewID, "", VIEW_ACTIVATE); } IViewPart::Pointer WorkbenchPage::ShowView(const std::string& viewID, const std::string& secondaryID, int mode) { if (secondaryID != "") { if (secondaryID.size() == 0 || secondaryID.find_first_of( ViewFactory::ID_SEP) != std::string::npos) { throw Poco::InvalidArgumentException( "Illegal secondary id (cannot be empty or contain a colon)"); } } if (!this->CertifyMode(mode)) { throw Poco::InvalidArgumentException("Illegal view mode"); } // Run op in busy cursor. // BusyIndicator.showWhile(0, new Runnable() // { // public void WorkbenchPage::run() // { // try // { return this->BusyShowView(viewID, secondaryID, mode); // } catch (PartInitException& e) // { // result = e; // } // } // }); } bool WorkbenchPage::CertifyMode(int mode) { if (mode == VIEW_ACTIVATE || mode == VIEW_VISIBLE || mode == VIEW_CREATE) return true; return false; } std::vector WorkbenchPage::GetSortedEditors() { return activationList->GetEditors(); } std::vector WorkbenchPage::GetOpenPerspectives() { std::list opened = perspList.GetOpenedPerspectives(); std::vector result; for (std::list::iterator iter = opened.begin(); iter != opened.end(); ++iter) { result.push_back((*iter)->GetDesc()); } return result; } std::list WorkbenchPage::GetOpenInternalPerspectives() { return perspList.GetOpenedPerspectives(); } Perspective::Pointer WorkbenchPage::GetFirstPerspectiveWithView( IViewPart::Pointer part) { std::list perspectives = perspList.GetSortedPerspectives(); for (std::list::reverse_iterator iter = perspectives.rbegin(); iter != perspectives.rend(); ++iter) { if ((*iter)->ContainsView(part)) { return *iter; } } // we should never get here return Perspective::Pointer(0); } std::vector WorkbenchPage::GetSortedPerspectives() { std::list sortedArray = perspList.GetSortedPerspectives(); std::vector result; for (std::list::iterator iter = sortedArray.begin(); iter != sortedArray.end(); ++iter) { result.push_back((*iter)->GetDesc()); } return result; } std::vector WorkbenchPage::GetSortedParts() { //return partList->GetParts(this->GetViewReferences()); return activationList->GetParts(); } IWorkbenchPartReference::Pointer WorkbenchPage::GetReference( IWorkbenchPart::Pointer part) { if (part == 0) { return IWorkbenchPartReference::Pointer(0); } IWorkbenchPartSite::Pointer site = part->GetSite(); if (site.Cast () == 0) { return IWorkbenchPartReference::Pointer(0); } PartSite::Pointer partSite = site.Cast (); PartPane::Pointer pane = partSite->GetPane(); return partSite->GetPartReference(); } // for dynamic UI void WorkbenchPage::AddPerspective(Perspective::Pointer persp) { perspList.Add(persp); IWorkbenchPage::Pointer thisPage(this); window->FirePerspectiveOpened(thisPage, persp->GetDesc()); } std::vector WorkbenchPage::GetViewReferenceStack( IViewPart::Pointer part) { // Sanity check. Perspective::Pointer persp = this->GetActivePerspective(); if (persp == 0 || !this->CertifyPart(part)) { return std::vector(); } - IStackableContainer::Pointer container = + ILayoutContainer::Pointer container = part->GetSite().Cast ()->GetPane()->GetContainer(); if (container.Cast () != 0) { PartStack::Pointer folder = container.Cast (); std::vector list; - IStackableContainer::ChildrenType children = folder->GetChildren(); - for (IStackableContainer::ChildrenType::iterator childIter = + ILayoutContainer::ChildrenType children = folder->GetChildren(); + for (ILayoutContainer::ChildrenType::iterator childIter = children.begin(); childIter != children.end(); ++childIter) { - StackablePart::Pointer stackablePart = *childIter; + LayoutPart::Pointer stackablePart = *childIter; if (stackablePart.Cast () != 0) { IViewReference::Pointer view = stackablePart.Cast ()->GetPartReference().Cast< IViewReference> (); if (view != 0) { list.push_back(view); } } } // sort the list by activation order (most recently activated first) std::sort(list.begin(), list.end(), ActivationOrderPred(activationList)); return list; } std::vector result; result.push_back(this->GetReference(part).Cast ()); return result; } std::vector WorkbenchPage::GetViewStack( IViewPart::Pointer part) { std::vector refStack = this->GetViewReferenceStack( part); std::vector result; for (unsigned int i = 0; i < refStack.size(); i++) { IViewPart::Pointer next = refStack[i]->GetView(false); if (next != 0) { result.push_back(next); } } return result; } void WorkbenchPage::ResizeView(IViewPart::Pointer part, int width, int height) { SashInfo sashInfo; PartPane::Pointer pane = part->GetSite().Cast ()->GetPane(); - IStackableContainer::Pointer container = pane->GetContainer(); + ILayoutContainer::Pointer container = pane->GetContainer(); LayoutTree::Pointer tree = this->GetPerspectivePresentation()->GetLayout()->GetLayoutTree()->Find( container.Cast ()); // retrieve our layout sashes from the layout tree this->FindSashParts(tree, pane->FindSashes(), sashInfo); // first set the width int deltaWidth = width - pane->GetBounds().width; if (sashInfo.right != 0) { Rectangle rightBounds = sashInfo.rightNode->GetBounds(); // set the new ratio sashInfo.right->SetRatio(static_cast((deltaWidth + sashInfo.right->GetBounds().x) - rightBounds.x) / rightBounds.width); // complete the resize sashInfo.rightNode->SetBounds(rightBounds); } else if (sashInfo.left != 0) { Rectangle leftBounds = sashInfo.leftNode->GetBounds(); // set the ratio sashInfo.left->SetRatio(static_cast((sashInfo.left->GetBounds().x - deltaWidth) - leftBounds.x) / leftBounds.width); // complete the resize sashInfo.leftNode->SetBounds(sashInfo.leftNode->GetBounds()); } // next set the height int deltaHeight = height - pane->GetBounds().height; if (sashInfo.bottom != 0) { Rectangle bottomBounds = sashInfo.bottomNode->GetBounds(); // set the new ratio sashInfo.bottom->SetRatio(static_cast((deltaHeight + sashInfo.bottom->GetBounds().y) - bottomBounds.y) / bottomBounds.height); // complete the resize sashInfo.bottomNode->SetBounds(bottomBounds); } else if (sashInfo.top != 0) { Rectangle topBounds = sashInfo.topNode->GetBounds(); // set the ratio sashInfo.top->SetRatio(static_cast((sashInfo.top->GetBounds().y - deltaHeight) - topBounds.y) / topBounds.height); // complete the resize sashInfo.topNode->SetBounds(topBounds); } } void WorkbenchPage::FindSashParts(LayoutTree::Pointer tree, const PartPane::Sashes& sashes, SashInfo& info) { LayoutTree::Pointer parent(tree->GetParent()); if (parent == 0) { return; } if (parent->part.Cast () != 0) { // get the layout part sash from this tree node LayoutPartSash::Pointer sash = parent->part.Cast (); // make sure it has a sash control void* control = sash->GetControl(); if (control != 0) { // check for a vertical sash if (sash->IsVertical()) { if (sashes.left == control) { info.left = sash; info.leftNode = parent->FindSash(sash); } else if (sashes.right == control) { info.right = sash; info.rightNode = parent->FindSash(sash); } } // check for a horizontal sash else { if (sashes.top == control) { info.top = sash; info.topNode = parent->FindSash(sash); } else if (sashes.bottom == control) { info.bottom = sash; info.bottomNode = parent->FindSash(sash); } } } } // recursive call to continue up the tree this->FindSashParts(parent, sashes, info); } std::vector WorkbenchPage::GetAllParts() { std::vector views = viewFactory->GetViews(); std::list editors = this->GetEditorReferences(); std::vector result; for (unsigned int i = 0; i < views.size(); i++) { result.push_back(views[i]); } for (std::list::iterator iter = editors.begin(); iter != editors.end(); ++iter) { result.push_back(*iter); } return result; } std::vector WorkbenchPage::GetOpenParts() { std::vector refs = this->GetAllParts(); std::vector result; for (unsigned int i = 0; i < refs.size(); i++) { IWorkbenchPartReference::Pointer reference = refs[i]; IWorkbenchPart::Pointer part = reference->GetPart(false); if (part != 0) { result.push_back(reference); } } return result; } void WorkbenchPage::TestInvariants() { Perspective::Pointer persp = this->GetActivePerspective(); if (persp != 0) { persp->TestInvariants(); // When we have widgets, ensure that there is no situation where the editor area is visible // and the perspective doesn't want an editor area. if (this->GetClientComposite() && editorPresentation->GetLayoutPart()->IsVisible()) { poco_assert(persp->IsEditorAreaVisible()); } } } /* (non-Javadoc) * @see org.blueberry.ui.IWorkbenchPage#getExtensionTracker() */ // IExtensionTracker WorkbenchPage::GetExtensionTracker() // { // if (tracker == 0) // { // tracker = new UIExtensionTracker(getWorkbenchWindow().getWorkbench().getDisplay()); // } // return tracker; // } /* * (non-Javadoc) * * @see org.blueberry.ui.IWorkbenchPage#getPerspectiveShortcuts() */ std::vector WorkbenchPage::GetPerspectiveShortcuts() { Perspective::Pointer persp = this->GetActivePerspective(); if (persp == 0) { return std::vector(); } return persp->GetPerspectiveShortcuts(); } std::vector WorkbenchPage::GetShowViewShortcuts() { Perspective::Pointer persp = this->GetActivePerspective(); if (persp == 0) { return std::vector(); } return persp->GetShowViewShortcuts(); } void WorkbenchPage::SuggestReset() { IWorkbench* workbench = this->GetWorkbenchWindow()->GetWorkbench(); // workbench.getDisplay().asyncExec(new Runnable() // { // public void WorkbenchPage::run() // { Shell::Pointer parentShell; IWorkbenchWindow::Pointer window = workbench->GetActiveWorkbenchWindow(); if (window == 0) { if (workbench->GetWorkbenchWindowCount() == 0) { return; } window = workbench->GetWorkbenchWindows()[0]; } parentShell = window->GetShell(); if (MessageDialog::OpenQuestion(parentShell, "Reset Perspective?", "Changes to installed plug-ins have affected this perspective. Would you like to reset this perspective to accept these changes?")) { IWorkbenchPage::Pointer page = window->GetActivePage(); if (page == 0) { return; } page->ResetPerspective(); } // } // }); } bool WorkbenchPage::IsPartVisible( IWorkbenchPartReference::Pointer reference) { IWorkbenchPart::Pointer part = reference->GetPart(false); // Can't be visible if it isn't created yet if (part == 0) { return false; } return this->IsPartVisible(part); } } diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryWorkbenchPage.h b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryWorkbenchPage.h index d8c948d082..54ed3da144 100644 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryWorkbenchPage.h +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryWorkbenchPage.h @@ -1,1786 +1,1786 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef BERRYWORKBENCHPAGE_H_ #define BERRYWORKBENCHPAGE_H_ #include #include #include "berryIWorkbenchPage.h" #include "berryIWorkbenchPartReference.h" #include "berryIReusableEditor.h" -#include "berryIStackableContainer.h" +#include "berryILayoutContainer.h" #include "berryIStickyViewManager.h" #include "berryWorkbenchPagePartList.h" #include "berryWorkbenchPartReference.h" #include "berryPageSelectionService.h" #include "berryEditorManager.h" #include "berryViewFactory.h" #include "berryPartPane.h" #include namespace berry { //class PartPane; //class PartPane::Sashes; class EditorAreaHelper; class WorkbenchWindow; class Perspective; class PerspectiveHelper; class PerspectiveDescriptor; class LayoutPartSash; class LayoutTree; class LayoutTreeNode; class PartService; /** * \ingroup org_blueberry_ui_internal * * A collection of views and editors in a workbench. */ class BERRY_UI WorkbenchPage: public IWorkbenchPage { public: berryObjectMacro(WorkbenchPage) ; protected: //TODO Weakpointer WorkbenchWindow* window; friend class ViewFactory; friend class WorkbenchWindow; friend class EditorAreaHelper; friend class WWinPartService; private: /** * Manages editor contributions and action set part associations. */ class ActionSwitcher { private: IWorkbenchPart::WeakPtr activePart; IEditorPart::WeakPtr topEditor; /** * Updates the contributions given the new part as the active part. * * @param newPart * the new active part, may be null */ public: void UpdateActivePart(IWorkbenchPart::Pointer newPart); /** * Updates the contributions given the new part as the topEditor. * * @param newEditor * the new top editor, may be null */ public: void UpdateTopEditor(IEditorPart::Pointer newEditor); /** * Activates the contributions of the given part. If enable * is true the contributions are visible and enabled, * otherwise they are disabled. * * @param part * the part whose contributions are to be activated * @param enable * true the contributions are to be enabled, * not just visible. */ private: void ActivateContributions(IWorkbenchPart::Pointer part, bool enable); /** * Deactivates the contributions of the given part. If remove * is true the contributions are removed, otherwise they * are disabled. * * @param part * the part whose contributions are to be deactivated * @param remove * true the contributions are to be removed, * not just disabled. */ private: void DeactivateContributions(IWorkbenchPart::Pointer part, bool remove); }; class ActivationList { public: //List of parts in the activation order (oldest first) typedef std::deque PartListType; typedef std::deque::iterator PartListIter; typedef std::deque::reverse_iterator PartListReverseIter; private: PartListType parts; WorkbenchPage* page; public: ActivationList(WorkbenchPage* page); /* * Add/Move the active part to end of the list; */ void SetActive(SmartPointer part); /* * Ensures that the given part appears AFTER any other part in the same * container. */ void BringToTop(SmartPointer ref); /* * Returns the last (most recent) iterator (index) of the given container in the activation list, or returns * end() if the given container does not appear in the activation list. */ - PartListIter LastIndexOfContainer(SmartPointer container); + PartListIter LastIndexOfContainer(SmartPointer container); /* * Add/Move the active part to end of the list; */ void SetActive(SmartPointer ref); /* * Add the active part to the beginning of the list. */ void Add(SmartPointer ref); /* * Return the active part. Filter fast views. */ SmartPointer GetActive(); /* * Return the previously active part. Filter fast views. */ SmartPointer GetPreviouslyActive(); SmartPointer GetActiveReference(bool editorsOnly); /* * Retuns the index of the part within the activation list. The higher * the index, the more recently it was used. */ PartListIter IndexOf(SmartPointer part); /* * Returns the index of the part reference within the activation list. * The higher the index, the more recent it was used. */ PartListIter IndexOf(SmartPointer ref); /* * Remove a part from the list */ bool Remove(SmartPointer ref); /* * Returns the topmost editor on the stack, or null if none. */ SmartPointer GetTopEditor(); /* * Returns the editors in activation order (oldest first). */ std::vector > GetEditors(); /* * Return a list with all parts (editors and views). */ std::vector > GetParts(); private: SmartPointer GetActive(PartListIter start); SmartPointer GetActiveReference(PartListIter start, bool editorsOnly); /* * Find a part in the list starting from the end and filter * and views from other perspectives. Will filter fast views * unless 'includeActiveFastViews' is true; */ SmartPointer GetActiveReference(PartListIter start, bool editorsOnly, bool skipPartsObscuredByZoom); }; /** * Helper class to keep track of all opened perspective. Both the opened * and used order is kept. */ struct PerspectiveList { public: typedef std::list > PerspectiveListType; typedef PerspectiveListType::iterator iterator; private: /** * List of perspectives in the order they were opened; */ PerspectiveListType openedList; /** * List of perspectives in the order they were used. Last element is * the most recently used, and first element is the least recently * used. */ PerspectiveListType usedList; /** * The perspective explicitly set as being the active one */ SmartPointer active; void UpdateActionSets(SmartPointer oldPersp, SmartPointer newPersp); public: /** * Creates an empty instance of the perspective list */ PerspectiveList(); /** * Update the order of the perspectives in the opened list * * @param perspective * @param newLoc */ void Reorder(IPerspectiveDescriptor::Pointer perspective, int newLoc); /** * Return all perspectives in the order they were activated. * * @return an array of perspectives sorted by activation order, least * recently activated perspective last. */ PerspectiveListType GetSortedPerspectives(); /** * Adds a perspective to the list. No check is done for a duplicate when * adding. * @param perspective the perspective to add * @return boolean true if the perspective was added */ bool Add(SmartPointer perspective); /** * Returns an iterator on the perspective list in the order they were * opened. */ PerspectiveListType::iterator Begin(); PerspectiveListType::iterator End(); /** * Returns an array with all opened perspectives */ PerspectiveListType GetOpenedPerspectives(); /** * Removes a perspective from the list. */ bool Remove(SmartPointer perspective); /** * Swap the opened order of old perspective with the new perspective. */ void Swap(SmartPointer oldPerspective, SmartPointer newPerspective); /** * Returns whether the list contains any perspectives */ bool IsEmpty(); /** * Returns the most recently used perspective in the list. */ SmartPointer GetActive(); /** * Returns the next most recently used perspective in the list. */ SmartPointer GetNextActive(); /** * Returns the number of perspectives opened */ PerspectiveListType::size_type Size(); /** * Marks the specified perspective as the most recently used one in the * list. */ void SetActive(SmartPointer perspective); }; IAdaptable* input; void* composite; //Could be delete. This information is in the active part list; ActivationList* activationList; EditorManager* editorMgr; EditorAreaHelper* editorPresentation; //ListenerList propertyChangeListeners = new ListenerList(); PageSelectionService* selectionService; WorkbenchPagePartList::Pointer partList; // = new WorkbenchPagePartList(selectionService); //IActionBars actionBars; ViewFactory* viewFactory; PerspectiveList perspList; SmartPointer deferredActivePersp; //NavigationHistory navigationHistory = new NavigationHistory(this); IStickyViewManager::Pointer stickyViewMan; /** * If we're in the process of activating a part, this points to the new part. * Otherwise, this is null. */ IWorkbenchPartReference::Pointer partBeingActivated; /** * Contains a list of perspectives that may be dirty due to plugin * installation and removal. */ std::set dirtyPerspectives; ActionSwitcher actionSwitcher; //IExtensionTracker tracker; // Deferral count... delays disposing parts and sending certain events if nonzero int deferCount; // Parts waiting to be disposed std::vector pendingDisposals; const IExtensionPoint* GetPerspectiveExtensionPoint(); public: /** * Constructs a new page with a given perspective and input. * * @param w * the parent window * @param layoutID * must not be null * @param input * the page input * @throws WorkbenchException * on null layout id */ WorkbenchPage(WorkbenchWindow* w, const std::string& layoutID, IAdaptable* input); /** * Constructs a page. restoreState(IMemento) should be * called to restore this page from data stored in a persistance file. * * @param w * the parent window * @param input * the page input * @throws WorkbenchException */ WorkbenchPage(WorkbenchWindow* w, IAdaptable* input); ~WorkbenchPage(); /** * Activates a part. The part will be brought to the front and given focus. * * @param part * the part to activate */ void Activate(IWorkbenchPart::Pointer part); /** * Activates a part. The part is given focus, the pane is hilighted. */ private: void ActivatePart(const IWorkbenchPart::Pointer part); /** * Adds an IPartListener to the part service. */ public: void AddPartListener(IPartListener::Pointer l); /* * (non-Javadoc) Method declared on ISelectionListener. */ public: void AddSelectionListener(ISelectionListener::Pointer listener); /* * (non-Javadoc) Method declared on ISelectionListener. */ public: void AddSelectionListener(const std::string& partId, ISelectionListener::Pointer listener); /* * (non-Javadoc) Method declared on ISelectionListener. */ public: void AddPostSelectionListener(ISelectionListener::Pointer listener); /* * (non-Javadoc) Method declared on ISelectionListener. */ public: void AddPostSelectionListener(const std::string& partId, ISelectionListener::Pointer listener); private: - IStackableContainer::Pointer GetContainer(IWorkbenchPart::Pointer part); + ILayoutContainer::Pointer GetContainer(IWorkbenchPart::Pointer part); private: - IStackableContainer::Pointer GetContainer(IWorkbenchPartReference::Pointer part); + ILayoutContainer::Pointer GetContainer(IWorkbenchPartReference::Pointer part); private: SmartPointer GetPane(IWorkbenchPart::Pointer part); private: SmartPointer GetPane(IWorkbenchPartReference::Pointer part); /** * Brings a part to the front of its stack. Does not update the active part or * active editor. This should only be called if the caller knows that the part * is not in the same stack as the active part or active editor, or if the caller * is prepared to update activation after the call. * * @param part */ private: bool InternalBringToTop(IWorkbenchPartReference::Pointer part); /** * Moves a part forward in the Z order of a perspective so it is visible. * If the part is in the same stack as the active part, the new part is * activated. * * @param part * the part to bring to move forward */ public: void BringToTop(IWorkbenchPart::Pointer part); /** * Resets the layout for the perspective. The active part in the old layout * is activated in the new layout for consistent user context. * * Assumes the busy cursor is active. */ private: void BusyResetPerspective(); /** * Implements setPerspective. * * Assumes that busy cursor is active. * * @param desc * identifies the new perspective. */ private: void BusySetPerspective(IPerspectiveDescriptor::Pointer desc); /** * Shows a view. * * Assumes that a busy cursor is active. */ protected: IViewPart::Pointer BusyShowView(const std::string& viewID, const std::string& secondaryID, int mode); /* * Performs showing of the view in the given mode. */ private: void BusyShowView(IViewPart::Pointer part, int mode); /** * Returns whether a part exists in the current page. */ private: bool CertifyPart(IWorkbenchPart::Pointer part); /** * Closes the perspective. */ public: bool Close(); /** * See IWorkbenchPage */ public: bool CloseAllSavedEditors(); /** * See IWorkbenchPage */ public: bool CloseAllEditors(bool save); private: void UpdateActivePart(); /** * Makes the given part active. Brings it in front if necessary. Permits null * (indicating that no part should be active). * * @since 3.1 * * @param ref new active part (or null) */ private: void MakeActive(IWorkbenchPartReference::Pointer ref); /** * Makes the given editor active. Brings it to front if necessary. Permits null * (indicating that no editor is active). * * @since 3.1 * * @param ref the editor to make active, or null for no active editor */ private: void MakeActiveEditor(IEditorReference::Pointer ref); /** * See IWorkbenchPage */ public: bool CloseEditors(const std::list& refArray, bool save); /** * Enables or disables listener notifications. This is used to delay listener notifications until the * end of a public method. * * @param shouldDefer */ private: void DeferUpdates(bool shouldDefer); private: void StartDeferring(); private: void HandleDeferredEvents(); private: bool IsDeferred(); /** * See IWorkbenchPage#closeEditor */ public: bool CloseEditor(IEditorReference::Pointer editorRef, bool save); /** * See IWorkbenchPage#closeEditor */ public: bool CloseEditor(IEditorPart::Pointer editor, bool save); /** * @see IWorkbenchPage#closePerspective(IPerspectiveDescriptor, boolean, boolean) */ public: void ClosePerspective(IPerspectiveDescriptor::Pointer desc, bool saveParts, bool closePage); /** * Closes the specified perspective. If last perspective, then entire page * is closed. * * @param persp * the perspective to be closed * @param saveParts * whether the parts that are being closed should be saved * (editors if last perspective, views if not shown in other * parspectives) */ /* package */ protected: void ClosePerspective(SmartPointer persp, bool saveParts, bool closePage); /** * @see IWorkbenchPage#closeAllPerspectives(boolean, boolean) */ public: void CloseAllPerspectives(bool saveEditors, bool closePage); /** * Creates the client composite. */ private: void CreateClientComposite(); /** * Creates a new view set. Return null on failure. * * @param desc the perspective descriptor * @param notify whether to fire a perspective opened event */ private: SmartPointer CreatePerspective(SmartPointer desc, bool notify); /** * This is called by child objects after a part has been added to the page. * The page will in turn notify its listeners. */ /* package */ protected: void PartAdded(WorkbenchPartReference::Pointer ref); /** * This is called by child objects after a part has been added to the page. * The part will be queued for disposal after all listeners have been notified */ /* package */ protected: void PartRemoved(WorkbenchPartReference::Pointer ref); private: void DisposePart(WorkbenchPartReference::Pointer ref); /** * Deactivates a part. The pane is unhilighted. */ private: void DeactivatePart(IWorkbenchPart::Pointer part); /** * Detaches a view from the WorkbenchWindow. */ public: void DetachView(IViewReference::Pointer ref); /** * Removes a detachedwindow. */ public: void AttachView(IViewReference::Pointer ref); /** * Dispose a perspective. * * @param persp the perspective descriptor * @param notify whether to fire a perspective closed event */ private: void DisposePerspective(SmartPointer persp, bool notify); /** * Returns the first view manager with given ID. */ public: SmartPointer FindPerspective(IPerspectiveDescriptor::Pointer desc); /** * See IWorkbenchPage@findView. */ public: IViewPart::Pointer FindView(const std::string& id); /* * (non-Javadoc) * * @see org.blueberry.ui.IWorkbenchPage */ public: IViewReference::Pointer FindViewReference(const std::string& viewId); /* * (non-Javadoc) * * @see org.blueberry.ui.IWorkbenchPage */ public: IViewReference::Pointer FindViewReference(const std::string& viewId, const std::string& secondaryId); /** * Notify property change listeners about a property change. * * @param changeId * the change id * @param oldValue * old property value * @param newValue * new property value */ //private: void FirePropertyChange(String changeId, Object oldValue, // Object newValue) { // // UIListenerLogging.logPagePropertyChanged(this, changeId, oldValue, newValue); // // Object[] listeners = propertyChangeListeners.getListeners(); // PropertyChangeEvent event = new PropertyChangeEvent(this, changeId, // oldValue, newValue); // // for (int i = 0; i < listeners.length; i++) { // ((IPropertyChangeListener) listeners[i]).propertyChange(event); // } // } /** * @see IWorkbenchPage */ public: IEditorPart::Pointer GetActiveEditor(); /** * Returns the reference for the active editor, or null * if there is no active editor. * * @return the active editor reference or null */ public: IEditorReference::Pointer GetActiveEditorReference(); /* * (non-Javadoc) Method declared on IPartService */ public: IWorkbenchPart::Pointer GetActivePart(); /* * (non-Javadoc) Method declared on IPartService */ public: IWorkbenchPartReference::Pointer GetActivePartReference(); /** * Returns the active perspective for the page, null if * none. */ public: SmartPointer GetActivePerspective(); /** * Returns the client composite. */ public: void* GetClientComposite(); // for dynamic UI - change access from private to protected // for testing purposes only, changed from protected to public /** * Answer the editor manager for this window. */ public: EditorManager* GetEditorManager(); /** * Answer the perspective presentation. */ public: PerspectiveHelper* GetPerspectivePresentation(); /** * Answer the editor presentation. */ public: EditorAreaHelper* GetEditorPresentation(); /** * Allow access to the part service for this page ... used internally to * propogate certain types of events to the page part listeners. * @return the part service for this page. */ public: PartService* GetPartService(); /** * See IWorkbenchPage. */ public: std::vector GetEditors(); public: std::vector GetDirtyEditors(); public: std::vector GetDirtyParts(); /** * See IWorkbenchPage. */ public: IEditorPart::Pointer FindEditor(IEditorInput::Pointer input); /** * See IWorkbenchPage. */ public: std::vector FindEditors( IEditorInput::Pointer input, const std::string& editorId, int matchFlags); /** * See IWorkbenchPage. */ public: std::list GetEditorReferences(); /** * @see IWorkbenchPage */ public: IAdaptable* GetInput(); /** * Returns the page label. This is a combination of the page input and * active perspective. */ public: std::string GetLabel(); /** * Returns the perspective. */ public: IPerspectiveDescriptor::Pointer GetPerspective(); /* * (non-Javadoc) Method declared on ISelectionService */ public: ISelection::ConstPointer GetSelection() const; /* * (non-Javadoc) Method declared on ISelectionService */ public: ISelection::ConstPointer GetSelection(const std::string& partId); //public: // SelectionEvents& GetSelectionEvents(const std::string& partId = ""); /* * Returns the view factory. */ public: ViewFactory* GetViewFactory(); /** * See IWorkbenchPage. */ public: std::vector GetViewReferences(); /** * See IWorkbenchPage. */ public: std::vector GetViews(); /** * Returns all view parts in the specified perspective * * @param persp the perspective * @return an array of view parts * @since 3.1 */ /*package*/ protected: std::vector GetViews(SmartPointer persp, bool restore); /** * See IWorkbenchPage. */ public: IWorkbenchWindow::Pointer GetWorkbenchWindow(); /* * (non-Javadoc) * * @see org.blueberry.ui.IWorkbenchPage#hideView(org.blueberry.ui.IViewReference) */ public: void HideView(IViewReference::Pointer ref); /* package */ protected: void RefreshActiveView(); /** * See IPerspective */ public: void HideView(IViewPart::Pointer view); /** * Initialize the page. * * @param w * the parent window * @param layoutID * may be null if restoring from file * @param input * the page input * @param openExtras * whether to process the perspective extras preference */ private: void Init(WorkbenchWindow* w, const std::string& layoutID, IAdaptable* input, bool openExtras); /** * Opens the perspectives specified in the PERSPECTIVE_BAR_EXTRAS preference (see bug 84226). */ public: void OpenPerspectiveExtras(); /** * See IWorkbenchPage. */ public: bool IsPartVisible(IWorkbenchPart::Pointer part); /** * See IWorkbenchPage. */ public: bool IsEditorAreaVisible(); /** * Returns whether the view is fast. */ public: bool IsFastView(IViewReference::Pointer ref); /** * Return whether the view is closeable or not. * * @param ref the view reference to check. Must not be null. * @return true if the part is closeable. * @since 3.1.1 */ public: bool IsCloseable(IViewReference::Pointer ref); /** * Return whether the view is moveable or not. * * @param ref the view reference to check. Must not be null. * @return true if the part is moveable. * @since 3.1.1 */ public: bool IsMoveable(IViewReference::Pointer ref); /** * Returns whether the layout of the active * perspective is fixed. */ public: bool IsFixedLayout(); /** * Return true if the perspective has a dirty editor. */ protected: bool IsSaveNeeded(); /** * This method is called when the page is activated. */ protected: void OnActivate(); /** * This method is called when the page is deactivated. */ protected: void OnDeactivate(); /** * See IWorkbenchPage. */ public: void ReuseEditor(IReusableEditor::Pointer editor, IEditorInput::Pointer input); /** * See IWorkbenchPage. */ public: IEditorPart::Pointer OpenEditor(IEditorInput::Pointer input, const std::string& editorID); /** * See IWorkbenchPage. */ public: IEditorPart::Pointer OpenEditor(IEditorInput::Pointer input, const std::string& editorID, bool activate); /** * See IWorkbenchPage. */ public: IEditorPart::Pointer OpenEditor(IEditorInput::Pointer input, const std::string& editorID, bool activate, int matchFlags); /** * This is not public API but for use internally. editorState can be null. */ public: IEditorPart::Pointer OpenEditor(IEditorInput::Pointer input, const std::string& editorID, bool activate, int matchFlags, IMemento::Pointer editorState); /* * Added to fix Bug 178235 [EditorMgmt] DBCS 3.3 - Cannot open file with external program. * Opens a new editor using the given input and descriptor. (Normally, editors are opened using * an editor ID and an input.) */ public: IEditorPart::Pointer OpenEditorFromDescriptor(IEditorInput::Pointer input, IEditorDescriptor::Pointer editorDescriptor, bool activate, IMemento::Pointer editorState); /** * @see #openEditor(IEditorInput, String, boolean, int) */ private: IEditorPart::Pointer BusyOpenEditor(IEditorInput::Pointer input, const std::string& editorID, bool activate, int matchFlags, IMemento::Pointer editorState); /* * Added to fix Bug 178235 [EditorMgmt] DBCS 3.3 - Cannot open file with external program. * See openEditorFromDescriptor(). */ private: IEditorPart::Pointer BusyOpenEditorFromDescriptor( IEditorInput::Pointer input, EditorDescriptor::Pointer editorDescriptor, bool activate, IMemento::Pointer editorState); /** * Do not call this method. Use busyOpenEditor. * * @see IWorkbenchPage#openEditor(IEditorInput, String, boolean) */ protected: IEditorPart::Pointer BusyOpenEditorBatched(IEditorInput::Pointer input, const std::string& editorID, bool activate, int matchFlags, IMemento::Pointer editorState); /* * Added to fix Bug 178235 [EditorMgmt] DBCS 3.3 - Cannot open file with external program. * See openEditorFromDescriptor(). */ private: IEditorPart::Pointer BusyOpenEditorFromDescriptorBatched( IEditorInput::Pointer input, EditorDescriptor::Pointer editorDescriptor, bool activate, IMemento::Pointer editorState); public: void OpenEmptyTab(); protected: void ShowEditor(bool activate, IEditorPart::Pointer editor); /** * See IWorkbenchPage. */ public: bool IsEditorPinned(IEditorPart::Pointer editor); /** * Removes an IPartListener from the part service. */ public: void RemovePartListener(IPartListener::Pointer l); /* * (non-Javadoc) Method declared on ISelectionListener. */ public: void RemoveSelectionListener(ISelectionListener::Pointer listener); /* * (non-Javadoc) Method declared on ISelectionListener. */ public: void RemoveSelectionListener(const std::string& partId, ISelectionListener::Pointer listener); /* * (non-Javadoc) Method declared on ISelectionListener. */ public: void RemovePostSelectionListener(ISelectionListener::Pointer listener); /* * (non-Javadoc) Method declared on ISelectionListener. */ public: void RemovePostSelectionListener(const std::string& partId, ISelectionListener::Pointer listener); /** * This method is called when a part is activated by clicking within it. In * response, the part, the pane, and all of its actions will be activated. * * In the current design this method is invoked by the part pane when the * pane, the part, or any children gain focus. */ public: void RequestActivation(IWorkbenchPart::Pointer part); /** * Resets the layout for the perspective. The active part in the old layout * is activated in the new layout for consistent user context. */ public: void ResetPerspective(); /** * Restore this page from the memento and ensure that the active * perspective is equals the active descriptor otherwise create a new * perspective for that descriptor. If activeDescriptor is null active the * old perspective. */ public: /*IStatus*/bool RestoreState(IMemento::Pointer memento, IPerspectiveDescriptor::Pointer activeDescriptor); /** * See IWorkbenchPage */ public: bool SaveAllEditors(bool confirm); /** * @param confirm * @param addNonPartSources true if saveables from non-part sources should be saved too * @return false if the user cancelled * */ public: bool SaveAllEditors(bool confirm, bool addNonPartSources); /* * Saves the workbench part. */ protected: bool SavePart(ISaveablePart::Pointer saveable, IWorkbenchPart::Pointer part, bool confirm); /** * Saves an editors in the workbench. If confirm is true * the user is prompted to confirm the command. * * @param confirm * if user confirmation should be sought * @return true if the command succeeded, or false * if the user cancels the command */ public: bool SaveEditor(IEditorPart::Pointer editor, bool confirm); /** * Saves the current perspective. */ public: void SavePerspective(); /** * Saves the perspective. */ public: void SavePerspectiveAs(IPerspectiveDescriptor::Pointer newDesc); /** * Save the state of the page. */ public: /*IStatus*/bool SaveState(IMemento::Pointer memento); private: std::string GetId(IWorkbenchPart::Pointer part); private: std::string GetId(IWorkbenchPartReference::Pointer ref); /** * Sets the active part. */ private: void SetActivePart(IWorkbenchPart::Pointer newPart); /** * See IWorkbenchPage. */ public: void SetEditorAreaVisible(bool showEditorArea); /** * Sets the layout of the page. Assumes the new perspective is not null. * Keeps the active part if possible. Updates the window menubar and * toolbar if necessary. */ private: void SetPerspective(SmartPointer newPersp); /* * Update visibility state of all views. */ private: void UpdateVisibility(SmartPointer oldPersp, SmartPointer newPersp); /** * Sets the perspective. * * @param desc * identifies the new perspective. */ public: void SetPerspective(IPerspectiveDescriptor::Pointer desc); /** * Restore the toolbar layout for the active perspective. */ protected: void ResetToolBarLayout(); /** * See IWorkbenchPage. */ public: IViewPart::Pointer ShowView(const std::string& viewID); /* * (non-Javadoc) * * @see org.blueberry.ui.IWorkbenchPage#showView(java.lang.String, * java.lang.String, int) */ public: IViewPart::Pointer ShowView(const std::string& viewID, const std::string& secondaryID, int mode); /** * @param mode the mode to test * @return whether the mode is recognized * @since 3.0 */ private: bool CertifyMode(int mode); /* * Returns the editors in activation order (oldest first). */ public: std::vector GetSortedEditors(); /** * @see IWorkbenchPage#getOpenPerspectives() */ public: std::vector GetOpenPerspectives(); /** * Return all open Perspective objects. * * @return all open Perspective objects * @since 3.1 */ /*package*/ protected: std::list > GetOpenInternalPerspectives(); /** * Checks perspectives in the order they were activiated * for the specfied part. The first sorted perspective * that contains the specified part is returned. * * @param part specified part to search for * @return the first sorted perspespective containing the part * @since 3.1 */ /*package*/ protected: SmartPointer GetFirstPerspectiveWithView(IViewPart::Pointer part); /** * Returns the perspectives in activation order (oldest first). */ public: std::vector GetSortedPerspectives(); /* * Returns the parts in activation order (oldest first). */ public: std::vector GetSortedParts(); /** * Returns the reference to the given part, or null if it has no reference * (i.e. it is not a top-level part in this workbench page). * * @param part the part * @return the part's reference or null if the given part does not belong * to this workbench page */ public: IWorkbenchPartReference::Pointer GetReference(IWorkbenchPart::Pointer part); // private: class ActivationList { // //List of parts in the activation order (oldest first) // List parts = new ArrayList(); // // /* // * Add/Move the active part to end of the list; // */ // void setActive(IWorkbenchPart part) { // if (parts.size() <= 0) { // return; // } // IWorkbenchPartReference ref = getReference(part); // if (ref != null) { // if (ref == parts.get(parts.size() - 1)) { // return; // } // parts.remove(ref); // parts.add(ref); // } // } // // /* // * Ensures that the given part appears AFTER any other part in the same // * container. // */ // void bringToTop(IWorkbenchPartReference ref) { // ILayoutContainer targetContainer = getContainer(ref); // // int newIndex = lastIndexOfContainer(targetContainer); // // //New index can be -1 if there is no last index // if (newIndex >= 0 && ref == parts.get(newIndex)) // return; // // parts.remove(ref); // if(newIndex >= 0) // parts.add(newIndex, ref); // else // parts.add(ref); // } // // /* // * Returns the last (most recent) index of the given container in the activation list, or returns // * -1 if the given container does not appear in the activation list. // */ // int lastIndexOfContainer(ILayoutContainer container) { // for (int i = parts.size() - 1; i >= 0; i--) { // IWorkbenchPartReference ref = (IWorkbenchPartReference)parts.get(i); // // ILayoutContainer cnt = getContainer(ref); // if (cnt == container) { // return i; // } // } // // return -1; // } // // /* // * Add/Move the active part to end of the list; // */ // void setActive(IWorkbenchPartReference ref) { // setActive(ref.getPart(true)); // } // // /* // * Add the active part to the beginning of the list. // */ // void add(IWorkbenchPartReference ref) { // if (parts.indexOf(ref) >= 0) { // return; // } // // IWorkbenchPart part = ref.getPart(false); // if (part != null) { // PartPane pane = ((PartSite) part.getSite()).getPane(); // if (pane instanceof MultiEditorInnerPane) { // MultiEditorInnerPane innerPane = (MultiEditorInnerPane) pane; // add(innerPane.getParentPane().getPartReference()); // return; // } // } // parts.add(0, ref); // } // // /* // * Return the active part. Filter fast views. // */ // IWorkbenchPart getActive() { // if (parts.isEmpty()) { // return null; // } // return getActive(parts.size() - 1); // } // // /* // * Return the previously active part. Filter fast views. // */ // IWorkbenchPart getPreviouslyActive() { // if (parts.size() < 2) { // return null; // } // return getActive(parts.size() - 2); // } // // private: IWorkbenchPart getActive(int start) { // IWorkbenchPartReference ref = getActiveReference(start, false); // // if (ref == null) { // return null; // } // // return ref.getPart(true); // } // // public: IWorkbenchPartReference getActiveReference(boolean editorsOnly) { // return getActiveReference(parts.size() - 1, editorsOnly); // } // // private: IWorkbenchPartReference getActiveReference(int start, boolean editorsOnly) { // // First look for parts that aren't obscured by the current zoom state // IWorkbenchPartReference nonObscured = getActiveReference(start, editorsOnly, true); // // if (nonObscured != null) { // return nonObscured; // } // // // Now try all the rest of the parts // return getActiveReference(start, editorsOnly, false); // } // // /* // * Find a part in the list starting from the end and filter // * and views from other perspectives. Will filter fast views // * unless 'includeActiveFastViews' is true; // */ // private: IWorkbenchPartReference getActiveReference(int start, boolean editorsOnly, boolean skipPartsObscuredByZoom) { // IWorkbenchPartReference[] views = getViewReferences(); // for (int i = start; i >= 0; i--) { // WorkbenchPartReference ref = (WorkbenchPartReference) parts // .get(i); // // if (editorsOnly && !(ref instanceof IEditorReference)) { // continue; // } // // // Skip parts whose containers have disabled auto-focus // PartPane pane = ref.getPane(); // // if (pane != null) { // if (!pane.allowsAutoFocus()) { // continue; // } // // if (skipPartsObscuredByZoom) { // if (pane.isObscuredByZoom()) { // continue; // } // } // } // // // Skip fastviews (unless overridden) // if (ref instanceof IViewReference) { // if (ref == getActiveFastView() || !((IViewReference) ref).isFastView()) { // for (int j = 0; j < views.length; j++) { // if (views[j] == ref) { // return ref; // } // } // } // } else { // return ref; // } // } // return null; // } // // /* // * Retuns the index of the part within the activation list. The higher // * the index, the more recently it was used. // */ // int indexOf(IWorkbenchPart part) { // IWorkbenchPartReference ref = getReference(part); // if (ref == null) { // return -1; // } // return parts.indexOf(ref); // } // // /* // * Returns the index of the part reference within the activation list. // * The higher the index, the more recent it was used. // */ // int indexOf(IWorkbenchPartReference ref) { // return parts.indexOf(ref); // } // // /* // * Remove a part from the list // */ // boolean remove(IWorkbenchPartReference ref) { // return parts.remove(ref); // } // // /* // * Returns the editors in activation order (oldest first). // */ // private: IEditorReference[] getEditors() { // ArrayList editors = new ArrayList(parts.size()); // for (Iterator i = parts.iterator(); i.hasNext();) { // IWorkbenchPartReference part = (IWorkbenchPartReference) i // .next(); // if (part instanceof IEditorReference) { // editors.add(part); // } // } // return (IEditorReference[]) editors // .toArray(new IEditorReference[editors.size()]); // } // // /* // * Return a list with all parts (editors and views). // */ // private: IWorkbenchPartReference[] getParts() { // IWorkbenchPartReference[] views = getViewReferences(); // ArrayList resultList = new ArrayList(parts.size()); // for (Iterator iterator = parts.iterator(); iterator.hasNext();) { // IWorkbenchPartReference ref = (IWorkbenchPartReference) iterator // .next(); // if (ref instanceof IViewReference) { // //Filter views from other perspectives // for (int i = 0; i < views.length; i++) { // if (views[i] == ref) { // resultList.add(ref); // break; // } // } // } else { // resultList.add(ref); // } // } // IWorkbenchPartReference[] result = new IWorkbenchPartReference[resultList // .size()]; // return (IWorkbenchPartReference[]) resultList.toArray(result); // } // // /* // * Returns the topmost editor on the stack, or null if none. // */ // IEditorPart getTopEditor() { // IEditorReference editor = (IEditorReference)getActiveReference(parts.size() - 1, true); // // if (editor == null) { // return null; // } // // return editor.getEditor(true); // } // }; // for dynamic UI protected: void AddPerspective(SmartPointer persp); /** * Find the stack of view references stacked with this view part. * * @param part * the part * @return the stack of references * @since 3.0 */ private: std::vector GetViewReferenceStack( IViewPart::Pointer part); /* * (non-Javadoc) * * @see org.blueberry.ui.IWorkbenchPage#getViewStack(org.blueberry.ui.IViewPart) */ public: std::vector GetViewStack(IViewPart::Pointer part); /** * Allow for programmatically resizing a part. *

    * EXPERIMENTAL *

    *

    * Known limitations: *

      *
    • currently applies only to views
    • *
    • has no effect when view is zoomed
    • *
    */ public: void ResizeView(IViewPart::Pointer part, int width, int height); private: struct ActivationOrderPred : std::binary_function { ActivationOrderPred(ActivationList* partList); ActivationList* activationList; bool operator()(const IViewReference::Pointer o1, const IViewReference::Pointer o2) const; }; // provides sash information for the given pane struct SashInfo { SmartPointer right; SmartPointer left; SmartPointer top; SmartPointer bottom; SmartPointer rightNode; SmartPointer leftNode; SmartPointer topNode; SmartPointer bottomNode; }; void FindSashParts(SmartPointer tree, const PartPane::Sashes& sashes, SashInfo& info); /** * Returns all parts that are owned by this page * * @return */ protected: std::vector GetAllParts(); /** * Returns all open parts that are owned by this page (that is, all parts * for which a part opened event would have been sent -- these would be * activated parts whose controls have already been created. */ protected: std::vector GetOpenParts(); /** * Sanity-checks the objects in this page. Throws an Assertation exception * if an object's internal state is invalid. ONLY INTENDED FOR USE IN THE * UI TEST SUITES. */ public: void TestInvariants(); /* (non-Javadoc) * @see org.blueberry.ui.IWorkbenchPage#getExtensionTracker() */ //public: IExtensionTracker GetExtensionTracker(); /* * (non-Javadoc) * * @see org.blueberry.ui.IWorkbenchPage#getPerspectiveShortcuts() */ public: std::vector GetPerspectiveShortcuts(); /* * (non-Javadoc) * * @see org.blueberry.ui.IWorkbenchPage#getShowViewShortcuts() */ public: std::vector GetShowViewShortcuts(); /** * @since 3.1 */ private: void SuggestReset(); public: bool IsPartVisible(IWorkbenchPartReference::Pointer reference); }; } #endif /*BERRYWORKBENCHPAGE_H_*/