/*

 Copyright (c) 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

 Copyright (c) 2011, 2014 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

 Copyright (c) 2010, 2014 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

 Copyright (c) 2013 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
*/
(function(g,m){"function"===typeof define&&define.amd?define("orion/Deferred",m):"object"===typeof exports?module.exports=m():(g.orion=g.orion||{},g.orion.Deferred=m())})(this,function(){function g(){for(var a;a=c.shift();)a();d=!1}function m(a){c.push(a);d||(d=!0,f())}function a(a){return function(b){a(b)}}function b(){function c(){for(var q;q=l.shift();){var b=q.deferred,d="fulfilled"===e?"resolve":"reject";q=q[d];if("function"===typeof q)try{var h=q(n),k=h&&("object"===typeof h||"function"===typeof h)&&
h.then;if("function"===typeof k)if(h===b.promise)b.reject(new TypeError);else{var f=h.cancel;"function"===typeof f?b._parentCancel=f.bind(h):delete b._parentCancel;k.call(h,a(b.resolve),a(b.reject),a(b.progress))}else b.resolve(h)}catch(w){b.reject(w)}else b[d](n)}}function h(a){delete k._parentCancel;e="rejected";n=a;l.length&&m(c)}function d(a){function f(a){return function(b){(!e||"assumed"===e)&&a(b)}}delete k._parentCancel;try{var g=a&&("object"===typeof a||"function"===typeof a)&&a.then;if("function"===
typeof g)if(a===k)h(new TypeError);else{e="assumed";var p=a&&a.cancel;if("function"!==typeof p){var s=new b;a=s.promise;try{g(s.resolve,s.reject,s.progress)}catch(t){s.reject(t)}p=a.cancel;g=a.then}n=a;g.call(a,f(d),f(h));k._parentCancel=p.bind(a)}else e="fulfilled",n=a,l.length&&m(c)}catch(r){f(h)(r)}}function f(){var a=k._parentCancel;a?(delete k._parentCancel,a()):e||(a=Error("Cancel"),a.name="Cancel",h(a))}var n,e,l=[],k=this;this.resolve=function(a){e||d(a);return k};this.reject=function(a){e||
h(a);return k};this.progress=function(a){e||l.forEach(function(b){if(b.progress)try{b.progress(a)}catch(c){}});return k.promise};this.cancel=function(){k._parentCancel?setTimeout(f,0):f();return k};this.then=function(a,h,d){var f=new b;f._parentCancel=k.promise.cancel;l.push({resolve:a,reject:h,progress:d,deferred:f});("fulfilled"===e||"rejected"===e)&&m(c);return f.promise};this.promise={then:k.then,cancel:k.cancel}}var c=[],d=!1,f=function(){if("undefined"!==typeof process&&"function"===typeof process.nextTick){var a=
process.nextTick;return function(){a(g)}}if("function"===typeof MutationObserver){var b=document.createElement("div");(new MutationObserver(g)).observe(b,{attributes:!0});return function(){b.setAttribute("class","_tick")}}return function(){setTimeout(g,0)}}();b.all=function(a,c){function d(a,b){l||(e[a]=b,0===--g&&k.resolve(e))}function f(a,b){if(!l){if(c)try{d(a,c(b));return}catch(e){b=e}k.reject(b)}}var g=a.length,e=[],l=!1,k=new b;k.then(void 0,function(){l=!0;a.forEach(function(a){a.cancel&&a.cancel()})});
0===g?k.resolve(e):a.forEach(function(a,b){a.then(d.bind(void 0,b),f.bind(void 0,b))});return k.promise};b.when=function(a,c,d,f){var g;a&&"function"===typeof a.then||(g=new b,g.resolve(a),a=g.promise);return a.then(c,d,f)};return b});
(function(g,m){"function"===typeof define&&define.amd?define("orion/plugin",["orion/Deferred"],m):"object"===typeof exports?module.exports=m(require("orion/Deferred")):(g.orion=g.orion||{},g.orion.PluginProvider=m(g.orion.Deferred))})(this,function(g){function m(a,b){this.__objectId=a;this.__methods=b}return function(a){function b(a){l&&("undefined"===typeof ArrayBuffer&&(a=JSON.stringify(a)),l===self?l.postMessage(a):l.postMessage(a,"*"))}function c(){var a=[];Object.keys(t).forEach(function(b){var c=
t[b];a.push({serviceId:b,names:c.names,methods:c.methods,properties:c.properties})});return{headers:n||{},services:a}}function d(a,b){if(b&&b instanceof XMLHttpRequest){var c,d;try{c=b.status,d=b.statusText}catch(e){c=0,d=""}return{status:c||0,statusText:d}}return b}function f(a){var b=a?JSON.parse(JSON.stringify(a,d)):a;a instanceof Error&&(b.__isError=!0,b.message=b.message||a.message,b.name=b.name||a.name);return b}function w(a){if(!l)return(new g).reject(Error("plugin not connected"));a.id=String(k++);
var b=new g;v[a.id]=b;b.then(null,function(b){e&&(b instanceof Error&&"Cancel"===b.name)&&r({requestId:a.id,method:"cancel",params:b.message?[b.message]:[]})});var c=Object.prototype.toString;a.params.forEach(function(d,e){if("[object Object]"===c.call(d)&&!(d instanceof m)){var f,h;for(f in d)"[object Function]"===c.call(d[f])&&(h=h||[],h.push(f));if(h){var g=q++;s[g]=d;f=function(){delete s[g]};b.then(f,f);a.params[e]=new m(g,h)}}});r(a);return b.promise}function h(a,b){a||0===a?r({id:a,result:null,
error:b}):console.log(b)}function x(a,b,c,d){d.forEach(function(a,b){if(a&&"undefined"!==typeof a.__objectId){var c={};a.__methods.forEach(function(b){c[b]=function(){return w({objectId:a.__objectId,method:b,params:Array.prototype.slice.call(arguments)})}});d[b]=c}});var e=void 0===typeof a?null:{id:a,result:null,error:null};try{var h=c.apply(b,d);e&&(h&&"function"===typeof h.then?(u[a]=h,h.then(function(b){delete u[a];e.result=b;r(e)},function(b){u[a]&&(delete u[a],e.error=f(b),r(e))},function(){r({responseId:a,
method:"progress",params:Array.prototype.slice.call(arguments)})})):(e.result=h,r(e)))}catch(g){e&&(e.error=f(g),r(e))}}function p(a){if(!(a.source!==l&&"undefined"!==typeof window)){a="string"!==typeof a.data?a.data:JSON.parse(a.data);try{if(a.method){var b=a.method,c=a.params||[];if("serviceId"in a){var d=t[a.serviceId];d||h(a.id,"service not found");d=d.implementation;b in d?x(a.id,d,d[b],c):h(a.id,"method not found")}else if("objectId"in a){var e=s[a.objectId];e||h(a.id,"object not found");!b in
e?x(a.id,e,e[b],c):h(a.id,"method not found")}else if("requestId"in a){var f=u[a.requestId];f&&("cancel"===b&&f.cancel)&&f.cancel.apply(f,c)}else if("responseId"in a){var g=v[a.responseId];g&&("progress"===b&&g.progress)&&g.progress.apply(g,c)}else throw Error("Bad method: "+a.method);}else{var k=v[String(a.id)];delete v[String(a.id)];a.error?k.reject(a.error):k.resolve(a.result)}}catch(n){console.log("Plugin._messageHandler "+n)}}}var n=a,e=!1,l=null,k=0,q=0,y=0,u={},v={},s={},t={},r=b;this.updateHeaders=
function(a){if(e)throw Error("Cannot update headers. Plugin Provider is connected");n=a};this.registerServiceProvider=this.registerService=function(a,b,c){if(e)throw Error("Cannot register service. Plugin Provider is connected");"string"===typeof a?a=[a]:Array.isArray(a)||(a=[]);var d=null,f=[];for(d in b)"function"===typeof b[d]&&f.push(d);t[y++]={names:a,methods:f,implementation:b,properties:c||{},listeners:{}}};this.connect=function(a,d){if(!e){if("undefined"===typeof window)l=self;else if(window!==
window.parent)l=window.parent;else if(null!==window.opener)l=window.opener;else{d&&d("No valid plugin target");return}addEventListener("message",p,!1);var f={method:"plugin",params:[c()]};b(f);e=!0}a&&a()};this.disconnect=function(){e&&(removeEventListener("message",p),l=null,e=!1)}}});
define("orion/editor/templates",[],function(){function g(a,b,c,d){this.prefix=a;this.description=b;this.template=c;this.name=d;this._parse()}function m(a,b){this._keywords=a||[];this._templates=[];this.addTemplates(b||[])}g.prototype={getProposal:function(a,b,c){a=b-a.length;b={};var d,f=void 0!==c.delimiter?c.delimiter:"\n";c.indentation&&(f+=c.indentation);var g=void 0!==c.tab?c.tab:"\t",h=0,m=this.variables,p=this.segments;c=[];for(var n=0;n<p.length;n++){var e=p[n],l=m[e];if(void 0!==l)switch(e){case "${tab}":e=
g;break;case "${delimiter}":e=f;break;case "${cursor}":e="";d=h;break;default:var k=b[e];k||(k=b[e]={data:l.data,positions:[]});e=l.substitution;k.data&&k.data.values&&(e=k.data.values[0]);k.positions.push({offset:a+h,length:e.length})}c.push(e);h+=e.length}var f=[],q;for(q in b)b.hasOwnProperty(q)&&f.push(b[q]);c=c.join("");void 0===d&&(d=c.length);return{proposal:c,name:this.name,description:this.description,groups:f,escapePosition:a+d,style:"noemphasis"}},match:function(a){return 0===this.prefix.indexOf(a)},
_parse:function(){var a=this.template,b=[],c={},d,f=0,a=a.replace(/\n/g,"${delimiter}"),a=a.replace(/\t/g,"${tab}");a.replace(/\$\{((?:[^\\}]+|\\.))*\}/g,function(g,h,m){var p=g.substring(2,g.length-1);h=g;var n=p,e=null,l=n.indexOf(":");-1!==l&&(n=n.substring(0,l),h="${"+n+"}",e=JSON.parse(p.substring(l+1).replace("\\}","}").trim()));(p=c[h])||(p=c[h]={});p.substitution=n;e&&(p.data=e);(d=a.substring(f,m))&&b.push(d);b.push(h);f=m+g.length;return n});(d=a.substring(f,a.length))&&b.push(d);this.segments=
b;this.variables=c}};m.prototype={addTemplates:function(a){for(var b=this.getTemplates(),c=0;c<a.length;c++)b.push(new g(a[c].prefix,a[c].description,a[c].template,a[c].name))},initialize:function(){},computeProposals:function(a,b,c){var d=this.getPrefix(a,b,c),f=[];this.isValid(d,a,b,c)&&(f=f.concat(this.getTemplateProposals(d,b,c)),f=f.concat(this.getKeywordProposals(d)));return f},getKeywords:function(){return this._keywords},getKeywordProposals:function(a){var b=[],c=this.getKeywords();if(c){for(var d=
0;d<c.length;d++)0===c[d].indexOf(a)&&b.push({proposal:c[d].substring(a.length),description:c[d],style:"noemphasis_keyword"});0<b.length&&b.splice(0,0,{proposal:"",description:"Keywords",style:"noemphasis_title_keywords",unselectable:!0})}return b},getPrefix:function(a,b,c){return c.prefix},getTemplates:function(){return this._templates},getTemplateProposals:function(a,b,c){for(var d=[],f=this.getTemplates(),g=0;g<f.length;g++){var h=f[g];h.match(a)&&(h=h.getProposal(a,b,c),this.removePrefix(a,h),
d.push(h))}0<d.length&&(d.sort(function(a,b){return a.name<b.name?-1:a.name>b.name?1:0}),d.splice(0,0,{proposal:"",description:"Templates",style:"noemphasis_title",unselectable:!0}));return d},removePrefix:function(a,b){if(!(b.overwrite=b.proposal.substring(0,a.length)!==a))b.proposal=b.proposal.substring(a.length)},isValid:function(a,b,c,d){return!0}};return{Template:g,TemplateContentAssist:m}});
define("plugins/webEditingPlugin",["orion/plugin","orion/editor/templates"],function(g,m){var a=new g({name:"Orion Web Editing Plugin",version:"1.0",description:"This plugin provides editor link support for the navigator."});a.registerService("orion.core.contenttype",{},{contentTypes:[{id:"text/plain",name:"Text",extension:["txt"],imageClass:"file-sprite-text modelDecorationSprite"},{id:"application/xml","extends":"text/plain",name:"XML",extension:["xml"],imageClass:"file-sprite-xml"},{id:"text/x-markdown",
"extends":"text/plain",name:"Markdown",extension:["md"]},{id:"text/conf","extends":"text/plain",name:"Conf",extension:["conf"]},{id:"text/sh","extends":"text/plain",name:"sh",extension:["sh"]},{id:"image/gif",name:"GIF",extension:["gif"],imageClass:"file-sprite-image modelDecorationSprite"},{id:"image/jpeg",name:"JPG",extension:["jpg","jpeg","jpe"],imageClass:"file-sprite-image modelDecorationSprite"},{id:"image/ico",name:"ICO",extension:["ico"],imageClass:"file-sprite-image modelDecorationSprite"},
{id:"image/png",name:"PNG",extension:["png"],imageClass:"file-sprite-image modelDecorationSprite"},{id:"image/tiff",name:"TIFF",extension:["tif","tiff"],imageClass:"file-sprite-image modelDecorationSprite"},{id:"image/svg",name:"SVG",extension:["svg"],imageClass:"file-sprite-image modelDecorationSprite"}]});a.registerService("orion.edit.editor",{},{id:"orion.editor","default":!0,nameKey:"Orion Editor",nls:"orion/nls/messages",uriTemplate:"../edit/edit.html#{,Location,params*}",orionTemplate:"../edit/edit.html#{,Location,params*}",
validationProperties:[{source:"!Projects"}]});a.registerService("orion.navigate.openWith",{},{editor:"orion.editor",excludedContentTypes:["image/*"]});a.registerService("orion.edit.editor",{},{id:"orion.viewer.markdown",nameKey:"Orion Markdown Viewer",nls:"orion/nls/messages",uriTemplate:"../edit/edit.html#{,Location,params*},editor\x3dorion.viewer.markdown"});a.registerService("orion.navigate.openWith",{},{editor:"orion.viewer.markdown",contentType:["text/x-markdown"]});a.registerService("orion.edit.editor",
{},{id:"orion.editor.markdown",nameKey:"Orion Markdown Editor",nls:"orion/nls/messages","default":!0,uriTemplate:"../edit/edit.html#{,Location,params*},editor\x3dorion.editor.markdown"});a.registerService("orion.navigate.openWith",{},{editor:"orion.editor.markdown",contentType:["text/x-markdown"]});a.registerService("orion.edit.editor",{},{id:"orion.viewer.raw",nameKey:"Browser",nls:"orion/nls/messages",uriTemplate:"{+Location}",validationProperties:[{source:"!Projects"}]});a.connect()});
//@ sourceMappingURL=webEditingPlugin.js.map