From a1384f34f3916186900dea3a47eae141eee6af3d Mon Sep 17 00:00:00 2001 From: Thiemo Kreuz Date: Fri, 9 Jul 2021 17:04:14 +0200 Subject: [PATCH] Add template outline widgets for all content types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The two new widgets are pretty trivial now, thanks to the base class. Note there is still no code to delete the widgets. That's also why you will always see a placeholder widget at the top. This will be fixed with the next patches. This patch also renames most of the "…TemplateOutline…" classes to "…TransclusionOutline…" The reason is that these widgets are not for a single template, but part of the container widget for a more complex transclusion (i.e. a sequence of multiple templates and wikitext snippets). Bug: T274544 Change-Id: If4219b0b8ad4d1969ab1ec5ec4db0728811bab35 --- extension.json | 8 ++++--- .../dialogs/ve.ui.MWTransclusionDialog.css | 6 +++--- ...ui.MWTransclusionOutlineContainerWidget.js | 9 ++++++-- ... ve.ui.MWTransclusionOutlinePartWidget.js} | 14 ++++++------- ....MWTransclusionOutlinePlaceholderWidget.js | 21 +++++++++++++++++++ ...ui.MWTransclusionOutlineTemplateWidget.js} | 18 +++++++--------- ....ui.MWTransclusionOutlineWikitextWidget.js | 21 +++++++++++++++++++ 7 files changed, 72 insertions(+), 25 deletions(-) rename modules/ve-mw/ui/widgets/{ve.ui.MWTemplateOutlinePartWidget.js => ve.ui.MWTransclusionOutlinePartWidget.js} (65%) create mode 100644 modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlinePlaceholderWidget.js rename modules/ve-mw/ui/widgets/{ve.ui.MWTemplateOutlineTemplateWidget.js => ve.ui.MWTransclusionOutlineTemplateWidget.js} (82%) create mode 100644 modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlineWikitextWidget.js diff --git a/extension.json b/extension.json index c104b47d92..d473d93fce 100644 --- a/extension.json +++ b/extension.json @@ -2149,9 +2149,11 @@ "modules/ve-mw/ui/contextitems/ve.ui.MWTransclusionContextItem.js", "modules/ve-mw/ui/contextitems/ve.ui.MWDefinedTransclusionContextItem.js", "modules/ve-mw/ui/widgets/ve.ui.MWTemplateOutlineParameterCheckboxLayout.js", - "modules/ve-mw/ui/widgets/ve.ui.MWTemplateOutlinePartWidget.js", - "modules/ve-mw/ui/widgets/ve.ui.MWTemplateOutlineTemplateWidget.js", - "modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlineContainerWidget.js" + "modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlinePartWidget.js", + "modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlineTemplateWidget.js", + "modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlineContainerWidget.js", + "modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlinePlaceholderWidget.js", + "modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlineWikitextWidget.js" ], "styles": [ "modules/ve-mw/ce/styles/nodes/ve.ce.MWTransclusionNode.css", diff --git a/modules/ve-mw/ui/styles/dialogs/ve.ui.MWTransclusionDialog.css b/modules/ve-mw/ui/styles/dialogs/ve.ui.MWTransclusionDialog.css index 497f0ba17b..74e3fc6724 100644 --- a/modules/ve-mw/ui/styles/dialogs/ve.ui.MWTransclusionDialog.css +++ b/modules/ve-mw/ui/styles/dialogs/ve.ui.MWTransclusionDialog.css @@ -50,7 +50,7 @@ font-style: italic; } -.ve-ui-mwTemplateOutlinePartWidget-header { +.ve-ui-mwTransclusionOutlinePartWidget-header { cursor: pointer; font-weight: bold; overflow: hidden; @@ -59,11 +59,11 @@ text-overflow: ellipsis; } -.ve-ui-mwTemplateOutlinePartWidget-header:hover { +.ve-ui-mwTransclusionOutlinePartWidget-header:hover { background-color: #eaecf0; } -.ve-ui-mwTemplateOutlinePartWidget-header .oo-ui-iconElement-icon { +.ve-ui-mwTransclusionOutlinePartWidget-header .oo-ui-iconElement-icon { left: 11px; } diff --git a/modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlineContainerWidget.js b/modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlineContainerWidget.js index eac0b45b74..a31bbbb0f0 100644 --- a/modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlineContainerWidget.js +++ b/modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlineContainerWidget.js @@ -51,8 +51,13 @@ ve.ui.MWTransclusionOutlineContainerWidget.prototype.onReplacePart = function ( if ( added instanceof ve.dm.MWTemplateModel ) { this.addTemplate( added ); + } else if ( added instanceof ve.dm.MWTemplatePlaceholderModel ) { + var placeholder = new ve.ui.MWTransclusionOutlinePlaceholderWidget(); + this.$element.append( placeholder.$element ); + } else if ( added instanceof ve.dm.MWTransclusionContentModel ) { + var wikitextItem = new ve.ui.MWTransclusionOutlineWikitextWidget(); + this.$element.append( wikitextItem.$element ); } - // TODO: and for wikitext snippets? }; /* Methods */ @@ -63,7 +68,7 @@ ve.ui.MWTransclusionOutlineContainerWidget.prototype.onReplacePart = function ( */ ve.ui.MWTransclusionOutlineContainerWidget.prototype.addTemplate = function ( template ) { // FIXME: Respect order - var container = new ve.ui.MWTemplateOutlineTemplateWidget( { + var container = new ve.ui.MWTransclusionOutlineTemplateWidget( { templateModel: template } ); diff --git a/modules/ve-mw/ui/widgets/ve.ui.MWTemplateOutlinePartWidget.js b/modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlinePartWidget.js similarity index 65% rename from modules/ve-mw/ui/widgets/ve.ui.MWTemplateOutlinePartWidget.js rename to modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlinePartWidget.js index 72048ab577..863bc6f940 100644 --- a/modules/ve-mw/ui/widgets/ve.ui.MWTemplateOutlinePartWidget.js +++ b/modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlinePartWidget.js @@ -17,26 +17,26 @@ * @cfg {string} [icon=''] * @cfg {string} [label] */ -ve.ui.MWTemplateOutlinePartWidget = function VeUiMWTemplateOutlinePartWidget( config ) { +ve.ui.MWTransclusionOutlinePartWidget = function VeUiMWTransclusionOutlinePartWidget( config ) { // Parent constructor - ve.ui.MWTemplateOutlinePartWidget.super.call( this, config ); + ve.ui.MWTransclusionOutlinePartWidget.super.call( this, config ); // Mixin constructors OO.ui.mixin.IconElement.call( this, config ); OO.ui.mixin.LabelElement.call( this, config ); this.$header = $( '
' ) - .addClass( 've-ui-mwTemplateOutlinePartWidget-header' ) + .addClass( 've-ui-mwTransclusionOutlinePartWidget-header' ) .prepend( this.$icon, this.$label ); this.$element - .addClass( 've-ui-mwTemplateOutlinePartWidget' ) + .addClass( 've-ui-mwTransclusionOutlinePartWidget' ) .prepend( this.$header ); }; /* Inheritance */ -OO.inheritClass( ve.ui.MWTemplateOutlinePartWidget, OO.ui.Widget ); -OO.mixinClass( ve.ui.MWTemplateOutlinePartWidget, OO.ui.mixin.IconElement ); -OO.mixinClass( ve.ui.MWTemplateOutlinePartWidget, OO.ui.mixin.LabelElement ); +OO.inheritClass( ve.ui.MWTransclusionOutlinePartWidget, OO.ui.Widget ); +OO.mixinClass( ve.ui.MWTransclusionOutlinePartWidget, OO.ui.mixin.IconElement ); +OO.mixinClass( ve.ui.MWTransclusionOutlinePartWidget, OO.ui.mixin.LabelElement ); // TODO: Add OO.ui.mixin.AccessKeyedElement? // TODO: Add OO.ui.mixin.TitledElement? diff --git a/modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlinePlaceholderWidget.js b/modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlinePlaceholderWidget.js new file mode 100644 index 0000000000..5b607efd48 --- /dev/null +++ b/modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlinePlaceholderWidget.js @@ -0,0 +1,21 @@ +/** + * @class + * @extends ve.ui.MWTransclusionOutlinePartWidget + * + * @constructor + * @param {Object} [config] + */ +ve.ui.MWTransclusionOutlinePlaceholderWidget = function VeUiMWTransclusionOutlinePlaceholderWidget( config ) { + // Initialize config + config = $.extend( { + icon: 'puzzle', + label: ve.msg( 'visualeditor-dialog-transclusion-add-template' ) + }, config ); + + // Parent constructor + ve.ui.MWTransclusionOutlinePlaceholderWidget.super.call( this, config ); +}; + +/* Inheritance */ + +OO.inheritClass( ve.ui.MWTransclusionOutlinePlaceholderWidget, ve.ui.MWTransclusionOutlinePartWidget ); diff --git a/modules/ve-mw/ui/widgets/ve.ui.MWTemplateOutlineTemplateWidget.js b/modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlineTemplateWidget.js similarity index 82% rename from modules/ve-mw/ui/widgets/ve.ui.MWTemplateOutlineTemplateWidget.js rename to modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlineTemplateWidget.js index c3061cdc77..6929d3b7f5 100644 --- a/modules/ve-mw/ui/widgets/ve.ui.MWTemplateOutlineTemplateWidget.js +++ b/modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlineTemplateWidget.js @@ -1,6 +1,4 @@ /*! - * VisualEditor user interface MWTemplateOutlineTemplateWidget class. - * * @license The MIT License (MIT); see LICENSE.txt */ @@ -8,13 +6,13 @@ * Container for template, as rendered in the template dialog sidebar. * * @class - * @extends ve.ui.MWTemplateOutlinePartWidget + * @extends ve.ui.MWTransclusionOutlinePartWidget * * @constructor * @param {Object} config * @param {ve.dm.MWTemplateModel} config.templateModel */ -ve.ui.MWTemplateOutlineTemplateWidget = function VeUiMWTemplateOutlineTemplateWidget( config ) { +ve.ui.MWTransclusionOutlineTemplateWidget = function VeUiMWTransclusionOutlineTemplateWidget( config ) { // Initialize config config = $.extend( { icon: 'puzzle', @@ -22,7 +20,7 @@ ve.ui.MWTemplateOutlineTemplateWidget = function VeUiMWTemplateOutlineTemplateWi }, config ); // Parent constructor - ve.ui.MWTemplateOutlineTemplateWidget.super.call( this, config ); + ve.ui.MWTransclusionOutlineTemplateWidget.super.call( this, config ); // Initialization this.templateModel = config.templateModel.connect( this, { @@ -57,13 +55,13 @@ ve.ui.MWTemplateOutlineTemplateWidget = function VeUiMWTemplateOutlineTemplateWi /* Inheritance */ -OO.inheritClass( ve.ui.MWTemplateOutlineTemplateWidget, ve.ui.MWTemplateOutlinePartWidget ); +OO.inheritClass( ve.ui.MWTransclusionOutlineTemplateWidget, ve.ui.MWTransclusionOutlinePartWidget ); /** * @param {string|ve.dm.MWParameterModel} parameter * @return {ve.ui.MWTemplateOutlineParameterCheckboxLayout} */ -ve.ui.MWTemplateOutlineTemplateWidget.prototype.createCheckbox = function ( parameter ) { +ve.ui.MWTransclusionOutlineTemplateWidget.prototype.createCheckbox = function ( parameter ) { var templateSpec = this.templateModel.getSpec(), parameterModel = ( parameter instanceof ve.dm.MWParameterModel ) ? parameter : this.templateModel.getParameter( parameter ), @@ -89,7 +87,7 @@ ve.ui.MWTemplateOutlineTemplateWidget.prototype.createCheckbox = function ( para * * @param {ve.dm.MWParameterModel} parameter */ -ve.ui.MWTemplateOutlineTemplateWidget.prototype.onAddParameter = function ( parameter ) { +ve.ui.MWTransclusionOutlineTemplateWidget.prototype.onAddParameter = function ( parameter ) { var paramName = parameter.getName(), paramCheckbox = this.parameters.findItemFromData( paramName ); @@ -114,7 +112,7 @@ ve.ui.MWTemplateOutlineTemplateWidget.prototype.onAddParameter = function ( para * * @param {ve.dm.MWParameterModel} parameter */ -ve.ui.MWTemplateOutlineTemplateWidget.prototype.onRemoveParameter = function ( parameter ) { +ve.ui.MWTransclusionOutlineTemplateWidget.prototype.onRemoveParameter = function ( parameter ) { var paramCheckbox = this.parameters.findItemFromData( parameter.getName() ); if ( paramCheckbox ) { paramCheckbox.setSelected( false, true ); @@ -127,7 +125,7 @@ ve.ui.MWTemplateOutlineTemplateWidget.prototype.onRemoveParameter = function ( p * @param {string} data Parameter name * @param {boolean} checked New checkbox state */ -ve.ui.MWTemplateOutlineTemplateWidget.prototype.onCheckboxChange = function ( data, checked ) { +ve.ui.MWTransclusionOutlineTemplateWidget.prototype.onCheckboxChange = function ( data, checked ) { var parameter = this.templateModel.getParameter( data ); if ( checked ) { diff --git a/modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlineWikitextWidget.js b/modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlineWikitextWidget.js new file mode 100644 index 0000000000..51f2a1aa2f --- /dev/null +++ b/modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlineWikitextWidget.js @@ -0,0 +1,21 @@ +/** + * @class + * @extends ve.ui.MWTransclusionOutlinePartWidget + * + * @constructor + * @param {Object} [config] + */ +ve.ui.MWTransclusionOutlineWikitextWidget = function VeUiMWTransclusionOutlineWikitextWidget( config ) { + // Initialize config + config = $.extend( { + icon: 'wikiText', + label: ve.msg( 'visualeditor-dialog-transclusion-content' ) + }, config ); + + // Parent constructor + ve.ui.MWTransclusionOutlineWikitextWidget.super.call( this, config ); +}; + +/* Inheritance */ + +OO.inheritClass( ve.ui.MWTransclusionOutlineWikitextWidget, ve.ui.MWTransclusionOutlinePartWidget );