Commit 6550cfe4 authored by Sergey.Konovalov's avatar Sergey.Konovalov Committed by Alexander.Trofimov

SerializeHistory, DeserializeHistory изменен формат пересылаемых изменений,...

SerializeHistory, DeserializeHistory изменен формат пересылаемых изменений, улучшение для одного человека.

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@56838 954022d7-b5bf-4e40-9824-e11837661b57
parent 8dc39a3e
......@@ -1328,7 +1328,10 @@ var ASC_DOCS_API_USE_EMBEDDED_FONTS = "@@ASC_DOCS_API_USE_EMBEDDED_FONTS";
_loadFonts: function (fonts, callback) {
if (window["NATIVE_EDITOR_ENJINE"])
return callback();
var aFonts = [];
for (var i in fonts)
aFonts.push(i);
History.Add(g_oUndoRedoWorkbook, historyitem_Workbook_AddFont, null, null, new UndoRedoData_SingleProperty(aFonts), true);
this.asyncMethodCallback = callback;
var arrLoadFonts = [];
for(var i in fonts)
......
......@@ -7,6 +7,8 @@ var historyitem_Workbook_SheetRemove = 2;
var historyitem_Workbook_SheetMove = 3;
var historyitem_Workbook_SheetPositions = 4;
var historyitem_Workbook_ChangeColorScheme = 5;
var historyitem_Workbook_AddFont = 6;
var historyitem_Workbook_AddFont2 = 7;
var historyitem_Worksheet_RemoveCell = 1;
var historyitem_Worksheet_RemoveRows = 2;
......@@ -930,24 +932,20 @@ CHistory.prototype =
GetSerializeArray : function()
{
var aRes = [];
for(var i = 0; i <= this.Index; ++i)
this._checkCurPoint();
var i = 0;
if (null != this.SavedIndex)
i = this.SavedIndex + 1;
for(; i <= this.Index; ++i)
{
var point = this.Points[i];
var aPointChanges = [];
for(var j = 0, length2 = point.Items.length; j < length2; ++j)
{
var elem = point.Items[j];
if(true != elem.LocalChange)
aRes.push(new UndoRedoItemSerializable(elem.Class, elem.Type, elem.SheetId, elem.Range, elem.Data));
}
}
if(null != this.CurPoint)
{
for(var j = 0, length2 = this.CurPoint.Items.length; j < length2; ++j)
{
var elem = this.CurPoint.Items[j];
if(true != elem.LocalChange)
aRes.push(new UndoRedoItemSerializable(elem.Class, elem.Type, elem.SheetId, elem.Range, elem.Data));
aPointChanges.push(new UndoRedoItemSerializable(elem.Class, elem.Type, elem.SheetId, elem.Range, elem.Data, elem.LocalChange));
}
aRes.push(aPointChanges);
}
return aRes;
},
......
......@@ -22,13 +22,14 @@ function DrawingCollaborativeData()
this.isDrawingCollaborativeData = true;
}
//главный обьект для пересылки изменений
function UndoRedoItemSerializable(oClass, nActionType, nSheetId, oRange, oData)
function UndoRedoItemSerializable(oClass, nActionType, nSheetId, oRange, oData, LocalChange)
{
this.oClass = oClass;
this.nActionType = nActionType;
this.nSheetId = nSheetId;
this.oRange = oRange;
this.oData = oData;
this.LocalChange = LocalChange;
}
UndoRedoItemSerializable.prototype = {
Serialize : function(oBinaryWriter, collaborativeEditing)
......
......@@ -1663,6 +1663,16 @@ Workbook.prototype.recalcDependency = function(f,bad,notRecalc){
return sr;
}
};
Workbook.prototype._SerializeHistoryBase64 = function (oMemory, item, aPointChangesBase64) {
if (!item.LocalChange) {
var nPosStart = oMemory.GetCurPosition();
item.Serialize(oMemory, this.oApi.collaborativeEditing);
var nPosEnd = oMemory.GetCurPosition();
var nLen = nPosEnd - nPosStart;
if (nLen > 0)
aPointChangesBase64.push(nLen + ";" + oMemory.GetBase64Memory2(nPosStart, nLen));
}
}
Workbook.prototype.SerializeHistory = function(){
var aRes = [];
//соединяем изменения, которые были до приема данных с теми, что получились после.
......@@ -1677,23 +1687,42 @@ Workbook.prototype.SerializeHistory = function(){
{
var oMemory = new CMemory();
var oThis = this;
var oFontMap = {};
var bChangeSheetPlace = false;
var aPointChangesBase64;
for(var i = 0, length = aActions.length; i < length; ++i)
{
var aPointChanges = aActions[i];
aPointChangesBase64 = [];
for (var j = 0, length2 = aPointChanges.length; j < length2; ++j) {
var item = aPointChanges[j];
if (g_oUndoRedoWorkbook == item.oClass) {
if (historyitem_Workbook_AddFont == item.nActionType) {
for (var k = 0, length3 = item.oData.elem.length; k < length3; ++k)
oFontMap[item.oData.elem[k]] = 1;
}
else if (historyitem_Workbook_SheetAdd == item.nActionType || historyitem_Workbook_SheetRemove == item.nActionType || historyitem_Workbook_SheetMove == item.nActionType)
bChangeSheetPlace = true;
}
this._SerializeHistoryBase64(oMemory, item, aPointChangesBase64);
}
aRes.push(aPointChangesBase64);
}
aPointChangesBase64 = [];
var aFonts = [];
for (var i in oFontMap)
aFonts.push(i);
if (aFonts.length > 0)
this._SerializeHistoryBase64(oMemory, new UndoRedoItemSerializable(g_oUndoRedoWorkbook, historyitem_Workbook_AddFont2, null, null, new UndoRedoData_SingleProperty(aFonts)), aPointChangesBase64);
if (bChangeSheetPlace) {
//создаем еще один элемент в undo/redo - взаимное расположение Sheet, чтобы не запутываться в add, move событиях
var oSheetPlaceData = [];
for(var i = 0, length = this.aWorksheets.length; i < length; ++i)
for (var i = 0, length = this.aWorksheets.length; i < length; ++i)
oSheetPlaceData.push(this.aWorksheets[i].getId());
aActions.push(new UndoRedoItemSerializable(g_oUndoRedoWorkbook, historyitem_Workbook_SheetPositions, null, null, new UndoRedoData_SheetPositions(oSheetPlaceData)));
for(var i = 0, length = aActions.length; i < length; ++i)
{
var nPosStart = oMemory.GetCurPosition();
var item = aActions[i];
item.Serialize(oMemory, this.oApi.collaborativeEditing);
var nPosEnd = oMemory.GetCurPosition();
var nLen = nPosEnd - nPosStart;
if(nLen > 0)
aRes.push(nLen + ";" + oMemory.GetBase64Memory2(nPosStart, nLen));
this._SerializeHistoryBase64(oMemory, new UndoRedoItemSerializable(g_oUndoRedoWorkbook, historyitem_Workbook_SheetPositions, null, null, new UndoRedoData_SheetPositions(oSheetPlaceData)), aPointChangesBase64);
}
//добавляем элемент, который содержит все используемые шрифты, чтобы их можно было загрузить в начале
aRes.push("0;fontmap" + this.generateFontMap().join(","));
if (aPointChangesBase64.length > 0)
aRes.push(aPointChangesBase64);
this.aCollaborativeActions = [];
}
return aRes;
......@@ -1710,14 +1739,18 @@ Workbook.prototype.DeserializeHistory = function(aChanges, fCallback){
var aIndexes = [];
for(var i = 0, length = aChanges.length;i < length; ++i)
{
var sChange = aChanges[i];
var aPointChanges = aChanges[i];
var aIndexesPoint = [];
for (var j = 0, length2 = aPointChanges.length; j < length2; ++j) {
var sChange = aPointChanges[j];
var nIndex = sChange.indexOf(";");
if(-1 != nIndex)
{
if (-1 != nIndex) {
dstLen += parseInt(sChange.substring(0, nIndex));
nIndex++;
}
aIndexes.push(nIndex);
aIndexesPoint.push(nIndex);
}
aIndexes.push(aIndexesPoint);
}
var pointer = g_memory.Alloc(dstLen);
var stream = new FT_Stream2(pointer.data, dstLen);
......@@ -1725,19 +1758,23 @@ Workbook.prototype.DeserializeHistory = function(aChanges, fCallback){
var nCurOffset = 0;
//пробегаемся первый раз чтобы заполнить oFontMap
var oFontMap = {};//собираем все шрифтры со всех изменений
var sFontMapString = "0;fontmap";
for(var i = 0, length = aChanges.length; i < length; ++i)
{
var sChange = aChanges[i];
if(sFontMapString == sChange.substring(0, sFontMapString.length))
{
var sFonts = sChange.substring(sFontMapString.length);
var aFonts = sFonts.split(",");
for(var j = 0, length2 = aFonts.length; j < length2; ++j)
oFontMap[aFonts[j]] = 1;
var aUndoRedoElems = [];
for (var i = 0, length = aChanges.length; i < length; ++i) {
var aPointChanges = aChanges[i];
var aIndexesPoint = aIndexes[i];
for (var j = 0, length2 = aPointChanges.length; j < length2; ++j) {
var sChange = aPointChanges[j];
var oBinaryFileReader = new Asc.BinaryFileReader();
nCurOffset = oBinaryFileReader.getbase64DecodedData2(sChange, aIndexesPoint[j], stream, nCurOffset);
var item = new UndoRedoItemSerializable();
item.Deserialize(stream);
if (g_oUndoRedoWorkbook == item.oClass && historyitem_Workbook_AddFont2 == item.nActionType) {
for (var k = 0, length3 = item.oData.elem.length; k < length3; ++k)
oFontMap[item.oData.elem[k]] = 1;
}
aUndoRedoElems.push(item);
}
}
window["Asc"]["editor"]._loadFonts(oFontMap, function(){
History.Clear();
History.Create_NewPoint();
......@@ -1746,28 +1783,19 @@ Workbook.prototype.DeserializeHistory = function(aChanges, fCallback){
var oHistoryPositions = null;//нужен самый последний historyitem_Workbook_SheetPositions
var oRedoObjectParam = new Asc.RedoObjectParam();
History.UndoRedoPrepare(oRedoObjectParam, false);
for(var i = 0, length = aChanges.length; i < length; ++i)
{
var sChange = aChanges[i];
if(sFontMapString != sChange.substring(0, sFontMapString.length))
for (var i = 0, length = aUndoRedoElems.length; i < length; ++i)
{
var oBinaryFileReader = new Asc.BinaryFileReader();
nCurOffset = oBinaryFileReader.getbase64DecodedData2(sChange, aIndexes[i], stream, nCurOffset);
var item = new UndoRedoItemSerializable();
item.Deserialize(stream);
if(null != item.oClass && null != item.nActionType)
{
if(g_oUndoRedoWorkbook == item.oClass && historyitem_Workbook_SheetPositions == item.nActionType)
var item = aUndoRedoElems[i];
if (null != item.oClass && null != item.nActionType) {
if (g_oUndoRedoWorkbook == item.oClass && historyitem_Workbook_SheetPositions == item.nActionType)
oHistoryPositions = item;
else
{
else {
// TODO if(g_oUndoRedoGraphicObjects == item.oClass && item.oData.drawingData)
// item.oData.drawingData.bCollaborativeChanges = true;
History.RedoAdd(oRedoObjectParam, item.oClass, item.nActionType, item.nSheetId, item.oRange, item.oData);
}
}
}
}
if(null != oHistoryPositions)
History.RedoAdd(oRedoObjectParam, oHistoryPositions.oClass, oHistoryPositions.nActionType, oHistoryPositions.nSheetId, oHistoryPositions.oRange, oHistoryPositions.oData);
......
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