Skip to content

Commit

Permalink
change to new dictionary when switching projects
Browse files Browse the repository at this point in the history
  • Loading branch information
trungtq committed Oct 4, 2015
1 parent 1218a3a commit 0fad245
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
20 changes: 20 additions & 0 deletions source/net/sourceforge/texlipse/spelling/TexSpellDictionary.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class TexSpellDictionary extends SpellDictionaryASpell {
* User dictionary
*/
private File dictFile = null;
private String dictFilePath = null;


/**
Expand Down Expand Up @@ -92,13 +93,32 @@ public void addDictionary(File wordList) throws FileNotFoundException, IOExcepti
*/
public void setUserDict(File userDict) {
dictFile = userDict;
dictFilePath = userDict.getAbsolutePath();
try {
addDictionary(userDict);
} catch (IOException e) {
//Do nothing
}
}

/**
* Set the user dictionary file
* @param userDict
*/
public void setUserDict(String userDictPath) {
try {
dictFile = new File (userDictPath);
dictFilePath = userDictPath;
addDictionary(dictFile);
} catch (IOException e) {
//Do nothing
}
}

public String getUserDictPath() {
return dictFilePath;
}

/**
* Add a word permanently to the dictionary (and the dictionary file).
* <p>This needs to be made thread safe (synchronized)</p>
Expand Down
21 changes: 12 additions & 9 deletions source/net/sourceforge/texlipse/spelling/TexSpellingEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,17 @@ public int getLength() {
private static SpellChecker getSpellChecker(String lang) {
//Return null, when no language is set
if (lang == null) return null;

// if the customDictPath isn't set, then use the current project path
String customDictPath = TexlipsePlugin.getPreference(TexlipseProperties.SPELLCHECKER_CUSTOM_DICT_DIR);
if ((customDictPath == null) || (customDictPath.trim().isEmpty()))
customDictPath = TexlipsePlugin.getCurrentProject().getLocation().toOSString();
String customDictFilePath = customDictPath + File.separator + lang + "_user.dict";

// return the current spellChecker if the default dict and custom dict unchanged
if ((lang.equals(currentLang)) && (dict.getUserDictPath().equals(customDictFilePath)))
return spellCheck;

if (lang.equals(currentLang)) return spellCheck;

//Get dictionary path from preferences and check if it exists
String dictPathSt = TexlipsePlugin.getPreference(TexlipseProperties.SPELLCHECKER_DICT_DIR);
if (dictPathSt == null || "".equals(dictPathSt.trim())) return null;
Expand All @@ -160,18 +168,13 @@ private static SpellChecker getSpellChecker(String lang) {
spellCheck = null;
dict = null;
currentLang = lang;

try {
FileInputStream input = new FileInputStream(f);
Reader r = new BufferedReader(new InputStreamReader(input, "UTF-8"));
dict = new TexSpellDictionary(r);
r.close();

String customDictPath = TexlipsePlugin.getPreference(TexlipseProperties.SPELLCHECKER_CUSTOM_DICT_DIR);
// if the customDictPath isn't set, then use the current project path
if ((customDictPath == null) || (customDictPath.trim().isEmpty()))
customDictPath = TexlipsePlugin.getCurrentProject().getLocation().toOSString();
dict.setUserDict(new File (customDictPath + File.separator + lang + "_user.dict"));
dict.setUserDict(customDictFilePath);
spellCheck = new SpellChecker(dict);
return spellCheck;
} catch (IOException e) {
Expand Down

0 comments on commit 0fad245

Please sign in to comment.