forked from mia/Aegisub
Made hunspell into a pluggable factory. This MIGHT cause issues with mythes if hunspell is not available...
Originally committed to SVN as r1108.
This commit is contained in:
parent
b2f2cf2d7f
commit
4f1dc2c59d
14 changed files with 108 additions and 199 deletions
|
@ -40,7 +40,6 @@
|
|||
#include "dialog_about.h"
|
||||
#include "version.h"
|
||||
#include "options.h"
|
||||
#include "setup.h"
|
||||
|
||||
|
||||
///////////////
|
||||
|
@ -62,21 +61,11 @@ AboutScreen::AboutScreen(wxWindow *parent)
|
|||
libString += _T("wxWidgets - Copyright (c) 1998-2006 Julian Smart, Robert Roebling et al;\n");
|
||||
libString += _T("wxStyledTextCtrl - Copyright (c) 2004 wxCode;\n");
|
||||
libString += _T("Lua - Copyright (c) 1994-2006 Lua.org, PUC-Rio;\n");
|
||||
#if USE_HUNSPELL == 1
|
||||
libString += _T("Hunspell - Copyright (c) Kevin Hendricks;\n");
|
||||
#endif
|
||||
#if USE_PORTAUDIO == 1
|
||||
libString += _T("PortAudio - Copyright (c) 1999-2000 Ross Bencina, Phil Burk;\n");
|
||||
#endif
|
||||
#if USE_LAVC == 1
|
||||
libString += _T("FFmpeg - Copyright (c) ??;\n");
|
||||
#endif
|
||||
#if USE_LIBASS == 1
|
||||
libString += _T("libass - Copyright (c) 2006, Evgeniy Stepanov;\n");
|
||||
#endif
|
||||
#if USE_ASA == 1
|
||||
libString += _T("FFmpeg - Copyright (c) 2001 Fabrice Bellard,;\n");
|
||||
libString += _T("libass - Copyright (c) 2006-2007, Evgeniy Stepanov;\n");
|
||||
libString += _T("asa - Copyright (c) 2004-2007, David Lamparter;\n");
|
||||
#endif
|
||||
libString += _T("MyThes - Copyright (c) 2003 Kevin B. Hendricks, Stratford, Ontario, Canada\n");
|
||||
libString += _T("Matroska Parser and VideoSink - Copyright (c) 2004-2007 Mike Matsnev\n");
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ DialogSpellChecker::DialogSpellChecker(wxFrame *parent)
|
|||
: wxDialog(parent, -1, _("Spell Checker"), wxDefaultPosition, wxDefaultSize)
|
||||
{
|
||||
// Get spell checker
|
||||
spellchecker = SpellChecker::GetSpellChecker();
|
||||
spellchecker = SpellCheckerFactory::GetSpellChecker();
|
||||
if (!spellchecker) {
|
||||
wxMessageBox(_T("No spellchecker available."),_T("Error"),wxICON_ERROR);
|
||||
Destroy();
|
||||
|
|
|
@ -234,9 +234,7 @@ void FrameMain::InitToolbar () {
|
|||
Toolbar->AddTool(Menu_Tools_Fonts_Collector,_("Fonts Collector"),wxBITMAP(font_collector_button),_("Open Fonts Collector"));
|
||||
Toolbar->AddTool(Menu_Tools_Resample,_("Resample"),wxBITMAP(resample_toolbutton),_("Resample Script Resolution"));
|
||||
Toolbar->AddTool(Menu_Tools_Timing_Processor,_("Timing Post-Processor"),wxBITMAP(timing_processor_toolbutton),_("Open Timing Post-processor dialog"));
|
||||
#if USE_HUNSPELL == 1
|
||||
Toolbar->AddTool(Menu_Tools_SpellCheck,_("Spell Checker"),wxBITMAP(spellcheck_toolbutton),_("Open Spell checker"));
|
||||
#endif
|
||||
Toolbar->AddSeparator();
|
||||
|
||||
// Options
|
||||
|
@ -332,9 +330,7 @@ void FrameMain::InitMenu() {
|
|||
AppendBitmapMenuItem (subtitlesMenu,Menu_Tools_Translation, _("&Translation Assistant..."),_("Open translation assistant"), wxBITMAP(translation_toolbutton));
|
||||
AppendBitmapMenuItem (subtitlesMenu,Menu_Tools_Resample,_("Resample resolution..."), _("Changes resolution and modifies subtitles to conform to change"), wxBITMAP(resample_toolbutton));
|
||||
AppendBitmapMenuItem (subtitlesMenu,Menu_Tools_Fonts_Collector, _("&Fonts Collector..."),_("Open fonts collector"), wxBITMAP(font_collector_button));
|
||||
#if USE_HUNSPELL == 1
|
||||
AppendBitmapMenuItem (subtitlesMenu,Menu_Tools_SpellCheck, _("Spe&ll Checker..."),_("Open spell checker"), wxBITMAP(spellcheck_toolbutton));
|
||||
#endif
|
||||
MenuBar->Append(subtitlesMenu, _("&Subtitles"));
|
||||
|
||||
// Create timing menu
|
||||
|
|
|
@ -38,12 +38,11 @@
|
|||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include "setup.h"
|
||||
#include "mythes.hxx"
|
||||
|
||||
// some basic utility routines
|
||||
|
||||
#if USE_HUNSPELL == 0
|
||||
#if 0
|
||||
// string duplication routine
|
||||
char * mystrdup(const char * p)
|
||||
{
|
||||
|
@ -56,7 +55,17 @@ char * mystrdup(const char * p)
|
|||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// remove cross-platform text line end characters
|
||||
void mychomp(char * s)
|
||||
{
|
||||
int k = strlen(s);
|
||||
if ((k > 0) && ((*(s+k-1)=='\r') || (*(s+k-1)=='\n'))) *(s+k-1) = '\0';
|
||||
if ((k > 1) && (*(s+k-2) == '\r')) *(s+k-2) = '\0';
|
||||
}
|
||||
#endif
|
||||
char * mystrdup(const char * p);
|
||||
void mychomp(char * s);
|
||||
|
||||
|
||||
// return index of char in string
|
||||
|
@ -68,17 +77,6 @@ int mystr_indexOfChar(const char * d, int c)
|
|||
}
|
||||
|
||||
|
||||
// remove cross-platform text line end characters
|
||||
#if USE_HUNSPELL == 0
|
||||
void mychomp(char * s)
|
||||
{
|
||||
int k = strlen(s);
|
||||
if ((k > 0) && ((*(s+k-1)=='\r') || (*(s+k-1)=='\n'))) *(s+k-1) = '\0';
|
||||
if ((k > 1) && (*(s+k-2) == '\r')) *(s+k-2) = '\0';
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
MyThes::MyThes(const char* idxpath, const char * datpath)
|
||||
{
|
||||
nw = 0;
|
||||
|
|
|
@ -108,6 +108,7 @@ void OptionsManager::LoadDefaults(bool onlyDefaults) {
|
|||
|
||||
// Edit Box
|
||||
SetText(_T("Dictionaries path"),_T("dictionaries"));
|
||||
SetText(_T("Spell Checker"),_T("hunspell"));
|
||||
SetBool(_T("Link time boxes commit"),true);
|
||||
SetModificationType(MOD_EDIT_BOX);
|
||||
SetBool(_T("Call tips enabled"),true);
|
||||
|
|
|
@ -93,15 +93,4 @@
|
|||
#pragma comment(lib, "wsock32.lib")
|
||||
|
||||
|
||||
////////////
|
||||
// Hunspell
|
||||
#if USE_HUNSPELL == 1
|
||||
#ifdef __WXDEBUG__
|
||||
#pragma comment(lib,"hunspelld.lib")
|
||||
#else
|
||||
#pragma comment(lib,"hunspell.lib")
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#endif // VisualC
|
||||
|
|
|
@ -42,36 +42,6 @@
|
|||
//
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////
|
||||
// Enable DirectShow Video Provider
|
||||
// Requires: Win32, DirectX SDK
|
||||
#define USE_DIRECTSHOW 0
|
||||
|
||||
|
||||
///////////////////////////////////
|
||||
// Enable DirectSound Audio Player
|
||||
// Requires: Win32, DirectX SDK
|
||||
#define USE_DIRECTSOUND 1
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Enable PortAudio Audio Player
|
||||
// Requires: PortAudio library
|
||||
#define USE_PORTAUDIO 0
|
||||
|
||||
|
||||
////////////////////////////////
|
||||
// Enable Hunspell spellchecker
|
||||
#define USE_HUNSPELL 0
|
||||
|
||||
|
||||
//////////////////////////////
|
||||
// Enable LAVC video provider
|
||||
// Requires: FFMPEG library
|
||||
#define USE_LAVC 0
|
||||
|
||||
|
||||
////////////////////////
|
||||
// Enable PRS Exporting
|
||||
// Requires: wxPNG library
|
||||
|
@ -84,17 +54,7 @@
|
|||
#define USE_FEXTRACKER 1
|
||||
|
||||
|
||||
// The following two are Linux-specific, so it would involve changing the makefiles
|
||||
// Therefore, I haven't changed the code to make them work, yet
|
||||
|
||||
|
||||
/////////////////
|
||||
// Enable LibASS
|
||||
// Requires: libass library, GNU?
|
||||
// Requires: libass library
|
||||
#define USE_LIBASS 0
|
||||
|
||||
|
||||
//////////////
|
||||
// Enable ASA
|
||||
// Requires: asa library
|
||||
#define USE_ASA 0
|
||||
|
|
|
@ -38,22 +38,35 @@
|
|||
// Headers
|
||||
#include "setup.h"
|
||||
#include "spellchecker.h"
|
||||
#if USE_HUNSPELL == 1
|
||||
#include "spellchecker_hunspell.h"
|
||||
#endif
|
||||
#include "options.h"
|
||||
|
||||
|
||||
/////////////////////
|
||||
// Get spell checker
|
||||
SpellChecker *SpellChecker::GetSpellChecker() {
|
||||
// Initialize
|
||||
SpellChecker *check = NULL;
|
||||
SpellChecker *SpellCheckerFactory::GetSpellChecker() {
|
||||
// List of providers
|
||||
wxArrayString list = GetFactoryList(Options.AsText(_T("Spell Checker")));
|
||||
|
||||
// Try hunspell
|
||||
#if USE_HUNSPELL == 1
|
||||
check = new HunspellSpellChecker();
|
||||
#endif
|
||||
// None available
|
||||
if (list.Count() == 0) throw _T("No spell checkers are available.");
|
||||
|
||||
// Return
|
||||
return check;
|
||||
// Get provider
|
||||
wxString error;
|
||||
for (unsigned int i=0;i<list.Count();i++) {
|
||||
try {
|
||||
SpellChecker *checker = GetFactory(list[i])->CreateSpellChecker();
|
||||
if (checker) return checker;
|
||||
}
|
||||
catch (wxString err) { error += list[i] + _T(" factory: ") + err + _T("\n"); }
|
||||
catch (const wxChar *err) { error += list[i] + _T(" factory: ") + wxString(err) + _T("\n"); }
|
||||
catch (...) { error += list[i] + _T(" factory: Unknown error\n"); }
|
||||
}
|
||||
|
||||
// Failed
|
||||
throw error;
|
||||
}
|
||||
|
||||
|
||||
//////////
|
||||
// Static
|
||||
template <class SpellCheckerFactory> std::map<wxString,SpellCheckerFactory*>* AegisubFactory<SpellCheckerFactory>::factories=NULL;
|
||||
|
|
|
@ -40,14 +40,13 @@
|
|||
///////////
|
||||
// Headers
|
||||
#include <wx/wxprec.h>
|
||||
#include "factory.h"
|
||||
|
||||
|
||||
///////////////////////////
|
||||
// Spellchecking interface
|
||||
class SpellChecker {
|
||||
public:
|
||||
static SpellChecker *GetSpellChecker();
|
||||
|
||||
SpellChecker() {}
|
||||
virtual ~SpellChecker() {}
|
||||
|
||||
|
@ -60,3 +59,16 @@ public:
|
|||
virtual wxArrayString GetLanguageList()=0;
|
||||
virtual void SetLanguage(wxString language)=0;
|
||||
};
|
||||
|
||||
|
||||
///////////
|
||||
// Factory
|
||||
class SpellCheckerFactory : public AegisubFactory<SpellCheckerFactory> {
|
||||
protected:
|
||||
virtual SpellChecker *CreateSpellChecker()=0;
|
||||
SpellCheckerFactory(wxString name) { RegisterFactory(name); }
|
||||
|
||||
public:
|
||||
virtual ~SpellCheckerFactory() {}
|
||||
static SpellChecker *GetSpellChecker();
|
||||
};
|
||||
|
|
|
@ -36,18 +36,63 @@
|
|||
|
||||
///////////
|
||||
// Headers
|
||||
#include "setup.h"
|
||||
#if USE_HUNSPELL == 1
|
||||
#include "spellchecker.h"
|
||||
#include "main.h"
|
||||
#include "utils.h"
|
||||
#include "options.h"
|
||||
#include <hunspell/hunspell.hxx>
|
||||
#include <wx/wxprec.h>
|
||||
#include <wx/wxprec.h>
|
||||
#include <wx/dir.h>
|
||||
#include <wx/filename.h>
|
||||
#include <wx/wfstream.h>
|
||||
#include <wx/txtstrm.h>
|
||||
#include "spellchecker_hunspell.h"
|
||||
#include "main.h"
|
||||
#include "utils.h"
|
||||
#include "options.h"
|
||||
|
||||
|
||||
/////////////
|
||||
// Libraries
|
||||
#if __VISUALC__ >= 1200
|
||||
#ifdef __WXDEBUG__
|
||||
#pragma comment(lib,"hunspelld.lib")
|
||||
#else
|
||||
#pragma comment(lib,"hunspell.lib")
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
//////////////////
|
||||
// Hunspell class
|
||||
class HunspellSpellChecker : public SpellChecker {
|
||||
private:
|
||||
Hunspell *hunspell;
|
||||
wxCSConv *conv;
|
||||
wxString affpath;
|
||||
wxString dicpath;
|
||||
|
||||
void Reset();
|
||||
|
||||
public:
|
||||
HunspellSpellChecker();
|
||||
~HunspellSpellChecker();
|
||||
|
||||
void AddWord(wxString word);
|
||||
bool CanAddWord(wxString word);
|
||||
|
||||
bool CheckWord(wxString word);
|
||||
wxArrayString GetSuggestions(wxString word);
|
||||
|
||||
wxArrayString GetLanguageList();
|
||||
void SetLanguage(wxString language);
|
||||
};
|
||||
|
||||
|
||||
///////////
|
||||
// Factory
|
||||
class HunspellSpellCheckerFactory : public SpellCheckerFactory {
|
||||
public:
|
||||
SpellChecker *CreateSpellChecker() { return new HunspellSpellChecker(); }
|
||||
HunspellSpellCheckerFactory() : SpellCheckerFactory(_T("hunspell")) {}
|
||||
} registerHunspell;
|
||||
|
||||
|
||||
///////////////
|
||||
|
@ -234,5 +279,3 @@ void HunspellSpellChecker::SetLanguage(wxString language) {
|
|||
conv = NULL;
|
||||
if (hunspell) conv = new wxCSConv(wxString(hunspell->get_dic_encoding(),wxConvUTF8));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,76 +0,0 @@
|
|||
// Copyright (c) 2006, Rodrigo Braz Monteiro
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// * Neither the name of the Aegisub Group nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// AEGISUB
|
||||
//
|
||||
// Website: http://aegisub.cellosoft.com
|
||||
// Contact: mailto:zeratul@cellosoft.com
|
||||
//
|
||||
|
||||
|
||||
///////////
|
||||
// Headers
|
||||
#include "setup.h"
|
||||
#if USE_HUNSPELL == 1
|
||||
#include "spellchecker.h"
|
||||
#include <wx/wxprec.h>
|
||||
|
||||
|
||||
//////////////
|
||||
// Prototypes
|
||||
class Hunspell;
|
||||
|
||||
|
||||
//////////////////
|
||||
// Hunspell class
|
||||
class HunspellSpellChecker : public SpellChecker {
|
||||
private:
|
||||
Hunspell *hunspell;
|
||||
wxCSConv *conv;
|
||||
wxString affpath;
|
||||
wxString dicpath;
|
||||
|
||||
void Reset();
|
||||
|
||||
public:
|
||||
HunspellSpellChecker();
|
||||
~HunspellSpellChecker();
|
||||
|
||||
void AddWord(wxString word);
|
||||
bool CanAddWord(wxString word);
|
||||
|
||||
bool CheckWord(wxString word);
|
||||
wxArrayString GetSuggestions(wxString word);
|
||||
|
||||
wxArrayString GetLanguageList();
|
||||
void SetLanguage(wxString language);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
|
@ -79,7 +79,6 @@
|
|||
#include <wx/event.h>
|
||||
#include <wx/stc/stc.h>
|
||||
#include <wx/string.h>
|
||||
//#include <GL/glew.h>
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
#include <wx/glcanvas.h>
|
||||
|
@ -92,18 +91,4 @@
|
|||
#include <map>
|
||||
|
||||
|
||||
///////////////
|
||||
// DirectSound
|
||||
#if USE_DIRECTSOUND == 1
|
||||
//#include <dsound.h>
|
||||
#endif
|
||||
|
||||
|
||||
////////////
|
||||
// Hunspell
|
||||
#if USE_HUNSPELL == 1
|
||||
#include <hunspell/hunspell.hxx>
|
||||
#endif
|
||||
|
||||
|
||||
#endif // C++
|
||||
|
|
|
@ -69,7 +69,7 @@ SubsTextEditCtrl::SubsTextEditCtrl(wxWindow* parent, wxWindowID id, const wxStri
|
|||
CmdKeyClear('U',wxSTC_SCMOD_CTRL);
|
||||
|
||||
// Set spellchecker
|
||||
spellchecker = SpellChecker::GetSpellChecker();
|
||||
spellchecker = SpellCheckerFactory::GetSpellChecker();
|
||||
|
||||
// Set thesaurus
|
||||
thesaurus = Thesaurus::GetThesaurus();
|
||||
|
|
|
@ -185,7 +185,7 @@ void TextFileReader::SetEncodingConfiguration() {
|
|||
wxString TextFileReader::ReadLineFromFile() {
|
||||
Open();
|
||||
wxString wxbuffer;
|
||||
int bufAlloc = 1024;
|
||||
size_t bufAlloc = 1024;
|
||||
wxbuffer.Alloc(bufAlloc);
|
||||
#ifdef TEXT_READER_USE_STDIO
|
||||
char buffer[512];
|
||||
|
@ -199,7 +199,6 @@ wxString TextFileReader::ReadLineFromFile() {
|
|||
char charbuffer[3];
|
||||
charbuffer[2] = 0;
|
||||
wchar_t ch = 0;
|
||||
int n = 0;
|
||||
size_t len = 0;
|
||||
#ifdef TEXT_READER_USE_STDIO
|
||||
while (ch != L'\n' && !feof(file)) {
|
||||
|
|
Loading…
Reference in a new issue