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