mirror of
https://github.com/mathuo/dockview
synced 2025-01-23 09:55:58 +00:00
feat: remove suppress closable option
This commit is contained in:
parent
e2f981274c
commit
9ca535efa7
@ -144,7 +144,6 @@ class TestGroupPanel implements IDockviewPanel {
|
||||
private _group: GroupPanel | undefined;
|
||||
|
||||
readonly view: IGroupPanelView;
|
||||
readonly suppressClosable: boolean = false;
|
||||
readonly api: DockviewPanelApi;
|
||||
|
||||
constructor(
|
||||
|
@ -41,46 +41,6 @@ describe('dockviewGroupPanel', () => {
|
||||
disposable.dispose();
|
||||
});
|
||||
|
||||
test('update suppress closable', () => {
|
||||
const dockviewApiMock = jest.fn<DockviewApi, []>(() => {
|
||||
return {} as any;
|
||||
});
|
||||
const accessorMock = jest.fn<DockviewComponent, []>(() => {
|
||||
return {} as any;
|
||||
});
|
||||
const groupMock = jest.fn<GroupPanel, []>(() => {
|
||||
return {} as any;
|
||||
});
|
||||
const api = new dockviewApiMock();
|
||||
const accessor = new accessorMock();
|
||||
const group = new groupMock();
|
||||
|
||||
const cut = new DockviewGroupPanel('fake-id', accessor, api, group);
|
||||
|
||||
let latestSuppressClosable: boolean | undefined = undefined;
|
||||
|
||||
const disposable = cut.api.onDidSuppressClosableChange((event) => {
|
||||
latestSuppressClosable = event.suppressClosable;
|
||||
});
|
||||
|
||||
expect(latestSuppressClosable).toBeFalsy();
|
||||
|
||||
cut.init({
|
||||
title: 'new title',
|
||||
suppressClosable: true,
|
||||
params: {},
|
||||
view: null,
|
||||
});
|
||||
expect(latestSuppressClosable).toBeTruthy();
|
||||
expect(cut.suppressClosable).toBeTruthy();
|
||||
|
||||
cut.update({ params: { suppressClosable: false } });
|
||||
expect(latestSuppressClosable).toBeFalsy();
|
||||
expect(cut.suppressClosable).toBeFalsy();
|
||||
|
||||
disposable.dispose();
|
||||
});
|
||||
|
||||
test('dispose cleanup', () => {
|
||||
const dockviewApiMock = jest.fn<DockviewApi, []>(() => {
|
||||
return {} as any;
|
||||
|
@ -144,10 +144,6 @@ export class TestPanel implements IDockviewPanel {
|
||||
return '';
|
||||
}
|
||||
|
||||
get suppressClosable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
get group() {
|
||||
return this._group!;
|
||||
}
|
||||
|
@ -8,10 +8,6 @@ export interface TitleEvent {
|
||||
readonly title: string;
|
||||
}
|
||||
|
||||
export interface SuppressClosableEvent {
|
||||
readonly suppressClosable: boolean;
|
||||
}
|
||||
|
||||
/*
|
||||
* omit visibility modifiers since the visibility of a single group doesn't make sense
|
||||
* because it belongs to a groupview
|
||||
@ -20,10 +16,8 @@ export interface DockviewPanelApi extends Omit<GridviewPanelApi, 'setVisible'> {
|
||||
readonly group: GroupPanel;
|
||||
readonly isGroupActive: boolean;
|
||||
readonly title: string;
|
||||
readonly suppressClosable: boolean;
|
||||
readonly onDidActiveGroupChange: Event<void>;
|
||||
readonly onDidGroupChange: Event<void>;
|
||||
readonly onDidSuppressClosableChange: Event<SuppressClosableEvent>;
|
||||
close(): void;
|
||||
setTitle(title: string): void;
|
||||
}
|
||||
@ -37,11 +31,6 @@ export class DockviewPanelApiImpl
|
||||
readonly _onDidTitleChange = new Emitter<TitleEvent>();
|
||||
readonly onDidTitleChange = this._onDidTitleChange.event;
|
||||
|
||||
readonly _onDidSuppressClosableChange =
|
||||
new Emitter<SuppressClosableEvent>();
|
||||
readonly onDidSuppressClosableChange =
|
||||
this._onDidSuppressClosableChange.event;
|
||||
|
||||
private readonly _onDidActiveGroupChange = new Emitter<void>();
|
||||
readonly onDidActiveGroupChange = this._onDidActiveGroupChange.event;
|
||||
|
||||
@ -54,10 +43,6 @@ export class DockviewPanelApiImpl
|
||||
return this.panel.title;
|
||||
}
|
||||
|
||||
get suppressClosable() {
|
||||
return !!this.panel.suppressClosable;
|
||||
}
|
||||
|
||||
get isGroupActive() {
|
||||
return !!this.group?.isActive;
|
||||
}
|
||||
@ -91,7 +76,6 @@ export class DockviewPanelApiImpl
|
||||
this.addDisposables(
|
||||
this.disposable,
|
||||
this._onDidTitleChange,
|
||||
this._onDidSuppressClosableChange,
|
||||
this._onDidGroupChange,
|
||||
this._onDidActiveGroupChange
|
||||
);
|
||||
|
@ -68,10 +68,6 @@
|
||||
border-radius: 2px;
|
||||
background-color: var(--dv-icon-hover-background-color);
|
||||
}
|
||||
|
||||
&.disable-close {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -81,14 +81,10 @@ export class DefaultTab extends CompositeDisposable implements ITabRenderer {
|
||||
this.params = params;
|
||||
this._content.textContent = params.title;
|
||||
|
||||
if (!this.params.suppressClosable) {
|
||||
addDisposableListener(this.action, 'click', (ev) => {
|
||||
ev.preventDefault(); //
|
||||
this.params.api.close();
|
||||
});
|
||||
} else {
|
||||
this.action.classList.add('disable-close');
|
||||
}
|
||||
addDisposableListener(this.action, 'click', (ev) => {
|
||||
ev.preventDefault(); //
|
||||
this.params.api.close();
|
||||
});
|
||||
}
|
||||
|
||||
public updateParentGroup(group: GroupPanel, isPanelVisible: boolean) {
|
||||
|
@ -731,7 +731,6 @@ export class DockviewComponent
|
||||
panel.init({
|
||||
view,
|
||||
title: options.title || options.id,
|
||||
suppressClosable: options?.suppressClosable,
|
||||
params: options?.params || {},
|
||||
});
|
||||
|
||||
|
@ -25,7 +25,6 @@ export class DockviewGroupPanel
|
||||
private _view?: IGroupPanelView;
|
||||
|
||||
private _title: string;
|
||||
private _suppressClosable: boolean;
|
||||
|
||||
get params() {
|
||||
return this._params;
|
||||
@ -35,10 +34,6 @@ export class DockviewGroupPanel
|
||||
return this._title;
|
||||
}
|
||||
|
||||
get suppressClosable() {
|
||||
return this._suppressClosable;
|
||||
}
|
||||
|
||||
get group(): GroupPanel {
|
||||
return this._group;
|
||||
}
|
||||
@ -54,7 +49,6 @@ export class DockviewGroupPanel
|
||||
group: GroupPanel
|
||||
) {
|
||||
super();
|
||||
this._suppressClosable = false;
|
||||
this._title = '';
|
||||
this._group = group;
|
||||
|
||||
@ -72,7 +66,6 @@ export class DockviewGroupPanel
|
||||
this._view = params.view;
|
||||
|
||||
this.setTitle(params.title);
|
||||
this.setSuppressClosable(params.suppressClosable || false);
|
||||
|
||||
this.view?.init({
|
||||
...params,
|
||||
@ -93,7 +86,6 @@ export class DockviewGroupPanel
|
||||
Object.keys(this._params || {}).length > 0
|
||||
? this._params
|
||||
: undefined,
|
||||
suppressClosable: this.suppressClosable || undefined,
|
||||
title: this.title,
|
||||
};
|
||||
}
|
||||
@ -108,33 +100,12 @@ export class DockviewGroupPanel
|
||||
params: {
|
||||
params: this._params,
|
||||
title: this.title,
|
||||
suppressClosable: this.suppressClosable,
|
||||
},
|
||||
});
|
||||
this.api._onDidTitleChange.fire({ title });
|
||||
}
|
||||
}
|
||||
|
||||
setSuppressClosable(suppressClosable: boolean) {
|
||||
const didSuppressChangableClose =
|
||||
suppressClosable !== this._params?.suppressClosable;
|
||||
|
||||
if (didSuppressChangableClose) {
|
||||
this._suppressClosable = suppressClosable;
|
||||
|
||||
this.view?.update({
|
||||
params: {
|
||||
params: this._params,
|
||||
title: this.title,
|
||||
suppressClosable: this.suppressClosable,
|
||||
},
|
||||
});
|
||||
this.api._onDidSuppressClosableChange.fire({
|
||||
suppressClosable: !!this.suppressClosable,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public update(event: GroupPanelUpdateEvent): void {
|
||||
const params = event.params as IGroupPanelInitParameters;
|
||||
|
||||
@ -150,20 +121,10 @@ export class DockviewGroupPanel
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof params.suppressClosable === 'boolean') {
|
||||
if (params.suppressClosable !== this._suppressClosable) {
|
||||
this._suppressClosable = params.suppressClosable;
|
||||
this.api._onDidSuppressClosableChange.fire({
|
||||
suppressClosable: !!this.suppressClosable,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
this.view?.update({
|
||||
params: {
|
||||
params: this._params,
|
||||
title: this.title,
|
||||
suppressClosable: this.suppressClosable,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
@ -76,7 +76,6 @@ export interface PanelOptions {
|
||||
params?: { [key: string]: any };
|
||||
id: string;
|
||||
title?: string;
|
||||
suppressClosable?: boolean;
|
||||
}
|
||||
|
||||
export interface AddPanelOptions
|
||||
|
@ -19,7 +19,6 @@ export interface IGroupPanelInitParameters
|
||||
export type GroupPanelUpdateEvent = PanelUpdateEvent<{
|
||||
params?: Parameters;
|
||||
title?: string;
|
||||
suppressClosable?: boolean;
|
||||
}>;
|
||||
|
||||
export interface IDockviewPanel extends IDisposable, IPanel {
|
||||
@ -27,7 +26,6 @@ export interface IDockviewPanel extends IDisposable, IPanel {
|
||||
readonly group: GroupPanel;
|
||||
readonly api: DockviewPanelApi;
|
||||
readonly title: string;
|
||||
readonly suppressClosable: boolean;
|
||||
readonly params: Record<string, any> | undefined;
|
||||
updateParentGroup(group: GroupPanel, isGroupActive: boolean): void;
|
||||
init(params: IGroupPanelInitParameters): void;
|
||||
@ -40,5 +38,4 @@ export interface GroupviewPanelState {
|
||||
view?: any;
|
||||
title: string;
|
||||
params?: { [key: string]: any };
|
||||
suppressClosable?: boolean;
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ export interface IRenderable {
|
||||
|
||||
export interface HeaderPartInitParameters {
|
||||
title: string;
|
||||
suppressClosable?: boolean;
|
||||
}
|
||||
|
||||
export interface GroupPanelPartInitParameters
|
||||
|
@ -40,11 +40,7 @@ export {
|
||||
GridviewPanelApi,
|
||||
GridConstraintChangeEvent,
|
||||
} from './api/gridviewPanelApi';
|
||||
export {
|
||||
TitleEvent,
|
||||
SuppressClosableEvent,
|
||||
DockviewPanelApi,
|
||||
} from './api/groupPanelApi';
|
||||
export { TitleEvent, DockviewPanelApi } from './api/groupPanelApi';
|
||||
export {
|
||||
PanelSizeEvent,
|
||||
PanelConstraintChangeEvent,
|
||||
|
@ -19,7 +19,6 @@ export class ReactPanelDeserialzier implements IPanelDeserializer {
|
||||
const panelId = panelData.id;
|
||||
const params = panelData.params;
|
||||
const title = panelData.title;
|
||||
const suppressClosable = panelData.suppressClosable;
|
||||
const viewData = panelData.view;
|
||||
|
||||
let tab: ITabRenderer;
|
||||
@ -67,7 +66,6 @@ export class ReactPanelDeserialzier implements IPanelDeserializer {
|
||||
panel.init({
|
||||
view,
|
||||
title,
|
||||
suppressClosable,
|
||||
params: params || {},
|
||||
});
|
||||
|
||||
|
@ -29,7 +29,7 @@ export const DockviewDefaultTab: React.FunctionComponent<IDockviewDefaultTabProp
|
||||
const iconClassname = React.useMemo(() => {
|
||||
const cn = ['dockview-react-tab-action'];
|
||||
return cn.join(',');
|
||||
}, [api.suppressClosable]);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div {...rest} onClick={onClick} className="dockview-react-tab">
|
||||
|
Loading…
Reference in New Issue
Block a user