diff --git a/styles/main.css b/styles/main.css
index 548c601..150f1c3 100644
--- a/styles/main.css
+++ b/styles/main.css
@@ -25,6 +25,10 @@
background: #1d1f21;
}
+.ext-documents .document.changed{
+ box-shadow: inset 0 3px 0px rgb(0, 184, 255);
+}
+
.ext-documents .document-icon{
font-size: 20px;
position: absolute;
diff --git a/templates/holder.html b/templates/holder.html
index 94ca1e2..f83dd1e 100644
--- a/templates/holder.html
+++ b/templates/holder.html
@@ -4,7 +4,7 @@
-
+
diff --git a/viewmodels/documents.js b/viewmodels/documents.js
index 2548c69..926c6b9 100644
--- a/viewmodels/documents.js
+++ b/viewmodels/documents.js
@@ -13,6 +13,10 @@ define(function(require, exports, module){
var self = this;
this.documents = ko.observableArray([]);
this.selected = ko.observable(null);
+ this.selectedPath = ko.computed(function(){
+ return this.selected() ? this.selected()._path : '';
+ }, this);
+ this.changed = ko.observableArray([]);
this.onDocumentClick = function(model){
DocumentManager.getDocumentForPath(model._path)
@@ -26,7 +30,7 @@ define(function(require, exports, module){
this.onDocumentClose = function(file, event){
DocumentManager.removeFromWorkingSet(file, false);
- self.documents.remove(file);
+ self.removeDocument(file);
event.stopPropagation();
}
@@ -50,7 +54,7 @@ define(function(require, exports, module){
if (!_.find(self.documents(), function(file){
return file === doc.file;
})){
- self.documents.push(doc.file);
+ self.addDocument(doc.file);
}
self.selected(doc.file);
}
@@ -59,12 +63,33 @@ define(function(require, exports, module){
})
}
+ this.isDocumentSelected = function(model){
+ if (self.selected() === null){
+ return false;
+ }
+ return self.selected()._path === model ? model._path : null;
+ }
+
+ this.isChanged = function(doc){
+ return _.contains(self.changed(), doc._path);
+ }
+
+ this.addDocument = function(doc){
+ this.documents.push(doc);
+ }
+
+ this.removeDocument = function(doc){
+ self.documents.remove(function(el){
+ return el._path === doc._path;
+ });
+ }
+
$DocumentManager.on('workingSetAdd', function(event, file){
- self.documents.push(file);
+ self.addDocument(file);
});
$DocumentManager.on('workingSetRemove', function(event, file){
- self.documents.remove(file);
+ self.removeDocument(file)
});
$DocumentManager.on('currentDocumentChange', function(event, newDocument){
@@ -76,19 +101,34 @@ define(function(require, exports, module){
$DocumentManager.on('workingSetAddList', function(event, files){
_.each(files, function(file){
- self.documents.push(file);
+ self.addDocument(file);
});
});
$DocumentManager.on('workingSetRemoveList', function(event, files){
_.each(files, function(file){
- self.documents.remove(file);
+ self.removeDocument(file);
});
});
$DocumentManager.on('fileNameChange', _.bind(this.handlePathChanges, this));
$DocumentManager.on('pathDeleted', _.bind(this.handlePathChanges, this));
+
+ this.isDocumentChanged = function(event, document){
+ if (document.isDirty){
+ if (_.contains(self.changed(), document.file._path)){
+ return;
+ }
+ self.changed.push(document.file._path);
+ } else {
+ self.changed.remove(document.file._path);
+ }
+ }
+
+ $DocumentManager.on('dirtyFlagChange', this.isDocumentChanged);
+
+ $DocumentManager.on('documentSaved', this.isDocumentChanged);
}
DocumentsViewModel.prototype.handlePathChanges = function(){