Commit d979a8b4 authored by konovalovsergey's avatar konovalovsergey

cStrucTable refactoring to support transformation without full rebuild; change...

cStrucTable refactoring to support transformation without full rebuild; change formulas at add/remove columns/rows in table; formulas transformation without full rebuild;
parent 2fa2962a
......@@ -1592,26 +1592,64 @@ cName.prototype.Calculate = function () {
/** @constructor */
function cStrucTable( val, wb, ws ) {
this.constructor.call( this, val[0], cElementType.table );
this.constructor.call( this, val, cElementType.table );
this.wb = wb;
this.ws = ws;
this.tableName = val['tableName'];
this.reservedColumn = null;
this.tableName = null;
this.oneColumnIndex = null;
this.colStartIndex = null;
this.colEndIndex = null;
this.reservedColumnIndex = null;
this.hdtIndexes = null;
this.hdtcstartIndex = null;
this.hdtcendIndex = null;
this.isDynamic = false;//#This row
this.area = null;
this.val = val;
var ret = this._createArea(val, null, false);
return (ret && ret.type != cElementType.error) ? this : ret;
}
cStrucTable.prototype = Object.create( cBaseType.prototype );
cStrucTable.prototype.createFromVal = function(val, wb, ws) {
var res = new cStrucTable(val[0], wb, ws);
if (res._parseVal(val)) {
res._updateArea(null, false);
}
return (res.area && res.area.type != cElementType.error) ? res : new cError( cErrorType.bad_reference );
};
cStrucTable.prototype.clone = function(opt_ws) {
var ws = opt_ws ? opt_ws : this.ws;
var wb = ws.workbook;
var oRes = new cStrucTable(this.val, wb, ws);
var oRes = new cStrucTable(this.value, wb, ws);
oRes.tableName = this.tableName;
oRes.oneColumnIndex = this._cloneIndex(this.oneColumnIndex);
oRes.colStartIndex = this._cloneIndex(this.colStartIndex);
oRes.colEndIndex = this._cloneIndex(this.colEndIndex);
oRes.reservedColumnIndex = this.reservedColumnIndex;
if (this.hdtIndexes) {
oRes.hdtIndexes = this.hdtIndexes.slice(0);
}
oRes.hdtcstartIndex = this._cloneIndex(this.hdtcstartIndex);
oRes.hdtcendIndex = this._cloneIndex(this.hdtcendIndex);
oRes.isDynamic = this.isDynamic;
if (this.area) {
if(this.area.clone){
oRes.area = this.area.clone(opt_ws);
} else {
oRes.area = this.area;
}
}
this.constructor.prototype.cloneTo.call(this, oRes);
return oRes;
};
cStrucTable.prototype._cloneIndex = function(val) {
if (val) {
return {wsID: val.wsID, index: val.index, name: val.name};
} else {
return val;
}
};
cStrucTable.prototype.toRef = function (opt_bbox) {
//opt_bbox usefull only for #This row
//case null == opt_bbox works like FormulaTablePartInfo.data
......@@ -1620,7 +1658,7 @@ cStrucTable.prototype.toRef = function (opt_bbox) {
return new cError( cErrorType.wrong_name );
}
if(!this.area || this.isDynamic){
this._createArea( this.val, opt_bbox, true );
this._updateArea(opt_bbox, true );
}
return this.area;
};
......@@ -1632,166 +1670,122 @@ cStrucTable.prototype.toLocaleString = function () {
};
cStrucTable.prototype._toString = function(isLocal) {
var tblStr, columns_1, columns_2;
var table = this.wb.getDefinesNames(this.tableName, this.ws ? this.ws.getId() : null);
var table = this.wb.getDefinesNames(this.tableName, null);
if (!table) {
if (!this.tableName) {
if (isLocal) {
return this.value.replace("[]", "");
} else {
//do not replace [] becase 'Table1[]' - right, 'Table1' - wrong
return this.value;
}
} else {
tblStr = this.tableName;
}
} else {
tblStr = table.name;
}
(!isLocal || this.columnName) ? tblStr += "[%1]" : null;
if (this.oneColumn) {
columns_1 = this.wb.getTableNameColumnByIndex(this.tableName, this.oneColumnIndex.index);
if (columns_1) {
this.oneColumn = columns_1.columnName;
} else if (this.oneColumnIndex.name) {
this.oneColumn = this.oneColumnIndex.name;
}
return tblStr.replace("%1", this.oneColumn.replace(/#/g, "'#"));
}
if (this.columnRange) {
columns_1 = this.wb.getTableNameColumnByIndex(this.tableName, this.colStartIndex.index);
columns_2 = this.wb.getTableNameColumnByIndex(this.tableName, this.colEndIndex.index);
if (columns_1) {
this.colStart = columns_1.columnName
} else if (this.colStartIndex.name) {
this.colStart = this.colStartIndex.name;
}
if (columns_2) {
this.colEnd = columns_2.columnName
} else if (this.colEndIndex.name) {
this.colEnd = this.colEndIndex.name;
}
var colStart = this.colStart.replace(/#/g, "'#");
var colEnd = this.colEnd.replace(/#/g, "'#");
return tblStr.replace("%1", "[" + colStart + "]:[" + colEnd + "]");
}
if (this.reservedColumn) {
return tblStr.replace("%1", this._buildLocalTableString(this.reservedColumnIndex, isLocal));
if (this.oneColumnIndex) {
var columns_1 = this.oneColumnIndex.name.replace(/#/g, "'#")
tblStr += "[" + columns_1 + "]";
} else if (this.colStartIndex && this.colEndIndex) {
columns_1 = this.colStartIndex.name.replace(/#/g, "'#");
columns_2 = this.colEndIndex.name.replace(/#/g, "'#");
tblStr += "[[" + columns_1 + "]:[" + columns_2 + "]]";
} else if (null != this.reservedColumnIndex) {
tblStr += "[" + this._buildLocalTableString(this.reservedColumnIndex, isLocal) + "]";
} else if (this.hdtIndexes || this.hdtcstartIndex || this.hdtcendIndex) {
tblStr += '[';
var i;
for (i = 0; i < this.hdtIndexes.length; ++i) {
if (0 != i) {
tblStr += FormulaSeparators.functionArgumentSeparatorDef;
}
if (this.hdt) {
var re = /\[(.*?)\]/ig, m, data = "", i = 0;
while (null !== (m = re.exec(this.hdt))) {
data += "[" + this._buildLocalTableString(this.hdtIndexes[i], isLocal) + "]" +
FormulaSeparators.functionArgumentSeparatorDef;
tblStr += "[" + this._buildLocalTableString(this.hdtIndexes[i], isLocal) + "]";
}
data = data.substr(0, data.length - 1);
if (this.hdtcstart) {
if (this.hdtcstartIndex) {
columns_1 = this.wb.getTableNameColumnByIndex(this.tableName, this.hdtcstartIndex.index);
if (columns_1) {
this.hdtcstart = columns_1.columnName;
} else if (this.hdtcstartIndex.name) {
this.hdtcstart = this.hdtcstartIndex.name;
}
if (this.hdtIndexes.length > 0) {
tblStr += FormulaSeparators.functionArgumentSeparatorDef;
}
data += FormulaSeparators.functionArgumentSeparatorDef + "[" + this.hdtcstart.replace(/#/g, "'#") + "]"
}
if (this.hdtcend) {
var hdtcstart = this.hdtcstartIndex.name.replace(/#/g, "'#");
tblStr += "[" + hdtcstart + "]";
if (this.hdtcendIndex) {
columns_2 = this.wb.getTableNameColumnByIndex(this.tableName, this.hdtcendIndex.index);
if (columns_2) {
this.hdtcend = columns_2.columnName;
} else if (this.hdtcendIndex.name) {
this.hdtcend = this.hdtcendIndex.name;
}
var hdtcend = this.hdtcendIndex.name.replace(/#/g, "'#");
tblStr += ":[" + hdtcend + "]";
}
data += ":[" + this.hdtcend.replace(/#/g, "'#") + "]"
}
return tblStr.replace("%1", data);
}
if (isLocal) {
return tblStr.replace("%1", "").replace("[]", "");
} else {
//do not replace [] becase 'Table1[]' - right, 'Table1' - wrong
return tblStr.replace("%1", "");
tblStr += ']';
} else if (!isLocal) {
tblStr += '[]';
}
return tblStr;
};
cStrucTable.prototype._createArea = function(val, opt_bbox, opt_toRef) {
this.columnName = val['columnName'];
var paramObj = {param: null, startCol: null, endCol: null, cell: opt_bbox, toRef: opt_toRef};
if (val['oneColumn'] || val['columnRange']) {
this.oneColumn = val['oneColumn'];
this.columnRange = val['columnRange'];
paramObj.param = AscCommon.FormulaTablePartInfo.columns;
if (val['columnRange']) {
this.columnRange = val['columnRange'];
paramObj.startCol = this.colStart = val['colStart'].replace(/'#/g, "#");
paramObj.endCol = this.colEnd = val['colEnd'].replace(/'#/g, "#");
if (!this.colEnd) {
this.colEnd = this.colStart;
}
this.colStartIndex = this.wb.getTableIndexColumnByName(this.tableName, this.colStart);
this.colEndIndex = this.wb.getTableIndexColumnByName(this.tableName, this.colEnd);
if (!this.colStartIndex || !this.colEndIndex) {
return this._createAreaError(paramObj);
}
} else {
paramObj.startCol = this.oneColumn = val['oneColumn'].replace(/'#/g, "#");
this.oneColumnIndex = this.wb.getTableIndexColumnByName(this.tableName, this.oneColumn);
if (!this.oneColumnIndex) {
return this._createAreaError(paramObj);
}
}
var tableData = this.wb.getTableRangeForFormula(this.tableName, paramObj);
if (!tableData) {
return this._createAreaError(paramObj);
}
this._createAreaByTableData(tableData);
} else if (val['reservedColumn'] || !val['columnName']) {
this.reservedColumn = val['reservedColumn'] || "";
this.reservedColumnIndex = paramObj.param = parserHelp.getColumnTypeByName(this.reservedColumn);
if (AscCommon.FormulaTablePartInfo.thisRow == paramObj.param ||
AscCommon.FormulaTablePartInfo.headers == paramObj.param ||
AscCommon.FormulaTablePartInfo.totals == paramObj.param) {
cStrucTable.prototype._parseVal = function(val) {
var bRes = true;
this.tableName = val['tableName'];
if (val['oneColumn']) {
var startCol = val['oneColumn'].replace(/'#/g, "#");
this.oneColumnIndex = this.wb.getTableIndexColumnByName(this.tableName, startCol);
bRes = !!this.oneColumnIndex;
} else if (val['columnRange']) {
var startCol = val['colStart'].replace(/'#/g, "#");
var endCol = val['colEnd'].replace(/'#/g, "#");
if (!endCol) {
endCol = startCol;
}
this.colStartIndex = this.wb.getTableIndexColumnByName(this.tableName, startCol);
this.colEndIndex = this.wb.getTableIndexColumnByName(this.tableName, endCol);
bRes = !!this.colStartIndex && !!this.colEndIndex;
} else if (val['reservedColumn']) {
this.reservedColumnIndex = parserHelp.getColumnTypeByName(val['reservedColumn']);
if (AscCommon.FormulaTablePartInfo.thisRow == this.reservedColumnIndex ||
AscCommon.FormulaTablePartInfo.headers == this.reservedColumnIndex ||
AscCommon.FormulaTablePartInfo.totals == this.reservedColumnIndex) {
this.isDynamic = true;
}
tableData = this.wb.getTableRangeForFormula(this.tableName, paramObj);
if (!tableData) {
return this._createAreaError(paramObj);
}
this._createAreaByTableData(tableData);
} else if (val['hdtcc']) {
this.hdt = val['hdt'];
this.hdtIndexes = [];
this.hdtcstart = val['hdtcstart'];
this.hdtcend = val['hdtcend'];
var hdtcstart = val['hdtcstart'];
var hdtcend = val['hdtcend'];
var re = /\[(.*?)\]/ig, m, data, range;
while (null !== (m = re.exec(this.hdt))) {
paramObj.param = parserHelp.getColumnTypeByName(m[1]);
if (AscCommon.FormulaTablePartInfo.thisRow == paramObj.param ||
AscCommon.FormulaTablePartInfo.headers == paramObj.param ||
AscCommon.FormulaTablePartInfo.totals == paramObj.param) {
while (null !== (m = re.exec(val['hdt']))) {
var param = parserHelp.getColumnTypeByName(m[1]);
if (AscCommon.FormulaTablePartInfo.thisRow == param ||
AscCommon.FormulaTablePartInfo.headers == param ||
AscCommon.FormulaTablePartInfo.totals == param) {
this.isDynamic = true;
}
this.hdtIndexes.push(paramObj.param);
data = this.wb.getTableRangeForFormula(this.tableName, paramObj);
this.hdtIndexes.push(param);
}
if (hdtcstart) {
var startCol = hdtcstart.replace(/'#/g, "#");
this.hdtcstartIndex = this.wb.getTableIndexColumnByName(this.tableName, startCol);
bRes = !!this.hdtcstartIndex;
if (bRes && hdtcend) {
var endCol = hdtcend.replace(/'#/g, "#");
this.hdtcendIndex = this.wb.getTableIndexColumnByName(this.tableName, endCol);
bRes = !!this.hdtcendIndex;
}
}
}
return bRes;
};
cStrucTable.prototype._updateArea = function(opt_bbox, opt_toRef) {
var paramObj = {param: null, startCol: null, endCol: null, cell: opt_bbox, toRef: opt_toRef};
var isThisRow = false;
var tableData;
if (this.oneColumnIndex) {
paramObj.param = AscCommon.FormulaTablePartInfo.columns;
paramObj.startCol = this.oneColumnIndex.name;
} else if (this.colStartIndex && this.colEndIndex) {
paramObj.param = AscCommon.FormulaTablePartInfo.columns;
paramObj.startCol = this.colStartIndex.name;
paramObj.endCol = this.colEndIndex.name;
} else if (null != this.reservedColumnIndex) {
paramObj.param = this.reservedColumnIndex;
isThisRow = AscCommon.FormulaTablePartInfo.thisRow == paramObj.param;
} else if (this.hdtIndexes || this.hdtcstartIndex) {
var data, range;
if (this.hdtIndexes) {
for(var i = 0 ; i < this.hdtIndexes.length; ++i){
paramObj.param = this.hdtIndexes[i];
isThisRow = AscCommon.FormulaTablePartInfo.thisRow == paramObj.param;
data = this.wb.getTableRangeForFormula(this.tableName, paramObj);
if (!data) {
return this._createAreaError(paramObj);
return this._createAreaError(isThisRow);
}
if (range) {
......@@ -1800,59 +1794,38 @@ cStrucTable.prototype.toLocaleString = function () {
range = data.range;
}
}
}
if (this.hdtcstart) {
this.hdtcstart = this.hdtcstart.replace(/'#/g, "#");
if (this.hdtcstartIndex) {
paramObj.param = AscCommon.FormulaTablePartInfo.columns;
paramObj.startCol = this.hdtcstart;
paramObj.startCol = this.hdtcstartIndex.name;
paramObj.endCol = null;
this.hdtcstartIndex = this.wb.getTableIndexColumnByName(this.tableName, this.hdtcstart);
if (!this.hdtcstartIndex) {
return this._createAreaError(paramObj);
}
if (this.hdtcend) {
this.hdtcend = this.hdtcend.replace(/'#/g, "#");
paramObj.endCol = this.hdtcend;
this.hdtcendIndex = this.wb.getTableIndexColumnByName(this.tableName, this.hdtcend);
if (!this.hdtcendIndex) {
return this._createAreaError(paramObj);
}
if (this.hdtcendIndex) {
paramObj.endCol = this.hdtcendIndex.name;
}
if (range) {
var _c1 = range.c1 + (this.hdtcstartIndex ? this.hdtcstartIndex.index : 0);
var _c2 = this.hdtcendIndex ? range.c1 + this.hdtcendIndex.index : _c1;
range = new Asc.Range(_c1, range.r1, _c2, range.r2);
} else {
data = this.wb.getTableRangeForFormula(this.tableName, paramObj);
if (!data) {
return this._createAreaError(paramObj);
return this._createAreaError(isThisRow);
}
if (range) {
range = new Asc.Range(data.range.c1, range.r1, data.range.c2, range.r2);
} else {
range = data.range;
}
}
tableData = data;
tableData.range = range;
this._createAreaByTableData(tableData);
}
!this.area ? this.area = new cError(cErrorType.bad_reference) : null;
return this.area;
};
cStrucTable.prototype._createAreaError = function (paramObj) {
if(AscCommon.FormulaTablePartInfo.thisRow == paramObj.param){
return this.area = new cError( cErrorType.wrong_value_type );
} else {
return this.area = new cError( cErrorType.bad_reference );
paramObj.param = AscCommon.FormulaTablePartInfo.data;
}
if (!tableData) {
tableData = this.wb.getTableRangeForFormula(this.tableName, paramObj);
if (!tableData) {
return this._createAreaError(isThisRow);
}
}
};
cStrucTable.prototype._createAreaByTableData = function (tableData) {
if (tableData.range) {
var refName = tableData.range.getAbsName();
var sheetName = this.wb.getWorksheetById(tableData.wsID).getName();
......@@ -1861,6 +1834,17 @@ cStrucTable.prototype.toLocaleString = function () {
} else {
this.area = new cArea3D(refName, sheetName, sheetName, this.wb);
}
} else {
this.area = new cError(cErrorType.bad_reference);
}
return this.area;
};
cStrucTable.prototype._createAreaError = function (isThisRow) {
if(isThisRow){
return this.area = new cError( cErrorType.wrong_value_type );
} else {
return this.area = new cError( cErrorType.bad_reference );
}
};
cStrucTable.prototype._buildLocalTableString = function (reservedColumn,local) {
......@@ -1872,58 +1856,97 @@ cStrucTable.prototype._buildLocalTableString = function (reservedColumn,local) {
}
};
cStrucTable.prototype.removeTableColumn = function(deleted) {
if (this.oneColumn) {
if (deleted[this.oneColumn]) {
if (this.oneColumnIndex) {
if (deleted[this.oneColumnIndex.name]) {
return true;
} else {
this.oneColumnIndex = this.wb.getTableIndexColumnByName(this.tableName, this.oneColumn);
this.oneColumnIndex = this.wb.getTableIndexColumnByName(this.tableName, this.oneColumnIndex.name);
if (!this.oneColumnIndex) {
return true;
}
}
}
if (this.columnRange) {
if (deleted[this.colStart]) {
if (this.colStartIndex && this.colEndIndex) {
if (deleted[this.colStartIndex.name]) {
return true;
} else {
this.colStartIndex = this.wb.getTableIndexColumnByName(this.tableName, this.colStart);
this.colStartIndex = this.wb.getTableIndexColumnByName(this.tableName, this.colStartIndex.name);
if (!this.colStartIndex) {
return true;
}
}
if (deleted[this.colEnd]) {
if (deleted[this.colEndIndex.name]) {
return true;
} else {
this.colEndIndex = this.wb.getTableIndexColumnByName(this.tableName, this.colEnd);
this.colEndIndex = this.wb.getTableIndexColumnByName(this.tableName, this.colEndIndex.name);
if (!this.colEndIndex) {
return true;
}
}
}
if (this.hdt) {
if(this.hdtcstart){
if (deleted[this.hdtcstart]) {
if (this.hdtcstartIndex) {
if (deleted[this.hdtcstartIndex.name]) {
return true;
} else {
this.hdtcstartIndex = this.wb.getTableIndexColumnByName(this.tableName, this.hdtcstart);
this.hdtcstartIndex = this.wb.getTableIndexColumnByName(this.tableName, this.hdtcstartIndex.name);
if (!this.hdtcstartIndex) {
return true;
}
}
}
if(this.hdtcend){
if (deleted[this.hdtcend]) {
if (this.hdtcendIndex) {
if (deleted[this.hdtcendIndex.name]) {
return true;
} else {
this.hdtcendIndex = this.wb.getTableIndexColumnByName(this.tableName, this.hdtcend);
this.hdtcendIndex = this.wb.getTableIndexColumnByName(this.tableName, this.hdtcendIndex.name);
if (!this.hdtcendIndex) {
return true;
}
}
}
}
return false;
};
cStrucTable.prototype.changeTableRef = function() {
if(!this.isDynamic){
this._updateArea(null, false);
}
};
cStrucTable.prototype.renameTableColumn = function() {
var bRes = true;
var columns1, columns2;
if (this.oneColumnIndex) {
columns1 = this.wb.getTableNameColumnByIndex(this.tableName, this.oneColumnIndex.index);
if (columns1) {
this.oneColumnIndex.name = columns1.columnName;
} else {
bRes = false;
}
} else if (this.colStartIndex && this.colEndIndex) {
columns1 = this.wb.getTableNameColumnByIndex(this.tableName, this.colStartIndex.index);
columns2 = this.wb.getTableNameColumnByIndex(this.tableName, this.colEndIndex.index);
if (columns1 && columns2) {
this.colStartIndex.name = columns1.columnName;
this.colEndIndex.name = columns2.columnName;
} else {
bRes = false;
}
} if (this.hdtcstartIndex) {
columns1 = this.wb.getTableNameColumnByIndex(this.tableName, this.hdtcstartIndex.index);
if (columns1) {
this.hdtcstartIndex.name = columns1.columnName;
} else {
bRes = false;
}
} if (this.hdtcendIndex) {
columns1 = this.wb.getTableNameColumnByIndex(this.tableName, this.hdtcendIndex.index);
if (columns1) {
this.hdtcendIndex.name = columns1.columnName;
} else {
bRes = false;
}
}
return bRes;
};
/** @constructor */
function cName3D(val, wb, ws) {
......@@ -3851,7 +3874,6 @@ function parserFormula( formula, parent, _ws ) {
this.operand_str = null;
this.parenthesesNotEnough = false;
this.f = [];
this.reRowCol = /^(ROW|ROWS|COLUMN|COLUMNS)$/gi
this.countRef = 0;
this.listenerId = lastListenerId++;
......@@ -3878,7 +3900,7 @@ function parserFormula( formula, parent, _ws ) {
this.isTable = isTable;
};
parserFormula.prototype.notify = function(data) {
var eventData = {notifyData: data, assemble: null, isRebuild: false, formula: this};
var eventData = {notifyData: data, assemble: null, formula: this};
if (this.parent && this.parent.onFormulaEvent) {
var checkCanDo = this.parent.onFormulaEvent(AscCommon.c_oNotifyParentType.CanDo, eventData);
if(!checkCanDo){
......@@ -3902,45 +3924,32 @@ function parserFormula( formula, parent, _ws ) {
if (AscCommon.c_oNotifyType.Shift === data.type || AscCommon.c_oNotifyType.Move === data.type ||
AscCommon.c_oNotifyType.Delete === data.type) {
this.shiftCells(data.type, data.sheetId, data.bbox, data.offset);
eventData.isRebuild = false;
} else if (AscCommon.c_oNotifyType.ChangeDefName === data.type) {
if (!data.to) {
this.removeTableName(data.from, data.bConvertTableFormulaToRef);
eventData.isRebuild = true;
} else if (data.from.name != data.to.name) {
this.changeDefName(data.from, data.to);
} else if (data.from.isTable) {
needAssemble = false;
eventData.isRebuild = true;
this.changeTableRef(data.from.name);
}
} else if (AscCommon.c_oNotifyType.DelColumnTable === data.type) {
this.removeTableColumn(data.tableName, data.deleted);
eventData.isRebuild = true;
} else if (AscCommon.c_oNotifyType.Rebuild === data.type) {
eventData.isRebuild = true;
} else if (AscCommon.c_oNotifyType.RenameTableColumn === data.type) {
this.renameTableColumn(data.tableName);
} else if (AscCommon.c_oNotifyType.ChangeSheet === data.type) {
needAssemble = false;
var changeData = data.data;
if (this.is3D || changeData.remove) {
if (changeData.insert) {
eventData.isRebuild = this.insertSheet(changeData.insert);
} else if (changeData.replace || changeData.remove) {
eventData.isRebuild = true;
var moveSheetRes = 0;
if (changeData.replace || changeData.remove) {
if (changeData.remove) {
moveSheetRes = this.removeSheet(changeData.remove, changeData.tableNamesMap);
needAssemble = this.removeSheet(changeData.remove, changeData.tableNamesMap, changeData.wsPrevName, changeData.wsNextName);
} else {
moveSheetRes = this.moveSheet(changeData.replace);
}
if (2 === moveSheetRes) {
needAssemble = true;
} else if (1 !== moveSheetRes) {
eventData.isRebuild = false;
needAssemble = this.moveSheet(changeData.replace);
}
} else if (changeData.rename) {
this.renameSheet(changeData.rename.from, changeData.rename.to);
needAssemble = true;
eventData.isRebuild = false;
}
}
}
......@@ -3952,6 +3961,12 @@ function parserFormula( formula, parent, _ws ) {
if (this.parent && this.parent.onFormulaEvent) {
this.parent.onFormulaEvent(AscCommon.c_oNotifyParentType.ChangeFormula, eventData);
}
this.Formula = eventData.assemble;
if (data.collectDependencies) {
data.collectDependencies.push(this);
} else {
this.buildDependencies();
}
}
};
parserFormula.prototype.clone = function(formula, parent, ws) {
......@@ -4005,7 +4020,7 @@ parserFormula.prototype.setFormula = function(formula) {
this.ca = false;
this.isDirty = false;
this.isCalculate = false;
this.isTable = false;
//this.isTable = false;
this.isInDependencies = false;
};
......@@ -4619,16 +4634,16 @@ parserFormula.prototype.parse = function(local, digitDelim) {
}
else if (_tableTMP = parserHelp.isTable.call(this, this.Formula, this.pCurrPos, local)) {
found_operand = new cStrucTable(_tableTMP, this.wb, this.ws);
found_operand = cStrucTable.prototype.createFromVal(_tableTMP, this.wb, this.ws);
//todo undo delete column
// if (found_operand.type == cElementType.error) {
// /*используется неверный именованный диапазон или таблица*/
// this.error.push(c_oAscError.ID.FrmlAnotherParsingError);
// this.outStack = [];
// this.elemArr = [];
// return false;
// }
if (found_operand.type == cElementType.error) {
/*используется неверный именованный диапазон или таблица*/
this.error.push(c_oAscError.ID.FrmlAnotherParsingError);
this.outStack = [];
this.elemArr = [];
return false;
}
if (found_operand.type != cElementType.error) {
this.RefPos.push({
......@@ -4646,11 +4661,10 @@ parserFormula.prototype.parse = function(local, digitDelim) {
this.ws)[0]) {
found_operand = new cName(this.operand_str, this.wb, this.ws);
var defName = found_operand.getDefName();
if (defName && defName.isTable) {
if (defName && defName.isTable && (_tableTMP = parserHelp.isTable(this.operand_str + "[]", 0))) {
found_operand = cStrucTable.prototype.createFromVal(_tableTMP, this.wb, this.ws);
//need assemble becase source formula wrong
needAssemble = true;
found_operand =
new cStrucTable(parserHelp.isTable(this.operand_str + "[]", 0), this.wb, this.ws);
}
this.RefPos.push({
start: this.pCurrPos - this.operand_str.length,
......@@ -4918,6 +4932,26 @@ parserFormula.prototype.calculate = function(opt_defName, opt_range) {
}
}
};
parserFormula.prototype.renameTableColumn = function(tableName) {
var i, elem;
for (i = 0; i < this.outStack.length; i++) {
elem = this.outStack[i];
if (elem.type == cElementType.table && elem.tableName == tableName) {
if (!elem.renameTableColumn()) {
this.outStack[i] = new cError(cErrorType.bad_reference);
}
}
}
};
parserFormula.prototype.changeTableRef = function(tableName) {
var i, elem;
for (i = 0; i < this.outStack.length; i++) {
elem = this.outStack[i];
if (elem.type == cElementType.table && elem.tableName == tableName) {
elem.changeTableRef();
}
}
};
parserFormula.prototype.shiftCells = function(notifyType, sheetId, bbox, offset) {
var elem;
for (var i = 0; i < this.outStack.length; i++) {
......@@ -5054,7 +5088,7 @@ parserFormula.prototype.calculate = function(opt_defName, opt_range) {
return this;
};
parserFormula.prototype.removeSheet = function(sheetId, tableNamesMap) {
var nRes = 0;
var bRes = false;
var ws = this.wb.getWorksheetById(sheetId);
if (ws) {
var wsIndex = ws.getIndex();
......@@ -5069,67 +5103,43 @@ parserFormula.prototype.calculate = function(opt_defName, opt_range) {
for (var i = 0; i < this.outStack.length; i++) {
var elem = this.outStack[i];
if (cElementType.cellsRange3D === elem.type) {
var wsTo = this.wb.getWorksheetById(elem.wsTo);
var wsToIndex = wsTo.getIndex();
var wsFrom = this.wb.getWorksheetById(elem.wsFrom);
var wsFromIndex = wsFrom.getIndex();
if (wsFromIndex <= wsIndex && wsIndex <= wsToIndex && 0 == nRes) {
nRes = 1;
}
if (elem.wsFrom == sheetId) {
if (elem.wsTo != sheetId && null != wsNext) {
elem.changeSheet(ws.getName(), wsNext.getName());
} else {
this.outStack[i] = new cError(cErrorType.bad_reference);
}
nRes = 2;
bRes = true;
} else if (elem.wsTo == sheetId) {
if (null != wsPrev) {
elem.changeSheet(ws.getName(), wsPrev.getName());
} else {
this.outStack[i] = new cError(cErrorType.bad_reference);
}
nRes = 2;
bRes = true;
}
} else if (cElementType.cell3D === elem.type) {
if (elem.ws.getId() == sheetId) {
this.outStack[i] = new cError(cErrorType.bad_reference);
nRes = 2;
bRes = true;
}
} else if (cElementType.name3D === elem.type) {
if (elem.ws.getId() == sheetId) {
this.outStack[i] = new cError(cErrorType.bad_reference);
nRes = 2;
bRes = true;
}
} else if (cElementType.table === elem.type) {
if (tableNamesMap[elem.tableName]) {
this.outStack[i] = new cError(cErrorType.bad_reference);
nRes = 2;
}
}
}
}
return nRes;
};
parserFormula.prototype.insertSheet = function(index) {
var bRes = false;
for (var i = 0; i < this.outStack.length; i++) {
var elem = this.outStack[i];
if (cElementType.cellsRange3D == elem.type) {
var wsTo = this.wb.getWorksheetById(elem.wsTo);
var wsToIndex = wsTo.getIndex();
var wsFrom = this.wb.getWorksheetById(elem.wsFrom);
var wsFromIndex = wsFrom.getIndex();
if (wsFromIndex <= index && index <= wsToIndex) {
bRes = true;
break;
}
}
}
}
return bRes;
};
parserFormula.prototype.moveSheet = function(tempW) {
var nRes = 0;
var bRes = false;
for (var i = 0; i < this.outStack.length; i++) {
var elem = this.outStack[i];
if (cElementType.cellsRange3D == elem.type) {
......@@ -5137,13 +5147,10 @@ parserFormula.prototype.calculate = function(opt_defName, opt_range) {
var wsToIndex = wsTo.getIndex();
var wsFrom = this.wb.getWorksheetById(elem.wsFrom);
var wsFromIndex = wsFrom.getIndex();
if (wsFromIndex <= tempW.wFI && tempW.wFI <= wsToIndex && 0 == nRes) {
nRes = 1;
}
if (elem.wsFrom !== elem.wsTo) {
if (elem.wsFrom == tempW.wFId) {
if (tempW.wTI > wsToIndex) {
nRes = 2;
bRes = true;
var wsNext = this.wb.getWorksheet(wsFromIndex + 1);
if (wsNext) {
elem.changeSheet(tempW.wFN, wsNext.getName());
......@@ -5153,7 +5160,7 @@ parserFormula.prototype.calculate = function(opt_defName, opt_range) {
}
} else if (elem.wsTo == tempW.wFId) {
if (tempW.wTI <= wsFromIndex) {
nRes = 2;
bRes = true;
var wsPrev = this.wb.getWorksheet(wsToIndex - 1);
if (wsPrev) {
elem.changeSheet(tempW.wFN, wsPrev.getName());
......@@ -5165,7 +5172,7 @@ parserFormula.prototype.calculate = function(opt_defName, opt_range) {
}
}
}
return nRes;
return bRes;
};
/* Сборка функции в инфиксную форму */
......@@ -5241,18 +5248,7 @@ parserFormula.prototype.assembleLocale = function(locale, digitDelim) {
if (ref.type == cElementType.table) {
this.wb.dependencyFormulas.startListeningDefName(ref.tableName, this);
continue;
}
if ((cElementType.cell === ref.type || cElementType.cell3D === ref.type ||
cElementType.cellsRange === ref.type || cElementType.cellsRange3D === ref.type) &&
ref.isValid() && this.outStack[i + 1] && this.outStack[i + 1] instanceof cBaseFunction &&
this.reRowCol.test(this.outStack[i + 1].name)) {
this.reRowCol.lastIndex = 0;
continue;
}
if (ref.type == cElementType.name) {
} else if (ref.type == cElementType.name) {
this.wb.dependencyFormulas.startListeningDefName(ref.value, this);
} else if (ref.type == cElementType.name3D) {
this.wb.dependencyFormulas.startListeningDefName(ref.value, this, ref.ws.getId());
......@@ -5306,18 +5302,7 @@ parserFormula.prototype.assembleLocale = function(locale, digitDelim) {
if (ref.type == cElementType.table) {
this.wb.dependencyFormulas.endListeningDefName(ref.tableName, this);
continue;
}
if ((cElementType.cell === ref.type || cElementType.cell3D === ref.type ||
cElementType.cellsRange === ref.type || cElementType.cellsRange3D === ref.type) &&
ref.isValid() && this.outStack[i + 1] && this.outStack[i + 1] instanceof cBaseFunction &&
this.reRowCol.test(this.outStack[i + 1].name)) {
this.reRowCol.lastIndex = 0;
continue;
}
if (ref.type == cElementType.name) {
} else if (ref.type == cElementType.name) {
this.wb.dependencyFormulas.endListeningDefName(ref.value, this);
} else if (ref.type == cElementType.name3D) {
this.wb.dependencyFormulas.endListeningDefName(ref.value, this, ref.ws.getId());
......@@ -5330,7 +5315,7 @@ parserFormula.prototype.assembleLocale = function(locale, digitDelim) {
bbox.setOffsetLast({offsetRow: 1, offsetCol: 0});
}
this.wb.dependencyFormulas.endListeningRange(ref.getWsId(), bbox, this);
} else if (cElementType.cellsRange3D === ref.type && ref.isValid() && ref.dependenceRange) {
} else if (cElementType.cellsRange3D === ref.type && ref.dependenceRange) {
wsR = ref.dependenceRange;
for (var j = 0; j < wsR.length; j++) {
var range = wsR[j];
......
......@@ -944,16 +944,6 @@ CHistory.prototype.GetSerializeArray = function()
}
return aRes;
};
//функция, которая перемещает последнее действие на первую позицию(в текущей точке)
CHistory.prototype.ChangeActionsEndToStart = function()
{
var curPoint = this.Points[this.Index];
if(curPoint && curPoint.Items.length > 0)
{
var endAction = curPoint.Items.pop();
curPoint.Items.unshift(endAction);
}
};
CHistory.prototype.loadFonts = function (fonts) {
for (var i = 0; i < fonts.length; ++i) {
this.LoadFonts[fonts[i].name] = 1;
......
......@@ -242,13 +242,8 @@
this.wb.dependencyFormulas.addToChangedDefName(this);
} else if (AscCommon.c_oNotifyParentType.ChangeFormula === type) {
var oldUndoName = this.getUndoDefName();
if (eventData.isRebuild) {
this.setRef(eventData.assemble, true);
} else {
this.ref = this.parsedRef.Formula = eventData.assemble;
this.parsedRef.buildDependencies();
this.wb.dependencyFormulas.addToChangedDefName(this);
}
var newUndoName = this.getUndoDefName();
History.Add(AscCommonExcel.g_oUndoRedoWorkbook, AscCH.historyitem_Workbook_DefinedNamesChangeUndo, null,
null, new UndoRedoData_FromTo(oldUndoName, newUndoName), true);
......@@ -427,7 +422,7 @@
this._shiftMoveDelete(AscCommon.c_oNotifyType.Move, sheetId, bboxFrom, offset);
this.addToChangedRange(sheetId, bboxFrom);
},
changeSheet: function(sheetId, data, tableNamesMap) {
changeSheet: function(sheetId, data, tableNamesMap, opt_collectDependencies) {
this.buildDependency();
var listeners = {};
var sheetContainer = this.sheetListeners[sheetId];
......@@ -459,12 +454,12 @@
}
}
}
var notifyData = {type: AscCommon.c_oNotifyType.ChangeSheet, data: data};
var notifyData = {type: AscCommon.c_oNotifyType.ChangeSheet, data: data, collectDependencies: opt_collectDependencies};
for (var listenerId in listeners) {
listeners[listenerId].notify(notifyData);
}
},
removeSheet: function(sheetId, tableNames) {
removeSheet: function(sheetId, tableNames, opt_collectDependencies) {
var t = this;
//cells
var formulas = [];
......@@ -486,7 +481,7 @@
tableNamesMap[tableName] = 1;
}
//dependence
this.changeSheet(sheetId, {remove: sheetId, tableNamesMap: tableNamesMap}, tableNamesMap);
this.changeSheet(sheetId, {remove: sheetId, tableNamesMap: tableNamesMap}, tableNamesMap, opt_collectDependencies);
},
//lock
lockRecal: function() {
......@@ -763,11 +758,11 @@
var notifyData = {type: AscCommon.c_oNotifyType.DelColumnTable, tableName: tableName, deleted: deleted};
this._broadcastDefName(tableName, notifyData);
},
rebuildTable: function(tableName) {
renameTableColumn: function(tableName) {
var defName = this.getDefNameByName(tableName, null);
if (defName) {
this.buildDependency();
var notifyData = {type: AscCommon.c_oNotifyType.Rebuild};
var notifyData = {type: AscCommon.c_oNotifyType.RenameTableColumn, tableName: tableName};
this._broadcastDefName(defName.name, notifyData);
}
this.calcTree();
......@@ -1297,14 +1292,7 @@
} else if (AscCommon.c_oNotifyParentType.Change === type) {
this.parsed.setIsDirty(false);
} else if (AscCommon.c_oNotifyParentType.ChangeFormula === type) {
if (eventData.isRebuild) {
this.parsed = new AscCommonExcel.parserFormula(eventData.assemble, this, this.parsed.ws);
this.parsed.parse();
} else {
this.parsed.Formula = eventData.assemble;
}
this.formula = eventData.assemble;
this.parsed.buildDependencies();
}
}
};
......@@ -1387,7 +1375,7 @@
self.dependencyFormulas.changeTableRef(table);
},
"changeColumnTablePart": function ( tableName ) {
self.dependencyFormulas.rebuildTable( tableName );
self.dependencyFormulas.renameTableColumn( tableName );
},
"deleteColumnTablePart": function(tableName, deleted) {
self.dependencyFormulas.delColumnTable(tableName, deleted);
......@@ -1595,10 +1583,16 @@
if(tempW.wFI < tempW.wTI)
tempW.wTI++;
this.dependencyFormulas.lockRecal();
this.dependencyFormulas.changeSheet(tempW.wFId, {replace: tempW});
var collectDependencies = [];
this.dependencyFormulas.changeSheet(tempW.wFId, {replace: tempW}, null, collectDependencies);
//move sheets
var movedSheet = this.aWorksheets.splice(indexFrom, 1);
this.aWorksheets.splice(indexTo, 0, movedSheet[0]);
this._updateWorksheetIndexes(wsActive);
//buildDependencies after move sheet for cArea3d
for (var i = 0; i < collectDependencies.length; ++i) {
collectDependencies[i].buildDependencies();
}
this._insertWorksheetFormula(indexTo);
......@@ -1648,12 +1642,17 @@
{
var removedSheetId = removedSheet.getId();
this.dependencyFormulas.lockRecal();
this.dependencyFormulas.removeSheet(removedSheetId, removedSheet.getTableNames());
var collectDependencies = [];
this.dependencyFormulas.removeSheet(removedSheetId, removedSheet.getTableNames(), collectDependencies);
//delete sheet
var wsActive = this.getActiveWs();
var oVisibleWs = null;
this.aWorksheets.splice(nIndex, 1);
delete this.aWorksheetsById[removedSheetId];
//buildDependencies after move sheet for cArea3d
for (var i = 0; i < collectDependencies.length; ++i) {
collectDependencies[i].buildDependencies();
}
if (nIndex == this.getActive()) {
oVisibleWs = this.findSheetNoHidden(nIndex);
if (null != oVisibleWs)
......@@ -3048,6 +3047,7 @@
var oActualRange = new Asc.Range(0, start, gc_nMaxCol0, stop);
//renameDependencyNodes before move cells to store current location in history
var changedFormulas = this.renameDependencyNodes({offsetRow: nDif, offsetCol: 0}, oActualRange);
var redrawTablesArr = this.autoFilters.insertRows( "delCell", new Asc.Range(0, start, gc_nMaxCol0, stop), c_oAscDeleteOptions.DeleteRows );
var i, j, length, nIndex, aIndexes = [];
for(i in this.aGCells)
{
......@@ -3069,8 +3069,14 @@
var oTargetRow = this._getRow(nIndex + nDif);
oTargetRow.copyProperty(row);
}
for(j in row.c)
for (j in row.c) {
var cell = row.c[j];
this._moveCellVer(nIndex, j - 0, nDif);
if (cell && cell.getFormula()) {
//for #Ref
this.workbook.dependencyFormulas.addToChangedCell(cell);
}
}
}
else
{
......@@ -3087,10 +3093,11 @@
}
delete this.aGCells[nIndex];
}
//notifyChanged after move cells to get new locations
//notifyChanged after move cells to get new locations(for intersect ranges)
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));
this.autoFilters.insertRows( "delCell", new Asc.Range(0, start, gc_nMaxCol0, stop), c_oAscDeleteOptions.DeleteRows );
this.autoFilters.redrawStylesTables(redrawTablesArr);
this.workbook.dependencyFormulas.unlockRecal();
......@@ -3106,6 +3113,7 @@
History.Create_NewPoint();
//renameDependencyNodes before move cells to store current location in history
var changedFormulas = this.renameDependencyNodes({offsetRow: count, offsetCol: 0}, oActualRange);
var redrawTablesArr = this.autoFilters.insertRows( "insCell", new Asc.Range(0, index, gc_nMaxCol0, index + count - 1), c_oAscInsertOptions.InsertColumns );
//index 0 based
var aIndexes = [];
for(var i in this.aGCells)
......@@ -3128,8 +3136,14 @@
var oTargetRow = this._getRow(nIndex + count);
oTargetRow.copyProperty(row);
}
for(var j in row.c)
for (var j in row.c) {
var cell = row.c[j];
this._moveCellVer(nIndex, j - 0, count);
if (cell && cell.getFormula()) {
//for #Ref
this.workbook.dependencyFormulas.addToChangedCell(cell);
}
}
delete this.aGCells[nIndex];
}
if (null != oPrevRow && false == this.workbook.bUndoChanges && (false == this.workbook.bRedoChanges || true == this.workbook.bCollaborativeChanges))
......@@ -3143,11 +3157,11 @@
}
History.LocalChange = false;
}
//notifyChanged after move cells to get new locations
//notifyChanged after move cells to get new locations(for intersect ranges)
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));
this.autoFilters.insertRows( "insCell", new Asc.Range(0, index, gc_nMaxCol0, index + count - 1), c_oAscInsertOptions.InsertColumns );
this.autoFilters.redrawStylesTables(redrawTablesArr);
this.workbook.dependencyFormulas.unlockRecal();
......@@ -3178,6 +3192,7 @@
var oActualRange = new Asc.Range(start, 0, stop, gc_nMaxRow0);
//renameDependencyNodes before move cells to store current location in history
var changedFormulas = this.renameDependencyNodes({ offsetRow: 0, offsetCol: nDif }, oActualRange);
var redrawTablesArr = this.autoFilters.insertColumn( "delCell", new Asc.Range(start, 0, stop, gc_nMaxRow0), c_oAscInsertOptions.InsertColumns );
for(i in this.aGCells)
{
var nRowIndex = i - 0;
......@@ -3196,7 +3211,12 @@
nIndex = aIndexes[j];
if(nIndex > stop)
{
var cell = row.c[nIndex];
this._moveCellHor(nRowIndex, nIndex, nDif, {r1: 0, c1: start, r2: gc_nMaxRow0, c2: stop});
if (cell && cell.getFormula()) {
//for #Ref
this.workbook.dependencyFormulas.addToChangedCell(cell);
}
}
else
{
......@@ -3224,11 +3244,12 @@
if(null != elem)
elem.moveHor(nDif);
}
//notifyChanged after move cells to get new locations
//notifyChanged after move cells to get new locations(for intersect ranges)
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));
this.autoFilters.insertColumn( "delCell", new Asc.Range(start, 0, stop, gc_nMaxRow0), c_oAscInsertOptions.InsertColumns );
this.autoFilters.redrawStylesTables(redrawTablesArr);
this.workbook.dependencyFormulas.unlockRecal();
return true;
......@@ -3243,6 +3264,7 @@
History.Create_NewPoint();
//renameDependencyNodes before move cells to store current location in history
var changedFormulas = this.renameDependencyNodes({offsetRow: 0, offsetCol: count}, oActualRange);
var redrawTablesArr = this.autoFilters.insertColumn( "insCells", new Asc.Range(index, 0, index + count - 1, gc_nMaxRow0), c_oAscInsertOptions.InsertColumns );
//index 0 based
for(var i in this.aGCells)
{
......@@ -3260,14 +3282,19 @@
for(var j = 0, length2 = aIndexes.length; j < length2; ++j)
{
var nIndex = aIndexes[j];
var cell = row.c[nIndex];
this._moveCellHor(nRowIndex, nIndex, count, oActualRange);
if (cell && cell.getFormula()) {
//for #Ref
this.workbook.dependencyFormulas.addToChangedCell(cell);
}
}
}
//notifyChanged after move cells to get new locations
//notifyChanged after move cells to get new locations(for intersect ranges)
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));
this.autoFilters.insertColumn( "insCells", new Asc.Range(index, 0, index + count - 1, gc_nMaxRow0), c_oAscInsertOptions.InsertColumns );
this.autoFilters.redrawStylesTables(redrawTablesArr);
this.workbook.dependencyFormulas.unlockRecal();
......@@ -4126,8 +4153,10 @@
var nLeft = oBBox.c1;
var nRight = oBBox.c2;
var dif = nLeft - nRight - 1;
var oActualRange = new Asc.Range(nLeft, oBBox.r1, gc_nMaxCol0, oBBox.r2);
//renameDependencyNodes before move cells to store current location in history
var changedFormulas = this.renameDependencyNodes({offsetRow: 0, offsetCol: dif}, oBBox);
var redrawTablesArr = this.autoFilters.insertColumn( "delCell", oBBox, c_oAscDeleteOptions.DeleteCellsAndShiftLeft );
for(var i = oBBox.r1; i <= oBBox.r2; i++){
var row = this.aGCells[i];
if(row){
......@@ -4148,23 +4177,31 @@
}
else{
//Сдвигаем ячейки
var cell = row.c[nCellInd];
this._moveCellHor(i, nCellInd, dif, oBBox);
if (cell && cell.getFormula()) {
//for #Ref
this.workbook.dependencyFormulas.addToChangedCell(cell);
}
}
}
}
}
//notifyChanged after move cells to get new locations
//notifyChanged after move cells to get new locations(for intersect ranges)
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));
this.autoFilters.insertColumn( "delCell", oBBox, c_oAscDeleteOptions.DeleteCellsAndShiftLeft );
History.Add(AscCommonExcel.g_oUndoRedoWorksheet, AscCH.historyitem_Worksheet_ShiftCellsLeft, this.getId(), oActualRange, new UndoRedoData_BBox(oBBox));
this.autoFilters.redrawStylesTables(redrawTablesArr);
//todo проверить не уменьшились ли границы таблицы
};
Woorksheet.prototype._shiftCellsUp=function(oBBox){
var nTop = oBBox.r1;
var nBottom = oBBox.r2;
var dif = nTop - nBottom - 1;
var oActualRange = new Asc.Range(oBBox.c1, oBBox.r1, oBBox.c2, gc_nMaxRow0);
//renameDependencyNodes before move cells to store current location in history
var changedFormulas = this.renameDependencyNodes({offsetRow: dif, offsetCol: 0}, oBBox);
var redrawTablesArr = this.autoFilters.insertRows( "delCell", oBBox, c_oAscDeleteOptions.DeleteCellsAndShiftTop );
var aIndexes = [];
for(var i in this.aGCells)
{
......@@ -4189,23 +4226,31 @@
var rowTop = this._getRow(nIndex);
//Сдвигаем ячейки
for(var j = oBBox.c1; j <= oBBox.c2; j++){
var cell = row.c[j];
this._moveCellVer(rowInd, j, dif);
if (cell && cell.getFormula()) {
//for #Ref
this.workbook.dependencyFormulas.addToChangedCell(cell);
}
}
}
}
}
//notifyChanged after move cells to get new locations
//notifyChanged after move cells to get new locations(for intersect ranges)
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));
this.autoFilters.insertRows( "delCell", oBBox, c_oAscDeleteOptions.DeleteCellsAndShiftTop );
History.Add(AscCommonExcel.g_oUndoRedoWorksheet, AscCH.historyitem_Worksheet_ShiftCellsTop, this.getId(), oActualRange, new UndoRedoData_BBox(oBBox));
this.autoFilters.redrawStylesTables(redrawTablesArr);
//todo проверить не уменьшились ли границы таблицы
};
Woorksheet.prototype._shiftCellsRight=function(oBBox, displayNameFormatTable){
var nLeft = oBBox.c1;
var nRight = oBBox.c2;
var dif = nRight - nLeft + 1;
var oActualRange = new Asc.Range(oBBox.c1, oBBox.r1, gc_nMaxCol0, oBBox.r2);
//renameDependencyNodes before move cells to store current location in history
var changedFormulas = this.renameDependencyNodes({offsetRow: 0, offsetCol: dif}, oBBox);
var redrawTablesArr = this.autoFilters.insertColumn( "insCells", oBBox, c_oAscInsertOptions.InsertCellsAndShiftRight, displayNameFormatTable );
for(var i = oBBox.r1; i <= oBBox.r2; i++){
var row = this.aGCells[i];
if(row){
......@@ -4226,22 +4271,34 @@
if(nCellInd + dif > this.nColsCount)
this.nColsCount = nCellInd + dif;
this._moveCellHor(/*row*/i, /*col*/nCellInd, dif, oBBox);
if (cell && cell.getFormula()) {
//for #Ref
this.workbook.dependencyFormulas.addToChangedCell(cell);
}
}
}
}
//notifyChanged after move cells to get new locations
}
//notifyChanged after move cells to get new locations(for intersect ranges)
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));
this.autoFilters.insertColumn( "insCells", oBBox, c_oAscInsertOptions.InsertCellsAndShiftRight, displayNameFormatTable );
History.Add(AscCommonExcel.g_oUndoRedoWorksheet, AscCH.historyitem_Worksheet_ShiftCellsRight, this.getId(), oActualRange, new UndoRedoData_BBox(oBBox));
this.autoFilters.redrawStylesTables(redrawTablesArr);
};
Woorksheet.prototype._shiftCellsBottom=function(oBBox, displayNameFormatTable){
var nTop = oBBox.r1;
var nBottom = oBBox.r2;
var dif = nBottom - nTop + 1;
var aIndexes = [];
var oActualRange = new Asc.Range(oBBox.c1, oBBox.r1, oBBox.c2, gc_nMaxRow0);
//renameDependencyNodes before move cells to store current location in history
var changedFormulas = this.renameDependencyNodes({offsetRow: dif, offsetCol: 0}, oBBox);
var redrawTablesArr;
if (!this.workbook.bUndoChanges) {
redrawTablesArr = this.autoFilters.insertRows("insCell", oBBox, c_oAscInsertOptions.InsertCellsAndShiftDown,
displayNameFormatTable);
}
for(var i in this.aGCells){
var rowInd = i - 0;
if(rowInd >= nTop)
......@@ -4259,17 +4316,22 @@
var rowTop = this._getRow(nIndex);
//Сдвигаем ячейки
for(var j = oBBox.c1; j <= oBBox.c2; j++){
var cell = row.c[j];
this._moveCellVer(rowInd, j, dif);
if (cell && cell.getFormula()) {
//for #Ref
this.workbook.dependencyFormulas.addToChangedCell(cell);
}
}
}
}
//notifyChanged after move cells to get new locations
//notifyChanged after move cells to get new locations(for intersect ranges)
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(), oActualRange, new UndoRedoData_BBox(oBBox));
if(!this.workbook.bUndoChanges)
{
this.autoFilters.insertRows( "insCell", oBBox, c_oAscInsertOptions.InsertCellsAndShiftDown, displayNameFormatTable );
this.autoFilters.redrawStylesTables(redrawTablesArr);
}
};
......@@ -5227,11 +5289,7 @@ Woorksheet.prototype.isApplyFilterBySheet = function(){
this.ws.workbook.dependencyFormulas.addToChangedCell(this);
} else if (AscCommon.c_oNotifyParentType.ChangeFormula === type) {
var DataOld = this.getValueData();
if (eventData.isRebuild) {
this.setFormula(eventData.assemble, true);
} else {
this.formulaParsed.Formula = eventData.assemble;
this.formulaParsed.buildDependencies();
this.ws.workbook.dependencyFormulas.addToChangedCell(this);
var DataNew = this.getValueData();
if (false == DataOld.isEqual(DataNew)) {
......@@ -5240,7 +5298,6 @@ Woorksheet.prototype.isApplyFilterBySheet = function(){
new UndoRedoData_CellSimpleData(this.nRow, this.nCol, DataOld, DataNew), true);
this.oValue.cleanCache();
}
}
} else if (AscCommon.c_oNotifyParentType.EndCalculate === type) {
this._updateCellValue();
}
......
......@@ -5897,11 +5897,11 @@ TablePart.prototype.deleteTableColumns = function(activeRange)
this.removeDependencies(deleted);
//todo undo
// var deletedMap = {};
// for (var i = 0; i < deleted.length; ++i) {
// deletedMap[deleted[i].Name] = 1;
// }
// this.handlers.trigger("deleteColumnTablePart", this.DisplayName, deletedMap);
var deletedMap = {};
for (var i = 0; i < deleted.length; ++i) {
deletedMap[deleted[i].Name] = 1;
}
this.handlers.trigger("deleteColumnTablePart", this.DisplayName, deletedMap);
}
};
......@@ -6360,15 +6360,6 @@ function TableColumn() {
return true;
} else if (AscCommon.c_oNotifyParentType.Change === type) {
this.TotalsRowFormula.setIsDirty(false);
} else if (AscCommon.c_oNotifyParentType.ChangeFormula === type) {
if (eventData.isRebuild) {
var ws = this.TotalsRowFormula.ws;
this.TotalsRowFormula = null;//to prevent removeDependencies in applyTotalRowFormula
this.applyTotalRowFormula(eventData.assemble, ws, true);
} else {
this.TotalsRowFormula.Formula = eventData.assemble;
this.TotalsRowFormula.buildDependencies();
}
}
};
TableColumn.prototype.renameSheetCopy = function(ws, renameParams) {
......
......@@ -919,14 +919,16 @@
case AscCH.historyitem_AutoFilter_Change:
if(data !== null && data.displayName)
{
var redrawTablesArr;
if(data.type === true)
{
this.insertLastTableColumn(data.displayName, data.activeCells);
redrawTablesArr = this.insertLastTableColumn(data.displayName, data.activeCells);
}
else if(data.type === false)
{
this.insertLastTableRow(data.displayName, data.activeCells);
redrawTablesArr = this.insertLastTableRow(data.displayName, data.activeCells);
}
this.redrawStylesTables(redrawTablesArr);
}
break;
case AscCH.historyitem_AutoFilter_ChangeTableInfo:
......@@ -1286,8 +1288,22 @@
}
return false;
},
insertColumn: function(type, activeRange, insertType, displayNameFormatTable)
_cleanStylesTables: function(redrawTablesArr) {
for(var i = 0; i < redrawTablesArr.length; i++) {
this._cleanStyleTable(redrawTablesArr[i].oldfilterRef);
}
},
_setStylesTables: function(redrawTablesArr) {
for(var i = 0; i < redrawTablesArr.length; i++) {
this._setColorStyleTable(redrawTablesArr[i].newFilter.Ref, redrawTablesArr[i].newFilter, null, true);
}
},
redrawStylesTables: function(redrawTablesArr) {
//set styles for tables
this._cleanStylesTables(redrawTablesArr);
this._setStylesTables(redrawTablesArr);
},
insertColumn: function(type, activeRange, insertType, displayNameFormatTable, bHistoryStyles)
{
var worksheet = this.worksheet;
var t = this;
......@@ -1306,25 +1322,6 @@
activeRange.r2 = AscCommon.gc_nMaxRow - 1;
}
History.StartTransaction();
History.Create_NewPoint();
var cleanStylesTables = function(redrawTablesArr)
{
for(var i = 0; i < redrawTablesArr.length; i++)
{
t._cleanStyleTable(redrawTablesArr[i].oldfilterRef);
}
};
var setStylesTables = function(redrawTablesArr)
{
for(var i = 0; i < redrawTablesArr.length; i++)
{
t._setColorStyleTable(redrawTablesArr[i].newFilter.Ref, redrawTablesArr[i].newFilter, null, true);
}
};
var changeFilter = function(filter, bTablePart)
{
var ref = filter.Ref;
......@@ -1435,14 +1432,9 @@
if(displayNameFormatTable && type == 'insCells')
{
this.insertLastTableColumn(displayNameFormatTable, activeRange);
redrawTablesArr = redrawTablesArr.concat(this.insertLastTableColumn(displayNameFormatTable, activeRange));
}
//set styles for tables
cleanStylesTables(redrawTablesArr);
setStylesTables(redrawTablesArr);
History.EndTransaction();
return redrawTablesArr;
},
insertLastTableColumn: function(displayNameFormatTable, activeRange)
......@@ -1454,25 +1446,6 @@
var redrawTablesArr = [];
History.StartTransaction();
History.Create_NewPoint();
var cleanStylesTables = function(redrawTablesArr)
{
for(var i = 0; i < redrawTablesArr.length; i++)
{
t._cleanStyleTable(redrawTablesArr[i].oldfilterRef);
}
};
var setStylesTables = function(redrawTablesArr)
{
for(var i = 0; i < redrawTablesArr.length; i++)
{
t._setColorStyleTable(redrawTablesArr[i].newFilter.Ref, redrawTablesArr[i].newFilter, null, true);
}
};
var changeFilter = function(filter)
{
var oldFilter = filter.clone(null);
......@@ -1499,14 +1472,10 @@
{
//change TableParts
changeFilter(tablePart);
//set styles for tables
cleanStylesTables(redrawTablesArr);
setStylesTables(redrawTablesArr);
}
History.EndTransaction();
return redrawTablesArr;
},
insertRows: function(type, activeRange, insertType, displayNameFormatTable)
......@@ -1529,25 +1498,6 @@
activeRange.c2 = AscCommon.gc_nMaxCol - 1;
}
History.StartTransaction();
History.Create_NewPoint();
var cleanStylesTables = function(redrawTablesArr)
{
for(var i = 0; i < redrawTablesArr.length; i++)
{
t._cleanStyleTable(redrawTablesArr[i].oldfilterRef);
}
};
var setStylesTables = function(redrawTablesArr)
{
for(var i = 0; i < redrawTablesArr.length; i++)
{
t._setColorStyleTable(redrawTablesArr[i].newFilter.Ref, redrawTablesArr[i].newFilter, null, true);
}
};
var changeFilter = function(filter, bTablePart)
{
var ref = filter.Ref;
......@@ -1611,14 +1561,10 @@
if(displayNameFormatTable && type == 'insCell')
{
this.insertLastTableRow(displayNameFormatTable, activeRange);
redrawTablesArr = redrawTablesArr.concat(this.insertLastTableRow(displayNameFormatTable, activeRange));
}
//set styles for tables
cleanStylesTables(redrawTablesArr);
setStylesTables(redrawTablesArr);
History.EndTransaction();
return redrawTablesArr;
},
insertLastTableRow: function(displayNameFormatTable, activeRange)
......@@ -1630,25 +1576,6 @@
var redrawTablesArr = [];
History.StartTransaction();
History.Create_NewPoint();
var cleanStylesTables = function(redrawTablesArr)
{
for(var i = 0; i < redrawTablesArr.length; i++)
{
t._cleanStyleTable(redrawTablesArr[i].oldfilterRef);
}
};
var setStylesTables = function(redrawTablesArr)
{
for(var i = 0; i < redrawTablesArr.length; i++)
{
t._setColorStyleTable(redrawTablesArr[i].newFilter.Ref, redrawTablesArr[i].newFilter, null, true);
}
};
var changeFilter = function(filter)
{
var oldFilter = filter.clone(null);
......@@ -1674,14 +1601,8 @@
{
//change TableParts
changeFilter(tablePart);
//set styles for tables
cleanStylesTables(redrawTablesArr);
setStylesTables(redrawTablesArr);
}
History.EndTransaction();
return redrawTablesArr;
},
sortColFilter: function(type, cellId, activeRange, sortProps, displayName, color) {
......@@ -2926,8 +2847,6 @@
activeHistoryRange = null;
History.Add(AscCommonExcel.g_oUndoRedoAutoFilters, type, ws.getId(), activeHistoryRange, oHistoryObject);
if(deleteFilterAfterDeleteColRow)
History.ChangeActionsEndToStart();
},
_getCurrentWS : function() {
......
......@@ -820,7 +820,7 @@
Shift: 1,
Move: 2,
Delete: 3,
Rebuild: 4,
RenameTableColumn: 4,
Changed: 5,
ChangeDefName: 6,
ChangeSheet: 7,
......
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