Skip to content

Commit

Permalink
show unsaved changes for document
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksandr Bardanov committed Aug 14, 2014
1 parent 4164742 commit 007b14b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 7 deletions.
4 changes: 4 additions & 0 deletions styles/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion templates/holder.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<i class="fa fa-folder-open-o"></i>
</span>
<span data-bind="foreach: documents">
<span class="document" data-bind="css:{selected: $parent.selected() === $data}, click: $parent.onDocumentClick">
<span class="document" data-bind="css:{selected: $data._path === $parent.selectedPath(), changed: $parent.isChanged($data)}, click: $parent.onDocumentClick">
<span class="document-icon" data-bind="css: $parent.getDocumentIcon($data), style:{color: $parent.getDocumentIconColor($data)}"></span>
<span class="document-name" data-bind="text: $data._name"></span>
<span class="document-close" data-bind="click: $parent.onDocumentClose">
Expand Down
52 changes: 46 additions & 6 deletions viewmodels/documents.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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();
}
Expand All @@ -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);
}
Expand All @@ -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){
Expand All @@ -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(){
Expand Down

0 comments on commit 007b14b

Please sign in to comment.