mirror of https://github.com/odrling/Aegisub
Fixed splash and added a "add to dictionary" option
Originally committed to SVN as r677.
This commit is contained in:
parent
9d1a3466dd
commit
4c792dc6ba
|
@ -58,8 +58,11 @@ SplashScreen::SplashScreen(wxWindow *parent)
|
||||||
// Center on current display
|
// Center on current display
|
||||||
if (wxDisplay::GetCount() < 1) CentreOnParent();
|
if (wxDisplay::GetCount() < 1) CentreOnParent();
|
||||||
else {
|
else {
|
||||||
|
// Get parent position
|
||||||
|
wxRect parRect = parent->GetRect();
|
||||||
|
|
||||||
// Get display number
|
// Get display number
|
||||||
int point = wxDisplay::GetFromPoint(parent->GetScreenPosition());
|
int point = wxDisplay::GetFromPoint(wxPoint(parRect.GetX() + parRect.GetWidth()/2,parRect.GetY() + parRect.GetHeight()/2));
|
||||||
if (point == wxNOT_FOUND) point = 0;
|
if (point == wxNOT_FOUND) point = 0;
|
||||||
|
|
||||||
// Get display size
|
// Get display size
|
||||||
|
|
|
@ -42,6 +42,8 @@
|
||||||
#include <wx/wxprec.h>
|
#include <wx/wxprec.h>
|
||||||
#include <wx/dir.h>
|
#include <wx/dir.h>
|
||||||
#include <wx/filename.h>
|
#include <wx/filename.h>
|
||||||
|
#include <wx/wfstream.h>
|
||||||
|
#include <wx/txtstrm.h>
|
||||||
#include "spellchecker_hunspell.h"
|
#include "spellchecker_hunspell.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
@ -60,10 +62,19 @@ HunspellSpellChecker::HunspellSpellChecker() {
|
||||||
//////////////
|
//////////////
|
||||||
// Destructor
|
// Destructor
|
||||||
HunspellSpellChecker::~HunspellSpellChecker() {
|
HunspellSpellChecker::~HunspellSpellChecker() {
|
||||||
|
Reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/////////
|
||||||
|
// Reset
|
||||||
|
void HunspellSpellChecker::Reset() {
|
||||||
delete hunspell;
|
delete hunspell;
|
||||||
hunspell = NULL;
|
hunspell = NULL;
|
||||||
delete conv;
|
delete conv;
|
||||||
conv = NULL;
|
conv = NULL;
|
||||||
|
affpath.Clear();
|
||||||
|
dicpath.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -78,7 +89,51 @@ bool HunspellSpellChecker::CanAddWord(wxString word) {
|
||||||
//////////////////////////
|
//////////////////////////
|
||||||
// Add word to dictionary
|
// Add word to dictionary
|
||||||
void HunspellSpellChecker::AddWord(wxString word) {
|
void HunspellSpellChecker::AddWord(wxString word) {
|
||||||
if (hunspell) hunspell->put_word(word.mb_str(*conv));
|
// Dictionary OK?
|
||||||
|
if (!hunspell) return;
|
||||||
|
|
||||||
|
// Add to currently loaded file
|
||||||
|
hunspell->put_word(word.mb_str(*conv));
|
||||||
|
|
||||||
|
// Load dictionary
|
||||||
|
wxArrayString dic;
|
||||||
|
wxString curLine;
|
||||||
|
if (!dicpath.IsEmpty()) { // Even if you ever want to remove this "if", keep the braces, so the stream closes at the end
|
||||||
|
bool first = true;
|
||||||
|
bool added = false;
|
||||||
|
wxFileInputStream in(dicpath);
|
||||||
|
if (!in.IsOk()) return;
|
||||||
|
wxTextInputStream textIn(in,_T(" \t"),*conv);
|
||||||
|
|
||||||
|
// Read it
|
||||||
|
while (in.CanRead() && !in.Eof()) {
|
||||||
|
// Read line
|
||||||
|
curLine = textIn.ReadLine();
|
||||||
|
curLine.Trim();
|
||||||
|
|
||||||
|
// First
|
||||||
|
if (first) {
|
||||||
|
first = false;
|
||||||
|
if (curLine.IsNumber()) continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// See if word to be added goes here
|
||||||
|
if (!added && curLine.Lower() > word.Lower()) {
|
||||||
|
dic.Add(word);
|
||||||
|
added = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add to memory dictionary
|
||||||
|
dic.Add(curLine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write back to disk
|
||||||
|
wxFileOutputStream out(dicpath);
|
||||||
|
if (!out.IsOk()) return;
|
||||||
|
wxTextOutputStream textOut(out,wxEOL_UNIX,*conv);
|
||||||
|
textOut.WriteString(wxString::Format(_T("%i"),dic.Count())+_T("\n"));
|
||||||
|
for (unsigned int i=0;i<dic.Count();i++) textOut.WriteString(dic[i]+_T("\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -159,20 +214,15 @@ wxArrayString HunspellSpellChecker::GetLanguageList() {
|
||||||
// Set language
|
// Set language
|
||||||
void HunspellSpellChecker::SetLanguage(wxString language) {
|
void HunspellSpellChecker::SetLanguage(wxString language) {
|
||||||
// Unload
|
// Unload
|
||||||
delete hunspell;
|
Reset();
|
||||||
hunspell = NULL;
|
|
||||||
delete conv;
|
|
||||||
conv = NULL;
|
|
||||||
|
|
||||||
// Unloading
|
|
||||||
if (language.IsEmpty()) return;
|
if (language.IsEmpty()) return;
|
||||||
|
|
||||||
// Get dir name
|
// Get dir name
|
||||||
wxString path = DecodeRelativePath(Options.AsText(_T("Dictionaries path")),AegisubApp::folderName) + _T("/");
|
wxString path = DecodeRelativePath(Options.AsText(_T("Dictionaries path")),AegisubApp::folderName) + _T("/");
|
||||||
|
|
||||||
// Get affix and dictionary paths
|
// Get affix and dictionary paths
|
||||||
wxString affpath = path + language + _T(".aff");
|
affpath = path + language + _T(".aff");
|
||||||
wxString dicpath = path + language + _T(".dic");
|
dicpath = path + language + _T(".dic");
|
||||||
|
|
||||||
// Check if language is available
|
// Check if language is available
|
||||||
if (!wxFileExists(affpath) || !wxFileExists(dicpath)) return;
|
if (!wxFileExists(affpath) || !wxFileExists(dicpath)) return;
|
||||||
|
|
|
@ -53,6 +53,10 @@ class HunspellSpellChecker : public SpellChecker {
|
||||||
private:
|
private:
|
||||||
Hunspell *hunspell;
|
Hunspell *hunspell;
|
||||||
wxCSConv *conv;
|
wxCSConv *conv;
|
||||||
|
wxString affpath;
|
||||||
|
wxString dicpath;
|
||||||
|
|
||||||
|
void Reset();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
HunspellSpellChecker();
|
HunspellSpellChecker();
|
||||||
|
|
Loading…
Reference in New Issue