Created
November 8, 2013 18:09
-
-
Save Naatan/7375126 to your computer and use it in GitHub Desktop.
Komodo Macro API Concept (pseudo-code)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | |
}); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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