Issue 77648

Summary: Undo of cell number format does not work in special cases
Product: Writer Reporter: andreas.martens
Component: editingAssignee: michael.ruess
Status: CLOSED FIXED QA Contact: issues@sw <issues>
Severity: Trivial    
Priority: P3 CC: andreas.martens, cno, issues, liujiaxiang, pagalmes.lists, peter.junge
Version: OOo 2.2   
Target Milestone: ---   
Hardware: All   
OS: All   
Issue Type: DEFECT Latest Confirmation in: ---
Developer Difficulty: ---
Issue Depends on:    
Issue Blocks: 72764    
Attachments:
Description Flags
Bug document
none
The patch file
none
The patch file
none
The patch file
none
the patch file
none
the correct patch file
none
the patch file for doing undo to change the number format back to "text"
none
the patch file
none
the patch file
none
the patch file
none
Modified patch none

Description andreas.martens 2007-05-21 13:28:27 UTC
If a cell contains more than one paragraph a change of the number format of that
cell from "text" to e.g. "date" is not undoable.
To reproduce:
Open bug document
Cursor into first cell
Call "number format..." via context menu (right mouse button)
Change to number format to "date"
=> Nothing visible happens but the number format of this cell has changed.
Undo (Ctrl+Z)
=> Nothing happens but the number format of the cell remains "date"
Expected behavior: the format should change back to "text".
Comment 1 andreas.martens 2007-05-21 13:32:49 UTC
Created attachment 45290 [details]
Bug document
Comment 2 liuyu 2007-05-24 03:16:05 UTC
Created attachment 45359 [details]
The patch file
Comment 3 liuyu 2007-05-24 03:16:59 UTC
I have fixed this issue, please have a look at the patch file.
Comment 4 andreas.martens 2007-05-24 08:38:25 UTC
Mmh, even your patch would solve this issue as well as issue 77649, I have some
concerns about it.
It would change the behavior of the function SwTableBox::IsValidNumTxtNd(..).
At the moment this function works for simple cases (only paragraphs, no
sections, no table in table) in the following way: It returns "false" if the
cell contains more than one paragraph. With your patch, even two or more
paragraphs would be accepted as "ValidNumTxt".
I would prefer a fix which does not change the behavior for these cases but
solve only the buggy ones.
Please have a look at the code (SwTableBox::IsValidNumTxtNd(..))
Instead of removing the check if the next node is an end node this check has to
be enhanced. A loop is required. Behind the text node are end nodes allowed if
it belongs to section start nodes. The first end node which does not belong to a
section start node will be the end of a cell. Then it has to be checked if this
cell is identical with the current table box to avoid a change in a table in table.
Oops, my idea would fix issue 77649, but not this one :-(
To fix this one, the Undo object which calls the function above has to be
change, I assume.
Comment 5 liuyu 2007-05-28 07:08:41 UTC
Created attachment 45454 [details]
The patch file
Comment 6 liuyu 2007-05-28 07:17:35 UTC
Hi ama, according to your suggestion, I have changed the patch. To fix this 
issue I didn't touch the function SwTableBox::IsValidNumTxtNd(..), I add some 
code to the areas (call this function) to get the node (number format) postion 
in the cell(contains more than one paragraph).
Please have a look.
Comment 7 liuyu 2007-05-28 07:56:37 UTC
Created attachment 45455 [details]
The patch file
Comment 8 liuyu 2007-05-28 08:02:22 UTC
The latest patch(2007/05/28 06:56:00 +0000: patch.diff) contains all the codes 
for this issue.Please have a look.
Comment 9 liuyu 2007-05-28 08:02:57 UTC
The latest patch(2007/05/28 06:56:00 +0000: patch.diff) contains all the codes 
for this issue.Please have a look.
Comment 10 liuyu 2007-05-28 08:03:18 UTC
The latest patch(2007/05/28 06:56:00 +0000: patch.diff) contains all the codes 
for this issue.Please have a look.
Comment 11 peter.junge 2007-05-28 08:17:54 UTC
Add dependency to meta issue
Comment 12 liujiaxiang 2007-05-28 08:31:02 UTC
add myself
Comment 13 andreas.martens 2007-05-29 10:27:05 UTC
Sorry, if I've been unclear. I wrote this issue because the "Undo" does not work
correctly. The action itself (changing number format from 'text' to 'date')
works as expected.
What I mean:
If you change the number format of a cell, two things should happen:
1. the number format of the cell changes (regardless of the content of the cell)
2. if the cell contains one single paragraph, this text will be reinterpreted
for the new number format, but if there is more than one paragraph in the cell,
the text should _not_ be reinterpreted.

Undo should change back the text if step 2. has been performed and of course,
step 1.
The problem is that Undo actually works only if step 1. _and_ step 2. has been
performed. If the condition of step 2. has not been fulfilled, neither step 2.
(which is okay) nor step 1. (that's the bug) will be undone.

Your patch would change the behavior in a way that step 1. and step 2. will be
performed regardless of the content of the cell. This would of course solve the
undo-problem but it would change the wanted behavior.
For this issue you should not change IsValidNumTxtNd(..) or their calling
functions in a way that step 2. will performed even there is more than one
paragraph. 
You should instead try to record the change of step 1 even when step 2. is
skipped. This does not work at the moment and is the reason for the failing of undo.

For issue 77649 we have to fix IsValidNumTxtNd(..) itself, I will provide some
comments into the other issue as well.
Comment 14 liuyu 2007-05-30 05:40:12 UTC
Created attachment 45503 [details]
the patch file
Comment 15 liuyu 2007-05-30 05:42:23 UTC
Created attachment 45504 [details]
the correct patch file
Comment 16 liuyu 2007-05-30 05:56:29 UTC
So the requirement is:
After change the cell's (has two or more paragraph) number format,
do undo will undo the operation before the change.
Not to make the cell can be changed.
Right?
Comment 17 liuyu 2007-05-30 07:34:11 UTC
Created attachment 45507 [details]
the patch file for doing undo to change the number format back to "text"
Comment 18 liuyu 2007-05-30 07:37:32 UTC
The latest patch is for the operation:
After change the cell's (has two or more paragraph) number format,
do undo will just change the number format back to "text".
Comment 19 andreas.martens 2007-05-30 10:49:13 UTC
This patch would not work if the two or more paragraphs are inside a section.
BTW: Every SwTxtNode is a SwCntntNode as well, it's not necessary to test
"IsTxtNode() && IsCntntNode()"
Comment 20 liuyu 2007-05-31 05:14:45 UTC
Created attachment 45545 [details]
the patch file
Comment 21 liuyu 2007-05-31 05:22:53 UTC
I think the patch has to cover all the situation (the cell contains complex 
paragraph and the function SwTableBox::IsValidNumTxtNd(..) return ULONG_MAX),
I think the latest patch could be fit to this issue.
Comment 22 andreas.martens 2007-05-31 15:41:42 UTC
Unfortunately I do not have the time to test your patch in real life, but I had
a look at the code. I think that it solves the situation I mentioned so far, but...
I could imagine more problems:
1. Please check the "Redo" functionality; I doubt it will work for cells with
more than one paragraph.
2. Please check the Undo if your cell contains "Hello world" with an attribute
like 'bold' attached to the second word ('world'), I fear this attribute will be
deleted by "Undo"?!

The solution:
The old code did two things if it found one paragraph, it changed the text and
it changed the cell format and recorded both changes.
You could separate this two items ( box format changes, text changes).
The box format changes should be done always, undoable and redoable. The text
change should only be done, if IsValidNumTxtNd() does not delivers ULONG_MAX. In
this case, all the text node related code has to be done in Ctor, Undo and Redo.
Comment 23 liuyu 2007-06-21 04:21:58 UTC
Created attachment 46125 [details]
the patch file
Comment 24 liuyu 2007-06-21 04:59:54 UTC
Created attachment 46126 [details]
the patch file
Comment 25 liuyu 2007-06-21 05:02:47 UTC
I have changed the patch file according to your suggestions. Please have a look 
at it.
Comment 26 andreas.martens 2007-06-21 15:06:20 UTC
Created attachment 46146 [details]
Modified patch
Comment 27 andreas.martens 2007-06-21 15:09:30 UTC
Fine, looks great! Thank you!
I have modified your patch slightly and will integrate it into CWS swqbf99.
Comment 28 andreas.martens 2007-06-21 15:10:59 UTC
Fixed in CWS swqbf99
untbl.cxx
Comment 29 andreas.martens 2007-07-04 11:21:54 UTC
Ready for QA
Comment 30 michael.ruess 2007-07-06 13:38:44 UTC
Verified in CWS swqbf99.
Comment 31 michael.ruess 2007-07-26 10:03:25 UTC
Checked fix in 680m222.