diff options
author | László Németh <laszlo.nemeth@collabora.com> | 2016-01-30 17:17:42 +0100 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2016-02-03 09:28:19 +0000 |
commit | 483d0e85fad6f8f787ada28bc16242c43f7496b4 (patch) | |
tree | 1c7ec02f5a813bb66801e6a44ed69845bae57b08 | |
parent | ddefbfd6453ec4184fbe806f9aec4188c4b88012 (diff) |
Autocompletion: complete year (part) to current date
to check or insert it during typing.
For example, typing "201" or "2016-0", Writer will
suggest "2016-01-30" - the current date in ISO 8601
format - in a tooltip, and it's possible to insert it
pressing enter.
There is no autocompletion for single years (e.g. "2016")
to avoid unintentional text insertion at line ending, e.g.
typing "30 January 2016" in a letter header.
Change-Id: I230a449b0e19d5316b8369d780d7c7fda57fea37
Reviewed-on: https://gerrit.libreoffice.org/21928
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Andras Timar <andras.timar@collabora.com>
-rw-r--r-- | sw/source/uibase/docvw/edtwin.cxx | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/sw/source/uibase/docvw/edtwin.cxx b/sw/source/uibase/docvw/edtwin.cxx index 72b03f361c53..bfb3a40cc25a 100644 --- a/sw/source/uibase/docvw/edtwin.cxx +++ b/sw/source/uibase/docvw/edtwin.cxx @@ -29,6 +29,7 @@ #include <com/sun/star/i18n/InputSequenceCheckMode.hpp> #include <com/sun/star/i18n/UnicodeScript.hpp> +#include <com/sun/star/i18n/CalendarFieldIndex.hpp> #include <vcl/help.hxx> #include <vcl/graph.hxx> @@ -6022,6 +6023,29 @@ void QuickHelpData::FillStrArr( SwWrtShell& rSh, const OUString& rWord ) aNames = (*pCalendar)->getDays(); } + // Add matching current date in ISO 8601 format, for example 2016-01-30 + OUString rStrToday; + + if (rWord[0] == '2') + { + OUStringBuffer rStr(""); + rStr.append(sal::static_int_cast< sal_Int32 >((*pCalendar)->getValue(i18n::CalendarFieldIndex::YEAR))).append("-"); + sal_Int32 nMonth = sal::static_int_cast< sal_Int32 >((*pCalendar)->getValue(i18n::CalendarFieldIndex::MONTH)+1); + sal_Int32 nDay = sal::static_int_cast< sal_Int32 > ((*pCalendar)->getValue(i18n::CalendarFieldIndex::DAY_OF_MONTH)); + if (nMonth < 10) + rStr.append("0"); + rStr.append(nMonth).append("-"); + if (nDay < 10) + rStr.append("0"); + rStrToday = rStr.append(nDay).toString(); + + // do not suggest for single years, for example for "2016", + // only for "201" or "2016-..." (to avoid unintentional text + // insertion at line ending, for example typing "30 January 2016") + if (rWord.getLength() != 4 && rStrToday.startsWith(rWord)) + m_aHelpStrings.push_back(rStrToday); + } + // Add matching words from AutoCompleteWord list const SwAutoCompleteWord& rACList = SwEditShell::GetAutoCompleteWords(); std::vector<OUString> strings; @@ -6031,6 +6055,13 @@ void QuickHelpData::FillStrArr( SwWrtShell& rSh, const OUString& rWord ) for (size_t i= 0; i<strings.size(); i++) { OUString aCompletedString = strings[i]; + + // when we have a matching current date, avoid to suggest + // other words with the same matching starting characters, + // for example 2016-01-3 instead of 2016-01-30 + if (!rStrToday.isEmpty() && aCompletedString.startsWith(rWord)) + continue; + //fdo#61251 if it's an exact match, ensure unchanged replacement //exists as a candidate if (aCompletedString.startsWith(rWord)) |