Commit ef40722d authored by konovalovsergey's avatar konovalovsergey

add function Workbook.recalcWB for test reason

parent c71c2431
...@@ -3996,6 +3996,11 @@ parserFormula.prototype.setFormula = function(formula) { ...@@ -3996,6 +3996,11 @@ parserFormula.prototype.setFormula = function(formula) {
this.parenthesesNotEnough = false; this.parenthesesNotEnough = false;
this.f = []; this.f = [];
this.countRef = 0; this.countRef = 0;
this.ca = false;
this.isDirty = false;
this.isCalculate = false;
this.isTable = false;
this.isInDependencies = false;
}; };
parserFormula.prototype.parse = function(local, digitDelim) { parserFormula.prototype.parse = function(local, digitDelim) {
......
...@@ -838,6 +838,12 @@ ...@@ -838,6 +838,12 @@
this.cleanCellCache[sheetId] = Asc.Range(col, row, col, row); this.cleanCellCache[sheetId] = Asc.Range(col, row, col, row);
} }
}, },
notifyChanged: function(changedFormulas) {
var notifyData = {type: AscCommon.c_oNotifyType.Changed};
for (var listenerId in changedFormulas) {
changedFormulas[listenerId].notify(notifyData);
}
},
//build, calc //build, calc
buildDependency: function() { buildDependency: function() {
for (var sheetId in this.buildCell) { for (var sheetId in this.buildCell) {
...@@ -897,29 +903,6 @@ ...@@ -897,29 +903,6 @@
AscCommonExcel.g_oVLOOKUPCache.clean(); AscCommonExcel.g_oVLOOKUPCache.clean();
AscCommonExcel.g_oHLOOKUPCache.clean(); AscCommonExcel.g_oHLOOKUPCache.clean();
}, },
calcAll: function(sheetId){
var worksheets = [];
if (sheetId) {
worksheets.push(this.wb.getWorksheetById(sheetId));
} else {
var wsCount = this.wb.getWorksheetCount();
for (var i = 0; i < wsCount; ++i) {
worksheets.push(this.wb.getWorksheet(i));
}
}
for (var i = 0; i < worksheets.length; ++i) {
var ws = worksheets[i];
if (ws) {
var cwf = ws.getCwf();
for (var i in cwf) {
var ca = g_oCellAddressUtils.getCellAddress(i);
var c = ws._getCellNoEmpty(ca.getRow0(), ca.getCol0());
this.addToChangedCell(c);
}
}
}
this.calcTree();
},
initOpen: function() { initOpen: function() {
this._foreachDefName(function(defName) { this._foreachDefName(function(defName) {
defName.setRef(defName.ref, true, true); defName.setRef(defName.ref, true, true);
...@@ -935,6 +918,13 @@ ...@@ -935,6 +918,13 @@
res.tableNameIndex = this.tableNameIndex; res.tableNameIndex = this.tableNameIndex;
return res; return res;
}, },
getAllFormulas: function(formulas) {
this._foreachDefName(function(defName) {
if (!defName.isTable && defName.parsedRef) {
formulas.push(defName.parsedRef);
}
});
},
//internal //internal
_addDefName: function(defName) { _addDefName: function(defName) {
var nameIndex = getDefNameIndex(defName.name); var nameIndex = getDefNameIndex(defName.name);
...@@ -1766,8 +1756,26 @@ ...@@ -1766,8 +1756,26 @@
this.aWorksheets[i].reassignImageUrls(oImages); this.aWorksheets[i].reassignImageUrls(oImages);
} }
}; };
Workbook.prototype.recalcWB = function(isRecalcWB){ Workbook.prototype.recalcWB = function(rebuild, opt_sheetId) {
//todo var formulas;
if (rebuild) {
formulas = this.getAllFormulas();
for (var i = 0; i < formulas.length; ++i) {
var formula = formulas[i];
formula.removeDependencies();
formula.setFormula(formula.getFormula());
formula.parse();
formula.buildDependencies();
}
} else if (opt_sheetId) {
formulas = [];
var ws = this.wb.getWorksheetById(opt_sheetId);
ws.getAllFormulas(formulas);
} else {
formulas = this.getAllFormulas();
}
this.dependencyFormulas.notifyChanged(formulas);
this.dependencyFormulas.calcTree();
}; };
Workbook.prototype.checkDefName = function (checkName, scope) { Workbook.prototype.checkDefName = function (checkName, scope) {
return this.dependencyFormulas.checkDefName(checkName, scope); return this.dependencyFormulas.checkDefName(checkName, scope);
...@@ -1854,6 +1862,14 @@ ...@@ -1854,6 +1862,14 @@
wb.init({}, true, false); wb.init({}, true, false);
return wb; return wb;
}; };
Workbook.prototype.getAllFormulas = function() {
var res = [];
this.dependencyFormulas.getAllFormulas(res);
for (var i = 0; i < this.aWorksheets.length; ++i) {
this.aWorksheets[i].getAllFormulas(res);
}
return res;
};
Workbook.prototype._forwardTransformation = function(wbSnapshot, changesMine, changesTheir) { Workbook.prototype._forwardTransformation = function(wbSnapshot, changesMine, changesTheir) {
History.TurnOff(); History.TurnOff();
//first mine changes to resolve conflict sheet names //first mine changes to resolve conflict sheet names
...@@ -3048,8 +3064,8 @@ ...@@ -3048,8 +3064,8 @@
} }
delete this.aGCells[nIndex]; delete this.aGCells[nIndex];
} }
//renameDependencyNodesChanged after move cells to get new locations //notifyChanged after move cells to get new locations
this.renameDependencyNodesChanged(changedFormulas); this.workbook.dependencyFormulas.notifyChanged(changedFormulas);
History.Add(AscCommonExcel.g_oUndoRedoWorksheet, AscCH.historyitem_Worksheet_RemoveRows, this.getId(), new Asc.Range(0, start, gc_nMaxCol0, gc_nMaxRow0), new UndoRedoData_FromToRowCol(true, start, stop)); History.Add(AscCommonExcel.g_oUndoRedoWorksheet, AscCH.historyitem_Worksheet_RemoveRows, this.getId(), new Asc.Range(0, start, gc_nMaxCol0, gc_nMaxRow0), new UndoRedoData_FromToRowCol(true, start, stop));
this.autoFilters.insertRows( "delCell", new Asc.Range(0, start, gc_nMaxCol0, stop), c_oAscDeleteOptions.DeleteRows ); this.autoFilters.insertRows( "delCell", new Asc.Range(0, start, gc_nMaxCol0, stop), c_oAscDeleteOptions.DeleteRows );
...@@ -3104,8 +3120,8 @@ ...@@ -3104,8 +3120,8 @@
} }
History.LocalChange = false; History.LocalChange = false;
} }
//renameDependencyNodesChanged after move cells to get new locations //notifyChanged after move cells to get new locations
this.renameDependencyNodesChanged(changedFormulas); this.workbook.dependencyFormulas.notifyChanged(changedFormulas);
History.Add(AscCommonExcel.g_oUndoRedoWorksheet, AscCH.historyitem_Worksheet_AddRows, this.getId(), new Asc.Range(0, index, gc_nMaxCol0, gc_nMaxRow0), new UndoRedoData_FromToRowCol(true, index, index + count - 1)); History.Add(AscCommonExcel.g_oUndoRedoWorksheet, AscCH.historyitem_Worksheet_AddRows, this.getId(), new Asc.Range(0, index, gc_nMaxCol0, gc_nMaxRow0), new UndoRedoData_FromToRowCol(true, index, index + count - 1));
this.autoFilters.insertRows( "insCell", new Asc.Range(0, index, gc_nMaxCol0, index + count - 1), c_oAscInsertOptions.InsertColumns ); this.autoFilters.insertRows( "insCell", new Asc.Range(0, index, gc_nMaxCol0, index + count - 1), c_oAscInsertOptions.InsertColumns );
...@@ -3185,8 +3201,8 @@ ...@@ -3185,8 +3201,8 @@
if(null != elem) if(null != elem)
elem.moveHor(nDif); elem.moveHor(nDif);
} }
//renameDependencyNodesChanged after move cells to get new locations //notifyChanged after move cells to get new locations
this.renameDependencyNodesChanged(changedFormulas); this.workbook.dependencyFormulas.notifyChanged(changedFormulas);
History.Add(AscCommonExcel.g_oUndoRedoWorksheet, AscCH.historyitem_Worksheet_RemoveCols, this.getId(), new Asc.Range(start, 0, gc_nMaxCol0, gc_nMaxRow0), new UndoRedoData_FromToRowCol(false, start, stop)); History.Add(AscCommonExcel.g_oUndoRedoWorksheet, AscCH.historyitem_Worksheet_RemoveCols, this.getId(), new Asc.Range(start, 0, gc_nMaxCol0, gc_nMaxRow0), new UndoRedoData_FromToRowCol(false, start, stop));
this.autoFilters.insertColumn( "delCell", new Asc.Range(start, 0, stop, gc_nMaxRow0), c_oAscInsertOptions.InsertColumns ); this.autoFilters.insertColumn( "delCell", new Asc.Range(start, 0, stop, gc_nMaxRow0), c_oAscInsertOptions.InsertColumns );
...@@ -3224,8 +3240,8 @@ ...@@ -3224,8 +3240,8 @@
this._moveCellHor(nRowIndex, nIndex, count, oActualRange); this._moveCellHor(nRowIndex, nIndex, count, oActualRange);
} }
} }
//renameDependencyNodesChanged after move cells to get new locations //notifyChanged after move cells to get new locations
this.renameDependencyNodesChanged(changedFormulas); this.workbook.dependencyFormulas.notifyChanged(changedFormulas);
History.Add(AscCommonExcel.g_oUndoRedoWorksheet, AscCH.historyitem_Worksheet_AddCols, this.getId(), new Asc.Range(index, 0, gc_nMaxCol0, gc_nMaxRow0), new UndoRedoData_FromToRowCol(false, index, index + count - 1)); History.Add(AscCommonExcel.g_oUndoRedoWorksheet, AscCH.historyitem_Worksheet_AddCols, this.getId(), new Asc.Range(index, 0, gc_nMaxCol0, gc_nMaxRow0), new UndoRedoData_FromToRowCol(false, index, index + count - 1));
this.autoFilters.insertColumn( "insCells", new Asc.Range(index, 0, index + count - 1, gc_nMaxRow0), c_oAscInsertOptions.InsertColumns ); this.autoFilters.insertColumn( "insCells", new Asc.Range(index, 0, index + count - 1, gc_nMaxRow0), c_oAscInsertOptions.InsertColumns );
...@@ -4114,8 +4130,8 @@ ...@@ -4114,8 +4130,8 @@
} }
} }
} }
//renameDependencyNodesChanged after move cells to get new locations //notifyChanged after move cells to get new locations
this.renameDependencyNodesChanged(changedFormulas); this.workbook.dependencyFormulas.notifyChanged(changedFormulas);
History.Add(AscCommonExcel.g_oUndoRedoWorksheet, AscCH.historyitem_Worksheet_ShiftCellsLeft, this.getId(), new Asc.Range(nLeft, oBBox.r1, gc_nMaxCol0, oBBox.r2), new UndoRedoData_BBox(oBBox)); History.Add(AscCommonExcel.g_oUndoRedoWorksheet, AscCH.historyitem_Worksheet_ShiftCellsLeft, this.getId(), new Asc.Range(nLeft, oBBox.r1, gc_nMaxCol0, oBBox.r2), new UndoRedoData_BBox(oBBox));
this.autoFilters.insertColumn( "delCell", oBBox, c_oAscDeleteOptions.DeleteCellsAndShiftLeft ); this.autoFilters.insertColumn( "delCell", oBBox, c_oAscDeleteOptions.DeleteCellsAndShiftLeft );
//todo проверить не уменьшились ли границы таблицы //todo проверить не уменьшились ли границы таблицы
...@@ -4155,8 +4171,8 @@ ...@@ -4155,8 +4171,8 @@
} }
} }
} }
//renameDependencyNodesChanged after move cells to get new locations //notifyChanged after move cells to get new locations
this.renameDependencyNodesChanged(changedFormulas); this.workbook.dependencyFormulas.notifyChanged(changedFormulas);
History.Add(AscCommonExcel.g_oUndoRedoWorksheet, AscCH.historyitem_Worksheet_ShiftCellsTop, this.getId(), new Asc.Range(oBBox.c1, oBBox.r1, oBBox.c2, gc_nMaxRow0), new UndoRedoData_BBox(oBBox)); History.Add(AscCommonExcel.g_oUndoRedoWorksheet, AscCH.historyitem_Worksheet_ShiftCellsTop, this.getId(), new Asc.Range(oBBox.c1, oBBox.r1, oBBox.c2, gc_nMaxRow0), new UndoRedoData_BBox(oBBox));
this.autoFilters.insertRows( "delCell", oBBox, c_oAscDeleteOptions.DeleteCellsAndShiftTop ); this.autoFilters.insertRows( "delCell", oBBox, c_oAscDeleteOptions.DeleteCellsAndShiftTop );
//todo проверить не уменьшились ли границы таблицы //todo проверить не уменьшились ли границы таблицы
...@@ -4191,8 +4207,8 @@ ...@@ -4191,8 +4207,8 @@
} }
} }
} }
//renameDependencyNodesChanged after move cells to get new locations //notifyChanged after move cells to get new locations
this.renameDependencyNodesChanged(changedFormulas); this.workbook.dependencyFormulas.notifyChanged(changedFormulas);
History.Add(AscCommonExcel.g_oUndoRedoWorksheet, AscCH.historyitem_Worksheet_ShiftCellsRight, this.getId(), new Asc.Range(oBBox.c1, oBBox.r1, gc_nMaxCol0, oBBox.r2), new UndoRedoData_BBox(oBBox)); History.Add(AscCommonExcel.g_oUndoRedoWorksheet, AscCH.historyitem_Worksheet_ShiftCellsRight, this.getId(), new Asc.Range(oBBox.c1, oBBox.r1, gc_nMaxCol0, oBBox.r2), new UndoRedoData_BBox(oBBox));
this.autoFilters.insertColumn( "insCells", oBBox, c_oAscInsertOptions.InsertCellsAndShiftRight, displayNameFormatTable ); this.autoFilters.insertColumn( "insCells", oBBox, c_oAscInsertOptions.InsertCellsAndShiftRight, displayNameFormatTable );
}; };
...@@ -4224,8 +4240,8 @@ ...@@ -4224,8 +4240,8 @@
} }
} }
} }
//renameDependencyNodesChanged after move cells to get new locations //notifyChanged after move cells to get new locations
this.renameDependencyNodesChanged(changedFormulas); this.workbook.dependencyFormulas.notifyChanged(changedFormulas);
History.Add(AscCommonExcel.g_oUndoRedoWorksheet, AscCH.historyitem_Worksheet_ShiftCellsBottom, this.getId(), new Asc.Range(oBBox.c1, oBBox.r1, oBBox.c2, gc_nMaxRow0), new UndoRedoData_BBox(oBBox)); History.Add(AscCommonExcel.g_oUndoRedoWorksheet, AscCH.historyitem_Worksheet_ShiftCellsBottom, this.getId(), new Asc.Range(oBBox.c1, oBBox.r1, oBBox.c2, gc_nMaxRow0), new UndoRedoData_BBox(oBBox));
if(!this.workbook.bUndoChanges) if(!this.workbook.bUndoChanges)
...@@ -4344,12 +4360,6 @@ Woorksheet.prototype.isApplyFilterBySheet = function(){ ...@@ -4344,12 +4360,6 @@ Woorksheet.prototype.isApplyFilterBySheet = function(){
Woorksheet.prototype.renameDependencyNodes = function(offset, oBBox, rec, noDelete){ Woorksheet.prototype.renameDependencyNodes = function(offset, oBBox, rec, noDelete){
return this.workbook.dependencyFormulas.shift(this.Id, oBBox, offset); return this.workbook.dependencyFormulas.shift(this.Id, oBBox, offset);
}; };
Woorksheet.prototype.renameDependencyNodesChanged = function(changedFormulas){
var notifyData = {type: AscCommon.c_oNotifyType.Changed};
for (var listenerId in changedFormulas) {
changedFormulas[listenerId].notify(notifyData);
}
};
Woorksheet.prototype.getAllCol = function(){ Woorksheet.prototype.getAllCol = function(){
if(null == this.oAllCol) if(null == this.oAllCol)
this.oAllCol = new AscCommonExcel.Col(this, g_nAllColIndex); this.oAllCol = new AscCommonExcel.Col(this, g_nAllColIndex);
...@@ -4473,6 +4483,18 @@ Woorksheet.prototype.isApplyFilterBySheet = function(){ ...@@ -4473,6 +4483,18 @@ Woorksheet.prototype.isApplyFilterBySheet = function(){
}); });
return cwf; return cwf;
}; };
Woorksheet.prototype.getAllFormulas = function(formulas) {
var range = this.getRange3(0, 0, gc_nMaxRow0, gc_nMaxCol0);
range._setPropertyNoEmpty(null, null, function(cell) {
if (cell.formulaParsed) {
formulas.push(cell.formulaParsed);
}
});
for (var i = 0; i < this.TableParts.length; ++i) {
var table = this.TableParts[i];
table.getAllFormulas(formulas);
}
};
Woorksheet.prototype.setTableStyleAfterOpen = function () { Woorksheet.prototype.setTableStyleAfterOpen = function () {
if (this.TableParts && this.TableParts.length) { if (this.TableParts && this.TableParts.length) {
for (var i = 0; i < this.TableParts.length; i++) { for (var i = 0; i < this.TableParts.length; i++) {
......
...@@ -5736,6 +5736,11 @@ TablePart.prototype.clone = function() { ...@@ -5736,6 +5736,11 @@ TablePart.prototype.clone = function() {
this.TableColumns[i].buildDependencies(); this.TableColumns[i].buildDependencies();
} }
}; };
TablePart.prototype.getAllFormulas = function(formulas) {
for (var i = 0; i < this.TableColumns.length; ++i) {
this.TableColumns[i].getAllFormulas(formulas);
}
};
TablePart.prototype.moveRef = function(col, row) { TablePart.prototype.moveRef = function(col, row) {
var ref = this.Ref.clone(); var ref = this.Ref.clone();
ref.setOffset({offsetCol: col ? col : 0, offsetRow: row ? row : 0}); ref.setOffset({offsetCol: col ? col : 0, offsetRow: row ? row : 0});
...@@ -6353,6 +6358,11 @@ function TableColumn() { ...@@ -6353,6 +6358,11 @@ function TableColumn() {
this.TotalsRowFormula.removeDependencies(); this.TotalsRowFormula.removeDependencies();
} }
}; };
TableColumn.prototype.getAllFormulas = function(formulas) {
if (this.TotalsRowFormula) {
formulas.push(this.TotalsRowFormula);
}
};
TableColumn.prototype.clone = function() { TableColumn.prototype.clone = function() {
var res = new TableColumn(); var res = new TableColumn();
res.Name = this.Name; res.Name = this.Name;
......
...@@ -720,7 +720,7 @@ ...@@ -720,7 +720,7 @@
switch (event.which) { switch (event.which) {
case 120: // F9 case 120: // F9
t.handlers.trigger("calcAll", shiftKey); t.handlers.trigger("calcAll", ctrlKey, event.altKey, shiftKey);
return result; return result;
case 113: // F2 case 113: // F2
......
...@@ -456,12 +456,14 @@ ...@@ -456,12 +456,14 @@
}, },
//calcAll //calcAll
'calcAll': function (shiftKey) { 'calcAll': function (ctrlKey, altKey, shiftKey) {
if(shiftKey){ if(ctrlKey && altKey && shiftKey){
self.model.recalcWB(true);
} else if(shiftKey){
var ws = self.model.getActiveWs(); var ws = self.model.getActiveWs();
self.model.dependencyFormulas.calcAll(ws.getId()); self.model.recalcWB(false, ws.getId());
} else { } else {
self.model.dependencyFormulas.calcAll(); self.model.recalcWB(false);
} }
}, },
}); });
......
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