Skip to content

Commit c4e4473

Browse files
committed
Implemented a confirm dialog
1 parent d07499d commit c4e4473

File tree

6 files changed

+169
-6
lines changed

6 files changed

+169
-6
lines changed

resources/messages/messages.properties

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ AssetComponentResourceTreeContextMenuCopyFile=Copy
1313
AssetComponentResourceTreeContextMenuCutFile=Cut
1414
AssetComponentResourceTreeContextMenuPasteFile=Paste
1515
AssetComponentResourceTreeContextMenuDeleteFile=Delete
16+
AssetComponentResourceTreeContextMenuDeleteFileQuestion=Do you want to remove the file "%file_name%"?
1617
AssetComponentResourceTreeContextMenuConvertFile=Convert
1718
AssetComponentResourceTreeContextMenuOpenFileByExternalEditor=Open fine in external editor
1819
AssetComponentResourceTreeContextMenuRenameFile=Rename
@@ -206,6 +207,10 @@ RenameDialogNewNameLabel=New name
206207
RenameDialogButtonOk=Rename
207208
RenameDialogButtonCancel=Cancel
208209
210+
QuestionDialogTitle=Question
211+
QuestionDialogButtonOk=Yes
212+
QuestionDialogButtonCancel=No
213+
209214
FolderCreatorDescription=New folder
210215
FolderCreatorTitle=Create new folder
211216
FolderCreatorFileNameLabel=Folder name

resources/messages/messages_ru.properties

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ AssetComponentResourceTreeContextMenuCopyFile=Копировать
1313
AssetComponentResourceTreeContextMenuCutFile=Вырезать
1414
AssetComponentResourceTreeContextMenuPasteFile=Вставить
1515
AssetComponentResourceTreeContextMenuDeleteFile=Удаить
16+
AssetComponentResourceTreeContextMenuDeleteFileQuestion=Вы уверены что хотите удалить файл "%file_name%"?
1617
AssetComponentResourceTreeContextMenuConvertFile=Конвертировать
1718
AssetComponentResourceTreeContextMenuOpenFileByExternalEditor=Открыть файл во внешнем редакторе
1819
AssetComponentResourceTreeContextMenuRenameFile=Переименовать
@@ -206,6 +207,10 @@ RenameDialogNewNameLabel=Новое имя
206207
RenameDialogButtonOk=Переименовать
207208
RenameDialogButtonCancel=Отменить
208209
210+
QuestionDialogTitle=Вопрос
211+
QuestionDialogButtonOk=Да
212+
QuestionDialogButtonCancel=Нет
213+
209214
FolderCreatorDescription=Новая папка
210215
FolderCreatorTitle=Создание новой папки
211216
FolderCreatorFileNameLabel=Название папки

src/com/ss/editor/Messages.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class Messages {
3030
public static final String ASSET_COMPONENT_RESOURCE_TREE_CONTEXT_MENU_CUT_FILE;
3131
public static final String ASSET_COMPONENT_RESOURCE_TREE_CONTEXT_MENU_PASTE_FILE;
3232
public static final String ASSET_COMPONENT_RESOURCE_TREE_CONTEXT_MENU_DELETE_FILE;
33+
public static final String ASSET_COMPONENT_RESOURCE_TREE_CONTEXT_MENU_DELETE_FILE_QUESTION;
3334
public static final String ASSET_COMPONENT_RESOURCE_TREE_CONTEXT_MENU_CONVERT_FILE;
3435
public static final String ASSET_COMPONENT_RESOURCE_TREE_CONTEXT_MENU_OPEN_FILE_BY_EXTERNAL_EDITOR;
3536
public static final String ASSET_COMPONENT_RESOURCE_TREE_CONTEXT_MENU_RENAME_FILE;
@@ -221,6 +222,10 @@ public class Messages {
221222
public static final String RENAME_DIALOG_BUTTON_OK;
222223
public static final String RENAME_DIALOG_BUTTON_CANCEL;
223224

225+
public static final String QUESTION_DIALOG_TITLE;
226+
public static final String QUESTION_DIALOG_BUTTON_OK;
227+
public static final String QUESTION_DIALOG_BUTTON_CANCEL;
228+
224229
public static final String FOLDER_CREATOR_DESCRIPTION;
225230
public static final String FOLDER_CREATOR_TITLE;
226231
public static final String FOLDER_CREATOR_FILE_NAME_LABEL;
@@ -295,6 +300,7 @@ public class Messages {
295300
ASSET_COMPONENT_RESOURCE_TREE_CONTEXT_MENU_CUT_FILE = bundle.getString("AssetComponentResourceTreeContextMenuCutFile");
296301
ASSET_COMPONENT_RESOURCE_TREE_CONTEXT_MENU_PASTE_FILE = bundle.getString("AssetComponentResourceTreeContextMenuPasteFile");
297302
ASSET_COMPONENT_RESOURCE_TREE_CONTEXT_MENU_DELETE_FILE = bundle.getString("AssetComponentResourceTreeContextMenuDeleteFile");
303+
ASSET_COMPONENT_RESOURCE_TREE_CONTEXT_MENU_DELETE_FILE_QUESTION = bundle.getString("AssetComponentResourceTreeContextMenuDeleteFileQuestion");
298304
ASSET_COMPONENT_RESOURCE_TREE_CONTEXT_MENU_CONVERT_FILE = bundle.getString("AssetComponentResourceTreeContextMenuConvertFile");
299305
ASSET_COMPONENT_RESOURCE_TREE_CONTEXT_MENU_OPEN_FILE_BY_EXTERNAL_EDITOR = bundle.getString("AssetComponentResourceTreeContextMenuOpenFileByExternalEditor");
300306
ASSET_COMPONENT_RESOURCE_TREE_CONTEXT_MENU_RENAME_FILE = bundle.getString("AssetComponentResourceTreeContextMenuRenameFile");
@@ -485,6 +491,10 @@ public class Messages {
485491
RENAME_DIALOG_BUTTON_OK = bundle.getString("RenameDialogButtonOk");
486492
RENAME_DIALOG_BUTTON_CANCEL = bundle.getString("RenameDialogButtonCancel");
487493

494+
QUESTION_DIALOG_TITLE = bundle.getString("QuestionDialogTitle");
495+
QUESTION_DIALOG_BUTTON_OK = bundle.getString("QuestionDialogButtonOk");
496+
QUESTION_DIALOG_BUTTON_CANCEL = bundle.getString("QuestionDialogButtonCancel");
497+
488498
FOLDER_CREATOR_DESCRIPTION = bundle.getString("FolderCreatorDescription");
489499
FOLDER_CREATOR_TITLE = bundle.getString("FolderCreatorTitle");
490500
FOLDER_CREATOR_FILE_NAME_LABEL = bundle.getString("FolderCreatorFileNameLabel");

src/com/ss/editor/ui/component/asset/tree/context/menu/action/DeleteFileAction.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
package com.ss.editor.ui.component.asset.tree.context.menu.action;
22

3+
import com.ss.editor.JFXApplication;
34
import com.ss.editor.Messages;
45
import com.ss.editor.config.EditorConfig;
56
import com.ss.editor.ui.component.asset.tree.resource.ResourceElement;
7+
import com.ss.editor.ui.dialog.ConfirmDialog;
8+
import com.ss.editor.ui.scene.EditorFXScene;
69

710
import java.nio.file.Path;
811

912
import javafx.scene.control.MenuItem;
1013
import rlib.util.FileUtils;
1114

1215
/**
13-
* Реализация действия по удалении файла.
16+
* The action for deleting a file.
1417
*
15-
* @author Ronn
18+
* @author JavaSaBr
1619
*/
1720
public class DeleteFileAction extends MenuItem {
1821

22+
private static final JFXApplication JFX_APPLICATION = JFXApplication.getInstance();
23+
1924
/**
20-
* Элемент действия.
25+
* The node in the tree.
2126
*/
2227
private final ResourceElement element;
2328

@@ -28,7 +33,7 @@ public DeleteFileAction(final ResourceElement element) {
2833
}
2934

3035
/**
31-
* Процесс удаления файла.
36+
* Handle deleting.
3237
*/
3338
private void processDelete() {
3439

@@ -41,6 +46,19 @@ private void processDelete() {
4146
return;
4247
}
4348

49+
String question = Messages.ASSET_COMPONENT_RESOURCE_TREE_CONTEXT_MENU_DELETE_FILE_QUESTION;
50+
question = question.replace("%file_name%", file.getFileName().toString());
51+
52+
final EditorFXScene scene = JFX_APPLICATION.getScene();
53+
final ConfirmDialog confirmDialog = new ConfirmDialog(result -> handle(file, result), question);
54+
confirmDialog.show(scene.getWindow());
55+
}
56+
57+
/**
58+
* Handle the answer.
59+
*/
60+
private void handle(final Path file, final Boolean result) {
61+
if (!result) return;
4462
FileUtils.delete(file);
4563
}
4664
}

src/com/ss/editor/ui/component/asset/tree/context/menu/action/RenameFileAction.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.ss.editor.Messages;
55
import com.ss.editor.ui.component.asset.tree.resource.ResourceElement;
66
import com.ss.editor.ui.dialog.RenameDialog;
7-
import com.ss.editor.ui.event.FXEventManager;
87
import com.ss.editor.ui.scene.EditorFXScene;
98
import com.ss.editor.util.EditorUtil;
109

@@ -23,7 +22,6 @@
2322
*/
2423
public class RenameFileAction extends MenuItem {
2524

26-
private static final FXEventManager FX_EVENT_MANAGER = FXEventManager.getInstance();
2725
private static final JFXApplication JFX_APPLICATION = JFXApplication.getInstance();
2826

2927
/**
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
package com.ss.editor.ui.dialog;
2+
3+
import com.ss.editor.Messages;
4+
import com.ss.editor.ui.css.CSSClasses;
5+
import com.ss.editor.ui.css.CSSIds;
6+
7+
import java.awt.Point;
8+
import java.util.function.Consumer;
9+
10+
import javafx.geometry.Insets;
11+
import javafx.geometry.Pos;
12+
import javafx.scene.control.Button;
13+
import javafx.scene.control.Label;
14+
import javafx.scene.input.KeyCode;
15+
import javafx.scene.input.KeyEvent;
16+
import javafx.scene.layout.HBox;
17+
import javafx.scene.layout.VBox;
18+
import javafx.scene.text.TextAlignment;
19+
import rlib.ui.util.FXUtils;
20+
21+
/**
22+
* The implementation of a dialog for asking questions.
23+
*
24+
* @author JavaSaBr
25+
*/
26+
public class ConfirmDialog extends EditorDialog {
27+
28+
private static final Insets OK_BUTTON_OFFSET = new Insets(0, 4, 0, 0);
29+
private static final Insets CANCEL_BUTTON_OFFSET = new Insets(0, 15, 0, 0);
30+
31+
private static final Point DIALOG_SIZE = new Point(600, 120);
32+
33+
/**
34+
* The handler pf an answer.
35+
*/
36+
private final Consumer<Boolean> handler;
37+
38+
/**
39+
* The ok button.
40+
*/
41+
private Button okButton;
42+
43+
/**
44+
* The label.
45+
*/
46+
private Label questionLabel;
47+
48+
public ConfirmDialog(final Consumer<Boolean> handler, final String question) {
49+
this.handler = handler;
50+
this.questionLabel.setText(question);
51+
}
52+
53+
@Override
54+
protected String getTitleText() {
55+
return Messages.QUESTION_DIALOG_TITLE;
56+
}
57+
58+
@Override
59+
protected void createContent(final VBox root) {
60+
super.createContent(root);
61+
62+
questionLabel = new Label();
63+
questionLabel.setAlignment(Pos.CENTER);
64+
questionLabel.setTextAlignment(TextAlignment.CENTER);
65+
questionLabel.setWrapText(true);
66+
questionLabel.prefWidthProperty().bind(root.widthProperty().multiply(0.9));
67+
questionLabel.setPadding(new Insets(10, 0, 10, 0));
68+
69+
FXUtils.addToPane(questionLabel, root);
70+
FXUtils.addClassTo(questionLabel, CSSClasses.SPECIAL_FONT_15);
71+
}
72+
73+
@Override
74+
protected void processKey(final KeyEvent event) {
75+
super.processKey(event);
76+
if (event.getCode() == KeyCode.ENTER) {
77+
processCancel();
78+
}
79+
}
80+
81+
@Override
82+
protected void createActions(final VBox root) {
83+
super.createActions(root);
84+
85+
final HBox container = new HBox();
86+
container.setId(CSSIds.ASSET_EDITOR_DIALOG_BUTTON_CONTAINER);
87+
88+
okButton = new Button(Messages.QUESTION_DIALOG_BUTTON_OK);
89+
okButton.setId(CSSIds.EDITOR_DIALOG_BUTTON_OK);
90+
okButton.setOnAction(event -> processOk());
91+
92+
final Button cancelButton = new Button(Messages.QUESTION_DIALOG_BUTTON_CANCEL);
93+
cancelButton.setId(CSSIds.EDITOR_DIALOG_BUTTON_CANCEL);
94+
cancelButton.setOnAction(event -> hide());
95+
96+
FXUtils.addToPane(okButton, container);
97+
FXUtils.addToPane(cancelButton, container);
98+
FXUtils.addToPane(container, root);
99+
100+
FXUtils.addClassTo(okButton, CSSClasses.SPECIAL_FONT_16);
101+
FXUtils.addClassTo(cancelButton, CSSClasses.SPECIAL_FONT_16);
102+
103+
HBox.setMargin(okButton, OK_BUTTON_OFFSET);
104+
HBox.setMargin(cancelButton, CANCEL_BUTTON_OFFSET);
105+
}
106+
107+
/**
108+
* Handle OK answer.
109+
*/
110+
private void processOk() {
111+
handler.accept(Boolean.TRUE);
112+
hide();
113+
}
114+
115+
/**
116+
* Handle reject answer.
117+
*/
118+
private void processCancel() {
119+
handler.accept(Boolean.FALSE);
120+
hide();
121+
}
122+
123+
@Override
124+
protected Point getSize() {
125+
return DIALOG_SIZE;
126+
}
127+
}

0 commit comments

Comments
 (0)