TheDJ has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/122085

Change subject: CodeEditor: Add support for Editor themes
......................................................................

CodeEditor: Add support for Editor themes

Bug: 59924
Change-Id: Idbf0e9dce4498c288de0aa22beca651ee9d6eaaf
---
M CodeEditor.php
M modules/jquery.codeEditor.css
M modules/jquery.codeEditor.js
3 files changed, 53 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CodeEditor 
refs/changes/85/122085/1

diff --git a/CodeEditor.php b/CodeEditor.php
index 2665a0b..b82e9d1 100644
--- a/CodeEditor.php
+++ b/CodeEditor.php
@@ -69,6 +69,7 @@
                'ace/mode-json.js',
                'ace/mode-css.js',
                'ace/mode-lua.js',
+               'ace/ext-themelist.js',
        ),
 ) + $tpl;
 
diff --git a/modules/jquery.codeEditor.css b/modules/jquery.codeEditor.css
index 9860f4e..dbd15ec 100644
--- a/modules/jquery.codeEditor.css
+++ b/modules/jquery.codeEditor.css
@@ -1,5 +1,6 @@
 .group-codeeditor-format,
 .group-codeeditor-style,
+.group-codeeditor-themes,
 .codeEditor-ui-toolbar .group-insert,
 .codeEditor-ui-toolbar .group-format,
 .codeEditor-ui-toolbar .tabs span.tab-advanced,
@@ -10,6 +11,15 @@
 }
 
 .codeEditor-ui-toolbar .group-codeeditor-format,
-.codeEditor-ui-toolbar .group-codeeditor-style {
+.codeEditor-ui-toolbar .group-codeeditor-style,
+.codeEditor-ui-toolbar .group-codeeditor-themes {
        display: block;
 }
+
+.codeEditor-ui-toolbar .options {
+       z-index: 5;
+}
+
+.codeEditor-ui-toolbar .tool[rel=theme] .options .option {
+       padding: 0.2em 0.5em 0.2em 0.5em;
+}
diff --git a/modules/jquery.codeEditor.js b/modules/jquery.codeEditor.js
index 38e775b..ae8e47b 100644
--- a/modules/jquery.codeEditor.js
+++ b/modules/jquery.codeEditor.js
@@ -43,6 +43,7 @@
                context.showInvisibleChars = ( cookieEnabled === 1 );
                cookieEnabled = parseInt( $.cookie('codeEditor-' + 
context.instance + '-lineWrapping' ), 10 );
                context.lineWrappingActive = ( cookieEnabled === 1 );
+               context.codeEditorTheme = $.cookie('codeEditor-' + 
context.instance + '-theme' );
                context.showSearchReplace = 0;
 
                /*
@@ -163,6 +164,37 @@
                                var gotoLine = function( context ) {
                                        context.codeEditor.execCommand( 
'gotolinecolumn' );
                                };
+                               var selectTheme = function( context, themeItem 
) {
+                                       context.codeEditorTheme = 
themeItem.theme;
+                                       context.codeEditor.setTheme( 
context.codeEditorTheme );
+                                       context.fn.changeCookieValue( 'theme', 
context.codeEditorTheme );
+                                       $( '.tool[rel="theme"] .label' ).text( 
themeItem.caption );
+                               }
+
+                               var themeList = function( ) {
+                                       var themelist = require( 
'ace/ext/themelist' ),
+                                               result = {
+                                                       label: '',
+                                                       type: 'select',
+                                                       list: {}
+                                               };
+
+                                       themelist.themes.forEach( function( x ) 
{
+                                               if ( context.codeEditorTheme 
=== x.theme ) {
+                                                       result.label = 
x.caption;
+                                               }
+                                               result.list[x.theme] = {
+                                                       label: x.caption,
+                                                       action: {
+                                                               type: 
'callback',
+                                                               execute: 
function( context ) {
+                                                                       
selectTheme( context, x )
+                                                               }
+                                                       }
+                                               }
+                                       } );
+                                       return result;
+                               }
 
                                context.api.addToToolbar( context, {
                                        'section': 'main',
@@ -243,9 +275,15 @@
                                                                        }
                                                                }
                                                        }
+                                               },
+                                               'codeeditor-themes': {
+                                                       'tools': {
+                                                               'theme': 
themeList()
+                                                       }
                                                }
                                        }
                                } );
+                               $( '.group-codeeditor-themes' ).prependTo( 
'.section-main' );
                                $( '.group-codeeditor-style' ).prependTo( 
'.section-main' );
                                $( '.group-codeeditor-format' ).prependTo( 
'.section-main' );
                                $( '.group-codeeditor-main' ).prependTo( 
'.section-main' );
@@ -306,6 +344,9 @@
                                                exec: 
context.fn.aceGotoLineColumn
                                        } );
 
+                                       if ( context.codeEditorTheme ) {
+                                               context.codeEditor.setTheme( 
context.codeEditorTheme );
+                                       }
                                        context.codeEditor.setShowInvisibles( 
context.showInvisibleChars );
                                        
context.codeEditor.getSession().setUseWrapMode(context.lineWrappingActive);
 

-- 
To view, visit https://gerrit.wikimedia.org/r/122085
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Idbf0e9dce4498c288de0aa22beca651ee9d6eaaf
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CodeEditor
Gerrit-Branch: master
Gerrit-Owner: TheDJ <hartman.w...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to