2015-10-19 22:27:16 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor UserInterface MWSyntaxHighlightDialog class.
|
|
|
|
*
|
2024-02-29 15:13:03 +00:00
|
|
|
* @copyright VisualEditor Team and others
|
2015-10-19 22:27:16 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MediaWiki syntax highlight dialog.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends ve.ui.MWExtensionDialog
|
|
|
|
* @mixins ve.ui.MWSyntaxHighlightWindow
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} [config] Configuration options
|
|
|
|
*/
|
|
|
|
ve.ui.MWSyntaxHighlightDialog = function VeUiMWSyntaxHighlightDialog() {
|
|
|
|
// Parent constructor
|
|
|
|
ve.ui.MWSyntaxHighlightDialog.super.apply( this, arguments );
|
|
|
|
|
|
|
|
// Mixin constructor
|
|
|
|
ve.ui.MWSyntaxHighlightWindow.call( this );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.ui.MWSyntaxHighlightDialog, ve.ui.MWExtensionDialog );
|
|
|
|
|
|
|
|
OO.mixinClass( ve.ui.MWSyntaxHighlightDialog, ve.ui.MWSyntaxHighlightWindow );
|
|
|
|
|
|
|
|
/* Static properties */
|
|
|
|
|
|
|
|
ve.ui.MWSyntaxHighlightDialog.static.name = 'syntaxhighlightDialog';
|
|
|
|
|
|
|
|
ve.ui.MWSyntaxHighlightDialog.static.size = 'larger';
|
|
|
|
|
|
|
|
ve.ui.MWSyntaxHighlightDialog.static.modelClasses = [ ve.dm.MWBlockSyntaxHighlightNode ];
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWSyntaxHighlightDialog.prototype.initialize = function () {
|
|
|
|
// Parent method
|
|
|
|
ve.ui.MWSyntaxHighlightDialog.super.prototype.initialize.call( this );
|
|
|
|
|
2015-10-20 14:20:56 +00:00
|
|
|
this.input = new ve.ui.MWAceEditorWidget( {
|
|
|
|
limit: 1,
|
|
|
|
rows: 10,
|
|
|
|
maxRows: 25,
|
|
|
|
autosize: true,
|
2016-09-19 16:24:47 +00:00
|
|
|
autocomplete: 'live',
|
2015-10-20 14:20:56 +00:00
|
|
|
classes: [ 've-ui-mwExtensionWindow-input' ]
|
|
|
|
} );
|
|
|
|
|
|
|
|
this.input.connect( this, { resize: 'updateSize' } );
|
|
|
|
|
2015-10-19 22:27:16 +00:00
|
|
|
// Mixin method
|
|
|
|
ve.ui.MWSyntaxHighlightWindow.prototype.initialize.call( this );
|
|
|
|
|
|
|
|
this.languageField.setAlignment( 'left' );
|
|
|
|
|
|
|
|
this.contentLayout = new OO.ui.PanelLayout( {
|
|
|
|
scrollable: true,
|
|
|
|
padded: true,
|
|
|
|
expanded: false,
|
|
|
|
content: [
|
|
|
|
this.languageField,
|
|
|
|
this.codeField,
|
2015-06-09 15:00:04 +00:00
|
|
|
this.showLinesField,
|
|
|
|
this.startLineField
|
2015-10-19 22:27:16 +00:00
|
|
|
]
|
|
|
|
} );
|
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.$content.addClass( 've-ui-mwSyntaxHighlightDialog-content' );
|
|
|
|
this.$body.append( this.contentLayout.$element );
|
|
|
|
};
|
|
|
|
|
2015-10-20 14:20:56 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc MWSyntaxHighlightWindow
|
|
|
|
*/
|
|
|
|
ve.ui.MWSyntaxHighlightDialog.prototype.onLanguageInputChange = function () {
|
|
|
|
// Mixin method
|
|
|
|
ve.ui.MWSyntaxHighlightWindow.prototype.onLanguageInputChange.call( this );
|
|
|
|
|
2024-04-23 11:29:42 +00:00
|
|
|
const validity = this.language.getValidity();
|
|
|
|
validity.always( () => {
|
|
|
|
const language = ve.dm.MWSyntaxHighlightNode.static.convertLanguageToAce( this.language.getValue() );
|
|
|
|
this.input.setLanguage( validity.state() === 'resolved' ? language : 'text' );
|
2015-10-20 14:20:56 +00:00
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2015-10-19 22:27:16 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWSyntaxHighlightDialog.prototype.getReadyProcess = function ( data ) {
|
|
|
|
// Parent process
|
2024-04-23 11:29:42 +00:00
|
|
|
const process = ve.ui.MWSyntaxHighlightDialog.super.prototype.getReadyProcess.call( this, data );
|
2015-10-19 22:27:16 +00:00
|
|
|
// Mixin process
|
|
|
|
return ve.ui.MWSyntaxHighlightWindow.prototype.getReadyProcess.call( this, data, process );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWSyntaxHighlightDialog.prototype.getSetupProcess = function ( data ) {
|
|
|
|
// Parent process
|
2024-04-23 11:29:42 +00:00
|
|
|
const process = ve.ui.MWSyntaxHighlightDialog.super.prototype.getSetupProcess.call( this, data );
|
2015-10-19 22:27:16 +00:00
|
|
|
// Mixin process
|
2015-10-20 14:20:56 +00:00
|
|
|
return ve.ui.MWSyntaxHighlightWindow.prototype.getSetupProcess.call( this, data, process )
|
2024-04-23 11:29:42 +00:00
|
|
|
.first( () => {
|
2015-10-20 14:20:56 +00:00
|
|
|
this.input.setup();
|
2024-04-23 11:29:42 +00:00
|
|
|
} )
|
|
|
|
.next( () => {
|
2015-10-20 14:20:56 +00:00
|
|
|
this.onShowLinesCheckboxChange();
|
2015-10-30 16:27:43 +00:00
|
|
|
this.input.clearUndoStack();
|
2024-04-23 11:29:42 +00:00
|
|
|
} );
|
2015-10-19 22:27:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWSyntaxHighlightDialog.prototype.getTeardownProcess = function ( data ) {
|
|
|
|
// Parent process
|
2024-04-23 11:29:42 +00:00
|
|
|
const process = ve.ui.MWSyntaxHighlightDialog.super.prototype.getTeardownProcess.call( this, data );
|
2015-10-19 22:27:16 +00:00
|
|
|
// Mixin process
|
2024-04-23 11:29:42 +00:00
|
|
|
return ve.ui.MWSyntaxHighlightWindow.prototype.getTeardownProcess.call( this, data, process ).first( () => {
|
2016-11-15 17:20:54 +00:00
|
|
|
this.language.setValue( '' );
|
2015-10-20 14:20:56 +00:00
|
|
|
this.input.teardown();
|
2024-04-23 11:29:42 +00:00
|
|
|
} );
|
2015-10-19 22:27:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWSyntaxHighlightDialog.prototype.updateMwData = function () {
|
|
|
|
// Parent method
|
|
|
|
ve.ui.MWSyntaxHighlightDialog.super.prototype.updateMwData.apply( this, arguments );
|
|
|
|
// Mixin method
|
|
|
|
ve.ui.MWSyntaxHighlightWindow.prototype.updateMwData.apply( this, arguments );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.ui.windowFactory.register( ve.ui.MWSyntaxHighlightDialog );
|