выводит сообщение типа Код отформатирован, и стирает документ.
function CodeBeautifier() {
CodeBeautifier = function(options) {
this.program = "c:\\phpCB.exe";
this.options = options || [ ];
this.temporaryExtension = ".pbftmp";
this.temporaryFileName = ScriptFullName + this.temporaryExtension;
}
var self = CodeBeautifier.prototype;
self.beautifyFile = function(fileName) {
if (!fileName) fileName = document.FullName;
var command =
[
"cmd /c",
this.program,
this.options.join(" "),
'"' + fileName + '"',
'> "' + this.temporaryFileName + '"'
].join(" ");
var shell = new ActiveXObject("WScript.Shell");
shell.Run(command, 7, true);
return this.temporaryFileName;
}
self.beautifyDocument = function(doc) {
if (!doc) doc = document;
if (!doc.Saved) throw "Не сохраняется!";
var tmp = this.beautifyFile(doc.FullName);
doc.selection.SelectAll();
doc.selection.InsertFromFile(tmp, doc.Encoding, 0);
var fso = new ActiveXObject("Scripting.FileSystemObject");
fso.DeleteFile(tmp);
}
} CodeBeautifier();
var beautifier = new CodeBeautifier();
/* Настройки здесь */
beautifier.options = [
// "--space-after-start-bracket",
// "--space-before-end-bracket",
"--space-after-if",
"--space-after-switch",
"--space-after-while",
"--space-before-start-angle-bracket",
"--space-after-end-angle-bracket",
"--extra-padding-for-case-statement",
"--one-true-brace-function-declaration",
"--glue-amperscore",
"--change-shell-comment-to-double-slashes-comment",
// "--indent-with-tab",
"--force-large-php-code-tag",
"--force-true-false-null-contant-lowercase",
"--align-equal-statements",
// "--align-equal-statements-to-fixed-pos",
"--equal-align-position 50",
"--comment-rendering-style PEAR",
"--padding-char-count 4",
"--optimize-eol"
];
/* Настройки здесь */
if (!document.Saved) {
if (confirm("Документ не сохранен\n Сохранить?")) {
try {
document.Save(document.FullName);
} catch(e) {
alert("Не удалось сохранить!");
Quit();
}
} else {
Quit();
}
}
beautifier.beautifyDocument();
document.selection.StartOfDocument();
//alert("Полностью отформатирован!");