[Libreoffice-commits] core.git: sw/source

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Tue Jun 18 11:06:30 UTC 2019


 sw/source/uibase/inc/wrtsh.hxx      |    5 ++
 sw/source/uibase/shells/textfld.cxx |   65 -------------------------------
 sw/source/uibase/wrtsh/wrtsh1.cxx   |   74 ++++++++++++++++++++++++++++++++++++
 3 files changed, 80 insertions(+), 64 deletions(-)

New commits:
commit 485e048c391da38f883adfbef920069bd7af2305
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Tue Jun 18 12:17:22 2019 +0200
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Tue Jun 18 13:05:22 2019 +0200

    sw: extract postit insert code from SwTextShell::ExecField()
    
    Into a new SwWrtShell::InsertPostIt(), so I can reuse it in
    SwFrameShell.
    
    Change-Id: Ib327aed033067250f021f3857f4ba3adb8e6c597
    Reviewed-on: https://gerrit.libreoffice.org/74264
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
    Tested-by: Jenkins

diff --git a/sw/source/uibase/inc/wrtsh.hxx b/sw/source/uibase/inc/wrtsh.hxx
index f474046de4be..8307327ce135 100644
--- a/sw/source/uibase/inc/wrtsh.hxx
+++ b/sw/source/uibase/inc/wrtsh.hxx
@@ -48,6 +48,8 @@ class NaviContentBookmark;
 struct SwCallMouseEvent;
 class SfxStringListItem;
 enum class SvMacroItemId : sal_uInt16;
+class SwFieldMgr;
+class SfxRequest;
 
 namespace i18nutil {
     struct SearchOptions2;
@@ -482,6 +484,9 @@ typedef bool (SwWrtShell:: *FNSimpleMove)();
     void ChangeHeaderOrFooter(const OUString& rStyleName, bool bHeader, bool bOn, bool bShowWarning);
     virtual void SetShowHeaderFooterSeparator( FrameControlType eControl, bool bShow ) override;
 
+    /// Inserts a new annotation/comment at the current cursor position / selection.
+    void InsertPostIt(SwFieldMgr& rFieldMgr, SfxRequest& rReq);
+
 private:
 
     SAL_DLLPRIVATE void  OpenMark();
diff --git a/sw/source/uibase/shells/textfld.cxx b/sw/source/uibase/shells/textfld.cxx
index 376fdb2f269c..fa5afebd6c59 100644
--- a/sw/source/uibase/shells/textfld.cxx
+++ b/sw/source/uibase/shells/textfld.cxx
@@ -411,70 +411,7 @@ void SwTextShell::ExecField(SfxRequest &rReq)
             break;
             case FN_POSTIT:
             {
-                SwPostItField* pPostIt = dynamic_cast<SwPostItField*>(aFieldMgr.GetCurField());
-                bool bNew = !(pPostIt && pPostIt->GetTyp()->Which() == SwFieldIds::Postit);
-                if (bNew || GetView().GetPostItMgr()->IsAnswer())
-                {
-                    const SvxPostItAuthorItem* pAuthorItem = rReq.GetArg<SvxPostItAuthorItem>(SID_ATTR_POSTIT_AUTHOR);
-                    OUString sAuthor;
-                    if ( pAuthorItem )
-                        sAuthor = pAuthorItem->GetValue();
-                    else
-                    {
-                        std::size_t nAuthor = SW_MOD()->GetRedlineAuthor();
-                        sAuthor = SW_MOD()->GetRedlineAuthor(nAuthor);
-                    }
-
-                    const SvxPostItTextItem* pTextItem = rReq.GetArg<SvxPostItTextItem>(SID_ATTR_POSTIT_TEXT);
-                    OUString sText;
-                    if ( pTextItem )
-                        sText = pTextItem->GetValue();
-
-                    // If we have a text already registered for answer, use that
-                    if (GetView().GetPostItMgr()->IsAnswer() && !GetView().GetPostItMgr()->GetAnswerText().isEmpty())
-                    {
-                        sText = GetView().GetPostItMgr()->GetAnswerText();
-                        GetView().GetPostItMgr()->RegisterAnswerText(OUString());
-                    }
-
-                    if ( rSh.HasSelection() && !rSh.IsTableMode() )
-                    {
-                        rSh.KillPams();
-                    }
-
-                    // #i120513# Inserting a comment into an autocompletion crashes
-                    // --> suggestion has to be removed before
-                    GetView().GetEditWin().StopQuickHelp();
-
-                    SwInsertField_Data aData(TYP_POSTITFLD, 0, sAuthor, sText, 0);
-                    aFieldMgr.InsertField( aData );
-
-                    rSh.Push();
-                    rSh.SwCursorShell::Left(1, CRSR_SKIP_CHARS);
-                    pPostIt = static_cast<SwPostItField*>(aFieldMgr.GetCurField());
-                    rSh.Pop(SwCursorShell::PopMode::DeleteCurrent); // Restore cursor position
-                }
-
-                // Client has disabled annotations rendering, no need to
-                // focus the postit field
-                if (comphelper::LibreOfficeKit::isActive() && !comphelper::LibreOfficeKit::isTiledAnnotations())
-                    break;
-
-                if (pPostIt)
-                {
-                    SwFieldType* pType = rSh.GetDoc()->getIDocumentFieldsAccess().GetFieldType(SwFieldIds::Postit, OUString(), false);
-                    SwIterator<SwFormatField,SwFieldType> aIter( *pType );
-                    SwFormatField* pSwFormatField = aIter.First();
-                    while( pSwFormatField )
-                    {
-                        if ( pSwFormatField->GetField() == pPostIt )
-                        {
-                            pSwFormatField->Broadcast( SwFormatFieldHint( nullptr, SwFormatFieldHintWhich::FOCUS, &GetView() ) );
-                            break;
-                        }
-                        pSwFormatField = aIter.Next();
-                    }
-                }
+                rSh.InsertPostIt(aFieldMgr, rReq);
             }
             break;
             case SID_EDIT_POSTIT:
diff --git a/sw/source/uibase/wrtsh/wrtsh1.cxx b/sw/source/uibase/wrtsh/wrtsh1.cxx
index cf2074b93467..f4bf6e00eae8 100644
--- a/sw/source/uibase/wrtsh/wrtsh1.cxx
+++ b/sw/source/uibase/wrtsh/wrtsh1.cxx
@@ -102,10 +102,16 @@
 
 #include <PostItMgr.hxx>
 #include <FrameControlsManager.hxx>
+#include <fldmgr.hxx>
+#include <docufld.hxx>
+#include <IDocumentFieldsAccess.hxx>
+#include <fmtfld.hxx>
 
 #include <sfx2/msgpool.hxx>
 #include <sfx2/msg.hxx>
 #include <svtools/embedhlp.hxx>
+#include <svx/postattr.hxx>
+#include <comphelper/lok.hxx>
 #include <memory>
 
 using namespace sw::mark;
@@ -1862,4 +1868,72 @@ void SwWrtShell::SetShowHeaderFooterSeparator( FrameControlType eControl, bool b
         GetView().GetEditWin().GetFrameControlsManager().HideControls( eControl );
 }
 
+void SwWrtShell::InsertPostIt(SwFieldMgr& rFieldMgr, SfxRequest& rReq)
+{
+    SwPostItField* pPostIt = dynamic_cast<SwPostItField*>(rFieldMgr.GetCurField());
+    bool bNew = !(pPostIt && pPostIt->GetTyp()->Which() == SwFieldIds::Postit);
+    if (bNew || GetView().GetPostItMgr()->IsAnswer())
+    {
+        const SvxPostItAuthorItem* pAuthorItem = rReq.GetArg<SvxPostItAuthorItem>(SID_ATTR_POSTIT_AUTHOR);
+        OUString sAuthor;
+        if ( pAuthorItem )
+            sAuthor = pAuthorItem->GetValue();
+        else
+        {
+            std::size_t nAuthor = SW_MOD()->GetRedlineAuthor();
+            sAuthor = SW_MOD()->GetRedlineAuthor(nAuthor);
+        }
+
+        const SvxPostItTextItem* pTextItem = rReq.GetArg<SvxPostItTextItem>(SID_ATTR_POSTIT_TEXT);
+        OUString sText;
+        if ( pTextItem )
+            sText = pTextItem->GetValue();
+
+        // If we have a text already registered for answer, use that
+        if (GetView().GetPostItMgr()->IsAnswer() && !GetView().GetPostItMgr()->GetAnswerText().isEmpty())
+        {
+            sText = GetView().GetPostItMgr()->GetAnswerText();
+            GetView().GetPostItMgr()->RegisterAnswerText(OUString());
+        }
+
+        if ( HasSelection() && !IsTableMode() )
+        {
+            KillPams();
+        }
+
+        // #i120513# Inserting a comment into an autocompletion crashes
+        // --> suggestion has to be removed before
+        GetView().GetEditWin().StopQuickHelp();
+
+        SwInsertField_Data aData(TYP_POSTITFLD, 0, sAuthor, sText, 0);
+        rFieldMgr.InsertField( aData );
+
+        Push();
+        SwCursorShell::Left(1, CRSR_SKIP_CHARS);
+        pPostIt = static_cast<SwPostItField*>(rFieldMgr.GetCurField());
+        Pop(SwCursorShell::PopMode::DeleteCurrent); // Restore cursor position
+    }
+
+    // Client has disabled annotations rendering, no need to
+    // focus the postit field
+    if (comphelper::LibreOfficeKit::isActive() && !comphelper::LibreOfficeKit::isTiledAnnotations())
+        return;
+
+    if (pPostIt)
+    {
+        SwFieldType* pType = GetDoc()->getIDocumentFieldsAccess().GetFieldType(SwFieldIds::Postit, OUString(), false);
+        SwIterator<SwFormatField,SwFieldType> aIter( *pType );
+        SwFormatField* pSwFormatField = aIter.First();
+        while( pSwFormatField )
+        {
+            if ( pSwFormatField->GetField() == pPostIt )
+            {
+                pSwFormatField->Broadcast( SwFormatFieldHint( nullptr, SwFormatFieldHintWhich::FOCUS, &GetView() ) );
+                break;
+            }
+            pSwFormatField = aIter.Next();
+        }
+    }
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list