From baa0a1329d60161a2defae4b5011d6cffb923cbd Mon Sep 17 00:00:00 2001 From: Julian Gonggrijp Date: Tue, 18 Aug 2020 13:54:10 +0200 Subject: [PATCH] Add the option to reset the explorer entirely (#106 #62) --- frontend/src/explorer/explorer-view-test.ts | 15 ++++++++++++++- frontend/src/explorer/explorer-view.ts | 10 ++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/frontend/src/explorer/explorer-view-test.ts b/frontend/src/explorer/explorer-view-test.ts index 75266910..693c8b22 100644 --- a/frontend/src/explorer/explorer-view-test.ts +++ b/frontend/src/explorer/explorer-view-test.ts @@ -1,5 +1,5 @@ import { $ } from 'backbone'; -import { times, after } from 'lodash'; +import { times, after, size } from 'lodash'; import './../core/scroll-easings'; import { enableI18n } from '../test-util'; @@ -232,4 +232,17 @@ describe('ExplorerView', function () { this.view.popUntil(stack1Panel2); expectSame(); }); + + it('can reset the panels wholesale', function() { + this.view.push(new View()).push(new View()).push(new View()); + expect(this.view.stacks.length).toBe(4); + const replacement = new View(); + const spy = jasmine.createSpy('resetSpy'); + this.view.once('reset', spy); + this.view.reset(replacement); + expect(spy).toHaveBeenCalledWith(this.view); + expect(this.view.stacks.length).toBe(1); + expect(size(this.view.rltPanelStack)).toBe(1); + expect(this.view.rltPanelStack[replacement.cid]).toBe(0); + }); }); diff --git a/frontend/src/explorer/explorer-view.ts b/frontend/src/explorer/explorer-view.ts index 01a2eaf3..5e713e93 100644 --- a/frontend/src/explorer/explorer-view.ts +++ b/frontend/src/explorer/explorer-view.ts @@ -200,6 +200,16 @@ export default class ExplorerView extends View { return this; } + /** + * Remove all panels, then make `panel` the new first panel. + * @param panel The panel that needs to become leftmost. + */ + reset(panel: View): this { + while (this.stacks.length) this.pop(); + this.trigger('reset', this).push(panel); + return this; + } + /** * Remove the topmost panel from the stack at position. Returns the deleted panel. * @param position The indes of the stack to remove the panel from