diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2022-05-31 09:29:54 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2022-06-01 10:52:19 +0200 |
commit | cc549ee5be9026bdacfbc76db92b7adff4a05492 (patch) | |
tree | 0dbedf01c62dde782df7aec8f80691041fa7d169 /sw | |
parent | 38d00152374e3df465fff78e379cecb4b0be2985 (diff) |
sw content controls, date: add insert UI
- handle the date case in SwWrtShell::InsertContentControl()
- expose this as a new .uno:InsertDateContentControl command
- add the new uno command to the default & MS-compatible menus
- hide the old .uno:DatePickerFormField from the menus that has the
problems described in the sw::mark::DateFieldmark documentation.
(cherry picked from commit 5f335154459e044b6035f099a3e08c98fe258d2b)
Change-Id: If3c1050d6a8302be0da4a11067a67805396dec48
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135222
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/inc/cmdid.h | 1 | ||||
-rw-r--r-- | sw/inc/strings.hrc | 1 | ||||
-rw-r--r-- | sw/qa/uibase/wrtsh/wrtsh.cxx | 21 | ||||
-rw-r--r-- | sw/sdi/_textsh.sdi | 6 | ||||
-rw-r--r-- | sw/sdi/swriter.sdi | 17 | ||||
-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 | 18 | ||||
-rw-r--r-- | sw/uiconfig/swriter/menubar/menubar.xml | 1 | ||||
-rw-r--r-- | sw/uiconfig/swriter/menubar/mscompatibleformsmenu.xml | 2 |
10 files changed, 71 insertions, 2 deletions
diff --git a/sw/inc/cmdid.h b/sw/inc/cmdid.h index 003c77e7efd0..e9f961c605b1 100644 --- a/sw/inc/cmdid.h +++ b/sw/inc/cmdid.h @@ -217,6 +217,7 @@ #define FN_INSERT_DROPDOWN_CONTENT_CONTROL (FN_INSERT + 24) /* Dropdown content control */ #define FN_CONTENT_CONTROL_PROPERTIES (FN_INSERT + 25) /* Content control properties */ #define FN_INSERT_PICTURE_CONTENT_CONTROL (FN_INSERT + 26) /* Picture content control */ +#define FN_INSERT_DATE_CONTENT_CONTROL (FN_INSERT + 27) /* Date 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/strings.hrc b/sw/inc/strings.hrc index 1c91a387b94b..25d518d58def 100644 --- a/sw/inc/strings.hrc +++ b/sw/inc/strings.hrc @@ -1422,6 +1422,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") +#define STR_DATE_CONTENT_CONTROL_PLACEHOLDER NC_("STR_DATE_CONTENT_CONTROL_PLACEHOLDER", "Choose a date") #endif diff --git a/sw/qa/uibase/wrtsh/wrtsh.cxx b/sw/qa/uibase/wrtsh/wrtsh.cxx index 6f3478e7f99b..7a659c2f0f49 100644 --- a/sw/qa/uibase/wrtsh/wrtsh.cxx +++ b/sw/qa/uibase/wrtsh/wrtsh.cxx @@ -346,6 +346,27 @@ CPPUNIT_TEST_FIXTURE(Test, testSelectDateContentControl) CPPUNIT_ASSERT_EQUAL(OUString("2022-05-24T00:00:00Z"), rFormatContentControl.GetContentControl()->GetCurrentDate()); } + +CPPUNIT_TEST_FIXTURE(Test, testInsertDateContentControl) +{ + // Given an empty document: + SwDoc* pDoc = createSwDoc(); + + // When inserting a date content control: + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->InsertContentControl(SwContentControlType::DATE); + + // 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()); + std::shared_ptr<SwContentControl> pContentControl = rFormatContentControl.GetContentControl(); + // Without the accompanying fix in place, this test would have failed, there was no special + // handling for date content control. + CPPUNIT_ASSERT(pContentControl->GetDate()); +} } CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/sdi/_textsh.sdi b/sw/sdi/_textsh.sdi index 16cd41e339ce..d23dedcf9885 100644 --- a/sw/sdi/_textsh.sdi +++ b/sw/sdi/_textsh.sdi @@ -296,6 +296,12 @@ interface BaseText StateMethod = NoState ; DisableFlags="SfxDisableFlags::SwOnProtectedCursor"; ] + FN_INSERT_DATE_CONTENT_CONTROL // status(final|play) + [ + ExecMethod = ExecInsert ; + StateMethod = NoState ; + DisableFlags="SfxDisableFlags::SwOnProtectedCursor"; + ] FN_CONTENT_CONTROL_PROPERTIES // status(final|play) [ ExecMethod = ExecInsert ; diff --git a/sw/sdi/swriter.sdi b/sw/sdi/swriter.sdi index 3361825974b2..4ef90b62f7d3 100644 --- a/sw/sdi/swriter.sdi +++ b/sw/sdi/swriter.sdi @@ -3100,6 +3100,23 @@ SfxVoidItem InsertPictureContentControl FN_INSERT_PICTURE_CONTENT_CONTROL GroupId = SfxGroupId::Insert; ] +SfxVoidItem InsertDateContentControl FN_INSERT_DATE_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 ContentControlProperties FN_CONTENT_CONTROL_PROPERTIES () [ diff --git a/sw/source/uibase/shells/textsh.cxx b/sw/source/uibase/shells/textsh.cxx index 94b0a50e211a..032545b3cf45 100644 --- a/sw/source/uibase/shells/textsh.cxx +++ b/sw/source/uibase/shells/textsh.cxx @@ -239,6 +239,11 @@ void SwTextShell::ExecInsert(SfxRequest &rReq) rReq.Done(); break; + case FN_INSERT_DATE_CONTENT_CONTROL: + rSh.InsertContentControl(SwContentControlType::DATE); + rReq.Done(); + break; + case FN_CONTENT_CONTROL_PROPERTIES: { SwWrtShell& rWrtSh = GetShell(); diff --git a/sw/source/uibase/uiview/view.cxx b/sw/source/uibase/uiview/view.cxx index 1400e25dcd0e..8a05bbb61444 100644 --- a/sw/source/uibase/uiview/view.cxx +++ b/sw/source/uibase/uiview/view.cxx @@ -596,6 +596,7 @@ void SwView::CheckReadonlyState() 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_INSERT_PICTURE_CONTENT_CONTROL, + FN_INSERT_DATE_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 d2c8815c305c..7436602a3028 100644 --- a/sw/source/uibase/wrtsh/wrtsh1.cxx +++ b/sw/source/uibase/wrtsh/wrtsh1.cxx @@ -103,6 +103,8 @@ #include <comphelper/lok.hxx> #include <comphelper/propertyvalue.hxx> #include <svtools/optionsdrawinglayer.hxx> +#include <svl/numformat.hxx> +#include <svl/zformat.hxx> #include <memory> #include <frmtool.hxx> @@ -1026,7 +1028,6 @@ void SwWrtShell::InsertContentControl(SwContentControlType eType) switch (eType) { case SwContentControlType::RICH_TEXT: - case SwContentControlType::DATE: { pContentControl->SetShowingPlaceHolder(true); if (!HasSelection()) @@ -1101,6 +1102,21 @@ void SwWrtShell::InsertContentControl(SwContentControlType eType) Left(CRSR_SKIP_CHARS, /*bSelect=*/true, 1, /*bBasicCall=*/false); break; } + case SwContentControlType::DATE: + { + pContentControl->SetShowingPlaceHolder(true); + pContentControl->SetDate(true); + SvNumberFormatter* pFormatter = GetDoc()->GetNumberFormatter(); + sal_uInt32 nStandardFormat = pFormatter->GetStandardFormat(SvNumFormatType::DATE); + const SvNumberformat* pFormat = pFormatter->GetEntry(nStandardFormat); + pContentControl->SetDateFormat(pFormat->GetFormatstring()); + pContentControl->SetDateLanguage(LanguageTag(pFormat->GetLanguage()).getBcp47()); + if (!HasSelection()) + { + aPlaceholder = SwResId(STR_DATE_CONTENT_CONTROL_PLACEHOLDER); + } + break; + } } if (aPlaceholder.getLength()) { diff --git a/sw/uiconfig/swriter/menubar/menubar.xml b/sw/uiconfig/swriter/menubar/menubar.xml index c755f9cc88da..3f257b9f0ebf 100644 --- a/sw/uiconfig/swriter/menubar/menubar.xml +++ b/sw/uiconfig/swriter/menubar/menubar.xml @@ -716,6 +716,7 @@ <menu:menuitem menu:id=".uno:InsertPictureContentControl"/> <menu:menuitem menu:id=".uno:InsertCheckboxContentControl"/> <menu:menuitem menu:id=".uno:InsertDropdownContentControl"/> + <menu:menuitem menu:id=".uno:InsertDateContentControl"/> <menu:menuitem menu:id=".uno:ContentControlProperties"/> </menu:menupopup> </menu:menu> diff --git a/sw/uiconfig/swriter/menubar/mscompatibleformsmenu.xml b/sw/uiconfig/swriter/menubar/mscompatibleformsmenu.xml index cc4483cda320..1e66cd782a8f 100644 --- a/sw/uiconfig/swriter/menubar/mscompatibleformsmenu.xml +++ b/sw/uiconfig/swriter/menubar/mscompatibleformsmenu.xml @@ -19,7 +19,7 @@ <menu:menuitem menu:id=".uno:InsertPictureContentControl"/> <menu:menuitem menu:id=".uno:InsertCheckboxContentControl"/> <menu:menuitem menu:id=".uno:InsertDropdownContentControl"/> - <menu:menuitem menu:id=".uno:DatePickerFormField"/> + <menu:menuitem menu:id=".uno:InsertDateContentControl"/> <menu:menuitem menu:id=".uno:ContentControlProperties"/> </menu:menupopup> </menu:menu> |