From 817eed5c799360a1aaac93b69b2c0df58725187e Mon Sep 17 00:00:00 2001 From: kerry Date: Mon, 17 Apr 2023 18:48:58 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-75308=20FVS=E5=A4=A7=E5=B1=8F=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E6=94=AF=E6=8C=81=E5=90=8C=E6=97=B6=E6=89=93=E5=BC=80?= =?UTF-8?q?=E5=A4=9A=E4=B8=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/actions/file/SwitchExistEnv.java | 2 +- .../fr/design/file/SaveSomeTemplatePane.java | 19 ++++----------- .../file/impl/AbstractTemplateTabOperate.java | 24 ++++++++++++++----- .../com/fr/design/mainframe/JTemplate.java | 8 +++++++ 4 files changed, 32 insertions(+), 21 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/actions/file/SwitchExistEnv.java b/designer-base/src/main/java/com/fr/design/actions/file/SwitchExistEnv.java index e38a39895a..33761a92e2 100644 --- a/designer-base/src/main/java/com/fr/design/actions/file/SwitchExistEnv.java +++ b/designer-base/src/main/java/com/fr/design/actions/file/SwitchExistEnv.java @@ -68,7 +68,7 @@ public class SwitchExistEnv extends MenuDef { EnvChangeEntrance.getInstance().chooseEnv(envName); } else { SaveSomeTemplatePane saveSomeTemplatePane = new SaveSomeTemplatePane(true); - if (saveSomeTemplatePane.showSavePane(true)) { + if (saveSomeTemplatePane.showSavePane()) { // 用户模板保存后,才进行切换目录操作 EnvChangeEntrance.getInstance().switch2Env(envName); } 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 c83c5ca800..23dfe83a57 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 @@ -84,6 +84,7 @@ public class SaveSomeTemplatePane extends BasicPane { for (int i = 0; i < unSavedTemplate.size(); i++) { templateCheckBoxes[i] = new UICheckBox(unSavedTemplate.get(i).getEditingFILE().getName()); templateCheckBoxes[i].setSelected(true); + templateCheckBoxes[i].setEnabled(!unSavedTemplate.get(i).mustSaveBeforeSwitchEnv()); } final UIList templatesList = new UIList(templateCheckBoxes); @@ -103,7 +104,9 @@ public class SaveSomeTemplatePane extends BasicPane { boolean isSelected = chooseAllCheckBox.isSelected(); for (int i = 0; i < templatesList.getModel().getSize(); i++) { UICheckBox checkBox = (UICheckBox) templatesList.getModel().getElementAt(i); - checkBox.setSelected(isSelected); + boolean mustSaveBeforeSwitchEnv = unSavedTemplate.get(i).mustSaveBeforeSwitchEnv(); + checkBox.setSelected(mustSaveBeforeSwitchEnv || isSelected); + templateCheckBoxes[i].setEnabled(!mustSaveBeforeSwitchEnv); } templatesList.repaint(); } @@ -150,24 +153,12 @@ public class SaveSomeTemplatePane extends BasicPane { return count; } - /** * 显示未保存弹窗 * @return */ public boolean showSavePane() { - return showSavePane(false); - } - - /** - * 显示未保存弹窗 - * @param switchEnv - * @return - */ - public boolean showSavePane(boolean switchEnv) { - return switchEnv ? - showSavePane(DefaultTemplateTabOperate.getInstance().getOpenedJTemplates()) : - showSavePane(HistoryTemplateListPane.getInstance().getHistoryList()); + return showSavePane(HistoryTemplateListPane.getInstance().getHistoryList()); } /** diff --git a/designer-base/src/main/java/com/fr/design/file/impl/AbstractTemplateTabOperate.java b/designer-base/src/main/java/com/fr/design/file/impl/AbstractTemplateTabOperate.java index 3f67fb69b2..75319d7e70 100644 --- a/designer-base/src/main/java/com/fr/design/file/impl/AbstractTemplateTabOperate.java +++ b/designer-base/src/main/java/com/fr/design/file/impl/AbstractTemplateTabOperate.java @@ -45,7 +45,7 @@ public abstract class AbstractTemplateTabOperate implements TemplateTabOperatePr //用于存放工作簿 private java.util.List> openedTemplate = new ArrayList<>(); //选中的Tab项 - private int selectedIndex = -1; + private int selectedIndex = 0; public AbstractTemplateTabOperate() { @@ -257,9 +257,10 @@ public abstract class AbstractTemplateTabOperate implements TemplateTabOperatePr } private void closeTpl(@Nonnull JTemplate specifiedTemplate) { + JTemplate currentSelectedFile = getSelectedFile(); HistoryTemplateListCache.getInstance().closeSelectedReport(specifiedTemplate); closeAndFreeLock(specifiedTemplate); - activePrevTemplateAfterClose(specifiedTemplate == HistoryTemplateListCache.getInstance().getCurrentEditingTemplate()); + activePrevTemplateAfterClose(specifiedTemplate == currentSelectedFile, currentSelectedFile); } /** @@ -270,12 +271,24 @@ public abstract class AbstractTemplateTabOperate implements TemplateTabOperatePr activePrevTemplateAfterClose(TemplateTabManager.getInstance().isCloseCurrent()); } + /** * 关闭掉一个模板之后激活新的待显示模板 */ public void activePrevTemplateAfterClose(boolean isCurrentSelectedTpl) { + activePrevTemplateAfterClose(isCurrentSelectedTpl, HistoryTemplateListCache.getInstance().getCurrentEditingTemplate()); + } + + /** + * 关闭掉一个模板之后激活新的待显示模板 + */ + public void activePrevTemplateAfterClose(boolean isCurrentSelectedTpl, JTemplate currentSelectedJTemplate) { + JTemplate template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); + boolean couldSwitch = template != null && this.accept(template.getTemplateTabOperatorType()); if (openedTemplate.isEmpty()) { - TemplateTabManager.getInstance().activeNewTemplate(); + if (couldSwitch){ + TemplateTabManager.getInstance().activeNewTemplate(); + } selectedIndex = 0; } else { // 如果关闭的模板是当前选中的模板,则重新激活当前 selectIndex 的模板; @@ -290,10 +303,9 @@ public abstract class AbstractTemplateTabOperate implements TemplateTabOperatePr } // 如果关闭的模板不是当前选中的模板,那么重新获取一下当前模板的 index,激活该 index else { - JTemplate template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); - selectedIndex = this.openedTemplate.indexOf(template); + selectedIndex = this.openedTemplate.indexOf(currentSelectedJTemplate); } - if (selectedIndex < openedTemplate.size()) { + if ( selectedIndex < openedTemplate.size() && couldSwitch) { //如果是已后台关闭的模板,则重新打开文件 openedTemplate.get(selectedIndex).activeOldJTemplate(); } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java index 3ede09d5ec..a92d59d072 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java @@ -2082,4 +2082,12 @@ public abstract class JTemplate> public boolean supportCache(){ return true; } + + /** + * 切换环境之前是否一定要保存 + * @return + */ + public boolean mustSaveBeforeSwitchEnv(){ + return false; + } }