Disable reload button for new unsaved files

This commit is contained in:
Jindra Petřík
2022-11-06 12:13:37 +01:00
parent 6de7438b26
commit 6640f82bcb
3 changed files with 20 additions and 3 deletions

View File

@@ -37,7 +37,18 @@ public class SWFSourceInfo {
private final String fileTitle;
private final boolean detectBundle;
private boolean empty = false;
public SWFSourceInfo(String fileTitle) {
this(null, null, fileTitle, false);
empty = true;
}
public boolean isEmpty() {
return empty;
}
public SWFSourceInfo(InputStream inputStream, String file, String fileTitle) {
this(inputStream, file, fileTitle, true);
}

View File

@@ -1359,7 +1359,12 @@ public class Main {
Helper.freeMem();
showModeFrame();
return true;
} else {
} else {
for (int i = sourceInfos.size() - 1; i >= 0; i--) {
if (sourceInfos.get(i).isEmpty()) {
sourceInfos.remove(i);
}
}
SWFSourceInfo[] sourceInfosCopy = new SWFSourceInfo[sourceInfos.size()];
sourceInfos.toArray(sourceInfosCopy);
sourceInfos.clear();
@@ -1478,7 +1483,7 @@ public class Main {
}
String ext = newFileDialog.isGfx() ? "gfx" : "swf";
String fileTitle = AppStrings.translate("new.filename") + "." + ext;
SWFSourceInfo sourceInfo = new SWFSourceInfo(new ByteArrayInputStream(new byte[0]), null, fileTitle);
SWFSourceInfo sourceInfo = new SWFSourceInfo(fileTitle);
sourceInfos.add(sourceInfo);
SWFList list = new SWFList();
list.sourceInfo = sourceInfo;

View File

@@ -731,6 +731,7 @@ public abstract class MainFrameMenu implements MenuBuilder {
boolean hasDebugger = hasAbc && DebuggerTools.hasDebugger(swf);
MainPanel mainPanel = mainFrame.getPanel();
boolean swfLoaded = mainPanel != null ? !mainPanel.getSwfs().isEmpty() : false;
boolean swfIsNew = swfSelected && swf.swfList != null && swf.swfList.sourceInfo.isEmpty();
setMenuEnabled("_/open", !isWorking);
setMenuEnabled("/file/open", !isWorking);
@@ -743,7 +744,7 @@ public abstract class MainFrameMenu implements MenuBuilder {
setMenuEnabled("/file/close", swfSelected && !isWorking);
setMenuEnabled("_/closeAll", swfLoaded && !isWorking);
setMenuEnabled("/file/closeAll", swfLoaded && !isWorking);
setMenuEnabled("/file/reload", swfSelected && !isWorking);
setMenuEnabled("/file/reload", swfSelected && !swfIsNew && !isWorking);
setMenuEnabled("/file/export", swfSelected);
setMenuEnabled("_/exportAll", swfSelected && !isWorking);