mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-22 11:12:36 +01:00
More Word hacking
git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@248 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
parent
0bb4add479
commit
053e360118
@ -82,6 +82,8 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
WaveFormUnDocked _waveFormUnDocked = null;
|
||||
VideoControlsUndocked _videoControlsUnDocked = null;
|
||||
|
||||
bool _cancelWordSpellCheck = false;
|
||||
|
||||
private bool AutoRepeatContinueOn
|
||||
{
|
||||
get
|
||||
@ -2767,7 +2769,7 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
}
|
||||
|
||||
private void SpellCheckViaWord()
|
||||
{
|
||||
{
|
||||
if (_subtitle == null | _subtitle.Paragraphs.Count == 0)
|
||||
return;
|
||||
|
||||
@ -2776,24 +2778,27 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
try
|
||||
{
|
||||
wordSpellChecker = new WordSpellChecker();
|
||||
wordSpellChecker.NewDocument();
|
||||
}
|
||||
catch
|
||||
{
|
||||
MessageBox.Show(_language.UnableToStartWord);
|
||||
//Configuration.Settings.General.SpellChecker = "hunspell"; ???
|
||||
return;
|
||||
}
|
||||
string version = wordSpellChecker.Version;
|
||||
int index = 1;
|
||||
string version = wordSpellChecker.Version;
|
||||
|
||||
int index = FirstSelectedIndex;
|
||||
if (index < 0)
|
||||
index = 0;
|
||||
|
||||
_cancelWordSpellCheck = false;
|
||||
foreach (Paragraph p in _subtitle.Paragraphs)
|
||||
{
|
||||
int errorsBefore;
|
||||
int errorsAfter;
|
||||
wordSpellChecker.NewDocument();
|
||||
ShowStatus(string.Format(_language.SpellChekingViaWordXLineYOfX, version, index, _subtitle.Paragraphs.Count.ToString()));
|
||||
SubtitleListview1.SelectIndexAndEnsureVisible(index - 1);
|
||||
string newText = wordSpellChecker.CheckSpelling(p.Text, out errorsBefore, out errorsAfter);
|
||||
wordSpellChecker.CloseDocument();
|
||||
if (errorsAfter > 0)
|
||||
{
|
||||
wordSpellChecker.Quit();
|
||||
@ -2806,9 +2811,14 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
}
|
||||
totalCorrections += (errorsBefore - errorsAfter);
|
||||
index++;
|
||||
|
||||
if (_cancelWordSpellCheck)
|
||||
break;
|
||||
}
|
||||
wordSpellChecker.CloseDocument();
|
||||
wordSpellChecker.Quit();
|
||||
ShowStatus(string.Format(_language.SpellCheckCompletedXCorrections, totalCorrections));
|
||||
Cursor = Cursors.Default;
|
||||
}
|
||||
|
||||
private void SpellCheck(bool autoDetect)
|
||||
@ -5126,6 +5136,11 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
InsertAfter();
|
||||
e.SuppressKeyPress = true;
|
||||
}
|
||||
else if (e.KeyCode == Keys.Escape)
|
||||
{
|
||||
_cancelWordSpellCheck = true;
|
||||
}
|
||||
|
||||
//else if (e.Modifiers == Keys.Control && e.KeyCode == Keys.D)
|
||||
//{
|
||||
// InsertAfter();
|
||||
|
@ -181,7 +181,7 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
labelSubtitleFontSize.Text = language.SubtitleFontSize;
|
||||
labelSubtitleFontColor.Text = language.SubtitleFontColor;
|
||||
labelSubtitleFontBackgroundColor.Text = language.SubtitleBackgroundColor;
|
||||
labelSpellChecker.Text = language.SubtitleBackgroundColor;
|
||||
labelSpellChecker.Text = language.SpellChecker;
|
||||
checkBoxSubtitleFontBold.Text = Configuration.Settings.Language.General.Bold;
|
||||
checkBoxRememberRecentFiles.Text = language.RememberRecentFiles;
|
||||
checkBoxReopenLastOpened.Text = language.StartWithLastFileLoaded;
|
||||
|
@ -18,8 +18,8 @@ namespace Nikse.SubtitleEdit.Logic
|
||||
{
|
||||
_wordApplicationType = System.Type.GetTypeFromProgID("Word.Application");
|
||||
_wordApplication = Activator.CreateInstance(_wordApplicationType);
|
||||
_wordApplicationType.InvokeMember("Top", BindingFlags.SetProperty, null, _wordApplication, new object[] { -1000 }); // hide window - it's a hack
|
||||
_wordApplicationType.InvokeMember("Visible", BindingFlags.SetProperty, null, _wordApplication, new object[] { true }); // set visible to true - otherwise it will appear in the background
|
||||
_wordApplicationType.InvokeMember("WindowState", BindingFlags.SetProperty, null, _wordApplication, new object[] { 0 }); // 0 == ?
|
||||
_wordApplicationType.InvokeMember("Top", BindingFlags.SetProperty, null, _wordApplication, new object[] { -10000 }); // hide window - it's a hack
|
||||
}
|
||||
|
||||
public void NewDocument()
|
||||
@ -32,7 +32,7 @@ namespace Nikse.SubtitleEdit.Logic
|
||||
{
|
||||
object saveChanges = false;
|
||||
object p = Missing.Value;
|
||||
_wordDocumentType.InvokeMember("Close", System.Reflection.BindingFlags.InvokeMethod, null, _wordDocument, new object[] { saveChanges, p, p });
|
||||
_wordDocumentType.InvokeMember("Close", BindingFlags.InvokeMethod, null, _wordDocument, new object[] { saveChanges, p, p });
|
||||
}
|
||||
|
||||
public string Version
|
||||
@ -49,7 +49,7 @@ namespace Nikse.SubtitleEdit.Logic
|
||||
object saveChanges = false;
|
||||
object originalFormat = Missing.Value;
|
||||
object routeDocument = Missing.Value;
|
||||
_wordApplicationType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, _wordApplication, new object[] { saveChanges, originalFormat, routeDocument });
|
||||
_wordApplicationType.InvokeMember("Quit", BindingFlags.InvokeMethod, null, _wordApplication, new object[] { saveChanges, originalFormat, routeDocument });
|
||||
try
|
||||
{
|
||||
System.Runtime.InteropServices.Marshal.ReleaseComObject(_wordDocument);
|
||||
@ -74,12 +74,13 @@ namespace Nikse.SubtitleEdit.Logic
|
||||
object spellingErrorsCount = spellingErrors.GetType().InvokeMember("Count", BindingFlags.GetProperty, null, spellingErrors, null);
|
||||
errorsBefore = int.Parse(spellingErrorsCount.ToString());
|
||||
System.Runtime.InteropServices.Marshal.ReleaseComObject(spellingErrors);
|
||||
|
||||
|
||||
// perform spell check
|
||||
object p = Missing.Value;
|
||||
_wordApplicationType.InvokeMember("Top", BindingFlags.SetProperty, null, _wordApplication, new object[] { -10000 }); // hide window - it's a hack
|
||||
_wordApplicationType.InvokeMember("Visible", BindingFlags.SetProperty, null, _wordApplication, new object[] { true }); // set visible to true - otherwise it will appear in the background
|
||||
_wordDocumentType.InvokeMember("CheckSpelling", BindingFlags.InvokeMethod, null, _wordDocument, new Object[] { p, p, p, p, p, p, p, p, p, p, p, p }); // 12 parameters
|
||||
// _wordApplicationType.InvokeMember("Top", BindingFlags.SetProperty, null, _wordApplication, new object[] { -1000 }); // hide window - it's a hack
|
||||
|
||||
|
||||
// spell check error count
|
||||
spellingErrors = _wordDocumentType.InvokeMember("SpellingErrors", BindingFlags.GetProperty, null, _wordDocument, null);
|
||||
@ -88,13 +89,12 @@ namespace Nikse.SubtitleEdit.Logic
|
||||
System.Runtime.InteropServices.Marshal.ReleaseComObject(spellingErrors);
|
||||
|
||||
// Get spellcheck text
|
||||
object first = 0;
|
||||
object characters = _wordDocumentType.InvokeMember("Characters", BindingFlags.GetProperty, null, _wordDocument, null);
|
||||
object charactersCount = characters.GetType().InvokeMember("Count", BindingFlags.GetProperty, null, characters, null);
|
||||
object last = int.Parse(charactersCount.ToString()) - 1;
|
||||
System.Runtime.InteropServices.Marshal.ReleaseComObject(characters);
|
||||
|
||||
object resultText = range.GetType().InvokeMember("Text", BindingFlags.GetProperty, null, range, null);
|
||||
range.GetType().InvokeMember("Delete", BindingFlags.InvokeMethod, null, range, null);
|
||||
|
||||
System.Runtime.InteropServices.Marshal.ReleaseComObject(words);
|
||||
System.Runtime.InteropServices.Marshal.ReleaseComObject(range);
|
||||
|
||||
return resultText.ToString().TrimEnd(); // result needs a trimming at the end
|
||||
}
|
||||
|
@ -561,7 +561,7 @@
|
||||
<Compile Include="Logic\VobSub\VobSubParser.cs" />
|
||||
<Compile Include="Logic\VobSub\VobSubMergedPack.cs" />
|
||||
<Compile Include="Logic\VobSub\VobSubPack.cs" />
|
||||
<Compile Include="Logic\WordLateBound.cs" />
|
||||
<Compile Include="Logic\WordSpellChecker.cs" />
|
||||
<Compile Include="Logic\zlib\Adler32.cs" />
|
||||
<Compile Include="Logic\zlib\Deflate.cs" />
|
||||
<Compile Include="Logic\zlib\InfBlocks.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user