Add printing. Fixes #120

This commit is contained in:
Thomas Wilburn 2014-01-20 09:10:24 -08:00
parent 0b2aaf1883
commit 1767cd3fc2
2 changed files with 21 additions and 0 deletions

View file

@ -8,6 +8,7 @@
{ "label": "Save As", "command": "session:save-file-as" },
{ "label": "Revert", "command": "session:revert-file" },
{ "label": "Close", "command": "session:close-tab" },
{ "label": "Print", "command": "editor:print" },
{ "label": "Exit", "command": "app:exit" }
]
},

View file

@ -84,6 +84,26 @@ define([
//disable focusing on the editor except by program
document.find("textarea").setAttribute("tabindex", -1);
command.on("editor:print", function(c) {
ace.require("ace/config").loadModule("ace/ext/static_highlight", function(static) {
var session = editor.getSession();
var printable = static.renderSync(session.getValue(), session.getMode(), editor.renderer.theme);
var iframe = document.createElement("iframe");
var css = "<style>" + printable.css + "</style>";
var doc = css + printable.html;
iframe.srcdoc = doc;
iframe.width = iframe.height = 1;
iframe.style.display = "none";
document.body.append(iframe);
setTimeout(function() {
iframe.contentWindow.print();
setTimeout(function() {
iframe.remove();
})
});
});
});
return editor;
});