Debian Codegraph @

extensions/SyntaxHighlight_GeSHi/modules/ve-syntaxhighlight/ve.ui.MWSyntaxHighlightDialog.js

raw symbols SCIP
1 /*!
2 * VisualEditor UserInterface MWSyntaxHighlightDialog class.
3 *
4 * @copyright VisualEditor Team and others
5 * @license The MIT License (MIT); see LICENSE.txt
6 */
7
8 /**
9 * MediaWiki syntax highlight dialog.
10 *
11 * @class
12 * @extends ve.ui.MWExtensionDialog
13 * @mixes ve.ui.MWSyntaxHighlightWindow
14 *
15 * @constructor
16 * @param {Object} [config] Configuration options
17 */
18 ve.ui.MWSyntaxHighlightDialog = function VeUiMWSyntaxHighlightDialog() {
19 // Parent constructor
20 ve.ui.MWSyntaxHighlightDialog.super.apply( this, arguments );
21
22 // Mixin constructor
23 ve.ui.MWSyntaxHighlightWindow.call( this );
24 };
25
26 /* Inheritance */
27
28 OO.inheritClass( ve.ui.MWSyntaxHighlightDialog, ve.ui.MWExtensionDialog );
29
30 OO.mixinClass( ve.ui.MWSyntaxHighlightDialog, ve.ui.MWSyntaxHighlightWindow );
31
32 /* Static properties */
33
34 ve.ui.MWSyntaxHighlightDialog.static.name = 'syntaxhighlightDialog';
35
36 ve.ui.MWSyntaxHighlightDialog.static.size = 'larger';
37
38 ve.ui.MWSyntaxHighlightDialog.static.modelClasses = [ ve.dm.MWBlockSyntaxHighlightNode ];
39
40 /* Methods */
41
42 /**
43 * @inheritdoc
44 */
45 ve.ui.MWSyntaxHighlightDialog.prototype.initialize = function () {
46 // Parent method
47 ve.ui.MWSyntaxHighlightDialog.super.prototype.initialize.call( this );
48
49 this.input = new ve.ui.MWAceEditorWidget( {
50 limit: 1,
51 rows: 10,
52 maxRows: 25,
53 autosize: true,
54 autocomplete: 'live',
55 classes: [ 've-ui-mwExtensionWindow-input' ]
56 } );
57
58 this.input.connect( this, { resize: 'updateSize' } );
59
60 // Mixin method
61 ve.ui.MWSyntaxHighlightWindow.prototype.initialize.call( this );
62
63 this.languageField.setAlignment( 'left' );
64
65 this.contentLayout = new OO.ui.PanelLayout( {
66 scrollable: true,
67 padded: true,
68 expanded: false,
69 content: [
70 this.languageField,
71 this.codeField,
72 this.showLinesField,
73 this.startLineField
74 ]
75 } );
76
77 // Initialization
78 this.$content.addClass( 've-ui-mwSyntaxHighlightDialog-content' );
79 this.$body.append( this.contentLayout.$element );
80 };
81
82 /**
83 * @inheritdoc MWSyntaxHighlightWindow
84 */
85 ve.ui.MWSyntaxHighlightDialog.prototype.onLanguageInputChange = function () {
86 // Mixin method
87 ve.ui.MWSyntaxHighlightWindow.prototype.onLanguageInputChange.call( this );
88
89 const validity = this.language.getValidity();
90 validity.always( () => {
91 const language = ve.dm.MWSyntaxHighlightNode.static.convertLanguageToAce( this.language.getValue() );
92 this.input.setLanguage( validity.state() === 'resolved' ? language : 'text' );
93 } );
94 };
95
96 /**
97 * @inheritdoc
98 */
99 ve.ui.MWSyntaxHighlightDialog.prototype.getReadyProcess = function ( data ) {
100 // Parent process
101 const process = ve.ui.MWSyntaxHighlightDialog.super.prototype.getReadyProcess.call( this, data );
102 // Mixin process
103 return ve.ui.MWSyntaxHighlightWindow.prototype.getReadyProcess.call( this, data, process );
104 };
105
106 /**
107 * @inheritdoc
108 */
109 ve.ui.MWSyntaxHighlightDialog.prototype.getSetupProcess = function ( data ) {
110 // Parent process
111 const process = ve.ui.MWSyntaxHighlightDialog.super.prototype.getSetupProcess.call( this, data );
112 // Mixin process
113 return ve.ui.MWSyntaxHighlightWindow.prototype.getSetupProcess.call( this, data, process )
114 .first( () => {
115 this.input.setup();
116 } )
117 .next( () => {
118 this.onShowLinesCheckboxChange();
119 this.input.clearUndoStack();
120 } );
121 };
122
123 /**
124 * @inheritdoc
125 */
126 ve.ui.MWSyntaxHighlightDialog.prototype.getTeardownProcess = function ( data ) {
127 // Parent process
128 const process = ve.ui.MWSyntaxHighlightDialog.super.prototype.getTeardownProcess.call( this, data );
129 // Mixin process
130 return ve.ui.MWSyntaxHighlightWindow.prototype.getTeardownProcess.call( this, data, process ).first( () => {
131 this.language.setValue( '' );
132 this.input.teardown();
133 } );
134 };
135
136 /**
137 * @inheritdoc
138 */
139 ve.ui.MWSyntaxHighlightDialog.prototype.updateMwData = function () {
140 // Parent method
141 ve.ui.MWSyntaxHighlightDialog.super.prototype.updateMwData.apply( this, arguments );
142 // Mixin method
143 ve.ui.MWSyntaxHighlightWindow.prototype.updateMwData.apply( this, arguments );
144 };
145
146 /* Registration */
147
148 ve.ui.windowFactory.register( ve.ui.MWSyntaxHighlightDialog );