Make "templateParameterClick" event similar to "choose"

The original idea was to make the interface as narrow as
possible. However, it turns out it's better to model the
"templateParameterClick" event more closely after the "choose"
event.

This is split off to make reviewing the following patches
easier.

Change-Id: I271f576c6cd756cecfc6cb1fd64810f8da5c3575
This commit is contained in:
Thiemo Kreuz 2021-09-10 16:20:51 +02:00
parent 9ef1b22b37
commit ec526ea64f
4 changed files with 20 additions and 9 deletions

View file

@ -107,7 +107,8 @@ ve.ui.MWAddParameterPage.prototype.onParameterNameSubmitted = function () {
return;
}
this.template.addParameter( new ve.dm.MWParameterModel( this.template, name ) );
var param = new ve.dm.MWParameterModel( this.template, name );
this.template.addParameter( param );
ve.track( 'activity.transclusion', {
action: 'add-unknown-parameter'

View file

@ -114,7 +114,8 @@ ve.ui.MWParameterPlaceholderPage.prototype.onParameterChoose = function ( name )
// Note that every parameter is known after it is added
var knownBefore = this.template.getSpec().isKnownParameterOrAlias( name );
this.template.addParameter( new ve.dm.MWParameterModel( this.template, name ) );
var param = new ve.dm.MWParameterModel( this.template, name );
this.template.addParameter( param );
ve.track( 'activity.transclusion', {
action: knownBefore ? 'add-known-parameter' : 'add-unknown-parameter'

View file

@ -39,7 +39,8 @@ OO.mixinClass( ve.ui.MWTransclusionOutlineParameterSelectWidget, OO.ui.mixin.Tab
* pressing enter/click on a parameter that's already selected.
*
* @event templateParameterClick
* @param {string} paramName
* @param {ve.ui.MWTransclusionOutlineParameterWidget} item
* @param {boolean} selected
*/
/* Static Methods */
@ -133,7 +134,7 @@ ve.ui.MWTransclusionOutlineParameterSelectWidget.prototype.onMouseDown = functio
var item = this.findTargetItem( e );
// Same as pressing enter, see below.
if ( item && item.isSelected() ) {
this.emit( 'templateParameterClick', item.getData() );
this.emit( 'templateParameterClick', item, item.isSelected() );
// Don't call the parent, i.e. can't click to unselect the item
return false;
@ -177,7 +178,7 @@ ve.ui.MWTransclusionOutlineParameterSelectWidget.prototype.onDocumentKeyDown = f
item = this.findHighlightedItem();
// Same as clicking with the mouse, see above.
if ( item && item.isSelected() ) {
this.emit( 'templateParameterClick', item.getData() );
this.emit( 'templateParameterClick', item, item.isSelected() );
e.preventDefault();
// Don't call the parent, i.e. can't use enter to unselect the item

View file

@ -179,17 +179,25 @@ ve.ui.MWTransclusionOutlineTemplateWidget.prototype.onTemplateParameterChoose =
if ( !selected ) {
this.templateModel.removeParameter( param );
} else if ( !param ) {
this.templateModel.addParameter( new ve.dm.MWParameterModel( this.templateModel, paramName ) );
param = new ve.dm.MWParameterModel( this.templateModel, paramName );
this.templateModel.addParameter( param );
}
};
/**
* @private
* @param {string} paramName
* @param {OO.ui.OptionWidget} item
* @param {boolean} selected
* @fires focusTemplateParameterById
*/
ve.ui.MWTransclusionOutlineTemplateWidget.prototype.onTemplateParameterClick = function ( paramName ) {
var param = this.templateModel.getParameter( paramName );
ve.ui.MWTransclusionOutlineTemplateWidget.prototype.onTemplateParameterClick = function ( item, selected ) {
// Fail-safe. There should be no code-path that calls this with false.
if ( !selected ) {
return;
}
var paramName = item.getData(),
param = this.templateModel.getParameter( paramName );
if ( param ) {
this.emit( 'focusTemplateParameterById', param.getId() );
}