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