Fixed some shortcuts + word spell check now tries to use correct language

git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@712 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
niksedk 2011-10-11 14:58:04 +00:00
parent 4d8b864770
commit 45ae2fb56a
2 changed files with 34 additions and 11 deletions

View File

@ -3644,7 +3644,7 @@ namespace Nikse.SubtitleEdit.Forms
int totalLinesChanged = 0;
try
{
wordSpellChecker = new WordSpellChecker(this);
wordSpellChecker = new WordSpellChecker(this, Utilities.AutoDetectGoogleLanguage(_subtitle));
wordSpellChecker.NewDocument();
Application.DoEvents();
}
@ -6432,13 +6432,18 @@ namespace Nikse.SubtitleEdit.Forms
return;
}
if (e.Modifiers == Keys.Alt && e.KeyCode == Keys.Insert)
if (e.Modifiers == Keys.Shift && e.KeyCode == Keys.ShiftKey)
return;
bool inListView = tabControlSubtitle.SelectedIndex == TabControlListView;
if (e.Modifiers == Keys.Alt && e.KeyCode == Keys.Insert && inListView)
{
InsertAfter();
e.SuppressKeyPress = true;
textBoxListViewText.Focus();
}
else if (e.Shift && e.KeyCode == Keys.Insert)
else if (e.Modifiers == (Keys.Shift | Keys.Control) && e.KeyCode == Keys.Insert && inListView)
{
InsertBefore();
e.SuppressKeyPress = true;
@ -6891,7 +6896,7 @@ namespace Nikse.SubtitleEdit.Forms
private void SubtitleListview1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.C && e.Control) //Ctrl+c = Copy to clipboard
if (e.KeyCode == Keys.C && e.Modifiers == Keys.Control) //Ctrl+c = Copy to clipboard
{
Subtitle tmp = new Subtitle();
foreach (int i in SubtitleListview1.SelectedIndices)
@ -6906,7 +6911,7 @@ namespace Nikse.SubtitleEdit.Forms
}
e.SuppressKeyPress = true;
}
else if (e.KeyCode == Keys.V && e.Control) //Ctrl+vPaste from clipboard
else if (e.KeyCode == Keys.V && e.Modifiers == Keys.Control) //Ctrl+vPaste from clipboard
{
if (Clipboard.ContainsText())
{
@ -6938,7 +6943,7 @@ namespace Nikse.SubtitleEdit.Forms
}
e.SuppressKeyPress = true;
}
else if (e.KeyCode == Keys.X && e.Control) //Ctrl+X = Cut to clipboard
else if (e.KeyCode == Keys.X && e.Modifiers == Keys.Control) //Ctrl+X = Cut to clipboard
{
Subtitle tmp = new Subtitle();
foreach (int i in SubtitleListview1.SelectedIndices)
@ -6951,13 +6956,13 @@ namespace Nikse.SubtitleEdit.Forms
_cutText = tmp.ToText(new SubRip());
ToolStripMenuItemDeleteClick(null, null);
}
else if (e.KeyCode == Keys.A && e.Control) //SelectAll
else if (e.KeyCode == Keys.A && e.Modifiers == Keys.Control) //SelectAll
{
foreach (ListViewItem item in SubtitleListview1.Items)
item.Selected = true;
e.SuppressKeyPress = true;
}
else if (e.KeyCode == Keys.D && e.Control) //SelectFirstSelectedItemOnly
else if (e.KeyCode == Keys.D && e.Modifiers == Keys.Control) //SelectFirstSelectedItemOnly
{
if (SubtitleListview1.SelectedItems.Count > 0)
{
@ -6976,7 +6981,7 @@ namespace Nikse.SubtitleEdit.Forms
{
ToolStripMenuItemDeleteClick(null, null);
}
else if (e.Shift && e.KeyCode == Keys.Insert)
else if (e.Modifiers == Keys.Shift && e.KeyCode == Keys.Insert)
{
InsertBefore();
e.SuppressKeyPress = true;
@ -6986,7 +6991,7 @@ namespace Nikse.SubtitleEdit.Forms
InsertAfter();
e.SuppressKeyPress = true;
}
else if (e.Shift && e.Control && e.KeyCode == Keys.I) //InverseSelection
else if (e.Modifiers == (Keys.Shift | Keys.Control) && e.KeyCode == Keys.I) //InverseSelection
{
foreach (ListViewItem item in SubtitleListview1.Items)
item.Selected = !item.Selected;

View File

@ -32,10 +32,12 @@ namespace Nikse.SubtitleEdit.Logic
private Type _wordApplicationType;
private Type _wordDocumentType;
IntPtr _mainHandle;
int _languageId = 1033; // english
public WordSpellChecker(Main main)
public WordSpellChecker(Main main, string languageId)
{
_mainHandle = main.Handle;
SetLanguageId(languageId);
_wordApplicationType = System.Type.GetTypeFromProgID("Word.Application");
_wordApplication = Activator.CreateInstance(_wordApplicationType);
@ -46,6 +48,19 @@ namespace Nikse.SubtitleEdit.Logic
Application.DoEvents();
}
private void SetLanguageId(string languageId)
{
try
{
System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo(languageId);
_languageId = ci.LCID;
}
catch
{
_languageId = System.Globalization.CultureInfo.CurrentUICulture.LCID;
}
}
public void NewDocument()
{
_wordDocumentType = System.Type.GetTypeFromProgID("Word.Document");
@ -93,6 +108,9 @@ namespace Nikse.SubtitleEdit.Logic
object range = words.GetType().InvokeMember("First", BindingFlags.GetProperty, null, words, null);
range.GetType().InvokeMember("InsertBefore", BindingFlags.InvokeMethod, null, range, new Object[] { text });
// set language...
range.GetType().InvokeMember("LanguageId", BindingFlags.SetProperty, null, range, new object[] { _languageId });
// spell check error count
object spellingErrors = _wordDocumentType.InvokeMember("SpellingErrors", BindingFlags.GetProperty, null, _wordDocument, null);
object spellingErrorsCount = spellingErrors.GetType().InvokeMember("Count", BindingFlags.GetProperty, null, spellingErrors, null);