Commit d961dcbc authored by Ilya Kirillov's avatar Ilya Kirillov

A new scheme with merging the changes of properties. A new scheme is the...

A new scheme with merging the changes of properties. A new scheme  is the result of development of an undo in collaborative editing of a document. The changes of properties for classes Paragraph, Document, TableId now can be merged.
parent b0995d63
......@@ -78,9 +78,10 @@ CCollaborativeChanges.prototype.Apply_Data = function()
{
var oChange = new fChangesClass(Class);
oChange.ReadFromBinary(Reader);
if (true === CollaborativeEditing.private_AddOverallChange(oChange))
oChange.Load(this.m_oColor);
CollaborativeEditing.private_AddOverallChange(oChange);
return true;
}
else
......@@ -420,6 +421,9 @@ CCollaborativeEditingBase.prototype.Apply_OtherChanges = function()
// Чтобы заново созданные параграфы не отображались залоченными
AscCommon.g_oIdCounter.Set_Load( true );
if (this.m_aChanges.length > 0)
this.private_CollectOwnChanges();
// Применяем изменения, пока они есть
var _count = this.m_aChanges.length;
for (var i = 0; i < _count; i++)
......@@ -734,6 +738,9 @@ CCollaborativeEditingBase.prototype.InitMemory = function() {
{
this.m_aChanges = [];
};
CCollaborativeEditingBase.prorotype.private_CollectOwnChanges = function()
{
};
CCollaborativeEditingBase.prototype.private_AddOverallChange = function(oChange)
{
};
......
......@@ -2878,6 +2878,10 @@
{
return null;
};
CChangesBase.prototype.Merge = function(oChange)
{
return true;
};
window['AscDFH'].CChangesBase = CChangesBase;
/**
* Базовый класс для изменений, которые меняют содержимое родительского класса.*
......@@ -3041,6 +3045,7 @@
{
var oChange = new fConstructor();
oChange.Class = this.Class;
oChange.Pos = this.Pos;
oChange.Items = this.Items;
oChange.Add = !this.Add;
......@@ -3052,6 +3057,11 @@
return oChange;
};
CChangesBaseContentChange.prototype.Merge = function(oChange)
{
// TODO: Сюда надо бы перенести работу с ContentChanges
return true;
};
window['AscDFH'].CChangesBaseContentChange = CChangesBaseContentChange;
/**
* Базовый класс для изменения свойств.
......@@ -3083,6 +3093,17 @@
{
return new this.constructor(this.Class, this.New, this.Old, this.Color);
};
CChangesBaseProperty.prototype.Merge = function(oChange)
{
if (oChange.Class === this.Class && oChange.Type === this.Type)
{
this.New = oChange.New;
return false;
}
return true;
};
window['AscDFH'].CChangesBaseProperty = CChangesBaseProperty;
/**
* Базовый класс для изменения булевых свойств.
......
......@@ -50,6 +50,8 @@ function CWordCollaborativeEditing()
this.m_aAllChanges = []; // Список всех изменений
this.m_aOwnChangesIndexes = []; // Список номеров своих изменений в общем списке, которые мы можем откатить
this.m_oOwnChanges = [];
}
AscCommon.extendClass(CWordCollaborativeEditing, AscCommon.CCollaborativeEditingBase);
......@@ -598,9 +600,38 @@ CWordCollaborativeEditing.prototype.private_ClearChanges = function()
{
this.m_aChanges = [];
};
CWordCollaborativeEditing.prototype.private_CollectOwnChanges = function()
{
var StartPoint = ( null === AscCommon.History.SavedIndex ? 0 : AscCommon.History.SavedIndex + 1 );
var LastPoint = -1;
if (this.m_nUseType <= 0)
LastPoint = AscCommon.History.Points.length - 1;
else
LastPoint = AscCommon.History.Index;
for (var PointIndex = StartPoint; PointIndex <= LastPoint; PointIndex++)
{
var Point = AscCommon.History.Points[PointIndex];
for (var Index = 0; Index < Point.Items.length; Index++)
{
var Item = Point.Items[Index];
if (Item.Data.IsChangesClass && Item.Data.IsChangesClass())
this.m_oOwnChanges.push(Item.Data);
}
}
};
CWordCollaborativeEditing.prototype.private_AddOverallChange = function(oChange)
{
// Здесь мы должны смержить пришедшее изменение с одним из наших изменений
for (var nIndex = 0, nCount = this.m_oOwnChanges.length; nIndex < nCount; ++nIndex)
{
if (false === oChange.Merge(this.m_oOwnChanges[nIndex]))
return false;
}
this.m_aAllChanges.push(oChange);
return true;
};
CWordCollaborativeEditing.prototype.private_OnSendOwnChanges = function(arrChanges, nDeleteIndex)
{
......@@ -621,6 +652,9 @@ CWordCollaborativeEditing.prototype.private_OnSendOwnChanges = function(arrChang
};
CWordCollaborativeEditing.prototype.Undo = function()
{
if (true === this.Get_GlobalLock())
return;
if (this.m_aOwnChangesIndexes.length <= 0)
return false;
......@@ -667,6 +701,35 @@ CWordCollaborativeEditing.prototype.Undo = function()
// Удаляем запись о последнем изменении
this.m_aOwnChangesIndexes.length = this.m_aOwnChangesIndexes.length - 1;
var arrReverseChanges = [];
for (var nIndex = 0, nCount = arrChanges.length; nIndex < nCount; ++nIndex)
{
var oReverseChange = arrChanges[nIndex].CreateReverseChange();
if (oReverseChange)
arrReverseChanges.splice(0, 0, oReverseChange);
}
var oLogicDocument = this.m_oLogicDocument;
oLogicDocument.DrawingDocument.EndTrackTable(null, true);
oLogicDocument.DrawingObjects.TurnOffCheckChartSelection();
for (var nIndex = arrReverseChanges.length - 1; nIndex >= 0; --nIndex)
{
arrReverseChanges[nIndex].Load();
}
oLogicDocument.DrawingObjects.TurnOnCheckChartSelection();
oLogicDocument.Recalculate(false, false, AscCommon.History.Get_RecalcData(null, arrReverseChanges));
oLogicDocument.Document_UpdateSelectionState();
oLogicDocument.Document_UpdateInterfaceState();
oLogicDocument.Document_UpdateRulersState();
};
CWordCollaborativeEditing.prototype.CanUndo = function()
{
......
......@@ -857,12 +857,21 @@ CHistory.prototype =
return false;
},
Get_RecalcData : function(RecalcData)
Get_RecalcData : function(RecalcData, arrChanges)
{
if (RecalcData)
{
this.RecalculateData = RecalcData;
}
else if (arrChanges)
{
this.Internal_RecalcData_Clear();
for (var nIndex = 0, nCount = arrChanges.length; nIndex < nCount; ++nIndex)
{
var oChange = arrChanges[nIndex];
oChange.RefreshRecalcData();
}
}
else
{
if (this.Index >= 0)
......
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