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 6df35d76b0..2e4f879b95 100644 --- a/Plugins/org.mitk.gui.qt.viewbrowser/src/internal/ViewBrowserView.cpp +++ b/Plugins/org.mitk.gui.qt.viewbrowser/src/internal/ViewBrowserView.cpp @@ -1,182 +1,214 @@ /*=================================================================== 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" #include #include // Qt #include #include #include +struct ViewBrowserViewListener : public berry::IPerspectiveListener +{ + ViewBrowserViewListener(ViewBrowserView* switcher) + : switcher(switcher) + {} + + Events::Types GetPerspectiveEventTypes() const + { + return Events::ACTIVATED; + } + + virtual void PerspectiveChanged(berry::SmartPointer /*page*/, + berry::IPerspectiveDescriptor::Pointer /*perspective*/, const std::string& /*changeId*/) + { + MITK_INFO << "Yep i did something..."; + switcher->FillTreeList(); + } + + void PerspectiveActivated(berry::IWorkbenchPage::Pointer /*page*/, + berry::IPerspectiveDescriptor::Pointer perspective) + { + MITK_INFO << "Yep i did something... and it is not wrong"; + switcher->FillTreeList(); + } + +private: + ViewBrowserView* switcher; +}; + const std::string ViewBrowserView::VIEW_ID = "org.mitk.views.viewbrowser"; void ViewBrowserView::SetFocus() { } void ViewBrowserView::CreateQtPartControl( QWidget *parent ) { // create GUI widgets from the Qt Designer's .ui file m_Controls.setupUi( parent ); connect( m_Controls.m_PluginTreeView, SIGNAL(customContextMenuRequested(QPoint)), SLOT(CustomMenuRequested(QPoint))); connect( m_Controls.m_PluginTreeView, SIGNAL(clicked(const QModelIndex&)), SLOT(ItemClicked(const QModelIndex&))); // Create a new TreeModel for the data m_TreeModel = new QStandardItemModel(); FillTreeList(); m_Controls.m_PluginTreeView->setModel(m_TreeModel); + + this->perspListener = new ViewBrowserViewListener(this); + berry::PlatformUI::GetWorkbench()->GetActiveWorkbenchWindow()->AddPerspectiveListener(this->perspListener); } void ViewBrowserView::FillTreeList() { m_TreeModel->clear(); QStandardItem *item = m_TreeModel->invisibleRootItem(); // Get all available views and create a map of all views std::map viewMap; berry::IViewRegistry* viewRegistry = berry::PlatformUI::GetWorkbench()->GetViewRegistry(); std::vector views(viewRegistry->GetViews()); for (unsigned int i=0; iGetId()] = views[i]; } // Get all available perspectives berry::IPerspectiveRegistry* perspRegistry = berry::PlatformUI::GetWorkbench()->GetPerspectiveRegistry(); std::vector perspectives(perspRegistry->GetPerspectives()); // Get the current Window and the current active Perspective if possible 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(); } } // Fill the TreeModel for (unsigned int i=0; i preparedRow; mitk::QtPerspectiveItem* pItem = new mitk::QtPerspectiveItem(QString::fromStdString(p->GetLabel())); pItem->m_Perspective = p; preparedRow << pItem; item->appendRow(preparedRow); // If the current perspective is the active perspective add current views if (currentPersp.compare(p->GetId())==0) { if (curWin.IsNull()) continue; berry::IWorkbenchPage::Pointer activePage = curWin->GetActivePage(); std::vector< std::string > currentViews = activePage->GetShowViewShortcuts(); for (int j = 0; j < currentViews.size(); ++j) { QList secondRow; mitk::QtViewItem* vItem = new mitk::QtViewItem(QString::fromStdString(currentViews[j])); vItem->m_View = viewMap[currentViews[j]]; secondRow << vItem; preparedRow.first()->appendRow(secondRow); } } } // Add a list with all available views QList< QStandardItem*> preparedRow; QStandardItem* pItem = new QStandardItem("All Views"); preparedRow << pItem; item->appendRow(preparedRow); for (int i = 0; i < views.size(); ++i) { QList secondRow; mitk::QtViewItem* vItem = new mitk::QtViewItem(QString::fromStdString(views[i]->GetLabel())); vItem->m_View = views[i]; secondRow << vItem; preparedRow.first()->appendRow(secondRow); } } 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) { QStandardItem* item = m_TreeModel->itemFromIndex(index); if ( dynamic_cast< mitk::QtPerspectiveItem* >(item) ) { try { // berry::IWorkbenchPage::Pointer page = berry::PlatformUI::GetWorkbench()->GetActiveWorkbenchWindow()->GetActivePage(); // page->CloseAllPerspectives(false, false); mitk::QtPerspectiveItem* pItem = dynamic_cast< mitk::QtPerspectiveItem* >(item); // page->ClosePerspective( pItem->m_Perspective, true, false ); berry::PlatformUI::GetWorkbench()->ShowPerspective( pItem->m_Perspective->GetId(), berry::PlatformUI::GetWorkbench()->GetActiveWorkbenchWindow() ); } catch (...) { QMessageBox::critical(0, "Opening Perspective Failed", QString("The requested perspective could not be opened.\nSee the log for details.")); } } else if ( dynamic_cast< mitk::QtViewItem* >(item) ) { berry::IWorkbenchPage::Pointer page = berry::PlatformUI::GetWorkbench()->GetActiveWorkbenchWindow()->GetActivePage(); if (page.IsNotNull()) { try { mitk::QtViewItem* vItem = dynamic_cast< mitk::QtViewItem* >(item); page->ShowView(vItem->m_View->GetId()); } catch (berry::PartInitException e) { BERRY_ERROR << "Error: " << e.displayText() << std::endl; } } } } void ViewBrowserView::CustomMenuRequested(QPoint pos) { // m_ContextMenu->popup(m_Controls.m_PerspectiveTree->viewport()->mapToGlobal(pos)); } \ No newline at end of file diff --git a/Plugins/org.mitk.gui.qt.viewbrowser/src/internal/ViewBrowserView.h b/Plugins/org.mitk.gui.qt.viewbrowser/src/internal/ViewBrowserView.h index 06ec773ce6..421957ee7a 100644 --- a/Plugins/org.mitk.gui.qt.viewbrowser/src/internal/ViewBrowserView.h +++ b/Plugins/org.mitk.gui.qt.viewbrowser/src/internal/ViewBrowserView.h @@ -1,70 +1,80 @@ /*=================================================================== 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. ===================================================================*/ #ifndef ViewBrowserView_h #define ViewBrowserView_h #include +#include #include #include "ui_ViewBrowserViewControls.h" #include +#include +#include +#include /** \brief ViewBrowserView \warning This class is not yet documented. Use "git blame" and ask the author to provide basic documentation. \sa QmitkAbstractView \ingroup ${plugin_target}_internal */ class ViewBrowserView : public QmitkAbstractView { // this is needed for all Qt objects that should have a Qt meta-object // (everything that derives from QObject and wants to have signal/slots) Q_OBJECT public: static const std::string VIEW_ID; + + /// \brief Fills the TreeList with the available perspectives and views. + void FillTreeList(); + + protected slots: /// \brief Called when the user clicks the GUI button void CustomMenuRequested(QPoint pos); void ItemClicked(const QModelIndex &index); protected: virtual void CreateQtPartControl(QWidget *parent); virtual void SetFocus(); /// \brief called by QmitkFunctionality when DataManager's selection has changed virtual void OnSelectionChanged( berry::IWorkbenchPart::Pointer source, const QList& nodes ); - /// \brief Fills the TreeList with the available perspectives and views. - void FillTreeList(); Ui::ViewBrowserViewControls m_Controls; QStandardItemModel* m_TreeModel; + berry::IPerspectiveListener::Pointer perspListener; + + friend struct ViewBrowserViewListener; }; #endif // ViewBrowserView_h