Kaydet (Commit) 9b67b6a6 authored tarafından Michael Stahl's avatar Michael Stahl

sw_redlinehide_4b: consider the comments in the margin

SwPostItMgr needs to hide the comments that are in delete redlines.

Also notify SwPostItMgr when redlines are created/removed.

SwPostItMgr is owned by the ViewShell but there is currently only one
layout so SwRootFrame still needs to broadcast to all of them.

Also an EndListening call was missing in
SwPostItMgr::CheckForRemovedPostIts() which caused asserts.

Change-Id: Ic0fccde50f6fdaa449afb535476c00c41ba94287
üst e41374f6
......@@ -31,6 +31,7 @@ class SwRootFrame;
class SwPostItMgr;
class SwEditWin;
class SwFrame;
class IDocumentRedlineAccess;
namespace sw { namespace annotation {
class SwAnnotationWin;
} }
......@@ -115,7 +116,7 @@ public:
SwSidebarItem & operator =(SwSidebarItem &&) = default;
virtual SwPosition GetAnchorPosition() const = 0;
virtual bool UseElement() = 0;
virtual bool UseElement(SwRootFrame const&, IDocumentRedlineAccess const&) = 0;
virtual const SwFormatField& GetFormatField() const = 0;
virtual const SfxBroadcaster* GetBroadCaster() const = 0;
virtual VclPtr<sw::annotation::SwAnnotationWin> GetSidebarWindow( SwEditWin& rEditWin,
......@@ -134,7 +135,7 @@ public:
}
virtual SwPosition GetAnchorPosition() const override;
virtual bool UseElement() override;
virtual bool UseElement(SwRootFrame const&, IDocumentRedlineAccess const&) override;
virtual const SwFormatField& GetFormatField() const override
{
return mrFormatField;
......
......@@ -21,6 +21,8 @@
#include <rootfrm.hxx>
#include <txtfrm.hxx>
#include <doc.hxx>
#include <docsh.hxx>
#include <fmtfld.hxx>
#include <IDocumentUndoRedo.hxx>
#include <IDocumentFieldsAccess.hxx>
#include <IDocumentState.hxx>
......@@ -166,6 +168,10 @@ void UpdateFramesForAddDeleteRedline(SwDoc & rDoc, SwPaM const& rPam)
}
// fields last - SwGetRefField::UpdateField requires up-to-date frames
UpdateFieldsForRedline(rDoc.getIDocumentFieldsAccess()); // after footnotes
// update SwPostItMgr / notes in the margin
rDoc.GetDocShell()->Broadcast(
SwFormatFieldHint(nullptr, SwFormatFieldHintWhich::REMOVED) );
}
void UpdateFramesForRemoveDeleteRedline(SwDoc & rDoc, SwPaM const& rPam)
......@@ -225,6 +231,10 @@ void UpdateFramesForRemoveDeleteRedline(SwDoc & rDoc, SwPaM const& rPam)
}
// fields last - SwGetRefField::UpdateField requires up-to-date frames
UpdateFieldsForRedline(rDoc.getIDocumentFieldsAccess()); // after footnotes
// update SwPostItMgr / notes in the margin
rDoc.GetDocShell()->Broadcast(
SwFormatFieldHint(nullptr, SwFormatFieldHintWhich::INSERTED) );
}
} // namespace sw
......
......@@ -31,6 +31,7 @@
#include <txtfrm.hxx>
#include <tabfrm.hxx>
#include <IDocumentRedlineAccess.hxx>
#include <IDocumentFieldsAccess.hxx>
#include <redline.hxx>
#include <scriptinfo.hxx>
#include <editeng/charhiddenitem.hxx>
......@@ -142,9 +143,12 @@ SwPosition SwAnnotationItem::GetAnchorPosition() const
return aPos;
}
bool SwAnnotationItem::UseElement()
bool SwAnnotationItem::UseElement(SwRootFrame const& rLayout,
IDocumentRedlineAccess const& rIDRA)
{
return mrFormatField.IsFieldInDoc();
return mrFormatField.IsFieldInDoc()
&& (!rLayout.IsHideRedlines()
|| !sw::IsFieldDeletedInModel(rIDRA, *mrFormatField.GetTextField()));
}
VclPtr<sw::annotation::SwAnnotationWin> SwAnnotationItem::GetSidebarWindow(
......
......@@ -4518,6 +4518,13 @@ void SwRootFrame::SetHideRedlines(bool const bHideRedlines)
rIDFA.UpdateExpFields(nullptr, false);
rIDFA.UpdateRefFields();
// update SwPostItMgr / notes in the margin
// note: as long as all shells share layout, broadcast to all shells!
rDoc.GetDocShell()->Broadcast( SwFormatFieldHint(nullptr, bHideRedlines
? SwFormatFieldHintWhich::REMOVED
: SwFormatFieldHintWhich::INSERTED) );
// InvalidateAllContent(SwInvalidateFlags::Size); // ??? TODO what to invalidate? this is the big hammer
}
......
......@@ -52,6 +52,7 @@
#include <ndtxt.hxx>
#include <redline.hxx>
#include <docary.hxx>
#include <rootfrm.hxx>
#include <SwRewriter.hxx>
#include <tools/color.hxx>
#include <unotools/datetime.hxx>
......@@ -240,13 +241,15 @@ SwPostItMgr::~SwPostItMgr()
void SwPostItMgr::CheckForRemovedPostIts()
{
IDocumentRedlineAccess const& rIDRA(mpWrtShell->getIDocumentRedlineAccess());
bool bRemoved = false;
auto currentIt = mvPostItFields.begin();
while(currentIt != mvPostItFields.end())
{
auto it = currentIt++;
if ( !(*it)->UseElement() )
if (!(*it)->UseElement(*mpWrtShell->GetLayout(), rIDRA))
{
EndListening(const_cast<SfxBroadcaster&>(*(*it)->GetBroadCaster()));
SwSidebarItem* p = *it;
currentIt = mvPostItFields.erase(std::remove(mvPostItFields.begin(), mvPostItFields.end(), *it), mvPostItFields.end());
if (GetActiveSidebarWin() == p->pPostIt)
......@@ -531,9 +534,10 @@ bool SwPostItMgr::CalcRects()
PreparePageContainer();
if ( !mvPostItFields.empty() )
{
IDocumentRedlineAccess const& rIDRA(mpWrtShell->getIDocumentRedlineAccess());
for (auto const& pItem : mvPostItFields)
{
if ( !pItem->UseElement() )
if (!pItem->UseElement(*mpWrtShell->GetLayout(), rIDRA))
{
OSL_FAIL("PostIt is not in doc or other wrong use");
bRepair = true;
......@@ -887,10 +891,11 @@ void SwPostItMgr::LayoutPostIts()
if (!ShowNotes())
{ // we do not want to see the notes anymore -> Options-Writer-View-Notes
IDocumentRedlineAccess const& rIDRA(mpWrtShell->getIDocumentRedlineAccess());
bool bRepair = false;
for (auto const& postItField : mvPostItFields)
{
if ( !postItField->UseElement() )
if (!postItField->UseElement(*mpWrtShell->GetLayout(), rIDRA))
{
OSL_FAIL("PostIt is not in doc!");
bRepair = true;
......@@ -1298,8 +1303,13 @@ void SwPostItMgr::AddPostIts(bool bCheckExistence, bool bFocus)
{
if ( pSwFormatField->GetTextField())
{
if ( pSwFormatField->IsFieldInDoc() )
IDocumentRedlineAccess const& rIDRA(mpWrtShell->getIDocumentRedlineAccess());
if (pSwFormatField->IsFieldInDoc()
&& (!mpWrtShell->GetLayout()->IsHideRedlines()
|| !sw::IsFieldDeletedInModel(rIDRA, *pSwFormatField->GetTextField())))
{
InsertItem(pSwFormatField,bCheckExistence,bFocus);
}
}
pSwFormatField = aIter.Next();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment