Skip to content

Commit

Permalink
[LO extension] another optimization of communication between LO and e…
Browse files Browse the repository at this point in the history
…xtension
  • Loading branch information
FredKruse committed Mar 10, 2023
1 parent df91ade commit 258a0f4
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,35 @@ public class LtDictionary {

private static Set<String> dictionaryList = new HashSet<>();
private static String listIgnoredWords = null;
private static boolean isDisposed = false;

/**
* Add a non permanent dictionary to LO/OO that contains additional words defined in LT
*/
public static void setDisposed() {
isDisposed = true;
}

/**
* Add a non permanent dictionary to LO/OO that contains additional words defined in LT
*/
public static boolean setLtDictionary(XComponentContext xContext, Locale locale, LinguisticServices linguServices) {
boolean debugMode = OfficeTools.DEBUG_MODE_LD;
if (isDisposed) {
return false;
}
XSearchableDictionaryList searchableDictionaryList = OfficeTools.getSearchableDictionaryList(xContext);
if (searchableDictionaryList == null) {
MessageHandler.printToLogFile("LtDictionary: setLtDictionary: searchableDictionaryList == null");
return false;
}
if (listIgnoredWords == null) {
if (listIgnoredWords == null && !isDisposed) {
setListIgnoredWords(searchableDictionaryList.getDictionaries());
}
String shortCode = OfficeTools.localeToString(locale);
String dictionaryNamePrefix = INTERNAL_DICT_PREFIX + shortCode + "_internal";
String dictionaryName = dictionaryNamePrefix + "1" + DICT_FILE_POSTFIX;
if (!dictionaryList.contains(dictionaryName) && searchableDictionaryList.getDictionaryByName(dictionaryName) == null) {
if (!isDisposed && !dictionaryList.contains(dictionaryName) && searchableDictionaryList.getDictionaryByName(dictionaryName) == null) {
dictionaryList.add(dictionaryName);
String ltDictionaryPath = getLTDictionaryFile(locale, linguServices);
if (ltDictionaryPath != null) {
Expand All @@ -91,6 +102,9 @@ public static boolean setLtDictionary(XComponentContext xContext, Locale locale,
int count = 0;
int dictNum = 1;
int dictCount = 0;
if (isDisposed) {
return false;
}
XDictionary manualDictionary = searchableDictionaryList.createDictionary(dictionaryName, locale, DictionaryType.POSITIVE, "");
if (debugMode) {
MessageHandler.printToLogFile("Add " + words.size() + " words to " + dictionaryName);
Expand All @@ -104,11 +118,17 @@ public static boolean setLtDictionary(XComponentContext xContext, Locale locale,
dictCount += manualDictionary.getCount();
dictNum++;
dictionaryName = dictionaryNamePrefix + dictNum + DICT_FILE_POSTFIX;
if (isDisposed) {
return false;
}
manualDictionary = searchableDictionaryList.createDictionary(dictionaryName, locale, DictionaryType.POSITIVE, "");
count = 0;
}
}
manualDictionary.setActive(true);
if (isDisposed) {
return false;
}
searchableDictionaryList.addDictionary(manualDictionary);
dictCount += manualDictionary.getCount();
long endTime = System.currentTimeMillis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ public class MultiDocumentsHandler {
private int heapCheckInterval = HEAP_CHECK_INTERVAL;
private boolean testMode = false;
private boolean javaLookAndFeelIsSet = false;
private boolean isHelperDisposed = false;



MultiDocumentsHandler(XComponentContext xContext, XProofreader xProofreader, XEventListener xEventListener) {
Expand Down Expand Up @@ -403,6 +405,14 @@ private void setContextOfClosedDoc(XComponent xComponent) {
found = true;
document.dispose(true);
isDisposed = true;
if (documents.size() < 2) {
LtDictionary.setDisposed();
if (textLevelQueue != null) {
textLevelQueue.setStop();
textLevelQueue = null;
}
isHelperDisposed = true;
}
/* save only if document is saved
if (config.saveLoCache()) {
document.writeCaches();
Expand Down Expand Up @@ -1973,12 +1983,16 @@ public boolean isRunning() {
/** class to start a separate thread to check for Impress documents
*/
private class LtHelper extends Thread {

@Override
public void run() {
try {
SingleDocument currentDocument = null;
while (currentDocument == null) {
Thread.sleep(1000);
while (!isHelperDisposed && currentDocument == null) {
Thread.sleep(250);
if (isHelperDisposed) {
return;
}
currentDocument = getCurrentDocument();
if (currentDocument != null && currentDocument.getDocumentType() == DocumentType.IMPRESS) {
checkImpressDocument = true;
Expand All @@ -1995,6 +2009,7 @@ public void run() {
MessageHandler.showError(e);
}
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public void setStop() {
if (debugMode) {
MessageHandler.printToLogFile("TextLevelCheckQueue: setStop: stop queue");
}
textRuleQueue.add(queueEntry);
textRuleQueue.add(0, queueEntry);
}
wakeupQueue();
}
Expand Down

0 comments on commit 258a0f4

Please sign in to comment.