diff --git a/.gitignore b/.gitignore index 813d6c10..c6a7ecc9 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ # Project files that should not be in the repo .* +\#* !/.gitignore .*.gz *.tmTheme.js diff --git a/demo/kitchen-sink/demo.js b/demo/kitchen-sink/demo.js index ec5718db..aa6e9096 100644 --- a/demo/kitchen-sink/demo.js +++ b/demo/kitchen-sink/demo.js @@ -36,6 +36,9 @@ require("ace/lib/fixoldbrowsers"); require("ace/multi_select") require("ace/ext/spellcheck"); +require("./inline_editor"); +require("./dev_util"); +require("./file_drop"); var config = require("ace/config"); config.init(); @@ -58,6 +61,8 @@ var Editor = require("ace/editor").Editor; var whitespace = require("ace/ext/whitespace"); + + var doclist = require("./doclist"); var modelist = require("ace/ext/modelist"); var layout = require("./layout"); @@ -532,112 +537,6 @@ bindCheckbox("highlight_token", function(checked) { } }); - -/************** dragover ***************************/ -event.addListener(container, "dragover", function(e) { - var types = e.dataTransfer.types; - if (types && Array.prototype.indexOf.call(types, 'Files') !== -1) - return event.preventDefault(e); -}); - -event.addListener(container, "drop", function(e) { - var file; - try { - file = e.dataTransfer.files[0]; - if (window.FileReader) { - var reader = new FileReader(); - reader.onload = function() { - var mode = modelist.getModeForPath(file.name); - - env.editor.session.doc.setValue(reader.result); - modeEl.value = mode.name; - env.editor.session.setMode(mode.mode); - env.editor.session.modeName = mode.name; - }; - reader.readAsText(file); - } - return event.preventDefault(e); - } catch(err) { - return event.stopEvent(e); - } -}); - - -var LineWidgets = require("ace/line_widgets").LineWidgets; - -env.editor.commands.addCommand({ - name: "foo", - bindKey: "F2|F3", - exec: function(editor) { - var Editor = require("ace/editor").Editor - var Renderer = require("ace/virtual_renderer").VirtualRenderer - var split = env.split - var s = editor.session - var inlineEditor = new Editor(new Renderer()) - var splitSession = split.$cloneSession(s) - - var row = editor.getCursorPosition().row - if (editor.session.lineWidgets && editor.session.lineWidgets[row]) { - editor.session.lineWidgets[row].destroy(); - return; - } - - var rowCount = 10; - var w = { - row: row, - // rowCount: rowCount, - fixedWidth: true, - el: dom.createElement("div"), - editor: editor - }; - var el = w.el; - el.appendChild(inlineEditor.container); - - if (!editor.session.widgetManager) { - editor.session.widgetManager = new LineWidgets(editor.session); - editor.session.widgetManager.attach(editor); - } - - var h = rowCount*editor.renderer.layerConfig.lineHeight; - inlineEditor.container.style.height = h + "px" - - el.style.position = "absolute" - el.style.zIndex = "4" - el.style.borderTop = "solid blue 2px" - el.style.borderBottom = "solid blue 2px" - - inlineEditor.setSession(splitSession) - editor.session.widgetManager.addLineWidget(w); - - var kb = { - handleKeyboard:function(_,hashId, keyString) { - if (hashId == 0 && keyString == "esc") { - w.destroy(); - return true; - } - } - } - - w.destroy = function() { - editor.keyBinding.removeKeyboardHandler(kb); - s.widgetManager.removeLineWidget(w); - } - - editor.keyBinding.addKeyboardHandler(kb) - inlineEditor.keyBinding.addKeyboardHandler(kb) - editor.on("changeSession", function(e) { - w.el.parentNode && w.el.parentNode.removeChild(w.el) - }); - inlineEditor.setTheme("ace/theme/solarized_light") - } -}) - -env.editor.commands.addCommand({ - -}) - - - var StatusBar = require("ace/ext/statusbar").StatusBar; new StatusBar(env.editor, cmdLine.container); @@ -689,48 +588,4 @@ env.editor.setOptions({ enableBasicAutocompletion: true, enableSnippets: true }) -/* for textinput debuggging -dom.importCssString("\ - .ace_text-input {\ - position: absolute;\ - z-index: 10!important;\ - width: 6em!important;\ - height: 1em;\ - opacity: 1!important;\ - background: rgba(0, 92, 255, 0.11);\ - border: none;\ - font: inherit;\ - padding: 0 1px;\ - margin: 0 -1px;\ - text-indent: 0em;\ -}\ -")*/ -}); - -// allow easy access to ace in console, but not in ace code which uses strict -void function() { -function isStrict() { - try { return !arguments.callee.caller.caller.caller} - catch(e){ return true } -} -function warn() { - if (isStrict()) { - console.error("trying to access to global variable"); - } -} -function def(o, key, get) { - Object.defineProperty(o, key, { - configurable: true, - get: get, - set: function(val) { - delete o[key]; - o[key] = val; - } - }); -} -def(window, "ace", function(){ warn(); return env.editor }); -def(window, "editor", function(){ warn(); return env.editor }); -def(window, "session", function(){ warn(); return env.editor.session }); -def(window, "split", function(){ warn(); return env.split }); - -}(); \ No newline at end of file +}); \ No newline at end of file diff --git a/demo/kitchen-sink/dev_util.js b/demo/kitchen-sink/dev_util.js new file mode 100644 index 00000000..2ed12c43 --- /dev/null +++ b/demo/kitchen-sink/dev_util.js @@ -0,0 +1,75 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Distributed under the BSD license: + * + * Copyright (c) 2010, Ajax.org B.V. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Ajax.org B.V. nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ***** END LICENSE BLOCK ***** */ + +define(function(require, exports, module) { +// allow easy access to ace in console, but not in ace code which uses strict +function isStrict() { + try { return !arguments.callee.caller.caller.caller} + catch(e){ return true } +} +function warn() { + if (isStrict()) { + console.error("trying to access to global variable"); + } +} +function def(o, key, get) { + Object.defineProperty(o, key, { + configurable: true, + get: get, + set: function(val) { + delete o[key]; + o[key] = val; + } + }); +} +def(window, "ace", function(){ warn(); return env.editor }); +def(window, "editor", function(){ warn(); return env.editor }); +def(window, "session", function(){ warn(); return env.editor.session }); +def(window, "split", function(){ warn(); return env.split }); + + +/* for textinput debuggging +dom.importCssString("\ + .ace_text-input {\ + position: absolute;\ + z-index: 10!important;\ + width: 6em!important;\ + height: 1em;\ + opacity: 1!important;\ + background: rgba(0, 92, 255, 0.11);\ + border: none;\ + font: inherit;\ + padding: 0 1px;\ + margin: 0 -1px;\ + text-indent: 0em;\ +}\ +")*/ + +}); diff --git a/demo/kitchen-sink/file_drop.js b/demo/kitchen-sink/file_drop.js new file mode 100644 index 00000000..dde70138 --- /dev/null +++ b/demo/kitchen-sink/file_drop.js @@ -0,0 +1,73 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Distributed under the BSD license: + * + * Copyright (c) 2010, Ajax.org B.V. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Ajax.org B.V. nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ***** END LICENSE BLOCK ***** */ + +define(function(require, exports, module) { + +var config = require("ace/config"); +var event = require("ace/lib/event"); +var modelist = require("ace/ext/modelist"); + +module.exports = function(editor) { + event.addListener(editor.container, "dragover", function(e) { + var types = e.dataTransfer.types; + if (types && Array.prototype.indexOf.call(types, 'Files') !== -1) + return event.preventDefault(e); + }); + + event.addListener(editor.container, "drop", function(e) { + var file; + try { + file = e.dataTransfer.files[0]; + if (window.FileReader) { + var reader = new FileReader(); + reader.onload = function() { + var mode = modelist.getModeForPath(file.name); + editor.session.doc.setValue(reader.result); + editor.session.setMode(mode.mode); + editor.session.modeName = mode.name; + }; + reader.readAsText(file); + } + return event.preventDefault(e); + } catch(err) { + return event.stopEvent(e); + } + }); +} + +var Editor = require("ace/editor").Editor; +config.defineOptions(Editor.prototype, "editor", { + loadDroppedFile: { + set: function() { module.exports(this); }, + value: true + } +}); + +}); \ No newline at end of file diff --git a/demo/kitchen-sink/inline_editor.js b/demo/kitchen-sink/inline_editor.js new file mode 100644 index 00000000..5b06174d --- /dev/null +++ b/demo/kitchen-sink/inline_editor.js @@ -0,0 +1,105 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Distributed under the BSD license: + * + * Copyright (c) 2010, Ajax.org B.V. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Ajax.org B.V. nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ***** END LICENSE BLOCK ***** */ + + +define(function(require, exports, module) { +"use strict"; + +var LineWidgets = require("ace/line_widgets").LineWidgets; +var Editor = require("ace/editor").Editor +var Renderer = require("ace/virtual_renderer").VirtualRenderer +var dom = require("ace/lib/dom"); + + +require("ace/commands/default_commands").commands.push({ + name: "openInlineEditor", + bindKey: "F3", + exec: function(editor) { + var split = env.split + var s = editor.session + var inlineEditor = new Editor(new Renderer()) + var splitSession = split.$cloneSession(s) + + var row = editor.getCursorPosition().row + if (editor.session.lineWidgets && editor.session.lineWidgets[row]) { + editor.session.lineWidgets[row].destroy(); + return; + } + + var rowCount = 10; + var w = { + row: row, + // rowCount: rowCount, + fixedWidth: true, + el: dom.createElement("div"), + editor: editor + }; + var el = w.el; + el.appendChild(inlineEditor.container); + + if (!editor.session.widgetManager) { + editor.session.widgetManager = new LineWidgets(editor.session); + editor.session.widgetManager.attach(editor); + } + + var h = rowCount*editor.renderer.layerConfig.lineHeight; + inlineEditor.container.style.height = h + "px" + + el.style.position = "absolute" + el.style.zIndex = "4" + el.style.borderTop = "solid blue 2px" + el.style.borderBottom = "solid blue 2px" + + inlineEditor.setSession(splitSession) + editor.session.widgetManager.addLineWidget(w); + + var kb = { + handleKeyboard:function(_,hashId, keyString) { + if (hashId == 0 && keyString == "esc") { + w.destroy(); + return true; + } + } + } + + w.destroy = function() { + editor.keyBinding.removeKeyboardHandler(kb); + s.widgetManager.removeLineWidget(w); + } + + editor.keyBinding.addKeyboardHandler(kb) + inlineEditor.keyBinding.addKeyboardHandler(kb) + editor.on("changeSession", function(e) { + w.el.parentNode && w.el.parentNode.removeChild(w.el) + }); + inlineEditor.setTheme("ace/theme/solarized_light") + } +}) +});