| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
ve.ui.MWSyntaxHighlightWindow = function VeUiMWSyntaxHighlightWindow() { |
| 17 |
}; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
OO.initClass( ve.ui.MWSyntaxHighlightWindow ); |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
ve.ui.MWSyntaxHighlightWindow.static.title = OO.ui.deferMsg( 'syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-title' ); |
| 26 |
|
| 27 |
ve.ui.MWSyntaxHighlightWindow.static.dir = 'ltr'; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
ve.ui.MWSyntaxHighlightWindow.prototype.initialize = function () { |
| 35 |
const noneMsg = ve.msg( 'syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-none' ); |
| 36 |
|
| 37 |
this.languageValid = null; |
| 38 |
|
| 39 |
this.language = new OO.ui.ComboBoxInputWidget( { |
| 40 |
$overlay: this.$overlay, |
| 41 |
menu: { |
| 42 |
filterFromInput: true, |
| 43 |
items: ve.dm.MWSyntaxHighlightNode.static.getLanguages().map( ( lang ) => new OO.ui.MenuOptionWidget( { data: lang, label: lang || noneMsg } ) |
| 44 |
) |
| 45 |
}, |
| 46 |
validate: function ( input ) { |
| 47 |
return ve.dm.MWSyntaxHighlightNode.static.isLanguageSupported( input ); |
| 48 |
} |
| 49 |
} ); |
| 50 |
|
| 51 |
this.showLinesCheckbox = new OO.ui.CheckboxInputWidget(); |
| 52 |
|
| 53 |
this.startLineNumber = new OO.ui.NumberInputWidget( { |
| 54 |
min: 0, |
| 55 |
isInteger: true, |
| 56 |
showButtons: false |
| 57 |
} ); |
| 58 |
|
| 59 |
|
| 60 |
this.language.connect( this, { change: 'onLanguageInputChange' } ); |
| 61 |
this.showLinesCheckbox.connect( this, { change: 'onShowLinesCheckboxChange' } ); |
| 62 |
this.startLineNumber.connect( this, { change: 'onStartLineNumberChange' } ); |
| 63 |
|
| 64 |
this.languageField = new OO.ui.FieldLayout( this.language, { |
| 65 |
classes: [ 've-ui-mwSyntaxHighlightWindow-languageField' ], |
| 66 |
align: 'top', |
| 67 |
label: ve.msg( 'syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-language' ) |
| 68 |
} ); |
| 69 |
this.codeField = new OO.ui.FieldLayout( this.input, { |
| 70 |
align: 'top', |
| 71 |
label: ve.msg( 'syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-code' ) |
| 72 |
} ); |
| 73 |
this.showLinesField = new OO.ui.FieldLayout( this.showLinesCheckbox, { |
| 74 |
align: 'inline', |
| 75 |
label: ve.msg( 'syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-showlines' ) |
| 76 |
} ); |
| 77 |
this.startLineField = new OO.ui.FieldLayout( this.startLineNumber, { |
| 78 |
classes: [ 've-ui-mwSyntaxHighlightWindow-startLineField' ], |
| 79 |
align: 'left', |
| 80 |
label: ve.msg( 'syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-startingline' ) |
| 81 |
} ); |
| 82 |
}; |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
ve.ui.MWSyntaxHighlightWindow.prototype.onLanguageInputChange = function () { |
| 90 |
const validity = this.language.getValidity(); |
| 91 |
validity.always( () => { |
| 92 |
this.languageValid = validity.state() === 'resolved'; |
| 93 |
this.updateActions(); |
| 94 |
} ); |
| 95 |
}; |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
ve.ui.MWSyntaxHighlightWindow.prototype.onShowLinesCheckboxChange = function () { |
| 103 |
const showLines = this.showLinesCheckbox.isSelected(); |
| 104 |
this.input.toggleLineNumbers( showLines ); |
| 105 |
this.startLineNumber.setDisabled( !showLines ); |
| 106 |
this.updateActions(); |
| 107 |
}; |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
ve.ui.MWSyntaxHighlightWindow.prototype.onStartLineNumberChange = function ( value ) { |
| 115 |
const input = this.input; |
| 116 |
|
| 117 |
input.loadingPromise.done( () => { |
| 118 |
input.editor.setOption( 'firstLineNumber', value !== '' ? +value : 1 ); |
| 119 |
} ).always( () => { |
| 120 |
this.updateActions(); |
| 121 |
} ); |
| 122 |
}; |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
ve.ui.MWSyntaxHighlightWindow.prototype.getReadyProcess = function ( data, process ) { |
| 128 |
return process.next( () => { |
| 129 |
this.language.getMenu().toggle( false ); |
| 130 |
if ( !this.language.getValue() ) { |
| 131 |
this.language.focus(); |
| 132 |
} else { |
| 133 |
this.input.focus(); |
| 134 |
} |
| 135 |
} ); |
| 136 |
}; |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
ve.ui.MWSyntaxHighlightWindow.prototype.getSetupProcess = function ( data, process ) { |
| 142 |
return process.next( () => { |
| 143 |
const attrs = this.selectedNode ? this.selectedNode.getAttribute( 'mw' ).attrs : {}, |
| 144 |
language = attrs.lang ? attrs.lang.toLowerCase() : '', |
| 145 |
showLines = attrs.line !== undefined, |
| 146 |
startLine = attrs.start, |
| 147 |
isReadOnly = this.isReadOnly(); |
| 148 |
|
| 149 |
this.language.setValue( language ).setReadOnly( isReadOnly ); |
| 150 |
|
| 151 |
this.showLinesCheckbox.setSelected( showLines ).setDisabled( isReadOnly ); |
| 152 |
this.startLineNumber.setValue( startLine ).setReadOnly( isReadOnly ); |
| 153 |
} ); |
| 154 |
}; |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
ve.ui.MWSyntaxHighlightWindow.prototype.getTeardownProcess = function ( data, process ) { |
| 160 |
return process; |
| 161 |
}; |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
ve.ui.MWSyntaxHighlightWindow.prototype.updateActions = function () { |
| 167 |
this.getActions().setAbilities( { done: this.languageValid && this.isModified() } ); |
| 168 |
}; |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
ve.ui.MWSyntaxHighlightWindow.prototype.updateMwData = function ( mwData ) { |
| 174 |
const language = this.language.getValue(), |
| 175 |
showLines = this.showLinesCheckbox.isSelected(), |
| 176 |
startLine = this.startLineNumber.getValue(); |
| 177 |
|
| 178 |
mwData.attrs.lang = language || undefined; |
| 179 |
if ( !showLines ) { |
| 180 |
delete mwData.attrs.line; |
| 181 |
|
| 182 |
} else if ( !( 'line' in mwData.attrs ) ) { |
| 183 |
mwData.attrs.line = '1'; |
| 184 |
} |
| 185 |
mwData.attrs.start = startLine !== '' ? startLine : undefined; |
| 186 |
}; |