diff --git a/designer-base/src/main/java/com/fr/design/file/MultiTemplateTabPane.java b/designer-base/src/main/java/com/fr/design/file/MultiTemplateTabPane.java index 901a12154e..f66743717d 100644 --- a/designer-base/src/main/java/com/fr/design/file/MultiTemplateTabPane.java +++ b/designer-base/src/main/java/com/fr/design/file/MultiTemplateTabPane.java @@ -322,8 +322,9 @@ public class MultiTemplateTabPane extends JComponent { @Override public void actionPerformed(ActionEvent e) { - SaveSomeTemplatePane saveSomeTempaltePane = new SaveSomeTemplatePane(false); - if (saveSomeTempaltePane.showSavePane()) { + //只有关闭所有模板才需要判断当前模板,关闭左侧、右侧、其他都不需要 + SaveSomeTemplatePane saveSomeTemplatePane = new SaveSomeTemplatePane(option == CloseOption.All); + if (saveSomeTemplatePane.showSavePane(option, false)) { JTemplate[] templates = new JTemplate[openedTemplate.size()]; for (int i = 0; i < openedTemplate.size(); i++) { diff --git a/designer-base/src/main/java/com/fr/design/file/SaveSomeTemplatePane.java b/designer-base/src/main/java/com/fr/design/file/SaveSomeTemplatePane.java index fa8e3d385d..25df1dd3cc 100644 --- a/designer-base/src/main/java/com/fr/design/file/SaveSomeTemplatePane.java +++ b/designer-base/src/main/java/com/fr/design/file/SaveSomeTemplatePane.java @@ -17,6 +17,7 @@ import com.fr.design.mainframe.JTemplate; import com.fr.general.ComparatorUtils; import com.fr.log.FineLoggerFactory; +import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.border.EmptyBorder; @@ -162,8 +163,25 @@ public class SaveSomeTemplatePane extends BasicPane { return showSavePane(false); } + /** + * 显示保存模板提醒面板 + * + * @param judgeJTemplateMustSave 模板是否必须保存 + * @return + */ public boolean showSavePane(boolean judgeJTemplateMustSave) { - populate(judgeJTemplateMustSave); + return showSavePane(null, judgeJTemplateMustSave); + } + + /** + * 显示保存模板提醒面板 + * + * @param option 具体关闭操作 + * @param judgeJTemplateMustSave 模板是否必须保存 + * @return + */ + public boolean showSavePane(@Nullable MultiTemplateTabPane.CloseOption option, boolean judgeJTemplateMustSave) { + populate(option, judgeJTemplateMustSave); //如果有未保存的文件 ,则跳出保存对话框,选择要存储的项目 if (!unSavedTemplate.isEmpty()) { dialog.setVisible(true); @@ -177,11 +195,14 @@ public class SaveSomeTemplatePane extends BasicPane { return HistoryTemplateListPane.getInstance().getHistoryList(); } - public void populate(boolean judgeJTemplateMustSave) { + private void populate(@Nullable MultiTemplateTabPane.CloseOption option, boolean judgeJTemplateMustSave) { java.util.List> opendedTemplate = getOpenedTemplatesToProcess(); JTemplate currentTemplate = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); + int currentIndex = opendedTemplate.indexOf(currentTemplate); for (int i = 0; i < opendedTemplate.size(); i++) { - if (isneedToAdd(opendedTemplate.get(i), currentTemplate)) { + //满足关闭条件的才继续判断文件是否发生了改动 + boolean needClose = option == null || option.shouldClose(currentIndex, i); + if (needClose && isneedToAdd(opendedTemplate.get(i), currentTemplate)) { unSavedTemplate.add(opendedTemplate.get(i)); } }