What I did in an extension where I had different behaviors depending on whether you clicked Save
, SaveClose
or SaveNew
was to:
- Register my commands as extensions of the existing commands:
<ext:commands>
<ext:command name="Save" extendingcommand="ReleaseValidationOnSave"/>
<ext:command name="SaveClose" extendingcommand="ReleaseValidationOnSaveClose"/>
<ext:command name="SaveNew" extendingcommand="ReleaseValidationOnSaveNew"/>
</ext:commands>
- Then on each of those methods that would be called I would set a variable identifying which was the original command
CompanyName.Extensions.ReleaseValidationOnSaveClose.prototype._execute = function ReleaseValidationOnSaveClose$_execute(selection, pipeline) {
if (!this.properties.InitialCommand) {
this.properties.InitialCommand = "SaveClose";
}
return $cme.getCommand("ReleaseValidationOnSave")._execute(selection, pipeline, this.properties.InitialCommand);
};
- Finally, on my "ReleaseValidationOnSave" code I would check the value of
this.properties.InitialCommand
and let the UI resume that command's execution:
// This function is triggered by the event "finish"
// It invokes the original command intended by the editor
CompanyName.Extensions.ReleaseValidationOnSave.prototype._onResumeExecution = function ReleaseValidationOnSave$_onResumeExecution() {
$evt.removeAllEventHandlers(this, "finish");
var p = this.properties;
$cme.getCommand(p.InitialCommand)._execute(p.selection, p.pipeline);
};
Basically this allowed me to "inject" my command before the UI's own, and also let me invoke the original command once my code was done running.