]> git.lyx.org Git - lyx.git/blobdiff - src/Thesaurus.cpp
GuiBox.cpp: fix this issue: horizontal box alignment is only possible without inner...
[lyx.git] / src / Thesaurus.cpp
index bca3c069193f0f1e7fbf78a2dff79c524dab91dc..83eed55ea0133963468f4c9c1e4fc68688f2f35e 100644 (file)
@@ -16,6 +16,7 @@
 #include "LyXRC.h"
 
 #include "support/FileNameList.h"
+#include "support/Package.h"
 #include "support/debug.h"
 #include "support/filetools.h"
 #include "support/gettext.h"
@@ -41,7 +42,6 @@ typedef std::map<docstring, MyThes *> Thesauri;
 
 } // namespace anon
 
-
 struct Thesaurus::Private
 {
        ~Private()
@@ -66,54 +66,77 @@ struct Thesaurus::Private
        ///
        typedef std::pair<std::string, std::string> ThesFiles;
        ///
+       ThesFiles getThesaurus(string const & path, docstring const & lang);
        ThesFiles getThesaurus(docstring const & lang);
        /// add a thesaurus to the list
        bool addThesaurus(docstring const & lang);
 
        /// the thesauri
        Thesauri thes_;
+
+       /// the location below system/user directory
+       /// there the data+idx files lookup will happen
+       const string dataDirectory(void) { return "thes"; }
+
 };
 
 
-pair<string, string> Thesaurus::Private::getThesaurus(docstring const & lang)
+pair<string,string> Thesaurus::Private::getThesaurus(string const & path, docstring const & lang)
 {
-       string const thes_path = external_path(lyxrc.thesaurusdir_path);
-       LYXERR(Debug::FILES, "thesaurus path: " << thes_path);
-       if (thes_path.empty())
-               return make_pair(string(), string());
-
-       if (thesaurusAvailable(lang))
+       FileName base(path);
+       if (!base.isDirectory()) {
                return make_pair(string(), string());
-
-       FileNameList const idx_files = FileName(thes_path).dirList("idx");
-       FileNameList const data_files = FileName(thes_path).dirList("dat");
+       }
+       FileNameList const idx_files = base.dirList("idx");
+       FileNameList const data_files = base.dirList("dat");
        string idx;
        string data;
 
-       for (FileNameList::const_iterator it = idx_files.begin();
-            it != idx_files.end(); ++it) {
-               LYXERR(Debug::FILES, "found thesaurus idx file: " << it->onlyFileName());
+       LYXERR(Debug::FILES, "thesaurus path: " << path);
+       for (FileNameList::const_iterator it = idx_files.begin(); it != idx_files.end(); ++it) {
                if (contains(it->onlyFileName(), to_ascii(lang))) {
-                       idx = it->absFilename();
+                       idx = it->absFileName();
                        LYXERR(Debug::FILES, "selected thesaurus idx file: " << idx);
                        break;
-                       }
                }
-
-       for (support::FileNameList::const_iterator it = data_files.begin();
-            it != data_files.end(); ++it) {
-               LYXERR(Debug::FILES, "found thesaurus data file: " << it->onlyFileName());
+       }
+       if (idx.empty()) {
+               return make_pair(string(), string());
+       }
+       for (support::FileNameList::const_iterator it = data_files.begin(); it != data_files.end(); ++it) {
                if (contains(it->onlyFileName(), to_ascii(lang))) {
-                       data = it->absFilename();
+                       data = it->absFileName();
                        LYXERR(Debug::FILES, "selected thesaurus data file: " << data);
                        break;
-                       }
                }
-
+       }
        return make_pair(idx, data);
 }
 
 
+pair<string,string> Thesaurus::Private::getThesaurus(docstring const & lang)
+{
+       string const thes_path = external_path(lyxrc.thesaurusdir_path);
+       pair<string,string> result ;
+
+       if (thesaurusAvailable(lang))
+               return make_pair(string(), string());
+
+       if (!thes_path.empty()) {
+               result = getThesaurus(thes_path, lang);
+       }
+       if (result.first.empty() || result.second.empty()) {
+               string const sys_path = external_path(addName(lyx::support::package().system_support().absFileName(),dataDirectory())) ;
+               result = getThesaurus(sys_path, lang);
+       }
+       if (result.first.empty() || result.second.empty()) {
+               string const user_path = external_path(addName(lyx::support::package().user_support().absFileName(),dataDirectory())) ;
+               result = getThesaurus(user_path, lang);
+       }
+       return result;
+}
+
+
 bool Thesaurus::Private::addThesaurus(docstring const & lang)
 {
        if (thesaurusAvailable(lang))