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")));
|
||||
}
|
||||
|
||||
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();
|
||||
wxPersistentRegisterAndRestore<wxTopLevelWindow>(mainFrame);
|
||||
mainFrame->Show();
|
||||
|
@ -28,6 +28,7 @@ class ZRColaApp;
|
||||
#include <wx/app.h>
|
||||
#include <wx/config.h>
|
||||
#include <wx/intl.h>
|
||||
#include <zrcola/translate.h>
|
||||
|
||||
|
||||
///
|
||||
@ -54,6 +55,9 @@ public:
|
||||
inline wxString GetDatabasePath() const;
|
||||
|
||||
|
||||
public:
|
||||
ZRCola::translation_db m_t_db; ///< Translation database
|
||||
|
||||
protected:
|
||||
wxLocale m_locale; ///< Current locale
|
||||
};
|
||||
|
@ -30,28 +30,6 @@ wxZRColaComposerPanel::wxZRColaComposerPanel(wxWindow* parent) :
|
||||
m_selComposed(0, 0),
|
||||
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);
|
||||
}
|
||||
|
||||
@ -94,7 +72,7 @@ void wxZRColaComposerPanel::OnDecomposedText(wxCommandEvent& event)
|
||||
#endif
|
||||
|
||||
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;
|
||||
m_decomposed->GetSelection(&from, &to);
|
||||
@ -141,7 +119,7 @@ void wxZRColaComposerPanel::OnComposedText(wxCommandEvent& event)
|
||||
#endif
|
||||
|
||||
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;
|
||||
m_composed->GetSelection(&from, &to);
|
||||
|
@ -27,7 +27,6 @@ class wxZRColaComposerPanel;
|
||||
|
||||
#include "zrcolagui.h"
|
||||
#include "zrcolakeyhndlr.h"
|
||||
#include <zrcola/translate.h>
|
||||
#include <utility>
|
||||
|
||||
|
||||
@ -49,7 +48,6 @@ protected:
|
||||
virtual void OnComposedText(wxCommandEvent& event);
|
||||
|
||||
protected:
|
||||
ZRCola::translation_db m_t_db; ///< Translation database
|
||||
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
|
||||
std::pair<long, long>
|
||||
|
Loading…
x
Reference in New Issue
Block a user