fix:修复重命名同样的文件名没有提示的bug
This commit is contained in:
parent
b3923c3cfe
commit
1e752c3ba9
@ -62,11 +62,15 @@ public class RenameFile implements EventHandler<ActionEvent> {
|
||||
textField.setOnKeyPressed(event -> {
|
||||
if (event.getCode() == KeyCode.ENTER) {
|
||||
String newTabName = textField.getText();
|
||||
|
||||
// 检查是否存在相同名称的标签页
|
||||
if (isTabNameExists(newTabName)) {
|
||||
|
||||
// 显示弹窗并提示用户更换名称
|
||||
showDuplicateNameAlert(newTabName);
|
||||
|
||||
// 恢复原始名称
|
||||
centerTab.setText(centerTab.getUserData().toString());
|
||||
|
||||
} else {
|
||||
centerTab.setText(newTabName);
|
||||
// 可选:移除 TextField 的图形
|
||||
@ -79,8 +83,14 @@ public class RenameFile implements EventHandler<ActionEvent> {
|
||||
|
||||
// 监听失去焦点事件,完成编辑
|
||||
textField.focusedProperty().addListener((observable, oldValue, newValue) -> {
|
||||
if (Boolean.FALSE.equals(newValue)) {
|
||||
String newTabName = textField.getText();
|
||||
// 检查是否存在相同名称的标签页
|
||||
if (isTabNameExists(newTabName)) {
|
||||
// 恢复原始名称
|
||||
centerTab.setText(centerTab.getUserData().toString());
|
||||
|
||||
}
|
||||
if (Boolean.FALSE.equals(newValue)) {
|
||||
centerTab.setText(newTabName);
|
||||
// 可选:移除 TextField 的图形
|
||||
centerTab.setGraphic(null);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user