Commit 8630fe5f authored by Ilya Kirillov's avatar Ilya Kirillov

Fixed bug #34371. Reworked function for replacing a style.

parent 1c20b87f
...@@ -162,81 +162,82 @@ CDocument.prototype.Is_DefaultStyleChanged = function(sName) ...@@ -162,81 +162,82 @@ CDocument.prototype.Is_DefaultStyleChanged = function(sName)
//---------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------
CStyles.prototype.Create_StyleFromInterface = function(oAscStyle, bCheckLink) CStyles.prototype.Create_StyleFromInterface = function(oAscStyle, bCheckLink)
{ {
var oStyle = new CStyle(); var sStyleName = oAscStyle.get_Name();
var sStyleId = this.Get_StyleIdByName(sStyleName, false);
if (null !== sStyleId)
{
var oStyle = this.Style[sStyleId];
var BasedOnId = this.Get_StyleIdByName(oAscStyle.get_BasedOn(), false); var NewStyleParaPr = oAscStyle.get_ParaPr();
oStyle.Set_BasedOn(BasedOnId); var NewStyleTextPr = oAscStyle.get_TextPr();
oStyle.Set_Next(this.Get_StyleIdByName(oAscStyle.get_Next(), false));
oStyle.Set_Type(oAscStyle.get_Type());
var NewStyleParaPr = oAscStyle.get_ParaPr(); var BasedOnId = this.Get_StyleIdByName(oAscStyle.get_BasedOn(), false);
var NewStyleTextPr = oAscStyle.get_TextPr(); var NextId = this.Get_StyleIdByName(oAscStyle.get_Next(), false);
// Если у нас есть стиль с данным именем, тогда мы старый стиль удаляем, а новый добавляем со старым Id, oStyle.Set_Type(oAscStyle.get_Type());
// чтобы если были ссылки на старый стиль - теперь они стали на новый.
var sStyleName = oAscStyle.get_Name();
var OldId = this.Get_StyleIdByName(sStyleName, false);
if (null != OldId)
{
var oOldStyle = this.Style[OldId];
oStyle.Set_QFormat(oOldStyle.Get_QFormat());
oStyle.Set_UiPriority(oOldStyle.Get_UiPriority());
oStyle.Set_Hidden(oOldStyle.Get_Hidden());
oStyle.Set_SemiHidden(oOldStyle.Get_SemiHidden());
oStyle.Set_UnhideWhenUsed(oOldStyle.Get_UnhideWhenUsed());
// Если удаляемый стиль - стиль, который стоит в BasedOn, либо это вообще дефолтовый стиль, тогда мы должны
// его смержить с заданным.
if (BasedOnId === OldId || OldId === this.Default.Paragraph)
{
oStyle.Set_BasedOn(null);
var OldStyleParaPr = oOldStyle.ParaPr.Copy();
var OldStyleTextPr = oOldStyle.TextPr.Copy();
OldStyleParaPr.Merge(NewStyleParaPr);
OldStyleTextPr.Merge(NewStyleTextPr);
NewStyleParaPr = OldStyleParaPr;
NewStyleTextPr = OldStyleTextPr;
}
if (oStyle.Get_Next() === OldId) if (BasedOnId === sStyleId || sStyleId === this.Default.Paragraph)
oStyle.Set_Next(null); {
oStyle.Set_BasedOn(null);
if (null != oOldStyle.Get_Next() && null == oStyle.Get_Next()) var OldStyleParaPr = oStyle.ParaPr.Copy();
oStyle.Set_Next(oOldStyle.Get_Next()); var OldStyleTextPr = oStyle.TextPr.Copy();
OldStyleParaPr.Merge(NewStyleParaPr);
OldStyleTextPr.Merge(NewStyleTextPr);
NewStyleParaPr = OldStyleParaPr;
NewStyleTextPr = OldStyleTextPr;
}
else
{
oStyle.Set_BasedOn(BasedOnId);
}
this.Remove(OldId); if (null === oStyle.Get_Next() || (null !== NextId && NextId !== sStyleId))
this.RemapIdReferences(OldId, oStyle.GetId()); {
if (NextId === sStyleId)
oStyle.Set_Next(null);
else
oStyle.Set_Next(NextId);
}
var oLogicDocument = editor.WordControl.m_oLogicDocument; var oAscLink = oAscStyle.get_Link();
if (oLogicDocument) if (false != bCheckLink && null != oAscLink && undefined !== oAscLink)
{ {
var arrParagraphs = oLogicDocument.Get_AllParagraphsByStyle([OldId]); var oLinkedStyle = this.Create_StyleFromInterface(oAscLink, false);
for (var nIndex = 0, nCount = arrParagraphs.length; nIndex < nCount; ++nIndex) oStyle.Set_Link(oLinkedStyle.Get_Id());
{ oLinkedStyle.Set_Link(oStyle.Get_Id());
arrParagraphs[nIndex].Style_Add(oStyle.GetId(), true);
}
} }
}
oStyle.Set_Name(sStyleName); oStyle.Set_TextPr(NewStyleTextPr);
oStyle.Set_ParaPr(NewStyleParaPr);
if (styletype_Paragraph === oStyle.Get_Type()) return oStyle;
oStyle.Set_QFormat(true); }
else
{
var oStyle = new CStyle();
var oAscLink = oAscStyle.get_Link(); var BasedOnId = this.Get_StyleIdByName(oAscStyle.get_BasedOn(), false);
if (false != bCheckLink && null != oAscLink && undefined !== oAscLink) oStyle.Set_BasedOn(BasedOnId);
{ oStyle.Set_Next(this.Get_StyleIdByName(oAscStyle.get_Next(), false));
var oLinkedStyle = this.Create_StyleFromInterface(oAscLink, false); oStyle.Set_Type(oAscStyle.get_Type());
oStyle.Set_Link(oLinkedStyle.Get_Id()); oStyle.Set_TextPr(oAscStyle.get_TextPr());
oLinkedStyle.Set_Link(oStyle.Get_Id()); oStyle.Set_ParaPr(oAscStyle.get_ParaPr());
} oStyle.Set_Name(sStyleName);
if (styletype_Paragraph === oStyle.Get_Type())
oStyle.Set_QFormat(true);
oStyle.Set_TextPr(NewStyleTextPr); var oAscLink = oAscStyle.get_Link();
oStyle.Set_ParaPr(NewStyleParaPr); if (false != bCheckLink && null != oAscLink && undefined !== oAscLink)
{
var oLinkedStyle = this.Create_StyleFromInterface(oAscLink, false);
oStyle.Set_Link(oLinkedStyle.Get_Id());
oLinkedStyle.Set_Link(oStyle.Get_Id());
}
this.Add(oStyle); this.Add(oStyle);
return oStyle; return oStyle;
}
}; };
CStyles.prototype.Remove_StyleFromInterface = function(StyleId) CStyles.prototype.Remove_StyleFromInterface = function(StyleId)
{ {
......
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