Still more word...

git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@250 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
niksedk 2011-01-15 12:25:50 +00:00
parent 7801d42aac
commit ade74553cf
4 changed files with 65 additions and 32 deletions

View File

@ -103,7 +103,7 @@ namespace Nikse.SubtitleEdit.Forms
if (versionInfo.Length >= 3 && versionInfo[2] != "0")
_title += "." + versionInfo[2];
}
return _title + " Beta 3";
return _title + " Beta 6";
}
}
@ -216,7 +216,7 @@ namespace Nikse.SubtitleEdit.Forms
fileName = Configuration.Settings.RecentFiles.Files[0].FileName;
if (File.Exists(fileName))
{
OpenSubtitle(fileName, null);
OpenSubtitle(fileName, null, Configuration.Settings.RecentFiles.Files[0].VideoFileName);
SetRecentIndecies(fileName);
}
}
@ -780,7 +780,7 @@ namespace Nikse.SubtitleEdit.Forms
{
_fileName = saveFileDialog1.FileName;
Text = Title + " - " + _fileName;
Configuration.Settings.RecentFiles.Add(_fileName, FirstVisibleIndex, FirstSelectedIndex);
Configuration.Settings.RecentFiles.Add(_fileName, FirstVisibleIndex, FirstSelectedIndex, _videoFileName);
Configuration.Settings.Save();
if (SaveSubtitle(GetCurrentSubtitleFormat()) == DialogResult.OK)
@ -923,12 +923,19 @@ namespace Nikse.SubtitleEdit.Forms
}
private void OpenSubtitle(string fileName, Encoding encoding)
{
OpenSubtitle(fileName, encoding, null);
}
private void OpenSubtitle(string fileName, Encoding encoding, string videoFileName)
{
if (File.Exists(fileName))
{
bool videoFileLoaded = false;
// save last first visible index + first selected index from listview
if (!string.IsNullOrEmpty(_fileName))
Configuration.Settings.RecentFiles.Add(_fileName, FirstVisibleIndex, FirstSelectedIndex);
Configuration.Settings.RecentFiles.Add(_fileName, FirstVisibleIndex, FirstSelectedIndex, _videoFileName);
openFileDialog1.InitialDirectory = Path.GetDirectoryName(fileName);
@ -1002,13 +1009,25 @@ namespace Nikse.SubtitleEdit.Forms
AudioWaveForm.WavePeaks = null;
AudioWaveForm.Invalidate();
if (!string.IsNullOrEmpty(videoFileName) && File.Exists(videoFileName))
{
OpenVideo(videoFileName);
}
else if (!string.IsNullOrEmpty(_fileName) && (toolStripButtonToogleVideo.Checked || toolStripButtonToogleWaveForm.Checked))
{
TryToFindAndOpenVideoFile(Path.Combine(Path.GetDirectoryName(_fileName), Path.GetFileNameWithoutExtension(_fileName)));
}
videoFileLoaded = _videoFileName != null;
if (Configuration.Settings.RecentFiles.Files.Count > 0 &&
Configuration.Settings.RecentFiles.Files[0].FileName == fileName)
{
}
else
{
Configuration.Settings.RecentFiles.Add(fileName);
Configuration.Settings.RecentFiles.Add(fileName, _videoFileName);
Configuration.Settings.Save();
UpdateRecentFilesUI();
}
@ -1060,7 +1079,7 @@ namespace Nikse.SubtitleEdit.Forms
AudioWaveForm.WavePeaks = null;
AudioWaveForm.Invalidate();
Configuration.Settings.RecentFiles.Add(fileName, FirstVisibleIndex, FirstSelectedIndex);
Configuration.Settings.RecentFiles.Add(fileName, FirstVisibleIndex, FirstSelectedIndex, _videoFileName);
Configuration.Settings.Save();
UpdateRecentFilesUI();
_fileName = fileName;
@ -1075,18 +1094,12 @@ namespace Nikse.SubtitleEdit.Forms
else
ShowUnknownSubtitle();
}
if (!string.IsNullOrEmpty(_fileName) && (toolStripButtonToogleVideo.Checked || toolStripButtonToogleWaveForm.Checked))
if (!videoFileLoaded && mediaPlayer.VideoPlayer != null)
{
TryToFindAndOpenVideoFile(Path.Combine(Path.GetDirectoryName(_fileName), Path.GetFileNameWithoutExtension(_fileName)));
}
else
{
if (mediaPlayer.VideoPlayer != null)
{
mediaPlayer.VideoPlayer.DisposeVideoPlayer();
mediaPlayer.VideoPlayer = null;
timer1.Stop();
}
}
}
else
@ -1220,7 +1233,7 @@ namespace Nikse.SubtitleEdit.Forms
_fileDateTime = File.GetLastWriteTime(_fileName);
Text = Title + " - " + _fileName;
Configuration.Settings.RecentFiles.Add(_fileName, FirstVisibleIndex, FirstSelectedIndex);
Configuration.Settings.RecentFiles.Add(_fileName, FirstVisibleIndex, FirstSelectedIndex, _videoFileName);
Configuration.Settings.Save();
int index = 0;
@ -2774,7 +2787,7 @@ namespace Nikse.SubtitleEdit.Forms
return;
WordSpellChecker wordSpellChecker = null;
int totalCorrections = 0;
int totalLinesChanged = 0;
try
{
wordSpellChecker = new WordSpellChecker();
@ -2805,15 +2818,18 @@ namespace Nikse.SubtitleEdit.Forms
{
wordSpellChecker.CloseDocument();
wordSpellChecker.Quit();
ShowStatus(string.Format(_language.SpellCheckAbortedXCorrections, totalCorrections));
ShowStatus(string.Format(_language.SpellCheckAbortedXCorrections, totalLinesChanged));
Cursor = Cursors.Default;
return;
}
else if (errorsBefore != errorsAfter)
{
textBoxListViewText.Text = newText;
if (textBoxListViewText.Text != newText)
{
textBoxListViewText.Text = newText;
totalLinesChanged++;
}
}
totalCorrections += (errorsBefore - errorsAfter);
Application.DoEvents();
if (_cancelWordSpellCheck)
@ -2821,7 +2837,7 @@ namespace Nikse.SubtitleEdit.Forms
}
wordSpellChecker.CloseDocument();
wordSpellChecker.Quit();
ShowStatus(string.Format(_language.SpellCheckCompletedXCorrections, totalCorrections));
ShowStatus(string.Format(_language.SpellCheckCompletedXCorrections, totalLinesChanged));
Cursor = Cursors.Default;
}
@ -3928,7 +3944,7 @@ namespace Nikse.SubtitleEdit.Forms
Configuration.Settings.General.AutoContinueOn = checkBoxAutoContinue.Checked;
Configuration.Settings.General.SyncListViewWithVideoWhilePlaying = checkBoxSyncListViewWithVideoWhilePlaying.Checked;
if (!string.IsNullOrEmpty(_fileName))
Configuration.Settings.RecentFiles.Add(_fileName, FirstVisibleIndex, FirstSelectedIndex);
Configuration.Settings.RecentFiles.Add(_fileName, FirstVisibleIndex, FirstSelectedIndex, _videoFileName);
Configuration.Settings.Save();
}

View File

@ -664,8 +664,8 @@ namespace Nikse.SubtitleEdit.Logic
XStartedSessionYAtZ = "{0}: Started session {1} at {2}",
SpellChekingViaWordXLineYOfX = "Spell checking using Word {0} - line {1} / {2}",
UnableToStartWord = "Unable to start Microsoft Word",
SpellCheckAbortedXCorrections = "Spell check aborted. {0} corrections was made.",
SpellCheckCompletedXCorrections = "Spell check completed. {0} corrections was made.",
SpellCheckAbortedXCorrections = "Spell check aborted. {0} lines was modified.",
SpellCheckCompletedXCorrections = "Spell check completed. {0} lines was modified.",
Menu = new LanguageStructure.Main.MainMenu
{

View File

@ -14,6 +14,7 @@ namespace Nikse.SubtitleEdit.Logic
public class RecentFileEntry
{
public string FileName { get; set; }
public string VideoFileName { get; set; }
public int FirstVisibleIndex { get; set; }
public int FirstSelectedIndex { get; set; }
}
@ -30,35 +31,35 @@ namespace Nikse.SubtitleEdit.Logic
Files = new List<RecentFileEntry>();
}
public void Add(string fileName, int firstVisibleIndex, int firstSelectedIndex)
public void Add(string fileName, int firstVisibleIndex, int firstSelectedIndex, string videoFileName)
{
var newList = new List<RecentFileEntry> { new RecentFileEntry() { FileName = fileName, FirstVisibleIndex = firstVisibleIndex, FirstSelectedIndex = firstSelectedIndex } };
var newList = new List<RecentFileEntry> { new RecentFileEntry() { FileName = fileName, FirstVisibleIndex = firstVisibleIndex, FirstSelectedIndex = firstSelectedIndex, VideoFileName = videoFileName } };
int index = 0;
foreach (var oldRecentFile in Files)
{
if (string.Compare(fileName, oldRecentFile.FileName, true) != 0 && index < MaxRecentFiles)
newList.Add(new RecentFileEntry() { FileName = oldRecentFile.FileName, FirstVisibleIndex = oldRecentFile.FirstVisibleIndex, FirstSelectedIndex = oldRecentFile.FirstSelectedIndex });
newList.Add(new RecentFileEntry() { FileName = oldRecentFile.FileName, FirstVisibleIndex = oldRecentFile.FirstVisibleIndex, FirstSelectedIndex = oldRecentFile.FirstSelectedIndex, VideoFileName = oldRecentFile.VideoFileName });
index++;
}
Files = newList;
}
public void Add(string fileName)
public void Add(string fileName, string videoFileName)
{
var newList = new List<RecentFileEntry>();
foreach (var oldRecentFile in Files)
{
if (string.Compare(fileName, oldRecentFile.FileName, true) == 0)
newList.Add(new RecentFileEntry() { FileName = oldRecentFile.FileName, FirstVisibleIndex = oldRecentFile.FirstVisibleIndex, FirstSelectedIndex = oldRecentFile.FirstSelectedIndex });
newList.Add(new RecentFileEntry() { FileName = oldRecentFile.FileName, FirstVisibleIndex = oldRecentFile.FirstVisibleIndex, FirstSelectedIndex = oldRecentFile.FirstSelectedIndex, VideoFileName = oldRecentFile.VideoFileName });
}
if (newList.Count == 0)
newList.Add(new RecentFileEntry() { FileName = fileName, FirstVisibleIndex = -1, FirstSelectedIndex = -1 });
newList.Add(new RecentFileEntry() { FileName = fileName, FirstVisibleIndex = -1, FirstSelectedIndex = -1, VideoFileName = videoFileName });
int index = 0;
foreach (var oldRecentFile in Files)
{
if (string.Compare(fileName, oldRecentFile.FileName, true) != 0 && index < MaxRecentFiles)
newList.Add(new RecentFileEntry() { FileName = oldRecentFile.FileName, FirstVisibleIndex = oldRecentFile.FirstVisibleIndex, FirstSelectedIndex = oldRecentFile.FirstSelectedIndex });
newList.Add(new RecentFileEntry() { FileName = oldRecentFile.FileName, FirstVisibleIndex = oldRecentFile.FirstVisibleIndex, FirstSelectedIndex = oldRecentFile.FirstSelectedIndex, VideoFileName = oldRecentFile.VideoFileName });
index++;
}
Files = newList;
@ -488,7 +489,11 @@ namespace Nikse.SubtitleEdit.Logic
if (listNode.Attributes["FirstSelectedIndex"] != null)
firstSelectedIndex = listNode.Attributes["FirstSelectedIndex"].Value;
settings.RecentFiles.Files.Add(new RecentFileEntry() { FileName = listNode.InnerText, FirstVisibleIndex = int.Parse(firstVisibleIndex), FirstSelectedIndex = int.Parse(firstSelectedIndex) });
string videoFileName = null;
if (listNode.Attributes["VideoFileName"] != null)
videoFileName = listNode.Attributes["VideoFileName"].Value;
settings.RecentFiles.Files.Add(new RecentFileEntry() { FileName = listNode.InnerText, FirstVisibleIndex = int.Parse(firstVisibleIndex), FirstSelectedIndex = int.Parse(firstSelectedIndex), VideoFileName = videoFileName });
}
@ -882,6 +887,8 @@ namespace Nikse.SubtitleEdit.Logic
foreach (var item in settings.RecentFiles.Files)
{
textWriter.WriteStartElement("FileName");
if (item.VideoFileName != null)
textWriter.WriteAttributeString("VideoFileName", item.VideoFileName);
textWriter.WriteAttributeString("FirstVisibleIndex", item.FirstVisibleIndex.ToString());
textWriter.WriteAttributeString("FirstSelectedIndex", item.FirstSelectedIndex.ToString());
textWriter.WriteString(item.FileName);

View File

@ -21,11 +21,19 @@ namespace Nikse.SubtitleEdit.Logic
private Type _wordDocumentType;
bool _firstShow = true;
const int wdWindowStateNormal = 0;
const int wdWindowStateMaximize = 1;
const int wdWindowStateMinimize = 2;
public WordSpellChecker()
{
_wordApplicationType = System.Type.GetTypeFromProgID("Word.Application");
_wordApplication = Activator.CreateInstance(_wordApplicationType);
_wordApplicationType.InvokeMember("WindowState", BindingFlags.SetProperty, null, _wordApplication, new object[] { 0 }); // 0 == ?
_wordApplicationType.InvokeMember("WindowState", BindingFlags.SetProperty, null, _wordApplication, new object[] { wdWindowStateMinimize });
_wordApplicationType.InvokeMember("WindowState", BindingFlags.SetProperty, null, _wordApplication, new object[] { wdWindowStateMinimize });
_wordApplicationType.InvokeMember("WindowState", BindingFlags.SetProperty, null, _wordApplication, new object[] { wdWindowStateMinimize });
_wordApplicationType.InvokeMember("Top", BindingFlags.SetProperty, null, _wordApplication, new object[] { -10000 }); // hide window - it's a hack
_wordApplicationType.InvokeMember("Top", BindingFlags.SetProperty, null, _wordApplication, new object[] { -10000 }); // hide window - it's a hack
}
@ -96,9 +104,11 @@ namespace Nikse.SubtitleEdit.Logic
_firstShow = false;
}
_wordApplicationType.InvokeMember("WindowState", BindingFlags.SetProperty, null, _wordApplication, new object[] { wdWindowStateMinimize });
_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[] { -10000 }); // hide window - it's a hack
}
// spell check error count