Skip to content

Commit

Permalink
[LO extension] toolbars for Impress and Calc added again / update of …
Browse files Browse the repository at this point in the history
…toolbar / problems with check dialog solved
  • Loading branch information
FredKruse committed Dec 30, 2023
1 parent dea64f1 commit 0891571
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down Expand Up @@ -444,6 +448,12 @@ LtMenus getLtMenu() {
return ltMenus;
}

/** Get LanguageTool toolbar
*/
LtToolbar getLtToolbar() {
return ltToolbar;
}

/**
* set menu ID to MultiDocumentsHandler
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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]);
Expand Down
88 changes: 44 additions & 44 deletions languagetool-office-extension/src/main/resources/Addons.xcu
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
</node>
<node oor:name="org.languagetool.openoffice.Main.imageLtBackCheckOff" oor:op="replace">
<prop oor:name="URL" oor:type="xs:string">
<value>service:org.languagetool.openoffice.Main?BackgroundCheckOff</value>
<value>service:org.languagetool.openoffice.Main?backgroundCheckOff</value>
</prop>
<node oor:name="UserDefinedImages">
<prop oor:name="ImageSmallURL">
Expand All @@ -134,7 +134,7 @@
</node>
<node oor:name="org.languagetool.openoffice.Main.imageLtBackCheckOn" oor:op="replace">
<prop oor:name="URL" oor:type="xs:string">
<value>service:org.languagetool.openoffice.Main?BackgroundCheckOn</value>
<value>service:org.languagetool.openoffice.Main?backgroundCheckOn</value>
</prop>
<node oor:name="UserDefinedImages">
<prop oor:name="ImageSmallURL">
Expand Down Expand Up @@ -172,28 +172,8 @@
</node>
</node>
</node>
<!--
<node oor:name="OfficeToolBar">
<node oor:name="org.languagetool.openoffice.Main.toolbar" oor:op="replace">
<node oor:name="T1" oor:op="replace">
<prop oor:name="URL" oor:type="xs:string">
<value>service:org.languagetool.openoffice.Main?nextError</value>
</prop>
<prop oor:name="Target" oor:type="xs:string">
<value>_self</value>
</prop>
<prop oor:name="Context" oor:type="xs:string">
<value>com.sun.star.text.TextDocument</value>
</prop>
<prop oor:name="Title" oor:type="xs:string">
<value xml:lang="en-US">Next spelling or grammar mistake</value>
<value xml:lang="de">Nächster Rechtschreib- oder Grammatikfehler</value>
<value xml:lang="gl">Erro ortográfico ou gramatical seguinte</value>
<value xml:lang="ru">Следующая грамматическая или орфографическая ошибка</value>
<value xml:lang="pt">Próximo erro ortográfico ou gramatical</value>
<value xml:lang="sv">Nästa grammatik- eller stavningskontrollpunkt</value>
</prop>
</node>
<node oor:name="T2" oor:op="replace">
<prop oor:name="URL" oor:type="xs:string">
<value>service:org.languagetool.openoffice.Main?checkDialog</value>
Expand All @@ -202,7 +182,7 @@
<value>_self</value>
</prop>
<prop oor:name="Context" oor:type="xs:string">
<value>com.sun.star.text.TextDocument,com.sun.star.presentation.PresentationDocument,com.sun.star.sheet.SpreadsheetDocument</value>
<value>com.sun.star.presentation.PresentationDocument,com.sun.star.sheet.SpreadsheetDocument</value>
</prop>
<prop oor:name="Title" oor:type="xs:string">
<value xml:lang="en-US">Check Text</value>
Expand Down Expand Up @@ -241,7 +221,7 @@
<value>_self</value>
</prop>
<prop oor:name="Context" oor:type="xs:string">
<value>com.sun.star.text.TextDocument,com.sun.star.presentation.PresentationDocument,com.sun.star.sheet.SpreadsheetDocument</value>
<value>com.sun.star.presentation.PresentationDocument,com.sun.star.sheet.SpreadsheetDocument</value>
</prop>
<prop oor:name="Title" oor:type="xs:string">
<value xml:lang="en-US">Recheck Document</value>
Expand Down Expand Up @@ -270,23 +250,6 @@
<value xml:lang="sv">Språkgranska dokumentet igen</value>
</prop>
</node>
<node oor:name="T4" oor:op="replace">
<prop oor:name="URL" oor:type="xs:string">
<value>service:org.languagetool.openoffice.Main?refreshCheck</value>
</prop>
<prop oor:name="Target" oor:type="xs:string">
<value>_self</value>
</prop>
<prop oor:name="Context" oor:type="xs:string">
<value>com.sun.star.text.TextDocument</value>
</prop>
<prop oor:name="Title" oor:type="xs:string">
<value xml:lang="en-US">Refresh Check Results</value>
<value xml:lang="de">Prüfergebnisse erneuern</value>
<value xml:lang="ru">Обновить результаты проверки</value>
<value xml:lang="sv">Uppdatera språkgranskningspunkterna</value>
</prop>
</node>
<node oor:name="T5" oor:op="replace">
<prop oor:name="URL" oor:type="xs:string">
<value>service:org.languagetool.openoffice.Main?configure</value>
Expand All @@ -295,7 +258,7 @@
<value>_self</value>
</prop>
<prop oor:name="Context" oor:type="xs:string">
<value>com.sun.star.text.TextDocument,com.sun.star.presentation.PresentationDocument,com.sun.star.sheet.SpreadsheetDocument</value>
<value>com.sun.star.presentation.PresentationDocument,com.sun.star.sheet.SpreadsheetDocument</value>
</prop>
<prop oor:name="Title" oor:type="xs:string">
<value xml:lang="en-US">Options...</value>
Expand Down Expand Up @@ -334,7 +297,7 @@
<value>_self</value>
</prop>
<prop oor:name="Context" oor:type="xs:string">
<value>com.sun.star.text.TextDocument,com.sun.star.presentation.PresentationDocument,com.sun.star.sheet.SpreadsheetDocument</value>
<value>com.sun.star.presentation.PresentationDocument,com.sun.star.sheet.SpreadsheetDocument</value>
</prop>
<prop oor:name="Title" oor:type="xs:string">
<value xml:lang="en-US">About...</value>
Expand Down Expand Up @@ -363,9 +326,46 @@
<value xml:lang="sv">Om LanguageTool ...</value>
</prop>
</node>
<!--
<node oor:name="T1" oor:op="replace">
<prop oor:name="URL" oor:type="xs:string">
<value>service:org.languagetool.openoffice.Main?nextError</value>
</prop>
<prop oor:name="Target" oor:type="xs:string">
<value>_self</value>
</prop>
<prop oor:name="Context" oor:type="xs:string">
<value>com.sun.star.text.TextDocument</value>
</prop>
<prop oor:name="Title" oor:type="xs:string">
<value xml:lang="en-US">Next spelling or grammar mistake</value>
<value xml:lang="de">Nächster Rechtschreib- oder Grammatikfehler</value>
<value xml:lang="gl">Erro ortográfico ou gramatical seguinte</value>
<value xml:lang="ru">Следующая грамматическая или орфографическая ошибка</value>
<value xml:lang="pt">Próximo erro ortográfico ou gramatical</value>
<value xml:lang="sv">Nästa grammatik- eller stavningskontrollpunkt</value>
</prop>
</node>
<node oor:name="T4" oor:op="replace">
<prop oor:name="URL" oor:type="xs:string">
<value>service:org.languagetool.openoffice.Main?refreshCheck</value>
</prop>
<prop oor:name="Target" oor:type="xs:string">
<value>_self</value>
</prop>
<prop oor:name="Context" oor:type="xs:string">
<value>com.sun.star.text.TextDocument</value>
</prop>
<prop oor:name="Title" oor:type="xs:string">
<value xml:lang="en-US">Refresh Check Results</value>
<value xml:lang="de">Prüfergebnisse erneuern</value>
<value xml:lang="ru">Обновить результаты проверки</value>
<value xml:lang="sv">Uppdatera språkgranskningspunkterna</value>
</prop>
</node>
-->
</node>
</node>
-->
<node oor:name="OfficeNotebookBar">
<node oor:name="org.languagetool.openoffice.Main.notebar" oor:op="replace">
<node oor:name="T1" oor:op="replace">
Expand Down

0 comments on commit 0891571

Please sign in to comment.