Make it possible to reuse existing transclusion outlines

Note that this patch alone probably does not make that much
sense. The code executed is pretty much the same. The only
difference is that the empty (!) …ContainerWidget is kept
and re-filled with what might be a completely different
template.

This is not much of a difference to before when the
container was recreated.

This change will make more sense when the container has to
manage more state, e.g. focus states. This state will
survive then.

Change-Id: Ic336d10a595e3e222741a3dc57c1d54639166b7a
This commit is contained in:
Thiemo Kreuz 2021-07-16 14:37:34 +02:00
parent 434c11f6de
commit 5c6d2212da
2 changed files with 16 additions and 5 deletions

View file

@ -472,12 +472,13 @@ ve.ui.MWTemplateDialog.prototype.getSetupProcess = function ( data ) {
if ( this.isNewSidebar ) {
// FIXME: This is created at the wrong time. That's why we run into the situation
// where an old instance exists. Should be in initialize().
if ( this.pocSidebar ) {
this.pocSidebar.$element.remove();
if ( !this.pocSidebar ) {
this.pocSidebar = new ve.ui.MWTransclusionOutlineContainerWidget(
this.bookletLayout
);
} else {
this.pocSidebar.clear();
}
this.pocSidebar = new ve.ui.MWTransclusionOutlineContainerWidget(
this.bookletLayout
);
this.transclusionModel.connect( this.pocSidebar, {
replace: 'onReplacePart',
change: [ 'onTransclusionModelChange', this.transclusionModel ]

View file

@ -114,3 +114,13 @@ ve.ui.MWTransclusionOutlineContainerWidget.prototype.addPartWidget = function (
ve.ui.MWTransclusionOutlineContainerWidget.prototype.onPartHeaderClick = function ( partId ) {
this.bookletLayout.setPage( partId );
};
/**
* Removes all {@see ve.ui.MWTransclusionOutlinePartWidget}, i.e. empties the list.
*/
ve.ui.MWTransclusionOutlineContainerWidget.prototype.clear = function () {
for ( var partId in this.partWidgets ) {
this.partWidgets[ partId ].$element.remove();
}
this.partWidgets = {};
};