mirror of https://git.tuxpa.in/a/code-server.git
Implement status bar API
This commit is contained in:
parent
976a326f47
commit
12bc26b6b4
|
@ -355,7 +355,7 @@ index add4dfb2fc..18fc71df51 100644
|
||||||
|
|
||||||
get onDidLanguagesChange(): Event<void> { return this.channel.listen('onDidLanguagesChange'); }
|
get onDidLanguagesChange(): Event<void> { return this.channel.listen('onDidLanguagesChange'); }
|
||||||
diff --git a/src/vs/platform/log/common/logIpc.ts b/src/vs/platform/log/common/logIpc.ts
|
diff --git a/src/vs/platform/log/common/logIpc.ts b/src/vs/platform/log/common/logIpc.ts
|
||||||
index 9f68b645b6..b422a3c809 100644
|
index 9f68b645b6..1e224cc29a 100644
|
||||||
--- a/src/vs/platform/log/common/logIpc.ts
|
--- a/src/vs/platform/log/common/logIpc.ts
|
||||||
+++ b/src/vs/platform/log/common/logIpc.ts
|
+++ b/src/vs/platform/log/common/logIpc.ts
|
||||||
@@ -26,6 +26,7 @@ export class LogLevelSetterChannel implements IServerChannel {
|
@@ -26,6 +26,7 @@ export class LogLevelSetterChannel implements IServerChannel {
|
||||||
|
@ -377,13 +377,6 @@ index 9f68b645b6..b422a3c809 100644
|
||||||
}
|
}
|
||||||
|
|
||||||
export class FollowerLogService extends DelegatedLogService implements ILogService {
|
export class FollowerLogService extends DelegatedLogService implements ILogService {
|
||||||
@@ -56,4 +61,4 @@ export class FollowerLogService extends DelegatedLogService implements ILogServi
|
|
||||||
setLevel(level: LogLevel): void {
|
|
||||||
this.master.setLevel(level);
|
|
||||||
}
|
|
||||||
-}
|
|
||||||
\ No newline at end of file
|
|
||||||
+}
|
|
||||||
diff --git a/src/vs/platform/product/node/package.ts b/src/vs/platform/product/node/package.ts
|
diff --git a/src/vs/platform/product/node/package.ts b/src/vs/platform/product/node/package.ts
|
||||||
index d39c5877d6..c189d6f19f 100644
|
index d39c5877d6..c189d6f19f 100644
|
||||||
--- a/src/vs/platform/product/node/package.ts
|
--- a/src/vs/platform/product/node/package.ts
|
||||||
|
@ -562,7 +555,7 @@ index 9fdeeeb1a1..db2dc002c3 100644
|
||||||
}
|
}
|
||||||
|
|
||||||
diff --git a/src/vs/workbench/browser/web.main.ts b/src/vs/workbench/browser/web.main.ts
|
diff --git a/src/vs/workbench/browser/web.main.ts b/src/vs/workbench/browser/web.main.ts
|
||||||
index f5944ce974..a3fcc391fd 100644
|
index f5944ce974..f2094de18b 100644
|
||||||
--- a/src/vs/workbench/browser/web.main.ts
|
--- a/src/vs/workbench/browser/web.main.ts
|
||||||
+++ b/src/vs/workbench/browser/web.main.ts
|
+++ b/src/vs/workbench/browser/web.main.ts
|
||||||
@@ -45,6 +45,7 @@ import { FileLogService } from 'vs/platform/log/common/fileLogService';
|
@@ -45,6 +45,7 @@ import { FileLogService } from 'vs/platform/log/common/fileLogService';
|
||||||
|
@ -573,14 +566,14 @@ index f5944ce974..a3fcc391fd 100644
|
||||||
|
|
||||||
class CodeRendererMain extends Disposable {
|
class CodeRendererMain extends Disposable {
|
||||||
|
|
||||||
@@ -57,6 +58,7 @@ class CodeRendererMain extends Disposable {
|
@@ -94,6 +95,7 @@ class CodeRendererMain extends Disposable {
|
||||||
|
|
||||||
async open(): Promise<void> {
|
// Startup
|
||||||
const services = await this.initServices();
|
workbench.startup();
|
||||||
+ await initialize(services.serviceCollection);
|
+ await initialize(services.serviceCollection);
|
||||||
|
}
|
||||||
|
|
||||||
await domContentLoaded();
|
private restoreBaseTheme(): void {
|
||||||
mark('willStartWorkbench');
|
|
||||||
@@ -204,6 +206,7 @@ class CodeRendererMain extends Disposable {
|
@@ -204,6 +206,7 @@ class CodeRendererMain extends Disposable {
|
||||||
const channel = connection.getChannel<IChannel>(REMOTE_FILE_SYSTEM_CHANNEL_NAME);
|
const channel = connection.getChannel<IChannel>(REMOTE_FILE_SYSTEM_CHANNEL_NAME);
|
||||||
const remoteFileSystemProvider = this._register(new RemoteExtensionsFileSystemProvider(channel, remoteAgentService.getEnvironment()));
|
const remoteFileSystemProvider = this._register(new RemoteExtensionsFileSystemProvider(channel, remoteAgentService.getEnvironment()));
|
||||||
|
|
104
src/api.ts
104
src/api.ts
|
@ -1,3 +1,4 @@
|
||||||
|
import * as vscode from "vscode";
|
||||||
import { createCSSRule } from "vs/base/browser/dom";
|
import { createCSSRule } from "vs/base/browser/dom";
|
||||||
import { Emitter, Event } from "vs/base/common/event";
|
import { Emitter, Event } from "vs/base/common/event";
|
||||||
import { IDisposable } from "vs/base/common/lifecycle";
|
import { IDisposable } from "vs/base/common/lifecycle";
|
||||||
|
@ -13,6 +14,7 @@ import { IInstantiationService, ServiceIdentifier } from "vs/platform/instantiat
|
||||||
import { ServiceCollection } from "vs/platform/instantiation/common/serviceCollection";
|
import { ServiceCollection } from "vs/platform/instantiation/common/serviceCollection";
|
||||||
import { INotificationService } from "vs/platform/notification/common/notification";
|
import { INotificationService } from "vs/platform/notification/common/notification";
|
||||||
import { Registry } from "vs/platform/registry/common/platform";
|
import { Registry } from "vs/platform/registry/common/platform";
|
||||||
|
import { IStatusbarEntry, IStatusbarEntryAccessor, IStatusbarService, StatusbarAlignment } from "vs/platform/statusbar/common/statusbar";
|
||||||
import { IStorageService } from "vs/platform/storage/common/storage";
|
import { IStorageService } from "vs/platform/storage/common/storage";
|
||||||
import { ITelemetryService } from "vs/platform/telemetry/common/telemetry";
|
import { ITelemetryService } from "vs/platform/telemetry/common/telemetry";
|
||||||
import { IThemeService } from "vs/platform/theme/common/themeService";
|
import { IThemeService } from "vs/platform/theme/common/themeService";
|
||||||
|
@ -28,7 +30,6 @@ import { IEditorService } from "vs/workbench/services/editor/common/editorServic
|
||||||
import { IExtensionService } from "vs/workbench/services/extensions/common/extensions";
|
import { IExtensionService } from "vs/workbench/services/extensions/common/extensions";
|
||||||
import { IWorkbenchLayoutService } from "vs/workbench/services/layout/browser/layoutService";
|
import { IWorkbenchLayoutService } from "vs/workbench/services/layout/browser/layoutService";
|
||||||
import { IViewletService } from "vs/workbench/services/viewlet/browser/viewlet";
|
import { IViewletService } from "vs/workbench/services/viewlet/browser/viewlet";
|
||||||
import * as vscode from "vscode";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Client-side implementation of VS Code's API.
|
* Client-side implementation of VS Code's API.
|
||||||
|
@ -42,6 +43,7 @@ export const vscodeApi = (serviceCollection: ServiceCollection): Partial<typeof
|
||||||
const notificationService = getService(INotificationService);
|
const notificationService = getService(INotificationService);
|
||||||
const fileService = getService(IFileService);
|
const fileService = getService(IFileService);
|
||||||
const viewsRegistry = Registry.as<IViewsRegistry>(ViewsExtensions.ViewsRegistry);
|
const viewsRegistry = Registry.as<IViewsRegistry>(ViewsExtensions.ViewsRegistry);
|
||||||
|
const statusbarService = getService(IStatusbarService);
|
||||||
|
|
||||||
// It would be nice to just export what VS Code creates but it looks to me
|
// It would be nice to just export what VS Code creates but it looks to me
|
||||||
// that it assumes it's running in the extension host and wouldn't work here.
|
// that it assumes it's running in the extension host and wouldn't work here.
|
||||||
|
@ -52,8 +54,10 @@ export const vscodeApi = (serviceCollection: ServiceCollection): Partial<typeof
|
||||||
EventEmitter: Emitter,
|
EventEmitter: Emitter,
|
||||||
TreeItemCollapsibleState: extHostTypes.TreeItemCollapsibleState,
|
TreeItemCollapsibleState: extHostTypes.TreeItemCollapsibleState,
|
||||||
FileSystemError: extHostTypes.FileSystemError,
|
FileSystemError: extHostTypes.FileSystemError,
|
||||||
FileType: FileType,
|
FileType,
|
||||||
Uri: URI,
|
Uri: URI,
|
||||||
|
StatusBarAlignment,
|
||||||
|
ThemeColor,
|
||||||
commands: {
|
commands: {
|
||||||
executeCommand: <T = any>(commandId: string, ...args: any[]): Promise<T | undefined> => {
|
executeCommand: <T = any>(commandId: string, ...args: any[]): Promise<T | undefined> => {
|
||||||
return commandService.executeCommand(commandId, ...args);
|
return commandService.executeCommand(commandId, ...args);
|
||||||
|
@ -63,6 +67,9 @@ export const vscodeApi = (serviceCollection: ServiceCollection): Partial<typeof
|
||||||
},
|
},
|
||||||
} as Partial<typeof vscode.commands>,
|
} as Partial<typeof vscode.commands>,
|
||||||
window: {
|
window: {
|
||||||
|
createStatusBarItem: (alignment?: vscode.StatusBarAlignment, priority?: number): vscode.StatusBarItem => {
|
||||||
|
return new StatusBarEntry(statusbarService, alignment, priority);
|
||||||
|
},
|
||||||
registerTreeDataProvider: <T>(id: string, dataProvider: vscode.TreeDataProvider<T>): IDisposable => {
|
registerTreeDataProvider: <T>(id: string, dataProvider: vscode.TreeDataProvider<T>): IDisposable => {
|
||||||
const tree = new TreeViewDataProvider(dataProvider);
|
const tree = new TreeViewDataProvider(dataProvider);
|
||||||
const view = viewsRegistry.getView(id);
|
const view = viewsRegistry.getView(id);
|
||||||
|
@ -267,3 +274,96 @@ class TreeViewDataProvider<T> implements ITreeViewDataProvider {
|
||||||
: `coder-tree-item-uuid/${generateUuid()}`;
|
: `coder-tree-item-uuid/${generateUuid()}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ThemeColor {
|
||||||
|
public id: string;
|
||||||
|
constructor(id: string) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface IStatusBarEntry extends IStatusbarEntry {
|
||||||
|
alignment: StatusbarAlignment;
|
||||||
|
priority?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum StatusBarAlignment {
|
||||||
|
Left = 1,
|
||||||
|
Right = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
class StatusBarEntry implements vscode.StatusBarItem {
|
||||||
|
private static ID = 0;
|
||||||
|
|
||||||
|
private _id: number;
|
||||||
|
private entry: IStatusBarEntry;
|
||||||
|
private _visible: boolean;
|
||||||
|
private disposed: boolean;
|
||||||
|
private statusId: string;
|
||||||
|
private statusName: string;
|
||||||
|
private accessor?: IStatusbarEntryAccessor;
|
||||||
|
private timeout: any;
|
||||||
|
|
||||||
|
constructor(private readonly statusbarService: IStatusbarService, alignment?: vscode.StatusBarAlignment, priority?: number) {
|
||||||
|
this._id = StatusBarEntry.ID--;
|
||||||
|
this.statusId = "web-api";
|
||||||
|
this.statusName = "Web API";
|
||||||
|
this.entry = {
|
||||||
|
alignment: alignment && alignment === StatusBarAlignment.Left
|
||||||
|
? StatusbarAlignment.LEFT : StatusbarAlignment.RIGHT,
|
||||||
|
text: "",
|
||||||
|
priority,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public get alignment(): vscode.StatusBarAlignment {
|
||||||
|
return this.entry.alignment === StatusbarAlignment.LEFT
|
||||||
|
? StatusBarAlignment.Left : StatusBarAlignment.Right;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get id(): number { return this._id; }
|
||||||
|
public get priority(): number | undefined { return this.entry.priority; }
|
||||||
|
public get text(): string { return this.entry.text; }
|
||||||
|
public get tooltip(): string | undefined { return this.entry.tooltip; }
|
||||||
|
public get color(): string | ThemeColor | undefined { return this.entry.color; }
|
||||||
|
public get command(): string | undefined { return this.entry.command; }
|
||||||
|
|
||||||
|
public set text(text: string) { this.update({ text }); }
|
||||||
|
public set tooltip(tooltip: string | undefined) { this.update({ tooltip }); }
|
||||||
|
public set color(color: string | ThemeColor | undefined) { this.update({ color }); }
|
||||||
|
public set command(command: string | undefined) { this.update({ command }); }
|
||||||
|
|
||||||
|
public show(): void {
|
||||||
|
this._visible = true;
|
||||||
|
this.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
public hide(): void {
|
||||||
|
clearTimeout(this.timeout);
|
||||||
|
this._visible = false;
|
||||||
|
if (this.accessor) {
|
||||||
|
this.accessor.dispose();
|
||||||
|
this.accessor = undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private update(values?: Partial<IStatusBarEntry>): void {
|
||||||
|
this.entry = { ...this.entry, ...values };
|
||||||
|
if (this.disposed || !this._visible) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
clearTimeout(this.timeout);
|
||||||
|
this.timeout = setTimeout(() => {
|
||||||
|
if (!this.accessor) {
|
||||||
|
this.accessor = this.statusbarService.addEntry(this.entry, this.statusId, this.statusName, this.entry.alignment, this.priority);
|
||||||
|
} else {
|
||||||
|
this.accessor.update(this.entry);
|
||||||
|
}
|
||||||
|
}, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public dispose(): void {
|
||||||
|
this.hide();
|
||||||
|
this.disposed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue