Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new menu entry to remove braces from selection, aka unprotect it. #9968

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- 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)
- We added the link icon for ISBNs in linked identifiers column. [#9819](https://github.com/JabRef/jabref/issues/9819)
- 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)
- We added drag and drop events for field 'Groups' in entry editor panel. [#569](https://github.com/koppor/jabref/issues/569)
- We added support for parsing MathML in the Medline importer. [#4273](https://github.com/JabRef/jabref/issues/4273)
- We added the ability to search for a DOI directly from 'Web Search'. [#9674](https://github.com/JabRef/jabref/issues/9674)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -42,6 +43,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());
Expand All @@ -54,6 +67,20 @@ public void execute() {
}
}

private class UnprotectSelectionAction extends SimpleCommand {

public UnprotectSelectionAction() {
this.executable.bind(textInputControl.selectedTextProperty().isNotEmpty());
}

@Override
public void execute() {
String selectedText = textInputControl.getSelectedText();
BeeJay28 marked this conversation as resolved.
Show resolved Hide resolved
String formattedString = new UnprotectTermsFormatter().format(selectedText);
textInputControl.replaceSelection(formattedString);
}
}

private class FormatFieldAction extends SimpleCommand {
FormatFieldAction() {
this.executable.bind(textInputControl.textProperty().isNotEmpty());
Expand Down Expand Up @@ -88,7 +115,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() {
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down