Merge "Allow selecting top-level parts in the new sidebar"

This commit is contained in:
jenkins-bot 2021-08-30 13:32:12 +00:00 committed by Gerrit Code Review
commit ddee2bdb72
5 changed files with 79 additions and 22 deletions

View file

@ -105,3 +105,13 @@ ve.ui.MWAddParameterPage.prototype.togglePlaceholder = function ( expand ) {
!this.isExpanded
);
};
ve.ui.MWAddParameterPage.prototype.setOutlineItem = function () {
// Parent method
ve.ui.MWParameterPage.super.prototype.setOutlineItem.apply( this, arguments );
if ( this.outlineItem ) {
// This page should not be shown in the (BookletLayout-based) sidebar
this.outlineItem.$element.empty().removeClass();
}
};

View file

@ -183,6 +183,10 @@
text-overflow: ellipsis;
}
.ve-ui-mwTransclusionOutlineButtonWidget.oo-ui-optionWidget-selected .oo-ui-buttonElement-button {
background-color: #eaf3ff;
}
.ve-ui-mwTransclusionOutlineButtonWidget.oo-ui-buttonElement-frameless.oo-ui-widget-enabled > .oo-ui-buttonElement-button:hover {
background-color: #eaecf0;
}

View file

@ -3,7 +3,7 @@
* {@see OO.ui.ButtonWidget} for inspiration.
*
* @class
* @extends OO.ui.Widget
* @extends OO.ui.OptionWidget
*
* @constructor
* @param {Object} config
@ -19,7 +19,6 @@ ve.ui.MWTransclusionOutlineButtonWidget = function VeUiMWTransclusionOutlineButt
framed: false
} );
OO.ui.mixin.IconElement.call( this, config );
OO.ui.mixin.LabelElement.call( this, config );
OO.ui.mixin.TabIndexedElement.call( this, ve.extendObject( {
$tabIndexed: this.$button
}, config ) );
@ -31,11 +30,10 @@ ve.ui.MWTransclusionOutlineButtonWidget = function VeUiMWTransclusionOutlineButt
/* Inheritance */
OO.inheritClass( ve.ui.MWTransclusionOutlineButtonWidget, OO.ui.Widget );
OO.inheritClass( ve.ui.MWTransclusionOutlineButtonWidget, OO.ui.OptionWidget );
OO.mixinClass( ve.ui.MWTransclusionOutlineButtonWidget, OO.ui.mixin.ButtonElement );
OO.mixinClass( ve.ui.MWTransclusionOutlineButtonWidget, OO.ui.mixin.IconElement );
OO.mixinClass( ve.ui.MWTransclusionOutlineButtonWidget, OO.ui.mixin.LabelElement );
// TODO: Add OO.ui.mixin.TitledElement?
// TODO: Add OO.ui.mixin.FlaggedElement?
OO.mixinClass( ve.ui.MWTransclusionOutlineButtonWidget, OO.ui.mixin.TabIndexedElement );
// TODO: Add OO.ui.mixin.AccessKeyedElement?
ve.ui.MWTransclusionOutlineButtonWidget.static.highlightable = false;
ve.ui.MWTransclusionOutlineButtonWidget.static.pressable = false;

View file

@ -75,6 +75,16 @@ ve.ui.MWTransclusionOutlineContainerWidget.prototype.onTransclusionModelChange =
}
};
/**
* This is inspired by {@see OO.ui.SelectWidget.selectItem}, but isn't one.
*/
ve.ui.MWTransclusionOutlineContainerWidget.prototype.onPartSelected = function ( partId ) {
for ( var id in this.partWidgets ) {
this.partWidgets[ id ].setSelected( id === partId );
}
this.emit( 'focusPart', partId );
};
/* Methods */
/**
@ -82,13 +92,12 @@ ve.ui.MWTransclusionOutlineContainerWidget.prototype.onTransclusionModelChange =
* @param {ve.dm.MWTransclusionPartModel} part
*/
ve.ui.MWTransclusionOutlineContainerWidget.prototype.removePartWidget = function ( part ) {
var partId = part.getId(),
widget = this.partWidgets[ partId ];
if ( widget ) {
widget.disconnect( this );
widget.$element.remove();
delete this.partWidgets[ partId ];
var id = part.getId();
if ( id in this.partWidgets ) {
this.partWidgets[ id ]
.disconnect( this )
.$element.remove();
delete this.partWidgets[ id ];
}
};
@ -111,7 +120,7 @@ ve.ui.MWTransclusionOutlineContainerWidget.prototype.addPartWidget = function (
widget = new ve.ui.MWTransclusionOutlineWikitextWidget( part );
}
widget.connect( this, { focusPart: [ 'emit', 'focusPart' ] } );
widget.connect( this, { selectPart: 'onPartSelected' } );
this.partWidgets[ part.getId() ] = widget;
if ( typeof newPosition === 'number' && newPosition < this.$element.children().length ) {
@ -121,14 +130,28 @@ ve.ui.MWTransclusionOutlineContainerWidget.prototype.addPartWidget = function (
}
};
/**
* This is inspired by {@see OO.ui.SelectWidget.findSelectedItem}, but isn't one.
*
* @return {string|undefined}
*/
ve.ui.MWTransclusionOutlineContainerWidget.prototype.findSelectedPartId = function () {
for ( var id in this.partWidgets ) {
var part = this.partWidgets[ id ];
if ( part.isSelected() ) {
return part.getData();
}
}
};
/**
* Removes all {@see ve.ui.MWTransclusionOutlinePartWidget}, i.e. empties the list.
*/
ve.ui.MWTransclusionOutlineContainerWidget.prototype.clear = function () {
for ( var partId in this.partWidgets ) {
var widget = this.partWidgets[ partId ];
widget.disconnect( this );
widget.$element.remove();
for ( var id in this.partWidgets ) {
this.partWidgets[ id ]
.disconnect( this )
.$element.remove();
}
this.partWidgets = {};
};

View file

@ -24,12 +24,12 @@ ve.ui.MWTransclusionOutlinePartWidget = function VeUiMWTransclusionOutlinePartWi
data: part.getId()
} ) );
var header = new ve.ui.MWTransclusionOutlineButtonWidget( config )
.connect( this, { click: [ 'emit', 'focusPart', part.getId() ] } );
this.header = new ve.ui.MWTransclusionOutlineButtonWidget( config )
.connect( this, { click: [ 'emit', 'selectPart', part.getId() ] } );
this.$element
.addClass( 've-ui-mwTransclusionOutlinePartWidget' )
.append( header.$element );
.append( this.header.$element );
};
/* Inheritance */
@ -42,3 +42,25 @@ OO.inheritClass( ve.ui.MWTransclusionOutlinePartWidget, OO.ui.Widget );
* @event focusPart
* @param {string} partId Unique id of the part, e.g. something "part_1" or "part_1/param1".
*/
/* Methods */
/**
* Convenience method, modelled after {@see OO.ui.OptionWidget}, but this isn't one.
*
* @return {boolean}
*/
ve.ui.MWTransclusionOutlinePartWidget.prototype.isSelected = function () {
return this.header.isSelected();
};
/**
* Convenience method, modelled after {@see OO.ui.OptionWidget}, but this isn't one.
*
* @param {boolean} state
*/
ve.ui.MWTransclusionOutlinePartWidget.prototype.setSelected = function ( state ) {
this.header
.setSelected( state )
.setFlags( { progressive: state } );
};