Added new files to Makefile. Added underscores to private members in HistoryRecordingService.
parent
53cfe68afa
commit
853891aeaf
2
Makefile
2
Makefile
|
@ -19,10 +19,12 @@ JS_FILES=\
|
||||||
svgutils.js \
|
svgutils.js \
|
||||||
sanitize.js \
|
sanitize.js \
|
||||||
history.js \
|
history.js \
|
||||||
|
historyrecording.js \
|
||||||
coords.js \
|
coords.js \
|
||||||
recalculate.js \
|
recalculate.js \
|
||||||
select.js \
|
select.js \
|
||||||
draw.js \
|
draw.js \
|
||||||
|
layer.js \
|
||||||
path.js \
|
path.js \
|
||||||
svgcanvas.js \
|
svgcanvas.js \
|
||||||
svg-editor.js \
|
svg-editor.js \
|
||||||
|
|
|
@ -5,8 +5,6 @@
|
||||||
*
|
*
|
||||||
* Licensed under the MIT License
|
* Licensed under the MIT License
|
||||||
*
|
*
|
||||||
* Copyright(c) 2010 Alexis Deveria
|
|
||||||
* Copyright(c) 2010 Jeff Schiller
|
|
||||||
* Copyright(c) 2016 Flint O'Brien
|
* Copyright(c) 2016 Flint O'Brien
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -24,9 +22,11 @@ var history = svgedit.history;
|
||||||
/**
|
/**
|
||||||
* History recording service.
|
* History recording service.
|
||||||
*
|
*
|
||||||
* A <strong>single</strong> service object that can be passed around to provide history
|
* A self-contained service interface for recording history. Once injected, no other dependencies
|
||||||
* recording. There is a simple start/end interface for batch commands.
|
* or globals are required (example: UndoManager, command types, etc.). Easy to mock for unit tests.
|
||||||
* Easy to mock for unit tests. Built on top of history classes in history.js.
|
* Built on top of history classes in history.js.
|
||||||
|
*
|
||||||
|
* There is a simple start/end interface for batch commands.
|
||||||
*
|
*
|
||||||
* HistoryRecordingService.NO_HISTORY is a singleton that can be passed in to functions
|
* HistoryRecordingService.NO_HISTORY is a singleton that can be passed in to functions
|
||||||
* that record history. This helps when the caller requires that no history be recorded.
|
* that record history. This helps when the caller requires that no history be recorded.
|
||||||
|
@ -58,9 +58,9 @@ var history = svgedit.history;
|
||||||
* See singleton: HistoryRecordingService.NO_HISTORY
|
* See singleton: HistoryRecordingService.NO_HISTORY
|
||||||
*/
|
*/
|
||||||
var HistoryRecordingService = history.HistoryRecordingService = function(undoManager) {
|
var HistoryRecordingService = history.HistoryRecordingService = function(undoManager) {
|
||||||
this.undoManager = undoManager;
|
this.undoManager_ = undoManager;
|
||||||
this.currentBatchCommand = null;
|
this.currentBatchCommand_ = null;
|
||||||
this.batchCommandStack = [];
|
this.batchCommandStack_ = [];
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -77,9 +77,9 @@ HistoryRecordingService.NO_HISTORY = new HistoryRecordingService();
|
||||||
* @returns {svgedit.history.HistoryRecordingService}
|
* @returns {svgedit.history.HistoryRecordingService}
|
||||||
*/
|
*/
|
||||||
HistoryRecordingService.prototype.startBatchCommand = function(text) {
|
HistoryRecordingService.prototype.startBatchCommand = function(text) {
|
||||||
if (!this.undoManager) {return this;}
|
if (!this.undoManager_) {return this;}
|
||||||
this.currentBatchCommand = new history.BatchCommand(text);
|
this.currentBatchCommand_ = new history.BatchCommand(text);
|
||||||
this.batchCommandStack.push(this.currentBatchCommand);
|
this.batchCommandStack_.push(this.currentBatchCommand_);
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -88,13 +88,13 @@ HistoryRecordingService.prototype.startBatchCommand = function(text) {
|
||||||
* @returns {svgedit.history.HistoryRecordingService}
|
* @returns {svgedit.history.HistoryRecordingService}
|
||||||
*/
|
*/
|
||||||
HistoryRecordingService.prototype.endBatchCommand = function() {
|
HistoryRecordingService.prototype.endBatchCommand = function() {
|
||||||
if (!this.undoManager) {return this;}
|
if (!this.undoManager_) {return this;}
|
||||||
if (this.currentBatchCommand) {
|
if (this.currentBatchCommand_) {
|
||||||
var batchCommand = this.currentBatchCommand;
|
var batchCommand = this.currentBatchCommand_;
|
||||||
this.batchCommandStack.pop();
|
this.batchCommandStack_.pop();
|
||||||
var length = this.batchCommandStack.length;
|
var length = this.batchCommandStack_.length;
|
||||||
this.currentBatchCommand = length ? this.batchCommandStack[length-1] : null;
|
this.currentBatchCommand_ = length ? this.batchCommandStack_[length-1] : null;
|
||||||
this._addCommand(batchCommand);
|
this.addCommand_(batchCommand);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
@ -108,8 +108,8 @@ HistoryRecordingService.prototype.endBatchCommand = function() {
|
||||||
* @returns {svgedit.history.HistoryRecordingService}
|
* @returns {svgedit.history.HistoryRecordingService}
|
||||||
*/
|
*/
|
||||||
HistoryRecordingService.prototype.moveElement = function(elem, oldNextSibling, oldParent, text) {
|
HistoryRecordingService.prototype.moveElement = function(elem, oldNextSibling, oldParent, text) {
|
||||||
if (!this.undoManager) {return this;}
|
if (!this.undoManager_) {return this;}
|
||||||
this._addCommand(new history.MoveElementCommand(elem, oldNextSibling, oldParent, text));
|
this.addCommand_(new history.MoveElementCommand(elem, oldNextSibling, oldParent, text));
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -120,8 +120,8 @@ HistoryRecordingService.prototype.moveElement = function(elem, oldNextSibling, o
|
||||||
* @returns {svgedit.history.HistoryRecordingService}
|
* @returns {svgedit.history.HistoryRecordingService}
|
||||||
*/
|
*/
|
||||||
HistoryRecordingService.prototype.insertElement = function(elem, text) {
|
HistoryRecordingService.prototype.insertElement = function(elem, text) {
|
||||||
if (!this.undoManager) {return this;}
|
if (!this.undoManager_) {return this;}
|
||||||
this._addCommand(new history.InsertElementCommand(elem, text));
|
this.addCommand_(new history.InsertElementCommand(elem, text));
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -135,8 +135,8 @@ HistoryRecordingService.prototype.insertElement = function(elem, text) {
|
||||||
* @returns {svgedit.history.HistoryRecordingService}
|
* @returns {svgedit.history.HistoryRecordingService}
|
||||||
*/
|
*/
|
||||||
HistoryRecordingService.prototype.removeElement = function(elem, oldNextSibling, oldParent, text) {
|
HistoryRecordingService.prototype.removeElement = function(elem, oldNextSibling, oldParent, text) {
|
||||||
if (!this.undoManager) {return this;}
|
if (!this.undoManager_) {return this;}
|
||||||
this._addCommand(new history.RemoveElementCommand(elem, oldNextSibling, oldParent, text));
|
this.addCommand_(new history.RemoveElementCommand(elem, oldNextSibling, oldParent, text));
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -149,8 +149,8 @@ HistoryRecordingService.prototype.removeElement = function(elem, oldNextSibling,
|
||||||
* @returns {svgedit.history.HistoryRecordingService}
|
* @returns {svgedit.history.HistoryRecordingService}
|
||||||
*/
|
*/
|
||||||
HistoryRecordingService.prototype.changeElement = function(elem, attrs, text) {
|
HistoryRecordingService.prototype.changeElement = function(elem, attrs, text) {
|
||||||
if (!this.undoManager) {return this;}
|
if (!this.undoManager_) {return this;}
|
||||||
this._addCommand(new history.ChangeElementCommand(elem, attrs, text));
|
this.addCommand_(new history.ChangeElementCommand(elem, attrs, text));
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -160,12 +160,12 @@ HistoryRecordingService.prototype.changeElement = function(elem, attrs, text) {
|
||||||
* @returns {svgedit.history.HistoryRecordingService}
|
* @returns {svgedit.history.HistoryRecordingService}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
HistoryRecordingService.prototype._addCommand = function(cmd) {
|
HistoryRecordingService.prototype.addCommand_ = function(cmd) {
|
||||||
if (!this.undoManager) {return this;}
|
if (!this.undoManager_) {return this;}
|
||||||
if (this.currentBatchCommand) {
|
if (this.currentBatchCommand_) {
|
||||||
this.currentBatchCommand.addSubCommand(cmd);
|
this.currentBatchCommand_.addSubCommand(cmd);
|
||||||
} else {
|
} else {
|
||||||
this.undoManager.addCommandToHistory(cmd);
|
this.undoManager_.addCommandToHistory(cmd);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue