library is cleared if new file is opened

This commit is contained in:
hneemann 2016-07-11 16:18:13 +02:00
parent 288b01388f
commit edd1b8e4cc
2 changed files with 14 additions and 4 deletions

View File

@ -89,10 +89,7 @@ public class LibrarySelector implements ElementNotFoundNotification {
customMenu.add(new ToolTipAction(Lang.get("menu_refresh")) {
@Override
public void actionPerformed(ActionEvent e) {
for (ImportedItem item : importedElements) {
library.removeElement(item.file);
customMenu.remove(item.menuEntry);
}
removeCustomElements();
}
}.setToolTip(Lang.get("menu_refresh_tt")).createJMenuItem());
@ -114,6 +111,16 @@ public class LibrarySelector implements ElementNotFoundNotification {
return parts;
}
/**
* removes all custom elements
*/
public void removeCustomElements() {
for (ImportedItem item : importedElements) {
library.removeElement(item.file);
customMenu.remove(item.menuEntry);
}
}
private String createToolTipText(String elementName) {
String toolTipText = Lang.getNull("elem_" + elementName + "_tt");
if (toolTipText == null)

View File

@ -279,6 +279,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
setFilename(null, true);
circuitComponent.setCircuit(new Circuit());
windowPosManager.closeAll();
librarySelector.removeCustomElements();
}
}
}.setActive(normalMode);
@ -289,6 +290,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
if (ClosingWindowListener.checkForSave(Main.this, Main.this)) {
JFileChooser fc = getJFileChooser(lastFilename);
if (fc.showOpenDialog(Main.this) == JFileChooser.APPROVE_OPTION) {
librarySelector.removeCustomElements();
loadFile(fc.getSelectedFile(), true);
}
}
@ -776,6 +778,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
@Override
public void open(File file) {
librarySelector.removeCustomElements();
loadFile(file, true);
}