From 9a6fbf5652979cbdf11f0be3ff9a01f824b174e6 Mon Sep 17 00:00:00 2001
From: Hallvard Traetteberg <hal@ntnu.no>
Date: Tue, 30 Jan 2018 11:39:24 +0100
Subject: [PATCH] Fixed bug, document location wasn't set when opening
 document.

---
 .../tdt4140/gr1800/app/core/DocumentStorageImpl.java     | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/tdt4140-gr1800/app.core/src/main/java/tdt4140/gr1800/app/core/DocumentStorageImpl.java b/tdt4140-gr1800/app.core/src/main/java/tdt4140/gr1800/app/core/DocumentStorageImpl.java
index 9314f27..4e91dfa 100644
--- a/tdt4140-gr1800/app.core/src/main/java/tdt4140/gr1800/app/core/DocumentStorageImpl.java
+++ b/tdt4140-gr1800/app.core/src/main/java/tdt4140/gr1800/app/core/DocumentStorageImpl.java
@@ -31,6 +31,7 @@ public abstract class DocumentStorageImpl<D, L> implements IDocumentStorage<L> {
 	@Override
 	public void openDocument(L storage) throws IOException {
 		setDocument(loadDocument(storage));
+		setDocumentLocation(storage);
 	}
 
 	@Override
@@ -39,8 +40,14 @@ public abstract class DocumentStorageImpl<D, L> implements IDocumentStorage<L> {
 	}
 
 	public void saveDocumentAs(L documentLocation) throws IOException {
+		L oldDocumentLocation = getDocumentLocation();
 		setDocumentLocation(documentLocation);
-		saveDocument();
+		try {
+			saveDocument();
+		} catch (IOException e) {
+			setDocumentLocation(oldDocumentLocation);
+			throw e;
+		}
 	}
 	
 	public void saveCopyAs(L documentLocation) throws IOException {
-- 
GitLab