fixed an issue concerning keeping the main file at "save as" operation.

This commit is contained in:
hneemann 2017-05-08 10:07:39 +02:00
parent e52ea13573
commit c1c9130c4f
2 changed files with 19 additions and 1 deletions

View File

@ -110,6 +110,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
private final ScheduledThreadPoolExecutor timerExecutor = new ScheduledThreadPoolExecutor(1); private final ScheduledThreadPoolExecutor timerExecutor = new ScheduledThreadPoolExecutor(1);
private final WindowPosManager windowPosManager = new WindowPosManager(); private final WindowPosManager windowPosManager = new WindowPosManager();
private final InsertHistory insertHistory; private final InsertHistory insertHistory;
private final boolean keepPrefMainFile;
private ToolTipAction doStep; private ToolTipAction doStep;
private ToolTipAction runToBreakAction; private ToolTipAction runToBreakAction;
@ -140,6 +141,8 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
setIconImages(IconCreator.createImages("icon32.png", "icon64.png", "icon128.png")); setIconImages(IconCreator.createImages("icon32.png", "icon64.png", "icon128.png"));
keepPrefMainFile = builder.keepPrefMainFile;
if (builder.library != null) library = builder.library; if (builder.library != null) library = builder.library;
else library = new ElementLibrary(); else library = new ElementLibrary();
@ -348,6 +351,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
.setLibrary(library) .setLibrary(library)
.setCircuit(new Circuit()) .setCircuit(new Circuit())
.setBaseFileName(getBaseFileName()) .setBaseFileName(getBaseFileName())
.keepPrefMainFile()
.build() .build()
.setVisible(true); .setVisible(true);
} }
@ -391,7 +395,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
saveAsHelper.checkOverwrite( saveAsHelper.checkOverwrite(
file -> { file -> {
if (library.isFileAccessible(file)) if (library.isFileAccessible(file))
saveFile(file, false); saveFile(file, !keepPrefMainFile);
else { else {
Object[] options = {Lang.get("btn_saveAnyway"), Lang.get("btn_newName"), Lang.get("cancel")}; Object[] options = {Lang.get("btn_saveAnyway"), Lang.get("btn_newName"), Lang.get("cancel")};
int res = JOptionPane.showOptionDialog(Main.this, int res = JOptionPane.showOptionDialog(Main.this,
@ -548,6 +552,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
.setLibrary(library) .setLibrary(library)
.setCircuit(circuit) .setCircuit(circuit)
.setBaseFileName(getBaseFileName()) .setBaseFileName(getBaseFileName())
.keepPrefMainFile()
.build() .build()
.setVisible(true); .setVisible(true);
} }
@ -1201,6 +1206,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
private Circuit circuit; private Circuit circuit;
private boolean allowAllFileActions = true; private boolean allowAllFileActions = true;
private File baseFileName; private File baseFileName;
private boolean keepPrefMainFile;
/** /**
* @param fileToOpen the file to open * @param fileToOpen the file to open
@ -1258,6 +1264,16 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
return this; return this;
} }
/**
* Keeps the main file defined in the preferences
*
* @return this for chained calls
*/
public MainBuilder keepPrefMainFile() {
this.keepPrefMainFile = true;
return this;
}
/** /**
* Creates a new Main instance * Creates a new Main instance
* *
@ -1273,5 +1289,6 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
public void openLater() { public void openLater() {
SwingUtilities.invokeLater(() -> build().setVisible(true)); SwingUtilities.invokeLater(() -> build().setVisible(true));
} }
} }
} }

View File

@ -612,6 +612,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
.setFileToOpen(((ElementLibrary.ElementTypeDescriptionCustom) elementType).getFile()) .setFileToOpen(((ElementLibrary.ElementTypeDescriptionCustom) elementType).getFile())
.setLibrary(library) .setLibrary(library)
.denyMostFileActions() .denyMostFileActions()
.keepPrefMainFile()
.openLater(); .openLater();
} }
}.setToolTip(Lang.get("attr_openCircuit_tt"))); }.setToolTip(Lang.get("attr_openCircuit_tt")));