]> git.lyx.org Git - features.git/blobdiff - src/PersonalWordList.cpp
Allow removing words from the personal dictionary, that weren't previously added.
[features.git] / src / PersonalWordList.cpp
index 5e32e204f99fe35ba8c58160acf9c515a63c7f90..5a34a28e832dabaddab0e1067565ef83fe9edce5 100644 (file)
 #include "support/filetools.h"
 #include "support/Package.h"
 #include "support/FileName.h"
-#include "support/lstrings.h"
-#include "support/os.h"
 
 #include <string>
 #include <fstream>
 
 using namespace std;
 using namespace lyx::support;
-using namespace lyx::support::os;
 
 namespace lyx {
 
-FileName PersonalWordList::dictfile() const
+FileName PersonalWordListPart::dictfile() const
 {
-       string fname = "pwl_" + lang_ + ".dict";
+       string fext = is_includes_ ? ".dict" : ".excl";
+       string fname = "pwl_" + lang_ + fext;
        return FileName(addName(package().user_support().absFileName(),fname));
 }
 
 
-docstring_list::const_iterator PersonalWordList::begin() const
+docstring_list::const_iterator PersonalWordListPart::begin() const
 {
        return words_.begin();
 }
 
 
-docstring_list::const_iterator PersonalWordList::end() const
+docstring_list::const_iterator PersonalWordListPart::end() const
 {
        return words_.end();
 }
 
 
-void PersonalWordList::load()
+void PersonalWordListPart::load()
 {
        FileName fn = dictfile();
        LYXERR(Debug::FILES, "load personal dictionary from: " << fn);
        ifstream ifs(fn.toFilesystemEncoding().c_str());
 
-       dirty(words_.size() > 0);
+       dirty(!words_.empty());
        words_.clear();
        string line;
        getline(ifs, line);
        if (line == header()) {
                while (ifs) {
                        getline(ifs, line);
-                       if (!line.empty()) {
+                       if (!line.empty() && !(line[0] == '#')) {
                                docstring const word = from_utf8(line);
                                insert(word);
                        }
@@ -75,7 +73,7 @@ void PersonalWordList::load()
 }
 
 
-void PersonalWordList::save()
+void PersonalWordListPart::save()
 {
        if (!isDirty())
                return;
@@ -92,13 +90,14 @@ void PersonalWordList::save()
        LYXERR(Debug::FILES, "count of saved items: " << words_.size());
 }
 
-bool PersonalWordList::equalwords(docstring const & w1, docstring const & w2) const
+
+bool PersonalWordListPart::equalwords(docstring const & w1, docstring const & w2) const
 {
        return w1 == w2;
 }
 
 
-bool PersonalWordList::exists(docstring const & word) const
+bool PersonalWordListPart::exists(docstring const & word) const
 {
        docstring_list::const_iterator it = words_.begin();
        docstring_list::const_iterator et = words_.end();
@@ -110,7 +109,7 @@ bool PersonalWordList::exists(docstring const & word) const
 }
 
 
-void PersonalWordList::insert(docstring const & word)
+void PersonalWordListPart::insert(docstring const & word)
 {
        if (exists(word))
                return;
@@ -119,7 +118,7 @@ void PersonalWordList::insert(docstring const & word)
 }
 
 
-void PersonalWordList::remove(docstring const & word)
+void PersonalWordListPart::remove(docstring const & word)
 {
        docstring_list::iterator it = words_.begin();
        docstring_list::const_iterator et = words_.end();