提交 fe137a20 编写于 作者: C Christof Marti

Fixes #12534: Show useful commands in watermark

上级 477cfc42
......@@ -21,6 +21,7 @@ import {IContextKeyService} from 'vs/platform/contextkey/common/contextkey';
import {KeybindingsRegistry} from 'vs/platform/keybinding/common/keybindingsRegistry';
import {IStatusbarService} from 'vs/platform/statusbar/common/statusbar';
import {IMessageService} from 'vs/platform/message/common/message';
import Event, {Emitter} from 'vs/base/common/event';
export abstract class KeybindingService implements IKeybindingService {
public _serviceBrand: any;
......@@ -31,6 +32,7 @@ export abstract class KeybindingService implements IKeybindingService {
private _firstTimeComputingResolver: boolean;
private _currentChord: number;
private _currentChordStatusMessage: IDisposable;
private _onDidUpdateKeybindings: Emitter<void>;
private _contextKeyService: IContextKeyService;
protected _commandService: ICommandService;
......@@ -52,6 +54,8 @@ export abstract class KeybindingService implements IKeybindingService {
this._firstTimeComputingResolver = true;
this._currentChord = 0;
this._currentChordStatusMessage = null;
this._onDidUpdateKeybindings = new Emitter<void>();
this.toDispose.push(this._onDidUpdateKeybindings);
}
public dispose(): void {
......@@ -73,6 +77,10 @@ export abstract class KeybindingService implements IKeybindingService {
return this._cachedResolver;
}
get onDidUpdateKeybindings(): Event<void> {
return this._onDidUpdateKeybindings ? this._onDidUpdateKeybindings.event : Event.None; // Sinon stubbing walks properties on prototype
}
public getLabelFor(keybinding: Keybinding): string {
return keybinding._toUSLabel();
}
......@@ -89,8 +97,9 @@ export abstract class KeybindingService implements IKeybindingService {
return keybinding._toElectronAccelerator();
}
protected updateResolver(): void {
protected updateResolver(): void {
this._cachedResolver = null;
this._onDidUpdateKeybindings.fire();
}
protected _getExtraKeybindings(isFirstTime: boolean): IKeybindingItem[] {
......
......@@ -8,6 +8,7 @@ import {IHTMLContentElement} from 'vs/base/common/htmlContent';
import {Keybinding} from 'vs/base/common/keybinding';
import {createDecorator} from 'vs/platform/instantiation/common/instantiation';
import {ContextKeyExpr} from 'vs/platform/contextkey/common/contextkey';
import Event from 'vs/base/common/event';
export interface IUserFriendlyKeybinding {
key: string;
......@@ -45,6 +46,8 @@ export let IKeybindingService = createDecorator<IKeybindingService>('keybindingS
export interface IKeybindingService {
_serviceBrand: any;
onDidUpdateKeybindings: Event<void>;
getLabelFor(keybinding: Keybinding): string;
getAriaLabelFor(keybinding: Keybinding): string;
getHTMLLabelFor(keybinding: Keybinding): IHTMLContentElement[];
......
......@@ -62,6 +62,10 @@ export class MockKeybindingService implements IContextKeyService {
export class MockKeybindingService2 implements IKeybindingService {
public _serviceBrand: any;
public get onDidUpdateKeybindings(): Event<void> {
return Event.None;
}
public getLabelFor(keybinding: Keybinding): string {
return keybinding._toUSLabel();
}
......
......@@ -18,6 +18,8 @@ export interface ITelemetryInfo {
export interface ITelemetryExperiments {
showDefaultViewlet: boolean;
showCommandsWatermark: boolean;
openUntitledFile: boolean;
}
export interface ITelemetryService {
......@@ -38,7 +40,9 @@ export interface ITelemetryService {
}
export const defaultExperiments: ITelemetryExperiments = {
showDefaultViewlet: false
showDefaultViewlet: false,
showCommandsWatermark: false,
openUntitledFile: true
};
export const NullTelemetryService = {
......@@ -67,12 +71,23 @@ export function loadExperiments(storageService: IStorageService): ITelemetryExpe
valueString = Math.random().toString();
storageService.store(key, valueString);
}
const value = parseFloat(valueString);
const random0 = parseFloat(valueString);
const [random1, showDefaultViewlet] = splitRandom(random0);
const [random2, showCommandsWatermark] = splitRandom(random1);
const [, openUntitledFile] = splitRandom(random2);
return {
showDefaultViewlet: value < 0.5
showDefaultViewlet,
showCommandsWatermark,
openUntitledFile
};
}
function splitRandom(random: number): [number, boolean] {
const scaled = random * 2;
const i = Math.floor(scaled);
return [scaled - i, i === 1];
}
export interface ITelemetryAppender {
log(eventName: string, data: any): void;
}
......
......@@ -74,6 +74,7 @@ import {MenuService} from 'vs/platform/actions/common/menuService';
import {IContextMenuService} from 'vs/platform/contextview/browser/contextView';
import {IEnvironmentService} from 'vs/platform/environment/common/environment';
import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry';
import * as watermark from 'vs/workbench/parts/watermark/watermark';
export const MessagesVisibleContext = new RawContextKey<boolean>('globalMessageVisible', false);
export const EditorsVisibleContext = new RawContextKey<boolean>('editorIsOpen', false);
......@@ -322,7 +323,7 @@ export class Workbench implements IPartService {
}
// Empty workbench
else if (!this.workbenchParams.workspace) {
else if (!this.workbenchParams.workspace && this.telemetryService.getExperiments().openUntitledFile) {
return TPromise.as([{ input: this.untitledEditorService.createOrGet() }]);
}
......@@ -780,6 +781,10 @@ export class Workbench implements IPartService {
role: 'main'
});
if (this.telemetryService.getExperiments().showCommandsWatermark) {
this.toDispose.push(watermark.create(editorContainer, this.keybindingService));
}
this.editorPart.create(editorContainer);
}
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
.monaco-workbench > .part.editor > .watermark {
position: absolute;
width: 100%;
bottom: 10%;
}
.monaco-workbench > .part.editor > .watermark dl {
width: 100%;
}
.monaco-workbench > .part.editor > .watermark dt {
clear: left;
float: left;
width: 49%;
margin: 0 1% 0 0;
text-align: right;
}
.monaco-workbench > .part.editor > .watermark dd {
float: left;
width: 49%;
margin: 0 0 0 1%;
text-align: left;
}
.monaco-workbench > .part.editor > .watermark dt {
color: #2B91AF;
}
.monaco-workbench > .part.editor > .watermark dl {
color: #2B91AF;
}
.vs-dark .monaco-workbench > .part.editor > .watermark dt {
color: #5A5A5A;
}
.vs-dark .monaco-workbench > .part.editor > .watermark dl {
color: #5A5A5A;
}
.hc-black .monaco-workbench > .part.editor > .watermark dt {
color: #FFF;
}
.hc-black .monaco-workbench > .part.editor > .watermark dl {
color: #FFF;
}
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import 'vs/css!./watermark';
import {Builder, $} from 'vs/base/browser/builder';
import {IDisposable} from 'vs/base/common/lifecycle';
import {IKeybindingService} from 'vs/platform/keybinding/common/keybinding';
import * as nls from 'vs/nls';
const entries = [
{
text: nls.localize('watermark.showCommands', "Command Pallette"),
ids: ['workbench.action.showCommands']
},
{
text: nls.localize('watermark.quickOpen', "Open File in Folder"),
ids: ['workbench.action.quickOpen']
},
{
text: nls.localize('watermark.moveLines', "Move Lines Up/Down"),
ids: ['editor.action.moveLinesUpAction', 'editor.action.moveLinesDownAction']
},
{
text: nls.localize('watermark.addCursor', "Add Cursors Above/Below"),
ids: ['cursorColumnSelectUp', 'cursorColumnSelectDown']
},
{
text: nls.localize('watermark.toggleTerminal', "Toggle Terminal"),
ids: ['workbench.action.terminal.toggleTerminal']
},
];
const UNBOUND = nls.localize('watermark.unboundCommand', "unbound");
export function create(container: Builder, keybindingService: IKeybindingService): IDisposable {
const div = $(container)
.div({
'class': 'watermark',
});
function update() {
$(div).clearChildren()
.element('dl', {
}, dl => entries.map(entry => {
dl.element('dt', {}, dt => dt.text(entry.text));
dl.element('dd', {}, dd => dd.text(
entry.ids
.map(id => keybindingService.lookupKeybindings(id)
.map(k => keybindingService.getLabelFor(k))
.join(', ') || UNBOUND)
.join(' / ')
));
}));
}
update();
return keybindingService.onDidUpdateKeybindings(update);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册