Commit 4698887a authored by GoshaZotov's avatar GoshaZotov Committed by Alexander.Trofimov

add function for change format table ref(af_changeTableRange)

parent 455a942a
...@@ -104,6 +104,7 @@ var historyitem_AutoFilter_ChangeTableStyle = 9; ...@@ -104,6 +104,7 @@ var historyitem_AutoFilter_ChangeTableStyle = 9;
var historyitem_AutoFilter_Change = 10; var historyitem_AutoFilter_Change = 10;
var historyitem_AutoFilter_CleanFormat = 11; var historyitem_AutoFilter_CleanFormat = 11;
var historyitem_AutoFilter_ChangeTableInfo = 12; var historyitem_AutoFilter_ChangeTableInfo = 12;
var historyitem_AutoFilter_ChangeTableRef = 13;
function CHistory(workbook) function CHistory(workbook)
......
...@@ -4563,6 +4563,47 @@ TablePart.prototype.changeRef = function(col, row, bIsFirst) { ...@@ -4563,6 +4563,47 @@ TablePart.prototype.changeRef = function(col, row, bIsFirst) {
if(this.AutoFilter) if(this.AutoFilter)
this.AutoFilter.changeRef(col, row, bIsFirst); this.AutoFilter.changeRef(col, row, bIsFirst);
}; };
TablePart.prototype.changeRefOnRange = function(range, autoFilters, generateNewTableColumns) {
if(!range)
return;
//add table columns
if(generateNewTableColumns)
{
var newTableColumns = [];
var intersectionRanges = this.Ref.intersection(range);
for(var i = range.c1; i <= range.c2; i++)
{
var tableColumn;
if(i >= intersectionRanges.c1 && i <= intersectionRanges.c2)
{
var tableIndex = i - this.Ref.c1;
tableColumn = this.TableColumns[tableIndex];
}
else
{
tableColumn = new TableColumn();
}
newTableColumns.push(tableColumn);
}
for(var j = 0; j < newTableColumns.length; j++)
{
if(newTableColumns[j].Name === null)
newTableColumns[j].Name = autoFilters._generateColumnName2(newTableColumns);
}
this.TableColumns = newTableColumns;
}
this.Ref = Asc.Range(range.c1, range.r1, range.c2, range.r2);
//event
this.handlers.trigger("changeRefTablePart", this.DisplayName, this.Ref);
if(this.AutoFilter)
this.AutoFilter.changeRefOnRange(range);
};
TablePart.prototype.isApplyAutoFilter = function() { TablePart.prototype.isApplyAutoFilter = function() {
var res = false; var res = false;
...@@ -4634,7 +4675,7 @@ TablePart.prototype.addTableColumns = function(activeRange, autoFilters) ...@@ -4634,7 +4675,7 @@ TablePart.prototype.addTableColumns = function(activeRange, autoFilters)
for(var j = 0; j < newTableColumns.length; j++) for(var j = 0; j < newTableColumns.length; j++)
{ {
if(newTableColumns[j].Name === null) if(newTableColumns[j].Name === null)
newTableColumns[j].Name = autoFilters._generateColumnName2(newTableColumns, newTableColumns[j - 1].Name); newTableColumns[j].Name = autoFilters._generateColumnName2(newTableColumns);
} }
this.TableColumns = newTableColumns; this.TableColumns = newTableColumns;
...@@ -4644,7 +4685,7 @@ TablePart.prototype.addTableLastColumn = function(activeRange, autoFilters, isAd ...@@ -4644,7 +4685,7 @@ TablePart.prototype.addTableLastColumn = function(activeRange, autoFilters, isAd
{ {
var newTableColumns = this.TableColumns; var newTableColumns = this.TableColumns;
newTableColumns.push(new TableColumn()); newTableColumns.push(new TableColumn());
newTableColumns[newTableColumns.length - 1].Name = autoFilters._generateColumnName2(newTableColumns, newTableColumns[newTableColumns.length - 2].Name); newTableColumns[newTableColumns.length - 1].Name = autoFilters._generateColumnName2(newTableColumns);
this.TableColumns = newTableColumns; this.TableColumns = newTableColumns;
}; };
...@@ -4846,6 +4887,15 @@ AutoFilter.prototype.changeRef = function(col, row, bIsFirst) { ...@@ -4846,6 +4887,15 @@ AutoFilter.prototype.changeRef = function(col, row, bIsFirst) {
this.Ref = ref; this.Ref = ref;
}; };
AutoFilter.prototype.changeRefOnRange = function(range) {
if(!range)
return;
this.Ref = Asc.Range(range.c1, range.r1, range.c2, range.r2);
if(this.AutoFilter)
this.AutoFilter.changeRefOnRange(range);
};
AutoFilter.prototype.isApplyAutoFilter = function() { AutoFilter.prototype.isApplyAutoFilter = function() {
var res = false; var res = false;
......
...@@ -727,6 +727,9 @@ ...@@ -727,6 +727,9 @@
case historyitem_AutoFilter_ChangeTableInfo: case historyitem_AutoFilter_ChangeTableInfo:
this.changeFormatTableInfo(data.displayName, data.type, data.val); this.changeFormatTableInfo(data.displayName, data.type, data.val);
break; break;
case historyitem_AutoFilter_ChangeTableRef:
this.changeTableRange(data.displayName, data.moveTo);
break;
} }
History.TurnOn(); History.TurnOn();
}, },
...@@ -768,7 +771,7 @@ ...@@ -768,7 +771,7 @@
else else
worksheet.AutoFilter = cloneData; worksheet.AutoFilter = cloneData;
} }
else if(type === historyitem_AutoFilter_Change || type === historyitem_AutoFilter_ChangeTableInfo)//добавление/удаление строк/столбцов else if(type === historyitem_AutoFilter_Change || type === historyitem_AutoFilter_ChangeTableInfo || type === historyitem_AutoFilter_ChangeTableRef)
{ {
if(worksheet.AutoFilter && cloneData.newFilterRef.isEqual(worksheet.AutoFilter.Ref)) if(worksheet.AutoFilter && cloneData.newFilterRef.isEqual(worksheet.AutoFilter.Ref))
worksheet.AutoFilter = cloneData.oldFilter.clone(null); worksheet.AutoFilter = cloneData.oldFilter.clone(null);
...@@ -2217,7 +2220,22 @@ ...@@ -2217,7 +2220,22 @@
changeTableRange: function(tableName, range) changeTableRange: function(tableName, range)
{ {
var tablePart = this._getFilterByDisplayName(tableName);
if(!tablePart)
{
return false;
}
var oldFilter = tablePart.clone(null);
tablePart.changeRefOnRange(range, this, true);
this._addHistoryObj({oldFilter: oldFilter, newFilterRef: tablePart.Ref.clone()}, historyitem_AutoFilter_ChangeTableRef,
{activeCells: tablePart.Ref.clone(), arnTo: range, displayName: tableName});
this._cleanStyleTable(oldFilter.Ref);
this._setColorStyleTable(tablePart.Ref, tablePart, null, true);
}, },
_clearRange: function(range, isClearText) _clearRange: function(range, isClearText)
...@@ -4380,10 +4398,9 @@ ...@@ -4380,10 +4398,9 @@
} }
}, },
_generateColumnName2: function(tableColumns, prevColumnName) _generateColumnName2: function(tableColumns)
{ {
var columnName = "Column"; var columnName = "Column";
var name = prevColumnName.split(columnName);
var indexColumn = name[1]; var indexColumn = name[1];
var nextIndex; var nextIndex;
......
...@@ -13181,9 +13181,11 @@ ...@@ -13181,9 +13181,11 @@
{ {
History.Create_NewPoint(); History.Create_NewPoint();
History.StartTransaction(); History.StartTransaction();
range = Asc.g_oRangeCache.getAscRange(range);
this.model.autoFilters.changeTableRange(tableName, range); this.model.autoFilters.changeTableRange(tableName, range);
//this._onUpdateFormatTable(isChangeRange, false, true); this._onUpdateFormatTable(range, false, true);
//TODO добавить перерисовку таблицы и перерисовку шаблонов //TODO добавить перерисовку таблицы и перерисовку шаблонов
History.EndTransaction(); History.EndTransaction();
}; };
......
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