!56 feat: #I7SOWB 重命名tab时样式调整

Merge pull request !56 from songdragon/feature-I7SOWB
This commit is contained in:
Luke 2023-08-30 16:02:44 +00:00 committed by Gitee
commit 3671354b5d
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 14 additions and 3 deletions

View File

@ -24,7 +24,7 @@ public class RenameFile implements EventHandler<ActionEvent> {
public void handle(ActionEvent actionEvent) {
// 获取当前标签页
JNotepadTab jnotepadtab = UiUtil.getJnotepadtab();
if (jnotepadtab == null) {
if (jnotepadtab == null || jnotepadtab.getText().isEmpty()) {
return;
}
// 判断当前是否为关联文件
@ -58,8 +58,7 @@ public class RenameFile implements EventHandler<ActionEvent> {
// 如果当前不是关联文件则重命名标签页
else {
TextField textField = new TextField(jnotepadtab.getText());
// 设置文本框尺寸
textField.setPrefSize(120, 12);
textField.getStyleClass().add("tab-title-editable");
// 清空标签页名称
jnotepadtab.setText("");
// 监听 Enter 完成编辑
@ -85,6 +84,9 @@ public class RenameFile implements EventHandler<ActionEvent> {
jnotepadtab.setClosable(false);
// 设置 TextField 作为标签页的图形
jnotepadtab.setGraphic(textField);
// 默认获取焦点并选中所有文字
textField.requestFocus();
textField.selectAll();
}
}

View File

@ -24,4 +24,13 @@
.main-text-area {
-fx-border-color: white;
-fx-background-color: white;
}
/* tab修改标签样式 */
.tab-title-editable {
-fx-fx-border-width: 0;
-fx-max-width: 80px;
-fx-max-height: 20px;
-fx-font-size: 14px;
-fx-padding: 2px 2px 2px 2px;
}