Skip to content

Commit

Permalink
library is cleared if new file is opened
Browse files Browse the repository at this point in the history
  • Loading branch information
hneemann committed Jul 11, 2016
1 parent 288b013 commit edd1b8e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/main/java/de/neemann/digital/gui/LibrarySelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,7 @@ public void actionPerformed(ActionEvent e) {
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());

Expand All @@ -114,6 +111,16 @@ public void actionPerformed(ActionEvent e) {
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)
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/de/neemann/digital/gui/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ public void actionPerformed(ActionEvent e) {
setFilename(null, true);
circuitComponent.setCircuit(new Circuit());
windowPosManager.closeAll();
librarySelector.removeCustomElements();
}
}
}.setActive(normalMode);
Expand All @@ -289,6 +290,7 @@ public void actionPerformed(ActionEvent 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);
}
}
Expand Down Expand Up @@ -776,6 +778,7 @@ public void saveChanges() {

@Override
public void open(File file) {
librarySelector.removeCustomElements();
loadFile(file, true);
}

Expand Down

0 comments on commit edd1b8e

Please sign in to comment.