Skip to content

Commit

Permalink
Reuse hard and soft action handlers
Browse files Browse the repository at this point in the history
New sidebar events take a `soft` parameter allowing reuse between
"hard" and "soft" selection and parameter add.  The "hard" variant
causes a content-pane focus.

Bug: T311987
Change-Id: Ic49718840ae56eb4cfab01ce964a2fbc2d8db63b
  • Loading branch information
adamwight committed Jul 4, 2022
1 parent 14deb72 commit c2e1112
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ ve.ui.MWTwoPaneTransclusionDialogLayout = function VeUiMWTwoPaneTransclusionDial

// Events
this.sidebar.connect( this, {
focusPageByName: 'focusPart',
filterPagesByName: 'onFilterPagesByName',
sidebarPartSoftSelected: 'onSidebarPartSoftSelected'
sidebarPartSelected: 'onSidebarItemSelected',
templateParameterAdded: 'onSidebarItemSelected'
} );
// Event 'focus' does not bubble, but 'focusin' does
this.stackLayout.$element.on( 'focusin', this.onStackLayoutFocus.bind( this ) );
Expand Down Expand Up @@ -149,10 +149,16 @@ ve.ui.MWTwoPaneTransclusionDialogLayout.prototype.focusPart = function ( pageNam
};

/**
* @param {*} pageName
* Parts and parameters can be soft-selected, or selected and focused.
*
* @param {string} pageName Full, unique name of part or parameter
* @param {string} [soft] If true, suppress content pane focus.
*/
ve.ui.MWTwoPaneTransclusionDialogLayout.prototype.onSidebarPartSoftSelected = function ( pageName ) {
ve.ui.MWTwoPaneTransclusionDialogLayout.prototype.onSidebarItemSelected = function ( pageName, soft ) {
this.setPage( pageName );
if ( !soft ) {
this.focus();
}
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ OO.inheritClass( ve.ui.MWTransclusionOutlineTemplateWidget, ve.ui.MWTransclusion
* @event templateParameterAdded
* @param {string} pageName Unique id of the {@see OO.ui.BookletLayout} page, e.g. something like
* "part_1" or "part_1/param1".
* @param {boolean} soft If true, focus should stay in the sidebar.
*/

/**
Expand Down Expand Up @@ -289,15 +290,9 @@ ve.ui.MWTransclusionOutlineTemplateWidget.prototype.onParameterRemovedFromTempla
* @private
* @param {OO.ui.OptionWidget} item
* @param {boolean} selected
* @fires templateParameterAdded
*/
ve.ui.MWTransclusionOutlineTemplateWidget.prototype.onTemplateParameterChoose = function ( item, selected ) {
this.onTemplateParameterSelectionChanged( item, selected );

var param = this.templateModel.getParameter( item.getData() );
if ( param && selected ) {
this.emit( 'templateParameterAdded', param.getId() );
}
this.toggleParameter( item, selected, false );
};

/**
Expand All @@ -306,6 +301,17 @@ ve.ui.MWTransclusionOutlineTemplateWidget.prototype.onTemplateParameterChoose =
* @param {boolean} selected
*/
ve.ui.MWTransclusionOutlineTemplateWidget.prototype.onTemplateParameterSelectionChanged = function ( item, selected ) {
this.toggleParameter( item, selected, true );
};

/**
* @private
* @param {OO.ui.OptionWidget} item
* @param {boolean} selected
* @param {boolean} soft If true, focus should stay in the sidebar.
* @fires templateParameterAdded
*/
ve.ui.MWTransclusionOutlineTemplateWidget.prototype.toggleParameter = function ( item, selected, soft ) {
var paramName = item.getData(),
param = this.templateModel.getParameter( paramName );
if ( !selected ) {
Expand All @@ -316,6 +322,10 @@ ve.ui.MWTransclusionOutlineTemplateWidget.prototype.onTemplateParameterSelection
}

this.updateUnusedParameterToggleState();

if ( param && selected ) {
this.emit( 'templateParameterAdded', param.getId(), soft );
}
};

/**
Expand Down
25 changes: 10 additions & 15 deletions modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlineWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,16 @@ OO.inheritClass( ve.ui.MWTransclusionOutlineWidget, OO.ui.Widget );
*/

/**
* @event focusPageByName
* Respond to the intent to select a sidebar item
*
* @event sidebarPartSelected
* @param {string} pageName Unique id of the {@see OO.ui.BookletLayout} page, e.g. something like
* "part_1" or "part_1/param1".
* @param {string} [soft] If true, don't focus the content pane. Defaults to false.
*/

/* Methods */

/**
* @param {ve.dm.MWTransclusionPartModel|null} removed Removed part
* @param {ve.dm.MWTransclusionPartModel|null} added Added part
Expand All @@ -60,23 +65,13 @@ ve.ui.MWTransclusionOutlineWidget.prototype.onReplacePart = function ( removed,
* Handle spacebar in a part header
*
* @param {*} pageName
* @fires sidebarPartSelected
*/
ve.ui.MWTransclusionOutlineWidget.prototype.onTransclusionPartSoftSelected = function ( pageName ) {
this.setSelectionByPageName( pageName );
this.emit( 'sidebarPartSoftSelected', pageName );
this.emit( 'sidebarPartSelected', pageName, true );
};

/* Events */

/**
* Respond to the intent to select a sidebar item but without focusing the content pane.
*
* @event sidebarPartSoftSelected
* @param {string} pageName
*/

/* Methods */

/**
* @private
* @param {ve.dm.MWTransclusionPartModel} part
Expand Down Expand Up @@ -108,7 +103,7 @@ ve.ui.MWTransclusionOutlineWidget.prototype.addPartWidget = function ( part, new
widget.connect( this, {
// We can forward these events as is. The parameter's unique ids are reused as page
// names in {@see ve.ui.MWTemplateDialog.onAddParameter}.
templateParameterAdded: [ 'emit', 'focusPageByName' ],
templateParameterAdded: [ 'emit', 'templateParameterAdded' ],
filterParametersById: [ 'emit', 'filterPagesByName' ]
} );
} else if ( part instanceof ve.dm.MWTemplatePlaceholderModel ) {
Expand All @@ -119,7 +114,7 @@ ve.ui.MWTransclusionOutlineWidget.prototype.addPartWidget = function ( part, new

widget.connect( this, {
transclusionPartSoftSelected: 'onTransclusionPartSoftSelected',
transclusionPartSelected: [ 'emit', 'focusPageByName' ]
transclusionPartSelected: [ 'emit', 'sidebarPartSelected' ]
} );

this.partWidgets[ part.getId() ] = widget;
Expand Down

0 comments on commit c2e1112

Please sign in to comment.