Created
December 15, 2011 09:19
-
-
Save anonymous/1480478 to your computer and use it in GitHub Desktop.
Umbraco upgrade CodeMirror to 2.x
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -Nur umbraco_92d7d98ea3fe/umbraco/presentation/umbraco/developer/Python/editPython.aspx umbraco_92d7d98ea3fe_mod/umbraco/presentation/umbraco/developer/Python/editPython.aspx | |
--- umbraco_92d7d98ea3fe/umbraco/presentation/umbraco/developer/Python/editPython.aspx 2011-09-21 11:05:44.000000000 +0200 | |
+++ umbraco_92d7d98ea3fe_mod/umbraco/presentation/umbraco/developer/Python/editPython.aspx 2011-11-18 15:53:32.261923600 +0100 | |
@@ -15,7 +15,7 @@ | |
//if CodeMirror is not defined, then the code editor is disabled. | |
if (typeof (CodeMirror) != "undefined") { | |
- codeVal = codeEditor.getCode(); | |
+ codeVal = codeEditor.getValue(); | |
} | |
umbraco.presentation.webservices.codeEditorSave.SaveDLRScript(jQuery('#<%= pythonFileName.ClientID %>').val(), '<%= pythonFileName.Text %>', codeVal, document.getElementById('<%= SkipTesting.ClientID %>').checked, submitSucces, submitFailure); | |
diff -Nur umbraco_92d7d98ea3fe/umbraco/presentation/umbraco/developer/Python/editPython.aspx.cs umbraco_92d7d98ea3fe_mod/umbraco/presentation/umbraco/developer/Python/editPython.aspx.cs | |
--- umbraco_92d7d98ea3fe/umbraco/presentation/umbraco/developer/Python/editPython.aspx.cs 2011-09-21 11:05:44.000000000 +0200 | |
+++ umbraco_92d7d98ea3fe_mod/umbraco/presentation/umbraco/developer/Python/editPython.aspx.cs 2011-11-21 10:04:50.096490700 +0100 | |
@@ -71,6 +71,11 @@ | |
// Add source and filename | |
String file = IOHelper.MapPath(SystemDirectories.MacroScripts + "/" + Request.QueryString["file"]); | |
+ if (file.EndsWith("cshtml")) | |
+ pythonSource.CodeBase = umbraco.uicontrols.CodeArea.EditorType.Razor; | |
+ else | |
+ pythonSource.CodeBase = umbraco.uicontrols.CodeArea.EditorType.Python; | |
+ | |
// validate file | |
IOHelper.ValidateEditPath(file, SystemDirectories.MacroScripts); | |
// validate extension | |
diff -Nur umbraco_6f33e2b81175/umbraco/presentation/umbraco/developer/Xslt/editXslt.aspx umbraco_6f33e2b81175_mod/umbraco/presentation/umbraco/developer/Xslt/editXslt.aspx | |
--- umbraco_6f33e2b81175/umbraco/presentation/umbraco/developer/Xslt/editXslt.aspx 2011-03-14 19:05:34.000000000 +0100 | |
+++ umbraco_6f33e2b81175_mod/umbraco/presentation/umbraco/developer/Xslt/editXslt.aspx 2011-11-06 22:12:10.245000000 +0100 | |
@@ -33,7 +33,7 @@ | |
var codeVal = jQuery('#<%= editorSource.ClientID %>').val(); | |
//if CodeMirror is not defined, then the code editor is disabled. | |
if (typeof (CodeMirror) != "undefined") { | |
- codeVal = codeEditor.getCode(); | |
+ codeVal = codeEditor.getValue(); | |
} | |
umbraco.presentation.webservices.codeEditorSave.SaveXslt(jQuery('#<%= xsltFileName.ClientID %>').val(), '<%= xsltFileName.Text %>', codeVal, document.getElementById('<%= SkipTesting.ClientID %>').checked, submitSucces, submitFailure); | |
diff -Nur umbraco_92d7d98ea3fe/umbraco/presentation/umbraco/settings/scripts/editScript.aspx umbraco_92d7d98ea3fe_mod/umbraco/presentation/umbraco/settings/scripts/editScript.aspx | |
--- umbraco_92d7d98ea3fe/umbraco/presentation/umbraco/settings/scripts/editScript.aspx 2011-09-21 11:05:44.000000000 +0200 | |
+++ umbraco_92d7d98ea3fe_mod/umbraco/presentation/umbraco/settings/scripts/editScript.aspx 2011-11-18 15:53:07.051838800 +0100 | |
@@ -10,7 +10,7 @@ | |
var codeVal = jQuery('#<%= editorSource.ClientID %>').val(); | |
//if CodeMirror is not defined, then the code editor is disabled. | |
if (typeof (CodeMirror) != "undefined") { | |
- codeVal = codeEditor.getCode(); | |
+ codeVal = codeEditor.getValue(); | |
} | |
umbraco.presentation.webservices.codeEditorSave.SaveScript(jQuery('#<%= NameTxt.ClientID %>').val(), '<%= NameTxt.Text %>', codeVal, submitSucces, submitFailure); | |
} | |
diff -Nur umbraco_6f33e2b81175/umbraco/presentation/umbraco/settings/stylesheet/editstylesheet.aspx umbraco_6f33e2b81175_mod/umbraco/presentation/umbraco/settings/stylesheet/editstylesheet.aspx | |
--- umbraco_6f33e2b81175/umbraco/presentation/umbraco/settings/stylesheet/editstylesheet.aspx 2011-03-14 19:05:34.000000000 +0100 | |
+++ umbraco_6f33e2b81175_mod/umbraco/presentation/umbraco/settings/stylesheet/editstylesheet.aspx 2011-11-06 22:11:44.600000000 +0100 | |
@@ -9,7 +9,7 @@ | |
var codeVal = jQuery('#<%= editorSource.ClientID %>').val(); | |
//if CodeMirror is not defined, then the code editor is disabled. | |
if (typeof(CodeMirror) != "undefined") { | |
- codeVal = codeEditor.getCode(); | |
+ codeVal = codeEditor.getValue(); | |
} | |
umbraco.presentation.webservices.codeEditorSave.SaveCss(jQuery('#<%= NameTxt.ClientID %>').val(), '<%= NameTxt.Text %>', codeVal, '<%= Request.QueryString["id"] %>', submitSucces, submitFailure); | |
} | |
diff -Nur umbraco_6f33e2b81175/umbraco/presentation/umbraco_client/CodeArea/styles.css umbraco_6f33e2b81175_mod/umbraco/presentation/umbraco_client/CodeArea/styles.css | |
--- umbraco_6f33e2b81175/umbraco/presentation/umbraco_client/CodeArea/styles.css 2011-03-14 19:05:34.000000000 +0100 | |
+++ umbraco_6f33e2b81175_mod/umbraco/presentation/umbraco_client/CodeArea/styles.css 2011-11-06 11:24:53.981200000 +0100 | |
@@ -1,14 +1,2 @@ | |
-.CodeMirror-line-numbers | |
-{ | |
- color:black; | |
- background-color:#fff; | |
- font-family:monospace; | |
- font-size:10pt; | |
- padding:6px 6px 0px 0px; | |
- line-height:16px; | |
- text-align:right; | |
- border-right: 1px solid #efefef; | |
-} | |
- | |
div.codepress{border: none !Important; background: #fff;} | |
div.codepress iframe{border: none !Important; background: #fff;} | |
\ Brak znaku nowej linii na końcu pliku | |
diff -Nur umbraco_92d7d98ea3fe/components/umbraco.controls/CodeArea.cs umbraco_92d7d98ea3fe_mod/components/umbraco.controls/CodeArea.cs | |
--- umbraco_92d7d98ea3fe/components/umbraco.controls/CodeArea.cs 2011-09-21 11:05:44.000000000 +0200 | |
+++ umbraco_92d7d98ea3fe_mod/components/umbraco.controls/CodeArea.cs 2011-11-21 11:51:42.240878400 +0100 | |
@@ -58,7 +58,7 @@ | |
public EditorType CodeBase { get; set; } | |
public string ClientSaveMethod { get; set; } | |
- public enum EditorType { JavaScript, Css, Python, XML, HTML } | |
+ public enum EditorType { JavaScript, Css, Python, XML, HTML, Razor } | |
protected override void OnInit(EventArgs e) | |
{ | |
@@ -67,7 +67,21 @@ | |
if (CodeMirrorEnabled) | |
{ | |
- ClientDependencyLoader.Instance.RegisterDependency("CodeMirror/js/codemirror.js", "UmbracoClient", ClientDependencyType.Javascript); | |
+ string codeMirrorTheme = UmbracoSettings.ScriptEditorTheme; | |
+ if (string.IsNullOrEmpty(codeMirrorTheme)) | |
+ codeMirrorTheme = "default"; | |
+ | |
+ ClientDependencyLoader.Instance.RegisterDependency(100, "CodeMirror/lib/codemirror.js", "UmbracoClient", ClientDependencyType.Javascript); | |
+ ClientDependencyLoader.Instance.RegisterDependency(100, "CodeMirror/lib/codemirror.css", "UmbracoClient", ClientDependencyType.Css); | |
+ ClientDependencyLoader.Instance.RegisterDependency(100, "CodeMirror/theme/" + codeMirrorTheme + ".css", "UmbracoClient", ClientDependencyType.Css); | |
+ | |
+ ClientDependencyLoader.Instance.RegisterDependency(200, "CodeMirror/mode/htmlmixed/htmlmixed.js", "UmbracoClient", ClientDependencyType.Javascript); | |
+ ClientDependencyLoader.Instance.RegisterDependency(201, "CodeMirror/mode/xml/xml.js", "UmbracoClient", ClientDependencyType.Javascript); | |
+ ClientDependencyLoader.Instance.RegisterDependency(201, "CodeMirror/mode/javascript/javascript.js", "UmbracoClient", ClientDependencyType.Javascript); | |
+ ClientDependencyLoader.Instance.RegisterDependency(201, "CodeMirror/mode/css/css.js", "UmbracoClient", ClientDependencyType.Javascript); | |
+ ClientDependencyLoader.Instance.RegisterDependency(201, "CodeMirror/mode/python/python.js", "UmbracoClient", ClientDependencyType.Javascript); | |
+ ClientDependencyLoader.Instance.RegisterDependency(201, "CodeMirror/mode/razor/razor.js", "UmbracoClient", ClientDependencyType.Javascript); | |
+ ClientDependencyLoader.Instance.RegisterDependency(201, "CodeMirror/mode/razor/razor.css", "UmbracoClient", ClientDependencyType.Css); | |
ClientDependencyLoader.Instance.RegisterDependency("CodeArea/styles.css", "UmbracoClient", ClientDependencyType.Css); | |
} | |
} | |
@@ -133,23 +147,19 @@ | |
if (this.AutoResize) | |
{ | |
- if (CodeMirrorEnabled) | |
- { | |
- //reduce the width if using code mirror because of the line numbers | |
- OffSetX += 20; | |
- } | |
- | |
jsEventCode += @" | |
- | |
- //create the editor | |
- var UmbEditor = new Umbraco.Controls.CodeEditor.UmbracoEditor(" + (!CodeMirrorEnabled).ToString().ToLower() + @", '" + this.ClientID + @"'); | |
- | |
- | |
- var m_textEditor = jQuery('#" + this.ClientID + @"'); | |
- //with codemirror adding divs for line numbers, we need to target a different element | |
- m_textEditor = m_textEditor.find('iframe').length > 0 ? m_textEditor.children('div').get(0) : m_textEditor.get(0); | |
- jQuery(window).resize(function(){ resizeTextArea(m_textEditor, " + OffSetX.ToString() + "," + OffSetY.ToString() + @"); }); | |
- jQuery(document).ready(function(){ resizeTextArea(m_textEditor, " + OffSetX.ToString() + "," + OffSetY.ToString() + @"); }); | |
+ var UmbEditor = new Umbraco.Controls.CodeEditor.UmbracoEditor(" + (!CodeMirrorEnabled).ToString().ToLower() + @", '" + this.ClientID + @"'); | |
+ var m_textEditor = UmbEditor.IsSimpleEditor ? UmbEditor._control : UmbEditor._editor.getScrollerElement(); | |
+ jQuery(window).resize(function(){ | |
+ resizeTextArea(m_textEditor, " + OffSetX.ToString() + "," + OffSetY.ToString() + @"); | |
+ if (!UmbEditor.IsSimpleEditor) | |
+ UmbEditor._editor.refresh(); | |
+ }); | |
+ jQuery(document).ready(function(){ | |
+ resizeTextArea(m_textEditor, " + OffSetX.ToString() + "," + OffSetY.ToString() + @"); | |
+ if (!UmbEditor.IsSimpleEditor) | |
+ UmbEditor._editor.refresh(); | |
+ }); | |
"; | |
if (!UmbracoSettings.ScriptDisableEditor && HttpContext.Current.Request.Browser.Browser == "IE") | |
@@ -176,62 +186,49 @@ | |
protected string RenderCodeEditor() | |
{ | |
- | |
- string[] parserFiles = new string[] { "tokenizejavascript.js", "parsejavascript.js" }; | |
- string[] cssFile = new string[] { "jscolors.css", "umbracoCustom.css" }; | |
- | |
+ string mode = "htmlmixed"; | |
switch (CodeBase) | |
{ | |
case EditorType.JavaScript: | |
- parserFiles = new string[] { "tokenizejavascript.js", "parsejavascript.js" }; | |
- cssFile = new string[] { "jscolors.css", "umbracoCustom.css" }; | |
+ mode = "javascript"; | |
break; | |
case EditorType.Css: | |
- parserFiles = new string[] { "parsecss.js" }; | |
- cssFile = new string[] { "csscolors.css", "umbracoCustom.css" }; | |
+ mode = "css"; | |
break; | |
case EditorType.Python: | |
- parserFiles = new string[] { "parsepython.js" }; | |
- cssFile = new string[] { "pythoncolors.css", "umbracoCustom.css" }; | |
+ mode = "python"; | |
break; | |
case EditorType.XML: | |
- parserFiles = new string[] { "parsexml.js" }; | |
- cssFile = new string[] { "xmlcolors.css", "umbracoCustom.css" }; | |
+ mode = "xml"; | |
break; | |
case EditorType.HTML: | |
- parserFiles = new string[] { "parsexml.js", "parsecss.js", "tokenizejavascript.js", "parsejavascript.js", "parsehtmlmixed.js" }; | |
- cssFile = new string[] { "xmlcolors.css", "jscolors.css", "csscolors.css", "umbracoCustom.css" }; | |
+ mode = "htmlmixed"; | |
+ break; | |
+ case EditorType.Razor: | |
+ mode = "razor"; | |
break; | |
} | |
- var jsEventCode = @" | |
- var textarea = document.getElementById('" + CodeTextBox.ClientID + @"'); | |
- | |
- | |
- var codeEditor = CodeMirror.fromTextArea(textarea, { | |
- | |
- width: ""100%"", | |
- height: ""100%"", | |
- tabMode: ""shift"", | |
- textWrapping: false, | |
- lineNumbers: true, | |
- parserfile: [" + string.Join(",", | |
- parserFiles | |
- .Select(x => string.Format(@"""{0}""", x)) | |
- .ToArray()) + @"], | |
- stylesheet: [" + string.Join(",", | |
- | |
- cssFile | |
- .Select(x => string.Format(@"""{0}""", IOHelper.ResolveUrl(SystemDirectories.Umbraco_client) + @"/CodeMirror/css/" + x)) | |
- .ToArray()) + @"], | |
- path: """ + IOHelper.ResolveUrl(SystemDirectories.Umbraco_client) + @"/CodeMirror/js/"", | |
- content: textarea.value, | |
- autoMatchParens: false," | |
- + (string.IsNullOrEmpty(ClientSaveMethod) ? "" : @"saveFunction: " + ClientSaveMethod + ",") + @" | |
- onChange: function() { /*codeVal.value = codeEditor.getCode(); */}}); | |
- | |
- "; | |
- | |
+ string codeMirrorExtra = string.Empty; | |
+ if (!string.IsNullOrEmpty(UmbracoSettings.ScriptEditorTheme)) | |
+ codeMirrorExtra += @" | |
+ theme: """ + UmbracoSettings.ScriptEditorTheme + @""","; | |
+ | |
+ if (UmbracoSettings.ScriptEditorKeepTabs) | |
+ codeMirrorExtra += @" | |
+ indentUnit: 8, | |
+ indentWithTabs: true, | |
+ "; | |
+ | |
+ var jsEventCode = @" | |
+ var textarea = document.getElementById('" + CodeTextBox.ClientID + @"'); | |
+ var codeEditor = CodeMirror.fromTextArea(textarea, {" + codeMirrorExtra + @" | |
+ mode: """ + mode + @""", | |
+ tabMode: ""classic"", | |
+ lineNumbers: true | |
+ }); | |
+ "; | |
+ | |
return jsEventCode; | |
} | |
} | |
diff -Nur --exclude _ReSharper.umbraco --exclude DesignTimeResolveAssemblyReferencesInput.cache --exclude '*.user' --exclude '*.suo' --exclude '*.FileListAbsolute.txt' --exclude bin --exclude obj umbraco_92d7d98ea3fe/umbraco/businesslogic/UmbracoSettings.cs umbraco_92d7d98ea3fe_mod/umbraco/businesslogic/UmbracoSettings.cs | |
--- umbraco_92d7d98ea3fe/umbraco/businesslogic/UmbracoSettings.cs 2011-09-21 11:05:44.000000000 +0200 | |
+++ umbraco_92d7d98ea3fe_mod/umbraco/businesslogic/UmbracoSettings.cs 2011-11-25 13:23:25.090000000 +0100 | |
@@ -581,6 +581,29 @@ | |
} | |
/// <summary> | |
+ /// Allows users to customize CodeMirror color scheme. | |
+ /// </summary> | |
+ public static string ScriptEditorTheme | |
+ { | |
+ get { return GetKey("/settings/content/scripteditor/scriptEditorTheme"); } | |
+ } | |
+ | |
+ /// <summary> | |
+ /// Makes the replacement of tabs with spaces configurable. | |
+ /// </summary> | |
+ public static bool ScriptEditorKeepTabs | |
+ { | |
+ get | |
+ { | |
+ string _tempValue = GetKey("/settings/content/scripteditor/scriptEditorKeepTabs"); | |
+ if (_tempValue != String.Empty) | |
+ return bool.Parse(_tempValue); | |
+ else | |
+ return false; | |
+ } | |
+ } | |
+ | |
+ /// <summary> | |
/// Gets the graphic headline format - png or gif | |
/// </summary> | |
/// <value>The graphic headline format.</value> | |
diff -Nur umbraco_6f33e2b81175/umbraco/presentation/umbraco_client/CodeArea/UmbracoEditor.js umbraco_6f33e2b81175_mod/umbraco/presentation/umbraco_client/CodeArea/UmbracoEditor.js | |
--- umbraco_6f33e2b81175/umbraco/presentation/umbraco_client/CodeArea/UmbracoEditor.js 2011-03-14 20:05:34.000000000 +0100 | |
+++ umbraco_6f33e2b81175_mod/umbraco/presentation/umbraco_client/CodeArea/UmbracoEditor.js 2011-11-17 16:59:48.490246000 +0100 | |
@@ -28,7 +28,7 @@ | |
} | |
else { | |
//this is a wrapper for CodeMirror | |
- return this._editor.getCode(); | |
+ return this._editor.getValue(); | |
} | |
}, | |
SetCode: function(code) { | |
@@ -37,7 +37,7 @@ | |
} | |
else { | |
//this is a wrapper for CodeMirror | |
- this._editor.setCode(code); | |
+ this._editor.setValue(code); | |
} | |
}, | |
Insert: function(open, end, txtEl, arg3) { | |
@@ -59,14 +59,14 @@ | |
} | |
} | |
else { | |
- this._editor.win.document.body.focus(); //need to restore the focus to the editor body | |
+ this._editor.focus(); //need to restore the focus to the editor body | |
//if the saved selection (IE only) is not null, then | |
if (this._cmSave != null) { | |
- this._editor.selectLines(this._cmSave.start.line, this._cmSave.start.character, this._cmSave.end.line, this._cmSave.end.character); | |
+ this._editor.setSelection({line:this._cmSave.start.line, ch:this._cmSave.start.character}, {line:this._cmSave.end.line, ch:this._cmSave.end.character}); | |
} | |
- var selection = this._editor.selection(); | |
+ var selection = this._editor.getSelection(); | |
var replace = (arg3) ? open + arg3 : open; //concat open and arg3, if arg3 specified | |
if (end != "") { | |
replace = replace + selection + end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment