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

New undo-redo scheme

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