Commit 797a4294 authored by konovalovsergey's avatar konovalovsergey

removeWorksheet, replaceWorksheet bugs

parent 5da40db3
...@@ -1866,7 +1866,7 @@ var editor; ...@@ -1866,7 +1866,7 @@ var editor;
History.Create_NewPoint(); History.Create_NewPoint();
History.StartTransaction(); History.StartTransaction();
t.wbModel.dependencyFormulas.lockRecal();
// Нужно проверить все диаграммы, ссылающиеся на удаляемый лист // Нужно проверить все диаграммы, ссылающиеся на удаляемый лист
for (var key in t.wb.model.aWorksheets) { for (var key in t.wb.model.aWorksheets) {
var wsModel = t.wb.model.aWorksheets[key]; var wsModel = t.wb.model.aWorksheets[key];
...@@ -1889,6 +1889,7 @@ var editor; ...@@ -1889,6 +1889,7 @@ var editor;
// Посылаем callback об изменении списка листов // Посылаем callback об изменении списка листов
t.sheetsChanged(); t.sheetsChanged();
} }
t.wbModel.dependencyFormulas.unlockRecal();
History.EndTransaction(); History.EndTransaction();
} }
}; };
......
...@@ -449,6 +449,32 @@ function getRangeType(oBBox){ ...@@ -449,6 +449,32 @@ function getRangeType(oBBox){
listeners[listenerId].notify(notifyData); listeners[listenerId].notify(notifyData);
} }
}, },
removeSheet: function(sheetId, tableNames) {
//cells
var sheet = this.wb.getWorksheetById(sheetId);
var range = sheet.getRange3(0, 0, gc_nMaxRow0, gc_nMaxCol0);
range._setPropertyNoEmpty(null, null, function(cell){
if (cell.formulaParsed) {
cell.formulaParsed.removeDependencies();
}
});
//defnames
var sheetContainerFrom = this.defNames.sheet[sheetId];
if (sheetContainerFrom) {
for (var name in sheetContainerFrom) {
var defNameOld = sheetContainerFrom[name];
if (!defNameOld.isTable) {
this._removeDefName(sheetId, name, AscCH.historyitem_Workbook_DefinedNamesChangeUndo);
}
}
}
//tables
for (var i = 0; i < tableNames.length; ++i) {
this._delDefName(tableNames[i], null);
}
//dependence
this.changeSheet(sheetId, {remove: sheetId});
},
//lock //lock
lockRecal: function() { lockRecal: function() {
++this.lockCounter; ++this.lockCounter;
...@@ -547,15 +573,7 @@ function getRangeType(oBBox){ ...@@ -547,15 +573,7 @@ function getRangeType(oBBox){
}, },
removeDefName: function(sheetIndex, name) { removeDefName: function(sheetIndex, name) {
var sheetId = this.wb.getSheetIdByIndex(sheetIndex); var sheetId = this.wb.getSheetIdByIndex(sheetIndex);
var defName = this._delDefName(name, sheetId); this._removeDefName(sheetId, name, AscCH.historyitem_Workbook_DefinedNamesChange);
if (defName) {
History.Create_NewPoint();
History.Add(AscCommonExcel.g_oUndoRedoWorkbook, AscCH.historyitem_Workbook_DefinedNamesChange, null,
null, new UndoRedoData_DefinedNamesChange(defName.getAscCDefName(), null));
defName.removeDependencies();
this.addToChangedDefName(defName);
}
}, },
editDefinesNames: function(oldAscName, newAscName) { editDefinesNames: function(oldAscName, newAscName) {
var res = null; var res = null;
...@@ -864,7 +882,7 @@ function getRangeType(oBBox){ ...@@ -864,7 +882,7 @@ function getRangeType(oBBox){
for (var i = 0; i < worksheets.length; ++i) { for (var i = 0; i < worksheets.length; ++i) {
var ws = worksheets[i]; var ws = worksheets[i];
if (ws) { if (ws) {
var cwf = ws.getCWF(); var cwf = ws.getCwf();
for (var i in cwf) { for (var i in cwf) {
var ca = g_oCellAddressUtils.getCellAddress(i); var ca = g_oCellAddressUtils.getCellAddress(i);
var c = ws._getCellNoEmpty(ca.getRow0(), ca.getCol0()); var c = ws._getCellNoEmpty(ca.getRow0(), ca.getCol0());
...@@ -894,6 +912,17 @@ function getRangeType(oBBox){ ...@@ -894,6 +912,17 @@ function getRangeType(oBBox){
} }
container[nameIndex] = defName; container[nameIndex] = defName;
}, },
_removeDefName: function(sheetId, name, historyType) {
var defName = this._delDefName(name, sheetId);
if (defName) {
History.Create_NewPoint();
History.Add(AscCommonExcel.g_oUndoRedoWorkbook, historyType, null, null,
new UndoRedoData_DefinedNamesChange(defName.getAscCDefName(), null));
defName.removeDependencies();
this.addToChangedDefName(defName);
}
},
_delDefName: function(name, sheetId) { _delDefName: function(name, sheetId) {
var res = null; var res = null;
var nameIndex = getDefNameIndex(name); var nameIndex = getDefNameIndex(name);
...@@ -1402,20 +1431,16 @@ Workbook.prototype.copyWorksheet=function(index, insertBefore, sName, sId, bFrom ...@@ -1402,20 +1431,16 @@ Workbook.prototype.copyWorksheet=function(index, insertBefore, sName, sId, bFrom
this.aWorksheetsById[newSheet.getId()] = newSheet; this.aWorksheetsById[newSheet.getId()] = newSheet;
this._updateWorksheetIndexes(wsActive); this._updateWorksheetIndexes(wsActive);
History.TurnOn(); History.TurnOn();
//now insertBefore is index of inserted sheet
this._insertWorksheetFormula(insertBefore); this._insertWorksheetFormula(insertBefore);
this.dependencyFormulas.copyDefNameByWorksheet(wsFrom, newSheet); this.dependencyFormulas.copyDefNameByWorksheet(wsFrom, newSheet);
//для формул. создаем копию this.cwf[this.Id] для нового листа. //для формул. создаем копию this.cwf[this.Id] для нового листа.
newSheet._BuildDependencies(wsFrom.getCWF()); newSheet._BuildDependencies(wsFrom.getCwf());
if(!tableNames && newSheet.TableParts && newSheet.TableParts.length) if (!tableNames) {
{ tableNames = newSheet.getTableNames();
tableNames = [];
for(var i = 0; i < newSheet.TableParts.length; i++)
{
tableNames.push(newSheet.TableParts[i].DisplayName);
}
} }
History.Add(AscCommonExcel.g_oUndoRedoWorkbook, AscCH.historyitem_Workbook_SheetAdd, null, null, new UndoRedoData_SheetAdd(insertBefore, newSheet.getName(), wsFrom.getId(), newSheet.getId(), tableNames)); History.Add(AscCommonExcel.g_oUndoRedoWorkbook, AscCH.historyitem_Workbook_SheetAdd, null, null, new UndoRedoData_SheetAdd(insertBefore, newSheet.getName(), wsFrom.getId(), newSheet.getId(), tableNames));
...@@ -1443,7 +1468,7 @@ Workbook.prototype.insertWorksheet = function (index, sheet) { ...@@ -1443,7 +1468,7 @@ Workbook.prototype.insertWorksheet = function (index, sheet) {
this._insertWorksheetFormula(index); this._insertWorksheetFormula(index);
this._insertTablePartsName(sheet); this._insertTablePartsName(sheet);
//восстанавливаем список ячеек с формулами для sheet //восстанавливаем список ячеек с формулами для sheet
sheet._BuildDependencies(sheet.getCWF()); sheet._BuildDependencies(sheet.getCwf());
this.sortDependency(); this.sortDependency();
}; };
Workbook.prototype._insertTablePartsName = function (sheet) { Workbook.prototype._insertTablePartsName = function (sheet) {
...@@ -1464,7 +1489,6 @@ Workbook.prototype._insertWorksheetFormula=function(index){ ...@@ -1464,7 +1489,6 @@ Workbook.prototype._insertWorksheetFormula=function(index){
Workbook.prototype.replaceWorksheet=function(indexFrom, indexTo){ Workbook.prototype.replaceWorksheet=function(indexFrom, indexTo){
if(indexFrom >= 0 && indexFrom < this.aWorksheets.length && if(indexFrom >= 0 && indexFrom < this.aWorksheets.length &&
indexTo >= 0 && indexTo < this.aWorksheets.length){ indexTo >= 0 && indexTo < this.aWorksheets.length){
History.TurnOff();
var wsActive = this.getActiveWs(); var wsActive = this.getActiveWs();
var oWsFrom = this.aWorksheets[indexFrom]; var oWsFrom = this.aWorksheets[indexFrom];
var tempW = { var tempW = {
...@@ -1478,7 +1502,6 @@ Workbook.prototype.replaceWorksheet=function(indexFrom, indexTo){ ...@@ -1478,7 +1502,6 @@ Workbook.prototype.replaceWorksheet=function(indexFrom, indexTo){
tempW.wTI++; tempW.wTI++;
this.dependencyFormulas.lockRecal(); this.dependencyFormulas.lockRecal();
this.dependencyFormulas.changeSheet(tempW.wFId, {replace: tempW}); this.dependencyFormulas.changeSheet(tempW.wFId, {replace: tempW});
History.TurnOn();
var movedSheet = this.aWorksheets.splice(indexFrom, 1); var movedSheet = this.aWorksheets.splice(indexFrom, 1);
this.aWorksheets.splice(indexTo, 0, movedSheet[0]); this.aWorksheets.splice(indexTo, 0, movedSheet[0]);
this._updateWorksheetIndexes(wsActive); this._updateWorksheetIndexes(wsActive);
...@@ -1529,10 +1552,9 @@ Workbook.prototype.removeWorksheet=function(nIndex, outputParams){ ...@@ -1529,10 +1552,9 @@ Workbook.prototype.removeWorksheet=function(nIndex, outputParams){
var removedSheet = this.getWorksheet(nIndex); var removedSheet = this.getWorksheet(nIndex);
if(removedSheet) if(removedSheet)
{ {
History.Create_NewPoint();
var removedSheetId = removedSheet.getId(); var removedSheetId = removedSheet.getId();
this.dependencyFormulas.lockRecal(); this.dependencyFormulas.lockRecal();
this.dependencyFormulas.changeSheet(removedSheetId, {remove: removedSheetId}); this.dependencyFormulas.removeSheet(removedSheetId, removedSheet.getTableNames());
var wsActive = this.getActiveWs(); var wsActive = this.getActiveWs();
var oVisibleWs = null; var oVisibleWs = null;
...@@ -1543,7 +1565,6 @@ Workbook.prototype.removeWorksheet=function(nIndex, outputParams){ ...@@ -1543,7 +1565,6 @@ Workbook.prototype.removeWorksheet=function(nIndex, outputParams){
if (null != oVisibleWs) if (null != oVisibleWs)
wsActive = oVisibleWs; wsActive = oVisibleWs;
} }
var _cwf = null;
History.Add(AscCommonExcel.g_oUndoRedoWorkbook, AscCH.historyitem_Workbook_SheetRemove, null, null, new AscCommonExcel.UndoRedoData_SheetRemove(nIndex, removedSheetId, removedSheet)); History.Add(AscCommonExcel.g_oUndoRedoWorkbook, AscCH.historyitem_Workbook_SheetRemove, null, null, new AscCommonExcel.UndoRedoData_SheetRemove(nIndex, removedSheetId, removedSheet));
if (null != oVisibleWs) { if (null != oVisibleWs) {
History.SetSheetUndo(removedSheetId); History.SetSheetUndo(removedSheetId);
...@@ -4019,6 +4040,15 @@ Woorksheet.prototype.getTableNameColumnByIndex = function(tableName, columnIndex ...@@ -4019,6 +4040,15 @@ Woorksheet.prototype.getTableNameColumnByIndex = function(tableName, columnIndex
} }
return res; return res;
}; };
Woorksheet.prototype.getTableNames = function() {
var res = [];
if (this.TableParts) {
for (var i = 0; i < this.TableParts.length; i++) {
res.push(this.TableParts[i].DisplayName);
}
}
return res;
};
Woorksheet.prototype.renameDependencyNodes = function(offset, oBBox, rec, noDelete){ Woorksheet.prototype.renameDependencyNodes = function(offset, oBBox, rec, noDelete){
this.workbook.dependencyFormulas.shift(this.Id, oBBox, offset); this.workbook.dependencyFormulas.shift(this.Id, oBBox, offset);
}; };
...@@ -4099,7 +4129,7 @@ Woorksheet.prototype.updateSparklineCache = function(sheet, ranges) { ...@@ -4099,7 +4129,7 @@ Woorksheet.prototype.updateSparklineCache = function(sheet, ranges) {
this.aSparklineGroups[i].updateCache(sheet, ranges); this.aSparklineGroups[i].updateCache(sheet, ranges);
} }
}; };
Woorksheet.prototype.getCWF = function() { Woorksheet.prototype.getCwf = function() {
var cwf = {}; var cwf = {};
var range = this.getRange3(0,0, gc_nMaxRow0, gc_nMaxCol0); var range = this.getRange3(0,0, gc_nMaxRow0, gc_nMaxCol0);
range._setPropertyNoEmpty(null, null, function(cell){ range._setPropertyNoEmpty(null, null, function(cell){
......
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