Skip to content

Commit 15b652a

Browse files
committed
Externalizing strings
1 parent 9b0f4e1 commit 15b652a

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/Messages.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ public class Messages
5959
SelectFolder,
6060
ShowHideDetails,
6161
SizeLimitsText,
62+
TextAreaContextMenuCopy,
63+
TextAreaContextMenuCut,
64+
TextAreaContextMenuDelete,
65+
TextAreaContextMenuPaste,
66+
TextAreaContextMenuPasteURLAsMarkdown,
67+
TextAreaContextMenuRedo,
68+
TextAreaContextMenuSelectAll,
69+
TextAreaContextMenuUndo,
6270
UpdateLogEntry;
6371

6472
static

app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/write/LogEntryEditorController.java

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -544,34 +544,40 @@ public LogTemplate fromString(String name) {
544544

545545
}
546546

547+
/**
548+
* Sets up the context menu for the {@link TextArea}. While a {@link TextArea} comes with a default
549+
* context menu containing the standard items (copy, paste...), the ability to access this context
550+
* menu is not possible since Java9, see <a href="https://stackoverflow.com/questions/71053358/javafx-17-custom-textarea-textfield-right-click-menu">this post</a>.
551+
* Any customization means the whole context menu must be built from scratch.
552+
*/
547553
private void setupTextAreaContextMenu() {
548554
// Create the context menu with default items
549555
ContextMenu contextMenu = new ContextMenu();
550556

551557
// Standard text editing items
552-
MenuItem undo = new MenuItem("Undo");
558+
MenuItem undo = new MenuItem(Messages.TextAreaContextMenuUndo);
553559
undo.setOnAction(e -> textArea.undo());
554560

555-
MenuItem redo = new MenuItem("Redo");
561+
MenuItem redo = new MenuItem(Messages.TextAreaContextMenuRedo);
556562
redo.setOnAction(e -> textArea.redo());
557563

558-
MenuItem cut = new MenuItem("Cut");
564+
MenuItem cut = new MenuItem(Messages.TextAreaContextMenuCut);
559565
cut.setOnAction(e -> textArea.cut());
560566

561-
MenuItem copy = new MenuItem("Copy");
567+
MenuItem copy = new MenuItem(Messages.TextAreaContextMenuCopy);
562568
copy.setOnAction(e -> textArea.copy());
563569

564-
MenuItem paste = new MenuItem("Paste");
570+
MenuItem paste = new MenuItem(Messages.TextAreaContextMenuPaste);
565571
paste.setOnAction(e -> textArea.paste());
566572

567-
MenuItem delete = new MenuItem("Delete");
573+
MenuItem delete = new MenuItem(Messages.TextAreaContextMenuDelete);
568574
delete.setOnAction(e -> textArea.replaceSelection(""));
569575

570-
MenuItem selectAll = new MenuItem("Select All");
576+
MenuItem selectAll = new MenuItem(Messages.TextAreaContextMenuSelectAll);
571577
selectAll.setOnAction(e -> textArea.selectAll());
572578

573579
// Our custom menu item
574-
MenuItem pasteUrlItem = new MenuItem("Paste URL as Markdown");
580+
MenuItem pasteUrlItem = new MenuItem(Messages.TextAreaContextMenuPasteURLAsMarkdown);
575581
pasteUrlItem.setOnAction(event -> handleSmartPaste());
576582
pasteUrlItem.setAccelerator(new KeyCodeCombination(KeyCode.V,
577583
KeyCombination.SHORTCUT_DOWN, KeyCombination.SHIFT_DOWN));
@@ -597,7 +603,10 @@ private void setupTextAreaContextMenu() {
597603
cut.disableProperty().bind(textArea.selectedTextProperty().isEmpty());
598604
copy.disableProperty().bind(textArea.selectedTextProperty().isEmpty());
599605
delete.disableProperty().bind(textArea.selectedTextProperty().isEmpty());
600-
606+
contextMenu.setOnShowing(e -> {
607+
String clipboardContent = Clipboard.getSystemClipboard().getString();
608+
pasteUrlItem.setDisable(clipboardContent == null || !clipboardContent.toLowerCase().startsWith("http"));
609+
});
601610
// Set the context menu on the text area
602611
textArea.setContextMenu(contextMenu);
603612
}
@@ -646,6 +655,7 @@ private void handleSmartPaste() {
646655
// Not a URL - do nothing
647656
}
648657
}
658+
649659
private String extractOlogUrl(String text) {
650660
String rootUrl = LogbookUIPreferences.web_client_root_URL;
651661
if (rootUrl == null || rootUrl.isEmpty()) {
@@ -957,7 +967,7 @@ private void getServerSideStaticData() {
957967
defaultLevel = optionalLevel.get().name();
958968
}
959969
selectedLevelProperty.set(logEntry.getLevel() != null ? logEntry.getLevel() : defaultLevel);
960-
levelSelector.getSelectionModel().select(selectedLevelProperty.get());
970+
Platform.runLater(() -> levelSelector.getSelectionModel().select(selectedLevelProperty.get()));
961971
});
962972
}
963973

app/logbook/olog/ui/src/main/resources/org/phoebus/logbook/olog/ui/messages.properties

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ TagsTitle=Select Tags
115115
TagsTooltip=Add tag to the log entry.
116116
Templates=Templates:
117117
Text=Text:
118+
TextAreaContextMenuCopy=Copy
119+
TextAreaContextMenuCut=Cut
120+
TextAreaContextMenuDelete=Delete
121+
TextAreaContextMenuPaste=Paste
122+
TextAreaContextMenuPasteURLAsMarkdown=Paste URL as Markdown
123+
TextAreaContextMenuRedo=Redo
124+
TextAreaContextMenuSelectAll=Select All
125+
TextAreaContextMenuUndo=Undo
118126
Time=Time:
119127
Title=Title:
120128
UnableToDownloadArchived=

0 commit comments

Comments
 (0)