diff --git a/BlueBerry/Bundles/org.blueberry.ui.qt/plugin.xml b/BlueBerry/Bundles/org.blueberry.ui.qt/plugin.xml
index 2dedb50602..f6516dcc1d 100644
--- a/BlueBerry/Bundles/org.blueberry.ui.qt/plugin.xml
+++ b/BlueBerry/Bundles/org.blueberry.ui.qt/plugin.xml
@@ -1,68 +1,68 @@
-
\ No newline at end of file
+
diff --git a/BlueBerry/Bundles/org.blueberry.ui.qt/src/internal/berryQtShell.cpp b/BlueBerry/Bundles/org.blueberry.ui.qt/src/internal/berryQtShell.cpp
index 23121d0711..8e65e622d3 100755
--- a/BlueBerry/Bundles/org.blueberry.ui.qt/src/internal/berryQtShell.cpp
+++ b/BlueBerry/Bundles/org.blueberry.ui.qt/src/internal/berryQtShell.cpp
@@ -1,224 +1,224 @@
/*=========================================================================
Program: BlueBerry Platform
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) German Cancer Research Center, Division of Medical and
Biological Informatics. All rights reserved.
See MITKCopyright.txt or http://www.mitk.org/copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY { } without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "berryQtShell.h"
#include "berryQtWidgetsTweakletImpl.h"
#include "berryQtMainWindowControl.h"
#include "berryQtControlWidget.h"
#include
#include
#include
#include
#include
namespace berry
{
QtShell::QtShell(QWidget* parent, Qt::WindowFlags flags)
: updatesDisabled(false)
{
if (parent == 0 || flags.testFlag(Qt::Window))
{
widget = new QtMainWindowControl(this, parent, flags);
widget->setUpdatesEnabled(false);
updatesDisabled = true;
widget->setAttribute(Qt::WA_DeleteOnClose);
}
else
{
widget = new QtControlWidget(parent, this, flags | Qt::Dialog);
widget->setObjectName("shell widget");
}
}
QtShell::~QtShell()
{
widget->deleteLater();
}
void QtShell::SetBounds(const Rectangle& bounds)
{
widget->move(bounds.x, bounds.y);
widget->resize(bounds.width, bounds.height);
}
Rectangle QtShell::GetBounds() const
{
const QRect& qRect = widget->frameGeometry();
const QSize& size = widget->size();
Rectangle rect(qRect.x(), qRect.y(), size.width(), size.height());
return rect;
}
void QtShell::SetLocation(int x, int y)
{
widget->move(x, y);
}
Point QtShell::ComputeSize(int /*wHint*/, int /*hHint*/, bool changed)
{
if (changed) widget->updateGeometry();
QSize size(widget->size());
Point point(size.width(), size.height());
return point;
}
std::string QtShell::GetText() const
{
return widget->windowTitle().toStdString();
}
void QtShell::SetText(const std::string& text)
{
QString title(QString::fromStdString(text));
widget->setWindowTitle(title);
widget->setObjectName(title);
}
bool QtShell::IsVisible()
{
return widget->isVisible();
}
void QtShell::SetVisible(bool visible)
{
widget->setVisible(visible);
}
void QtShell::SetActive()
{
widget->activateWindow();
widget->raise();
}
void* QtShell::GetControl()
{
return widget;
}
void QtShell::SetImages(const std::vector& /*images*/)
{
}
bool QtShell::GetMaximized()
{
return widget->isMaximized();
}
bool QtShell::GetMinimized()
{
return widget->isMinimized();
}
void QtShell::SetMaximized(bool maximized)
{
maximized ? widget->showMaximized() : widget->showNormal();
}
void QtShell::SetMinimized(bool minimized)
{
minimized ? widget->showMinimized() : widget->showNormal();
}
void QtShell::AddShellListener(IShellListener::Pointer listener)
{
QVariant variant = widget->property(QtWidgetController::PROPERTY_ID);
poco_assert(variant.isValid());
QtWidgetController::Pointer controller = variant.value();
poco_assert(controller != 0);
controller->AddShellListener(listener);
}
void QtShell::RemoveShellListener(IShellListener::Pointer listener)
{
QVariant variant = widget->property(QtWidgetController::PROPERTY_ID);
if (variant.isValid())
{
QtWidgetController::Pointer controller = variant.value();
if (controller != 0)
controller->RemoveShellListener(listener);
}
}
void QtShell::Open(bool block)
{
if (updatesDisabled)
{
widget->setUpdatesEnabled(true);
updatesDisabled = false;
}
widget->setWindowModality(block ? Qt::WindowModal : Qt::NonModal);
widget->show();
}
void QtShell::Close()
{
widget->close();
}
std::vector QtShell::GetShells()
{
- GuiWidgetsTweaklet::Pointer widgetTweaklet = Tweaklets::Get(GuiWidgetsTweaklet::KEY);
+ GuiWidgetsTweaklet* widgetTweaklet = Tweaklets::Get(GuiWidgetsTweaklet::KEY);
std::vector allShells(widgetTweaklet->GetShells());
std::vector descendants;
for (std::size_t i = 0; i < allShells.size(); ++i)
{
Shell::Pointer shell = allShells[i];
if (widgetTweaklet->GetShell(shell->GetControl()) == this)
{
descendants.push_back(shell);
}
}
return descendants;
}
int QtShell::GetStyle()
{
Qt::WindowFlags qtFlags = widget->windowFlags();
int berryFlags = 0;
if (!(qtFlags & Qt::FramelessWindowHint))
berryFlags |= Constants::BORDER;
if (qtFlags & Qt::WindowTitleHint)
berryFlags |= Constants::TITLE;
if (qtFlags & Qt::WindowSystemMenuHint)
berryFlags |= Constants::CLOSE;
if (qtFlags & Qt::WindowMinimizeButtonHint)
berryFlags |= Constants::MIN;
if (qtFlags & Qt::WindowMaximizeButtonHint)
berryFlags |= Constants::MAX;
if (widget->windowModality() == Qt::WindowModal)
berryFlags |= Constants::PRIMARY_MODAL;
else if(widget->windowModality() == Qt::ApplicationModal)
berryFlags |= Constants::APPLICATION_MODAL;
return berryFlags;
}
QWidget* QtShell::GetWidget()
{
return widget;
}
}
diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/berryGeometry.cpp b/BlueBerry/Bundles/org.blueberry.ui/src/berryGeometry.cpp
index 9cfa13404a..1b71a8a824 100755
--- a/BlueBerry/Bundles/org.blueberry.ui/src/berryGeometry.cpp
+++ b/BlueBerry/Bundles/org.blueberry.ui/src/berryGeometry.cpp
@@ -1,172 +1,172 @@
/*=========================================================================
Program: BlueBerry Platform
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) German Cancer Research Center, Division of Medical and
Biological Informatics. All rights reserved.
See MITKCopyright.txt or http://www.mitk.org/copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
// needed under windows to suppress the definition of the
// min/max macros in windows.h, which would clash with
// std::numeric_limits<>::max()
#define NOMINMAX
+#include "tweaklets/berryGuiWidgetsTweaklet.h"
+
#include "berryGeometry.h"
#include "berryConstants.h"
-#include "tweaklets/berryGuiWidgetsTweaklet.h"
-
#include
namespace berry
{
int Geometry::GetDimension(const Rectangle& toMeasure, bool width)
{
if (width)
{
return toMeasure.width;
}
return toMeasure.height;
}
bool Geometry::IsHorizontal(int berrySideConstant)
{
return !(berrySideConstant == Constants::LEFT || berrySideConstant
== Constants::RIGHT);
}
Rectangle Geometry::GetExtrudedEdge(const Rectangle& toExtrude, int size,
int orientation)
{
Rectangle bounds(toExtrude);
if (!IsHorizontal(orientation))
{
bounds.width = size;
}
else
{
bounds.height = size;
}
if (orientation == Constants::RIGHT)
{
bounds.x = toExtrude.x + toExtrude.width - bounds.width;
}
else if (orientation == Constants::BOTTOM)
{
bounds.y = toExtrude.y + toExtrude.height - bounds.height;
}
Normalize(bounds);
return bounds;
}
void Geometry::Normalize(Rectangle& rect)
{
if (rect.width < 0)
{
rect.width = -rect.width;
rect.x -= rect.width;
}
if (rect.height < 0)
{
rect.height = -rect.height;
rect.y -= rect.height;
}
}
int Geometry::GetClosestSide(const Rectangle& boundary, const Point& toTest)
{
int sides[] =
{ Constants::LEFT, Constants::RIGHT, Constants::TOP, Constants::BOTTOM };
int closestSide = Constants::LEFT;
int closestDistance = std::numeric_limits::max();
for (unsigned int idx = 0; idx < 4; idx++)
{
int side = sides[idx];
int distance = GetDistanceFromEdge(boundary, toTest, side);
if (distance < closestDistance)
{
closestDistance = distance;
closestSide = side;
}
}
return closestSide;
}
int Geometry::GetDistanceFromEdge(const Rectangle& rectangle,
const Point& testPoint, int edgeOfInterest)
{
if (edgeOfInterest == Constants::TOP)
return testPoint.y - rectangle.y;
else if (edgeOfInterest == Constants::BOTTOM)
return rectangle.y + rectangle.height - testPoint.y;
else if (edgeOfInterest == Constants::LEFT)
return testPoint.x - rectangle.x;
else if (edgeOfInterest == Constants::RIGHT)
return rectangle.x + rectangle.width - testPoint.x;
return 0;
}
int Geometry::GetOppositeSide(int directionConstant)
{
if (directionConstant == Constants::TOP)
return Constants::BOTTOM;
else if (directionConstant == Constants::BOTTOM)
return Constants::TOP;
else if (directionConstant == Constants::LEFT)
return Constants::RIGHT;
else if (directionConstant == Constants::RIGHT)
return Constants::LEFT;
return directionConstant;
}
Rectangle Geometry::ToControl(void* coordinateSystem,
const Rectangle& toConvert)
{
return Tweaklets::Get(GuiWidgetsTweaklet::KEY)->ToControl(coordinateSystem,
toConvert);
}
Point Geometry::ToControl(void* coordinateSystem, const Point& toConvert)
{
return Tweaklets::Get(GuiWidgetsTweaklet::KEY)->ToControl(coordinateSystem,
toConvert);
}
Rectangle Geometry::ToDisplay(void* coordinateSystem,
const Rectangle& toConvert)
{
return Tweaklets::Get(GuiWidgetsTweaklet::KEY)->ToDisplay(coordinateSystem,
toConvert);
}
Point Geometry::ToDisplay(void* coordinateSystem, const Point& toConvert)
{
return Tweaklets::Get(GuiWidgetsTweaklet::KEY)->ToDisplay(coordinateSystem,
toConvert);
}
}
diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/berryImageDescriptor.cpp b/BlueBerry/Bundles/org.blueberry.ui/src/berryImageDescriptor.cpp
index 2b9b0caeac..66a27f70c1 100755
--- a/BlueBerry/Bundles/org.blueberry.ui/src/berryImageDescriptor.cpp
+++ b/BlueBerry/Bundles/org.blueberry.ui/src/berryImageDescriptor.cpp
@@ -1,44 +1,44 @@
/*=========================================================================
Program: BlueBerry Platform
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) German Cancer Research Center, Division of Medical and
Biological Informatics. All rights reserved.
See MITKCopyright.txt or http://www.mitk.org/copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
-#include "berryImageDescriptor.h"
-
#include "tweaklets/berryImageTweaklet.h"
+#include "berryImageDescriptor.h"
+
namespace berry {
ImageDescriptor::Pointer ImageDescriptor::CreateFromFile(const std::string& filename, const std::string& pluginid)
{
return Tweaklets::Get(ImageTweaklet::KEY)->CreateFromFile(filename, pluginid);
}
ImageDescriptor::Pointer ImageDescriptor::CreateFromImage(void* img)
{
return Tweaklets::Get(ImageTweaklet::KEY)->CreateFromImage(img);
}
ImageDescriptor::Pointer ImageDescriptor::GetMissingImageDescriptor()
{
return Tweaklets::Get(ImageTweaklet::KEY)->GetMissingImageDescriptor();
}
ImageDescriptor::ImageDescriptor()
{
}
}
diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/berryWindow.cpp b/BlueBerry/Bundles/org.blueberry.ui/src/berryWindow.cpp
index ea00ac2a22..8850ca72fb 100755
--- a/BlueBerry/Bundles/org.blueberry.ui/src/berryWindow.cpp
+++ b/BlueBerry/Bundles/org.blueberry.ui/src/berryWindow.cpp
@@ -1,531 +1,531 @@
/*=========================================================================
Program: BlueBerry Platform
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) German Cancer Research Center, Division of Medical and
Biological Informatics. All rights reserved.
See MITKCopyright.txt or http://www.mitk.org/copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "berryWindow.h"
#include "berryConstants.h"
#include "berrySameShellProvider.h"
#include "tweaklets/berryGuiWidgetsTweaklet.h"
namespace berry
{
const int Window::OK = 0;
const int Window::CANCEL = 1;
std::vector Window::defaultImages = std::vector();
Window::IExceptionHandler::Pointer Window::exceptionHandler(new DefaultExceptionHandler());
IShellProvider::Pointer Window::defaultModalParent(new DefaultModalParent());
Window::WindowShellListener::WindowShellListener(Window* wnd)
: window(wnd)
{
}
void Window::WindowShellListener::ShellClosed(ShellEvent::Pointer event)
{
event->doit = false; // don't close now
if (window->CanHandleShellCloseEvent())
{
window->HandleShellCloseEvent();
}
}
void Window::DefaultExceptionHandler::HandleException(const std::exception& t)
{
// Try to keep running.
std::cerr << t.what();
}
Shell::Pointer Window::DefaultModalParent::GetShell()
{
Shell::Pointer parent = Tweaklets::Get(GuiWidgetsTweaklet::KEY)->GetActiveShell();
// Make sure we don't pick a parent that has a modal child (this can lock the app)
if (parent == 0)
{
// If this is a top-level window, then there must not be any open modal windows.
parent = Window::GetModalChild(Tweaklets::Get(GuiWidgetsTweaklet::KEY)->GetShells());
}
else
{
// If we picked a parent with a modal child, use the modal child instead
Shell::Pointer modalChild = Window::GetModalChild(parent->GetShells());
if (modalChild != 0)
{
parent = modalChild;
}
}
return parent;
}
Shell::Pointer Window::GetModalChild(const std::vector& toSearch)
{
int modal = Constants::APPLICATION_MODAL | Constants::SYSTEM_MODAL | Constants::PRIMARY_MODAL;
size_t size = toSearch.size();
for (size_t i = size - 1; i < size; i--)
{
Shell::Pointer shell = toSearch[i];
// Check if this shell has a modal child
std::vector children = shell->GetShells();
Shell::Pointer modalChild = GetModalChild(children);
if (modalChild != 0)
{
return modalChild;
}
// If not, check if this shell is modal itself
if (shell->IsVisible() && (shell->GetStyle() & modal) != 0)
{
return shell;
}
}
return Shell::Pointer(0);
}
//void Window::RunEventLoop()
//{
//
// //Use the display provided by the shell if possible
// Display display;
// if (shell == null)
// {
// display = Display.getCurrent();
// }
// else
// {
// display = loopShell.getDisplay();
// }
//
// while (loopShell != null && !loopShell.isDisposed())
// {
// try
// {
// if (!display.readAndDispatch())
// {
// display.sleep();
// }
// } catch (Throwable e)
// {
// exceptionHandler.handleException(e);
// }
// }
// display.update();
//}
Window::Window(Shell::Pointer parentShell)
{
this->parentShell = new SameShellProvider(parentShell);
this->Init();
}
Window::Window(IShellProvider::Pointer shellProvider)
{
poco_assert(shellProvider != 0);
this->parentShell = shellProvider;
this->Init();
}
void Window::Init()
{
this->shellStyle = Constants::SHELL_TRIM;
this->returnCode = OK;
this->block = false;
}
bool Window::CanHandleShellCloseEvent()
{
return true;
}
void Window::ConfigureShell(Shell::Pointer newShell)
{
// The single image version of this code had a comment related to bug
// 46624,
// and some code that did nothing if the stored image was already
// disposed.
// The equivalent in the multi-image version seems to be to remove the
// disposed images from the array passed to the shell.
if (defaultImages.size() > 0)
{
// ArrayList nonDisposedImages = new ArrayList(defaultImages.length);
// for (int i = 0; i < defaultImages.length; ++i)
// {
// if (defaultImages[i] != null && !defaultImages[i].isDisposed())
// {
// nonDisposedImages.add(defaultImages[i]);
// }
// }
//
// if (nonDisposedImages.size() <= 0)
// {
// System.err.println("Window.configureShell: images disposed"); //$NON-NLS-1$
// }
// else
// {
// //Image[] array = new Image[nonDisposedImages.size()];
// nonDisposedImages.toArray(array);
newShell->SetImages(defaultImages);
// }
}
// Layout layout = getLayout();
// if (layout != null)
// {
// newShell.setLayout(layout);
// }
}
//voidWindow::ConstrainShellSize()
//{
// // limit the shell size to the display size
// Rectangle bounds = shell.getBounds();
// Rectangle constrained = getConstrainedShellBounds(bounds);
// if (!bounds.equals(constrained))
// {
// shell.setBounds(constrained);
// }
//}
void* Window::CreateContents(Shell::Pointer parent)
{
// by default, just create a composite
//return new Composite(parent, SWT.NONE);
return parent->GetControl();
}
Shell::Pointer Window::CreateShell()
{
Shell::Pointer newParent = this->GetParentShell();
// if (newParent != 0 && newParent.isDisposed())
// {
// parentShell = new SameShellProvider(null);
// newParent = getParentShell();//Find a better parent
// }
//Create the shell
Shell::Pointer newShell = Tweaklets::Get(GuiWidgetsTweaklet::KEY)->CreateShell(newParent, this->GetShellStyle());
// resizeListener = new Listener() {
// public void handleEvent(Event e) {
// resizeHasOccurred = true;
// }
// };
//newShell.addListener(SWT.Resize, resizeListener);
newShell->SetData(Object::Pointer(this));
//Add a listener
newShell->AddShellListener(this->GetShellListener());
//Set the layout
this->ConfigureShell(newShell);
// //Register for font changes
// if (fontChangeListener == null)
// {
// fontChangeListener = new FontChangeListener();
// }
// JFaceResources.getFontRegistry().addListener(fontChangeListener);
return newShell;
}
void* Window::GetContents()
{
return contents;
}
Point Window::GetInitialLocation(const Point& initialSize)
{
void* parent = Tweaklets::Get(GuiWidgetsTweaklet::KEY)->GetParent(shell->GetControl());
Point centerPoint(0,0);
Rectangle parentBounds(0,0,0,0);
if (parent != 0)
{
parentBounds = Tweaklets::Get(GuiWidgetsTweaklet::KEY)->GetBounds(parent);
centerPoint.x = parentBounds.x + parentBounds.width/2;
centerPoint.y = parentBounds.y - parentBounds.height/2;
}
else
{
parentBounds = Tweaklets::Get(GuiWidgetsTweaklet::KEY)
->GetScreenSize(Tweaklets::Get(GuiWidgetsTweaklet::KEY)->GetPrimaryScreenNumber());
centerPoint.x = parentBounds.width/2;
centerPoint.y = parentBounds.height/2;
}
return Point(centerPoint.x - (initialSize.x / 2),
std::max(parentBounds.y,
std::min(centerPoint.y - (initialSize.y * 2 / 3),
parentBounds.y + parentBounds.height - initialSize.y)));
}
Point Window::GetInitialSize()
{
return shell->ComputeSize(Constants::DEFAULT, Constants::DEFAULT, true);
}
Shell::Pointer Window::GetParentShell()
{
Shell::Pointer parent = parentShell->GetShell();
int modal = Constants::APPLICATION_MODAL | Constants::SYSTEM_MODAL | Constants::PRIMARY_MODAL;
if ((this->GetShellStyle() & modal) != 0)
{
// If this is a modal shell with no parent, pick a shell using defaultModalParent.
if (parent == 0)
{
parent = defaultModalParent->GetShell();
}
}
return parent;
}
IShellListener::Pointer Window::GetShellListener()
{
if (windowShellListener == 0)
windowShellListener = new WindowShellListener(this);
return windowShellListener;
}
int Window::GetShellStyle()
{
return shellStyle;
}
void Window::HandleShellCloseEvent()
{
this->SetReturnCode(CANCEL);
this->Close();
}
void Window::InitializeBounds()
{
// if (resizeListener != null)
// {
// shell.removeListener(SWT.Resize, resizeListener);
// }
// if (resizeHasOccurred)
// { // Check if shell size has been set already.
// return;
// }
Point size = this->GetInitialSize();
Point location = this->GetInitialLocation(size);
shell->SetBounds(this->GetConstrainedShellBounds(Rectangle(location.x, location.y, size.x, size.y)));
}
Rectangle Window::GetConstrainedShellBounds(const Rectangle& preferredSize)
{
Rectangle result(preferredSize);
- GuiWidgetsTweaklet::Pointer guiTweaklet(Tweaklets::Get(GuiWidgetsTweaklet::KEY));
+ GuiWidgetsTweaklet* guiTweaklet(Tweaklets::Get(GuiWidgetsTweaklet::KEY));
int screenNum = guiTweaklet->GetClosestScreenNumber(result);
Rectangle bounds(guiTweaklet->GetAvailableScreenSize(screenNum));
if (result.height > bounds.height) {
result.height = bounds.height;
}
if (result.width > bounds.width) {
result.width = bounds.width;
}
result.x = std::max(bounds.x, std::min(result.x, bounds.x
+ bounds.width - result.width));
result.y = std::max(bounds.y, std::min(result.y, bounds.y
+ bounds.height - result.height));
return result;
}
void Window::SetParentShell(Shell::Pointer newParentShell)
{
poco_assert(shell == 0); // "There must not be an existing shell."; //$NON-NLS-1$
parentShell = new SameShellProvider(newParentShell);
}
void Window::SetReturnCode(int code)
{
returnCode = code;
}
void Window::SetShellStyle(int newShellStyle)
{
shellStyle = newShellStyle;
}
bool Window::Close()
{
BERRY_INFO << "Window::Close()";
// // stop listening for font changes
// if (fontChangeListener != null)
// {
// JFaceResources.getFontRegistry().removeListener(fontChangeListener);
// fontChangeListener = null;
// }
// remove this window from a window manager if it has one
if (windowManager != 0)
{
windowManager->Remove(Window::Pointer(this));
windowManager = 0;
}
if (shell == 0)
{
return true;
}
shell->RemoveShellListener(this->GetShellListener());
shell->SetData(Object::Pointer(0));
// If we "close" the shell recursion will occur.
// Instead, we need to "dispose" the shell to remove it from the
// display.
Tweaklets::Get(GuiWidgetsTweaklet::KEY)->DisposeShell(shell);
shell = 0;
contents = 0;
return true;
}
void Window::Create()
{
shell = this->CreateShell();
contents = this->CreateContents(shell);
//initialize the bounds of the shell to that appropriate for the
// contents
this->InitializeBounds();
}
void* Window::GetDefaultImage()
{
return (defaultImages.size() < 1) ? 0
: defaultImages[0];
}
std::vector Window::GetDefaultImages()
{
return defaultImages;
}
int Window::GetReturnCode()
{
return returnCode;
}
Shell::Pointer Window::GetShell()
{
return shell;
}
WindowManager* Window::GetWindowManager()
{
return windowManager;
}
int Window::Open()
{
if (shell == 0)
{
// create the window
this->Create();
}
// limit the shell size to the display size
//constrainShellSize();
// open the window
shell->Open(block);
// // run the event loop if specified
// if (block)
// {
// this->RunEventLoop();
// }
return returnCode;
}
void Window::SetBlockOnOpen(bool shouldBlock)
{
block = shouldBlock;
}
void Window::SetDefaultImage(void* image)
{
if (image != 0)
defaultImages.push_back(image);
}
void Window::SetDefaultImages(const std::vector& images)
{
defaultImages = images;
}
void Window::SetWindowManager(WindowManager* manager)
{
windowManager = manager;
// Code to detect invalid usage
if (manager != 0)
{
std::vector windows = manager->GetWindows();
for (unsigned int i = 0; i < windows.size(); i++)
{
if (windows[i] == this)
{
return;
}
}
manager->Add(Window::Pointer(this));
}
}
void Window::SetExceptionHandler(IExceptionHandler::Pointer handler)
{
if (exceptionHandler == 0)
{
exceptionHandler = handler;
}
}
void Window::SetDefaultModalParent(IShellProvider::Pointer provider)
{
defaultModalParent = provider;
}
}
diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/dialogs/berryMessageDialog.cpp b/BlueBerry/Bundles/org.blueberry.ui/src/dialogs/berryMessageDialog.cpp
index 94ce1d14da..2d8e08e7ae 100755
--- a/BlueBerry/Bundles/org.blueberry.ui/src/dialogs/berryMessageDialog.cpp
+++ b/BlueBerry/Bundles/org.blueberry.ui/src/dialogs/berryMessageDialog.cpp
@@ -1,67 +1,68 @@
/*=========================================================================
Program: BlueBerry Platform
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) German Cancer Research Center, Division of Medical and
Biological Informatics. All rights reserved.
See MITKCopyright.txt or http://www.mitk.org/copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
-#include "berryMessageDialog.h"
#include "../tweaklets/berryMessageDialogTweaklet.h"
+#include "berryMessageDialog.h"
+
namespace berry
{
bool MessageDialog::OpenConfirm(Shell::Pointer parent,
const std::string& title, const std::string& message)
{
return Tweaklets::Get(MessageDialogTweaklet::KEY)->OpenConfirm(parent, title,
message);
}
void MessageDialog::OpenError(Shell::Pointer parent, const std::string& title,
const std::string& message)
{
Tweaklets::Get(MessageDialogTweaklet::KEY)->OpenError(parent, title, message);
}
void MessageDialog::OpenInformation(Shell::Pointer parent,
const std::string& title, const std::string& message)
{
Tweaklets::Get(MessageDialogTweaklet::KEY)->OpenInformation(parent, title,
message);
}
bool MessageDialog::OpenQuestion(Shell::Pointer parent,
const std::string& title, const std::string& message)
{
return Tweaklets::Get(MessageDialogTweaklet::KEY)->OpenQuestion(parent, title,
message);
}
void MessageDialog::OpenWarning(Shell::Pointer parent,
const std::string& title, const std::string& message)
{
Tweaklets::Get(MessageDialogTweaklet::KEY)->OpenWarning(parent, title,
message);
}
IDialog::Pointer MessageDialog::CreateMessageDialog(Shell::Pointer parentShell, const std::string& dialogTitle,
void* dialogTitleImage, const std::string& dialogMessage, int dialogImageType,
const std::vector& dialogButtonLabels, int defaultIndex)
{
return Tweaklets::Get(MessageDialogTweaklet::KEY)->MessageDialog(parentShell, dialogTitle,
dialogTitleImage, dialogMessage, dialogImageType,
dialogButtonLabels, defaultIndex);
}
}
diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/handlers/berryShowViewHandler.cpp b/BlueBerry/Bundles/org.blueberry.ui/src/handlers/berryShowViewHandler.cpp
index f12109bb2e..78895a1045 100644
--- a/BlueBerry/Bundles/org.blueberry.ui/src/handlers/berryShowViewHandler.cpp
+++ b/BlueBerry/Bundles/org.blueberry.ui/src/handlers/berryShowViewHandler.cpp
@@ -1,118 +1,118 @@
/*=========================================================================
Program: BlueBerry Platform
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) German Cancer Research Center, Division of Medical and
Biological Informatics. All rights reserved.
See MITKCopyright.txt or http://www.mitk.org/copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "berryShowViewHandler.h"
#include "berryHandlerUtil.h"
+#include "../tweaklets/berryWorkbenchTweaklet.h"
+#include "../dialogs/berryIShowViewDialog.h"
+
#include "../berryUIException.h"
#include "../berryIWorkbenchPage.h"
#include "../berryIViewDescriptor.h"
#include "../berryPlatformUI.h"
-#include "../tweaklets/berryWorkbenchTweaklet.h"
-#include "../dialogs/berryIShowViewDialog.h"
-
#include
#include
namespace berry
{
const std::string ShowViewHandler::PARAMETER_NAME_VIEW_ID = "org.blueberry.ui.showView.viewId"; //$NON-NLS-1$
ShowViewHandler::ShowViewHandler()
{
}
Object::Pointer ShowViewHandler::Execute(
const ExecutionEvent::Pointer event)
{
IWorkbenchWindow::Pointer window = HandlerUtil::GetActiveWorkbenchWindowChecked(event);
// Get the view identifier, if any.
const ExecutionEvent::ParameterMap& parameters = event->GetParameters();
ExecutionEvent::ParameterMap::const_iterator result = parameters.find(PARAMETER_NAME_VIEW_ID);
std::string value;
if (result != parameters.end()) value = result->second;
if (value == "")
{
this->OpenOther(window);
}
else
{
try
{
this->OpenView(value, window);
}
catch (PartInitException e)
{
throw ExecutionException("Part could not be initialized", e); //$NON-NLS-1$
}
}
return Object::Pointer(0);
}
void ShowViewHandler::OpenOther(IWorkbenchWindow::Pointer window)
{
const IWorkbenchPage::Pointer page = window->GetActivePage();
if (page.IsNull())
{
return;
}
IShowViewDialog::Pointer dialog = Tweaklets::Get(WorkbenchTweaklet::KEY)->CreateStandardDialog(WorkbenchTweaklet::DIALOG_ID_SHOW_VIEW).Cast();
if (dialog.IsNull()) return;
int returnCode = dialog->Open();
if (returnCode == IDialog::CANCEL)
{
return;
}
const std::vector descriptors =
dialog->GetSelection();
for (unsigned int i = 0; i < descriptors.size(); ++i)
{
try
{
this->OpenView(descriptors[i]->GetId(), window);
}
catch (PartInitException e)
{
// StatusUtil.handleStatus(e.getStatus(),
// WorkbenchMessages.ShowView_errorTitle
// + ": " + e.getMessage(), //$NON-NLS-1$
// StatusManager.SHOW);
}
}
}
void ShowViewHandler::OpenView(const std::string& viewId, IWorkbenchWindow::Pointer activeWorkbenchWindow)
{
const IWorkbenchPage::Pointer activePage = activeWorkbenchWindow->GetActivePage();
if (activePage.IsNull())
{
return;
}
activePage->ShowView(viewId);
}
}
diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryEditorReference.cpp b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryEditorReference.cpp
index 898995a80f..7ba4582f03 100644
--- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryEditorReference.cpp
+++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryEditorReference.cpp
@@ -1,560 +1,561 @@
/*=========================================================================
Program: BlueBerry Platform
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) German Cancer Research Center, Division of Medical and
Biological Informatics. All rights reserved.
See MITKCopyright.txt or http://www.mitk.org/copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "berryEditorReference.h"
+#include "../tweaklets/berryWorkbenchPageTweaklet.h"
+
#include "berryEditorManager.h"
#include "berryEditorDescriptor.h"
#include "berryEditorRegistry.h"
#include "berryEditorSite.h"
#include "berryEditorAreaHelper.h"
#include "berryWorkbenchPlugin.h"
#include "berryWorkbenchPage.h"
#include "berryNullEditorInput.h"
#include "berryPartTester.h"
-#include "../tweaklets/berryWorkbenchPageTweaklet.h"
#include "../berryImageDescriptor.h"
#include "../berryPlatformUI.h"
namespace berry
{
EditorReference::EditorReference(EditorManager* man,
IEditorInput::Pointer input, EditorDescriptor::Pointer desc,
IMemento::Pointer editorState) :
manager(man), expectingInputChange(false),
reportedMalfunctioningEditor(false)
{
this->InitListenersAndHandlers();
restoredInput = input;
this->editorState = editorState;
this->Init(desc->GetId(), "", desc->GetImageDescriptor(),
desc->GetLabel(), "");
}
EditorReference::EditorReference(EditorManager* man, IMemento::Pointer memento) :
manager(man), expectingInputChange(false),
reportedMalfunctioningEditor(false)
{
this->InitListenersAndHandlers();
this->editorMemento = memento;
if (manager->UseIPersistableEditor())
{
//editorState = editorMemento->GetChild(WorkbenchConstants::TAG_EDITOR_STATE);
}
else
{
editorState = 0;
}
// String id = memento.getString(IWorkbenchConstants.TAG_ID);
// String title = memento.getString(IWorkbenchConstants.TAG_TITLE);
// String tooltip = Util.safeString(memento
// .getString(IWorkbenchConstants.TAG_TOOLTIP));
// String partName = memento
// .getString(IWorkbenchConstants.TAG_PART_NAME);
//
// IMemento propBag = memento.getChild(IWorkbenchConstants.TAG_PROPERTIES);
// if (propBag != null)
// {
// IMemento[] props = propBag
// .getChildren(IWorkbenchConstants.TAG_PROPERTY);
// for (int i = 0; i < props.length; i++)
// {
// propertyCache.put(props[i].getID(), props[i].getTextData());
// }
// }
// For compatibility set the part name to the title if not found
// if (partName.empty())
// {
// partName = title;
// }
// Get the editor descriptor.
// EditorDescriptor::Pointer desc;
// if (id != null)
// {
// desc = getDescriptor(id);
// }
// // desc may be null if id is null or desc is not found, but findImage below handles this
// String location = memento.getString(IWorkbenchConstants.TAG_PATH);
// IPath path = location == null ? null : new Path(location);
// ImageDescriptor iDesc = this.manager.findImage(desc, path);
//
// this.name = memento.getString(IWorkbenchConstants.TAG_NAME);
// if (this.name == null)
// {
// this.name = title;
// }
// setPinned("true".equals(memento.getString(IWorkbenchConstants.TAG_PINNED))); //$NON-NLS-1$
//
// IMemento inputMem = memento.getChild(IWorkbenchConstants.TAG_INPUT);
// if (inputMem != null)
// {
// this.factoryId = inputMem
// .getString(IWorkbenchConstants.TAG_FACTORY_ID);
// }
//
// init(id, title, tooltip, iDesc, partName, ""); //$NON-NLS-1$
}
EditorDescriptor::Pointer EditorReference::GetDescriptor()
{
return this->GetDescriptor(this->GetId());
}
EditorDescriptor::Pointer EditorReference::GetDescriptor(const std::string& id)
{
EditorDescriptor::Pointer desc;
IEditorRegistry* reg = WorkbenchPlugin::GetDefault()->GetEditorRegistry();
desc = reg->FindEditor(id).Cast ();
return desc;
}
void EditorReference::InitListenersAndHandlers()
{
// Create a property change listener to track the "close editors automatically"
// preference and show/remove the pin icon on editors
// Only 1 listener will be created in the EditorManager when necessary
//this->manager->CheckCreateEditorPropListener();
// Create a keyboard shortcut handler for pinning editors
// Only 1 handler will be created in the EditorManager when necessary
//this->manager->CheckCreatePinEditorShortcutKeyHandler();
}
PartPane::Pointer EditorReference::CreatePane()
{
PartPane::Pointer pane(
new PartPane(IWorkbenchPartReference::Pointer(this), this->manager->page));
return pane;
//return Tweaklets::Get(WorkbenchTweaklet::KEY)->CreateEditorPane(this,
// this->manager->page);
}
void EditorReference::PinStatusUpdated()
{
//firePropertyChange(IWorkbenchPart.PROP_TITLE);
}
std::string EditorReference::GetFactoryId()
{
// IEditorPart editor = getEditor(false);
// if (editor != null)
// {
// IPersistableElement persistable = editor.getEditorInput()
// .getPersistable();
// if (persistable != null)
// {
// return persistable.getFactoryId();
// }
// return null;
// }
// return factoryId;
return "";
}
std::string EditorReference::ComputePartName()
{
return WorkbenchPartReference::ComputePartName();
}
std::string EditorReference::GetName()
{
if (part.IsNotNull())
{
return this->GetEditor(false)->GetEditorInput()->GetName();
}
return name;
}
IEditorPart::Pointer EditorReference::GetEditor(bool restore)
{
return this->GetPart(restore).Cast ();
}
void EditorReference::SetName(const std::string& name)
{
this->name = name;
}
IMemento::Pointer EditorReference::GetMemento()
{
return editorMemento;
}
IWorkbenchPage::Pointer EditorReference::GetPage() const
{
return IWorkbenchPage::Pointer(this->manager->page);
}
IEditorInput::Pointer EditorReference::GetEditorInput()
{
IEditorPart::Pointer part = this->GetEditor(false);
if (part.IsNotNull())
{
return part->GetEditorInput();
}
return this->GetRestoredInput();
}
IEditorInput::Pointer EditorReference::GetRestoredInput()
{
if (restoredInput.IsNotNull())
{
return restoredInput;
}
// Get the input factory.
// IMemento::Pointer editorMem = this->GetMemento();
// if (editorMem == null)
// {
// throw new PartInitException(NLS.bind(WorkbenchMessages.EditorManager_no_persisted_state, getId(), getName()));
// }
// IMemento inputMem = editorMem
// .getChild(IWorkbenchConstants.TAG_INPUT);
// String factoryID = null;
// if (inputMem != null)
// {
// factoryID = inputMem
// .getString(IWorkbenchConstants.TAG_FACTORY_ID);
// }
// if (factoryID == null)
// {
// throw new PartInitException(NLS.bind(WorkbenchMessages.EditorManager_no_input_factory_ID, getId(), getName()));
// }
// IAdaptable input = null;
// String label = null; // debugging only
// if (UIStats.isDebugging(UIStats.CREATE_PART_INPUT))
// {
// label = getName() != null ? getName() : factoryID;
// }
// try
// {
// UIStats.start(UIStats.CREATE_PART_INPUT, label);
// IElementFactory factory = PlatformUI.getWorkbench()
// .getElementFactory(factoryID);
// if (factory == null)
// {
// throw new PartInitException(NLS.bind(WorkbenchMessages.EditorManager_bad_element_factory, new Object[]
// { factoryID, getId(), getName()}));
// }
//
// // Get the input element.
// input = factory.createElement(inputMem);
// if (input == null)
// {
// throw new PartInitException(NLS.bind(WorkbenchMessages.EditorManager_create_element_returned_null, new Object[]
// { factoryID, getId(), getName()}));
// }
// }finally
// {
// UIStats.end(UIStats.CREATE_PART_INPUT, input, label);
// }
// if (!(input instanceof IEditorInput))
// {
// throw new PartInitException(NLS.bind(WorkbenchMessages.EditorManager_wrong_createElement_result, new Object[]
// { factoryID, getId(), getName()}));
// }
// restoredInput = (IEditorInput) input;
return restoredInput;
}
IWorkbenchPart::Pointer EditorReference::CreatePart()
{
if (EditorRegistry::EMPTY_EDITOR_ID == this->GetId())
{
return this->GetEmptyEditor(this->GetDescriptor());
}
IWorkbenchPart::Pointer result;
// Try to restore the editor -- this does the real work of restoring the editor
//
try
{
result = this->CreatePartHelper().Cast ();
} catch (PartInitException e)
{
// If unable to create the part, create an error part instead
// and pass the error to the status handling facility
// IStatus originalStatus = exception.getStatus();
// IStatus logStatus = StatusUtil.newStatus(originalStatus,
// NLS.bind("Unable to create editor ID {0}: {1}", //$NON-NLS-1$
// getId(), originalStatus.getMessage()));
// IStatus displayStatus = StatusUtil.newStatus(originalStatus,
// NLS.bind(WorkbenchMessages.EditorManager_unableToCreateEditor,
// originalStatus.getMessage()));
WorkbenchPlugin::Log("Unable to create editor ID " + this->GetId() + ": "
+ e.displayText());
// Pass the error to the status handling facility
//StatusManager.getManager().handle(logStatus);
EditorDescriptor::Pointer descr = this->GetDescriptor();
std::string label = this->GetId();
if (descr.IsNotNull())
label = descr->GetLabel();
IEditorPart::Pointer part =
Tweaklets::Get(WorkbenchPageTweaklet::KEY)->CreateErrorEditorPart(label,
e.displayText());
if (part.IsNotNull())
{
IEditorInput::Pointer input;
try
{
input = this->GetEditorInput();
} catch (PartInitException e1)
{
input = new NullEditorInput(EditorReference::Pointer(this));
}
PartPane::Pointer pane = this->GetPane();
pane->CreateControl(
manager->page->GetEditorPresentation()->GetLayoutPart()->GetControl());
EditorSite::Pointer site(
new EditorSite(IEditorReference::Pointer(this), part, manager->page, descr));
//site.setActionBars(new EditorActionBars(manager.page, site.getWorkbenchWindow(), getId()));
part->Init(site, input);
try
{
part->CreatePartControl(pane->GetControl());
} catch (...)
{
//content.dispose();
//StatusUtil.handleStatus(e, StatusManager.SHOW
// | StatusManager.LOG);
WorkbenchPlugin::Log("Error creating editor");
return IWorkbenchPart::Pointer(0);
}
result = part.Cast ();
}
}
return result;
}
bool EditorReference::SetInput(IEditorInput::Pointer input)
{
if (part.IsNotNull())
{
if (part.Cast ().IsNotNull())
{
IReusableEditor::Pointer editor = part.Cast ();
expectingInputChange = true;
editor->SetInput(input);
// If the editor never fired a PROP_INPUT event, log the fact that we've discovered
// a buggy editor and fire the event for free. Firing the event for free isn't required
// and cannot be relied on (it only works if the input change was triggered by this
// method, and there are definitely other cases where events will still be lost),
// but older versions of the workbench did this so we fire it here in the spirit
// of playing nice.
if (expectingInputChange)
{
// Log the fact that this editor is broken
this->ReportMalfunction(
"Editor is not firing a PROP_INPUT event in response to IReusableEditor.setInput(...)"); //$NON-NLS-1$
// Fire the property for free (can't be relied on since there are other ways the input
// can change, but we do it here to be consistent with older versions of the workbench)
//firePropertyChange(IWorkbenchPartConstants.PROP_INPUT);
}
return editor->GetEditorInput() == input;
}
// Can't change the input if the editor already exists and isn't an IReusableEditor
return false;
}
// Changing the input is trivial and always succeeds if the editor doesn't exist yet
if (input != restoredInput)
{
restoredInput = input;
//firePropertyChange(IWorkbenchPartConstants.PROP_INPUT);
}
return true;
}
void EditorReference::ReportMalfunction(const std::string& string)
{
if (!reportedMalfunctioningEditor)
{
reportedMalfunctioningEditor = true;
std::string errorMessage = "Problem detected with part " + this->GetId(); //$NON-NLS-1$
if (part.IsNotNull())
{
errorMessage.append("(class = ").append(part->GetClassName()).append(
")"); //$NON-NLS-1$ //$NON-NLS-2$
}
errorMessage += ": " + string; //$NON-NLS-1$
//StatusManager.getManager().handle(StatusUtil.newStatus(getDescriptor().getPluginId(), errorMessage, null));
BERRY_ERROR << errorMessage << std::endl;
}
}
IEditorPart::Pointer EditorReference::CreatePartHelper()
{
EditorSite::Pointer site;
IEditorPart::Pointer part;
try
{
IEditorInput::Pointer editorInput = this->GetEditorInput();
// Get the editor descriptor.
std::string editorID = this->GetId();
EditorDescriptor::Pointer desc = this->GetDescriptor();
if (desc.IsNull())
{
throw PartInitException("No editor descriptor for id " + editorID);
}
if (desc->IsInternal())
{
// Create an editor instance.
part = manager->CreatePart(desc);
this->CreatePartProperties(part);
}
// else if (desc->GetId() == IEditorRegistry.SYSTEM_INPLACE_EDITOR_ID)
// {
//
// part = ComponentSupport.getSystemInPlaceEditor();
//
// if (part == null)
// {
// throw new PartInitException(WorkbenchMessages.EditorManager_no_in_place_support);
// }
// }
else
{
throw PartInitException("Invalid editor descriptor for id " + editorID);
}
// Create a pane for this part
PartPane::Pointer pane = this->GetPane();
pane->CreateControl(manager->page->GetEditorPresentation()->GetLayoutPart()->GetControl());
// Link everything up to the part reference (the part reference itself should not have
// been modified until this point)
site = manager->CreateSite(IEditorReference::Pointer(this), part, desc, editorInput);
// if there is saved state that's appropriate, pass it on
if (/*part instanceof IPersistableEditor &&*/editorState.IsNotNull())
{
//part->RestoreState(editorState);
}
// Remember the site and the action bars (now that we've created them, we'll need to dispose
// them if an exception occurs)
//actionBars = (EditorActionBars) site.getActionBars();
part->CreatePartControl(pane->GetControl());
// The editor should now be fully created. Exercise its public interface, and sanity-check
// it wherever possible. If it's going to throw exceptions or behave badly, it's much better
// that it does so now while we can still cancel creation of the part.
PartTester::TestEditor(part);
return part;
} catch (std::exception e)
{
throw PartInitException(e.what());
}
}
IEditorPart::Pointer EditorReference::GetEmptyEditor(
EditorDescriptor::Pointer descr)
{
IEditorPart::Pointer part =
Tweaklets::Get(WorkbenchPageTweaklet::KEY)->CreateErrorEditorPart("(Empty)", "");
IEditorInput::Pointer input;
try
{
input = this->GetEditorInput();
} catch (PartInitException e1)
{
input = new NullEditorInput(EditorReference::Pointer(this));
}
PartPane::Pointer pane = this->GetPane();
pane->CreateControl(
manager->page->GetEditorPresentation()->GetLayoutPart()->GetControl());
EditorSite::Pointer site(new EditorSite(IEditorReference::Pointer(this),
part, manager->page, descr));
//site.setActionBars(new EditorActionBars(manager.page, site.getWorkbenchWindow(), getId()));
part->Init(site, input);
try
{
part->CreatePartControl(pane->GetControl());
} catch (std::exception e)
{
//StatusManager.getManager().handle(
// StatusUtil.newStatus(WorkbenchPlugin.PI_WORKBENCH, e));
BERRY_ERROR << e.what() << std::endl;
return IEditorPart::Pointer(0);
}
this->part = part.Cast ();
// Add a dispose listener to the part. This dispose listener does nothing but log an exception
// if the part's widgets get disposed unexpectedly. The workbench part reference is the only
// object that should dispose this control, and it will remove the listener before it does so.
this->RefreshFromPart();
//this->ReleaseReferences();
if (this->GetPage().Cast ()->GetActiveEditorReference()
!= this)
{
//fireInternalPropertyChange(INTERNAL_PROPERTY_OPENED);
}
return part;
}
}
diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryErrorViewPart.h b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryErrorViewPart.h
index 6c04b873a3..a7b82385a6 100644
--- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryErrorViewPart.h
+++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryErrorViewPart.h
@@ -1,82 +1,83 @@
/*=========================================================================
Program: BlueBerry Platform
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) German Cancer Research Center, Division of Medical and
Biological Informatics. All rights reserved.
See MITKCopyright.txt or http://www.mitk.org/copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef BERRYERRORVIEWPART_H_
#define BERRYERRORVIEWPART_H_
-#include "../berryViewPart.h"
#include "../tweaklets/berryWorkbenchPageTweaklet.h"
+#include "../berryViewPart.h"
+
namespace berry {
/**
* This part is shown instead the views with errors.
*
* @since 3.3
*/
class ErrorViewPart : public ViewPart {
public:
berryObjectMacro(ErrorViewPart)
/**
* Creates instance of the class
*/
ErrorViewPart();
/**
* Creates instance of the class
*
* @param error the status
*/
ErrorViewPart(const std::string& title, const std::string& error);
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
*/
void CreatePartControl(void* parent);
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.part.ViewPart#setPartName(java.lang.String)
*/
void SetPartName(const std::string& newName);
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.part.WorkbenchPart#setFocus()
*/
void SetFocus();
private:
//IStatus error;
std::string title;
std::string error;
Object::Pointer statusPart;
};
}
#endif /* BERRYERRORVIEWPART_H_ */
diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryLayoutPart.cpp b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryLayoutPart.cpp
index 5c32e724ae..e8cfd72bb1 100644
--- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryLayoutPart.cpp
+++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryLayoutPart.cpp
@@ -1,338 +1,338 @@
/*=========================================================================
Program: BlueBerry Platform
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) German Cancer Research Center, Division of Medical and
Biological Informatics. All rights reserved.
See MITKCopyright.txt or http://www.mitk.org/copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#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;
}
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::Pointer guiTweaklet = Tweaklets::Get(GuiWidgetsTweaklet::KEY);
+ 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::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/berryPartPane.cpp b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartPane.cpp
index 23db3ffd52..8fb22a4a87 100644
--- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartPane.cpp
+++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartPane.cpp
@@ -1,467 +1,467 @@
/*=========================================================================
Program: BlueBerry Platform
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) German Cancer Research Center, Division of Medical and
Biological Informatics. All rights reserved.
See MITKCopyright.txt or http://www.mitk.org/copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#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"
-#include "../tweaklets/berryGuiWidgetsTweaklet.h"
-#include "../tweaklets/berryWorkbenchPageTweaklet.h"
-
namespace berry
{
PartPane::Sashes::Sashes() :
left(0), right(0), top(0), bottom(0)
{
}
PartPane::PartPane(IWorkbenchPartReference::Pointer partReference,
WorkbenchPage* workbenchPage)
: StackablePart(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();
if (container == 0) {
return result;
}
container->FindSashes(result);
return result;
}
WorkbenchPage::Pointer PartPane::GetPage()
{
return WorkbenchPage::Pointer(page);
}
void PartPane::SetContainer(IStackableContainer::Pointer container)
{
if (hasFocus)
{
IStackableContainer::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);
}
void PartPane::Reparent(void* newParent)
{
void* control = this->GetControl();
- GuiWidgetsTweaklet::Pointer guiTweaklet = Tweaklets::Get(GuiWidgetsTweaklet::KEY);
+ 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();
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/berryPartStack.cpp b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartStack.cpp
index bb86eaee8a..bb1dd25b63 100644
--- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartStack.cpp
+++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPartStack.cpp
@@ -1,1608 +1,1608 @@
/*=========================================================================
Program: BlueBerry Platform
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) German Cancer Research Center, Division of Medical and
Biological Informatics. All rights reserved.
See MITKCopyright.txt or http://www.mitk.org/copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#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)
{
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;
// 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();
// 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;
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)
{
this->Add(child, Object::Pointer(0));
}
void PartStack::Add(StackablePart::Pointer newChild, Object::Pointer cookie)
{
children.push_back(newChild);
// Fix for bug 78470:
if(newChild->GetContainer().Cast() == 0)
{
newChild->SetContainer(IStackableContainer::Pointer(this));
}
this->ShowPart(newChild, cookie);
}
bool PartStack::AllowsAdd(StackablePart::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));
}
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)
{
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
{
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)
{
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()
{
return current;
}
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)
{
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));
}
if (child == requestedCurrent)
{
this->UpdateContainerVisibleTab();
}
}
void PartStack::Reparent(void* newParent)
{
void* control = this->GetControl();
- GuiWidgetsTweaklet::Pointer tweaklet = Tweaklets::Get(GuiWidgetsTweaklet::KEY);
+ 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)
{
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));
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());
}
// 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;
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());
}
}
// 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)
{
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::Pointer tweaklet = Tweaklets::Get(GuiWidgetsTweaklet::KEY);
+ 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)
{
if (this->GetPresentation() == 0)
{
return;
}
if (part->IsPlaceHolder())
{
part->SetContainer(IStackableContainer::Pointer(this));
return;
}
if (part.Cast() == 0)
{
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));
// 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));
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)
{
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*/)
{
}
}
diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPerspective.cpp b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPerspective.cpp
index f8dff83130..9f12ed0d71 100644
--- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPerspective.cpp
+++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPerspective.cpp
@@ -1,1765 +1,1765 @@
/*=========================================================================
Program: BlueBerry Platform
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) German Cancer Research Center, Division of Medical and
Biological Informatics. All rights reserved.
See MITKCopyright.txt or http://www.mitk.org/copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
+#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 "../tweaklets/berryGuiWidgetsTweaklet.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());
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);
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().Cast());
}
}
// // 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/berryPerspectiveHelper.cpp b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPerspectiveHelper.cpp
index 1d7d96b4f6..65115057d9 100755
--- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPerspectiveHelper.cpp
+++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPerspectiveHelper.cpp
@@ -1,1673 +1,1674 @@
/*=========================================================================
Program: BlueBerry Platform
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) German Cancer Research Center, Division of Medical and
Biological Informatics. All rights reserved.
See MITKCopyright.txt or http://www.mitk.org/copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
+#include "../tweaklets/berryGuiWidgetsTweaklet.h"
+
#include "berryPerspectiveHelper.h"
-#include "../tweaklets/berryGuiWidgetsTweaklet.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();
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)
{
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)
{
// Look for a placeholder.
PartPlaceholder::Pointer placeholder;
StackablePart::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)
{
IStackableContainer::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();
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();
iter != otherChildren.end(); ++iter)
{
part->GetContainer()->Add(*iter);
}
}
else
{
// show parent if necessary
if (container.Cast () != 0)
{
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));
}
// 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());
// }
// see if we should replace the placeholder
if (placeholder->HasWildCard())
{
// if (container instanceof PartSashContainer)
// {
// ((PartSashContainer) container) .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)
{
IStackableContainer::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;
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();
if (container.Cast () != 0)
{
return false;
}
if (container.Cast () != 0)
{
PartStack::Pointer folder = container.Cast();
StackablePart::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);
if (part == 0)
{
return false;
}
IStackableContainer::Pointer container = part->GetContainer();
if (container != 0 && container.Cast () != 0)
{
container
= container.Cast()->GetRealContainer();
}
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 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();
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::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)
{
// 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());
result.insert(result.end(), newParts.begin(), newParts.end());
}
else if (part.Cast () != 0)
{
result.push_back(part.Cast());
}
}
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());
}
}
}
}
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)
{
std::list