From 4ac22c1c505948034ae38811ad271b91be6678f9 Mon Sep 17 00:00:00 2001 From: Artur Herdt Date: Thu, 1 Jun 2023 13:33:05 +0200 Subject: [PATCH 1/4] Add new menu entry to remove braces from selection, aka unprotect it. --- CHANGELOG.md | 1 + .../contextmenu/ProtectedTermsMenu.java | 25 ++++++++++++++++++- src/main/resources/l10n/JabRef_en.properties | 2 ++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 05e957b5bbc..396f88a260c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We added the option to automatically download online files when a new entry is created from an existing ID (e.g. DOI). The option can be disabled in the preferences under "Import and Export". [#9756](https://github.com/JabRef/jabref/issues/9756) - We added a new Integrity check for unscaped ampersands. [koppor#585](https://github.com/koppor/jabref/issues/585) - We added the possibility to automatically fetch entries when an IBSN is pasted on the main table. [#9864](https://github.com/JabRef/jabref/issues/9864) +- We added the option to unprotect a text selection, which strips all pairs of curly braces away. [#9950](https://github.com/JabRef/jabref/issues/9950) ### Changed diff --git a/src/main/java/org/jabref/gui/fieldeditors/contextmenu/ProtectedTermsMenu.java b/src/main/java/org/jabref/gui/fieldeditors/contextmenu/ProtectedTermsMenu.java index e085eb981bd..422a242d0d1 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/contextmenu/ProtectedTermsMenu.java +++ b/src/main/java/org/jabref/gui/fieldeditors/contextmenu/ProtectedTermsMenu.java @@ -42,6 +42,18 @@ public String getDescription() { } }; + private final Action unprotectSelectionActionInformation = new Action() { + @Override + public String getText() { + return Localization.lang("Unprotect selection"); + } + + @Override + public String getDescription() { + return Localization.lang("Remove all {} in selected text"); + } + }; + private class ProtectSelectionAction extends SimpleCommand { ProtectSelectionAction() { this.executable.bind(textInputControl.selectedTextProperty().isNotEmpty()); @@ -54,6 +66,16 @@ public void execute() { } } + private class UnprotectSelectionAction extends SimpleCommand { + + @Override + public void execute() { + String selectedText = textInputControl.getSelectedText(); + String strippedOfCurlyBracesText = selectedText.replaceAll("\\{([^{}]*?)\\}", "$1"); + textInputControl.replaceSelection(strippedOfCurlyBracesText); + } + } + private class FormatFieldAction extends SimpleCommand { FormatFieldAction() { this.executable.bind(textInputControl.textProperty().isNotEmpty()); @@ -88,7 +110,8 @@ public ProtectedTermsMenu(final TextInputControl textInputControl) { getItems().addAll(factory.createMenuItem(protectSelectionActionInformation, new ProtectSelectionAction()), getExternalFilesMenu(), new SeparatorMenuItem(), - factory.createMenuItem(() -> Localization.lang("Format field"), new FormatFieldAction())); + factory.createMenuItem(() -> Localization.lang("Format field"), new FormatFieldAction()), + factory.createMenuItem(unprotectSelectionActionInformation, new UnprotectSelectionAction())); } private Menu getExternalFilesMenu() { diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 9f57b9dd104..906ab9524dd 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -1634,6 +1634,7 @@ Are\ you\ sure\ you\ want\ to\ remove\ the\ protected\ terms\ file?=Are you sure Remove\ protected\ terms\ file=Remove protected terms file Add\ selected\ text\ to\ list=Add selected text to list Add\ {}\ around\ selected\ text=Add {} around selected text +Remove\ all\ {}\ in\ selected\ text=Remove all {} in selected text Format\ field=Format field New\ protected\ terms\ file=New protected terms file change\ field\ %0\ of\ entry\ %1\ from\ %2\ to\ %3=change field %0 of entry %1 from %2 to %3 @@ -2290,6 +2291,7 @@ Custom\ import\ formats=Custom import formats No\ list\ enabled=No list enabled Protect\ selection=Protect selection +Unprotect\ selection=Unprotect selection Customized\ preview\ style=Customized preview style Next\ preview\ style=Next preview style From fc67fb122f6f72859692318038bd06735e68f9a0 Mon Sep 17 00:00:00 2001 From: Artur Herdt Date: Sun, 4 Jun 2023 11:28:03 +0200 Subject: [PATCH 2/4] Replace regex-based text-replace implementation with formatter-based one --- .../gui/fieldeditors/contextmenu/ProtectedTermsMenu.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/fieldeditors/contextmenu/ProtectedTermsMenu.java b/src/main/java/org/jabref/gui/fieldeditors/contextmenu/ProtectedTermsMenu.java index 422a242d0d1..ad8cc4fe767 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/contextmenu/ProtectedTermsMenu.java +++ b/src/main/java/org/jabref/gui/fieldeditors/contextmenu/ProtectedTermsMenu.java @@ -16,6 +16,7 @@ import org.jabref.gui.icon.JabRefIcon; import org.jabref.logic.cleanup.Formatter; import org.jabref.logic.formatter.casechanger.ProtectTermsFormatter; +import org.jabref.logic.formatter.casechanger.UnprotectTermsFormatter; import org.jabref.logic.l10n.Localization; import org.jabref.logic.protectedterms.ProtectedTermsList; @@ -71,8 +72,8 @@ private class UnprotectSelectionAction extends SimpleCommand { @Override public void execute() { String selectedText = textInputControl.getSelectedText(); - String strippedOfCurlyBracesText = selectedText.replaceAll("\\{([^{}]*?)\\}", "$1"); - textInputControl.replaceSelection(strippedOfCurlyBracesText); + String formattedString = new UnprotectTermsFormatter().format(selectedText); + textInputControl.replaceSelection(formattedString); } } From dc2df85ed2df34f9badf555a2b76ec7470f0b79d Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Tue, 6 Jun 2023 07:57:43 +0200 Subject: [PATCH 3/4] Remove double entry in changelog --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d5c0bf8aa27..0ff91909069 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,6 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We enabled scrolling in the groups list when dragging a group on another group. [#2869](https://github.com/JabRef/jabref/pull/2869) - We added the option to automatically download online files when a new entry is created from an existing ID (e.g., DOI). The option can be disabled in the preferences under "Import and Export". [#9756](https://github.com/JabRef/jabref/issues/9756) - We added a new Integrity check for unscaped ampersands. [koppor#585](https://github.com/koppor/jabref/issues/585) -- We added the possibility to automatically fetch entries when an IBSN is pasted on the main table. [#9864](https://github.com/JabRef/jabref/issues/9864) - We added support for parsing `$\backslash$` in file paths (as exported by Mendeley). [forum#3470](https://discourse.jabref.org/t/mendeley-bib-import-with-linked-files/3470) - We added the possibility to automatically fetch entries when an ISBN is pasted on the main table. [#9864](https://github.com/JabRef/jabref/issues/9864) - We added the option to disable the automatic linking of files in the entry editor [#5105](https://github.com/JabRef/jabref/issues/5105) From 4d2b1ea433731b5474b077e1e5157f34811df4cd Mon Sep 17 00:00:00 2001 From: Artur Herdt Date: Tue, 6 Jun 2023 14:51:06 +0200 Subject: [PATCH 4/4] Add logic to disable 'unprotect selection', if selection is empty --- .../gui/fieldeditors/contextmenu/ProtectedTermsMenu.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/org/jabref/gui/fieldeditors/contextmenu/ProtectedTermsMenu.java b/src/main/java/org/jabref/gui/fieldeditors/contextmenu/ProtectedTermsMenu.java index ad8cc4fe767..d66eb82a777 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/contextmenu/ProtectedTermsMenu.java +++ b/src/main/java/org/jabref/gui/fieldeditors/contextmenu/ProtectedTermsMenu.java @@ -69,6 +69,10 @@ public void execute() { private class UnprotectSelectionAction extends SimpleCommand { + public UnprotectSelectionAction() { + this.executable.bind(textInputControl.selectedTextProperty().isNotEmpty()); + } + @Override public void execute() { String selectedText = textInputControl.getSelectedText();