Translation database moved to ZRColaApp
This commit is contained in:
parent
c21e1b8198
commit
ab3ef08a5f
@ -62,6 +62,38 @@ bool ZRColaApp::OnInit()
|
|||||||
wxVERIFY(m_locale.AddCatalog(wxT("ZRCola")));
|
wxVERIFY(m_locale.AddCatalog(wxT("ZRCola")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::fstream dat((LPCTSTR)GetDatabasePath(), std::ios_base::in | std::ios_base::binary);
|
||||||
|
if (dat.good()) {
|
||||||
|
if (stdex::idrec::find<ZRCola::recordid_t, ZRCola::recordsize_t, ZRCOLA_RECORD_ALIGN>(dat, ZRCOLA_DB_ID, sizeof(ZRCola::recordid_t))) {
|
||||||
|
ZRCola::recordsize_t size;
|
||||||
|
dat.read((char*)&size, sizeof(ZRCola::recordsize_t));
|
||||||
|
if (dat.good()) {
|
||||||
|
bool has_translation_data = false;
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
ZRCola::recordid_t id;
|
||||||
|
if (!stdex::idrec::read_id(dat, id, size)) break;
|
||||||
|
|
||||||
|
if (id == ZRCola::translation_rec::id) {
|
||||||
|
dat >> ZRCola::translation_rec(m_t_db);
|
||||||
|
if (dat.good()) {
|
||||||
|
has_translation_data = true;
|
||||||
|
} else {
|
||||||
|
wxFAIL_MSG(wxT("Error reading translation data from ZRCola.zrcdb."));
|
||||||
|
m_t_db.idxComp .clear();
|
||||||
|
m_t_db.idxDecomp.clear();
|
||||||
|
m_t_db.data .clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!has_translation_data)
|
||||||
|
wxFAIL_MSG(wxT("ZRCola.zrcdb has no translation data."));
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
wxFAIL_MSG(wxT("ZRCola.zrcdb is not a valid ZRCola database."));
|
||||||
|
}
|
||||||
|
|
||||||
wxZRColaFrame* mainFrame = new wxZRColaFrame();
|
wxZRColaFrame* mainFrame = new wxZRColaFrame();
|
||||||
wxPersistentRegisterAndRestore<wxTopLevelWindow>(mainFrame);
|
wxPersistentRegisterAndRestore<wxTopLevelWindow>(mainFrame);
|
||||||
mainFrame->Show();
|
mainFrame->Show();
|
||||||
|
@ -28,6 +28,7 @@ class ZRColaApp;
|
|||||||
#include <wx/app.h>
|
#include <wx/app.h>
|
||||||
#include <wx/config.h>
|
#include <wx/config.h>
|
||||||
#include <wx/intl.h>
|
#include <wx/intl.h>
|
||||||
|
#include <zrcola/translate.h>
|
||||||
|
|
||||||
|
|
||||||
///
|
///
|
||||||
@ -54,6 +55,9 @@ public:
|
|||||||
inline wxString GetDatabasePath() const;
|
inline wxString GetDatabasePath() const;
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
ZRCola::translation_db m_t_db; ///< Translation database
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
wxLocale m_locale; ///< Current locale
|
wxLocale m_locale; ///< Current locale
|
||||||
};
|
};
|
||||||
|
@ -30,28 +30,6 @@ wxZRColaComposerPanel::wxZRColaComposerPanel(wxWindow* parent) :
|
|||||||
m_selComposed(0, 0),
|
m_selComposed(0, 0),
|
||||||
wxZRColaComposerPanelBase(parent)
|
wxZRColaComposerPanelBase(parent)
|
||||||
{
|
{
|
||||||
std::fstream dat((LPCTSTR)((ZRColaApp*)wxTheApp)->GetDatabasePath(), std::ios_base::in | std::ios_base::binary);
|
|
||||||
if (dat.good()) {
|
|
||||||
if (stdex::idrec::find<ZRCola::recordid_t, ZRCola::recordsize_t, ZRCOLA_RECORD_ALIGN>(dat, ZRCOLA_DB_ID, sizeof(ZRCola::recordid_t))) {
|
|
||||||
ZRCola::recordsize_t size;
|
|
||||||
dat.read((char*)&size, sizeof(ZRCola::recordsize_t));
|
|
||||||
if (dat.good()) {
|
|
||||||
ZRCola::translation_rec rec(m_t_db);
|
|
||||||
if (rec.find(dat, size)) {
|
|
||||||
dat >> rec;
|
|
||||||
if (!dat.good()) {
|
|
||||||
wxFAIL_MSG(wxT("Error reading translation data from ZRCola.zrcdb."));
|
|
||||||
m_t_db.idxComp .clear();
|
|
||||||
m_t_db.idxDecomp.clear();
|
|
||||||
m_t_db.data .clear();
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
wxFAIL_MSG(wxT("ZRCola.zrcdb has no translation data."));
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
wxFAIL_MSG(wxT("ZRCola.zrcdb is not a valid ZRCola database."));
|
|
||||||
}
|
|
||||||
|
|
||||||
m_decomposed->PushEventHandler(&m_keyhandler);
|
m_decomposed->PushEventHandler(&m_keyhandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +72,7 @@ void wxZRColaComposerPanel::OnDecomposedText(wxCommandEvent& event)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::wstring dst;
|
std::wstring dst;
|
||||||
m_t_db.Compose(src.data(), src.size(), dst, &m_mapping);
|
((ZRColaApp*)wxTheApp)->m_t_db.Compose(src.data(), src.size(), dst, &m_mapping);
|
||||||
|
|
||||||
long from, to;
|
long from, to;
|
||||||
m_decomposed->GetSelection(&from, &to);
|
m_decomposed->GetSelection(&from, &to);
|
||||||
@ -141,7 +119,7 @@ void wxZRColaComposerPanel::OnComposedText(wxCommandEvent& event)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::wstring dst;
|
std::wstring dst;
|
||||||
m_t_db.Decompose(src.data(), src.size(), dst, &m_mapping);
|
((ZRColaApp*)wxTheApp)->m_t_db.Decompose(src.data(), src.size(), dst, &m_mapping);
|
||||||
|
|
||||||
long from, to;
|
long from, to;
|
||||||
m_composed->GetSelection(&from, &to);
|
m_composed->GetSelection(&from, &to);
|
||||||
|
@ -27,7 +27,6 @@ class wxZRColaComposerPanel;
|
|||||||
|
|
||||||
#include "zrcolagui.h"
|
#include "zrcolagui.h"
|
||||||
#include "zrcolakeyhndlr.h"
|
#include "zrcolakeyhndlr.h"
|
||||||
#include <zrcola/translate.h>
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
|
||||||
@ -49,7 +48,6 @@ protected:
|
|||||||
virtual void OnComposedText(wxCommandEvent& event);
|
virtual void OnComposedText(wxCommandEvent& event);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ZRCola::translation_db m_t_db; ///< Translation database
|
|
||||||
bool m_progress; ///< Boolean flag to avoid recursive updates of composed and decomposed text controls
|
bool m_progress; ///< Boolean flag to avoid recursive updates of composed and decomposed text controls
|
||||||
ZRCola::mapping_vector m_mapping; ///< Character index mapping vector between composed and decomposed text
|
ZRCola::mapping_vector m_mapping; ///< Character index mapping vector between composed and decomposed text
|
||||||
std::pair<long, long>
|
std::pair<long, long>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user