Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Commit

Permalink
More code review changes:
Browse files Browse the repository at this point in the history
- Rename CSSAgent methods for clarity
- When discarding unsaved changes, revert Document contents after closing
  main editor instead of before. As a bonus, this makes it easy to skip the
  revert if the main editor was the only view attached to the Document.
  • Loading branch information
peterflynn committed Apr 5, 2012
1 parent 8b88262 commit 5cd730e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/LiveDevelopment/Agents/CSSAgent.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ define(function CSSAgent(require, exports, module) {
/** Reload a CSS style sheet from a document
* @param {Document} document
*/
function reloadDocument(doc) {
function reloadCSSForDocument(doc) {
var style = styleForURL(doc.url);
console.assert(style, "Style Sheet for document not loaded: " + doc.url);
Inspector.CSS.setStyleSheetText(style.styleSheetId, doc.getText());
Expand All @@ -63,7 +63,7 @@ define(function CSSAgent(require, exports, module) {
/** Empties a CSS style sheet given a document that has been deleted
* @param {Document} document
*/
function reloadDeletedDocument(doc) {
function clearCSSForDocument(doc) {
var style = styleForURL(doc.url);
console.assert(style, "Style Sheet for document not loaded: " + doc.url);
Inspector.CSS.setStyleSheetText(style.styleSheetId, "");
Expand All @@ -84,8 +84,8 @@ define(function CSSAgent(require, exports, module) {
// Export public functions
exports.styleForURL = styleForURL;
exports.getStylesheetURLs = getStylesheetURLs;
exports.reloadDocument = reloadDocument;
exports.reloadDeletedDocument = reloadDeletedDocument;
exports.reloadCSSForDocument = reloadCSSForDocument;
exports.clearCSSForDocument = clearCSSForDocument;
exports.load = load;
exports.unload = unload;
});
4 changes: 2 additions & 2 deletions src/LiveDevelopment/Documents/CSSDocument.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ define(function CSSDocumentModule(require, exports, module) {
/** Triggered whenever the Document is edited */
CSSDocument.prototype.onChange = function onChange(event, editor, change) {
// brute force: update the CSS
CSSAgent.reloadDocument(this.doc);
CSSAgent.reloadCSSForDocument(this.doc);
};
/** Triggered if the Document's file is deleted */
CSSDocument.prototype.onDeleted = function onDeleted(event, editor, change) {
// clear the CSS
CSSAgent.reloadDeletedDocument(this.doc);
CSSAgent.clearCSSForDocument(this.doc);

// shut down, since our Document is now dead
this.close();
Expand Down
17 changes: 9 additions & 8 deletions src/document/DocumentCommandHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,14 +433,15 @@ define(function (require, exports, module) {
// "Don't Save" case: even though we're closing the main editor, other views of
// the Document may remain in the UI. So we need to revert the Document to a clean
// copy of whatever's on disk.
doRevert(doc)
.done(function () {
doClose(file);
result.resolve();
})
.fail(function () {
result.reject();
});
doClose(file);

// Only reload from disk if other views still exist
if (DocumentManager.getOpenDocumentForPath(file.fullPath)) {
doRevert(doc)
.pipe(result.resolve, result.reject);
} else {
result.resolve();
}
}
});
result.always(function () {
Expand Down

0 comments on commit 5cd730e

Please sign in to comment.