Commit 6a12c0d6 authored by Ilya.Kirillov's avatar Ilya.Kirillov Committed by Alexander.Trofimov

Реализованы функции Ignore и IgnoreAll для проверки орфографии (доработан тестовый пример).

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@47346 954022d7-b5bf-4e40-9824-e11837661b57
parent b32b41e7
......@@ -221,6 +221,44 @@ CStatistics.prototype =
}
};
function CDocumentSpelling()
{
this.Paragraphs = new Object(); // Параграфы, в которых есть ошибки в орфографии (объект с ключом - Id параграфа)
this.Words = new Object(); // Слова, которые пользователь решил пропустить(нажал "пропустить все") при проверке орфографии
}
CDocumentSpelling.prototype =
{
Add_Paragraph : function(Id, Para)
{
this.Paragraphs[Id] = Para;
},
Remove_Paragraph : function(Id)
{
delete this.Paragraphs[Id];
},
Check_Word : function(Word)
{
if ( undefined != this.Words[Word] )
return true;
return false;
},
Add_Word : function(Word)
{
this.Words[Word] = true;
for ( var Id in this.Paragraphs )
{
var Para = this.Paragraphs[Id];
Para.SpellChecker.Ignore( Word );
}
}
};
function CDocument(DrawingDocument)
{
this.History = new CHistory(this);
......@@ -348,6 +386,9 @@ function CDocument(DrawingDocument)
// Класс для работы с поиском и заменой в документе
this.SearchEngine = new CDocumentSearch();
// Параграфы, в которых есть ошибки в орфографии (объект с ключом - Id параграфа)
this.Spelling = new CDocumentSpelling();
// Добавляем данный класс в таблицу Id (обязательно в конце конструктора)
g_oTableId.Add( this, this.Id );
}
......
......@@ -3800,6 +3800,7 @@ Paragraph.prototype =
var CurLine = this.Pages[CurPage].FirstLine;
var CurRange = 0;
var X = this.Lines[CurLine].Ranges[CurRange].XVisible;
var Y = this.Pages[CurPage].Y + this.Lines[CurLine].Y;
var SpecW = 2.5; // 2.5 mm
var SpecX = Math.min( X, this.X ) - SpecW;
......@@ -12020,7 +12021,45 @@ Paragraph.prototype =
Count--;
}
}
},
Replace_MisspelledWord : function(Word, WordId)
{
var Element = this.SpellChecker.Elements[WordId];
var StartPos = Element.StartPos;
var EndPos = Element.EndPos;
for ( var Pos = EndPos; Pos >= StartPos; Pos-- )
{
var ItemType = this.Content[Pos].Type;
if ( para_TextPr != ItemType )
this.Internal_Content_Remove(Pos);
}
var Len = Word.length;
for ( var Pos = 0; Pos < Len; Pos++ )
{
this.Internal_Content_Add( StartPos + Pos, new ParaText( Word[Pos] ) );
}
this.RecalcInfo.Set_Type_0( pararecalc_0_All );
this.Selection.Use = false;
this.Selection.Start = false;
this.Selection.StartPos = EndPos;
this.Selection.EndPos = EndPos;
this.CurPos.ContentPos = EndPos;
this.Document_SetThisElementCurrent();
},
Ignore_MisspelledWord : function(WordId)
{
var Element = this.SpellChecker.Elements[WordId];
Element.Checked = true;
this.ReDraw();
}
};
var pararecalc_0_All = 0;
......@@ -12283,14 +12322,42 @@ CParaSpellChecker.prototype =
{
if ( RecalcId == this.RecalcId && this.Elements.length === UsrCorrect.length )
{
var DocumentSpelling = editor.WordControl.m_oLogicDocument.Spelling;
var Count = this.Elements.length;
for ( var Index = 0; Index < Count; Index++ )
{
this.Elements[Index].Checked = UsrCorrect[Index];
var Element = this.Elements[Index];
// Если слово есть в локальном словаре, не проверяем его
if ( true === DocumentSpelling.Check_Word( Element.Word ) )
Element.Checked = true;
else
Element.Checked = UsrCorrect[Index];
}
this.Internal_UpdateParagraphState();
}
},
Internal_UpdateParagraphState : function()
{
var DocumentSpelling = editor.WordControl.m_oLogicDocument.Spelling;
var bMisspeled = false;
var Count = this.Elements.length;
for ( var Index = 0; Index < Count; Index++ )
{
// Если есть хоть одно неправильное слово, запоминаем этот параграф
if ( false === this.Elements[Index].Checked )
bMisspeled = true;
}
if ( true === bMisspeled )
DocumentSpelling.Add_Paragraph( this.ParaId, g_oTableId.Get_ById( this.ParaId ) );
else
DocumentSpelling.Remove_Paragraph( this.ParaId );
},
Check_Spelling : function(Pos)
{
var Count = this.Elements.length;
......@@ -12350,7 +12417,7 @@ CParaSpellChecker.prototype =
}
}
editor.sync_SpellCheckCallback( Word, Checked, Variants );
editor.sync_SpellCheckCallback( Word, Checked, Variants, this.ParaId, FoundIndex );
},
Check_CallBack2: function(RecalcId, ElementId, usrVariants)
......@@ -12359,6 +12426,19 @@ CParaSpellChecker.prototype =
{
this.Elements[ElementId].Variants = usrVariants[0];
}
},
Ignore : function(Word)
{
var Count = this.Elements.length;
for ( var Index = 0; Index < Count; Index++ )
{
var Element = this.Elements[Index];
if ( false === Element.Checked && Word === Element.Word )
Element.Checked = true;
}
this.Internal_UpdateParagraphState();
}
};
......
......@@ -2154,6 +2154,11 @@
<select id="prSpellingVariants" style="float:left">
</select>
<div id="prIgnoreMisspelling_div" style="float:left;width:300px">
<input id="prIgnoreMisspelling" type="button" value="Ignore"/>
<input id="prIgnoreAllMisspelling" type="button" value="Ignore All"/>
</div>
</div>
</div>
<div id="prUsersDrag" style="display:none;width:200px;background-color:#fff;top:215px;right:50px;z-index:100;position:absolute;border: 4px ridge silver;cursor:move;">
......
......@@ -4834,26 +4834,65 @@ asc_docs_api.prototype.sync_DialogAddHyperlink = function()
//-----------------------------------------------------------------
// Функции для работы с орфографией
//-----------------------------------------------------------------
function asc_CSpellCheckProperty( Word, Checked, Variants )
function asc_CSpellCheckProperty( Word, Checked, Variants, ParaId, ElemId )
{
this.Word = Word;
this.Checked = Checked;
this.Variants = Variants;
this.ParaId = ParaId;
this.ElemId = ElemId;
}
asc_CSpellCheckProperty.prototype.get_Word = function() { return this.Word; }
asc_CSpellCheckProperty.prototype.get_Checked = function() { return this.Checked; }
asc_CSpellCheckProperty.prototype.get_Variants = function() { return this.Variants; }
asc_docs_api.prototype.sync_SpellCheckCallback = function(Word, Checked, Variants)
asc_docs_api.prototype.sync_SpellCheckCallback = function(Word, Checked, Variants, ParaId, ElemId)
{
this.SelectedObjectsStack[this.SelectedObjectsStack.length] = new CSelectedObject( c_oAscTypeSelectElement.SpellCheck, new asc_CSpellCheckProperty( Word, Checked, Variants ) );
this.SelectedObjectsStack[this.SelectedObjectsStack.length] = new CSelectedObject( c_oAscTypeSelectElement.SpellCheck, new asc_CSpellCheckProperty( Word, Checked, Variants, ParaId, ElemId ) );
}
asc_docs_api.prototype.sync_SpellCheckVariantsFound = function()
{
this.asc_fireCallback("asc_onSpellCheckVariantsFound");
}
asc_docs_api.prototype.asc_replaceMisspelledWord = function(Word, SpellCheckProperty)
{
var ParaId = SpellCheckProperty.ParaId;
var ElemId = SpellCheckProperty.ElemId;
var Paragraph = g_oTableId.Get_ById(ParaId);
if ( null != Paragraph && false === this.WordControl.m_oLogicDocument.Document_Is_SelectionLocked(changestype_None, { Type : changestype_2_Element_and_Type, Element : Paragraph, CheckType : changestype_Paragraph_Content } ) )
{
this.WordControl.m_oLogicDocument.Create_NewHistoryPoint();
Paragraph.Replace_MisspelledWord( Word, ElemId );
this.WordControl.m_oLogicDocument.Recalculate();
}
}
asc_docs_api.prototype.asc_ignoreMisspelledWord = function(SpellCheckProperty, bAll)
{
if ( false === bAll )
{
var ParaId = SpellCheckProperty.ParaId;
var ElemId = SpellCheckProperty.ElemId;
var Paragraph = g_oTableId.Get_ById(ParaId);
if ( null != Paragraph )
{
Paragraph.Ignore_MisspelledWord( ElemId );
}
}
else
{
var LogicDocument = editor.WordControl.m_oLogicDocument;
LogicDocument.Spelling.Add_Word( SpellCheckProperty.Word );
LogicDocument.DrawingDocument.ClearCachePages();
LogicDocument.DrawingDocument.FirePaint();
}
}
//-----------------------------------------------------------------
// Функции для работы с комментариями
//-----------------------------------------------------------------
......
......@@ -19,6 +19,7 @@ var g_oImagePr = new Object();//
var g_nImageWrap = 0;//c_oAscWrapStyle2.Inline;
var g_bImageCanBeFlow = true;
var g_oTablePr = new Object();
var g_oSpellCheck = new Object();
//var oChartEditor = new ChartEditor();
var Drag = {
......@@ -2016,6 +2017,22 @@ $(".colorWatch").mouseover(function(){
editor.put_TextPrLang( lcid );
})
$("#prSpellingVariants").change(function(evt)
{
var word = this.options[this.selectedIndex].text;
editor.asc_replaceMisspelledWord( word, g_oSpellCheck );
})
$("#prIgnoreMisspelling").click(function()
{
editor.asc_ignoreMisspelledWord(g_oSpellCheck, false);
})
$("#prIgnoreAllMisspelling").click(function()
{
editor.asc_ignoreMisspelledWord(g_oSpellCheck, true);
})
$("#tblLookFirstRow, #tblLookLastRow, #tblLookFirstCol, #tblLookLastCol, #tblLookHorBand, #tblLookVerBand,").change(function(evt)
{
var TableLook =
......@@ -2762,6 +2779,7 @@ $(".colorWatch").mouseover(function(){
else if ( ObjectType == c_oAscTypeSelectElement.SpellCheck )
{
var elemVal = elemArg.get_ObjectValue();
g_oSpellCheck = elemVal;
var Word = elemVal.get_Word();
var Checked = elemVal.get_Checked();
......@@ -2772,10 +2790,11 @@ $(".colorWatch").mouseover(function(){
if ( true === Checked )
{
document.getElementById("prIgnoreMisspelling_div").style.display = "none";
}
else
{
document.getElementById("prIgnoreMisspelling_div").style.display = "block";
var SpellingVariants = document.getElementById("prSpellingVariants");
SpellingVariants.options.length = 0;
......
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