Skip to content

Commit 38b02b7

Browse files
author
Benjamin Pasero
committed
quickpick - move Themable to platform
1 parent 3124d49 commit 38b02b7

12 files changed

Lines changed: 56 additions & 61 deletions

File tree

src/vs/platform/theme/common/colorRegistry.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { IJSONSchema, IJSONSchemaMap } from 'vs/base/common/jsonSchema';
88
import { Color, RGBA } from 'vs/base/common/color';
99
import { IColorTheme } from 'vs/platform/theme/common/themeService';
1010
import { Event, Emitter } from 'vs/base/common/event';
11-
1211
import * as nls from 'vs/nls';
1312
import { Extensions as JSONExtensions, IJSONContributionRegistry } from 'vs/platform/jsonschemas/common/jsonContributionRegistry';
1413
import { RunOnceScheduler } from 'vs/base/common/async';

src/vs/platform/theme/common/themeService.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
77
import { Color } from 'vs/base/common/color';
8-
import { IDisposable, toDisposable } from 'vs/base/common/lifecycle';
8+
import { IDisposable, toDisposable, Disposable } from 'vs/base/common/lifecycle';
99
import * as platform from 'vs/platform/registry/common/platform';
1010
import { ColorIdentifier } from 'vs/platform/theme/common/colorRegistry';
1111
import { Event, Emitter } from 'vs/base/common/event';
@@ -191,3 +191,41 @@ platform.Registry.add(Extensions.ThemingContribution, themingRegistry);
191191
export function registerThemingParticipant(participant: IThemingParticipant): IDisposable {
192192
return themingRegistry.onColorThemeChange(participant);
193193
}
194+
195+
/**
196+
* Utility base class for all themable components.
197+
*/
198+
export class Themable extends Disposable {
199+
protected theme: IColorTheme;
200+
201+
constructor(
202+
protected themeService: IThemeService
203+
) {
204+
super();
205+
206+
this.theme = themeService.getColorTheme();
207+
208+
// Hook up to theme changes
209+
this._register(this.themeService.onDidColorThemeChange(theme => this.onThemeChange(theme)));
210+
}
211+
212+
protected onThemeChange(theme: IColorTheme): void {
213+
this.theme = theme;
214+
215+
this.updateStyles();
216+
}
217+
218+
protected updateStyles(): void {
219+
// Subclasses to override
220+
}
221+
222+
protected getColor(id: string, modify?: (color: Color, theme: IColorTheme) => Color): string | null {
223+
let color = this.theme.getColor(id);
224+
225+
if (color && modify) {
226+
color = modify(color, this.theme);
227+
}
228+
229+
return color ? color.toString() : null;
230+
}
231+
}

src/vs/workbench/browser/parts/editor/editorDropTarget.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import 'vs/css!./media/editordroptarget';
77
import { LocalSelectionTransfer, DraggedEditorIdentifier, ResourcesDropHandler, DraggedEditorGroupIdentifier, DragAndDropObserver, containsDragType } from 'vs/workbench/browser/dnd';
88
import { addDisposableListener, EventType, EventHelper, isAncestor, toggleClass, addClass, removeClass } from 'vs/base/browser/dom';
99
import { IEditorGroupsAccessor, EDITOR_TITLE_HEIGHT, IEditorGroupView, getActiveTextEditorOptions } from 'vs/workbench/browser/parts/editor/editor';
10-
import { EDITOR_DRAG_AND_DROP_BACKGROUND, Themable } from 'vs/workbench/common/theme';
11-
import { IThemeService } from 'vs/platform/theme/common/themeService';
10+
import { EDITOR_DRAG_AND_DROP_BACKGROUND } from 'vs/workbench/common/theme';
11+
import { IThemeService, Themable } from 'vs/platform/theme/common/themeService';
1212
import { activeContrastBorder } from 'vs/platform/theme/common/colorRegistry';
1313
import { IEditorIdentifier, EditorInput, EditorOptions } from 'vs/workbench/common/editor';
1414
import { isMacintosh, isWeb } from 'vs/base/common/platform';

src/vs/workbench/browser/parts/editor/editorGroupView.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import { ServiceCollection } from 'vs/platform/instantiation/common/serviceColle
1414
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
1515
import { ProgressBar } from 'vs/base/browser/ui/progressbar/progressbar';
1616
import { attachProgressBarStyler } from 'vs/platform/theme/common/styler';
17-
import { IThemeService, registerThemingParticipant } from 'vs/platform/theme/common/themeService';
17+
import { IThemeService, registerThemingParticipant, Themable } from 'vs/platform/theme/common/themeService';
1818
import { editorBackground, contrastBorder } from 'vs/platform/theme/common/colorRegistry';
19-
import { Themable, EDITOR_GROUP_HEADER_TABS_BORDER, EDITOR_GROUP_HEADER_TABS_BACKGROUND, EDITOR_GROUP_HEADER_NO_TABS_BACKGROUND, EDITOR_GROUP_EMPTY_BACKGROUND, EDITOR_GROUP_FOCUSED_EMPTY_BORDER } from 'vs/workbench/common/theme';
19+
import { EDITOR_GROUP_HEADER_TABS_BORDER, EDITOR_GROUP_HEADER_TABS_BACKGROUND, EDITOR_GROUP_HEADER_NO_TABS_BACKGROUND, EDITOR_GROUP_EMPTY_BACKGROUND, EDITOR_GROUP_FOCUSED_EMPTY_BORDER } from 'vs/workbench/common/theme';
2020
import { IMoveEditorOptions, ICopyEditorOptions, ICloseEditorsFilter, IGroupChangeEvent, GroupChangeKind, GroupsOrder, ICloseEditorOptions } from 'vs/workbench/services/editor/common/editorGroupsService';
2121
import { TabsTitleControl } from 'vs/workbench/browser/parts/editor/tabsTitleControl';
2222
import { EditorControl } from 'vs/workbench/browser/parts/editor/editorControl';

src/vs/workbench/browser/parts/editor/titleControl.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { INotificationService } from 'vs/platform/notification/common/notificati
2626
import { IQuickOpenService } from 'vs/platform/quickOpen/common/quickOpen';
2727
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
2828
import { listActiveSelectionBackground, listActiveSelectionForeground } from 'vs/platform/theme/common/colorRegistry';
29-
import { ICssStyleCollector, IColorTheme, IThemeService, registerThemingParticipant } from 'vs/platform/theme/common/themeService';
29+
import { ICssStyleCollector, IColorTheme, IThemeService, registerThemingParticipant, Themable } from 'vs/platform/theme/common/themeService';
3030
import { prepareActions } from 'vs/workbench/browser/actions';
3131
import { DraggedEditorGroupIdentifier, DraggedEditorIdentifier, fillResourceDataTransfers, LocalSelectionTransfer } from 'vs/workbench/browser/dnd';
3232
import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor';
@@ -35,7 +35,6 @@ import { BreadcrumbsControl, IBreadcrumbsControlOptions } from 'vs/workbench/bro
3535
import { EDITOR_TITLE_HEIGHT, IEditorGroupsAccessor, IEditorGroupView } from 'vs/workbench/browser/parts/editor/editor';
3636
import { EditorCommandsContextActionRunner, IEditorCommandsContext, IEditorInput, toResource, IEditorPartOptions, SideBySideEditor, EditorPinnedContext } from 'vs/workbench/common/editor';
3737
import { ResourceContextKey } from 'vs/workbench/common/resources';
38-
import { Themable } from 'vs/workbench/common/theme';
3938
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
4039
import { AnchorAlignment } from 'vs/base/browser/ui/contextview/contextview';
4140
import { IFileService } from 'vs/platform/files/common/files';

src/vs/workbench/browser/parts/notifications/notificationsCenter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
import 'vs/css!./media/notificationsCenter';
77
import 'vs/css!./media/notificationsActions';
8-
import { Themable, NOTIFICATIONS_BORDER, NOTIFICATIONS_CENTER_HEADER_FOREGROUND, NOTIFICATIONS_CENTER_HEADER_BACKGROUND, NOTIFICATIONS_CENTER_BORDER } from 'vs/workbench/common/theme';
9-
import { IThemeService, registerThemingParticipant, IColorTheme, ICssStyleCollector } from 'vs/platform/theme/common/themeService';
8+
import { NOTIFICATIONS_BORDER, NOTIFICATIONS_CENTER_HEADER_FOREGROUND, NOTIFICATIONS_CENTER_HEADER_BACKGROUND, NOTIFICATIONS_CENTER_BORDER } from 'vs/workbench/common/theme';
9+
import { IThemeService, registerThemingParticipant, IColorTheme, ICssStyleCollector, Themable } from 'vs/platform/theme/common/themeService';
1010
import { INotificationsModel, INotificationChangeEvent, NotificationChangeType, NotificationViewItemContentChangeKind } from 'vs/workbench/common/notifications';
1111
import { IWorkbenchLayoutService, Parts } from 'vs/workbench/services/layout/browser/layoutService';
1212
import { Emitter } from 'vs/base/common/event';

src/vs/workbench/browser/parts/notifications/notificationsList.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import { addClass, isAncestor, trackFocus } from 'vs/base/browser/dom';
88
import { WorkbenchList } from 'vs/platform/list/browser/listService';
99
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
1010
import { IListOptions } from 'vs/base/browser/ui/list/listWidget';
11-
import { Themable, NOTIFICATIONS_LINKS, NOTIFICATIONS_BACKGROUND, NOTIFICATIONS_FOREGROUND, NOTIFICATIONS_ERROR_ICON_FOREGROUND, NOTIFICATIONS_WARNING_ICON_FOREGROUND, NOTIFICATIONS_INFO_ICON_FOREGROUND } from 'vs/workbench/common/theme';
12-
import { IThemeService, registerThemingParticipant, IColorTheme, ICssStyleCollector } from 'vs/platform/theme/common/themeService';
11+
import { NOTIFICATIONS_LINKS, NOTIFICATIONS_BACKGROUND, NOTIFICATIONS_FOREGROUND, NOTIFICATIONS_ERROR_ICON_FOREGROUND, NOTIFICATIONS_WARNING_ICON_FOREGROUND, NOTIFICATIONS_INFO_ICON_FOREGROUND } from 'vs/workbench/common/theme';
12+
import { IThemeService, registerThemingParticipant, IColorTheme, ICssStyleCollector, Themable } from 'vs/platform/theme/common/themeService';
1313
import { contrastBorder, focusBorder } from 'vs/platform/theme/common/colorRegistry';
1414
import { INotificationViewItem } from 'vs/workbench/common/notifications';
1515
import { NotificationsListDelegate, NotificationRenderer } from 'vs/workbench/browser/parts/notifications/notificationsViewer';

src/vs/workbench/browser/parts/notifications/notificationsToasts.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
1111
import { NotificationsList } from 'vs/workbench/browser/parts/notifications/notificationsList';
1212
import { Event, Emitter } from 'vs/base/common/event';
1313
import { IWorkbenchLayoutService, Parts } from 'vs/workbench/services/layout/browser/layoutService';
14-
import { Themable, NOTIFICATIONS_TOAST_BORDER, NOTIFICATIONS_BACKGROUND } from 'vs/workbench/common/theme';
15-
import { IThemeService } from 'vs/platform/theme/common/themeService';
14+
import { NOTIFICATIONS_TOAST_BORDER, NOTIFICATIONS_BACKGROUND } from 'vs/workbench/common/theme';
15+
import { IThemeService, Themable } from 'vs/platform/theme/common/themeService';
1616
import { widgetShadow } from 'vs/platform/theme/common/colorRegistry';
1717
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
1818
import { NotificationsToastsVisibleContext, INotificationsToastController } from 'vs/workbench/browser/parts/notifications/notificationsCommands';

src/vs/workbench/common/component.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { Memento, MementoObject } from 'vs/workbench/common/memento';
7-
import { IThemeService } from 'vs/platform/theme/common/themeService';
8-
import { Themable } from 'vs/workbench/common/theme';
7+
import { IThemeService, Themable } from 'vs/platform/theme/common/themeService';
98
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
109

1110
export class Component extends Themable {
@@ -42,4 +41,4 @@ export class Component extends Themable {
4241
protected saveState(): void {
4342
// Subclasses to implement for storing state
4443
}
45-
}
44+
}

src/vs/workbench/common/theme.ts

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55

66
import * as nls from 'vs/nls';
77
import { registerColor, editorBackground, contrastBorder, transparent, editorWidgetBackground, textLinkForeground, lighten, darken, focusBorder, activeContrastBorder, editorWidgetForeground, editorErrorForeground, editorWarningForeground, editorInfoForeground } from 'vs/platform/theme/common/colorRegistry';
8-
import { Disposable } from 'vs/base/common/lifecycle';
9-
import { IThemeService, IColorTheme } from 'vs/platform/theme/common/themeService';
8+
import { IColorTheme } from 'vs/platform/theme/common/themeService';
109
import { Color } from 'vs/base/common/color';
1110

1211
// < --- Workbench (not customizable) --- >
@@ -606,41 +605,3 @@ export const WINDOW_INACTIVE_BORDER = registerColor('window.inactiveBorder', {
606605
light: null,
607606
hc: contrastBorder
608607
}, nls.localize('windowInactiveBorder', "The color used for the border of the window when it is inactive. Only supported in the desktop client when using the custom title bar."));
609-
610-
/**
611-
* Base class for all themable workbench components.
612-
*/
613-
export class Themable extends Disposable {
614-
protected theme: IColorTheme;
615-
616-
constructor(
617-
protected themeService: IThemeService
618-
) {
619-
super();
620-
621-
this.theme = themeService.getColorTheme();
622-
623-
// Hook up to theme changes
624-
this._register(this.themeService.onDidColorThemeChange(theme => this.onThemeChange(theme)));
625-
}
626-
627-
protected onThemeChange(theme: IColorTheme): void {
628-
this.theme = theme;
629-
630-
this.updateStyles();
631-
}
632-
633-
protected updateStyles(): void {
634-
// Subclasses to override
635-
}
636-
637-
protected getColor(id: string, modify?: (color: Color, theme: IColorTheme) => Color): string | null {
638-
let color = this.theme.getColor(id);
639-
640-
if (color && modify) {
641-
color = modify(color, this.theme);
642-
}
643-
644-
return color ? color.toString() : null;
645-
}
646-
}

0 commit comments

Comments
 (0)