diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryFolderLayout.cpp b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryFolderLayout.cpp index 1661d690fa..208f6899d0 100644 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryFolderLayout.cpp +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryFolderLayout.cpp @@ -1,97 +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. ===================================================================*/ #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. 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) { + pageLayout->AddShowViewShortcut(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, LayoutPart::Pointer newPart) { pageLayout->SetRefPart(viewId, newPart); pageLayout->SetFolderPart(viewId, folder); // force creation of the view layout rec pageLayout->GetViewLayoutRec(viewId, true); } - -} +} \ No newline at end of file diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPageLayout.cpp b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPageLayout.cpp index 028013cd3d..67671fe310 100644 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPageLayout.cpp +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPageLayout.cpp @@ -1,673 +1,670 @@ /*=================================================================== 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. 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(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::AddPart(LayoutPart::Pointer newPart, const std::string& partId, int relationship, float ratio, const std::string& refId) { - this->SetRefPart(partId, newPart); // If the referenced part is inside a folder, // then use the folder as the reference part. 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, this->GetPartSashConst(relationship), ratio, refPart); } else { WorkbenchPlugin::Log("Reference part does not exist yet: " + refId); 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 the placeholder. PartPlaceholder::Pointer newPart(new PartPlaceholder(viewId)); 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()) + if (std::find(showViewShortcuts.begin(), showViewShortcuts.end(), id) == showViewShortcuts.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) { + this->AddShowViewShortcut(viewId); if (this->CheckPartInLayout(viewId)) { return; } try { // Create the part. LayoutPart::Pointer newPart = this->CreateView(viewId); if (newPart == 0) { this->AddPlaceholder(viewId, relationship, ratio, refId); 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->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)) { ILayoutContainer::Pointer folder = this->GetFolderPart(folderId); return mapFolderToFolderLayout[folder].Cast(); } // Create the folder. PartStack::Pointer folder(new PartStack(rootLayoutContainer->page)); folder->SetID(folderId); 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(ILayoutContainer::Pointer(new PartStack(rootLayoutContainer->page))); folder->SetID(folderId); 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; } LayoutPart::Pointer PageLayout::CreateView(const std::string& partID) { if (partID == ID_EDITOR_AREA) { return editorFolder; } // 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; } PartStack::Pointer PageLayout::GetFolderPart(const std::string& viewId) { return mapIDtoFolder[viewId].Cast(); } int PageLayout::GetPartSashConst(int nRelationship) { return nRelationship; } std::vector PageLayout::GetPerspectiveShortcuts() { return perspectiveShortcuts; } 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) { LayoutPart::Pointer tabFolder = container->GetRealContainer(); mapIDtoFolder[viewId] = tabFolder.Cast(); } void PageLayout::SetFolderPart(const std::string& viewId, PartStack::Pointer folder) { mapIDtoFolder[viewId] = folder.Cast(); } void PageLayout::SetFolderPart(const std::string& viewId, ILayoutContainer::Pointer folder) { mapIDtoFolder[viewId] = folder; } void PageLayout::SetRefPart(const std::string& partID, LayoutPart::Pointer part) { mapIDtoPart[partID] = part; } 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. // 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)); 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 { 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(ILayoutContainer::Pointer(new PartStack(rootLayoutContainer->page, true, appearance, 0))); folder->SetID(stackId); 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) { LayoutPart::Pointer part = this->GetRefPart(id); if (part->IsPlaceHolder()) { 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); 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; } - -} +} \ No newline at end of file diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPerspective.cpp b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPerspective.cpp index 2c8e5003e2..28c20a001d 100644 --- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPerspective.cpp +++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPerspective.cpp @@ -1,1763 +1,1755 @@ /*=================================================================== 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 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(); + showViewShortcuts = layout->GetShowViewShortcuts(); // 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); if (willPartBeVisible) { IViewPart::Pointer view = ref->GetPart(true).Cast(); if (view) { ViewSite::Pointer site = view->GetSite().Cast(); pres->ReplacePlaceholderWithPart(site->GetPane().Cast()); } } else { 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; } - -} +} \ No newline at end of file diff --git a/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkDiffusionImagingPublicPerspective.cpp b/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkDiffusionImagingPublicPerspective.cpp index 3fa659c034..9ab9b5f24a 100644 --- a/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkDiffusionImagingPublicPerspective.cpp +++ b/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkDiffusionImagingPublicPerspective.cpp @@ -1,78 +1,76 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) 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 "QmitkDiffusionImagingPublicPerspective.h" #include "berryIViewLayout.h" QmitkDiffusionImagingPublicPerspective::QmitkDiffusionImagingPublicPerspective() { - } QmitkDiffusionImagingPublicPerspective::QmitkDiffusionImagingPublicPerspective(const QmitkDiffusionImagingPublicPerspective& other) { Q_UNUSED(other) throw std::runtime_error("Copy constructor not implemented"); } void QmitkDiffusionImagingPublicPerspective::CreateInitialLayout(berry::IPageLayout::Pointer layout) { std::string editorArea = layout->GetEditorArea(); layout->AddStandaloneView("org.mitk.views.datamanager", false, berry::IPageLayout::LEFT, 0.3f, editorArea); layout->AddStandaloneView("org.mitk.views.controlvisualizationpropertiesview", false, berry::IPageLayout::BOTTOM, .2f, "org.mitk.views.datamanager"); berry::IFolderLayout::Pointer left = layout->CreateFolder("org.mitk.leftcontrols", berry::IPageLayout::BOTTOM, 0.125f, "org.mitk.views.controlvisualizationpropertiesview"); layout->AddStandaloneView("org.mitk.views.imagenavigator", false, berry::IPageLayout::BOTTOM, 0.8f, "org.mitk.leftcontrols"); layout->AddStandaloneView("org.mitk.views.perspectiveswitcher", false, berry::IPageLayout::BOTTOM, 0.99f, "org.mitk.views.imagenavigator"); // layout->AddStandaloneViewPlaceholder("org.mitk.views.imagenavigator", // berry::IPageLayout::TOP, 0.9f, "org.mitk.views.perspectiveswitcher",false); left->AddView("org.mitk.views.diffusionpreprocessing"); left->AddView("org.mitk.views.tensorreconstruction"); left->AddView("org.mitk.views.qballreconstruction"); left->AddView("org.mitk.views.diffusionquantification"); left->AddView("org.mitk.views.diffusiondicomimport"); berry::IViewLayout::Pointer lo = layout->GetViewLayout("org.mitk.views.diffusionpreprocessing"); lo->SetCloseable(false); lo = layout->GetViewLayout("org.mitk.views.qballreconstruction"); lo->SetCloseable(false); lo = layout->GetViewLayout("org.mitk.views.tensorreconstruction"); lo->SetCloseable(false); lo = layout->GetViewLayout("org.mitk.views.diffusionquantification"); lo->SetCloseable(false); lo = layout->GetViewLayout("org.mitk.views.diffusiondicomimport"); lo->SetCloseable(false); //berry::IFolderLayout::Pointer right2 = // layout->CreateFolder("right2", berry::IPageLayout::BOTTOM, 0.5f, "right"); - -} +} \ No newline at end of file diff --git a/Plugins/org.mitk.gui.qt.viewbrowser/src/internal/ViewBrowserView.cpp b/Plugins/org.mitk.gui.qt.viewbrowser/src/internal/ViewBrowserView.cpp index e3a566837a..076d2d90db 100644 --- a/Plugins/org.mitk.gui.qt.viewbrowser/src/internal/ViewBrowserView.cpp +++ b/Plugins/org.mitk.gui.qt.viewbrowser/src/internal/ViewBrowserView.cpp @@ -1,156 +1,200 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) 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. ===================================================================*/ // Blueberry #include #include #include #include #include // Qmitk #include "ViewBrowserView.h" // Qt #include #include #include const std::string ViewBrowserView::VIEW_ID = "org.mitk.views.viewbrowser"; void ViewBrowserView::SetFocus() { m_Controls.buttonPerformImageProcessing->setFocus(); } void ViewBrowserView::CreateQtPartControl( QWidget *parent ) { // create GUI widgets from the Qt Designer's .ui file m_Controls.setupUi( parent ); connect( m_Controls.buttonPerformImageProcessing, SIGNAL(clicked()), this, SLOT(DoSomething()) ); connect( m_Controls.m_PluginTreeView, SIGNAL(customContextMenuRequested(QPoint)), SLOT(CustomMenuRequested(QPoint))); connect( m_Controls.m_PluginTreeView, SIGNAL(clicked(const QModelIndex&)), SLOT(ItemClicked(const QModelIndex&))); m_TreeModel = new QStandardItemModel(); QStandardItem *item = m_TreeModel->invisibleRootItem(); berry::IPerspectiveRegistry* perspRegistry = berry::PlatformUI::GetWorkbench()->GetPerspectiveRegistry(); std::vector perspectives(perspRegistry->GetPerspectives()); bool skip = false; berry::IViewRegistry* viewRegistry = berry::PlatformUI::GetWorkbench()->GetViewRegistry(); std::vector views(viewRegistry->GetViews()); + berry::IWorkbenchWindow::Pointer curWin = berry::PlatformUI::GetWorkbench()->GetActiveWorkbenchWindow(); + std::string currentPersp = ""; + if (curWin.IsNotNull()) + { + if (curWin->GetActivePage().IsNotNull()) + { + berry::IPerspectiveDescriptor::Pointer persps = curWin->GetActivePage()->GetPerspective(); + currentPersp=persps->GetId(); + } + } MITK_INFO << "PERSPECTIVES"; for (unsigned int i=0; i preparedRow =prepareRow("first", "second", "third"); berry::IPerspectiveDescriptor::Pointer p = perspectives.at(i); MITK_INFO << p->GetId(); QList preparedRow; preparedRow << new QStandardItem(QString::fromStdString(p->GetLabel())); preparedRow << new QStandardItem(QString::fromStdString(p->GetId())); item->appendRow(preparedRow); - - for (unsigned int i=0; iGetId())==0) { - berry::IViewDescriptor::Pointer w = views.at(i); + if (curWin.IsNull()) + continue; + berry::IWorkbenchPage::Pointer activePage = curWin->GetActivePage(); + std::vector< std::string > currentViews = activePage->GetShowViewShortcuts(); + MITK_INFO << "Views: " << currentViews.size(); + for (int j = 0; j < currentViews.size(); ++j) + { + MITK_INFO << currentViews[j]; QList secondRow; - secondRow << new QStandardItem(QString::fromStdString(w->GetLabel())); - secondRow << new QStandardItem(QString::fromStdString(w->GetId())); + secondRow << new QStandardItem(QString::fromStdString("")); + secondRow << new QStandardItem(QString::fromStdString(currentViews[j])); preparedRow.first()->appendRow(secondRow); + } } + // if perspectiveExcludeList is set, it contains the id-strings of perspectives, which // should not appear as an menu-entry in the perspective menu // if (perspectiveExcludeList.size() > 0) // { // for (unsigned int i=0; iGetId()) // { // skip = true; // break; // } // } // if (skip) // { // skip = false; // continue; // } // } // QAction* perspAction = new berry::QtOpenPerspectiveAction(window, // *perspIt, perspGroup); // mapPerspIdToAction.insert(std::make_pair((*perspIt)->GetId(), perspAction)); } MITK_INFO << "VIEWS"; //berry::QTOpenPers // adding a row to the invisible root item produces a root element //item->appendRow(preparedRow); //QList secondRow =prepareRow("111", "222", "333"); // adding a row to an item starts a subtree //preparedRow.first()->appendRow(secondRow); + //QList preparedRow =prepareRow("first", "second", "third"); + QList preparedRow; + preparedRow << new QStandardItem(QString::fromStdString("All Views")); + preparedRow << new QStandardItem(QString::fromStdString("")); + item->appendRow(preparedRow); + + for (unsigned int i=0; i secondRow; + secondRow << new QStandardItem(QString::fromStdString(w->GetLabel())); + secondRow << new QStandardItem(QString::fromStdString(w->GetId())); + preparedRow.first()->appendRow(secondRow); + } + + m_Controls.m_PluginTreeView->setModel(m_TreeModel); m_Controls.m_PluginTreeView->expandAll(); } void ViewBrowserView::OnSelectionChanged( berry::IWorkbenchPart::Pointer /*source*/, const QList& nodes ) { // iterate all selected objects, adjust warning visibility foreach( mitk::DataNode::Pointer node, nodes ) { if( node.IsNotNull() ) { return; } } } void ViewBrowserView::ItemClicked(const QModelIndex &index) { MITK_INFO << index.row() << "-" << index.column(); + MITK_INFO << m_TreeModel->itemFromIndex(index)->text().toStdString(); // if (index.column()==0) // { try { std::vector perspectives(berry::PlatformUI::GetWorkbench()->GetPerspectiveRegistry()->GetPerspectives()); berry::PlatformUI::GetWorkbench()->ShowPerspective( perspectives.at(index.row())->GetId(), berry::PlatformUI::GetWorkbench()->GetWorkbenchWindows().at(0) ); } catch (...) { QMessageBox::critical(0, "Opening Perspective Failed", QString("The requested perspective could not be opened.\nSee the log for details.")); } // } } void ViewBrowserView::CustomMenuRequested(QPoint pos) { // m_ContextMenu->popup(m_Controls.m_PerspectiveTree->viewport()->mapToGlobal(pos)); } void ViewBrowserView::DoSomething() { - -} + berry::IWorkbenchPage::Pointer activePage = berry::PlatformUI::GetWorkbench()->GetActiveWorkbenchWindow()->GetActivePage(); + std::vector< std::string > currentViews = activePage->GetShowViewShortcuts(); + MITK_INFO << "Views: " << currentViews.size(); + for (int i = 0; i < currentViews.size(); ++i) + { + MITK_INFO << currentViews[i]; + } + berry::IPerspectiveDescriptor::Pointer persps = berry::PlatformUI::GetWorkbench()->GetActiveWorkbenchWindow()->GetActivePage()->GetPerspective(); + MITK_INFO << "Open Perspectives"; + MITK_INFO <GetLabel(); +} \ No newline at end of file