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

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

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