Simplify interface to remove pages

Makes some things easier, some harder—not sure if this is a helpful
patch.

Change-Id: If56e9b2fbc1796cd637aaeececec779d31a7921f
This commit is contained in:
Adam Wight 2022-07-04 16:12:25 +02:00 committed by Thiemo Kreuz (WMDE)
parent 1a4bb6c5e4
commit 2759752a0a
3 changed files with 10 additions and 11 deletions

View file

@ -29,7 +29,7 @@ QUnit.test( 'can add and remove multiple pages', ( assert ) => {
assert.strictEqual( layout.getPage( parameterPageB.getName() ), parameterPageB );
assert.strictEqual( layout.getPage( parameterPageC.getName() ), parameterPageC );
layout.removePages( [ parameterPageA, parameterPageB ] );
layout.removePages( [ parameterPageA.getName(), parameterPageB.getName() ] );
assert.strictEqual( layout.getPage( parameterPageA.getName() ), undefined );
assert.strictEqual( layout.getPage( parameterPageB.getName() ), undefined );
assert.strictEqual( layout.getPage( parameterPageC.getName() ), parameterPageC );

View file

@ -106,15 +106,14 @@ ve.ui.MWTemplateDialog.prototype.onReplacePart = function ( removed, added ) {
if ( removed ) {
// Remove parameter pages of removed templates
var partPage = this.bookletLayout.getPage( removed.getId() );
if ( removed instanceof ve.dm.MWTemplateModel ) {
var params = removed.getParameters();
for ( var name in params ) {
removePages.push( this.bookletLayout.getPage( params[ name ].getId() ) );
removePages.push( params[ name ].getId() );
}
removed.disconnect( this );
}
removePages.push( partPage );
removePages.push( removed.getId() );
this.bookletLayout.removePages( removePages );
}
@ -207,9 +206,7 @@ ve.ui.MWTemplateDialog.prototype.onAddParameter = function ( param ) {
* @param {ve.dm.MWParameterModel} param Removed param
*/
ve.ui.MWTemplateDialog.prototype.onRemoveParameter = function ( param ) {
var page = this.bookletLayout.getPage( param.getId() );
this.bookletLayout.removePages( [ page ] );
this.bookletLayout.removePages( [ param.getId() ] );
this.touch();
};

View file

@ -274,7 +274,7 @@ ve.ui.MWTwoPaneTransclusionDialogLayout.prototype.addPages = function ( pages, i
if ( currentIndex !== -1 && currentIndex + 1 < index ) {
index--;
}
remove.push( this.pages[ name ] );
remove.push( name );
}
}
if ( remove.length ) {
@ -296,17 +296,19 @@ ve.ui.MWTwoPaneTransclusionDialogLayout.prototype.addPages = function ( pages, i
*
* To remove all pages from the booklet, you may wish to use the #clearPages method instead.
*
* @param {OO.ui.PageLayout[]} pagesToRemove An array of pages to remove
* @param {string[]} pagesNamesToRemove
*/
ve.ui.MWTwoPaneTransclusionDialogLayout.prototype.removePages = function ( pagesToRemove ) {
ve.ui.MWTwoPaneTransclusionDialogLayout.prototype.removePages = function ( pagesNamesToRemove ) {
var layout = this,
pagesToRemove = [],
isCurrentParameter = this.pages[ this.currentPageName ] instanceof ve.ui.MWParameterPage,
isCurrentPageRemoved = false,
prevSelectionCandidate, nextSelectionCandidate;
this.stackLayout.getItems().forEach( function ( page ) {
var pageName = page.getName();
if ( pagesToRemove.indexOf( page ) !== -1 ) {
if ( pagesNamesToRemove.indexOf( pageName ) !== -1 ) {
pagesToRemove.push( page );
delete layout.pages[ pageName ];
// If the current page is removed, clear currentPageName
if ( layout.currentPageName === pageName ) {