Skip to content

Instantly share code, notes, and snippets.

@Naatan
Created November 8, 2013 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Naatan/7375126 to your computer and use it in GitHub Desktop.
Save Naatan/7375126 to your computer and use it in GitHub Desktop.
Komodo Macro API Concept (pseudo-code)
api.macro.register({
id: "executeAsPHP",
execute: function() {
var selection = api.editor.getSelectedContents() || api.editor.getEditorContents();
var tempFile = api.files.writeTempFile(selection);
api.commands.executeAndOutput("php -d display_errors=true " + tempFile.path);
},
onStartup: function() {
var macro = this;
api.menu.addItem("editorContextMenu",
{
type: "menuitem",
menu: "editorContextMenu",
label: "Execute as PHP",
execute: macro.execute(),
enabled: function() { return true; }
});
}
});
api.macro.register({
id: "showRevisions",
execute: function() {
this.showDialog();
},
onStartup: function() {
var macro = this;
api.menu.addItem("editorContextMenu",
{
label: "Show File Revisions",
execute: macro.execute(),
enabled: function() {
return api.editor.file.vcs == 'git';
}
});
api.toolbar.addButton("toolbarId",
{
icon: "chrome://icomoon/icon.png",
label: "Show File Revisions",
execute: macro.execute(),
enabled: function() {
return api.editor.file.vcs == 'git';
}
});
},
showDialog: function() {
// This would be a new type of tool that allows you to create UI elements (ie. write out xul/html)
api.macro.openDialog("RevisionListDialog", this.RevisionListDialog /* scope for dialog */);
/* Contents of RevisionListDialog tool:
<ul id="list"></ul>
*/
},
RevisionListDialog: {
onStartup: function() {
var file = api.editor.file;
var command =
'git log \
--pretty=format:\'{%n "commit": "%H",%n "author": "%an <%ae>",%n "date": "%ad",%n "message": "%f"%n},\' \
' + file.path + ' | \
perl -pe \'BEGIN{print "["}; END{print "]\n"}\' | \
perl -pe \'s/},]/}]/\'';
api.commands.execute(command, function(output) {
var entries = JSON.parse(output);
var list = api.jq("#list", this.window);
for (let [,entry] in Iterator(entries)) {
list.append("<li>" + entry.commit + " - " + entry.message +
", by " + entry.author + " at " + entry.date + "</li>");
}
}.bind(this));
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment