[Libreoffice-commits] core.git: sw/source
László Németh
laszlo.nemeth at collabora.com
Wed Feb 3 09:28:58 UTC 2016
sw/source/uibase/docvw/edtwin.cxx | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
New commits:
commit 483d0e85fad6f8f787ada28bc16242c43f7496b4
Author: László Németh <laszlo.nemeth at collabora.com>
Date: Sat Jan 30 17:17:42 2016 +0100
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 at libreoffice.org>
Reviewed-by: Andras Timar <andras.timar at collabora.com>
diff --git a/sw/source/uibase/docvw/edtwin.cxx b/sw/source/uibase/docvw/edtwin.cxx
index 72b03f3..bfb3a40 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))
More information about the Libreoffice-commits
mailing list