Merge "Move getters for the currently selected part to two-pane layout"

This commit is contained in:
jenkins-bot 2022-07-26 12:30:41 +00:00 committed by Gerrit Code Review
commit 4997f3d41d
3 changed files with 26 additions and 33 deletions

View file

@ -76,7 +76,7 @@ ve.ui.MWTransclusionDialog.static.isSmallScreen = function () {
* @param {number} places Number of places to move the selected item
*/
ve.ui.MWTransclusionDialog.prototype.onOutlineControlsMove = function ( places ) {
var part = this.transclusionModel.getPartFromId( this.findSelectedItemId() );
var part = this.transclusionModel.getPartFromId( this.bookletLayout.getSelectedTopLevelPartId() );
if ( !part ) {
return;
}
@ -109,7 +109,7 @@ ve.ui.MWTransclusionDialog.prototype.onOutlineControlsRemove = function () {
return;
}
var itemId = this.findSelectedItemId(),
var itemId = this.bookletLayout.getSelectedTopLevelPartId(),
part = this.transclusionModel.getPartFromId( itemId );
// Check if the part is the actual template, or one of its parameters
// TODO: This applies to the old sidebar only and can be removed later
@ -147,9 +147,8 @@ ve.ui.MWTransclusionDialog.prototype.addWikitext = function () {
* @private
*/
ve.ui.MWTransclusionDialog.prototype.addParameter = function () {
var pageName = this.bookletLayout.getCurrentPage().getName(),
topLevelPartId = pageName.split( '/', 1 )[ 0 ],
part = this.transclusionModel.getPartFromId( topLevelPartId );
var partId = this.bookletLayout.getTopLevelPartIdForSelection(),
part = this.transclusionModel.getPartFromId( partId );
if ( !( part instanceof ve.dm.MWTemplateModel ) ) {
return;
}
@ -262,15 +261,6 @@ ve.ui.MWTransclusionDialog.prototype.onKeyDown = function ( e ) {
}
};
/**
* @deprecated This can only find selected top-level parts
* @private
* @return {string|undefined} Top-level part id
*/
ve.ui.MWTransclusionDialog.prototype.findSelectedItemId = function () {
return this.sidebar.findSelectedPartId();
};
/**
* @inheritdoc
*/
@ -418,9 +408,8 @@ ve.ui.MWTransclusionDialog.prototype.updateModeActionState = function () {
*/
ve.ui.MWTransclusionDialog.prototype.addPart = function ( part ) {
var parts = this.transclusionModel.getParts(),
pageName = this.bookletLayout.getCurrentPage().getName(),
topLevelPartId = pageName.split( '/', 1 )[ 0 ],
selectedPart = this.transclusionModel.getPartFromId( topLevelPartId );
partId = this.bookletLayout.getTopLevelPartIdForSelection(),
selectedPart = this.transclusionModel.getPartFromId( partId );
// Insert after selected part, or at the end if nothing is selected
var index = selectedPart ? parts.indexOf( selectedPart ) + 1 : parts.length;
// Add the part, and if dialog is loaded switch to part page

View file

@ -199,6 +199,25 @@ ve.ui.MWTwoPaneTransclusionDialogLayout.prototype.getCurrentPage = function () {
return this.pages[ this.currentPageName ];
};
/**
* @return {string|null} A top-level part id like "part_0" if that part is selected. When a
* parameter is selected null is returned.
*/
ve.ui.MWTwoPaneTransclusionDialogLayout.prototype.getSelectedTopLevelPartId = function () {
var page = this.getCurrentPage(),
isParameter = page instanceof ve.ui.MWParameterPage || page instanceof ve.ui.MWAddParameterPage;
return page && !isParameter ? page.getName() : null;
};
/**
* @return {string|null} A top-level part id like "part_0" that corresponds to the current
* selection, whatever is selected. When a parameter is selected the id of the template the
* parameter belongs to is returned.
*/
ve.ui.MWTwoPaneTransclusionDialogLayout.prototype.getTopLevelPartIdForSelection = function () {
return this.currentPageName ? this.currentPageName.split( '/', 1 )[ 0 ] : null;
};
/**
* When pages are added with the same names as existing pages, the existing pages will be
* automatically removed before the new pages are added.
@ -324,7 +343,7 @@ ve.ui.MWTwoPaneTransclusionDialogLayout.prototype.setPage = function ( name ) {
* @private
*/
ve.ui.MWTwoPaneTransclusionDialogLayout.prototype.refreshControls = function () {
var partId = this.sidebar.findSelectedPartId(),
var partId = this.getSelectedTopLevelPartId(),
pages = this.stackLayout.getItems(),
page = this.getPage( partId ),
index = pages.indexOf( page ),

View file

@ -165,21 +165,6 @@ ve.ui.MWTransclusionOutlineWidget.prototype.toggleHasValueByPageName = function
templatePartWidget.toggleHasValue( idParts[ 1 ], hasValue );
};
/**
* This is inspired by {@see OO.ui.SelectWidget.findSelectedItem}, but isn't one.
*
* @deprecated This can only find selected top-level parts
* @return {string|undefined} Always a top-level part id, e.g. "part_0"
*/
ve.ui.MWTransclusionOutlineWidget.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.
*/