2015-10-19 22:27:16 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor UserInterface MWSyntaxHighlightWindow class.
|
|
|
|
*
|
|
|
|
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MediaWiki syntax highlight window.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @abstract
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
ve.ui.MWSyntaxHighlightWindow = function VeUiMWSyntaxHighlightWindow() {
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.initClass( ve.ui.MWSyntaxHighlightWindow );
|
|
|
|
|
|
|
|
/* Static properties */
|
|
|
|
|
|
|
|
ve.ui.MWSyntaxHighlightWindow.static.title = OO.ui.deferMsg( 'syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-title' );
|
|
|
|
|
|
|
|
ve.ui.MWSyntaxHighlightWindow.static.dir = 'ltr';
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWSyntaxHighlightWindow.prototype.initialize = function () {
|
|
|
|
var noneMsg = ve.msg( 'syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-none' );
|
|
|
|
|
2018-10-08 17:37:11 +00:00
|
|
|
this.languageValid = null;
|
|
|
|
|
2016-11-09 19:39:06 +00:00
|
|
|
this.language = new OO.ui.ComboBoxInputWidget( {
|
2017-07-10 22:15:38 +00:00
|
|
|
$overlay: this.$overlay,
|
2015-10-19 22:27:16 +00:00
|
|
|
menu: {
|
|
|
|
filterFromInput: true,
|
2018-10-31 12:51:24 +00:00
|
|
|
items: ve.dm.MWSyntaxHighlightNode.static.getLanguages().map( function ( lang ) {
|
2015-10-19 22:27:16 +00:00
|
|
|
return new OO.ui.MenuOptionWidget( { data: lang, label: lang || noneMsg } );
|
|
|
|
} )
|
|
|
|
},
|
2016-11-15 17:20:54 +00:00
|
|
|
validate: function ( input ) {
|
2015-10-19 22:27:16 +00:00
|
|
|
return ve.dm.MWSyntaxHighlightNode.static.isLanguageSupported( input );
|
2016-11-15 17:20:54 +00:00
|
|
|
}
|
2015-10-19 22:27:16 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
this.showLinesCheckbox = new OO.ui.CheckboxInputWidget();
|
|
|
|
|
2015-06-09 15:00:04 +00:00
|
|
|
this.startLineNumber = new OO.ui.NumberInputWidget( {
|
|
|
|
min: 0,
|
2019-04-16 11:13:18 +00:00
|
|
|
isInteger: true,
|
|
|
|
showButtons: false
|
2015-06-09 15:00:04 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
// Events
|
|
|
|
this.language.connect( this, { change: 'onLanguageInputChange' } );
|
|
|
|
this.showLinesCheckbox.connect( this, { change: 'onShowLinesCheckboxChange' } );
|
|
|
|
this.startLineNumber.connect( this, { change: 'onStartLineNumberChange' } );
|
|
|
|
|
2015-10-19 22:27:16 +00:00
|
|
|
this.languageField = new OO.ui.FieldLayout( this.language, {
|
|
|
|
classes: [ 've-ui-mwSyntaxHighlightWindow-languageField' ],
|
|
|
|
align: 'top',
|
|
|
|
label: ve.msg( 'syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-language' )
|
|
|
|
} );
|
|
|
|
this.codeField = new OO.ui.FieldLayout( this.input, {
|
|
|
|
align: 'top',
|
|
|
|
label: ve.msg( 'syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-code' )
|
|
|
|
} );
|
|
|
|
this.showLinesField = new OO.ui.FieldLayout( this.showLinesCheckbox, {
|
|
|
|
align: 'inline',
|
|
|
|
label: ve.msg( 'syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-showlines' )
|
|
|
|
} );
|
2015-06-09 15:00:04 +00:00
|
|
|
this.startLineField = new OO.ui.FieldLayout( this.startLineNumber, {
|
|
|
|
classes: [ 've-ui-mwSyntaxHighlightWindow-startLineField' ],
|
|
|
|
align: 'left',
|
|
|
|
label: ve.msg( 'syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-startingline' )
|
|
|
|
} );
|
2015-10-19 22:27:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle input change events
|
|
|
|
*
|
|
|
|
* @param {string} value New value
|
|
|
|
*/
|
|
|
|
ve.ui.MWSyntaxHighlightWindow.prototype.onLanguageInputChange = function () {
|
2021-10-07 13:34:31 +00:00
|
|
|
var inspector = this;
|
|
|
|
var validity = this.language.getValidity();
|
2016-11-15 17:20:54 +00:00
|
|
|
validity.always( function () {
|
2018-10-08 17:37:11 +00:00
|
|
|
inspector.languageValid = validity.state() === 'resolved';
|
|
|
|
inspector.updateActions();
|
2015-10-19 22:27:16 +00:00
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2015-06-09 15:00:04 +00:00
|
|
|
/**
|
|
|
|
* Handle change events from the show lines chechbox
|
|
|
|
*
|
|
|
|
* @param {boolean} value Widget value
|
|
|
|
*/
|
|
|
|
ve.ui.MWSyntaxHighlightWindow.prototype.onShowLinesCheckboxChange = function () {
|
|
|
|
var showLines = this.showLinesCheckbox.isSelected();
|
|
|
|
this.input.toggleLineNumbers( showLines );
|
|
|
|
this.startLineNumber.setDisabled( !showLines );
|
2018-10-08 17:37:11 +00:00
|
|
|
this.updateActions();
|
2015-06-09 15:00:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle change events from the start line input
|
|
|
|
*
|
|
|
|
* @param {string} value Widget value
|
|
|
|
*/
|
|
|
|
ve.ui.MWSyntaxHighlightWindow.prototype.onStartLineNumberChange = function ( value ) {
|
2018-10-08 17:37:11 +00:00
|
|
|
var inspector = this,
|
|
|
|
input = this.input;
|
2015-06-09 15:00:04 +00:00
|
|
|
|
|
|
|
input.loadingPromise.done( function () {
|
|
|
|
input.editor.setOption( 'firstLineNumber', value !== '' ? +value : 1 );
|
2018-10-08 17:37:11 +00:00
|
|
|
} ).always( function () {
|
|
|
|
inspector.updateActions();
|
2015-06-09 15:00:04 +00:00
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2015-10-19 22:27:16 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc OO.ui.Window
|
|
|
|
*/
|
|
|
|
ve.ui.MWSyntaxHighlightWindow.prototype.getReadyProcess = function ( data, process ) {
|
|
|
|
return process.next( function () {
|
|
|
|
this.language.getMenu().toggle( false );
|
2016-11-15 17:20:54 +00:00
|
|
|
if ( !this.language.getValue() ) {
|
|
|
|
this.language.focus();
|
2015-10-19 22:27:16 +00:00
|
|
|
} else {
|
|
|
|
this.input.focus();
|
|
|
|
}
|
|
|
|
}, this );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc OO.ui.Window
|
|
|
|
*/
|
|
|
|
ve.ui.MWSyntaxHighlightWindow.prototype.getSetupProcess = function ( data, process ) {
|
|
|
|
return process.next( function () {
|
|
|
|
var attrs = this.selectedNode ? this.selectedNode.getAttribute( 'mw' ).attrs : {},
|
2018-10-31 12:45:50 +00:00
|
|
|
language = attrs.lang ? attrs.lang.toLowerCase() : '',
|
2015-06-09 15:00:04 +00:00
|
|
|
showLines = attrs.line !== undefined,
|
2019-04-16 11:13:18 +00:00
|
|
|
startLine = attrs.start,
|
|
|
|
isReadOnly = this.isReadOnly();
|
2015-10-19 22:27:16 +00:00
|
|
|
|
2019-04-16 11:13:18 +00:00
|
|
|
this.language.setValue( language ).setReadOnly( isReadOnly );
|
2015-10-19 22:27:16 +00:00
|
|
|
|
2019-04-16 11:13:18 +00:00
|
|
|
this.showLinesCheckbox.setSelected( showLines ).setDisabled( isReadOnly );
|
|
|
|
this.startLineNumber.setValue( startLine ).setReadOnly( isReadOnly );
|
2015-10-19 22:27:16 +00:00
|
|
|
}, this );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc OO.ui.Window
|
|
|
|
*/
|
|
|
|
ve.ui.MWSyntaxHighlightWindow.prototype.getTeardownProcess = function ( data, process ) {
|
|
|
|
return process;
|
|
|
|
};
|
|
|
|
|
2018-10-08 17:37:11 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc ve.ui.MWExtensionWindow
|
|
|
|
*/
|
|
|
|
ve.ui.MWSyntaxHighlightWindow.prototype.updateActions = function () {
|
|
|
|
this.getActions().setAbilities( { done: this.languageValid && this.isModified() } );
|
|
|
|
};
|
|
|
|
|
2015-10-19 22:27:16 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc ve.ui.MWExtensionWindow
|
|
|
|
*/
|
|
|
|
ve.ui.MWSyntaxHighlightWindow.prototype.updateMwData = function ( mwData ) {
|
2015-06-09 15:00:04 +00:00
|
|
|
var language = this.language.getValue(),
|
|
|
|
showLines = this.showLinesCheckbox.isSelected(),
|
|
|
|
startLine = this.startLineNumber.getValue();
|
2015-10-19 22:27:16 +00:00
|
|
|
|
|
|
|
mwData.attrs.lang = language || undefined;
|
|
|
|
mwData.attrs.line = showLines ? '1' : undefined;
|
2015-06-09 15:00:04 +00:00
|
|
|
mwData.attrs.start = startLine !== '' ? startLine : undefined;
|
2015-10-19 22:27:16 +00:00
|
|
|
};
|