Commit c2d1018d authored by Ilya Kirillov's avatar Ilya Kirillov

Added base classes for changes in collaboration. Started to rework...

Added base classes for changes in collaboration. Started to rework collabotation changes into a classes for class ParaRun.
parent 6caadc8c
......@@ -1005,10 +1005,15 @@
}
return sString;
}
function GetHistoryClassTypeByChangeType(nChangeType)
{
return (nChangeType >> 16) & 0x0000FFFF;
}
//------------------------------------------------------------export--------------------------------------------------
window['AscDFH'] = window['AscDFH'] || {};
window['AscDFH'].GetHistoryPointStringDescription = GetHistoryPointStringDescription;
window['AscDFH'].GetHistoryClassTypeByChangeType = GetHistoryClassTypeByChangeType;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
......@@ -2843,4 +2848,122 @@
window['AscDFH'].historydescription_Document_AddPageCount = 0x013b;
window['AscDFH'].historydescription_Document_AddFootnote = 0x013c;
window['AscDFH'].historydescription_Document_SetFootnotePr = 0x013d;
/**
* Базовый класс для всех изменений совместного редактирования.
* @constructor
*/
function CChangesBase(Class)
{
this.Class = Class;
}
CChangesBase.prototype.Type = window['AscDFH'].historyitem_Unknown_Unknown;
CChangesBase.prototype.Undo = function()
{
if (this.Class && this.Class.Undo)
this.Class.Undo(this);
};
CChangesBase.prototype.Redo = function()
{
if (this.Class && this.Class.Redo)
this.Class.Redo(this);
};
CChangesBase.prototype.WriteToBinary = function(Writer)
{
if (this.Class && this.Class.Save_Changes)
this.Class.Save_Changes(this, Writer);
};
CChangesBase.prototype.ReadFromBinary = function(Reader)
{
};
CChangesBase.prototype.Load = function()
{
// В большинстве случаев загрузка чужого изменения работает как простое Redo
this.Redo();
};
window['AscDFH'].CChangesBase = CChangesBase;
/**
* Базовый класс для изменения булевых свойств.
* @constructor
* @extends {AscDFH.CChangesBase}
*/
function CChangesBaseBoolProperty(Class, Old, New)
{
CChangesBaseBoolProperty.superclass.constructor.call(this, Class);
this.Color = false;
this.Old = Old;
this.New = New;
}
AscCommon.extendClass(CChangesBase, CChangesBaseBoolProperty);
CChangesBaseBoolProperty.prototype.Undo = function()
{
this.private_SetValue(this.Old);
};
CChangesBaseBoolProperty.prototype.Redo = function()
{
this.private_SetValue(this.New);
};
CChangesBaseBoolProperty.prototype.WriteToBinary = function(Writer)
{
// Long : Flag
// 1-bit : Подсвечивать ли данные изменения
// 2-bit : IsUndefined New
// 3-bit : New value
// 4-bit : IsUndefined Old
// 5-bit : Old value
var nFlags = 0;
if (false !== this.Color)
nFlags |= 1;
if (undefined === this.New)
nFlags |= 2;
else if (true === this.New)
nFlags |= 4;
if (undefined === this.Old)
nFlags |= 8;
else if (true === this.Old)
nFlags |= 16;
Writer.WriteLong(nFlags);
};
CChangesBaseBoolProperty.prototype.ReadFromBinary = function(Reader)
{
// Long : Flag
// 1-bit : Подсвечивать ли данные изменения
// 2-bit : IsUndefined New
// 3-bit : New value
// 4-bit : IsUndefined Old
// 5-bit : Old value
var nFlags = Reader.GetLong();
if (nFlags & 1)
this.Color = true;
else
this.Color = false;
if (nFlags & 2)
this.New = undefined;
else if (nFlags & 4)
this.New = true;
else
this.New = false;
if (nFlags & 8)
this.Old = undefined;
else if (nFlags & 16)
this.Old = true;
else
this.Old = false;
};
CChangesBaseBoolProperty.prototype.private_SetValue = function(Value)
{
// Эту функцию нужно переопределить в дочернем классе
};
window['AscDFH'].CChangesBaseBoolProperty = CChangesBaseBoolProperty;
})(window);
......@@ -2392,7 +2392,7 @@ CTableId.prototype.Load_Changes = function(Reader, Reader2)
// console.log("----------------------------");
// console.log("FileCheckSum " + FileCheckSum);
// console.log("FileSize " + FileSize);
// console.log("Description " + Description + " " + AscDFH.Get_HistoryPointStringDescription(Description));
// console.log("Description " + Description + " " + AscDFH.GetHistoryPointStringDescription(Description));
// console.log("PointIndex " + PointIndex);
// console.log("StartPoint " + StartPoint);
// console.log("LastPoint " + LastPoint);
......
......@@ -7300,32 +7300,6 @@ ParaRun.prototype.Undo = function(Data)
switch ( Type )
{
case AscDFH.historyitem_ParaRun_AddItem :
{
this.Content.splice( Data.Pos, Data.EndPos - Data.Pos + 1 );
this.RecalcInfo.Measure = true;
this.protected_UpdateSpellChecking();
this.private_UpdateTrackRevisionOnChangeContent(false);
break;
}
case AscDFH.historyitem_ParaRun_RemoveItem :
{
var Pos = Data.Pos;
var Array_start = this.Content.slice( 0, Pos );
var Array_end = this.Content.slice( Pos );
this.Content = Array_start.concat( Data.Items, Array_end );
this.RecalcInfo.Measure = true;
this.protected_UpdateSpellChecking();
this.private_UpdateTrackRevisionOnChangeContent(false);
break;
}
case AscDFH.historyitem_ParaRun_TextPr:
{
......@@ -7747,31 +7721,6 @@ ParaRun.prototype.Redo = function(Data)
switch ( Type )
{
case AscDFH.historyitem_ParaRun_AddItem:
{
var Pos = Data.Pos;
var Array_start = this.Content.slice( 0, Pos );
var Array_end = this.Content.slice( Pos );
this.Content = Array_start.concat( Data.Items, Array_end );
this.RecalcInfo.Measure = true;
this.protected_UpdateSpellChecking();
this.private_UpdateTrackRevisionOnChangeContent(false);
break;
}
case AscDFH.historyitem_ParaRun_RemoveItem:
{
this.Content.splice( Data.Pos, Data.EndPos - Data.Pos + 1 );
this.RecalcInfo.Measure = true;
this.protected_UpdateSpellChecking();
this.private_UpdateTrackRevisionOnChangeContent(false);
break;
}
case AscDFH.historyitem_ParaRun_TextPr:
{
......@@ -8212,77 +8161,6 @@ ParaRun.prototype.Save_Changes = function(Data, Writer)
switch ( Type )
{
case AscDFH.historyitem_ParaRun_AddItem:
{
// Bool : Подсвечивать ли данные изменения
// Long : Количество элементов
// Array of :
// {
// Long : Позиция
// Variable : Элемент
// }
var bArray = Data.UseArray;
var Count = Data.Items.length;
if (false === Data.Color)
Writer.WriteBool(false);
else
Writer.WriteBool(true);
Writer.WriteLong( Count );
for ( var Index = 0; Index < Count; Index++ )
{
if ( true === bArray )
Writer.WriteLong( Data.PosArray[Index] );
else
Writer.WriteLong( Data.Pos + Index );
Data.Items[Index].Write_ToBinary(Writer);
}
break;
}
case AscDFH.historyitem_ParaRun_RemoveItem:
{
// Long : Количество удаляемых элементов
// Array of Long : позиции удаляемых элементов
var bArray = Data.UseArray;
var Count = Data.Items.length;
var StartPos = Writer.GetCurPosition();
Writer.Skip(4);
var RealCount = Count;
for ( var Index = 0; Index < Count; Index++ )
{
if ( true === bArray )
{
if ( false === Data.PosArray[Index] )
{
RealCount--;
}
else
{
Writer.WriteLong(Data.PosArray[Index]);
}
}
else
{
Writer.WriteLong(Data.Pos);
}
}
var EndPos = Writer.GetCurPosition();
Writer.Seek( StartPos );
Writer.WriteLong( RealCount );
Writer.Seek( EndPos );
break;
}
case AscDFH.historyitem_ParaRun_TextPr:
{
// Bool : Подсвечивать ли данные изменения
......@@ -8822,73 +8700,6 @@ ParaRun.prototype.Load_Changes = function(Reader, Reader2, Color)
var bColorPrChange = false;
switch ( Type )
{
case AscDFH.historyitem_ParaRun_AddItem :
{
// Bool : Подсвечивать ли данные изменения
// Long : Количество элементов
// Array of :
// {
// Long : Позиция
// Variable : Id Элемента
// }
var bColorChanges = Reader.GetBool();
var Count = Reader.GetLong();
for ( var Index = 0; Index < Count; Index++ )
{
var Pos = this.m_oContentChanges.Check( AscCommon.contentchanges_Add, Reader.GetLong() );
var Element = ParagraphContent_Read_FromBinary(Reader);
if ( null != Element )
{
if (true === bColorChanges && null !== Color)
{
this.CollaborativeMarks.Update_OnAdd( Pos );
this.CollaborativeMarks.Add( Pos, Pos + 1, Color );
AscCommon.CollaborativeEditing.Add_ChangedClass(this);
}
this.Content.splice(Pos, 0, Element);
this.private_UpdatePositionsOnAdd(Pos);
this.private_UpdateCompositeInputPositionsOnAdd(Pos);
AscCommon.CollaborativeEditing.Update_DocumentPositionsOnAdd(this, Pos);
}
}
this.RecalcInfo.Measure = true;
this.protected_UpdateSpellChecking();
this.private_UpdateTrackRevisionOnChangeContent(false);
break;
}
case AscDFH.historyitem_ParaRun_RemoveItem:
{
// Long : Количество удаляемых элементов
// Array of Long : позиции удаляемых элементов
var Count = Reader.GetLong();
for ( var Index = 0; Index < Count; Index++ )
{
var ChangesPos = this.m_oContentChanges.Check(AscCommon.contentchanges_Remove, Reader.GetLong());
// действие совпало, не делаем его
if (false === ChangesPos)
continue;
this.CollaborativeMarks.Update_OnRemove(ChangesPos, 1);
this.Content.splice(ChangesPos, 1);
this.private_UpdatePositionsOnRemove(ChangesPos, 1);
this.private_UpdateCompositeInputPositionsOnRemove(ChangesPos, 1);
AscCommon.CollaborativeEditing.Update_DocumentPositionsOnRemove(this, ChangesPos, 1);
}
this.RecalcInfo.Measure = true;
this.protected_UpdateSpellChecking();
this.private_UpdateTrackRevisionOnChangeContent(false);
break;
}
case AscDFH.historyitem_ParaRun_TextPr:
{
// CTextPr
......
This diff is collapsed.
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