more startup hackery to populate the environment
This commit is contained in:
parent
f61550c862
commit
9ee72169ac
2 changed files with 18 additions and 17 deletions
|
|
@ -39,7 +39,7 @@
|
||||||
|
|
||||||
define(function(require, exports, module) {
|
define(function(require, exports, module) {
|
||||||
|
|
||||||
exports.launch = function() {
|
exports.launch = function(env) {
|
||||||
|
|
||||||
var event = require("pilot/event").event;
|
var event = require("pilot/event").event;
|
||||||
var Editor = require("ace/editor").Editor;
|
var Editor = require("ace/editor").Editor;
|
||||||
|
|
@ -69,9 +69,12 @@ exports.launch = function() {
|
||||||
|
|
||||||
var docEl = document.getElementById("doc");
|
var docEl = document.getElementById("doc");
|
||||||
|
|
||||||
|
var container = document.getElementById("editor");
|
||||||
|
env.editor = new Editor(new Renderer(container, theme));
|
||||||
|
|
||||||
function onDocChange() {
|
function onDocChange() {
|
||||||
var doc = getDoc();
|
var doc = getDoc();
|
||||||
editor.setDocument(doc);
|
env.editor.setDocument(doc);
|
||||||
|
|
||||||
var mode = doc.getMode();
|
var mode = doc.getMode();
|
||||||
if (mode instanceof JavaScriptMode) {
|
if (mode instanceof JavaScriptMode) {
|
||||||
|
|
@ -90,7 +93,7 @@ exports.launch = function() {
|
||||||
modeEl.value = "text";
|
modeEl.value = "text";
|
||||||
}
|
}
|
||||||
|
|
||||||
editor.focus();
|
env.editor.focus();
|
||||||
}
|
}
|
||||||
docEl.onchange = onDocChange;
|
docEl.onchange = onDocChange;
|
||||||
|
|
||||||
|
|
@ -100,7 +103,7 @@ exports.launch = function() {
|
||||||
|
|
||||||
var modeEl = document.getElementById("mode");
|
var modeEl = document.getElementById("mode");
|
||||||
modeEl.onchange = function() {
|
modeEl.onchange = function() {
|
||||||
editor.getDocument().setMode(modes[modeEl.value] || modes.text);
|
env.editor.getDocument().setMode(modes[modeEl.value] || modes.text);
|
||||||
};
|
};
|
||||||
|
|
||||||
var modes = {
|
var modes = {
|
||||||
|
|
@ -117,31 +120,29 @@ exports.launch = function() {
|
||||||
|
|
||||||
var themeEl = document.getElementById("theme");
|
var themeEl = document.getElementById("theme");
|
||||||
themeEl.onchange = function() {
|
themeEl.onchange = function() {
|
||||||
editor.setTheme(themeEl.value);
|
env.editor.setTheme(themeEl.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
var selectEl = document.getElementById("select_style");
|
var selectEl = document.getElementById("select_style");
|
||||||
selectEl.onchange = function() {
|
selectEl.onchange = function() {
|
||||||
if (selectEl.checked) {
|
if (selectEl.checked) {
|
||||||
editor.setSelectionStyle("line");
|
env.editor.setSelectionStyle("line");
|
||||||
} else {
|
} else {
|
||||||
editor.setSelectionStyle("text");
|
env.editor.setSelectionStyle("text");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var activeEl = document.getElementById("highlight_active");
|
var activeEl = document.getElementById("highlight_active");
|
||||||
activeEl.onchange = function() {
|
activeEl.onchange = function() {
|
||||||
editor.setHighlightActiveLine(!!activeEl.checked);
|
env.editor.setHighlightActiveLine(!!activeEl.checked);
|
||||||
};
|
};
|
||||||
|
|
||||||
var container = document.getElementById("editor");
|
|
||||||
var editor = new Editor(new Renderer(container, theme));
|
|
||||||
onDocChange();
|
onDocChange();
|
||||||
|
|
||||||
window.jump = function() {
|
window.jump = function() {
|
||||||
var jump = document.getElementById("jump");
|
var jump = document.getElementById("jump");
|
||||||
var cursor = editor.getCursorPosition();
|
var cursor = env.editor.getCursorPosition();
|
||||||
var pos = editor.renderer.textToScreenCoordinates(cursor.row, cursor.column);
|
var pos = env.editor.renderer.textToScreenCoordinates(cursor.row, cursor.column);
|
||||||
jump.style.left = pos.pageX + "px";
|
jump.style.left = pos.pageX + "px";
|
||||||
jump.style.top = pos.pageY + "px";
|
jump.style.top = pos.pageY + "px";
|
||||||
jump.style.display = "block";
|
jump.style.display = "block";
|
||||||
|
|
@ -150,7 +151,7 @@ exports.launch = function() {
|
||||||
function onResize() {
|
function onResize() {
|
||||||
container.style.width = (document.documentElement.clientWidth - 4) + "px";
|
container.style.width = (document.documentElement.clientWidth - 4) + "px";
|
||||||
container.style.height = (document.documentElement.clientHeight - 55 - 4) + "px";
|
container.style.height = (document.documentElement.clientHeight - 55 - 4) + "px";
|
||||||
editor.resize();
|
env.editor.resize();
|
||||||
};
|
};
|
||||||
|
|
||||||
window.onresize = onResize;
|
window.onresize = onResize;
|
||||||
|
|
@ -170,7 +171,7 @@ exports.launch = function() {
|
||||||
if (window.FileReader) {
|
if (window.FileReader) {
|
||||||
var reader = new FileReader();
|
var reader = new FileReader();
|
||||||
reader.onload = function(e) {
|
reader.onload = function(e) {
|
||||||
editor.getSelection().selectAll();
|
env.editor.getSelection().selectAll();
|
||||||
|
|
||||||
var mode = "text";
|
var mode = "text";
|
||||||
if (/^.*\.js$/i.test(file.name)) {
|
if (/^.*\.js$/i.test(file.name)) {
|
||||||
|
|
@ -183,10 +184,10 @@ exports.launch = function() {
|
||||||
mode = "css";
|
mode = "css";
|
||||||
}
|
}
|
||||||
|
|
||||||
editor.onTextInput(reader.result);
|
env.editor.onTextInput(reader.result);
|
||||||
|
|
||||||
modeEl.value = mode;
|
modeEl.value = mode;
|
||||||
editor.getDocument().setMode(modes[mode]);
|
env.editor.getDocument().setMode(modes[mode]);
|
||||||
};
|
};
|
||||||
reader.readAsText(file);
|
reader.readAsText(file);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@
|
||||||
};
|
};
|
||||||
plugin_manager.catalog.startupPlugins(data, plugin_manager.REASONS.APP_STARTUP).then(function() {
|
plugin_manager.catalog.startupPlugins(data, plugin_manager.REASONS.APP_STARTUP).then(function() {
|
||||||
var demo_startup = require("demo_startup");
|
var demo_startup = require("demo_startup");
|
||||||
demo_startup.launch();
|
demo_startup.launch(data.env);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue