Commit d1961821 authored by Dmitry.Shahtanov's avatar Dmitry.Shahtanov Committed by Alexander.Trofimov

fix: Bug 20008 - Не восстанавливается содержимое формулы после Undo удаления...

fix: Bug 20008 - Не восстанавливается содержимое формулы после Undo удаления строк, на которые ссылалась формула

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@49942 954022d7-b5bf-4e40-9824-e11837661b57
parent 182bb10a
...@@ -2246,8 +2246,6 @@ parserFormula.prototype = { ...@@ -2246,8 +2246,6 @@ parserFormula.prototype = {
setFormula:function ( formula ) { setFormula:function ( formula ) {
this.Formula = formula; this.Formula = formula;
this.cellId = _cellId;
this.ws = _ws;
this.value = null; this.value = null;
this.pCurrPos = 0; this.pCurrPos = 0;
this.elemArr = []; this.elemArr = [];
......
...@@ -31,6 +31,7 @@ var historyitem_Worksheet_CreateRow = 20; ...@@ -31,6 +31,7 @@ var historyitem_Worksheet_CreateRow = 20;
var historyitem_Worksheet_CreateCol = 21; var historyitem_Worksheet_CreateCol = 21;
var historyitem_Worksheet_CreateCell = 22; var historyitem_Worksheet_CreateCell = 22;
var historyitem_Worksheet_SetViewSettings = 23; var historyitem_Worksheet_SetViewSettings = 23;
var historyitem_Worksheet_RemoveCellFormula = 24;
var historyitem_RowCol_Fontname = 1; var historyitem_RowCol_Fontname = 1;
var historyitem_RowCol_Fontsize = 2; var historyitem_RowCol_Fontsize = 2;
......
...@@ -365,7 +365,7 @@ var UndoRedoDataTypes = new function() { ...@@ -365,7 +365,7 @@ var UndoRedoDataTypes = new function() {
case this.ValueMultiTextElem: return new CCellValueMultiText();break; case this.ValueMultiTextElem: return new CCellValueMultiText();break;
case this.CellValue:return new CCellValue();break; case this.CellValue:return new CCellValue();break;
case this.CellValueData: return new UndoRedoData_CellValueData();break; case this.CellValueData: return new UndoRedoData_CellValueData();break;
case this.CellData: return new UndoRedoData_CellData();break; case this.CellData: return new UndoRedoData_CellData();break;
case this.CellSimpleData: return new UndoRedoData_CellSimpleData();break; case this.CellSimpleData: return new UndoRedoData_CellSimpleData();break;
case this.FromTo: return new UndoRedoData_FromTo();break; case this.FromTo: return new UndoRedoData_FromTo();break;
case this.FromToRowCol: return new UndoRedoData_FromToRowCol();break; case this.FromToRowCol: return new UndoRedoData_FromToRowCol();break;
...@@ -432,7 +432,7 @@ var UndoRedoDataTypes = new function() { ...@@ -432,7 +432,7 @@ var UndoRedoDataTypes = new function() {
}; };
}; };
function UndoRedoData_CellSimpleData(nRow, nCol, oOldVal, oNewVal){ function UndoRedoData_CellSimpleData(nRow, nCol, oOldVal, oNewVal, sFormula){
this.Properties = { this.Properties = {
Row: 0, Row: 0,
Col: 1, Col: 1,
...@@ -442,6 +442,7 @@ function UndoRedoData_CellSimpleData(nRow, nCol, oOldVal, oNewVal){ ...@@ -442,6 +442,7 @@ function UndoRedoData_CellSimpleData(nRow, nCol, oOldVal, oNewVal){
this.nCol = nCol; this.nCol = nCol;
this.oOldVal = oOldVal; this.oOldVal = oOldVal;
this.oNewVal = oNewVal; this.oNewVal = oNewVal;
this.sFormula = sFormula;
} }
UndoRedoData_CellSimpleData.prototype = { UndoRedoData_CellSimpleData.prototype = {
getType : function() getType : function()
...@@ -682,7 +683,7 @@ UndoRedoData_FromToCell.prototype = { ...@@ -682,7 +683,7 @@ UndoRedoData_FromToCell.prototype = {
this.from.r2 = collaborativeEditing.getLockMeRow2(nSheetId, this.from.r2); this.from.r2 = collaborativeEditing.getLockMeRow2(nSheetId, this.from.r2);
this.from.c1 = collaborativeEditing.getLockMeColumn2(nSheetId, this.from.c1); this.from.c1 = collaborativeEditing.getLockMeColumn2(nSheetId, this.from.c1);
this.from.c2 = collaborativeEditing.getLockMeColumn2(nSheetId, this.from.c2); this.from.c2 = collaborativeEditing.getLockMeColumn2(nSheetId, this.from.c2);
this.to.r1 = collaborativeEditing.getLockMeRow2(nSheetId, this.to.r1); this.to.r1 = collaborativeEditing.getLockMeRow2(nSheetId, this.to.r1);
this.to.r2 = collaborativeEditing.getLockMeRow2(nSheetId, this.to.r2); this.to.r2 = collaborativeEditing.getLockMeRow2(nSheetId, this.to.r2);
this.to.c1 = collaborativeEditing.getLockMeColumn2(nSheetId, this.to.c1); this.to.c1 = collaborativeEditing.getLockMeColumn2(nSheetId, this.to.c1);
...@@ -759,7 +760,7 @@ function UndoRedoData_ColProp(col){ ...@@ -759,7 +760,7 @@ function UndoRedoData_ColProp(col){
UndoRedoData_ColProp.prototype = { UndoRedoData_ColProp.prototype = {
isEqual : function(val) isEqual : function(val)
{ {
return this.hd == val.hd && this.CustomWidth == val.CustomWidth && ((this.BestFit == val.BestFit && this.width == val.width) || return this.hd == val.hd && this.CustomWidth == val.CustomWidth && ((this.BestFit == val.BestFit && this.width == val.width) ||
((null == this.width || gc_dDefaultColWidthCharsAttribute == this.width) && (null == this.BestFit || true == this.BestFit) && ((null == this.width || gc_dDefaultColWidthCharsAttribute == this.width) && (null == this.BestFit || true == this.BestFit) &&
(null == val.width || gc_dDefaultColWidthCharsAttribute == val.width) && (null == val.BestFit || true == val.BestFit))); (null == val.width || gc_dDefaultColWidthCharsAttribute == val.width) && (null == val.BestFit || true == val.BestFit)));
}, },
...@@ -815,7 +816,7 @@ function UndoRedoData_RowProp(row){ ...@@ -815,7 +816,7 @@ function UndoRedoData_RowProp(row){
UndoRedoData_RowProp.prototype = { UndoRedoData_RowProp.prototype = {
isEqual : function(val) isEqual : function(val)
{ {
return this.hd == val.hd && ((this.CustomHeight == val.CustomHeight && this.h == val.h) || return this.hd == val.hd && ((this.CustomHeight == val.CustomHeight && this.h == val.h) ||
((null == this.h || gc_dDefaultRowHeightAttribute == this.h) && (null == this.CustomHeight || false == this.CustomHeight) && ((null == this.h || gc_dDefaultRowHeightAttribute == this.h) && (null == this.CustomHeight || false == this.CustomHeight) &&
(null == val.h || gc_dDefaultRowHeightAttribute == val.h) && (null == val.CustomHeight || false == val.CustomHeight))); (null == val.h || gc_dDefaultRowHeightAttribute == val.h) && (null == val.CustomHeight || false == val.CustomHeight)));
}, },
...@@ -2964,6 +2965,24 @@ UndoRedoWoorksheet.prototype = { ...@@ -2964,6 +2965,24 @@ UndoRedoWoorksheet.prototype = {
else else
ws._removeCell(nRow, nCol); ws._removeCell(nRow, nCol);
} }
else if(historyitem_Worksheet_RemoveCellFormula == Type){
var nRow = Data.nRow;
var nCol = Data.nCol;
if(bUndo)
{
var sFormula = Data.sFormula
var cell = ws._getCell(nRow, nCol);
cell.setFormula(sFormula);
cell.formulaParsed.setFormula(sFormula);
if( !arrRecalc[ws.getId()] ){
arrRecalc[ws.getId()] = {};
}
arrRecalc[ws.getId()][cell.getName()] = cell.getName();
ws.workbook.needRecalc[ getVertexId(ws.getId(),cell.getName()) ] = [ ws.getId(),cell.getName() ];
if( ws.workbook.needRecalc.length < 0) ws.workbook.needRecalc.length = 0;
ws.workbook.needRecalc.length++;
}
}
else if(historyitem_Worksheet_ColProp == Type) else if(historyitem_Worksheet_ColProp == Type)
{ {
var index = Data.index; var index = Data.index;
...@@ -3136,21 +3155,21 @@ UndoRedoWoorksheet.prototype = { ...@@ -3136,21 +3155,21 @@ UndoRedoWoorksheet.prototype = {
else if(historyitem_Worksheet_MoveRange == Type) else if(historyitem_Worksheet_MoveRange == Type)
{ {
if( bUndo ){ if( bUndo ){
var rec = {length:0}, rec2; var rec = {length:0}, rec2;
for(var ind = 0; ind < Data.arr.to.length; ind++ ){ for(var ind = 0; ind < Data.arr.to.length; ind++ ){
var nRow = Data.arr.to[ind].getCellAddress().getRow0(), var nRow = Data.arr.to[ind].getCellAddress().getRow0(),
nCol = Data.arr.to[ind].getCellAddress().getCol0(); nCol = Data.arr.to[ind].getCellAddress().getCol0();
var c = ws._getCell(nRow, nCol) var c = ws._getCell(nRow, nCol)
if( c.sFormula ){ if( c.sFormula ){
this.wb.cwf[ws.Id].cells[c.getName()] = null; this.wb.cwf[ws.Id].cells[c.getName()] = null;
delete this.wb.cwf[ws.Id].cells[ c.getName()]; delete this.wb.cwf[ws.Id].cells[ c.getName()];
} }
var oTargetRow = ws._getRow(nRow); var oTargetRow = ws._getRow(nRow);
if(Data.arr.to[ind].isEmpty()){ if(Data.arr.to[ind].isEmpty()){
delete oTargetRow.c[nCol]; delete oTargetRow.c[nCol];
continue; continue;
...@@ -3171,20 +3190,20 @@ UndoRedoWoorksheet.prototype = { ...@@ -3171,20 +3190,20 @@ UndoRedoWoorksheet.prototype = {
} }
} }
} }
for(var ind = 0; ind < Data.arr.from.length; ind++ ){ for(var ind = 0; ind < Data.arr.from.length; ind++ ){
var nRow = Data.arr.from[ind].getCellAddress().getRow0(), var nRow = Data.arr.from[ind].getCellAddress().getRow0(),
nCol = Data.arr.from[ind].getCellAddress().getCol0(); nCol = Data.arr.from[ind].getCellAddress().getCol0();
var c = ws._getCell(nRow, nCol) var c = ws._getCell(nRow, nCol)
if( c.sFormula ){ if( c.sFormula ){
this.wb.cwf[ws.Id].cells[c.getName()] = null; this.wb.cwf[ws.Id].cells[c.getName()] = null;
delete this.wb.cwf[ws.Id].cells[ c.getName()]; delete this.wb.cwf[ws.Id].cells[ c.getName()];
} }
var oTargetRow = ws._getRow(nRow); var oTargetRow = ws._getRow(nRow);
if(Data.arr.from[ind].isEmpty()){ if(Data.arr.from[ind].isEmpty()){
delete oTargetRow.c[nCol]; delete oTargetRow.c[nCol];
continue; continue;
...@@ -3223,14 +3242,14 @@ UndoRedoWoorksheet.prototype = { ...@@ -3223,14 +3242,14 @@ UndoRedoWoorksheet.prototype = {
var worksheetView = this.wb.oApi.wb.getWorksheetById(nSheetId); var worksheetView = this.wb.oApi.wb.getWorksheetById(nSheetId);
worksheetView.autoFilters._moveAutoFilters(worksheetView ,null, null, g_oUndoRedoAutoFiltersMoveData); worksheetView.autoFilters._moveAutoFilters(worksheetView ,null, null, g_oUndoRedoAutoFiltersMoveData);
g_oUndoRedoAutoFiltersMoveData = null; g_oUndoRedoAutoFiltersMoveData = null;
} }
} }
else{ else{
if(false != this.wb.bCollaborativeChanges) if(false != this.wb.bCollaborativeChanges)
{ {
var collaborativeEditing = this.wb.oApi.collaborativeEditing, var collaborativeEditing = this.wb.oApi.collaborativeEditing,
nSheetId = ws.getId(), nSheetId = ws.getId(),
coBBoxTo = {r1:0,c1:0,r2:0,c2:0 }, coBBoxTo = {r1:0,c1:0,r2:0,c2:0 },
coBBoxFrom = {r1:0,c1:0,r2:0,c2:0 }; coBBoxFrom = {r1:0,c1:0,r2:0,c2:0 };
...@@ -3238,12 +3257,12 @@ UndoRedoWoorksheet.prototype = { ...@@ -3238,12 +3257,12 @@ UndoRedoWoorksheet.prototype = {
coBBoxTo.c1 = collaborativeEditing.getLockOtherColumn2( nSheetId, Data.to.c1); coBBoxTo.c1 = collaborativeEditing.getLockOtherColumn2( nSheetId, Data.to.c1);
coBBoxTo.r2 = collaborativeEditing.getLockOtherRow2( nSheetId, Data.to.r2); coBBoxTo.r2 = collaborativeEditing.getLockOtherRow2( nSheetId, Data.to.r2);
coBBoxTo.c2 = collaborativeEditing.getLockOtherColumn2( nSheetId, Data.to.c2); coBBoxTo.c2 = collaborativeEditing.getLockOtherColumn2( nSheetId, Data.to.c2);
coBBoxFrom.r1 = collaborativeEditing.getLockOtherRow2( nSheetId, Data.from.r1); coBBoxFrom.r1 = collaborativeEditing.getLockOtherRow2( nSheetId, Data.from.r1);
coBBoxFrom.c1 = collaborativeEditing.getLockOtherColumn2( nSheetId, Data.from.c1); coBBoxFrom.c1 = collaborativeEditing.getLockOtherColumn2( nSheetId, Data.from.c1);
coBBoxFrom.r2 = collaborativeEditing.getLockOtherRow2( nSheetId, Data.from.r2); coBBoxFrom.r2 = collaborativeEditing.getLockOtherRow2( nSheetId, Data.from.r2);
coBBoxFrom.c2 = collaborativeEditing.getLockOtherColumn2( nSheetId, Data.from.c2); coBBoxFrom.c2 = collaborativeEditing.getLockOtherColumn2( nSheetId, Data.from.c2);
ws._moveRange(coBBoxFrom, coBBoxTo); ws._moveRange(coBBoxFrom, coBBoxTo);
} }
else{ else{
...@@ -3484,7 +3503,7 @@ UndoRedoComment.prototype = { ...@@ -3484,7 +3503,7 @@ UndoRedoComment.prototype = {
var cellCommentator = ws.cellCommentator; var cellCommentator = ws.cellCommentator;
if ( bUndo == true ) if ( bUndo == true )
cellCommentator.Undo(Type, Data); cellCommentator.Undo(Type, Data);
else { else {
// CCommentData // CCommentData
if ( (Data.commentBefore == undefined) && (Data.commentAfter == undefined) ) { if ( (Data.commentBefore == undefined) && (Data.commentAfter == undefined) ) {
...@@ -3501,13 +3520,13 @@ UndoRedoComment.prototype = { ...@@ -3501,13 +3520,13 @@ UndoRedoComment.prototype = {
if ( !Data.commentAfter.bDocument ) { if ( !Data.commentAfter.bDocument ) {
if ( false != this.wb.bCollaborativeChanges ) { if ( false != this.wb.bCollaborativeChanges ) {
var collaborativeEditing = this.wb.oApi.collaborativeEditing; var collaborativeEditing = this.wb.oApi.collaborativeEditing;
Data.commentAfter.nRow = collaborativeEditing.getLockOtherRow2(nSheetId, Data.commentAfter.nRow); Data.commentAfter.nRow = collaborativeEditing.getLockOtherRow2(nSheetId, Data.commentAfter.nRow);
Data.commentAfter.nCol = collaborativeEditing.getLockOtherColumn2(nSheetId, Data.commentAfter.nCol); Data.commentAfter.nCol = collaborativeEditing.getLockOtherColumn2(nSheetId, Data.commentAfter.nCol);
} }
} }
} }
cellCommentator.Redo(Type, Data); cellCommentator.Redo(Type, Data);
} }
} }
......
...@@ -1110,17 +1110,15 @@ function unLockDraw(wb){ ...@@ -1110,17 +1110,15 @@ function unLockDraw(wb){
} }
} }
function buildRecalc(_wb){ function buildRecalc(_wb){
var wb = _wb, ws, ar; var ws;
if( lc > 1 ) return;
for( var id in arrRecalc ){ for( var id in arrRecalc ){
ws = wb.getWorksheetById(id); ws = _wb.getWorksheetById(id);
if (ws) { if (ws) {
ar = arrRecalc[id]; ws._BuildDependencies(arrRecalc[id]);
ws._BuildDependencies(ar);
} }
} }
recalc(wb) recalc(_wb)
} }
function searchCleenCacheArea(o1,o2){ function searchCleenCacheArea(o1,o2){
var o3 = {}; var o3 = {};
...@@ -1220,9 +1218,8 @@ function sortDependency(ws, ar){ ...@@ -1220,9 +1218,8 @@ function sortDependency(ws, ar){
} }
} }
function recalc(wb){ function recalc(wb){
var nR = wb.needRecalc, thas = wb, calculatedCells = new Object(), nRLength = nR.length, first = true,
var nR = wb.needRecalc, thas = wb, calculatedCells = {}, nRLength = nR.length, first = true, startActionOn = false, timerID, timeStart, timeEnd, timeCount = 0, timeoutID1, timeoutID2, sr = new Object();
startActionOn = false, timerID, timeStart, timeEnd, timeCount = 0, timeoutID1, timeoutID2, sr = {};
function R(){ function R(){
if( nR.length > 0 ){ if( nR.length > 0 ){
...@@ -1247,10 +1244,11 @@ function recalc(wb){ ...@@ -1247,10 +1244,11 @@ function recalc(wb){
sr2 = helpRecalc(dep1, nR, calculatedCells, thas); sr2 = helpRecalc(dep1, nR, calculatedCells, thas);
sr = searchCleenCacheArea(sr,searchCleenCacheArea(sr1,sr2)); sr = searchCleenCacheArea(sr,searchCleenCacheArea(sr1,sr2));
if( nR[id] ){ if ( nR[id] ) {
delete nR[id]; delete nR[id];
nR.length--; nR.length--;
} }
id = undefined;
} }
clearTimeout(timerID); clearTimeout(timerID);
timeEnd = (new Date()).getTime(); timeEnd = (new Date()).getTime();
...@@ -3216,7 +3214,23 @@ Woorksheet.prototype._removeCell=function(nRow, nCol, cell){ ...@@ -3216,7 +3214,23 @@ Woorksheet.prototype._removeCell=function(nRow, nCol, cell){
} }
this.helperRebuildFormulas(cell,cell.getName(),cell.getName()); this.helperRebuildFormulas(cell,cell.getName(),cell.getName());
var node = this.workbook.dependencyFormulas.getNodeByNodeId( getVertexId( this.Id, cell.getName() ) )
if ( node ) {
node = node.getSlaveEdges();
if ( node ) {
for ( var id in node ) {
if ( node[id].cell && node[id].cell.sFormula ){
History.Add(g_oUndoRedoWorksheet,
historyitem_Worksheet_RemoveCellFormula,
node[id].sheetId,
new Asc.Range(node[id].cell.oId.getCol0(), node[id].cell.oId.getRow0(), node[id].cell.oId.getCol0(), node[id].cell.oId.getRow0()),
new UndoRedoData_CellSimpleData(node[id].cell.oId.getRow0(), node[id].cell.oId.getCol0(), null, null, node[id].cell.sFormula));
}
}
}
}
if( !arrRecalc[this.getId()] ){ if( !arrRecalc[this.getId()] ){
arrRecalc[this.getId()] = {}; arrRecalc[this.getId()] = {};
} }
...@@ -3886,7 +3900,7 @@ Woorksheet.prototype.renameDependencyNodes = function(offset,oBBox,rec, noDelete ...@@ -3886,7 +3900,7 @@ Woorksheet.prototype.renameDependencyNodes = function(offset,oBBox,rec, noDelete
} }
} }
if ( false !== rec ) if ( false !== rec && lc <= 1 )
recalc(this.workbook); recalc(this.workbook);
} }
...@@ -4191,7 +4205,13 @@ Cell.prototype.setCellStyle=function(val){ ...@@ -4191,7 +4205,13 @@ Cell.prototype.setCellStyle=function(val){
this.oValue.cleanCache(); this.oValue.cleanCache();
}; };
Cell.prototype.setNumFormat=function(val){ Cell.prototype.setNumFormat=function(val){
var oRes = this.sm.setNumFormat(this, val); var oRes;
if( val == aStandartNumFormats[0] &&
this.formulaParsed && this.formulaParsed.value && this.formulaParsed.value.numFormat !== null &&
this.formulaParsed.value.numFormat !== undefined && aStandartNumFormats[this.formulaParsed.value.numFormat] )
oRes = this.sm.setNumFormat(this, aStandartNumFormats[this.formulaParsed.value.numFormat]);
else
oRes = this.sm.setNumFormat(this, val);
if(History.Is_On() && oRes.oldVal != oRes.newVal) if(History.Is_On() && oRes.oldVal != oRes.newVal)
History.Add(g_oUndoRedoCell, historyitem_Cell_Numformat, this.ws.getId(), new Asc.Range(0, this.oId.getRow0(), gc_nMaxCol0, this.oId.getRow0()), new UndoRedoData_CellSimpleData(this.oId.getRow0(), this.oId.getCol0(), oRes.oldVal, oRes.newVal)); History.Add(g_oUndoRedoCell, historyitem_Cell_Numformat, this.ws.getId(), new Asc.Range(0, this.oId.getRow0(), gc_nMaxCol0, this.oId.getRow0()), new UndoRedoData_CellSimpleData(this.oId.getRow0(), this.oId.getCol0(), oRes.oldVal, oRes.newVal));
this.bNeedCompileXfs = true; this.bNeedCompileXfs = true;
......
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