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

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

fix: Bug 20008 - Не восстанавливается содержимое формулы после Undo удаления строк, на которые ссылалась формула (http://bugzserver/show_bug.cgi?id=20008)

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@64378 954022d7-b5bf-4e40-9824-e11837661b57
parent 17306438
...@@ -2886,7 +2886,7 @@ UndoRedoWorkbook.prototype = { ...@@ -2886,7 +2886,7 @@ UndoRedoWorkbook.prototype = {
oldName = Data.oldName; oldName = Data.oldName;
newName = Data.newName; newName = Data.newName;
} }
res = this.wb.editDefinesNames( oldName, newName ); res = this.wb.editDefinesNames( oldName, newName, bUndo );
this.wb.handlers.trigger("asc_onEditDefName", oldName, newName); this.wb.handlers.trigger("asc_onEditDefName", oldName, newName);
} }
else if(historyitem_Workbook_DefinedNamesDelete === Type ){ else if(historyitem_Workbook_DefinedNamesDelete === Type ){
......
...@@ -242,10 +242,10 @@ DependencyGraph.prototype = { ...@@ -242,10 +242,10 @@ DependencyGraph.prototype = {
return this.nodeslength; return this.nodeslength;
}, },
checkOffset:function ( BBox, offset, wsId, noDelete ) { checkOffset:function ( BBox, offset, wsId, noDelete ) {
var _this = this; var _this = this,
var bHor = 0 != offset.offsetCol; bHor = 0 != offset.offsetCol,
var toDelete = offset.offsetCol < 0 || offset.offsetRow < 0; toDelete = offset.offsetCol < 0 || offset.offsetRow < 0,
var bSetRefErrorOld = this.bSetRefError; bSetRefErrorOld = this.bSetRefError;
this.bSetRefError = true; this.bSetRefError = true;
var oShiftGetBBox = shiftGetBBox(BBox, bHor); var oShiftGetBBox = shiftGetBBox(BBox, bHor);
var sShiftGetBBoxName = oShiftGetBBox.getName(); var sShiftGetBBoxName = oShiftGetBBox.getName();
...@@ -269,7 +269,7 @@ DependencyGraph.prototype = { ...@@ -269,7 +269,7 @@ DependencyGraph.prototype = {
for (var i in oSlaves) { for (var i in oSlaves) {
slave = oSlaves[i]; slave = oSlaves[i];
if( slave instanceof DefNameVertex ){ if( slave instanceof DefNameVertex ){
this.wb.delDefinesNames(slave.getAscCDefName()) this.wb.delDefinesNames(slave.getAscCDefName());
continue; continue;
} }
if (null == toDelete || slave != toDelete[slave.nodeId]) { if (null == toDelete || slave != toDelete[slave.nodeId]) {
...@@ -317,8 +317,7 @@ DependencyGraph.prototype = { ...@@ -317,8 +317,7 @@ DependencyGraph.prototype = {
elem.node.setFormula(elem.formula, true, false); elem.node.setFormula(elem.formula, true, false);
} }
}, },
_changeNode : function(node, from, to) _changeNode : function(node, from, to){
{
var toDelete = null == to; var toDelete = null == to;
var toAdd = null == from; var toAdd = null == from;
var wsId = node.sheetId; var wsId = node.sheetId;
...@@ -1021,6 +1020,12 @@ DependencyGraph.prototype = { ...@@ -1021,6 +1020,12 @@ DependencyGraph.prototype = {
} }
} }
} }
else{
oldN.deleteAllMasterEdges();
oldN.parsedRef = new parserFormula(oldN.Ref, "", oldN.wb.getWorksheet(0));
oldN.parsedRef.parse();
oldN.parsedRef.buildDependencies(null,oldN);
}
return oldN; return oldN;
}, },
...@@ -1077,10 +1082,10 @@ DependencyGraph.prototype = { ...@@ -1077,10 +1082,10 @@ DependencyGraph.prototype = {
return sNewName; return sNewName;
}, },
addTableName:function ( sName, ws, Ref ) { addTableName:function ( sName, ws, Ref ) {
var refClone = Ref.clone(true); var refClone = Ref.clone(true ), dfv, defNameSheetsList;
refClone.r1++; refClone.r1++;
var dfv = new DefNameVertex( null, sName, parserHelp.get3DRef( ws.getName(), refClone.getAbsName() ), null, this.wb, true ), dfv = new DefNameVertex( null, sName, parserHelp.get3DRef( ws.getName(), refClone.getAbsName() ), null, this.wb, true );
defNameSheetsList = this.defNameSheets[dfv.sheetId]; defNameSheetsList = this.defNameSheets[dfv.sheetId];
this.defNameList[dfv.nodeId] = dfv; this.defNameList[dfv.nodeId] = dfv;
if ( defNameSheetsList == null ) { if ( defNameSheetsList == null ) {
defNameSheetsList = {}; defNameSheetsList = {};
...@@ -1166,32 +1171,33 @@ Vertex.prototype = { ...@@ -1166,32 +1171,33 @@ Vertex.prototype = {
}, },
moveInner: function (bboxTo) { moveInner: function (bboxTo) {
//удаляем старые ссылки slave и master //удаляем старые ссылки slave и master
for (var i in this.slaveEdges) { var slave, master;
var slave = this.slaveEdges[i]; for (var i in this.slaveEdges) {
slave = this.slaveEdges[i];
slave.deleteMasterEdge(this); slave.deleteMasterEdge(this);
} }
for (var i in this.masterEdges) { for (var i in this.masterEdges) {
var master = this.masterEdges[i]; master = this.masterEdges[i];
master.deleteSlaveEdge(this); master.deleteSlaveEdge(this);
} }
var sOldNodeId = this.nodeId;
this.bbox = bboxTo; this.bbox = bboxTo;
this.cellId = bboxTo.getName(); this.cellId = bboxTo.getName();
this.nodeId = getVertexId(this.sheetId, this.cellId); this.nodeId = getVertexId(this.sheetId, this.cellId);
this.wb.needRecalc.nodes[this.nodeId] = [this.sheetId, this.cellId ]; this.wb.needRecalc.nodes[this.nodeId] = [this.sheetId, this.cellId];
this.wb.needRecalc.length++; this.wb.needRecalc.length++;
//добавляем новые slave и master //добавляем новые slave и master
for (var i in this.slaveEdges) { for (var i in this.slaveEdges) {
var slave = this.slaveEdges[i]; slave = this.slaveEdges[i];
slave.addMasterEdge(this); slave.addMasterEdge(this);
} }
for (var i in this.masterEdges) { for (var i in this.masterEdges) {
var master = this.masterEdges[i]; master = this.masterEdges[i];
master.addSlaveEdge(this); master.addSlaveEdge(this);
} }
}, },
moveOuter: function (from, to, oFormulas) { moveOuter: function (from, to, oFormulas) {
if ((from.r1 == to.r1 && from.c1 == to.c1) || (from.r2 == to.r2 && from.c2 == to.c2)) { if ((from.r1 == to.r1 && from.c1 == to.c1) || (from.r2 == to.r2 && from.c2 == to.c2)) {
/*вставляем/удаляем по вертикали/горизонтали внутри диапазона*/
var _sn = this.getSlaveEdges(), slave, cell; var _sn = this.getSlaveEdges(), slave, cell;
for (var _id in _sn) { for (var _id in _sn) {
slave = _sn[_id]; slave = _sn[_id];
...@@ -1221,6 +1227,7 @@ Vertex.prototype = { ...@@ -1221,6 +1227,7 @@ Vertex.prototype = {
} }
} }
else { else {
/*вставляем.удаляем левее/выше вне диапазона*/
if (oFormulas) { if (oFormulas) {
if (null == oFormulas[this.nodeId]) if (null == oFormulas[this.nodeId])
oFormulas[this.nodeId] = { node: this, formula: null }; oFormulas[this.nodeId] = { node: this, formula: null };
...@@ -1239,7 +1246,6 @@ Vertex.prototype = { ...@@ -1239,7 +1246,6 @@ Vertex.prototype = {
/*slave.parsedRef.shiftCells(this, from, to); /*slave.parsedRef.shiftCells(this, from, to);
slave.relinkRef();*/ slave.relinkRef();*/
if ( false == this.wb.bUndoChanges && (false == this.wb.bRedoChanges || true == this.wb.bCollaborativeChanges )){ if ( false == this.wb.bUndoChanges && (false == this.wb.bRedoChanges || true == this.wb.bCollaborativeChanges )){
History.LocalChange = true; History.LocalChange = true;
var oN = slave.getAscCDefName(), nN; var oN = slave.getAscCDefName(), nN;
...@@ -1358,7 +1364,8 @@ Vertex.prototype = { ...@@ -1358,7 +1364,8 @@ Vertex.prototype = {
{ {
var ws = this.wb.getWorksheetById(this.sheetId); var ws = this.wb.getWorksheetById(this.sheetId);
if(ws) if(ws)
this.cell = ws._getCellNoEmpty(this.bbox.r1, this.bbox.c1); this.cell = ws._getCell(this.bbox.r1, this.bbox.c1);
// this.cell = ws._getCellNoEmpty(this.bbox.r1, this.bbox.c1);
} }
return this.cell; return this.cell;
} }
...@@ -1546,24 +1553,16 @@ DefNameVertex.prototype = { ...@@ -1546,24 +1553,16 @@ DefNameVertex.prototype = {
//удаляем ребро между конкретной ведущей ячейки. //удаляем ребро между конкретной ведущей ячейки.
deleteMasterEdge:function ( node ) { deleteMasterEdge:function ( node ) {
if ( this.masterEdges ) { if ( this.masterEdges ) {
// if ( this.masterEdges[node.nodeId] ) { delete this.masterEdges[node.nodeId];
// this.masterEdges[node.nodeId] = null; this.refCount--;
delete this.masterEdges[node.nodeId];
// node.deleteSlaveEdge( this );
this.refCount--;
// }
} }
}, },
//удаляем ребро между конкретной зависимой(ведомой) ячейки. //удаляем ребро между конкретной зависимой(ведомой) ячейки.
deleteSlaveEdge:function ( node ) { deleteSlaveEdge:function ( node ) {
if ( this.slaveEdges ) { if ( this.slaveEdges ) {
// if ( this.slaveEdges[node.nodeId] ) { delete this.slaveEdges[node.nodeId];
// this.slaveEdges[node.nodeId] = null; this.refCount--;
delete this.slaveEdges[node.nodeId];
// node.deleteMasterEdge( this );
this.refCount--;
// }
} }
}, },
...@@ -2574,11 +2573,12 @@ Workbook.prototype.editDefinesNames = function ( oldName, newName, bUndo ) { ...@@ -2574,11 +2573,12 @@ Workbook.prototype.editDefinesNames = function ( oldName, newName, bUndo ) {
} }
if(retRes){ if(retRes){
// retRes.deleteAllSlaveEdges();
retRes = retRes.getAscCDefName(); retRes = retRes.getAscCDefName();
} }
sortDependency( this ); if(!bUndo){
sortDependency( this );
}
} }
...@@ -3318,6 +3318,8 @@ Woorksheet.prototype._removeRows=function(start, stop){ ...@@ -3318,6 +3318,8 @@ Woorksheet.prototype._removeRows=function(start, stop){
History.Create_NewPoint(); History.Create_NewPoint();
//start, stop 0 based //start, stop 0 based
var nDif = -(stop - start + 1); var nDif = -(stop - start + 1);
var oActualRange = {r1: start, c1: 0, r2: stop, c2: gc_nMaxCol0};
this.renameDependencyNodes({offsetRow:nDif,offsetCol:0}, oActualRange);
var i, j, length, nIndex, aIndexes = []; var i, j, length, nIndex, aIndexes = [];
for(i in this.aGCells) for(i in this.aGCells)
{ {
...@@ -3357,10 +3359,9 @@ Woorksheet.prototype._removeRows=function(start, stop){ ...@@ -3357,10 +3359,9 @@ Woorksheet.prototype._removeRows=function(start, stop){
} }
delete this.aGCells[nIndex]; delete this.aGCells[nIndex];
} }
History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_RemoveRows, this.getId(), new Asc.Range(0, start, gc_nMaxCol0, gc_nMaxRow0), new UndoRedoData_FromToRowCol(true, start, stop));
var oActualRange = {r1: start, c1: 0, r2: stop, c2: gc_nMaxCol0};
this.renameDependencyNodes({offsetRow:nDif,offsetCol:0}, oActualRange); History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_RemoveRows, this.getId(), new Asc.Range(0, start, gc_nMaxCol0, gc_nMaxRow0), new UndoRedoData_FromToRowCol(true, start, stop));
buildRecalc(this.workbook); buildRecalc(this.workbook);
unLockDraw(this.workbook); unLockDraw(this.workbook);
...@@ -3378,6 +3379,7 @@ Woorksheet.prototype._insertRowsBefore=function(index, count){ ...@@ -3378,6 +3379,7 @@ Woorksheet.prototype._insertRowsBefore=function(index, count){
lockDraw(this.workbook); lockDraw(this.workbook);
var oActualRange = {r1: index, c1: 0, r2: index + count - 1, c2: gc_nMaxCol0}; var oActualRange = {r1: index, c1: 0, r2: index + count - 1, c2: gc_nMaxCol0};
History.Create_NewPoint(); History.Create_NewPoint();
this.renameDependencyNodes({offsetRow:count,offsetCol:0},oActualRange);
History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_AddRows, this.getId(), new Asc.Range(0, index, gc_nMaxCol0, gc_nMaxRow0), new UndoRedoData_FromToRowCol(true, index, index + count - 1)); History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_AddRows, this.getId(), new Asc.Range(0, index, gc_nMaxCol0, gc_nMaxRow0), new UndoRedoData_FromToRowCol(true, index, index + count - 1));
//index 0 based //index 0 based
var aIndexes = []; var aIndexes = [];
...@@ -3416,7 +3418,7 @@ Woorksheet.prototype._insertRowsBefore=function(index, count){ ...@@ -3416,7 +3418,7 @@ Woorksheet.prototype._insertRowsBefore=function(index, count){
} }
History.LocalChange = false; History.LocalChange = false;
} }
this.renameDependencyNodes({offsetRow:count,offsetCol:0},oActualRange);
buildRecalc(this.workbook); buildRecalc(this.workbook);
unLockDraw(this.workbook); unLockDraw(this.workbook);
...@@ -3448,6 +3450,8 @@ Woorksheet.prototype._removeCols=function(start, stop){ ...@@ -3448,6 +3450,8 @@ Woorksheet.prototype._removeCols=function(start, stop){
History.Create_NewPoint(); History.Create_NewPoint();
//start, stop 0 based //start, stop 0 based
var nDif = -(stop - start + 1), i, j, length, nIndex; var nDif = -(stop - start + 1), i, j, length, nIndex;
var oActualRange = { r1: 0, c1: start, r2: gc_nMaxRow0, c2: stop };
this.renameDependencyNodes({ offsetRow: 0, offsetCol: nDif }, oActualRange);
for(i in this.aGCells) for(i in this.aGCells)
{ {
var nRowIndex = i - 0; var nRowIndex = i - 0;
...@@ -3496,10 +3500,8 @@ Woorksheet.prototype._removeCols=function(start, stop){ ...@@ -3496,10 +3500,8 @@ Woorksheet.prototype._removeCols=function(start, stop){
elem.moveHor(nDif); elem.moveHor(nDif);
} }
History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_RemoveCols, this.getId(), new Asc.Range(start, 0, gc_nMaxCol0, gc_nMaxRow0), new UndoRedoData_FromToRowCol(false, start, stop));
var oActualRange = { r1: 0, c1: start, r2: gc_nMaxRow0, c2: stop }; History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_RemoveCols, this.getId(), new Asc.Range(start, 0, gc_nMaxCol0, gc_nMaxRow0), new UndoRedoData_FromToRowCol(false, start, stop));
this.renameDependencyNodes({ offsetRow: 0, offsetCol: nDif }, oActualRange);
buildRecalc(this.workbook); buildRecalc(this.workbook);
unLockDraw(this.workbook); unLockDraw(this.workbook);
...@@ -3517,7 +3519,8 @@ Woorksheet.prototype._insertColsBefore=function(index, count){ ...@@ -3517,7 +3519,8 @@ Woorksheet.prototype._insertColsBefore=function(index, count){
lockDraw(this.workbook); lockDraw(this.workbook);
var oActualRange = {r1: 0, c1: index, r2: gc_nMaxRow0, c2: index + count - 1}; var oActualRange = {r1: 0, c1: index, r2: gc_nMaxRow0, c2: index + count - 1};
History.Create_NewPoint(); History.Create_NewPoint();
History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_AddCols, this.getId(), new Asc.Range(index, 0, gc_nMaxCol0, gc_nMaxRow0), new UndoRedoData_FromToRowCol(false, index, index + count - 1)); this.renameDependencyNodes({offsetRow:0,offsetCol:count},oActualRange);
History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_AddCols, this.getId(), new Asc.Range(index, 0, gc_nMaxCol0, gc_nMaxRow0), new UndoRedoData_FromToRowCol(false, index, index + count - 1));
//index 0 based //index 0 based
for(var i in this.aGCells) for(var i in this.aGCells)
{ {
...@@ -3539,7 +3542,7 @@ Woorksheet.prototype._insertColsBefore=function(index, count){ ...@@ -3539,7 +3542,7 @@ Woorksheet.prototype._insertColsBefore=function(index, count){
} }
} }
this.renameDependencyNodes({offsetRow:0,offsetCol:count},oActualRange);
buildRecalc(this.workbook); buildRecalc(this.workbook);
unLockDraw(this.workbook); unLockDraw(this.workbook);
...@@ -4415,9 +4418,9 @@ Woorksheet.prototype._shiftCellsLeft=function(oBBox){ ...@@ -4415,9 +4418,9 @@ Woorksheet.prototype._shiftCellsLeft=function(oBBox){
} }
} }
} }
History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_ShiftCellsLeft, this.getId(), new Asc.Range(nLeft, oBBox.r1, gc_nMaxCol0, oBBox.r2), new UndoRedoData_BBox(oBBox)); this.renameDependencyNodes( {offsetRow:0,offsetCol:dif}, oBBox );
this.renameDependencyNodes( {offsetRow:0,offsetCol:dif}, oBBox ); History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_ShiftCellsLeft, this.getId(), new Asc.Range(nLeft, oBBox.r1, gc_nMaxCol0, oBBox.r2), new UndoRedoData_BBox(oBBox));
//todo проверить не уменьшились ли границы таблицы //todo проверить не уменьшились ли границы таблицы
}; };
Woorksheet.prototype._shiftCellsUp=function(oBBox){ Woorksheet.prototype._shiftCellsUp=function(oBBox){
...@@ -4458,9 +4461,9 @@ Woorksheet.prototype._shiftCellsUp=function(oBBox){ ...@@ -4458,9 +4461,9 @@ Woorksheet.prototype._shiftCellsUp=function(oBBox){
} }
} }
History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_ShiftCellsTop, this.getId(), new Asc.Range(oBBox.c1, oBBox.r1, oBBox.c2, gc_nMaxRow0), new UndoRedoData_BBox(oBBox)); this.renameDependencyNodes({offsetRow:dif,offsetCol:0}, oBBox );
this.renameDependencyNodes({offsetRow:dif,offsetCol:0}, oBBox ); History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_ShiftCellsTop, this.getId(), new Asc.Range(oBBox.c1, oBBox.r1, oBBox.c2, gc_nMaxRow0), new UndoRedoData_BBox(oBBox));
//todo проверить не уменьшились ли границы таблицы //todo проверить не уменьшились ли границы таблицы
}; };
Woorksheet.prototype._shiftCellsRight=function(oBBox){ Woorksheet.prototype._shiftCellsRight=function(oBBox){
...@@ -4495,9 +4498,9 @@ Woorksheet.prototype._shiftCellsRight=function(oBBox){ ...@@ -4495,9 +4498,9 @@ Woorksheet.prototype._shiftCellsRight=function(oBBox){
} }
} }
} }
History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_ShiftCellsRight, this.getId(), new Asc.Range(oBBox.c1, oBBox.r1, gc_nMaxCol0, oBBox.r2), new UndoRedoData_BBox(oBBox)); this.renameDependencyNodes({offsetRow:0,offsetCol:dif}, oBBox);
this.renameDependencyNodes({offsetRow:0,offsetCol:dif}, oBBox); History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_ShiftCellsRight, this.getId(), new Asc.Range(oBBox.c1, oBBox.r1, gc_nMaxCol0, oBBox.r2), new UndoRedoData_BBox(oBBox));
}; };
Woorksheet.prototype._shiftCellsBottom=function(oBBox){ Woorksheet.prototype._shiftCellsBottom=function(oBBox){
//до перемещения ячеек, перед функцией, в которой используются nodesSheetArea/nodesSheetCell move/shift нужно обязательно вызвать force buildRecalc //до перемещения ячеек, перед функцией, в которой используются nodesSheetArea/nodesSheetCell move/shift нужно обязательно вызвать force buildRecalc
...@@ -4529,9 +4532,9 @@ Woorksheet.prototype._shiftCellsBottom=function(oBBox){ ...@@ -4529,9 +4532,9 @@ Woorksheet.prototype._shiftCellsBottom=function(oBBox){
} }
} }
} }
History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_ShiftCellsBottom, this.getId(), new Asc.Range(oBBox.c1, oBBox.r1, oBBox.c2, gc_nMaxRow0), new UndoRedoData_BBox(oBBox)); this.renameDependencyNodes({offsetRow:dif,offsetCol:0}, oBBox);
this.renameDependencyNodes({offsetRow:dif,offsetCol:0}, oBBox); History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_ShiftCellsBottom, this.getId(), new Asc.Range(oBBox.c1, oBBox.r1, oBBox.c2, gc_nMaxRow0), new UndoRedoData_BBox(oBBox));
}; };
Woorksheet.prototype._setIndex=function(ind){ Woorksheet.prototype._setIndex=function(ind){
this.index = ind; this.index = ind;
...@@ -4561,11 +4564,11 @@ Woorksheet.prototype._BuildDependencies=function(cellRange){ ...@@ -4561,11 +4564,11 @@ Woorksheet.prototype._BuildDependencies=function(cellRange){
var aCache = []; var aCache = [];
for(var j = 0, length2 = temp.length; j < length2; j++) for(var j = 0, length2 = temp.length; j < length2; j++)
{ {
var c = temp[j]; var c = temp[j],
var cellId = g_oCellAddressUtils.getCellId(c.nRow, c.nCol); cellId = g_oCellAddressUtils.getCellId(c.nRow, c.nCol ),
var aRefs = []; aRefs = [],
var cache = inCache(aCache, c.sFormula, aRefs); cache = inCache(aCache, c.sFormula, aRefs ),
var bInCache = false; bInCache = false;
if(cache) if(cache)
{ {
bInCache = true; bInCache = 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