diff options
author | Libing Wang <libingw@ca.ibm.com> | 2016-05-18 15:49:24 -0400 |
---|---|---|
committer | Libing Wang <libingw@ca.ibm.com> | 2016-05-18 15:49:24 -0400 |
commit | a8912bc3914fc391513e682718ee1a7ffdaf9c47 (patch) | |
tree | f910cecde7aaa30f5ff861ac04e5357962793008 | |
parent | ffaa8635821a6c15c53d326416df77c8e7ce7b8e (diff) | |
download | org.eclipse.orion.client-origin/stable_20160518.zip org.eclipse.orion.client-origin/stable_20160518.tar.gz org.eclipse.orion.client-origin/stable_20160518.tar.bz2 |
Bug 493461 - codeEdit: Need to hook up project metadata to the in memory file system. -- Add importFiles and exportFiles APIS.origin/stable_20160518
7 files changed, 247 insertions, 51 deletions
diff --git a/bundles/org.eclipse.orion.client.ui/web/embeddedEditor/builder/embeddedEditor.js b/bundles/org.eclipse.orion.client.ui/web/embeddedEditor/builder/embeddedEditor.js index e9593cc..2f05183 100644 --- a/bundles/org.eclipse.orion.client.ui/web/embeddedEditor/builder/embeddedEditor.js +++ b/bundles/org.eclipse.orion.client.ui/web/embeddedEditor/builder/embeddedEditor.js @@ -16,6 +16,7 @@ define([ 'orion/editorCommands', 'embeddedEditor/helper/bootstrap', 'embeddedEditor/helper/editorSetup', + 'embeddedEditor/helper/memoryFileSysConst', 'orion/serviceregistry', 'orion/Deferred', 'orion/commonPreferences', @@ -28,6 +29,7 @@ define([ mEditorCommands, mBootstrap, mEditorSetup, + memoryFileSysConst, mServiceRegistry, Deferred, mCommonPreferences, @@ -39,6 +41,7 @@ define([ this.contentTypeRegistry = new mContentTypes.ContentTypeRegistry(this.serviceRegistry); this._startupOptions = options; this._toolbarId = options && options.toolbarId ? options.toolbarId : "__code__edit__hidden__toolbar"; + this.Deferred = Deferred; } var once; objects.mixin(CodeEdit.prototype, { @@ -92,15 +95,18 @@ define([ * @property {String} [contentType] the type of the content (eg.- application/javascript, text/html, etc.) */ /** - * Creates an editorview instance configured with the given options. + * If options is defined, creates an editorview instance configured with the given options. Otherwise load all the plugins nad initialize the widegt. * * @param {orion.editor.EditOptions} options the editor options. */ - create: function(options) { + startup: function(options) { return mBootstrap.startup(this.serviceRegistry, this.contentTypeRegistry, this._startupOptions).then(function(core) { var serviceRegistry = core.serviceRegistry; var pluginRegistry = core.pluginRegistry; return this._init(core).then( function () { + if(!options) { + return new Deferred().resolve(core); + } var editorHelper = new mEditorSetup.EditorSetupHelper({ serviceRegistry: serviceRegistry, pluginRegistry: pluginRegistry, @@ -116,7 +122,54 @@ define([ }.bind(this)); }.bind(this)); + }, + /** + * @class This object describes the options for <code>create</code>. + * @name orion.editor.EditOptions + * + * @property {String|DOMElement} parent the parent element for the view, it can be either a DOM element or an ID for a DOM element. + * @property {String} [contents=""] the editor contents. + * @property {String} [contentType] the type of the content (eg.- application/javascript, text/html, etc.) + */ + /** + * Creates an editorview instance configured with the given options. + * + * @param {orion.editor.EditOptions} options the editor options. + */ + create: function(options) { + return this.startup(options); + }, + importFiles: function(files2import) { + var fileClient = this.serviceRegistry.getService("orion.core.file.client"); + var promises = []; + if(fileClient) { + files2import.forEach(function(file) { + var promise = fileClient.createFile(file.parentLocation ? file.parentLocation : memoryFileSysConst.MEMORY_FILE_PROJECT_PATTERN, file.name).then(function(result){ + return fileClient.write(result.Location, file.contents); + }); + promises.push(promise); + }); + } + return Deferred.all(promises); + }, + exportFiles: function(files2export) { + var fileClient = this.serviceRegistry.getService("orion.core.file.client"); + var promises = []; + if(fileClient) { + files2export.forEach(function(file) { + var promise; + if(file.name || file.location) { + var readLocation = file.location ? file.location : memoryFileSysConst.MEMORY_FILE_PROJECT_PATTERN + file.name; + promise = fileClient.read(readLocation); + } else { + promise = new Deferred().resolve(""); + } + promises.push(promise); + }); + } + return Deferred.all(promises); } }); + return CodeEdit; });
\ No newline at end of file diff --git a/bundles/org.eclipse.orion.client.ui/web/embeddedEditor/demo/built-codeEdit.js b/bundles/org.eclipse.orion.client.ui/web/embeddedEditor/demo/built-codeEdit.js index 68301a7..d6a9feb 100644 --- a/bundles/org.eclipse.orion.client.ui/web/embeddedEditor/demo/built-codeEdit.js +++ b/bundles/org.eclipse.orion.client.ui/web/embeddedEditor/demo/built-codeEdit.js @@ -131,52 +131,100 @@ Deferred) { }
};
- embeddedEditor.create({parent: "embeddedEditor", statusReporter: statusReporter}).then(function(editorViewer) {
- document.getElementById("progressMessageDiv").textContent = "Plugins loaded!";
- editorViewer.setContents(contents, "application/javascript");
- //editorViewer.inputManager.setAutoSaveTimeout(-1);
- editorViewer.editor.getTextView().addEventListener("Options",function(evt){
- if(evt.options) {
- if(evt.options.tabMode !== undefined) {
- //CTRL+m keys
- //True: you can tab inside the editor. False: Tab will get out of the editor DIV
- console.log("Tab mode has been changed to: " + evt.options.tabMode);
- } else if(evt.options.wrapMode !== undefined) {
- //CTRL+ALT+w keys
- console.log("Wrap mode has been changed to: " + evt.options.wrapMode);
- } else if(evt.options.overwriteMode !== undefined) {
- //Insert key
- console.log("Overwrite mode has been changed to: " + evt.options.overwriteMode);
- } else {
- console.log("Other options has been changed: ");
- console.log(evt.options);
+ var startup = function() {
+ embeddedEditor.create({parent: "embeddedEditor", statusReporter: statusReporter}).then(function(editorViewer) {
+ document.getElementById("progressMessageDiv").textContent = "Plugins loaded!";
+ editorViewer.setContents(contents, "application/javascript");
+ //editorViewer.inputManager.setAutoSaveTimeout(-1);
+ editorViewer.editor.getTextView().addEventListener("Options",function(evt){
+ if(evt.options) {
+ if(evt.options.tabMode !== undefined) {
+ //CTRL+m keys
+ //True: you can tab inside the editor. False: Tab will get out of the editor DIV
+ console.log("Tab mode has been changed to: " + evt.options.tabMode);
+ } else if(evt.options.wrapMode !== undefined) {
+ //CTRL+ALT+w keys
+ console.log("Wrap mode has been changed to: " + evt.options.wrapMode);
+ } else if(evt.options.overwriteMode !== undefined) {
+ //Insert key
+ console.log("Overwrite mode has been changed to: " + evt.options.overwriteMode);
+ } else {
+ console.log("Other options has been changed: ");
+ console.log(evt.options);
+ }
}
+ });
+ //editorViewer.editor.getTextView().setOptions({themeClass: "editorTheme"});
+ function execute(orionContext, params) {
+ //alert("foo");
+ //editorViewer.editor.getTextView()._setThemeClass("editorTheme");
+ //editorViewer.editor.getTextView().setOptions({themeClass: "editorTheme"});
+ editorViewer.editor.getTextView().invokeAction("undo");
+ }
+ editorViewer.serviceRegistry.registerService('orion.edit.command', {execute: execute}, {
+ name: 'Xtext formatting service',
+ id: 'xtext.formatter',
+ key: ['l', true, true],
+ contentType: ["application/javascript"]
+ });
+ var markerService = editorViewer.serviceRegistry.getService(editorViewer.problemsServiceID);
+ if(markerService) {
+ markerService.addEventListener("problemsChanged", function(evt) { //$NON-NLS-0$
+ if(evt.problems) {
+ evt.problems.forEach(function(problem) {
+ console.log(problem);
+ })
+ }
+ });
}
});
- //editorViewer.editor.getTextView().setOptions({themeClass: "editorTheme"});
- function execute(orionContext, params) {
- //alert("foo");
- //editorViewer.editor.getTextView()._setThemeClass("editorTheme");
- //editorViewer.editor.getTextView().setOptions({themeClass: "editorTheme"});
- editorViewer.editor.getTextView().invokeAction("undo");
+ };
+
+ var files2create = [
+ {
+ name: ".tern-project",
+ contents:'{"sourceType": "module","ecmaVersion": 6}'
}
- editorViewer.serviceRegistry.registerService('orion.edit.command', {execute: execute}, {
- name: 'Xtext formatting service',
- id: 'xtext.formatter',
- key: ['l', true, true],
- contentType: ["application/javascript"]
- });
- var markerService = editorViewer.serviceRegistry.getService(editorViewer.problemsServiceID);
- if(markerService) {
- markerService.addEventListener("problemsChanged", function(evt) { //$NON-NLS-0$
- if(evt.problems) {
- evt.problems.forEach(function(problem) {
- console.log(problem);
- })
- }
- });
+ ];
+ var files2export = [
+ {
+ name: ".tern-project"
+ },
+ {
+ name: ".eslintrc"
}
+ ];
+
+ embeddedEditor.startup().then(function() {
+// var fileClient = embeddedEditor.serviceRegistry.getService("orion.core.file.client");
+// if(fileClient) {
+// var promises = [];
+// files2create.forEach(function(file) {
+// var promise = fileClient.createFile("/in_memory_file_system/project/", file.name).then(function(result){
+// return fileClient.write(result.Location, file.contents);
+// });
+// promises.push(promise);
+// });
+// }
+// embeddedEditor.Deferred.all(promises).then(function(result) {
+// new embeddedEditor.Deferred().resolve(result).then(function(rr) {
+// console.log(rr);
+// });
+// startup();
+// });
+
+ embeddedEditor.importFiles(files2create).then(function(results) {
+ console.log(results);
+ startup();
+ embeddedEditor.exportFiles(files2export).then(function(exportResults) {
+ console.log(exportResults);
+ });
+ });
+
});
+
+
+
// embeddedEditor.create({parent: "embeddedEditor1"}).then(function(editorViewer) {
// editorViewer.setContents(contents, "application/javascript");
// editorViewer.inputManager.setAutoSaveTimeout(-1);
diff --git a/bundles/org.eclipse.orion.client.ui/web/embeddedEditor/demoBuild/demo/demoTernProject.html b/bundles/org.eclipse.orion.client.ui/web/embeddedEditor/demoBuild/demo/demoTernProject.html new file mode 100644 index 0000000..2df69ef --- /dev/null +++ b/bundles/org.eclipse.orion.client.ui/web/embeddedEditor/demoBuild/demo/demoTernProject.html @@ -0,0 +1,71 @@ +<!doctype html> +<html> + <head> + <meta name="copyright" content="Copyright (c) IBM Corporation and others 2010, 2014." > + <meta http-equiv="Content-Language" content="en-us"> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> + <title>Pluggable Editor Demo</title> + <style type="text/css"> + .demoTitle{ + border: none; + vertical-align: middle; + overflow: hidden; + text-align: left; + margin-left: 15%; + margin-right: 15%; + padding-bottom: 5px; + position: relative; + } + .demoBody{ + border: 1px solid; + vertical-align: middle; + border-color: blue; + overflow: hidden; + text-align: left; + margin-left: 15%; + margin-right: 15%; + margin-bottom: 15px; + padding-bottom: 5px; + position: relative; + height: 450px; + } + </style> + <link rel="stylesheet" type="text/css" href="editorBuild/code_edit/built-codeEdit.css"/> + <style type="text/css"> + .orionPage { + background-color: #FFFFFF; + } + </style> + <script src="editorBuild/code_edit/built-codeEdit.js"></script> + <script> + /*globals orion */ + var contents = 'var MYCONSTANT = 1;\n' + + 'import "somehting";\n' + + "export function myFunc() { return MYCONSTANT;}"; + window.onload=function(){ + var codeEdit = new orion.codeEdit(); + codeEdit.create({parent: "embeddedEditor", contentType: "application/javascript", contents: contents}).then(function(editorViewer) { + document.getElementById("progressMessageDiv").textContent = "Plugins loaded!"; + }); + codeEdit.create({parent: "embeddedEditor1", contentType: "application/javascript", contents: ""}).then(function(editorViewer) { + document.getElementById("progressMessageDiv").textContent = "Plugins loaded!"; + }); + }; + </script> + </head> + <body id="orion-browser" spellcheck="false" class="orionPage"> + <div class="demoTitle"> + <p>This is a demo for the <b>Orion Code Edit</b> widget tern project. The top editor display the main editor contents and the bottom one reflects the .tern-project while you are using quick fix.</p> + </div> + <div class="demoTitle"> + <span id = "progressMessageDiv" style="color: green">Loading language tooling plugins...</span> + </div> + <div class="demoBody" id="embeddedEditor"> + </div> + <div class="demoTitle"> + <span id = "progressMessageDiv" style="color: green">/in_memory_file_system/project/.tern-project</span> + </div> + <div class="demoBody" id="embeddedEditor1"> + </div> + </body> +</html>
\ No newline at end of file diff --git a/bundles/org.eclipse.orion.client.ui/web/embeddedEditor/helper/bootstrap.js b/bundles/org.eclipse.orion.client.ui/web/embeddedEditor/helper/bootstrap.js index 8c7d1fa..18686d1 100644 --- a/bundles/org.eclipse.orion.client.ui/web/embeddedEditor/helper/bootstrap.js +++ b/bundles/org.eclipse.orion.client.ui/web/embeddedEditor/helper/bootstrap.js @@ -39,17 +39,19 @@ if (_all_script && _all_script.length && _all_script.length > 0) { }
define([
'embeddedEditor/helper/embeddedFileImpl',
+ 'embeddedEditor/helper/memoryFileSysConst',
'orion/pluginregistry',
'orion/Deferred',
'orion/URL-shim'
], function(
EmbeddedFileImpl,
+ memoryFileSysConst,
mPluginRegistry,
Deferred
) {
var once; // Deferred
- var inMemoryFilePattern = "/in_memory_file_system/";
+ var inMemoryFilePattern = memoryFileSysConst.MEMORY_FILE_PATTERN;
var defaultPluginURLs = [
"../javascript/plugins/javascriptPlugin.html",
"../webtools/plugins/webToolsPlugin.html",
diff --git a/bundles/org.eclipse.orion.client.ui/web/embeddedEditor/helper/embeddedFileImpl.js b/bundles/org.eclipse.orion.client.ui/web/embeddedEditor/helper/embeddedFileImpl.js index aaa3641..d6a1da5 100644 --- a/bundles/org.eclipse.orion.client.ui/web/embeddedEditor/helper/embeddedFileImpl.js +++ b/bundles/org.eclipse.orion.client.ui/web/embeddedEditor/helper/embeddedFileImpl.js @@ -11,13 +11,11 @@ /*eslint-env browser, amd*/
/*global URL*/
-define(["orion/Deferred", "orion/encoding-shim", "orion/URL-shim"], function(Deferred) {
- var PROJECT_LOC = "project/";
+define(["orion/Deferred", 'embeddedEditor/helper/memoryFileSysConst', "orion/encoding-shim", "orion/URL-shim"], function(Deferred, memoryFileSysConst) {
function EmbeddedFileImpl(fileBase) {
this.fileBase = fileBase;
this.fileRoot = {};
- this.projectMetaLocation = this.fileBase + PROJECT_LOC;
- this.fileRoot[this.projectMetaLocation] = {Location: this.projectMetaLocation, Directory: true};
+ this.fileRoot[memoryFileSysConst.MEMORY_FILE_PROJECT_PATTERN] = {Location: memoryFileSysConst.MEMORY_FILE_PROJECT_PATTERN, Directory: true};
}
EmbeddedFileImpl.prototype = {
@@ -82,9 +80,11 @@ define(["orion/Deferred", "orion/encoding-shim", "orion/URL-shim"], function(Def */
read: function(fLocation, isMetadata) {
var file = this._getFile(fLocation);
- if (file === undefined) return new Deferred().reject();
+ if (file === undefined) {
+ return new Deferred().resolve(isMetadata ? {} : "");
+ }
if(isMetadata){
- var parents = fLocation === this.projectMetaLocation ? [] : [this.fileRoot[this.projectMetaLocation]];
+ var parents = fLocation === memoryFileSysConst.MEMORY_FILE_PROJECT_PATTERN ? [] : [this.fileRoot[memoryFileSysConst.MEMORY_FILE_PROJECT_PATTERN]];
var meta = {
Length: file.length,
Directory: !!file.Directory,
diff --git a/bundles/org.eclipse.orion.client.ui/web/embeddedEditor/helper/memoryFileSysConst.js b/bundles/org.eclipse.orion.client.ui/web/embeddedEditor/helper/memoryFileSysConst.js new file mode 100644 index 0000000..c8044b7 --- /dev/null +++ b/bundles/org.eclipse.orion.client.ui/web/embeddedEditor/helper/memoryFileSysConst.js @@ -0,0 +1,21 @@ +/******************************************************************************* + * @license + * Copyright (c) 2009, 2012 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v1.0 + * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution + * License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). + * + * Contributors: IBM Corporation - initial API and implementation + *******************************************************************************/ +/*eslint-env browser, amd*/ +define([ +], function() { + var inMemoryFilePattern = "/in_memory_file_system/"; + var project = "/in_memory_file_system/project/"; + //return module exports + return { + MEMORY_FILE_PATTERN: inMemoryFilePattern, + MEMORY_FILE_PROJECT_PATTERN: project + }; +}); diff --git a/bundles/org.eclipse.orion.client.ui/web/orion/editorView.js b/bundles/org.eclipse.orion.client.ui/web/orion/editorView.js index bd5defd..6b3e161 100644 --- a/bundles/org.eclipse.orion.client.ui/web/orion/editorView.js +++ b/bundles/org.eclipse.orion.client.ui/web/orion/editorView.js @@ -44,6 +44,7 @@ define([ 'orion/webui/contextmenu',
'orion/metrics',
'orion/commonPreferences',
+ 'embeddedEditor/helper/memoryFileSysConst',
'orion/objects'
], function(
messages,
@@ -53,9 +54,9 @@ define([ mDispatcher, EditorContext, Highlight,
mMarkOccurrences, mSyntaxchecker, LiveEditSession,
mProblems, mBlamer, mDiffer,
- mKeyBinding, util, Deferred, mContextMenu, mMetrics, mCommonPreferences, objects
+ mKeyBinding, util, Deferred, mContextMenu, mMetrics, mCommonPreferences, memoryFileSysConst, objects
) {
- var inMemoryFilePattern = "/in_memory_file_system/"; //$NON-NLS-1$
+ var inMemoryFilePattern = memoryFileSysConst.MEMORY_FILE_PATTERN;
var Dispatcher = mDispatcher.Dispatcher;
function parseNumericParams(input, params) {
|