Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debt - more readonly properties #159841

Merged
merged 1 commit into from Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/vs/workbench/browser/part.ts
Expand Up @@ -14,13 +14,13 @@ import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/la
import { assertIsDefined } from 'vs/base/common/types';

export interface IPartOptions {
hasTitle?: boolean;
borderWidth?: () => number;
readonly hasTitle?: boolean;
readonly borderWidth?: () => number;
}

export interface ILayoutContentResult {
titleSize: IDimension;
contentSize: IDimension;
readonly titleSize: IDimension;
readonly contentSize: IDimension;
}

/**
Expand Down
62 changes: 34 additions & 28 deletions src/vs/workbench/browser/parts/compositeBar.ts
Expand Up @@ -25,7 +25,9 @@ import { CompositeDragAndDropData, CompositeDragAndDropObserver, IDraggedComposi
import { Gesture, EventType as TouchEventType, GestureEvent } from 'vs/base/browser/touch';

export interface ICompositeBarItem {
id: string;

readonly id: string;

name?: string;
pinned: boolean;
order?: number;
Expand All @@ -39,7 +41,7 @@ export class CompositeDragAndDrop implements ICompositeDragAndDrop {
private targetContainerLocation: ViewContainerLocation,
private openComposite: (id: string, focus?: boolean) => Promise<IPaneComposite | null>,
private moveComposite: (from: string, to: string, before?: Before2D) => void,
private getItems: () => ICompositeBarItem[],
private getItems: () => ICompositeBarItem[]
) { }

drop(data: CompositeDragAndDropData, targetCompositeId: string | undefined, originalEvent: DragEvent, before?: Before2D): void {
Expand Down Expand Up @@ -68,7 +70,6 @@ export class CompositeDragAndDrop implements ICompositeDragAndDrop {

if (dragData.type === 'view') {
const viewToMove = this.viewDescriptorService.getViewDescriptorById(dragData.id)!;

if (viewToMove && viewToMove.canMoveView) {
this.viewDescriptorService.moveViewToLocation(viewToMove, this.targetContainerLocation);

Expand Down Expand Up @@ -100,13 +101,14 @@ export class CompositeDragAndDrop implements ICompositeDragAndDrop {

const items = this.getItems();
const before = this.targetContainerLocation === ViewContainerLocation.Panel ? before2d?.horizontallyBefore : before2d?.verticallyBefore;
return items.filter(o => o.visible).findIndex(o => o.id === targetId) + (before ? 0 : 1);
return items.filter(item => item.visible).findIndex(item => item.id === targetId) + (before ? 0 : 1);
}

private canDrop(data: CompositeDragAndDropData, targetCompositeId: string | undefined): boolean {
const dragData = data.getData();

if (dragData.type === 'composite') {

// Dragging a composite
const currentContainer = this.viewDescriptorService.getViewContainerById(dragData.id)!;
const currentLocation = this.viewDescriptorService.getViewContainerLocation(currentContainer);
Expand All @@ -120,8 +122,9 @@ export class CompositeDragAndDrop implements ICompositeDragAndDrop {
const draggedViews = this.viewDescriptorService.getViewContainerModel(currentContainer)!.allViewDescriptors;

// ... all views must be movable
return !draggedViews.some(v => !v.canMoveView);
return !draggedViews.some(view => !view.canMoveView);
} else {

// Dragging an individual view
const viewDescriptor = this.viewDescriptorService.getViewDescriptorById(dragData.id);

Expand All @@ -147,14 +150,16 @@ export interface ICompositeBarOptions {
readonly activityHoverOptions: IActivityHoverOptions;
readonly preventLoopNavigation?: boolean;

getActivityAction: (compositeId: string) => ActivityAction;
getCompositePinnedAction: (compositeId: string) => IAction;
getOnCompositeClickAction: (compositeId: string) => IAction;
fillExtraContextMenuActions: (actions: IAction[], e?: MouseEvent | GestureEvent) => void;
getContextMenuActionsForComposite: (compositeId: string) => IAction[];
openComposite: (compositeId: string, preserveFocus?: boolean) => Promise<IComposite | null>;
getDefaultCompositeId: () => string | undefined;
hidePart: () => void;
readonly getActivityAction: (compositeId: string) => ActivityAction;
readonly getCompositePinnedAction: (compositeId: string) => IAction;
readonly getOnCompositeClickAction: (compositeId: string) => IAction;
readonly fillExtraContextMenuActions: (actions: IAction[], e?: MouseEvent | GestureEvent) => void;
readonly getContextMenuActionsForComposite: (compositeId: string) => IAction[];

readonly openComposite: (compositeId: string, preserveFocus?: boolean) => Promise<IComposite | null>;
readonly getDefaultCompositeId: () => string | undefined;

readonly hidePart: () => void;
}

export class CompositeBar extends Widget implements ICompositeBar {
Expand All @@ -168,9 +173,9 @@ export class CompositeBar extends Widget implements ICompositeBar {
private compositeOverflowAction: CompositeOverflowActivityAction | undefined;
private compositeOverflowActionViewItem: CompositeOverflowActivityActionViewItem | undefined;

private model: CompositeBarModel;
private visibleComposites: string[];
private compositeSizeInBar: Map<string, number>;
private readonly model: CompositeBarModel;
private readonly visibleComposites: string[];
private readonly compositeSizeInBar: Map<string, number>;

constructor(
items: ICompositeBarItem[],
Expand Down Expand Up @@ -236,10 +241,11 @@ export class CompositeBar extends Widget implements ICompositeBar {
this._register(Gesture.addTarget(parent));
this._register(addDisposableListener(parent, TouchEventType.Contextmenu, e => this.showContextMenu(e)));

let insertDropBefore: Before2D | undefined = undefined;
// Register a drop target on the whole bar to prevent forbidden feedback
let insertDropBefore: Before2D | undefined = undefined;
this._register(CompositeDragAndDropObserver.INSTANCE.registerTarget(parent, {
onDragOver: (e: IDraggedCompositeData) => {

// don't add feedback if this is over the composite bar actions or there are no actions
const visibleItems = this.getVisibleComposites();
if (!visibleItems.length || (e.eventData.target && isAncestor(e.eventData.target as HTMLElement, actionBarDiv))) {
Expand All @@ -253,7 +259,6 @@ export class CompositeBar extends Widget implements ICompositeBar {
toggleDropEffect(e.eventData.dataTransfer, 'move', validDropTarget);
insertDropBefore = this.updateFromDragging(parent, validDropTarget, insertAtFront, true);
},

onDragLeave: (e: IDraggedCompositeData) => {
insertDropBefore = this.updateFromDragging(parent, false, false, false);
},
Expand Down Expand Up @@ -308,6 +313,7 @@ export class CompositeBar extends Widget implements ICompositeBar {

layout(dimension: Dimension): void {
this.dimension = dimension;

if (dimension.height === 0 || dimension.width === 0) {
// Do not layout if not visible. Otherwise the size measurment would be computed wrongly
return;
Expand All @@ -323,7 +329,6 @@ export class CompositeBar extends Widget implements ICompositeBar {
}

addComposite({ id, name, order, requestedIndex }: { id: string; name: string; order?: number; requestedIndex?: number }): void {
// Add to the model
if (this.model.add(id, name, order, requestedIndex)) {
this.computeSizes([this.model.findItem(id)]);
this.updateCompositeSwitcher();
Expand Down Expand Up @@ -436,7 +441,6 @@ export class CompositeBar extends Widget implements ICompositeBar {
}

move(compositeId: string, toCompositeId: string, before?: boolean): void {

if (before !== undefined) {
const fromIndex = this.model.items.findIndex(c => c.id === compositeId);
let toIndex = this.model.items.findIndex(c => c.id === toCompositeId);
Expand All @@ -457,7 +461,6 @@ export class CompositeBar extends Widget implements ICompositeBar {
}
}
}

} else {
if (this.model.move(compositeId, toCompositeId)) {
// timeout helps to prevent artifacts from showing up
Expand All @@ -468,6 +471,7 @@ export class CompositeBar extends Widget implements ICompositeBar {

getAction(compositeId: string): ActivityAction {
const item = this.model.findItem(compositeId);

return item?.activityAction;
}

Expand All @@ -478,6 +482,7 @@ export class CompositeBar extends Widget implements ICompositeBar {
} else {
const compositeSwitcherBar = this.compositeSwitcherBar;
if (compositeSwitcherBar && this.dimension && this.dimension.height !== 0 && this.dimension.width !== 0) {

// Compute sizes only if visible. Otherwise the size measurment would be computed wrongly.
const currentItemsLength = compositeSwitcherBar.viewItems.length;
compositeSwitcherBar.push(items.map(composite => composite.activityAction));
Expand Down Expand Up @@ -630,6 +635,7 @@ export class CompositeBar extends Widget implements ICompositeBar {

private showContextMenu(e: MouseEvent | GestureEvent): void {
EventHelper.stop(e, true);

const event = new StandardMouseEvent(e);
this.contextMenuService.showContextMenu({
getAnchor: () => { return { x: event.posx, y: event.posy }; },
Expand Down Expand Up @@ -660,15 +666,18 @@ export class CompositeBar extends Widget implements ICompositeBar {
}

interface ICompositeBarModelItem extends ICompositeBarItem {
activityAction: ActivityAction;
pinnedAction: IAction;
activity: ICompositeActivity[];
readonly activityAction: ActivityAction;
readonly pinnedAction: IAction;
readonly activity: ICompositeActivity[];
}

class CompositeBarModel {

private _items: ICompositeBarModelItem[] = [];
get items(): ICompositeBarModelItem[] { return this._items; }

private readonly options: ICompositeBarOptions;

activeItem?: ICompositeBarModelItem;

constructor(
Expand All @@ -679,10 +688,6 @@ class CompositeBarModel {
this.setItems(items);
}

get items(): ICompositeBarModelItem[] {
return this._items;
}

setItems(items: ICompositeBarItem[]): boolean {
const result: ICompositeBarModelItem[] = [];
let hasChanges: boolean = false;
Expand Down Expand Up @@ -914,6 +919,7 @@ class CompositeBarModel {
return index;
}
}

return -1;
}
}