do not overwrite ipython file if cell content is identical

This commit is contained in:
Ekaterina Tuzova
2016-02-29 20:05:46 +03:00
parent da97e4ed9e
commit 71d74888b4
4 changed files with 69 additions and 3 deletions
@@ -105,6 +105,7 @@ public class IpnbFilePanel extends JPanel implements Scrollable, DataProvider, D
try {
IpnbFile file = IpnbParser.parseIpnbFile(myDocument, myVirtualFile);
if (file.equals(myIpnbFile)) return;
removeAll();
myIpnbFile = file;
myIpnbPanels.clear();
mySelectedCell = null;
@@ -348,7 +349,6 @@ public class IpnbFilePanel extends JPanel implements Scrollable, DataProvider, D
final IpnbEditablePanel selectedCell = getSelectedCell();
final int index = myIpnbPanels.indexOf(selectedCell);
myInitialSelection = index >= 0 && index < myIpnbPanels.size() ? index : myIpnbPanels.size() - 1;
removeAll();
readFromFile(false);
}
}
@@ -10,9 +10,9 @@ public class IpnbFile {
private final Map<String, Object> myMetadata;
private final int myNbformat;
private final List<IpnbCell> myCells;
private final String myPath;
@NotNull private final String myPath;
public IpnbFile(Map<String, Object> metadata, int nbformat, List<IpnbCell> cells, String path) {
public IpnbFile(Map<String, Object> metadata, int nbformat, List<IpnbCell> cells, @NotNull String path) {
myMetadata = metadata;
myNbformat = nbformat;
myCells = cells;
@@ -31,6 +31,7 @@ public class IpnbFile {
myCells.remove(index);
}
@NotNull
public String getPath() {
return myPath;
}
@@ -43,4 +44,27 @@ public class IpnbFile {
return myNbformat;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
IpnbFile file = (IpnbFile)o;
if (myNbformat != file.myNbformat) return false;
if (myMetadata != null ? !myMetadata.equals(file.myMetadata) : file.myMetadata != null) return false;
if (myCells != null ? !myCells.equals(file.myCells) : file.myCells != null) return false;
if (!myPath.equals(file.myPath)) return false;
return true;
}
@Override
public int hashCode() {
int result = myMetadata != null ? myMetadata.hashCode() : 0;
result = 31 * result + myNbformat;
result = 31 * result + (myCells != null ? myCells.hashCode() : 0);
result = 31 * result + (myPath.hashCode());
return result;
}
}
@@ -34,4 +34,24 @@ public abstract class IpnbEditableCell implements IpnbCell {
public Map<String, Object> getMetadata() {
return myMetadata;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
IpnbEditableCell cell = (IpnbEditableCell)o;
if (!mySource.equals(cell.mySource)) return false;
if (myMetadata != null ? !myMetadata.equals(cell.myMetadata) : cell.myMetadata != null) return false;
return true;
}
@Override
public int hashCode() {
int result = mySource.hashCode();
result = 31 * result + (myMetadata != null ? myMetadata.hashCode() : 0);
return result;
}
}
@@ -37,4 +37,26 @@ public class IpnbOutputCell implements IpnbCell {
public Map<String, Object> getMetadata() {
return myMetadata;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
IpnbOutputCell cell = (IpnbOutputCell)o;
if (myPromptNumber != null ? !myPromptNumber.equals(cell.myPromptNumber) : cell.myPromptNumber != null) return false;
if (myText != null ? !myText.equals(cell.myText) : cell.myText != null) return false;
if (myMetadata != null ? !myMetadata.equals(cell.myMetadata) : cell.myMetadata != null) return false;
return true;
}
@Override
public int hashCode() {
int result = myPromptNumber != null ? myPromptNumber.hashCode() : 0;
result = 31 * result + (myText != null ? myText.hashCode() : 0);
result = 31 * result + (myMetadata != null ? myMetadata.hashCode() : 0);
return result;
}
}