Kaydet (Commit) d65ba563 authored tarafından Niklas Johansson's avatar Niklas Johansson Kaydeden (comit) Miklos Vajna

Make number recognition work in writer tables again

It seems that number recognition in tables are not working properly
enter 10-10-10 and it should be converted to a date but it is not.
I tracked it down to the fix of bug fdo#32082. It looks like bSetNumFmt
was changed to false by mistake. Since then it has changed name to
bSetNumFormat. From what I can tell fdo#32082 still works after this
patch, but I might have missed some nuance of that bug report.

Added two tests, one for the bug mentioned above and one to check
that number recognition is working. At least with a simple date.

Reviewed-on: https://gerrit.libreoffice.org/19563Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarJan Holesovsky <kendy@collabora.com>
(cherry picked from commit aa334d55)

Change-Id: Id58849a223eb602054c66c7379cd56a68a93dea2
Reviewed-on: https://gerrit.libreoffice.org/20082Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
üst 377381e2
import math
import unittest
from org.libreoffice.unotest import UnoInProcess
from com.sun.star.beans import PropertyValue
from com.sun.star.uno import RuntimeException
from com.sun.star.table import BorderLine
from com.sun.star.table import BorderLine2
from com.sun.star.table.BorderLineStyle import (DOUBLE, SOLID, EMBOSSED,\
THICKTHIN_LARGEGAP, DASHED, DOTTED)
from com.sun.star.util import XNumberFormats
from com.sun.star.lang import Locale
class CheckTable(unittest.TestCase):
_uno = None
......@@ -344,6 +348,72 @@ class CheckTable(unittest.TestCase):
self.assertEqual( xTable.Data, ((1,2,3), (4,55,66), (7,88,99), (10,1111,1212)))
xDoc.dispose()
def test_tdf32082(self):
xDoc = CheckTable._uno.openEmptyWriterDoc()
xDocFrame = xDoc.CurrentController.Frame
xContext = CheckTable._uno.getContext()
xServiceManager = xContext.ServiceManager
xDispatcher = xServiceManager.createInstanceWithContext(
'com.sun.star.frame.DispatchHelper', xContext)
xTable = xDoc.createInstance("com.sun.star.text.TextTable")
xTable.initialize(1,1)
xCursor = xDoc.Text.createTextCursor()
xDoc.Text.insertTextContent(xCursor, xTable, False)
# Setup numberformat for the cell
xNumberFormats = xDoc.NumberFormats
xLocale = Locale('en', 'US', '')
formatString = '#,##0.00 [$€-407];[RED]-#,##0.00 [$€-407]'
key = xNumberFormats.queryKey(formatString, xLocale, True)
if key == -1:
key = xNumberFormats.addNew(formatString, xLocale)
# Apply the format on the first cell
xTable.getCellByPosition(0,0).NumberFormat = key
xDispatcher.executeDispatch(xDocFrame, '.uno:GoToStartOfDoc', '', 0, ())
xDispatcher.executeDispatch(xDocFrame, '.uno:InsertText', '', 0,
(PropertyValue('Text', 0, '3', 0),))
xDispatcher.executeDispatch(xDocFrame, '.uno:JumpToNextCell', '', 0, ())
# Check that the formatting we set up is not destroyed
self.assertEquals(xTable.getCellByPosition(0,0).getString(), '3.00 €')
self.assertEquals(xTable.getCellByPosition(0,0).getValue(), 3)
# Verify that it works with number recognition turned on as well
xDispatcher.executeDispatch(xDocFrame, '.uno:TableNumberRecognition', '', 0,
(PropertyValue('TableNumberRecognition', 0, True, 0),))
xDispatcher.executeDispatch(xDocFrame, '.uno:InsertText', '', 0,
(PropertyValue('Text', 0, '4', 0),))
xDispatcher.executeDispatch(xDocFrame, '.uno:JumpToNextCell', '', 0, ())
self.assertEquals(xTable.getCellByPosition(0,1).getString(), '4.00 €')
self.assertEquals(xTable.getCellByPosition(0,1).getValue(), 4)
xDoc.dispose()
def test_numberRecognition(self):
xDoc = CheckTable._uno.openEmptyWriterDoc()
xDocFrame = xDoc.CurrentController.Frame
xContext = CheckTable._uno.getContext()
xServiceManager = xContext.ServiceManager
xDispatcher = xServiceManager.createInstanceWithContext(
'com.sun.star.frame.DispatchHelper', xContext)
xTable = xDoc.createInstance('com.sun.star.text.TextTable')
xTable.initialize(2,1)
xCursor = xDoc.Text.createTextCursor()
xDoc.Text.insertTextContent(xCursor, xTable, False)
xDispatcher.executeDispatch(xDocFrame, '.uno:GoToStartOfDoc', '', 0, ())
xDispatcher.executeDispatch(xDocFrame, '.uno:InsertText', '', 0,
(PropertyValue('Text', 0, '15-10-30', 0),))
xDispatcher.executeDispatch(xDocFrame, '.uno:JumpToNextCell', '', 0, ())
# Without number recognition 15-10-30 should not be interperated as a date
self.assertEquals(xTable.getCellByPosition(0,0).getString(), '15-10-30')
self.assertEquals(xTable.getCellByPosition(0,0).getValue(), 0)
# Activate number recognition
xDispatcher.executeDispatch(xDocFrame, '.uno:TableNumberRecognition', '', 0,
(PropertyValue('TableNumberRecognition', 0, True, 0),))
xDispatcher.executeDispatch(xDocFrame, '.uno:InsertText', '', 0,
(PropertyValue('Text', 0, '15-10-30', 0),))
xDispatcher.executeDispatch(xDocFrame, '.uno:JumpToNextCell', '', 0, ())
# With number recognition it should now be a date, confirm by checking
# the string and value of the cell.
self.assertEquals(xTable.getCellByPosition(0,1).getString(), '2015-10-30')
self.assertEquals(xTable.getCellByPosition(0,1).getValue(), 42307.0)
xDoc.dispose()
if __name__ == '__main__':
unittest.main()
......
......@@ -4043,7 +4043,7 @@ void SwDoc::ChkBoxNumFormat( SwTableBox& rBox, bool bCallUpdate )
SfxItemSet aBoxSet( GetAttrPool(), RES_BOXATR_FORMAT, RES_BOXATR_VALUE );
bool bLockModify = true;
bool bSetNumberFormat = false;
bool bSetNumberFormat = IsInsTableFormatNum();
const bool bForceNumberFormat = IsInsTableFormatNum() && IsInsTableChangeNumFormat();
// if the user forced a number format in this cell previously,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment