mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 02:23:58 +00:00
Merge "Reuse hard and soft action handlers"
This commit is contained in:
commit
90a5f8aaad
|
@ -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 ) );
|
||||
|
@ -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();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -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 );
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -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 ) {
|
||||
|
@ -316,6 +322,10 @@ ve.ui.MWTransclusionOutlineTemplateWidget.prototype.onTemplateParameterSelection
|
|||
}
|
||||
|
||||
this.updateUnusedParameterToggleState();
|
||||
|
||||
if ( param && selected ) {
|
||||
this.emit( 'templateParameterAdded', param.getId(), soft );
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 ) {
|
||||
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue