* Note that each page has its own views; views are never shared between
* pages.
*
*
* @return a list of visible views
*
* @deprecated use #getViewReferences() instead.
*/
virtual std::vector GetViews() = 0;
/**
* Returns the workbench window of this page.
*
* @return the workbench window
*/
virtual IWorkbenchWindow::Pointer GetWorkbenchWindow() = 0;
/**
* Hides the given view. The view must belong to this page.
*
* @param view
* the view to hide
*/
virtual void HideView(IViewPart::Pointer view) = 0;
/**
* Hides the given view that belongs to the reference, if any.
*
* @param view
* the references whos view is to be hidden
* @since 3.0
*/
virtual void HideView(IViewReference::Pointer view) = 0;
/**
* Returns whether the specified part is visible.
*
* @param part
* the part to test
* @return boolean true
if part is visible
*/
virtual bool IsPartVisible(IWorkbenchPart::Pointer part) = 0;
/**
* Reuses the specified editor by setting its new input.
*
* @param editor
* the editor to be reused
* @param input
* the new input for the reusable editor
*/
- //virtual void ReuseEditor(IReusableEditor::Pointer editor, IEditorInput* input);
+ virtual void ReuseEditor(IReusableEditor::Pointer editor, IEditorInput::Pointer input) = 0;
/**
* Opens an editor on the given input.
*
* If this page already has an editor open on the target input that editor
* is activated; otherwise, a new editor is opened. Two editor inputs,
* input1 and input2, are considered the same if
*
*
* input1.equals(input2) == true
*
.
*
*
* The editor type is determined by mapping editorId
to an
* editor extension registered with the workbench. An editor id is passed
* rather than an editor object to prevent the accidental creation of more
* than one editor for the same input. It also guarantees a consistent
* lifecycle for editors, regardless of whether they are created by the user
* or restored from saved data.
*
*
* @param input
* the editor input
* @param editorId
* the id of the editor extension to use
* @return an open and active editor, or null
if an external
* editor was opened
* @exception PartInitException
* if the editor could not be created or initialized
*/
virtual IEditorPart::Pointer OpenEditor(IEditorInput::Pointer input, const std::string& editorId) = 0;
/**
* Opens an editor on the given input.
*
* If this page already has an editor open on the target input that editor
* is brought to the front; otherwise, a new editor is opened. Two editor
* inputs are considered the same if they equal. See
* Object.equals(Object)
* and IEditorInput
. If activate == true
the editor
* will be activated.
*
* The editor type is determined by mapping editorId
to an editor
* extension registered with the workbench. An editor id is passed rather than
* an editor object to prevent the accidental creation of more than one editor
* for the same input. It also guarantees a consistent lifecycle for editors,
* regardless of whether they are created by the user or restored from saved
* data.
*
*
* @param input the editor input
* @param editorId the id of the editor extension to use
* @param activate if true
the editor will be activated
* @return an open editor, or null
if an external editor was opened
* @exception PartInitException if the editor could not be created or initialized
*/
virtual IEditorPart::Pointer OpenEditor(IEditorInput::Pointer input, const std::string& editorId,
bool activate) = 0;
/**
* Opens an editor on the given input.
*
* If this page already has an editor open that matches the given input
* and/or editor id (as specified by the matchFlags argument), that editor
* is brought to the front; otherwise, a new editor is opened. Two editor
* inputs are considered the same if they equal. See
* Object.equals(Object)
* and IEditorInput
. If activate == true
the editor
* will be activated.
*
* The editor type is determined by mapping editorId
to an editor
* extension registered with the workbench. An editor id is passed rather than
* an editor object to prevent the accidental creation of more than one editor
* for the same input. It also guarantees a consistent lifecycle for editors,
* regardless of whether they are created by the user or restored from saved
* data.
*
*
* @param input the editor input
* @param editorId the id of the editor extension to use
* @param activate if true
the editor will be activated
* @param matchFlags a bit mask consisting of zero or more of the MATCH_* constants OR-ed together
* @return an open editor, or null
if an external editor was opened
* @exception PartInitException if the editor could not be created or initialized
*
* @see #MATCH_NONE
* @see #MATCH_INPUT
* @see #MATCH_ID
* @since 3.2
*/
virtual IEditorPart::Pointer OpenEditor(IEditorInput::Pointer input,
const std::string& editorId, bool activate, int matchFlags) = 0;
/**
* Removes the property change listener.
*
* @param listener
* the property change listener to remove
* @since 2.0
*/
//virtual void removePropertyChangeListener(IPropertyChangeListener listener);
/**
* Changes the visible views, their layout, and the visible action sets
* within the page to match the current perspective descriptor. This is a
* rearrangement of components and not a replacement. The contents of the
* current perspective descriptor are unaffected.
*
* For more information on perspective change see
* setPerspective()
.
*
*/
virtual void ResetPerspective() = 0;
/**
* Saves the contents of all dirty editors belonging to this workbench page.
* If there are no dirty editors this method returns without effect.
*
* If confirm
is true
the user is prompted to
* confirm the command.
*
*
* Note that as of 3.2, this method also saves views that implement
* ISaveablePart and are dirty.
*
*
* @param confirm true
to ask the user before saving unsaved
* changes (recommended), and false
to save
* unsaved changes without asking
* @return true
if the command succeeded, and
* false
if the operation was canceled by the user or
* an error occurred while saving
*/
virtual bool SaveAllEditors(bool confirm) = 0;
/**
* Saves the contents of the given editor if dirty. If not, this method
* returns without effect.
*
* If confirm
is true
the user is prompted to
* confirm the command. Otherwise, the save happens without prompt.
*
*
* The editor must belong to this workbench page.
*
*
* @param editor
* the editor to close
* @param confirm
* true
to ask the user before saving unsaved
* changes (recommended), and false
to save
* unsaved changes without asking
* @return true
if the command succeeded, and
* false
if the editor was not saved
*/
virtual bool SaveEditor(IEditorPart::Pointer editor, bool confirm) = 0;
/**
* Saves the visible views, their layout, and the visible action sets for
* this page to the current perspective descriptor. The contents of the
* current perspective descriptor are overwritten.
*/
virtual void SavePerspective() = 0;
/**
* Saves the visible views, their layout, and the visible action sets for
* this page to the given perspective descriptor. The contents of the given
* perspective descriptor are overwritten and it is made the current one for
* this page.
*
* @param perspective
* the perspective descriptor to save to
*/
virtual void SavePerspectiveAs(IPerspectiveDescriptor::Pointer perspective) = 0;
/**
* Changes the visible views, their layout, and the visible action sets
* within the page to match the given perspective descriptor. This is a
* rearrangement of components and not a replacement. The contents of the
* old perspective descriptor are unaffected.
*
* When a perspective change occurs the old perspective is deactivated
* (hidden) and cached for future reference. Then the new perspective is
* activated (shown). The views within the page are shared by all existing
* perspectives to make it easy for the user to switch between one
* perspective and another quickly without loss of context.
*
*
* During activation the action sets are modified. If an action set is
* specified in the new perspective which is not visible in the old one it
* will be created. If an old action set is not specified in the new
* perspective it will be disposed.
*
*
* The visible views and their layout within the page also change. If a view
* is specified in the new perspective which is not visible in the old one a
* new instance of the view will be created. If an old view is not specified
* in the new perspective it will be hidden. This view may reappear if the
* user selects it from the View menu or if they switch to a perspective
* (which may be the old one) where the view is visible.
*
*
* The open editors are not modified by this method.
*
*
* @param perspective
* the perspective descriptor
*/
virtual void SetPerspective(IPerspectiveDescriptor::Pointer perspective) = 0;
/**
* Shows the view identified by the given view id in this page and gives it
* focus. If there is a view identified by the given view id (and with no
* secondary id) already open in this page, it is given focus.
*
* @param viewId
* the id of the view extension to use
* @return the shown view
* @exception PartInitException
* if the view could not be initialized
*/
virtual IViewPart::Pointer ShowView(const std::string& viewId) = 0;
/**
* Shows a view in this page with the given id and secondary id. The
* behaviour of this method varies based on the supplied mode. If
* VIEW_ACTIVATE
is supplied, the view is focus. If
* VIEW_VISIBLE
is supplied, then it is made visible but not
* given focus. Finally, if VIEW_CREATE
is supplied the view
* is created and will only be made visible if it is not created in a folder
* that already contains visible views.
*
* This allows multiple instances of a particular view to be created. They
* are disambiguated using the secondary id. If a secondary id is given, the
* view must allow multiple instances by having specified
* allowMultiple="true" in its extension.
*
*
* @param viewId
* the id of the view extension to use
* @param secondaryId
* the secondary id to use, or null
for no
* secondary id
* @param mode
* the activation mode. Must be {@link #VIEW_ACTIVATE},
* {@link #VIEW_VISIBLE} or {@link #VIEW_CREATE}
* @return a view
* @exception PartInitException
* if the view could not be initialized
* @exception IllegalArgumentException
* if the supplied mode is not valid
* @since 3.0
*/
virtual IViewPart::Pointer ShowView(const std::string& viewId, const std::string& secondaryId, int mode) = 0;
/**
* Returns true
if the editor is pinned and should not be
* reused.
*
* @param editor
* the editor to test
* @return boolean whether the editor is pinned
*/
virtual bool IsEditorPinned(IEditorPart::Pointer editor) = 0;
/**
* Returns the perspective shortcuts associated with the current
* perspective. Returns an empty array if there is no current perspective.
*
* @see IPageLayout#addPerspectiveShortcut(String)
* @return an array of perspective identifiers
* @since 3.1
*/
virtual std::vector GetPerspectiveShortcuts() = 0;
/**
* Returns the show view shortcuts associated with the current perspective.
* Returns an empty array if there is no current perspective.
*
* @see IPageLayout#addShowViewShortcut(String)
* @return an array of view identifiers
* @since 3.1
*/
virtual std::vector GetShowViewShortcuts() = 0;
/**
* Returns the descriptors for the perspectives that are open in this page,
* in the order in which they were opened.
*
* @return the open perspective descriptors, in order of opening
* @since 3.1
*/
virtual std::vector GetOpenPerspectives() = 0;
/**
* Returns the descriptors for the perspectives that are open in this page,
* in the order in which they were activated (oldest first).
*
* @return the open perspective descriptors, in order of activation
* @since 3.1
*/
virtual std::vector GetSortedPerspectives() = 0;
/**
* Closes the specified perspective in this page. If the last perspective in
* this page is closed, then all editors are closed. Views that are not
* shown in other perspectives are closed as well. If saveParts
* is true
, the user will be prompted to save any unsaved
* changes for parts that are being closed. The page itself is closed if
* closePage
is true
.
*
* @param desc
* the descriptor of the perspective to be closed
* @param saveParts
* whether the page's parts should be saved if closed
* @param closePage
* whether the page itself should be closed if last perspective
* @since 3.1
*/
virtual void ClosePerspective(IPerspectiveDescriptor::Pointer desc,
bool saveParts, bool closePage) = 0;
/**
* Closes all perspectives in this page. All editors are closed, prompting
* to save any unsaved changes if saveEditors
is
* true
. The page itself is closed if closePage
* is true
.
*
* @param saveEditors
* whether the page's editors should be saved
* @param closePage
* whether the page itself should be closed
* @since 3.1
*/
virtual void CloseAllPerspectives(bool saveEditors, bool closePage) = 0;
/**
* Find the part reference for the given part. A convenience method to
* quickly go from part to part reference.
*
* @param part
* The part to search for. It can be null
.
* @return The reference for the given part, or null
if no
* reference can be found.
* @since 3.2
*/
virtual IWorkbenchPartReference::Pointer GetReference(IWorkbenchPart::Pointer part) = 0;
};
} // namespace berry
#endif /*BERRYIWORKBENCHPAGE_H_*/
diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryEditorManager.cpp b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryEditorManager.cpp
index b33aa62b06..63be5410dc 100644
--- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryEditorManager.cpp
+++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryEditorManager.cpp
@@ -1,1296 +1,1296 @@
/*=========================================================================
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 "berryEditorManager.h"
#include "../berryIWorkbenchPart.h"
#include "../berryIWorkbenchWindow.h"
#include "../berryIEditorRegistry.h"
#include "../berryUIException.h"
#include "berryWorkbenchWindow.h"
#include "berryWorkbenchPage.h"
#include "berryEditorSite.h"
#include "berryEditorReference.h"
#include "berryWorkbenchPlugin.h"
#include "berryWorkbenchConstants.h"
#include "berryNullEditorInput.h"
#include "berryEditorAreaHelper.h"
#include "berryPartStack.h"
#include
namespace berry
{
const std::string EditorManager::PIN_EDITOR_KEY = "PIN_EDITOR";
const std::string EditorManager::RESOURCES_TO_SAVE_MESSAGE = "Select resources to save:";
const std::string EditorManager::SAVE_RESOURCES_TITLE = "Save Resources";
EditorManager::EditorManager(WorkbenchWindow::Pointer wind,
WorkbenchPage::Pointer workbenchPage,
EditorAreaHelper* pres)
: editorPresentation(pres), window(wind.GetPointer()), page(workbenchPage.GetPointer()) {
poco_check_ptr(editorPresentation);
poco_assert(window != 0);
poco_assert(page != 0);
//page.getExtensionTracker().registerHandler(this, null);
}
void EditorManager::CheckDeleteEditorResources()
{
// // get the current number of editors
// IEditorReference[] editors = page.getEditorReferences();
// // If there are no editors
// if (editors.length == 0)
// {
// if (editorPropChangeListnener != null)
// {
// // remove property change listener for editors
// IPreferenceStore prefStore = WorkbenchPlugin.getDefault()
// .getPreferenceStore();
// prefStore
// .removePropertyChangeListener(editorPropChangeListnener);
// editorPropChangeListnener = null;
// }
// if (pinEditorHandlerActivation != null)
// {
// // remove pin editor keyboard shortcut handler
// final IHandlerService handlerService = (IHandlerService) window.getWorkbench().getService(IHandlerService.class);
// handlerService.deactivateHandler(pinEditorHandlerActivation);
// pinEditorHandlerActivation = null;
// }
// }
}
//void EditorManager::CheckCreateEditorPropListener()
//{
// if (editorPropChangeListnener == null)
// {
// // Add a property change listener for closing editors automatically
// // preference
// // Add or remove the pin icon accordingly
// editorPropChangeListnener = new IPropertyChangeListener()
// {
// public void propertyChange(PropertyChangeEvent event)
// {
// if (event.getProperty().equals(
// IPreferenceConstants.REUSE_EDITORS_BOOLEAN))
// {
// IEditorReference[] editors = getEditors();
// for (int i = 0; i < editors.length; i++)
// {
// ((EditorReference) editors[i]).pinStatusUpdated();
// }
// }
// }
// };
// WorkbenchPlugin.getDefault().getPreferenceStore()
// .addPropertyChangeListener(editorPropChangeListnener);
// }
//}
//void EditorManager::CheckCreatePinEditorShortcutKeyHandler()
//{
// if (pinEditorHandlerActivation == null)
// {
// final Shell shell = window.getShell();
// final IHandler pinEditorHandler = new AbstractHandler()
// {
// public final Object execute(final ExecutionEvent event)
// {
// // check if the "Close editors automatically" preference is
// // set
// IPreferenceStore store = WorkbenchPlugin.getDefault().getPreferenceStore();
// if (store
// .getBoolean(IPreferenceConstants.REUSE_EDITORS_BOOLEAN)
// || ((TabBehaviour)Tweaklets.get(TabBehaviour.KEY)).alwaysShowPinAction())
// {
//
// IWorkbenchPartReference ref = editorPresentation
// .getVisibleEditor();
// if (ref instanceof WorkbenchPartReference)
// {
// WorkbenchPartReference concreteRef = (WorkbenchPartReference) ref;
//
// concreteRef.setPinned(concreteRef.isPinned());
// }
// }
// return null;
// }
// };
//
// // Assign the handler for the pin editor keyboard shortcut.
// final IHandlerService handlerService = (IHandlerService) window.getWorkbench().getService(IHandlerService.class);
// pinEditorHandlerActivation = handlerService.activateHandler(
// "org.blueberry.ui.window.pinEditor", pinEditorHandler, //$NON-NLS-1$
// new ActiveShellExpression(shell));
// }
//}
std::vector EditorManager::CollectDirtyEditors()
{
std::vector result;
std::list editors(page->GetEditorReferences());
for (std::list::iterator i = editors.begin();
i != editors.end(); ++i)
{
IEditorPart::Pointer part = (*i)->GetPart(false).Cast();
if (part.IsNotNull() && part->IsDirty())
{
result.push_back(part);
}
}
return result;
}
bool EditorManager::ContainsEditor(IEditorReference::Pointer ref)
{
std::list editors(page->GetEditorReferences());
return std::find(editors.begin(), editors.end(), ref) != editors.end();
}
//EditorActionBars* EditorManager::CreateEditorActionBars(
// EditorDescriptor::Pointer desc, IEditorSite::Pointer site)
//{
// // Get the editor type.
// String type = desc.getId();
//
// // If an action bar already exists for this editor type return it.
// EditorActionBars actionBars = (EditorActionBars) actionCache.get(type);
// if (actionBars != null)
// {
// actionBars.addRef();
// return actionBars;
// }
//
// // Create a new action bar set.
// actionBars = new EditorActionBars(page, site.getWorkbenchWindow(), type);
// actionBars.addRef();
// actionCache.put(type, actionBars);
//
// // Read base contributor.
// IEditorActionBarContributor contr = desc.createActionBarContributor();
// if (contr != null)
// {
// actionBars.setEditorContributor(contr);
// contr.init(actionBars, page);
// }
//
// // Read action extensions.
// EditorActionBuilder builder = new EditorActionBuilder();
// contr = builder.readActionExtensions(desc);
// if (contr != null)
// {
// actionBars.setExtensionContributor(contr);
// contr.init(actionBars, page);
// }
//
// // Return action bars.
// return actionBars;
//}
//EditorActionBars* EditorManager::CreateEmptyEditorActionBars(
// IEditorSite::Pointer site)
//{
// // Get the editor type.
// String type = String.valueOf(System.currentTimeMillis());
//
// // Create a new action bar set.
// // Note: It is an empty set.
// EditorActionBars actionBars = new EditorActionBars(page, site.getWorkbenchWindow(), type);
// actionBars.addRef();
// actionCache.put(type, actionBars);
//
// // Return action bars.
// return actionBars;
//}
//void EditorManager::DisposeEditorActionBars(EditorActionBars* actionBars)
//{
// actionBars.removeRef();
// if (actionBars.getRef() <= 0)
// {
// String type = actionBars.getEditorType();
// actionCache.remove(type);
// // refresh the cool bar manager before disposing of a cool item
// ICoolBarManager2 coolBar = (ICoolBarManager2) window.getCoolBarManager2();
// if (coolBar != null)
// {
// coolBar.refresh();
// }
// actionBars.dispose();
// }
//}
IEditorPart::Pointer EditorManager::FindEditor(IEditorInput::Pointer input)
{
return this->FindEditor("", input, IWorkbenchPage::MATCH_INPUT);
}
IEditorPart::Pointer EditorManager::FindEditor(const std::string& editorId,
IEditorInput::Pointer input, int matchFlags)
{
std::vector refs(this->FindEditors(input, editorId, matchFlags));
if (refs.size() == 0)
{
return IEditorPart::Pointer();
}
return refs[0]->GetEditor(true);
}
std::vector EditorManager::FindEditors(
IEditorInput::Pointer input, const std::string& editorId, int matchFlags)
{
if (matchFlags == IWorkbenchPage::MATCH_NONE)
{
return std::vector();
}
std::vector result;
std::list othersList(page->GetEditorReferences());
if (!othersList.empty())
{
IEditorReference::Pointer active = page->GetActiveEditorReference();
if (active.IsNotNull())
{
othersList.remove(active);
std::list activeList;
activeList.push_back(active);
this->FindEditors(activeList, input, editorId, matchFlags, result);
}
this->FindEditors(othersList, input, editorId, matchFlags, result);
}
return result;
}
void EditorManager::FindEditors(
std::list& editorList,
IEditorInput::Pointer input, const std::string& editorId, int matchFlags,
std::vector& result)
{
if (matchFlags == IWorkbenchPage::MATCH_NONE)
{
return;
}
// Phase 0: Remove editors whose ids don't match (if matching by id)
if (((matchFlags & IWorkbenchPage::MATCH_ID) != 0) && !editorId.empty())
{
for (std::list::iterator i = editorList.begin();
i != editorList.end();)
{
if (editorId != (*i)->GetId())
{
i = editorList.erase(i);
continue;
}
++i;
}
}
// If not matching on editor input, just return the remaining editors.
// In practice, this case is never used.
if ((matchFlags & IWorkbenchPage::MATCH_INPUT) == 0)
{
- result.assign(editorList.begin(), editorList.end());
+ result.insert(result.end(), editorList.begin(), editorList.end());
return;
}
// Phase 1: check editors that have their own matching strategy
for (std::list::iterator i = editorList.begin();
i != editorList.end();)
{
EditorReference::Pointer editor = i->Cast();
IEditorDescriptor::Pointer desc = editor->GetDescriptor();
if (desc.IsNotNull())
{
IEditorMatchingStrategy::Pointer matchingStrategy = desc
->GetEditorMatchingStrategy();
if (matchingStrategy.IsNotNull())
{
i = editorList.erase(i); // We're handling this one here, so remove it
// from the list.
if (matchingStrategy->Matches(editor, input))
{
result.push_back(editor);
}
continue;
}
}
++i;
}
// Phase 2: check materialized editors (without their own matching
// strategy)
for (std::list::iterator i = editorList.begin();
i != editorList.end();)
{
EditorReference::Pointer editor = i->Cast();
IEditorPart::Pointer part = editor->GetPart(false).Cast();
if (part.IsNotNull())
{
i = editorList.erase(i); // We're handling this one here, so remove it from
// the list.
if (part->GetEditorInput().IsNotNull() && part->GetEditorInput() == input)
{
result.push_back(editor);
}
}
else ++i;
}
// Phase 3: check unmaterialized editors for input equality,
// delaying plug-in activation further by only restoring the editor
// input
// if the editor reference's factory id and name match.
// std::string name = input->GetName();
// IPersistableElement persistable = input.getPersistable();
// if (name == null || persistable == null)
// {
// return;
// }
// String id = persistable.getFactoryId();
// if (id == null)
// {
// return;
// }
// for (Iterator i = editorList.iterator(); i.hasNext();)
// {
// EditorReference editor = (EditorReference) i.next();
// if (name.equals(editor.getName()) && id.equals(editor.getFactoryId()))
// {
// IEditorInput restoredInput;
// try
// {
// restoredInput = editor.getEditorInput();
// if (Util.equals(restoredInput, input))
// {
// result.add(editor);
// }
// }
// catch (PartInitException e1)
// {
// WorkbenchPlugin.log(e1);
// }
// }
// }
}
std::size_t EditorManager::GetEditorCount()
{
return page->GetEditorReferences().size();
}
IEditorRegistry* EditorManager::GetEditorRegistry()
{
return WorkbenchPlugin::GetDefault()->GetEditorRegistry();
}
std::vector EditorManager::GetDirtyEditors()
{
return this->CollectDirtyEditors();
}
std::list EditorManager::GetEditors()
{
return page->GetEditorReferences();
}
IEditorPart::Pointer EditorManager::GetVisibleEditor()
{
IEditorReference::Pointer ref = editorPresentation->GetVisibleEditor();
if (ref.IsNull())
{
return IEditorPart::Pointer(0);
}
return ref->GetPart(true).Cast();
}
bool EditorManager::IsSaveAllNeeded()
{
std::list editors(page->GetEditorReferences());
for (std::list::iterator i = editors.begin();
i != editors.end(); ++i)
{
if ((*i)->IsDirty())
{
return true;
}
}
return false;
}
IEditorReference::Pointer EditorManager::FindReusableEditor(
EditorDescriptor::Pointer /*desc*/)
{
//return ((TabBehaviour)Tweaklets.get(TabBehaviour.KEY)).findReusableEditor(page);
return IEditorReference::Pointer(0);
}
IEditorReference::Pointer EditorManager::OpenEditor(
const std::string& editorId, IEditorInput::Pointer input, bool /*setVisible*/,
IMemento::Pointer editorState)
{
if (input.IsNull())
{
throw Poco::InvalidArgumentException();
}
IEditorRegistry* reg = this->GetEditorRegistry();
EditorDescriptor::Pointer desc = reg->FindEditor(editorId).Cast();
if (desc.IsNull())
{
throw PartInitException("Unable to open editor, unknown editor id", editorId);
}
return this->OpenEditorFromDescriptor(desc, input, editorState);
}
IEditorReference::Pointer EditorManager::OpenEditorFromDescriptor(
EditorDescriptor::Pointer desc, IEditorInput::Pointer input,
IMemento::Pointer editorState)
{
IEditorReference::Pointer result;
if (desc->IsInternal())
{
result = this->ReuseInternalEditor(desc, input);
if (result.IsNull())
{
result = new EditorReference(this, input, desc, editorState);
}
}
// else if (desc->GetId() == IEditorRegistry::SYSTEM_INPLACE_EDITOR_ID)
// {
// if (ComponentSupport.inPlaceEditorSupported())
// {
// result = new EditorReference(this, input, desc);
// }
// }
// else if (desc->GetId() == IEditorRegistry::SYSTEM_EXTERNAL_EDITOR_ID)
// {
// IPathEditorInput pathInput = getPathEditorInput(input);
// if (pathInput != null)
// {
// result = openSystemExternalEditor(pathInput.getPath());
// }
// else
// {
// throw new PartInitException(
// WorkbenchMessages.EditorManager_systemEditorError);
// }
// }
// else if (desc->IsOpenExternal())
// {
// result = openExternalEditor(desc, input);
// }
else
{
// this should never happen
throw PartInitException("Invalid editor descriptor for id", desc->GetId());
}
if (result.IsNotNull())
{
this->CreateEditorTab(result.Cast(), ""); //$NON-NLS-1$
}
// Workbench wb = (Workbench) window.getWorkbench();
// wb.getEditorHistory().add(input, desc);
return result;
}
//IEditorReference::Pointer EditorManager::OpenExternalEditor(
// EditorDescriptor::Pointer desc, IEditorInput::Pointer input)
//{
// final CoreException ex[] = new CoreException[1];
//
// final IPathEditorInput pathInput = getPathEditorInput(input);
// if (pathInput != null && pathInput.getPath() != null)
// {
// BusyIndicator.showWhile(getDisplay(), new Runnable()
// {
// public void run()
// {
// try
// {
// if (desc.getLauncher() != null)
// {
// // open using launcher
// Object launcher = WorkbenchPlugin.createExtension(
// desc.getConfigurationElement(), "launcher"); //$NON-NLS-1$
// ((IEditorLauncher) launcher).open(pathInput
// .getPath());
// }
// else
// {
// // open using command
// ExternalEditor oEditor = new ExternalEditor(
// pathInput.getPath(), desc);
// oEditor.open();
// }
// }
// catch (CoreException e)
// {
// ex[0] = e;
// }
// }
// }
// );
// }
// else
// {
// throw new PartInitException(NLS.bind(
// WorkbenchMessages.EditorManager_errorOpeningExternalEditor,
// desc.getFileName(), desc.getId()));
// }
//
// if (ex[0] != null)
// {
// throw new PartInitException(NLS.bind(
// WorkbenchMessages.EditorManager_errorOpeningExternalEditor,
// desc.getFileName(), desc.getId()), ex[0]);
// }
//
// // we do not have an editor part for external editors
// return null;
//}
void EditorManager::CreateEditorTab(EditorReference::Pointer ref, const std::string& workbookId)
{
editorPresentation->AddEditor(ref, workbookId);
}
EditorSite::Pointer EditorManager::CreateSite(IEditorReference::Pointer ref,
IEditorPart::Pointer part, EditorDescriptor::Pointer desc,
IEditorInput::Pointer input) const
{
EditorSite::Pointer site(new EditorSite(ref, part, page, desc));
if (desc.IsNotNull())
{
//site.setActionBars(createEditorActionBars(desc, site));
}
else
{
//site.setActionBars(createEmptyEditorActionBars(site));
}
const std::string label = part->GetPartName(); // debugging only
try
{
part->Init(site, input);
// Sanity-check the site
if (!(part->GetSite() == site) || !(part->GetEditorSite() == site))
{
throw PartInitException("Editor initialization failed: " + desc->GetId() + ". Site is incorrect.");
}
}
catch (PartInitException e)
{
throw e;
}
catch (std::exception e)
{
throw PartInitException("An exception was thrown during initialization", e.what());
}
return site;
}
IEditorReference::Pointer EditorManager::ReuseInternalEditor(
EditorDescriptor::Pointer /*desc*/, IEditorInput::Pointer /*input*/)
{
// poco_assert(desc.IsNotNull()); // "descriptor must not be null"); //$NON-NLS-1$
// poco_assert(input.IsNotNull()); // "input must not be null"); //$NON-NLS-1$
//
// IEditorReference::Pointer reusableEditorRef = this->FindReusableEditor(desc);
// if (reusableEditorRef.IsNotNull())
// {
// return this->ReuseInternalEditor(page, this, editorPresentation, desc, input,
// reusableEditorRef);
// }
return IEditorReference::Pointer(0);
}
IEditorPart::Pointer EditorManager::CreatePart(EditorDescriptor::Pointer desc) const
{
// try
// {
IEditorPart::Pointer result = desc->CreateEditor();
// IConfigurationElement element = desc.getConfigurationElement();
// if (element != null)
// {
// page.getExtensionTracker().registerObject(
// element.getDeclaringExtension(), result,
// IExtensionTracker.REF_WEAK);
// }
return result;
// }
// catch (CoreException e)
// {
// throw PartInitException(StatusUtil.newStatus(
// desc.getPluginID(),
// WorkbenchMessages.EditorManager_instantiationError, e));
// }
}
//IEditorReference::Pointer EditorManager::OpenSystemExternalEditor(
// Poco::Path location)
//{
// if (location == null)
// {
// throw new IllegalArgumentException();
// }
//
// final boolean result[] =
// { false};
// BusyIndicator.showWhile(getDisplay(), new Runnable()
// {
// public void run()
// {
// if (location != null)
// {
// result[0] = Program.launch(location.toOSString());
// }
// }
// }
// );
//
// if (!result[0])
// {
// throw new PartInitException(NLS.bind(
// WorkbenchMessages.EditorManager_unableToOpenExternalEditor,
// location));
// }
//
// // We do not have an editor part for external editors
// return null;
// }
// ImageDescriptor EditorManager::FindImage(EditorDescriptor::Pointer desc,
// Poco::Path path)
// {
// if (desc == null)
// {
// // @issue what should be the default image?
// return ImageDescriptor.getMissingImageDescriptor();
// }
//
// if (desc.isOpenExternal() && path != null)
// {
// return PlatformUI.getWorkbench().getEditorRegistry()
// .getImageDescriptor(path.toOSString());
// }
//
// return desc.getImageDescriptor();
// }
bool EditorManager::RestoreState(IMemento::Pointer memento)
{
// Restore the editor area workbooks layout/relationship
// MultiStatus result = new MultiStatus(PlatformUI.PLUGIN_ID,
// IStatus.OK,
// WorkbenchMessages.EditorManager_problemsRestoringEditors, null);
bool result = true;
std::string activeWorkbookID;
std::vector visibleEditors;
std::vector activeEditor;
IMemento::Pointer areaMem = memento->GetChild(WorkbenchConstants::TAG_AREA);
if (areaMem)
{
//result.add(editorPresentation.restoreState(areaMem));
editorPresentation->RestoreState(areaMem);
areaMem->GetString(WorkbenchConstants::TAG_ACTIVE_WORKBOOK, activeWorkbookID);
}
// Loop through the editors.
std::vector editorMems(memento->GetChildren(WorkbenchConstants::TAG_EDITOR));
for (std::size_t x = 0; x < editorMems.size(); x++)
{
// for dynamic UI - call restoreEditorState to replace code which is
// commented out
RestoreEditorState(editorMems[x], visibleEditors, activeEditor); //, result);
}
// restore the presentation
if (areaMem)
{
//result.add(editorPresentation.restorePresentationState(areaMem));
result &= editorPresentation->RestorePresentationState(areaMem);
}
try
{
// StartupThreading.runWithThrowable(new StartupRunnable()
// {
//
// public void runWithException() throws Throwable
// {
// Update each workbook with its visible editor.
for (std::size_t i = 0; i < visibleEditors.size(); i++)
{
SetVisibleEditor(visibleEditors[i], false);
}
// Update the active workbook
if (!activeWorkbookID.empty())
{
editorPresentation->SetActiveEditorWorkbookFromID(activeWorkbookID);
}
if (!activeEditor.empty() && activeEditor[0])
{
IWorkbenchPart::Pointer editor = activeEditor[0]->GetPart(true);
if (editor)
{
page->Activate(editor);
}
}
// }});
}
catch (...)
{
// The exception is already logged.
// result
// .add(new Status(
// IStatus.ERR,
// PlatformUI.PLUGIN_ID,
// 0,
// WorkbenchMessages.EditorManager_exceptionRestoringEditor,
// t));
result &= false;
}
return result;
}
bool EditorManager::SaveAll(bool confirm, bool closing,
bool addNonPartSources)
{
// Get the list of dirty editors and views. If it is
// empty just return.
std::vector parts(page->GetDirtyParts());
if (parts.empty())
{
return true;
}
std::vector wbParts;
for (std::vector::const_iterator i = parts.begin();
i != parts.end(); ++i)
{
if (IWorkbenchPart::Pointer part = i->Cast())
{
wbParts.push_back(part);
}
}
// If confirmation is required ..
return this->SaveAll(wbParts, confirm, closing, addNonPartSources, IWorkbenchWindow::Pointer(window));
}
bool EditorManager::SaveAll(
const std::vector& /*dirtyParts*/, bool /*confirm*/,
bool /*closing*/, bool /*addNonPartSources*/, SmartPointer /*window*/)
{
// // clone the input list
// dirtyParts = new ArrayList(dirtyParts);
// List modelsToSave;
// if (confirm) {
// boolean saveable2Processed = false;
// // Process all parts that implement ISaveablePart2.
// // These parts are removed from the list after saving
// // them. We then need to restore the workbench to
// // its previous state, for now this is just last
// // active perspective.
// // Note that the given parts may come from multiple
// // windows, pages and perspectives.
// ListIterator listIterator = dirtyParts.listIterator();
//
// WorkbenchPage currentPage = null;
// Perspective currentPageOriginalPerspective = null;
// while (listIterator.hasNext()) {
// IWorkbenchPart part = (IWorkbenchPart) listIterator.next();
// if (part instanceof ISaveablePart2) {
// WorkbenchPage page = (WorkbenchPage) part.getSite()
// .getPage();
// if (!Util.equals(currentPage, page)) {
// if (currentPage != null
// && currentPageOriginalPerspective != null) {
// if (!currentPageOriginalPerspective
// .equals(currentPage.getActivePerspective())) {
// currentPage
// .setPerspective(currentPageOriginalPerspective
// .getDesc());
// }
// }
// currentPage = page;
// currentPageOriginalPerspective = page
// .getActivePerspective();
// }
// if (confirm) {
// if (part instanceof IViewPart) {
// Perspective perspective = page
// .getFirstPerspectiveWithView((IViewPart) part);
// if (perspective != null) {
// page.setPerspective(perspective.getDesc());
// }
// }
// // show the window containing the page?
// IWorkbenchWindow partsWindow = page
// .getWorkbenchWindow();
// if (partsWindow != partsWindow.getWorkbench()
// .getActiveWorkbenchWindow()) {
// Shell shell = partsWindow.getShell();
// if (shell.getMinimized()) {
// shell.setMinimized(false);
// }
// shell.setActive();
// }
// page.bringToTop(part);
// }
// // try to save the part
// int choice = SaveableHelper.savePart((ISaveablePart2) part,
// page.getWorkbenchWindow(), confirm);
// if (choice == ISaveablePart2.CANCEL) {
// // If the user cancels, don't restore the previous
// // workbench state, as that will
// // be an unexpected switch from the current state.
// return false;
// } else if (choice != ISaveablePart2.DEFAULT) {
// saveable2Processed = true;
// listIterator.remove();
// }
// }
// }
//
// // try to restore the workbench to its previous state
// if (currentPage != null && currentPageOriginalPerspective != null) {
// if (!currentPageOriginalPerspective.equals(currentPage
// .getActivePerspective())) {
// currentPage.setPerspective(currentPageOriginalPerspective
// .getDesc());
// }
// }
//
// // if processing a ISaveablePart2 caused other parts to be
// // saved, remove them from the list presented to the user.
// if (saveable2Processed) {
// listIterator = dirtyParts.listIterator();
// while (listIterator.hasNext()) {
// ISaveablePart part = (ISaveablePart) listIterator.next();
// if (!part.isDirty()) {
// listIterator.remove();
// }
// }
// }
//
// modelsToSave = convertToSaveables(dirtyParts, closing, addNonPartSources);
//
// // If nothing to save, return.
// if (modelsToSave.isEmpty()) {
// return true;
// }
// boolean canceled = SaveableHelper.waitForBackgroundSaveJobs(modelsToSave);
// if (canceled) {
// return false;
// }
// // Use a simpler dialog if there's only one
// if (modelsToSave.size() == 1) {
// Saveable model = (Saveable) modelsToSave.get(0);
// String message = NLS.bind(WorkbenchMessages.EditorManager_saveChangesQuestion, model.getName());
// // Show a dialog.
// String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL };
// MessageDialog d = new MessageDialog(
// shellProvider.getShell(), WorkbenchMessages.Save_Resource,
// null, message, MessageDialog.QUESTION, buttons, 0);
//
// int choice = SaveableHelper.testGetAutomatedResponse();
// if (SaveableHelper.testGetAutomatedResponse() == SaveableHelper.USER_RESPONSE) {
// choice = d.open();
// }
//
// // Branch on the user choice.
// // The choice id is based on the order of button labels
// // above.
// switch (choice) {
// case ISaveablePart2.YES: // yes
// break;
// case ISaveablePart2.NO: // no
// return true;
// default:
// case ISaveablePart2.CANCEL: // cancel
// return false;
// }
// }
// else {
// ListSelectionDialog dlg = new ListSelectionDialog(
// shellProvider.getShell(), modelsToSave,
// new ArrayContentProvider(),
// new WorkbenchPartLabelProvider(), RESOURCES_TO_SAVE_MESSAGE);
// dlg.setInitialSelections(modelsToSave.toArray());
// dlg.setTitle(SAVE_RESOURCES_TITLE);
//
// // this "if" statement aids in testing.
// if (SaveableHelper.testGetAutomatedResponse()==SaveableHelper.USER_RESPONSE) {
// int result = dlg.open();
// //Just return false to prevent the operation continuing
// if (result == IDialogConstants.CANCEL_ID) {
// return false;
// }
//
// modelsToSave = Arrays.asList(dlg.getResult());
// }
// }
// }
// else {
// modelsToSave = convertToSaveables(dirtyParts, closing, addNonPartSources);
// }
//
// // If the editor list is empty return.
// if (modelsToSave.isEmpty()) {
// return true;
// }
//
// // Create save block.
// final List finalModels = modelsToSave;
// IRunnableWithProgress progressOp = new IRunnableWithProgress() {
// public void run(IProgressMonitor monitor) {
// IProgressMonitor monitorWrap = new EventLoopProgressMonitor(
// monitor);
// monitorWrap.beginTask("", finalModels.size()); //$NON-NLS-1$
// for (Iterator i = finalModels.iterator(); i.hasNext();) {
// Saveable model = (Saveable) i.next();
// // handle case where this model got saved as a result of saving another
// if (!model.isDirty()) {
// monitor.worked(1);
// continue;
// }
// SaveableHelper.doSaveModel(model, new SubProgressMonitor(monitorWrap, 1), shellProvider, closing || confirm);
// if (monitorWrap.isCanceled()) {
// break;
// }
// }
// monitorWrap.done();
// }
// };
//
// // Do the save.
// return SaveableHelper.runProgressMonitorOperation(
// WorkbenchMessages.Save_All, progressOp, runnableContext, shellProvider);
return true;
}
bool EditorManager::SavePart(ISaveablePart::Pointer /*saveable*/, IWorkbenchPart::Pointer /*part*/, bool /*confirm*/)
{
//TODO EditorManager save part (SaveableHelper)
//return SaveableHelper.savePart(saveable, part, window, confirm);
return true;
}
bool EditorManager::SaveState(const IMemento::Pointer memento)
{
// final MultiStatus result = new MultiStatus(PlatformUI.PLUGIN_ID,
// IStatus.OK,
// WorkbenchMessages.EditorManager_problemsSavingEditors, null);
bool result = true;
// Save the editor area workbooks layout/relationship
IMemento::Pointer editorAreaMem = memento->CreateChild(WorkbenchConstants::TAG_AREA);
//result.add(editorPresentation.saveState(editorAreaMem));
result &= editorPresentation->SaveState(editorAreaMem);
// Save the active workbook id
editorAreaMem->PutString(WorkbenchConstants::TAG_ACTIVE_WORKBOOK,
editorPresentation->GetActiveEditorWorkbookID());
// Get each workbook
std::list workbooks(editorPresentation->GetWorkbooks());
for (std::list::iterator iter = workbooks.begin();
iter != workbooks.end(); ++iter)
{
PartStack::Pointer workbook = *iter;
// Use the list of editors found in EditorStack; fix for 24091
std::list editorPanes(workbook->GetChildren());
for (std::list::iterator i = editorPanes.begin();
i != editorPanes.end(); ++i)
{
// Save each open editor.
EditorReference::Pointer editorReference = i->Cast()->GetPartReference().Cast();
IEditorPart::Pointer editor = editorReference->GetEditor(false);
if (!editor)
{
if (editorReference->GetMemento())
{
IMemento::Pointer editorMem = memento
->CreateChild(WorkbenchConstants::TAG_EDITOR);
editorMem->PutMemento(editorReference->GetMemento());
}
continue;
}
// for dynamic UI - add the next line to replace the subsequent
// code which is commented out
SaveEditorState(memento, editorReference); //, result);
}
}
return result;
}
bool EditorManager::SetVisibleEditor(IEditorReference::Pointer newEd,
bool setFocus)
{
return editorPresentation->SetVisibleEditor(newEd, setFocus);
}
IPathEditorInput::Pointer EditorManager::GetPathEditorInput(
IEditorInput::Pointer input)
{
if (input.Cast().IsNotNull())
{
return input.Cast();
}
// return (IPathEditorInput)
// Util.getAdapter(input, IPathEditorInput.class);
return IPathEditorInput::Pointer(0);
}
void EditorManager::RestoreEditorState(IMemento::Pointer /*editorMem*/,
std::vector& /*visibleEditors*/,
std::vector& /*activeEditor*/)
{
// MultiStatus result) {
//TODO Restore editor state
// String strFocus = editorMem.getString(IWorkbenchConstants.TAG_FOCUS);
// boolean visibleEditor = "true".equals(strFocus); //$NON-NLS-1$
// EditorReference::Pointer e = new EditorReference(this, editorMem);
//
// try
// {
// StartupThreading.runWithPartInitExceptions(new StartupRunnable ()
// {
//
// public void runWithException() throws Throwable
// {
// createEditorTab(e, workbookID);
// }});
//
// }
// catch (PartInitException ex)
// {
// result.add(ex.getStatus());
// }
//
// String strActivePart = editorMem
// .getString(IWorkbenchConstants.TAG_ACTIVE_PART);
// if ("true".equals(strActivePart))
// { //$NON-NLS-1$
// activeEditor[0] = e;
// }
//
// String strFocus = editorMem.getString(IWorkbenchConstants.TAG_FOCUS);
// boolean visibleEditor = "true".equals(strFocus); //$NON-NLS-1$
// if (visibleEditor)
// {
// visibleEditors.add(e);
// }
}
void EditorManager::SaveEditorState(IMemento::Pointer /*mem*/,
IEditorReference::Pointer /*ed*/)
{
//TODO Save editor state
// final EditorReference editorRef = (EditorReference) ed;
// final IEditorPart editor = ed.getEditor(false);
// final IMemento memento = mem;
// final MultiStatus result = res;
// if (!(editor.getEditorSite() instanceof EditorSite))
// {
// return;
// }
// final EditorSite site = (EditorSite) editor.getEditorSite();
// if (site.getPane() instanceof MultiEditorInnerPane)
// {
// return;
// }
//
// SafeRunner.run(new SafeRunnable()
// {
// public void run()
// {
// // Get the input.
// IEditorInput input = editor.getEditorInput();
// if (!input.exists())
// {
// return;
// }
// IPersistableElement persistable = input.getPersistable();
// if (persistable == null)
// {
// return;
// }
//
// // Save editor.
// IMemento editorMem = memento
// .createChild(IWorkbenchConstants.TAG_EDITOR);
// editorMem.putString(IWorkbenchConstants.TAG_TITLE, editorRef
// .getTitle());
// editorMem.putString(IWorkbenchConstants.TAG_NAME, editorRef
// .getName());
// editorMem.putString(IWorkbenchConstants.TAG_ID, editorRef
// .getId());
// editorMem.putString(IWorkbenchConstants.TAG_TOOLTIP, editorRef
// .getTitleToolTip());
//
// editorMem.putString(IWorkbenchConstants.TAG_PART_NAME,
// editorRef.getPartName());
//
// if (editor instanceof IWorkbenchPart3)
// {
// Map properties = ((IWorkbenchPart3) editor)
// .getPartProperties();
// if (!properties.isEmpty())
// {
// IMemento propBag = editorMem
// .createChild(IWorkbenchConstants.TAG_PROPERTIES);
// Iterator i = properties.entrySet().iterator();
// while (i.hasNext())
// {
// Map.Entry entry = (Map.Entry) i.next();
// IMemento p = propBag.createChild(
// IWorkbenchConstants.TAG_PROPERTY,
// (String) entry.getKey());
// p.putTextData((String) entry.getValue());
// }
// }
// }
//
// if (editorRef.isPinned())
// {
// editorMem.putString(IWorkbenchConstants.TAG_PINNED, "true"); //$NON-NLS-1$
// }
//
// EditorPane editorPane = (EditorPane) ((EditorSite) editor
// .getEditorSite()).getPane();
// editorMem.putString(IWorkbenchConstants.TAG_WORKBOOK,
// editorPane.getWorkbook().getID());
//
// if (editor == page.getActivePart())
// {
// editorMem.putString(IWorkbenchConstants.TAG_ACTIVE_PART,
// "true"); //$NON-NLS-1$
// }
//
// if (editorPane == editorPane.getWorkbook().getSelection())
// {
// editorMem.putString(IWorkbenchConstants.TAG_FOCUS, "true"); //$NON-NLS-1$
// }
//
// if (input instanceof IPathEditorInput)
// {
// IPath path = ((IPathEditorInput) input).getPath();
// if (path != null)
// {
// editorMem.putString(IWorkbenchConstants.TAG_PATH, path
// .toString());
// }
// }
//
// // Save input.
// IMemento inputMem = editorMem
// .createChild(IWorkbenchConstants.TAG_INPUT);
// inputMem.putString(IWorkbenchConstants.TAG_FACTORY_ID,
// persistable.getFactoryId());
// persistable.saveState(inputMem);
//
// // any editors that want to persist state
// if (editor instanceof IPersistableEditor)
// {
// IMemento editorState = editorMem
// .createChild(IWorkbenchConstants.TAG_EDITOR_STATE);
// ((IPersistableEditor) editor).saveState(editorState);
// }
// }
//
// public void handleException(Throwable e)
// {
// result
// .add(new Status(
// IStatus.ERR,
// PlatformUI.PLUGIN_ID,
// 0,
// NLS
// .bind(
// WorkbenchMessages.EditorManager_unableToSaveEditor,
// editorRef.getTitle()), e));
// }
// }
// );
}
IMemento::Pointer EditorManager::GetMemento(IEditorReference::Pointer e)
{
if (e.Cast().IsNotNull())
{
return e.Cast()->GetMemento();
}
return IMemento::Pointer(0);
}
IEditorReference::Pointer EditorManager::OpenEmptyTab()
{
IEditorInput::Pointer input(new NullEditorInput());
EditorDescriptor::Pointer desc = (dynamic_cast(this->GetEditorRegistry()))
->FindEditor(EditorRegistry::EMPTY_EDITOR_ID).Cast();
EditorReference::Pointer result(new EditorReference(this, input, desc));
try
{
this->CreateEditorTab(result, ""); //$NON-NLS-1$
return result;
}
catch (PartInitException e)
{
// StatusManager.getManager().handle(
// StatusUtil.newStatus(WorkbenchPlugin.PI_WORKBENCH, e));
BERRY_ERROR << e.displayText() << std::endl;
}
return IEditorReference::Pointer(0);
}
bool EditorManager::UseIPersistableEditor()
{
// IPreferenceStore store = WorkbenchPlugin.getDefault()
// .getPreferenceStore();
// return store.getBoolean(IPreferenceConstants.USE_IPERSISTABLE_EDITORS);
return false;
}
}
diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryEditorReference.cpp b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryEditorReference.cpp
index 7ba4582f03..e1f2804563 100644
--- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryEditorReference.cpp
+++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryEditorReference.cpp
@@ -1,561 +1,575 @@
/*=========================================================================
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 "../berryImageDescriptor.h"
#include "../berryPlatformUI.h"
+#include "../berryIWorkbenchPartConstants.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;
}
+void EditorReference::PropertyChanged(Object::Pointer source, int propId)
+{
+ // Detect badly behaved editors that don't fire PROP_INPUT events
+ // when they're supposed to. This branch is only needed to handle
+ // malfunctioning editors.
+ if (propId == IWorkbenchPartConstants::PROP_INPUT)
+ {
+ expectingInputChange = false;
+ }
+
+ WorkbenchPartReference::PropertyChanged(source, propId);
+}
+
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);
+ 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/berryEditorReference.h b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryEditorReference.h
index 4d117213e1..9ada64b0d8 100644
--- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryEditorReference.h
+++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryEditorReference.h
@@ -1,252 +1,243 @@
/*=========================================================================
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 BERRYEDITORREFERENCE_H_
#define BERRYEDITORREFERENCE_H_
#include "berryWorkbenchPartReference.h"
#include "../berryIEditorReference.h"
#include "../berryIEditorInput.h"
#include "../berryIMemento.h"
#include "../berryIWorkbenchPart.h"
#include "../berryIEditorPart.h"
namespace berry
{
class EditorManager;
class EditorDescriptor;
class PartPane;
struct IWorkbenchPage;
/**
* \ingroup org_blueberry_ui_internal
*
*/
class EditorReference : public WorkbenchPartReference, public IEditorReference
{
private:
const EditorManager* manager;
private:
IMemento::Pointer editorMemento;
private:
IMemento::Pointer editorState;
/**
* Flag that lets us detect malfunctioning editors that don't fire PROP_INPUT events.
* It is never needed for a correctly-functioning
*/
private:
bool expectingInputChange;
/**
* Flag that determines whether we've already reported that this editor is malfunctioning.
* This prevents us from spamming the event log if we repeatedly detect the same error in
* a particular editor. If we ever detect an editor is violating its public contract in
* a way we can recover from (such as a missing property change event), we report the error
* once and then silently ignore errors from the same editor.
*/
private:
bool reportedMalfunctioningEditor;
/**
* User-readable name of the editor's input
*/
std::string name;
std::string factoryId;
IEditorInput::Pointer restoredInput;
/**
* @param manager
* The editor manager for this reference
* @param input
* our input
* @param desc
* the descriptor from the declaration
* @param editorState
* propogate state from another editor. Can be null
.
*/
public:
berryObjectMacro(EditorReference)
EditorReference(EditorManager* manager, IEditorInput::Pointer input,
SmartPointer desc, IMemento::Pointer editorState = IMemento::Pointer(0));
/**
* Constructs a new editor reference for use by editors being restored from
* a memento.
*/
EditorReference(EditorManager* manager, IMemento::Pointer memento);
public:
SmartPointer GetDescriptor();
/**
* @since 3.1
*
* @param id the id
* @return the editor descriptor
*/
private:
SmartPointer GetDescriptor(const std::string& id);
/**
* Initializes the necessary editor listeners and handlers
*/
private:
void InitListenersAndHandlers();
protected:
SmartPointer CreatePane();
/**
* This method is called when there should be a change in the editor pin
* status (added or removed) so that it will ask its presentable part
* to fire a PROP_TITLE event in order for the presentation to request
* the new icon for this editor
*/
public:
void PinStatusUpdated();
public:
std::string GetFactoryId();
protected:
std::string ComputePartName();
public:
std::string GetName();
public:
IEditorPart::Pointer GetEditor(bool restore);
public:
void SetName(const std::string& name);
public:
IMemento::Pointer GetMemento();
public:
SmartPointer GetPage() const;
public:
IEditorInput::Pointer GetEditorInput();
private:
IEditorInput::Pointer GetRestoredInput();
/* (non-Javadoc)
* @see org.blueberry.ui.IWorkbenchPartReference#getTitleImage()
* This method will append a pin to the icon of the editor
* if the "automatically close editors" option in the
* preferences is enabled and the editor has been pinned.
*/
//public: ImageDescriptor computeImageDescriptor() {
// ImageDescriptor descriptor = super.computeImageDescriptor();
// if (!isPinned()) {
// return descriptor;
// }
//
// // Check if the pinned preference is set
// IPreferenceStore prefStore = WorkbenchPlugin.getDefault()
// .getPreferenceStore();
// boolean bUsePin = prefStore
// .getBoolean(IPreferenceConstants.REUSE_EDITORS_BOOLEAN)
// || ((TabBehaviour)Tweaklets.get(TabBehaviour.KEY)).alwaysShowPinAction();
//
// if (!bUsePin) {
// return descriptor;
// }
//
// ImageDescriptor pinDesc = this.manager.getEditorPinImageDesc();
// if (pinDesc == null) {
// return descriptor;
// }
//
// return new OverlayIcon(descriptor, pinDesc, new Point(16, 16));
// }
+protected:
+
/**
* Wrapper for restoring the editor. First, this delegates to busyRestoreEditorHelper
* to do the real work of restoring the view. If unable to restore the editor, this
* method tries to substitute an error part and return success.
*
* @return the created part
*/
-protected:
IWorkbenchPart::Pointer CreatePart();
- //protected: void PartPropertyChanged(Object source, int propId) {
- //
- // // Detect badly behaved editors that don't fire PROP_INPUT events
- // // when they're supposed to. This branch is only needed to handle
- // // malfunctioning editors.
- // if (propId == IWorkbenchPartConstants.PROP_INPUT) {
- // expectingInputChange = false;
- // }
- //
- // super.partPropertyChanged(source, propId);
- // }
+ void PropertyChanged(Object::Pointer source, int propId);
/**
* Attempts to set the input of the editor to the given input. Note that the input
* can't always be changed for an editor. Editors that don't implement IReusableEditor
* can't have their input changed once they've been materialized.
*
* @since 3.1
*
* @param input new input
* @return true iff the input was actually changed
*/
public:
bool SetInput(IEditorInput::Pointer input);
/**
* Reports a recoverable malfunction in the system log. A recoverable malfunction would be
* something like failure to fire an expected property change. Only the first malfunction is
* recorded to avoid spamming the system log with repeated failures in the same editor.
*
* @since 3.1
*
* @param string
*/
private:
void ReportMalfunction(const std::string& string);
private:
IEditorPart::Pointer CreatePartHelper();
/**
* Creates and returns an empty editor (ErrorEditorPart
).
*
* @param descr the editor descriptor
* @return the empty editor part or null
in case of an exception
*/
public:
IEditorPart::Pointer GetEmptyEditor(SmartPointer descr);
};
} // namespace berry
#endif /*BERRYEDITORREFERENCE_H_*/