officecfg/registry/data/org/openoffice/Office/UI/WriterCommands.xcu | 8 +++ sw/inc/cmdid.h | 1 sw/inc/strings.hrc | 1 sw/qa/uibase/wrtsh/wrtsh.cxx | 16 ++++++ sw/sdi/_textsh.sdi | 6 ++ sw/sdi/swriter.sdi | 17 ++++++ sw/source/uibase/inc/wrtsh.hxx | 1 sw/source/uibase/shells/textsh.cxx | 5 + sw/source/uibase/uiview/view.cxx | 2 sw/source/uibase/wrtsh/wrtsh1.cxx | 26 ++++++++++ sw/uiconfig/swriter/menubar/menubar.xml | 2 11 files changed, 84 insertions(+), 1 deletion(-)
New commits: commit e83223ae22585fbd4b03397cb78b8b98bb71a717 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Thu Apr 21 09:08:03 2022 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Mon Apr 25 08:33:53 2022 +0200 sw content controls: add insert UI - add an SwWrtShell::InsertContentControl() to put the current selection into a content control - if there is no selection, add a non-empty placeholder - expose this as a new .uno:InsertContentControl uno command - add this new command to the bottom of the form menu -- probably we can have a sub-menu there once there will be more types (cherry picked from commit 59393b73ec4c0f1f1965a9c24a2635780c707189) Change-Id: Icb32aee777ab08d09401bf468788692b933a90ac Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133331 Tested-by: Miklos Vajna <vmik...@collabora.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/officecfg/registry/data/org/openoffice/Office/UI/WriterCommands.xcu b/officecfg/registry/data/org/openoffice/Office/UI/WriterCommands.xcu index 3b960d95c58f..86c6302f6e18 100644 --- a/officecfg/registry/data/org/openoffice/Office/UI/WriterCommands.xcu +++ b/officecfg/registry/data/org/openoffice/Office/UI/WriterCommands.xcu @@ -614,6 +614,14 @@ <value>1</value> </prop> </node> + <node oor:name=".uno:InsertContentControl" oor:op="replace"> + <prop oor:name="Label" oor:type="xs:string"> + <value xml:lang="en-US">Insert Rich Text Content Control</value> + </prop> + <prop oor:name="Properties" oor:type="xs:int"> + <value>1</value> + </prop> + </node> <node oor:name=".uno:InsertObjectDialog" oor:op="replace"> <prop oor:name="Label" oor:type="xs:string"> <value xml:lang="en-US">Insert Other Objects</value> diff --git a/sw/inc/cmdid.h b/sw/inc/cmdid.h index afe61b164849..8499a54b2b28 100644 --- a/sw/inc/cmdid.h +++ b/sw/inc/cmdid.h @@ -210,6 +210,7 @@ #define FN_INSERT_LINEBREAK (FN_INSERT + 18) /* Newline */ #define FN_INSERT_FIELD_DATA_ONLY (FN_INSERT + 19) /* Field dialog for mail merge*/ +#define FN_INSERT_CONTENT_CONTROL (FN_INSERT + 20) /* Content control */ #define FN_INSERT_OBJECT_DLG (FN_INSERT + 22) /* Object */ #define FN_INSERT_PAGEBREAK (FN_INSERT + 23) /* Page break*/ #define FN_POSTIT (FN_INSERT + 29) /* Insert/edit PostIt */ diff --git a/sw/inc/strings.hrc b/sw/inc/strings.hrc index d5aaf979b66f..90a7f5b44d73 100644 --- a/sw/inc/strings.hrc +++ b/sw/inc/strings.hrc @@ -1420,6 +1420,7 @@ #define STR_AUTOMARK_NO NC_("createautomarkdialog|no", "No") #define STR_WRAP_PANEL_CUSTOM_STR NC_("sidebarwrap|customlabel", "Custom") +#define STR_CONTENT_CONTROL_PLACEHOLDER NC_("STR_CONTENT_CONTROL_PLACEHOLDER", "Click here to enter text") #endif diff --git a/sw/qa/uibase/wrtsh/wrtsh.cxx b/sw/qa/uibase/wrtsh/wrtsh.cxx index d73ba55ef09f..51489553d30f 100644 --- a/sw/qa/uibase/wrtsh/wrtsh.cxx +++ b/sw/qa/uibase/wrtsh/wrtsh.cxx @@ -90,6 +90,22 @@ CPPUNIT_TEST_FIXTURE(Test, testGotoContentControl) sal_Int32 nEnd = pWrtShell->GetCursor()->End()->nContent.GetIndex(); CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(5), nEnd); } + +CPPUNIT_TEST_FIXTURE(Test, testInsertContentControl) +{ + // Given an empty document: + SwDoc* pDoc = createSwDoc(); + + // When inserting a content control: + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->InsertContentControl(); + + // Then make sure that the matching text attribute is added to the document model: + SwTextNode* pTextNode = pWrtShell->GetCursor()->GetNode().GetTextNode(); + // Without the accompanying fix in place, this test would have failed, nothing happened on + // InsertContentControl(). + CPPUNIT_ASSERT(pTextNode->GetTextAttrForCharAt(0, RES_TXTATR_CONTENTCONTROL)); +} } CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/sdi/_textsh.sdi b/sw/sdi/_textsh.sdi index 38359c593471..f1689474467f 100644 --- a/sw/sdi/_textsh.sdi +++ b/sw/sdi/_textsh.sdi @@ -272,6 +272,12 @@ interface BaseText StateMethod = NoState ; DisableFlags="SfxDisableFlags::SwOnProtectedCursor"; ] + FN_INSERT_CONTENT_CONTROL // status(final|play) + [ + ExecMethod = ExecInsert ; + StateMethod = NoState ; + DisableFlags="SfxDisableFlags::SwOnProtectedCursor"; + ] FN_INSERT_COLUMN_BREAK // status(final|play) [ ExecMethod = ExecInsert ; diff --git a/sw/sdi/swriter.sdi b/sw/sdi/swriter.sdi index 265a4000c5a0..16922267cf85 100644 --- a/sw/sdi/swriter.sdi +++ b/sw/sdi/swriter.sdi @@ -3032,6 +3032,23 @@ SfxVoidItem InsertLinebreak FN_INSERT_LINEBREAK GroupId = SfxGroupId::Insert; ] +SfxVoidItem InsertContentControl FN_INSERT_CONTENT_CONTROL +() +[ + AutoUpdate = FALSE, + FastCall = FALSE, + ReadOnlyDoc = FALSE, + Toggle = FALSE, + Container = FALSE, + RecordAbsolute = FALSE, + RecordPerSet; + + AccelConfig = TRUE, + MenuConfig = TRUE, + ToolBoxConfig = TRUE, + GroupId = SfxGroupId::Insert; +] + SfxVoidItem InsertMultiIndex FN_INSERT_MULTI_TOX () [ diff --git a/sw/source/uibase/inc/wrtsh.hxx b/sw/source/uibase/inc/wrtsh.hxx index e271569f0bf8..37d82557ac03 100644 --- a/sw/source/uibase/inc/wrtsh.hxx +++ b/sw/source/uibase/inc/wrtsh.hxx @@ -316,6 +316,7 @@ typedef bool (SwWrtShell::*FNSimpleMove)(); void InsertPageBreak(const OUString *pPageDesc = nullptr, const ::std::optional<sal_uInt16>& rPgNum = std::nullopt); void InsertLineBreak(std::optional<SwLineBreakClear> oClear = std::nullopt); void InsertColumnBreak(); + void InsertContentControl(); void InsertFootnote(const OUString &, bool bEndNote = false, bool bEdit = true ); void SplitNode( bool bAutoFormat = false ); bool CanInsert(); diff --git a/sw/source/uibase/shells/textsh.cxx b/sw/source/uibase/shells/textsh.cxx index eece3fcf4588..7fec748ba488 100644 --- a/sw/source/uibase/shells/textsh.cxx +++ b/sw/source/uibase/shells/textsh.cxx @@ -218,6 +218,11 @@ void SwTextShell::ExecInsert(SfxRequest &rReq) rReq.Done(); break; + case FN_INSERT_CONTENT_CONTROL: + rSh.InsertContentControl(); + rReq.Done(); + break; + case FN_INSERT_COLUMN_BREAK: rSh.InsertColumnBreak(); rReq.Done(); diff --git a/sw/source/uibase/uiview/view.cxx b/sw/source/uibase/uiview/view.cxx index 7d418acd17b0..b43ff17782fc 100644 --- a/sw/source/uibase/uiview/view.cxx +++ b/sw/source/uibase/uiview/view.cxx @@ -594,7 +594,7 @@ void SwView::CheckReadonlyState() SID_CHARMAP, SID_EMOJI_CONTROL, FN_INSERT_SOFT_HYPHEN, FN_INSERT_HARDHYPHEN, FN_INSERT_HARD_SPACE, FN_INSERT_NNBSP, FN_INSERT_BREAK, FN_INSERT_LINEBREAK, FN_INSERT_COLUMN_BREAK, - FN_INSERT_BREAK_DLG, + FN_INSERT_BREAK_DLG, FN_INSERT_CONTENT_CONTROL, FN_DELETE_SENT, FN_DELETE_BACK_SENT, FN_DELETE_WORD, FN_DELETE_BACK_WORD, FN_DELETE_LINE, FN_DELETE_BACK_LINE, FN_DELETE_PARA, FN_DELETE_BACK_PARA, FN_DELETE_WHOLE_LINE, diff --git a/sw/source/uibase/wrtsh/wrtsh1.cxx b/sw/source/uibase/wrtsh/wrtsh1.cxx index fec9d1d6ecb6..1d93f1e31983 100644 --- a/sw/source/uibase/wrtsh/wrtsh1.cxx +++ b/sw/source/uibase/wrtsh/wrtsh1.cxx @@ -111,6 +111,7 @@ #include <UndoInsert.hxx> #include <UndoCore.hxx> #include <formatlinebreak.hxx> +#include <formatcontentcontrol.hxx> using namespace sw::mark; using namespace com::sun::star; @@ -1006,6 +1007,31 @@ void SwWrtShell::InsertColumnBreak() EndUndo(SwUndoId::UI_INSERT_COLUMN_BREAK); } +void SwWrtShell::InsertContentControl() +{ + if (!lcl_IsAllowed(this)) + { + return; + } + + ResetCursorStack(); + if (!CanInsert()) + { + return; + } + + auto pContentControl = std::make_shared<SwContentControl>(nullptr); + pContentControl->SetShowingPlaceHolder(true); + if (!HasSelection()) + { + OUString aPlaceholder = SwResId(STR_CONTENT_CONTROL_PLACEHOLDER); + Insert(aPlaceholder); + Left(CRSR_SKIP_CHARS, /*bSelect=*/true, aPlaceholder.getLength(), /*bBasicCall=*/false); + } + SwFormatContentControl aContentControl(pContentControl, RES_TXTATR_CONTENTCONTROL); + SetAttrItem(aContentControl); +} + // Insert footnote // rStr - optional footnote mark diff --git a/sw/uiconfig/swriter/menubar/menubar.xml b/sw/uiconfig/swriter/menubar/menubar.xml index e6dc87371c22..526cbac6a8ca 100644 --- a/sw/uiconfig/swriter/menubar/menubar.xml +++ b/sw/uiconfig/swriter/menubar/menubar.xml @@ -709,6 +709,8 @@ <menu:menuseparator/> <menu:menuitem menu:id=".uno:OpenReadOnly"/> <menu:menuitem menu:id=".uno:AutoControlFocus"/> + <menu:menuseparator/> + <menu:menuitem menu:id=".uno:InsertContentControl"/> </menu:menupopup> </menu:menu> <menu:menu menu:id=".uno:ToolsMenu">