summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2019-06-18 12:17:22 +0200
committerMiklos Vajna <vmiklos@collabora.com>2019-07-01 16:19:22 +0200
commitbbb8ab79db6eec109d128d00df835250e51904dc (patch)
treec3544be67721c189336a24ff1cd929efaf7cfbc7
parenta05459a700422d1af2dfa2e81fb83a2e67e0ebf5 (diff)
sw: extract postit insert code from SwTextShell::ExecField()
Into a new SwWrtShell::InsertPostIt(), so I can reuse it in SwFrameShell. (cherry picked from commit 485e048c391da38f883adfbef920069bd7af2305) Conflicts: sw/source/uibase/inc/wrtsh.hxx sw/source/uibase/wrtsh/wrtsh1.cxx Change-Id: Ib327aed033067250f021f3857f4ba3adb8e6c597 Reviewed-on: https://gerrit.libreoffice.org/74423 Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com> Tested-by: Miklos Vajna <vmiklos@collabora.com>
-rw-r--r--sw/source/uibase/inc/wrtsh.hxx5
-rw-r--r--sw/source/uibase/shells/textfld.cxx65
-rw-r--r--sw/source/uibase/wrtsh/wrtsh1.cxx73
3 files changed, 79 insertions, 64 deletions
diff --git a/sw/source/uibase/inc/wrtsh.hxx b/sw/source/uibase/inc/wrtsh.hxx
index 936b910d0de6..10d652aadd9a 100644
--- a/sw/source/uibase/inc/wrtsh.hxx
+++ b/sw/source/uibase/inc/wrtsh.hxx
@@ -46,6 +46,8 @@ class SvxAutoCorrect;
class NaviContentBookmark;
struct SwCallMouseEvent;
class SfxStringListItem;
+class SwFieldMgr;
+class SfxRequest;
namespace i18nutil {
struct SearchOptions2;
@@ -476,6 +478,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 d810ed63cec2..73ec7c99508f 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 d401687ec5a3..2ce1783a80b0 100644
--- a/sw/source/uibase/wrtsh/wrtsh1.cxx
+++ b/sw/source/uibase/wrtsh/wrtsh1.cxx
@@ -100,8 +100,13 @@
#include <PostItMgr.hxx>
#include <FrameControlsManager.hxx>
+#include <fldmgr.hxx>
+#include <docufld.hxx>
+#include <IDocumentFieldsAccess.hxx>
+#include <fmtfld.hxx>
#include <sfx2/msgpool.hxx>
+#include <svx/postattr.hxx>
#include <comphelper/lok.hxx>
#include <memory>
@@ -1836,4 +1841,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: */