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

Enabled movable Custom Views #89240

Merged
merged 5 commits into from
Jan 27, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions src/vs/platform/list/browser/listService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,11 @@ export class WorkbenchDataTree<TInput, T, TFilterData = void> extends DataTree<T
this.internals = new WorkbenchTreeInternals(this, treeOptions, getAutomaticKeyboardNavigation, options.overrideStyles, contextKeyService, listService, themeService, configurationService, accessibilityService);
this.disposables.add(this.internals);
}

updateOptions(options: IWorkbenchAsyncDataTreeOptions<T, TFilterData> = {}): void {
super.updateOptions(options);
this.internals.updateStyleOverrides(options.overrideStyles);
}
}

export interface IWorkbenchAsyncDataTreeOptions<T, TFilterData> extends IAsyncDataTreeOptions<T, TFilterData> {
Expand Down Expand Up @@ -839,6 +844,11 @@ export class WorkbenchAsyncDataTree<TInput, T, TFilterData = void> extends Async
this.internals = new WorkbenchTreeInternals(this, treeOptions, getAutomaticKeyboardNavigation, options.overrideStyles, contextKeyService, listService, themeService, configurationService, accessibilityService);
this.disposables.add(this.internals);
}

updateOptions(options: IWorkbenchAsyncDataTreeOptions<T, TFilterData> = {}): void {
super.updateOptions(options);
this.internals.updateStyleOverrides(options.overrideStyles);
}
}

export interface IWorkbenchCompressibleAsyncDataTreeOptions<T, TFilterData> extends ICompressibleAsyncDataTreeOptions<T, TFilterData> {
Expand Down Expand Up @@ -936,15 +946,16 @@ class WorkbenchTreeInternals<TInput, T, TFilterData> {
private hasMultiSelection: IContextKey<boolean>;
private _useAltAsMultipleSelectionModifier: boolean;
private disposables: IDisposable[] = [];
private styler!: IDisposable;

constructor(
tree: WorkbenchObjectTree<T, TFilterData> | CompressibleObjectTree<T, TFilterData> | WorkbenchDataTree<TInput, T, TFilterData> | WorkbenchAsyncDataTree<TInput, T, TFilterData> | WorkbenchCompressibleAsyncDataTree<TInput, T, TFilterData>,
private tree: WorkbenchObjectTree<T, TFilterData> | CompressibleObjectTree<T, TFilterData> | WorkbenchDataTree<TInput, T, TFilterData> | WorkbenchAsyncDataTree<TInput, T, TFilterData> | WorkbenchCompressibleAsyncDataTree<TInput, T, TFilterData>,
options: IAbstractTreeOptions<T, TFilterData> | IAsyncDataTreeOptions<T, TFilterData>,
getAutomaticKeyboardNavigation: () => boolean | undefined,
overrideStyles: IColorMapping | undefined,
@IContextKeyService contextKeyService: IContextKeyService,
@IListService listService: IListService,
@IThemeService themeService: IThemeService,
@IThemeService private themeService: IThemeService,
@IConfigurationService configurationService: IConfigurationService,
@IAccessibilityService accessibilityService: IAccessibilityService,
) {
Expand All @@ -970,10 +981,11 @@ class WorkbenchTreeInternals<TInput, T, TFilterData> {
});
};

this.updateStyleOverrides(overrideStyles);

this.disposables.push(
this.contextKeyService,
(listService as ListService).register(tree),
overrideStyles ? attachListStyler(tree, themeService, overrideStyles) : Disposable.None,
tree.onDidChangeSelection(() => {
const selection = tree.getSelection();
const focus = tree.getFocus();
Expand Down Expand Up @@ -1023,8 +1035,14 @@ class WorkbenchTreeInternals<TInput, T, TFilterData> {
return this._useAltAsMultipleSelectionModifier;
}

updateStyleOverrides(overrideStyles?: IColorMapping): void {
dispose(this.styler);
this.styler = overrideStyles ? attachListStyler(this.tree, this.themeService, overrideStyles) : Disposable.None;
}

dispose(): void {
this.disposables = dispose(this.disposables);
this.styler = dispose(this.styler);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/vs/workbench/api/browser/viewsExtensionPoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,9 @@ class ViewsExtensionHandler implements IWorkbenchContribution {
ctorDescriptor: new SyncDescriptor(CustomTreeViewPane),
when: ContextKeyExpr.deserialize(item.when),
canToggleVisibility: true,
canMoveView: true,
treeView: this.instantiationService.createInstance(CustomTreeView, item.id, item.name),
collapsed: this.showCollapsed(container),
treeView: this.instantiationService.createInstance(CustomTreeView, item.id, item.name, container),
order: order,
extensionId: extension.description.identifier,
originalContainerId: entry.key,
Expand Down
25 changes: 17 additions & 8 deletions src/vs/workbench/browser/parts/views/customView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { IContextMenuService } from 'vs/platform/contextview/browser/contextView
import { IMenuService, MenuId, MenuItemAction } from 'vs/platform/actions/common/actions';
import { ContextAwareMenuEntryActionViewItem, createAndFillInContextMenuActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { ITreeView, ITreeItem, TreeItemCollapsibleState, ITreeViewDataProvider, TreeViewItemHandleArg, ITreeViewDescriptor, IViewsRegistry, ViewContainer, ITreeItemLabel, Extensions, IViewDescriptorService } from 'vs/workbench/common/views';
import { ITreeView, ITreeItem, TreeItemCollapsibleState, ITreeViewDataProvider, TreeViewItemHandleArg, ITreeViewDescriptor, IViewsRegistry, ITreeItemLabel, Extensions, IViewDescriptorService, ViewContainer, ViewContainerLocation } from 'vs/workbench/common/views';
import { IViewletViewOptions } from 'vs/workbench/browser/parts/views/viewsViewlet';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { INotificationService } from 'vs/platform/notification/common/notification';
Expand Down Expand Up @@ -41,7 +41,7 @@ import { ITreeRenderer, ITreeNode, IAsyncDataSource, ITreeContextMenuEvent } fro
import { FuzzyScore, createMatches } from 'vs/base/common/filters';
import { CollapseAllAction } from 'vs/base/browser/ui/tree/treeDefaults';
import { isFalsyOrWhitespace } from 'vs/base/common/strings';
import { SIDE_BAR_BACKGROUND } from 'vs/workbench/common/theme';
import { SIDE_BAR_BACKGROUND, PANEL_BACKGROUND } from 'vs/workbench/common/theme';

export class CustomTreeViewPane extends ViewPane {

Expand Down Expand Up @@ -154,7 +154,6 @@ export class CustomTreeView extends Disposable implements ITreeView {
constructor(
private id: string,
private _title: string,
private viewContainer: ViewContainer,
@IExtensionService private readonly extensionService: IExtensionService,
@IWorkbenchThemeService private readonly themeService: IWorkbenchThemeService,
@IInstantiationService private readonly instantiationService: IInstantiationService,
Expand All @@ -163,7 +162,8 @@ export class CustomTreeView extends Disposable implements ITreeView {
@IProgressService private readonly progressService: IProgressService,
@IContextMenuService private readonly contextMenuService: IContextMenuService,
@IKeybindingService private readonly keybindingService: IKeybindingService,
@INotificationService private readonly notificationService: INotificationService
@INotificationService private readonly notificationService: INotificationService,
@IViewDescriptorService private readonly viewDescriptorService: IViewDescriptorService
) {
super();
this.root = new Root();
Expand All @@ -174,14 +174,23 @@ export class CustomTreeView extends Disposable implements ITreeView {
this.doRefresh([this.root]); /** soft refresh **/
}
}));
this._register(Registry.as<IViewsRegistry>(Extensions.ViewsRegistry).onDidChangeContainer(({ views, from, to }) => {
if (from === this.viewContainer && views.some(v => v.id === this.id)) {
this.viewContainer = to;
this._register(this.viewDescriptorService.onDidChangeLocation(({ views, from, to }) => {
if (views.some(v => v.id === this.id)) {
this.tree?.updateOptions({ overrideStyles: { listBackground: this.viewLocation === ViewContainerLocation.Sidebar ? SIDE_BAR_BACKGROUND : PANEL_BACKGROUND } });
}
}));

this.create();
}

get viewContainer(): ViewContainer {
return this.viewDescriptorService.getViewContainer(this.id)!;
}

get viewLocation(): ViewContainerLocation {
return this.viewDescriptorService.getViewLocation(this.id)!;
}

private _dataProvider: ITreeViewDataProvider | undefined;
get dataProvider(): ITreeViewDataProvider | undefined {
return this._dataProvider;
Expand Down Expand Up @@ -360,7 +369,7 @@ export class CustomTreeView extends Disposable implements ITreeView {
},
multipleSelectionSupport: this.canSelectMany,
overrideStyles: {
listBackground: SIDE_BAR_BACKGROUND
listBackground: this.viewLocation === ViewContainerLocation.Sidebar ? SIDE_BAR_BACKGROUND : PANEL_BACKGROUND
}
}) as WorkbenchAsyncDataTree<ITreeItem, ITreeItem, FuzzyScore>);
aligner.tree = this.tree;
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/browser/parts/views/viewPaneContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export abstract class ViewPane extends Pane implements IView {
@IContextMenuService protected contextMenuService: IContextMenuService,
@IConfigurationService protected readonly configurationService: IConfigurationService,
@IContextKeyService contextKeyService: IContextKeyService,
@IViewDescriptorService private viewDescriptorService: IViewDescriptorService,
@IViewDescriptorService protected viewDescriptorService: IViewDescriptorService,
@IInstantiationService protected instantiationService: IInstantiationService,
) {
super(options);
Expand Down
10 changes: 5 additions & 5 deletions src/vs/workbench/common/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,8 @@ export interface IViewsViewlet extends IViewlet {

}

export const IViewDescriptorService = createDecorator<IViewDescriptorService>('viewDescriptorService');
export const IViewsService = createDecorator<IViewsService>('viewsService');


export interface IViewsService {
_serviceBrand: undefined;

Expand All @@ -361,11 +359,15 @@ export interface IViewsService {
openView(id: string, focus?: boolean): Promise<IView | null>;
}

export const IViewDescriptorService = createDecorator<IViewDescriptorService>('viewDescriptorService');

export interface IViewDescriptorService {

_serviceBrand: undefined;

readonly onDidChangeContainer: Event<{ views: IViewDescriptor[], from: ViewContainer, to: ViewContainer }>;
readonly onDidChangeLocation: Event<{ views: IViewDescriptor[], from: ViewContainerLocation, to: ViewContainerLocation }>;

moveViewToLocation(view: IViewDescriptor, location: ViewContainerLocation): void;

moveViewsToContainer(views: IViewDescriptor[], viewContainer: ViewContainer): void;
Expand Down Expand Up @@ -443,9 +445,7 @@ export interface IRevealOptions {
}

export interface ITreeViewDescriptor extends IViewDescriptor {

readonly treeView: ITreeView;

treeView: ITreeView;
}

export type TreeViewItemHandleArg = {
Expand Down
9 changes: 7 additions & 2 deletions src/vs/workbench/contrib/outline/browser/outlinePane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import { basename } from 'vs/base/common/resources';
import { IDataSource } from 'vs/base/browser/ui/tree/tree';
import { IMarkerDecorationsService } from 'vs/editor/common/services/markersDecorationService';
import { MarkerSeverity } from 'vs/platform/markers/common/markers';
import { SIDE_BAR_BACKGROUND } from 'vs/workbench/common/theme';
import { IViewDescriptorService } from 'vs/workbench/common/views';

class RequestState {
Expand Down Expand Up @@ -335,13 +334,19 @@ export class OutlinePane extends ViewPane {
keyboardNavigationLabelProvider: new OutlineNavigationLabelProvider(),
hideTwistiesOfChildlessElements: true,
overrideStyles: {
listBackground: SIDE_BAR_BACKGROUND
listBackground: this.getBackgroundColor()
}
}
);


this._disposables.push(this._tree);
this._disposables.push(this._outlineViewState.onDidChange(this._onDidChangeUserState, this));
this._disposables.push(this.viewDescriptorService.onDidChangeLocation(({ views, from, to }) => {
if (views.some(v => v.id === this.id)) {
this._tree.updateOptions({ overrideStyles: { listBackground: this.getBackgroundColor() } });
}
}));

// override the globally defined behaviour
this._tree.updateOptions({
Expand Down
23 changes: 22 additions & 1 deletion src/vs/workbench/services/views/browser/viewDescriptorService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor
private static readonly CACHED_VIEW_POSITIONS = 'views.cachedViewPositions';
private static readonly COMMON_CONTAINER_ID_PREFIX = 'workbench.views.service';

private readonly _onDidChangeContainer: Emitter<{ views: IViewDescriptor[], from: ViewContainer, to: ViewContainer }> = this._register(new Emitter<{ views: IViewDescriptor[], from: ViewContainer, to: ViewContainer }>());
readonly onDidChangeContainer: Event<{ views: IViewDescriptor[], from: ViewContainer, to: ViewContainer }> = this._onDidChangeContainer.event;

private readonly _onDidChangeLocation: Emitter<{ views: IViewDescriptor[], from: ViewContainerLocation, to: ViewContainerLocation }> = this._register(new Emitter<{ views: IViewDescriptor[], from: ViewContainerLocation, to: ViewContainerLocation }>());
readonly onDidChangeLocation: Event<{ views: IViewDescriptor[], from: ViewContainerLocation, to: ViewContainerLocation }> = this._onDidChangeLocation.event;

private readonly viewDescriptorCollections: Map<ViewContainer, { viewDescriptorCollection: ViewDescriptorCollection, disposable: IDisposable; }>;
private readonly activeViewContextKeys: Map<string, IContextKey<boolean>>;
private readonly movableViewContextKeys: Map<string, IContextKey<boolean>>;
Expand Down Expand Up @@ -230,7 +236,7 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor
this._register(this.viewsRegistry.onViewsRegistered(({ views, viewContainer }) => this.onDidRegisterViews(views, viewContainer)));
this._register(this.viewsRegistry.onViewsDeregistered(({ views, viewContainer }) => this.onDidDeregisterViews(views, viewContainer)));

this._register(this.viewsRegistry.onDidChangeContainer(({ views, from, to }) => { this.removeViews(from, views); this.addViews(to, views); }));
this._register(this.viewsRegistry.onDidChangeContainer(({ views, from, to }) => { this.removeViews(from, views); this.addViews(to, views); this._onDidChangeContainer.fire({ views, from, to }); }));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we shall also check location change here even though currently location change is not yet supported in registry. This should be ready for future if it is allowed.

I would recommend to have a single method that can be reused when views are moved in registry or in cache.

this.removeViews(from, views);
 this.addViews(to, views);

  const oldLocation = this.viewContainersRegistry.getViewContainerLocation(from)!;
 const newLocation = this.viewContainersRegistry.getViewContainerLocation(to)!;

  if (oldLocation !== newLocation) {
 	this._onDidChangeLocation.fire({ views, from: oldLocation, to: newLocation });
 }

 this._onDidChangeContainer.fire({ views, from, to });

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sandy081 thanks, will take care of this.


this._register(this.viewContainersRegistry.onDidRegister(({ viewContainer }) => this.onDidRegisterViewContainer(viewContainer)));
this._register(this.viewContainersRegistry.onDidDeregister(({ viewContainer }) => this.onDidDeregisterViewContainer(viewContainer)));
Expand Down Expand Up @@ -295,6 +301,11 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor
const viewDescriptor = this.getViewDescriptor(viewId);
if (viewContainer && viewDescriptor) {
this.addViews(viewContainer, [viewDescriptor]);

const newLocation = this.viewContainersRegistry.getViewContainerLocation(viewContainer)!;
if (containerInfo.location && containerInfo.location !== newLocation) {
this._onDidChangeLocation.fire({ views: [viewDescriptor], from: containerInfo.location, to: newLocation });
}
}
}

Expand Down Expand Up @@ -357,6 +368,7 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor

getViewContainer(viewId: string): ViewContainer | null {
const containerId = this.cachedViewInfo.get(viewId)?.containerId;

return containerId ?
this.viewContainersRegistry.get(containerId) ?? null :
this.viewsRegistry.getViewContainer(viewId);
Expand Down Expand Up @@ -395,6 +407,15 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor
if (from && to && from !== to) {
this.removeViews(from, views);
this.addViews(to, views);

const oldLocation = this.viewContainersRegistry.getViewContainerLocation(from)!;
const newLocation = this.viewContainersRegistry.getViewContainerLocation(to)!;

if (oldLocation !== newLocation) {
this._onDidChangeLocation.fire({ views, from: oldLocation, to: newLocation });
}

this._onDidChangeContainer.fire({ views, from, to });
this.saveViewPositionsToCache();
}
}
Expand Down