diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2022-05-12 08:17:02 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2022-05-12 17:48:51 +0200 |
commit | 9f37840b0d7778ab4fc3294c44f62198ea932e3f (patch) | |
tree | 5178fd0927ce62bb5edebcff87a76ea55f49c0fe | |
parent | e98a68b23e14580dfa236536254b6ff80cd10df7 (diff) |
sw content controls, dropdown: add insert UI
- introduce a SwContentControlListItem::ToString() that tries to use the
display text of the list item, otherwise falls back to its value and use it
while building the dropdown widget and when inserting selected list item
- handle the dropdown case in SwWrtShell::InsertContentControl()
- expose this as a new .uno:InsertDropdownContentControl command
- mention the new and all previous content control commands in the
MS-compatible forms menu as well
Change-Id: I075f77933c1466b5258357d5a661e173c34de34f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134215
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
-rw-r--r-- | officecfg/registry/data/org/openoffice/Office/UI/WriterCommands.xcu | 8 | ||||
-rw-r--r-- | sw/inc/cmdid.h | 3 | ||||
-rw-r--r-- | sw/inc/formatcontentcontrol.hxx | 2 | ||||
-rw-r--r-- | sw/inc/strings.hrc | 1 | ||||
-rw-r--r-- | sw/qa/uibase/wrtsh/wrtsh.cxx | 23 | ||||
-rw-r--r-- | sw/sdi/_textsh.sdi | 6 | ||||
-rw-r--r-- | sw/sdi/swriter.sdi | 17 | ||||
-rw-r--r-- | sw/source/core/crsr/dropdowncontentcontrolbutton.cxx | 4 | ||||
-rw-r--r-- | sw/source/core/txtnode/attrcontentcontrol.cxx | 10 | ||||
-rw-r--r-- | sw/source/uibase/shells/textsh.cxx | 5 | ||||
-rw-r--r-- | sw/source/uibase/uiview/view.cxx | 1 | ||||
-rw-r--r-- | sw/source/uibase/wrtsh/wrtsh1.cxx | 13 | ||||
-rw-r--r-- | sw/source/uibase/wrtsh/wrtsh3.cxx | 2 | ||||
-rw-r--r-- | sw/uiconfig/swriter/menubar/menubar.xml | 1 | ||||
-rw-r--r-- | sw/uiconfig/swriter/menubar/mscompatibleformsmenu.xml | 3 | ||||
-rw-r--r-- | xmloff/source/text/txtparae.cxx | 2 |
16 files changed, 96 insertions, 5 deletions
diff --git a/officecfg/registry/data/org/openoffice/Office/UI/WriterCommands.xcu b/officecfg/registry/data/org/openoffice/Office/UI/WriterCommands.xcu index b36802016c1d..f3181fea0059 100644 --- a/officecfg/registry/data/org/openoffice/Office/UI/WriterCommands.xcu +++ b/officecfg/registry/data/org/openoffice/Office/UI/WriterCommands.xcu @@ -635,6 +635,14 @@ <value>1</value> </prop> </node> + <node oor:name=".uno:InsertDropdownContentControl" oor:op="replace"> + <prop oor:name="Label" oor:type="xs:string"> + <value xml:lang="en-US">Insert Drop-Down List 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 355d607a5bc5..a11bfd4e21df 100644 --- a/sw/inc/cmdid.h +++ b/sw/inc/cmdid.h @@ -217,10 +217,11 @@ class SwUINumRuleItem; #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_CONTENT_CONTROL (FN_INSERT + 20) /* Rich text content control */ #define FN_INSERT_CHECKBOX_CONTENT_CONTROL (FN_INSERT + 21) /* Checkbox content control */ #define FN_INSERT_OBJECT_DLG (FN_INSERT + 22) /* Object */ #define FN_INSERT_PAGEBREAK (FN_INSERT + 23) /* Page break*/ +#define FN_INSERT_DROPDOWN_CONTENT_CONTROL (FN_INSERT + 24) /* Dropdown content control */ #define FN_POSTIT (FN_INSERT + 29) /* Insert/edit PostIt */ #define FN_INSERT_TABLE (FN_INSERT + 30) /* Insert Table */ #define FN_INSERT_STRING (FN_INSERT+31) diff --git a/sw/inc/formatcontentcontrol.hxx b/sw/inc/formatcontentcontrol.hxx index e3debfb77bf4..09797fd00b0a 100644 --- a/sw/inc/formatcontentcontrol.hxx +++ b/sw/inc/formatcontentcontrol.hxx @@ -84,6 +84,8 @@ public: void dumpAsXml(xmlTextWriterPtr pWriter) const; + OUString ToString() const; + static void ItemsToAny(const std::vector<SwContentControlListItem>& rItems, css::uno::Any& rVal); diff --git a/sw/inc/strings.hrc b/sw/inc/strings.hrc index c19ebe69fc9b..75ffb71a3441 100644 --- a/sw/inc/strings.hrc +++ b/sw/inc/strings.hrc @@ -1430,6 +1430,7 @@ #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") +#define STR_DROPDOWN_CONTENT_CONTROL_PLACEHOLDER NC_("STR_DROPDOWN_CONTENT_CONTROL_PLACEHOLDER", "Choose an item") #endif diff --git a/sw/qa/uibase/wrtsh/wrtsh.cxx b/sw/qa/uibase/wrtsh/wrtsh.cxx index 72d8e7060de6..2799a8213ead 100644 --- a/sw/qa/uibase/wrtsh/wrtsh.cxx +++ b/sw/qa/uibase/wrtsh/wrtsh.cxx @@ -216,6 +216,29 @@ CPPUNIT_TEST_FIXTURE(Test, testSelectDropdownContentControl) // i.e. the document text was unchanged instead of display text of the first list item. CPPUNIT_ASSERT_EQUAL(OUString("red"), pTextNode->GetExpandText(pWrtShell->GetLayout())); } + +CPPUNIT_TEST_FIXTURE(Test, testInsertDropdownContentControl) +{ + // Given an empty document: + SwDoc* pDoc = createSwDoc(); + + // When inserting a content control: + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->InsertContentControl(SwContentControlType::DROP_DOWN_LIST); + + // Then make sure that the matching text attribute is added to the document model: + SwTextNode* pTextNode = pWrtShell->GetCursor()->GetNode().GetTextNode(); + SwTextAttr* pAttr = pTextNode->GetTextAttrForCharAt(0, RES_TXTATR_CONTENTCONTROL); + auto pTextContentControl = static_txtattr_cast<SwTextContentControl*>(pAttr); + auto& rFormatContentControl + = static_cast<SwFormatContentControl&>(pTextContentControl->GetAttr()); + SwContentControl* pContentControl = rFormatContentControl.GetContentControl(); + // Without the accompanying fix in place, this test would have failed: + // - Expected: 1 + // - Actual : 0 + // i.e. the inserted content control was a default (rich text) one, not a dropdown. + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pContentControl->GetListItems().size()); +} } CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/sdi/_textsh.sdi b/sw/sdi/_textsh.sdi index 21b56b6c1a60..1995156b79ae 100644 --- a/sw/sdi/_textsh.sdi +++ b/sw/sdi/_textsh.sdi @@ -284,6 +284,12 @@ interface BaseText StateMethod = NoState ; DisableFlags="SfxDisableFlags::SwOnProtectedCursor"; ] + FN_INSERT_DROPDOWN_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 0b808255e588..123404e32c36 100644 --- a/sw/sdi/swriter.sdi +++ b/sw/sdi/swriter.sdi @@ -3066,6 +3066,23 @@ SfxVoidItem InsertCheckboxContentControl FN_INSERT_CHECKBOX_CONTENT_CONTROL GroupId = SfxGroupId::Insert; ] +SfxVoidItem InsertDropdownContentControl FN_INSERT_DROPDOWN_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/core/crsr/dropdowncontentcontrolbutton.cxx b/sw/source/core/crsr/dropdowncontentcontrolbutton.cxx index b7113994c0c7..a1f73dc1b522 100644 --- a/sw/source/core/crsr/dropdowncontentcontrolbutton.cxx +++ b/sw/source/core/crsr/dropdowncontentcontrolbutton.cxx @@ -24,7 +24,9 @@ void SwDropDownContentControlButton::InitDropdown() std::vector<SwContentControlListItem> aListItems = m_rContentControl.GetListItems(); for (const auto& rListItem : aListItems) - m_xTreeView->append_text(rListItem.m_aDisplayText); + { + m_xTreeView->append_text(rListItem.ToString()); + } if (aListItems.empty()) { diff --git a/sw/source/core/txtnode/attrcontentcontrol.cxx b/sw/source/core/txtnode/attrcontentcontrol.cxx index 8704221a9a3b..fd98947e3458 100644 --- a/sw/source/core/txtnode/attrcontentcontrol.cxx +++ b/sw/source/core/txtnode/attrcontentcontrol.cxx @@ -246,6 +246,16 @@ void SwContentControlListItem::dumpAsXml(xmlTextWriterPtr pWriter) const (void)xmlTextWriterEndElement(pWriter); } +OUString SwContentControlListItem::ToString() const +{ + if (!m_aDisplayText.isEmpty()) + { + return m_aDisplayText; + } + + return m_aValue; +} + void SwContentControlListItem::ItemsToAny(const std::vector<SwContentControlListItem>& rItems, uno::Any& rVal) { diff --git a/sw/source/uibase/shells/textsh.cxx b/sw/source/uibase/shells/textsh.cxx index 815b353d825c..6902bcb25529 100644 --- a/sw/source/uibase/shells/textsh.cxx +++ b/sw/source/uibase/shells/textsh.cxx @@ -229,6 +229,11 @@ void SwTextShell::ExecInsert(SfxRequest &rReq) rReq.Done(); break; + case FN_INSERT_DROPDOWN_CONTENT_CONTROL: + rSh.InsertContentControl(SwContentControlType::DROP_DOWN_LIST); + 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 4efcfc677a7c..9bec819807ee 100644 --- a/sw/source/uibase/uiview/view.cxx +++ b/sw/source/uibase/uiview/view.cxx @@ -593,6 +593,7 @@ void SwView::CheckReadonlyState() 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_CONTENT_CONTROL, FN_INSERT_CHECKBOX_CONTENT_CONTROL, + FN_INSERT_DROPDOWN_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 f0c1b47b95d1..ebdefe75971b 100644 --- a/sw/source/uibase/wrtsh/wrtsh1.cxx +++ b/sw/source/uibase/wrtsh/wrtsh1.cxx @@ -1030,7 +1030,6 @@ void SwWrtShell::InsertContentControl(SwContentControlType eType) switch (eType) { case SwContentControlType::RICH_TEXT: - case SwContentControlType::DROP_DOWN_LIST: { pContentControl->SetShowingPlaceHolder(true); if (!HasSelection()) @@ -1049,6 +1048,18 @@ void SwWrtShell::InsertContentControl(SwContentControlType eType) aPlaceholder = u"\u2610"; break; } + case SwContentControlType::DROP_DOWN_LIST: + { + pContentControl->SetShowingPlaceHolder(true); + if (!HasSelection()) + { + aPlaceholder = SwResId(STR_DROPDOWN_CONTENT_CONTROL_PLACEHOLDER); + } + SwContentControlListItem aListItem; + aListItem.m_aValue = aPlaceholder; + pContentControl->SetListItems({ aListItem }); + break; + } } if (aPlaceholder.getLength()) { diff --git a/sw/source/uibase/wrtsh/wrtsh3.cxx b/sw/source/uibase/wrtsh/wrtsh3.cxx index 573ea4a9752d..5225c7278357 100644 --- a/sw/source/uibase/wrtsh/wrtsh3.cxx +++ b/sw/source/uibase/wrtsh/wrtsh3.cxx @@ -132,7 +132,7 @@ bool SwWrtShell::GotoContentControl(const SwFormatContentControl& rContentContro size_t nSelectedListItem = *pContentControl->GetSelectedListItem(); LockView(/*bViewLocked=*/true); OUString aOldState = GetCursorDescr(); - OUString aNewState = pContentControl->GetListItems()[nSelectedListItem].m_aDisplayText; + OUString aNewState = pContentControl->GetListItems()[nSelectedListItem].ToString(); SwRewriter aRewriter; aRewriter.AddRule(UndoArg1, aOldState); aRewriter.AddRule(UndoArg2, SwResId(STR_YIELDS)); diff --git a/sw/uiconfig/swriter/menubar/menubar.xml b/sw/uiconfig/swriter/menubar/menubar.xml index e5d20fa5a751..14c3705a3189 100644 --- a/sw/uiconfig/swriter/menubar/menubar.xml +++ b/sw/uiconfig/swriter/menubar/menubar.xml @@ -714,6 +714,7 @@ <menu:menupopup> <menu:menuitem menu:id=".uno:InsertContentControl"/> <menu:menuitem menu:id=".uno:InsertCheckboxContentControl"/> + <menu:menuitem menu:id=".uno:InsertDropdownContentControl"/> </menu:menupopup> </menu:menu> </menu:menupopup> diff --git a/sw/uiconfig/swriter/menubar/mscompatibleformsmenu.xml b/sw/uiconfig/swriter/menubar/mscompatibleformsmenu.xml index 6be7228ded4d..83b8cd35d98a 100644 --- a/sw/uiconfig/swriter/menubar/mscompatibleformsmenu.xml +++ b/sw/uiconfig/swriter/menubar/mscompatibleformsmenu.xml @@ -15,6 +15,9 @@ <menu:menuseparator/> <menu:menu menu:id=".uno:MSCompatContentControls"> <menu:menupopup> + <menu:menuitem menu:id=".uno:InsertContentControl"/> + <menu:menuitem menu:id=".uno:InsertCheckboxContentControl"/> + <menu:menuitem menu:id=".uno:InsertDropdownContentControl"/> <menu:menuitem menu:id=".uno:DatePickerFormField"/> </menu:menupopup> </menu:menu> diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx index ac566ace391d..5c37dc7a865b 100644 --- a/xmloff/source/text/txtparae.cxx +++ b/xmloff/source/text/txtparae.cxx @@ -3946,7 +3946,7 @@ void XMLTextParagraphExport::ExportContentControl( comphelper::SequenceAsHashMap aMap(rListItem); auto it = aMap.find("DisplayText"); OUString aValue; - if (it != aMap.end() && (it->second >>= aValue)) + if (it != aMap.end() && (it->second >>= aValue) && !aValue.isEmpty()) { GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_DISPLAY_TEXT, aValue); } |