From 0891571fb3411f59f455b48a63954208f5caa2c8 Mon Sep 17 00:00:00 2001 From: Fred Kruse Date: Sat, 30 Dec 2023 14:05:44 +0100 Subject: [PATCH] [LO extension] toolbars for Impress and Calc added again / update of toolbar / problems with check dialog solved --- .../org/languagetool/openoffice/LtMenus.java | 23 +++-- .../languagetool/openoffice/LtToolbar.java | 11 ++- .../openoffice/MultiDocumentsHandler.java | 5 +- .../openoffice/SingleDocument.java | 12 ++- .../SpellAndGrammarCheckDialog.java | 12 +-- .../src/main/resources/Addons.xcu | 88 +++++++++---------- 6 files changed, 89 insertions(+), 62 deletions(-) diff --git a/languagetool-office-extension/src/main/java/org/languagetool/openoffice/LtMenus.java b/languagetool-office-extension/src/main/java/org/languagetool/openoffice/LtMenus.java index ee183507c918..8a0b8481ef32 100644 --- a/languagetool-office-extension/src/main/java/org/languagetool/openoffice/LtMenus.java +++ b/languagetool-office-extension/src/main/java/org/languagetool/openoffice/LtMenus.java @@ -79,8 +79,8 @@ public class LtMenus { public static final String LT_STATISTICAL_ANALYSES_COMMAND = "service:org.languagetool.openoffice.Main?statisticalAnalyses"; public static final String LT_RESET_IGNORE_PERMANENT_COMMAND = "service:org.languagetool.openoffice.Main?resetIgnorePermanent"; public static final String LT_TOGGLE_BACKGROUND_CHECK_COMMAND = "service:org.languagetool.openoffice.Main?toggleNoBackgroundCheck"; - public static final String LT_BACKGROUND_CHECK_ON_COMMAND = "service:org.languagetool.openoffice.Main?BackgroundCheckOn"; - public static final String LT_BACKGROUND_CHECK_OFF_COMMAND = "service:org.languagetool.openoffice.Main?BackgroundCheckOff"; + public static final String LT_BACKGROUND_CHECK_ON_COMMAND = "service:org.languagetool.openoffice.Main?backgroundCheckOn"; + public static final String LT_BACKGROUND_CHECK_OFF_COMMAND = "service:org.languagetool.openoffice.Main?backgroundCheckOff"; public static final String LT_REFRESH_CHECK_COMMAND = "service:org.languagetool.openoffice.Main?refreshCheck"; public static final String LT_ABOUT_COMMAND = "service:org.languagetool.openoffice.Main?about"; public static final String LT_LANGUAGETOOL_COMMAND = "service:org.languagetool.openoffice.Main?lt"; @@ -104,10 +104,6 @@ public class LtMenus { private final static String ADD_TO_DICTIONARY_3 = "slot:3"; private final static String SPEll_DIALOG_URL = "slot:4"; - private final boolean hasStatisticalStyleRules; - - - private static boolean debugMode; // should be false except for testing private static boolean debugModeTm; // should be false except for testing private static boolean isRunning = false; @@ -127,7 +123,6 @@ public class LtMenus { this.document = document; this.xContext = xContext; this.xComponent = document.getXComponent(); - hasStatisticalStyleRules = OfficeTools.hasStatisticalStyleRules(document.getLanguage()); setConfigValues(config); if (document.getDocumentType() == DocumentType.WRITER) { ltHeadMenu = new LTHeadMenu(xComponent); @@ -214,6 +209,13 @@ public LTHeadMenu(XComponent xComponent) { MessageHandler.printToLogFile("LanguageToolMenus: LTHeadMenu: switchOffId not found"); return; } + boolean hasStatisticalStyleRules; + if (document.getDocumentType() == DocumentType.WRITER && + !document.getMultiDocumentsHandler().isBackgroundCheckOff()) { + hasStatisticalStyleRules = OfficeTools.hasStatisticalStyleRules(document.getLanguage()); + } else { + hasStatisticalStyleRules = false; + } if (hasStatisticalStyleRules) { ltMenu.insertItem((short)(switchOffId + 1), MESSAGES.getString("loStatisticalAnalysis") + " ...", (short)0, switchOffPos); @@ -706,6 +708,13 @@ private void addLTMenuEntry(int nId, XIndexContainer xContextMenu, XMultiService boolean showAll) throws Exception { XIndexContainer xSubMenuContainer = (XIndexContainer)UnoRuntime.queryInterface(XIndexContainer.class, xMenuElementFactory.createInstance("com.sun.star.ui.ActionTriggerContainer")); + boolean hasStatisticalStyleRules; + if (document.getDocumentType() == DocumentType.WRITER && + !document.getMultiDocumentsHandler().isBackgroundCheckOff()) { + hasStatisticalStyleRules = OfficeTools.hasStatisticalStyleRules(document.getLanguage()); + } else { + hasStatisticalStyleRules = false; + } XPropertySet xNewSubMenuEntry; int j = 0; if (showAll) { diff --git a/languagetool-office-extension/src/main/java/org/languagetool/openoffice/LtToolbar.java b/languagetool-office-extension/src/main/java/org/languagetool/openoffice/LtToolbar.java index f055895b39c9..6ff1e68a6539 100644 --- a/languagetool-office-extension/src/main/java/org/languagetool/openoffice/LtToolbar.java +++ b/languagetool-office-extension/src/main/java/org/languagetool/openoffice/LtToolbar.java @@ -58,18 +58,16 @@ public class LtToolbar { private static final ResourceBundle MESSAGES = JLanguageTool.getMessageBundle(); private static final String WRITER_SERVICE = "com.sun.star.text.TextDocument"; private static final String LT_TOOLBAR_URL = "private:resource/toolbar/org.languagetool.openoffice.Main.toolbar"; - private final boolean hasStatisticalStyleRules; private XComponentContext xContext; private SingleDocument document; LtToolbar(XComponentContext xContext, SingleDocument document) { this.xContext = xContext; this.document = document; - hasStatisticalStyleRules = OfficeTools.hasStatisticalStyleRules(document.getLanguage()); makeToolbar(); } - private void makeToolbar() { + public void makeToolbar() { try { Configuration config = document.getMultiDocumentsHandler().getConfiguration(); XUIConfigurationManager confMan = getUIConfigManagerDoc(xContext); @@ -81,6 +79,13 @@ private void makeToolbar() { String toolbarName = LT_TOOLBAR_URL; XIndexContainer elementsContainer = confMan.createSettings(); + + boolean hasStatisticalStyleRules; + if (document.getMultiDocumentsHandler().isBackgroundCheckOff()) { + hasStatisticalStyleRules = false; + } else { + hasStatisticalStyleRules = OfficeTools.hasStatisticalStyleRules(document.getLanguage()); + } int j = 0; PropertyValue[] itemProps = makeBarItem(LtMenus.LT_NEXT_ERROR_COMMAND, MESSAGES.getString("loMenuNextError")); diff --git a/languagetool-office-extension/src/main/java/org/languagetool/openoffice/MultiDocumentsHandler.java b/languagetool-office-extension/src/main/java/org/languagetool/openoffice/MultiDocumentsHandler.java index e4715f61c48f..073a785a59ad 100644 --- a/languagetool-office-extension/src/main/java/org/languagetool/openoffice/MultiDocumentsHandler.java +++ b/languagetool-office-extension/src/main/java/org/languagetool/openoffice/MultiDocumentsHandler.java @@ -1633,9 +1633,10 @@ public void trigger(String sEvent) { } AboutDialogThread aboutThread = new AboutDialogThread(messages, xContext); aboutThread.start(); - } else if ("toggleNoBackgroundCheck".equals(sEvent) || "BackgroundCheckOn".equals(sEvent) || "BackgroundCheckOff".equals(sEvent)) { + } else if ("toggleNoBackgroundCheck".equals(sEvent) || "backgroundCheckOn".equals(sEvent) || "backgroundCheckOff".equals(sEvent)) { if (toggleNoBackgroundCheck()) { - resetCheck(); + resetCheck(); + getCurrentDocument().getLtToolbar().makeToolbar(); } } else if ("ignoreOnce".equals(sEvent)) { ignoreOnce(); diff --git a/languagetool-office-extension/src/main/java/org/languagetool/openoffice/SingleDocument.java b/languagetool-office-extension/src/main/java/org/languagetool/openoffice/SingleDocument.java index 0febad8cb88a..97d8e0a30849 100644 --- a/languagetool-office-extension/src/main/java/org/languagetool/openoffice/SingleDocument.java +++ b/languagetool-office-extension/src/main/java/org/languagetool/openoffice/SingleDocument.java @@ -165,8 +165,12 @@ public class SingleDocument { if (xComponent != null) { setFlatParagraphTools(); } - if (!mDocHandler.isOpenOffice && docType == DocumentType.IMPRESS && ltMenus == null) { + if (!mDocHandler.isOpenOffice && (docType == DocumentType.IMPRESS + || (mDH.isBackgroundCheckOff() && docType == DocumentType.WRITER)) && ltMenus == null) { ltMenus = new LtMenus(xContext, this, config); + if (docType == DocumentType.WRITER) { + ltToolbar = new LtToolbar(xContext, this); + } } } @@ -444,6 +448,12 @@ LtMenus getLtMenu() { return ltMenus; } + /** Get LanguageTool toolbar + */ + LtToolbar getLtToolbar() { + return ltToolbar; + } + /** * set menu ID to MultiDocumentsHandler */ diff --git a/languagetool-office-extension/src/main/java/org/languagetool/openoffice/SpellAndGrammarCheckDialog.java b/languagetool-office-extension/src/main/java/org/languagetool/openoffice/SpellAndGrammarCheckDialog.java index fc10d72cedc0..32a630f1189c 100644 --- a/languagetool-office-extension/src/main/java/org/languagetool/openoffice/SpellAndGrammarCheckDialog.java +++ b/languagetool-office-extension/src/main/java/org/languagetool/openoffice/SpellAndGrammarCheckDialog.java @@ -260,7 +260,7 @@ public void run() { * Actualize impress/calc document cache */ private void actualizeNonWriterDocumentCache(SingleDocument document) { - if (docType != DocumentType.WRITER) { + if (docType != DocumentType.WRITER || documents.isBackgroundCheckOff()) { DocumentCache oldCache = new DocumentCache(docCache); docCache.refresh(document, null, null, document.getXComponent(), 7); if (!oldCache.isEmpty()) { @@ -308,7 +308,7 @@ private SingleDocument getCurrentDocument(boolean actualize) { if (currentDocument != null) { docType = currentDocument.getDocumentType(); docCache = currentDocument.getDocumentCache(); - if (docType != DocumentType.WRITER) { + if (docType != DocumentType.WRITER || documents.isBackgroundCheckOff()) { actualizeNonWriterDocumentCache(currentDocument); } } @@ -648,9 +648,11 @@ SingleProofreadingError getNextGrammatikOrSpellErrorInParagraph(int x, int nFPar suggestionList.add(suggestion); } String[] suggestions = documents.getLinguisticServices().getSpellAlternatives(text, locale); - for (String suggestion : suggestions) { - if (!suggestionList.contains(suggestion)) { - suggestionList.add(suggestion); + if (suggestions != null) { + for (String suggestion : suggestions) { + if (!suggestionList.contains(suggestion)) { + suggestionList.add(suggestion); + } } } error.aSuggestions = suggestionList.toArray(new String[0]); diff --git a/languagetool-office-extension/src/main/resources/Addons.xcu b/languagetool-office-extension/src/main/resources/Addons.xcu index 55ae248579ff..554966bd0d94 100644 --- a/languagetool-office-extension/src/main/resources/Addons.xcu +++ b/languagetool-office-extension/src/main/resources/Addons.xcu @@ -121,7 +121,7 @@ - service:org.languagetool.openoffice.Main?BackgroundCheckOff + service:org.languagetool.openoffice.Main?backgroundCheckOff @@ -134,7 +134,7 @@ - service:org.languagetool.openoffice.Main?BackgroundCheckOn + service:org.languagetool.openoffice.Main?backgroundCheckOn @@ -172,28 +172,8 @@ - --->