From 1767cd3fc265b4ca990ad104d7fe9aac112f5b94 Mon Sep 17 00:00:00 2001 From: Thomas Wilburn Date: Mon, 20 Jan 2014 09:10:24 -0800 Subject: [PATCH] Add printing. Fixes #120 --- config/menus.json | 1 + js/editor.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/config/menus.json b/config/menus.json index 69b063f..a6d8aa4 100644 --- a/config/menus.json +++ b/config/menus.json @@ -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" } ] }, diff --git a/js/editor.js b/js/editor.js index a68d008..85ec8e3 100644 --- a/js/editor.js +++ b/js/editor.js @@ -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 = ""; + 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; }); \ No newline at end of file