Patch #3316 2012-08-16 17:26

alpha0010

SpellChecker: search harder for resources
Download
3316-SpellChecker_s.patch (12.3 KB)
Category
Plugin::Refinement
Status
Accepted
Close date
2012-08-21 04:39
Assigned to
mortenmacfly
Index: src/plugins/contrib/SpellChecker/Thesaurus.cpp
===================================================================
--- src/plugins/contrib/SpellChecker/Thesaurus.cpp    (revision 8236)
+++ src/plugins/contrib/SpellChecker/Thesaurus.cpp    (working copy)
@@ -56,7 +56,48 @@
         m_pT = new wxThes( idxpath, datpath );
     }
     else
+    {
         Manager::Get()->GetLogManager()->Log(_T("SpellChecker: Thesaurus files '") + idxpath + _T("' not found!"));
+        wxString altIdx = wxFindFirstFile(idxpath.BeforeLast(wxT('.')) + wxT("*.idx"), wxFILE); // "*_v2.idx"
+        if (altIdx.IsEmpty()) // try again with more wildcards
+        {
+            altIdx = idxpath.AfterLast(wxFILE_SEP_PATH).BeforeLast(wxT('.')) + wxT("*.idx");
+            altIdx.Replace(wxT("_"), wxT("*"));
+            altIdx.Replace(wxT("-"), wxT("*"));
+            altIdx = wxFindFirstFile(idxpath.BeforeLast(wxFILE_SEP_PATH) + wxFILE_SEP_PATH + altIdx, wxFILE);
+        }
+        if (altIdx.IsEmpty()) // try to find the thesaurus of a related language (something is better than nothing)
+        {
+            altIdx = idxpath.AfterLast(wxFILE_SEP_PATH);
+            altIdx.Replace(wxT("_"), wxT("*"));
+            altIdx.Replace(wxT("-"), wxT("*"));
+            altIdx = altIdx.BeforeLast(wxT('*')) + wxT("*.idx");
+            altIdx = wxFindFirstFile(idxpath.BeforeLast(wxFILE_SEP_PATH) + wxFILE_SEP_PATH + altIdx, wxFILE);
+        }
+
+        wxString altDat = wxFindFirstFile(datpath.BeforeLast(wxT('.')) + wxT("*.dat"), wxFILE); // "*_v2.dat"
+        if (altDat.IsEmpty()) // try again with more wildcards
+        {
+            altDat = datpath.AfterLast(wxFILE_SEP_PATH).BeforeLast(wxT('.')) + wxT("*.dat");
+            altDat.Replace(wxT("_"), wxT("*"));
+            altDat.Replace(wxT("-"), wxT("*"));
+            altDat = wxFindFirstFile(datpath.BeforeLast(wxFILE_SEP_PATH) + wxFILE_SEP_PATH + altDat, wxFILE);
+        }
+        if (altDat.IsEmpty()) // try to find the thesaurus of a related language (something is better than nothing)
+        {
+            altDat = datpath.AfterLast(wxFILE_SEP_PATH);
+            altDat.Replace(wxT("_"), wxT("*"));
+            altDat.Replace(wxT("-"), wxT("*"));
+            altDat = altDat.BeforeLast(wxT('*')) + wxT("*.dat");
+            altDat = wxFindFirstFile(datpath.BeforeLast(wxFILE_SEP_PATH) + wxFILE_SEP_PATH + altDat, wxFILE);
+        }
+
+        if (!altIdx.IsEmpty() && !altDat.IsEmpty() && wxFileExists(altIdx) && wxFileExists(altDat))
+        {
+            m_pT = new  wxThes(altIdx, altDat);
+            Manager::Get()->GetLogManager()->Log(wxT("SpellChecker: Loading '") + altIdx + wxT("' instead..."));
+        }
+    }
 }
 
 
Index: src/plugins/contrib/SpellChecker/StatusField.cpp
===================================================================
--- src/plugins/contrib/SpellChecker/StatusField.cpp    (revision 8236)
+++ src/plugins/contrib/SpellChecker/StatusField.cpp    (working copy)
@@ -26,7 +26,10 @@
     //ctor
     m_text = new wxStaticText(this, wxID_ANY, m_sccfg->GetDictionaryName());
 
-    wxBitmap bm(wxImage( m_sccfg->GetBitmapPath() + wxFILE_SEP_PATH + m_sccfg->GetDictionaryName() + _T(".png"), wxBITMAP_TYPE_PNG ));
+    wxString name = m_sccfg->GetDictionaryName();
+    if (!wxFileExists(m_sccfg->GetBitmapPath() + wxFILE_SEP_PATH + name + _T(".png")))
+        name.Replace(wxT("-"), wxT("_")); // some dictionaries are distributed with hyphens
+    wxBitmap bm(wxImage( m_sccfg->GetBitmapPath() + wxFILE_SEP_PATH + name + _T(".png"), wxBITMAP_TYPE_PNG ));
     m_bitmap = new wxStaticBitmap(this, wxID_ANY, bm);
 
     if ( bm.IsOk() )
@@ -41,6 +44,9 @@
     m_text->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(SpellCheckerStatusField::OnRightUp), NULL, this);
     m_bitmap->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(SpellCheckerStatusField::OnRightUp), NULL, this);
     Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(SpellCheckerStatusField::OnRightUp), NULL, this);
+    m_text->Connect(wxEVT_LEFT_DCLICK, wxMouseEventHandler(SpellCheckerStatusField::OnRightUp), NULL, this);
+    m_bitmap->Connect(wxEVT_LEFT_DCLICK, wxMouseEventHandler(SpellCheckerStatusField::OnRightUp), NULL, this);
+    Connect(wxEVT_LEFT_DCLICK, wxMouseEventHandler(SpellCheckerStatusField::OnRightUp), NULL, this);
 }
 
 SpellCheckerStatusField::~SpellCheckerStatusField()
@@ -58,7 +64,10 @@
 void SpellCheckerStatusField::Update()
 {
     m_text->SetLabel(m_sccfg->GetDictionaryName() );
-    wxBitmap bm(wxImage( m_sccfg->GetBitmapPath() + wxFILE_SEP_PATH + m_sccfg->GetDictionaryName()  + _T(".png"), wxBITMAP_TYPE_PNG ));
+    wxString name = m_sccfg->GetDictionaryName();
+    if (!wxFileExists(m_sccfg->GetBitmapPath() + wxFILE_SEP_PATH + name + _T(".png")))
+        name.Replace(wxT("-"), wxT("_")); // some dictionaries are distributed with hyphens
+    wxBitmap bm(wxImage( m_sccfg->GetBitmapPath() + wxFILE_SEP_PATH + name + _T(".png"), wxBITMAP_TYPE_PNG ));
     if ( bm.IsOk() )
     {
download for full patch...
alpha0010 2012-08-16 17:26

Also include Linux build fix.