Commit 5d7fe4fb authored by Sergey Luzyanin's avatar Sergey Luzyanin

New undo-redo scheme

parent ae3cf693
......@@ -252,10 +252,25 @@ CHistory.prototype.Undo = function()
for ( var Index = Point.Items.length - 1; Index >= 0; Index-- )
{
var Item = Point.Items[Index];
if(!Item.Class.Read_FromBinary2)
if(!Item.Class.Read_FromBinary2 && !Item.Class.IsChangesClass)
Item.Class.Undo( Item.Type, Item.Data, Item.SheetId );
else
Item.Class.Undo(Item.Data);
{
if (Item.Class && Item.Class.IsChangesClass && Item.Class.IsChangesClass())
{
Item.Class.Undo();
Item.Class.RefreshRecalcData();
}
else
{
Item.Class.Undo(Item.Type);
Item.Class.Refresh_RecalcData(Item.Type);
}
}
this._addRedoObjectParam(oRedoObjectParam, Item);
}
this.UndoRedoEnd(Point, oRedoObjectParam, true);
......@@ -301,26 +316,39 @@ CHistory.prototype.RedoAdd = function(oRedoObjectParam, Class, Type, sheetid, ra
this.TurnOff();
// ToDo Убрать это!!!
if(Class && !Class.Load_Changes)
if(Class && !Class.Load_Changes && !Class.Load)
{
Class.Redo( Type, Data, sheetid );
}
else
{
if(!Data.isDrawingCollaborativeData)
if(Class && Data && !Data.isDrawingCollaborativeData)
Class.Redo(Data);
else
{
Data.oBinaryReader.Seek2(Data.nPos);
if(!Class)
{
Class = AscCommon.g_oTableId.Get_ById(Data.sChangedObjectId);
if(Class)
this.Add(Class, Type, sheetid, range, Data, LocalChange);
}
if(Class)
{
Class.Load_Changes(Data.oBinaryReader, null, new CDocumentColor(255, 255, 255));
if(!Class){
if(Data.isDrawingCollaborativeData){
Data.oBinaryReader.Seek2(Data.nPos);
var nReaderPos = Data.oBinaryReader.GetCurPos();
var nChangesType = Data.oBinaryReader.GetLong();
var changedObject = AscCommon.g_oTableId.Get_ById(Data.sChangedObjectId);
if(changedObject){
var fChangesClass = AscDFH.changesFactory[nChangesType];
if (fChangesClass)
{
var oChange = new fChangesClass(changedObject);
oChange.ReadFromBinary(Data.oBinaryReader);
oChange.Load(new CDocumentColor(255, 255, 255));
}
else
{
Data.oBinaryReader.Seek2(nReaderPos);
changedObject.Load_Changes(Data.oBinaryReader, null, new CDocumentColor(255, 255, 255));
}
}
}
}
}
}
......@@ -340,12 +368,24 @@ CHistory.prototype.RedoExecute = function(Point, oRedoObjectParam)
for ( var Index = 0; Index < Point.Items.length; Index++ )
{
var Item = Point.Items[Index];
if(!Item.Class.Load_Changes)
if(!Item.Class.Read_FromBinary2 && !Item.Class.IsChangesClass)
Item.Class.Redo( Item.Type, Item.Data, Item.SheetId );
else
{
if(!Item.Data.isDrawingCollaborativeData)
Item.Class.Redo(Item.Data);
if(!Item.Data || !Item.Data.isDrawingCollaborativeData)
{
if (Item.Class && Item.Class.IsChangesClass && Item.Class.IsChangesClass())
{
Item.Class.Redo();
Item.Class.RefreshRecalcData();
}
else
{
Item.Class.Redo(Item.Type);
Item.Class.Refresh_RecalcData(Item.Type);
}
}
else
{
Item.Data.oBinaryReader.Seek(Item.Data.nPos);
......@@ -548,8 +588,10 @@ CHistory.prototype.Get_RecalcData = function(Point2)
{
var Item = Point.Items[Index];
if ( /*true === Item.NeedRecalc*/ Item.Class && Item.Class.Refresh_RecalcData )
Item.Class.Refresh_RecalcData( Item.Data );
if (Item.Class && Item.Class.Refresh_RecalcData )
Item.Class.Refresh_RecalcData( Item.Type );
else if (Item.Class && Item.Class.RefreshRecalcData )
Item.Class.RefreshRecalcData();
if(Item.Type === AscCH.historyitem_Workbook_ChangeColorScheme && Item.Class === AscCommonExcel.g_oUndoRedoWorkbook)
{
var wsViews = Asc["editor"].wb.wsViews;
......@@ -694,32 +736,15 @@ CHistory.prototype.Add = function(Class, Type, sheetid, range, Data, LocalChange
var Item;
if ( this.RecIndex >= this.Index )
this.RecIndex = this.Index - 1;
// ToDo Убрать это!!!
if(Class && !Class.Save_Changes)
Item =
{
Item =
{
Class : Class,
Type : Type,
SheetId : sheetid,
Range : null,
Data : Data,
LocalChange: this.LocalChange
};
}
else
{
Item =
{
Class : Class,
Type : Type.Type,
SheetId : sheetid,
Range : null,
Data : Type,
LocalChange: this.LocalChange
};
}
Class : Class,
Type : Type,
SheetId : sheetid,
Range : null,
Data : Data,
LocalChange: this.LocalChange
};
if(null != range)
Item.Range = range.clone();
if(null != LocalChange)
......
......@@ -82,7 +82,7 @@ function UndoRedoItemSerializable(oClass, nActionType, nSheetId, oRange, oData,
UndoRedoItemSerializable.prototype = {
Serialize : function(oBinaryWriter, collaborativeEditing)
{
if(this.oData.getType || this.oClass.Save_Changes)
if((this.oData && this.oData.getType) || this.oClass.Save_Changes || this.oClass.WriteToBinary)
{
var oThis = this;
var oBinaryCommonWriter = new AscCommon.BinaryCommonWriter(oBinaryWriter);
......@@ -92,7 +92,7 @@ UndoRedoItemSerializable.prototype = {
SerializeInner : function(oBinaryWriter, collaborativeEditing)
{
//nClassType
if(!this.oClass.Save_Changes)
if(!this.oClass.Save_Changes && !this.oClass.WriteToBinary)
{
oBinaryWriter.WriteBool(true);
var nClassType = this.oClass.getClassType();
......@@ -139,9 +139,20 @@ UndoRedoItemSerializable.prototype = {
else
{
oBinaryWriter.WriteBool(false);
oBinaryWriter.WriteString2(this.oClass.Get_Id());
var Class;
if (this.oClass && this.oClass.IsChangesClass && this.oClass.IsChangesClass())
{
Class = this.oClass.GetClass();
oBinaryWriter.WriteString2(Class.Get_Id());
oBinaryWriter.WriteLong(this.oClass.Type);
this.oClass.WriteToBinary(oBinaryWriter);
}
else
{
oBinaryWriter.WriteString2(this.oClass.Get_Id());
this.oClass.Save_Changes(this.nActionType, oBinaryWriter);
}
this.oClass.Save_Changes(this.oData, oBinaryWriter);
}
},
SerializeDataObject : function(oBinaryWriter, oData, nSheetId, collaborativeEditing)
......@@ -281,14 +292,12 @@ UndoRedoItemSerializable.prototype = {
else
{
var changedObjectId = oBinaryReader.GetString2();
var changedObject = AscCommon.g_oTableId.Get_ById(changedObjectId);
this.nActionType = 1;
this.oClass = changedObject;
this.oData = new DrawingCollaborativeData();
this.oData.oClass = changedObject;
this.oData.sChangedObjectId = changedObjectId;
this.oData.oBinaryReader = oBinaryReader;
this.oData.nPos = oBinaryReader.cur;
}
},
DeserializeData : function(oBinaryReader)
......
......@@ -59,10 +59,23 @@ AscCommon.CContentChangesElement.prototype.Refresh_BinaryData = function()
var Binary_Writer = History.BinaryWriter;
var Binary_Pos = Binary_Writer.GetCurPosition();
this.m_pData.Data.UseArray = true;
this.m_pData.Data.PosArray = this.m_aPositions;
Binary_Writer.WriteString2(this.m_pData.Class.Get_Id());
this.m_pData.Class.Save_Changes( this.m_pData.Data, Binary_Writer );
if (this.m_pData.Data && this.m_pData.Data.IsChangesClass && this.m_pData.Data.IsChangesClass())
{
this.m_pData.Data.UseArray = true;
this.m_pData.Data.PosArray = this.m_aPositions;
Binary_Writer.WriteString2(this.m_pData.Class.Get_Id());
Binary_Writer.WriteLong(this.m_pData.Data.Type);
this.m_pData.Data.WriteToBinary(Binary_Writer);
}
else
{
this.m_pData.Data.UseArray = true;
this.m_pData.Data.PosArray = this.m_aPositions;
Binary_Writer.WriteString2(this.m_pData.Class.Get_Id());
this.m_pData.Class.Save_Changes(this.m_pData.Data, Binary_Writer);
}
var Binary_Len = Binary_Writer.GetCurPosition() - Binary_Pos;
......
......@@ -743,6 +743,7 @@ CCollaborativeEditingBase.prototype.InitMemory = function() {
};
CCollaborativeEditingBase.prototype.private_AddOverallChange = function(oChange)
{
return true;
};
......
......@@ -300,7 +300,10 @@ CChangesDocumentRemoveItem.prototype.Load = function(Color)
oDocument.Content[Pos].Prev = null;
}
oDocument.SectionsInfo.Update_OnRemove(Pos, 1);
if(oDocument.SectionsInfo)
{
oDocument.SectionsInfo.Update_OnRemove(Pos, 1);
}
oDocument.private_ReindexContent(Pos);
}
};
......
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