For the first question you could solve calling different commands in your config file:
<ext:commandextensions>
<ext:commands>
<ext:command name="SaveNew" extendingcommand="BotonSaveNew" />
<ext:command name="Save" extendingcommand="BotonSave" />
<ext:command name="SaveClose" extendingcommand="BotonSaveClose" />
<ext:command name="Publish" extendingcommand="SecurePublish" />
<ext:command name="UnPublish" extendingcommand="SecurePublish" />
</ext:commands>
<ext:dependencies>
<cfg:dependency>Extensions.ValidateFields.comands</cfg:dependency>
</ext:dependencies>
</ext:commandextensions>
...
<commands>
<cfg:commandset id="Extensions.ValidateFields.Interfaz">
<cfg:command name="BotonSaveNew" implementation="Extensions.ValidateFields.BotonSaveNew"/>
<cfg:command name="BotonSave" implementation="Extensions.ValidateFields.BotonSave"/>
<cfg:command name="BotonSaveClose" implementation="Extensions.ValidateFields.BotonSaveClose"/>
<cfg:command name="SecurePublish" implementation="Extensions.ValidateFields.SecurePublish"/>
</cfg:commandset>
</commands>
Then in a unique js file define those commands:
Extensions.ValidateFields.BotonSaveNew = function BotonSaveNew() {
Type.enableInterface(this, "Extensions.ValidateFields.BotonSaveNew");
this.addInterface("Tridion.Cme.Command", ["BotonSaveNew"]);
console.log("Extensions.ValidateFields.BotonSaveNew");
};
Extensions.ValidateFields.BotonSave = function BotonSave() {
Type.enableInterface(this, "Extensions.ValidateFields.BotonSave");
this.addInterface("Tridion.Cme.Command", ["BotonSave"]);
console.log("Extensions.ValidateFields.BotonSave");
};
...
And finally in the same js file, define your function:
Extensions.ValidateFields.BotonSave.prototype._execute = function BotonSave$_execute(selection, pipeline) {
var error = false;
error = YourFunction();
if (!error) return $cme.getCommand("Save")._execute(selection, pipeline);
};
Extensions.ValidateFields.BotonSaveClose.prototype._execute = function BotonSaveClose$_execute(selection, pipeline) {
var error = false;
error = YourFunction();
if (!error) return $cme.getCommand("SaveClose")._execute(selection, pipeline);
};
...
function YourFunction() {
//your voodoo magic...
}
For the second question Im not pretty sure but I think you could extend the checkin:
...
<ext:commands>
<ext:command name="CheckIn" extendingcommand="ExtendCheckIn" />
</ext:commands>
...
Other aproach is tho make those validations in the event system despite a GUI extension.