void PartList::PartOpened(WorkbenchPartReference::Pointer ref) { poco_assert(ref.IsNotNull()); IWorkbenchPart::Pointer actualPart = ref->GetPart(false); // We're firing the event that says "the part was just created"... so // there better be a part there. poco_assert(actualPart.IsNotNull()); // Must be called after the part is inserted into the part list //poco_assert(this->Contains(ref)); // The active part must be opened before it is activated, so we should // never get an open event for a part that is already active. // (This either indicates that a redundant // open event was fired or that a closed part was somehow activated) poco_assert(activePartReference.Lock() != ref); // The active editor must be opened before it is activated, so we should // never get an open event for an editor that is already active. // (This either indicates that a redundant // open event was fired or that a closed editor was somehow activated) poco_assert((void*)activeEditorReference.Lock().GetPointer() != (void*)ref.GetPointer()); SaveablesList* modelManager = dynamic_cast<SaveablesList*>( actualPart->GetSite()->GetService<ISaveablesLifecycleListener>()); modelManager->PostOpen(actualPart); // Fire the "part opened" event this->FirePartOpened(ref); }
ISelectionProvider::Pointer PagePartSelectionTracker::GetSelectionProvider() { IWorkbenchPart::Pointer part = this->GetPart(); if (part.IsNotNull()) { return part->GetSite()->GetSelectionProvider(); } return ISelectionProvider::Pointer(nullptr); }
void PagePartSelectionTracker::SetPart(IWorkbenchPart::Pointer part, bool notify) { if (fPart.IsNotNull()) { // remove myself as a listener from the existing part ISelectionProvider::Pointer sp = fPart->GetSite()->GetSelectionProvider(); if (sp.IsNotNull()) { sp->RemoveSelectionChangedListener(selChangedListener.data()); if (sp.Cast<IPostSelectionProvider> ().IsNotNull()) { sp.Cast<IPostSelectionProvider> () ->RemovePostSelectionChangedListener( postSelectionListener.data()); } else { sp->RemoveSelectionChangedListener(postSelectionListener.data()); } } } fPart = part; ISelection::ConstPointer sel; if (part.IsNotNull()) { ISelectionProvider::Pointer sp = part->GetSite()->GetSelectionProvider(); if (sp.IsNotNull()) { sp->AddSelectionChangedListener(selChangedListener.data()); if (sp.Cast<IPostSelectionProvider> ().IsNotNull()) { sp.Cast<IPostSelectionProvider> () ->AddPostSelectionChangedListener( postSelectionListener.data()); } else { sp->AddSelectionChangedListener(postSelectionListener.data()); } if (notify) { // get the selection to send below sel = sp->GetSelection(); } } } if (notify) { this->FireSelection(part, sel); this->FirePostSelection(part, sel); } }
void PartList::PartClosed(WorkbenchPartReference::Pointer ref) { poco_assert(ref.IsNotNull()); IWorkbenchPart::Pointer actualPart = ref->GetPart(false); // Called before the part is disposed, so the part should still be // there. poco_assert(actualPart.IsNotNull()); // Must be called before the part is actually removed from the part list // poco_assert(this->Contains(ref)); // Not allowed to close the active part. The part must be deactivated // before it may be closed. poco_assert(activePartReference.Lock() != ref); // Not allowed to close the active editor. The editor must be // deactivated before it may be closed. if (ref.Cast<IEditorReference>()) { poco_assert(activeEditorReference.Lock() != ref.Cast<IEditorReference>()); } this->FirePartClosed(ref); }
void AbstractSelectionService::SetActivePart(IWorkbenchPart::Pointer newPart) { // Optimize. if (newPart == activePart) { return; } ISelectionProvider::Pointer selectionProvider; if (newPart.IsNotNull()) { selectionProvider = newPart->GetSite()->GetSelectionProvider(); if (selectionProvider.IsNull()) { newPart = nullptr; } } if (newPart == activePart) { return; } if (activePart.IsNotNull()) { if (activeProvider.IsNotNull()) { activeProvider->RemoveSelectionChangedListener(selListener.data()); if (activeProvider.Cast<IPostSelectionProvider>().IsNotNull()) { activeProvider.Cast<IPostSelectionProvider>() ->RemovePostSelectionChangedListener(postSelListener.data()); } else { activeProvider ->RemoveSelectionChangedListener(postSelListener.data()); } activeProvider = nullptr; } activePart = nullptr; } activePart = newPart; if (newPart.IsNotNull()) { activeProvider = selectionProvider; // Fire an event if there's an active provider activeProvider->AddSelectionChangedListener(selListener.data()); ISelection::ConstPointer sel = activeProvider->GetSelection(); this->FireSelection(newPart, sel); if (activeProvider.Cast<IPostSelectionProvider>().IsNotNull()) { activeProvider.Cast<IPostSelectionProvider>() ->AddPostSelectionChangedListener(postSelListener.data()); } else { activeProvider->AddSelectionChangedListener(postSelListener.data()); } this->FirePostSelection(newPart, sel); } else { this->FireSelection(IWorkbenchPart::Pointer(nullptr), ISelection::ConstPointer(nullptr)); this->FirePostSelection(IWorkbenchPart::Pointer(nullptr), ISelection::ConstPointer(nullptr)); } }