@param name File name. @return Context menu for files.
(String name)
| 604 | * @return Context menu for files. |
| 605 | */ |
| 606 | public ContextMenu ofFile(String name) { |
| 607 | // Create the menu |
| 608 | MenuItem header = new MenuItem(shorten(name)); |
| 609 | header.getStyleClass().add("context-menu-header"); |
| 610 | header.setGraphic(UiUtil.createFileGraphic(name)); |
| 611 | header.setDisable(true); |
| 612 | ContextMenu menu = new ContextMenu(); |
| 613 | menu.getItems().add(header); |
| 614 | // Add workspace-navigator specific items, but only for primary files |
| 615 | if (isWorkspaceTree() && isPrimaryFile(name)) { |
| 616 | MenuItem rename = new ActionMenuItem(LangUtil.translate("misc.rename"), () -> { |
| 617 | Window main = controller.windows().getMainWindow().getStage(); |
| 618 | RenamingTextField popup = RenamingTextField.forFile(controller, name); |
| 619 | popup.show(main); |
| 620 | }); |
| 621 | MenuItem remove = new ActionMenuItem(LangUtil.translate("misc.remove"), () -> { |
| 622 | YesNoWindow.prompt(LangUtil.translate("misc.confirm.message"), () -> { |
| 623 | controller.getWorkspace().getPrimary().getFiles().remove(name); |
| 624 | controller.windows().getMainWindow().getTabs().closeTab(name); |
| 625 | }, null).show(treeView); |
| 626 | }); |
| 627 | menu.getItems().addAll( |
| 628 | rename, |
| 629 | remove, |
| 630 | new SeparatorMenuItem(), |
| 631 | new ActionMenuItem(translate("ui.edit.copypath"), () -> { |
| 632 | ClipboardContent content = new ClipboardContent(); |
| 633 | content.putString(name); |
| 634 | Clipboard.getSystemClipboard().setContent(content); |
| 635 | }) |
| 636 | ); |
| 637 | |
| 638 | } |
| 639 | // Inject plugin menus |
| 640 | plugins.ofType(ContextMenuInjectorPlugin.class).forEach(injector -> injector.forFile(this, menu, name)); |
| 641 | return menu; |
| 642 | } |
| 643 | |
| 644 | /** |
| 645 | * @param resource |
no test coverage detected