Skip to content

Commit

Permalink
为原文列表添加复制功能
Browse files Browse the repository at this point in the history
  • Loading branch information
yushijinhun committed Jan 29, 2017
1 parent a0ef070 commit ef68b4e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.to2mbn.maptranslator.impl.ui;

import static org.to2mbn.maptranslator.impl.ui.UIUtils.copyToClipboard;
import static org.to2mbn.maptranslator.impl.ui.UIUtils.reportException;
import static org.to2mbn.maptranslator.impl.ui.UIUtils.translate;
import java.util.HashSet;
Expand Down Expand Up @@ -27,11 +28,13 @@
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.control.MenuItem;
import javafx.scene.control.SeparatorMenuItem;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCodeCombination;
import javafx.scene.input.KeyCombination;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

Expand All @@ -46,8 +49,9 @@ class OriginalTextsWindow {
private Button btnLoad;
private Set<String> stringsSet = new HashSet<>();
private Map<String, ListCell<String>> cellsMapping = new WeakHashMap<>();
private MenuItem menuCopy = new MenuItem(translate("menu.copy"));
private MenuItem menuShowIn = new MenuItem(translate("strings.menu.lookup_appearances"));
private ContextMenu popupMenu = new ContextMenu(menuShowIn);
private ContextMenu popupMenu = new ContextMenu(menuShowIn, new SeparatorMenuItem(), menuCopy);
private TextField txtFilter;

private Runnable showFilter;
Expand Down Expand Up @@ -125,8 +129,10 @@ protected void updateItem(String item, boolean empty) {
}
});
list.setContextMenu(popupMenu);
popupMenu.setOnShowing(event -> menuShowIn.setDisable(list.getSelectionModel().isEmpty()));
menuShowIn.setOnAction(event -> showSelectedInNBTExplorer());
menuShowIn.disableProperty().bind(list.getSelectionModel().selectedItemProperty().isNull());
menuCopy.setOnAction(evemt -> copySelected());
menuCopy.disableProperty().bind(list.getSelectionModel().selectedItemProperty().isNull());

list.itemsProperty().bind(Bindings.createObjectBinding(() -> {
if (txtFilter.getText().isEmpty()) {
Expand Down Expand Up @@ -164,6 +170,11 @@ protected void updateItem(String item, boolean empty) {
stage.getScene().getAccelerators().put(new KeyCodeCombination(KeyCode.F, KeyCombination.CONTROL_DOWN), showFilter);
stage.getScene().getAccelerators().put(new KeyCodeCombination(KeyCode.ESCAPE), hideFilter);
stage.getScene().getAccelerators().put(new KeyCodeCombination(KeyCode.G, KeyCombination.CONTROL_DOWN), this::showSelectedInNBTExplorer);
list.addEventHandler(KeyEvent.KEY_PRESSED, event -> {
if (event.isControlDown() && event.getCode() == KeyCode.C) {
copySelected();
}
});
}

public void onStringAddedToTranslate(String origin) {
Expand Down Expand Up @@ -211,4 +222,9 @@ private void showSelectedInNBTExplorer() {
String str = list.getSelectionModel().getSelectedItem();
if (str != null) showSelectedInNBTExplorer.accept(str);
}

private void copySelected() {
String str = list.getSelectionModel().getSelectedItem();
if (str != null) copyToClipboard(str);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ nbt_view.find.tip=%d of %d (Ctrl+N Find next, Ctrl+P Find previous, Ctrl+; Clear
nbt_view.path.no_selected=No node is selected
nbt_view.goto=Go to node
nbt_view.goto.message=The path of the node to go to:
menu.copy=Copy
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ nbt_view.find.tip=\u7B2C%d\u4E2A\u5339\u914D\uFF0C\u5171%d\u4E2A (Ctrl+N \u4E0B\
nbt_view.path.no_selected=\u6CA1\u6709\u9009\u4E2D\u8282\u70B9
nbt_view.goto=\u5207\u6362\u8282\u70B9
nbt_view.goto.message=\u8981\u5207\u6362\u5230\u7684\u8282\u70B9\u7684\u8DEF\u5F84\uFF1A
menu.copy=\u590D\u5236

0 comments on commit ef68b4e

Please sign in to comment.