提交 7b4bb1ed 编写于 作者: J Joao Moreno

Merge branch 'commit-counter' of https://github.com/jayjun/vscode into jayjun-commit-counter

......@@ -519,6 +519,7 @@ export class Repository implements Disposable {
this._sourceControl.inputBox.placeholder = localize('commitMessage', "Message (press {0} to commit)");
this._sourceControl.acceptInputCommand = { command: 'git.commitWithInput', title: localize('commit', "Commit"), arguments: [this._sourceControl] };
this._sourceControl.quickDiffProvider = this;
this._sourceControl.inputBox.warningLength = 72;
this.disposables.push(this._sourceControl);
this._mergeGroup = this._sourceControl.createResourceGroup('merge', localize('merge changes', "Merge Changes"));
......
......@@ -5782,6 +5782,11 @@ declare module 'vscode' {
* A string to show as place holder in the input box to guide the user.
*/
placeholder: string;
/**
* The warning threshold for commit messages.
*/
warningLength: number | undefined;
}
interface QuickDiffProvider {
......
......@@ -391,4 +391,14 @@ export class MainThreadSCM implements MainThreadSCMShape {
repository.input.placeholder = placeholder;
}
$setWarningLength(sourceControlHandle: number, warningLength: number): void {
const repository = this._repositories[sourceControlHandle];
if (!repository) {
return;
}
repository.input.warningLength = warningLength;
}
}
......@@ -410,6 +410,7 @@ export interface MainThreadSCMShape extends IDisposable {
$setInputBoxValue(sourceControlHandle: number, value: string): void;
$setInputBoxPlaceholder(sourceControlHandle: number, placeholder: string): void;
$setWarningLength(sourceControlHandle: number, warningLength: number): void;
}
export type DebugSessionUUID = string;
......
......@@ -110,7 +110,7 @@ function compareResourceStates(a: vscode.SourceControlResourceState, b: vscode.S
return result;
}
export class ExtHostSCMInputBox {
export class ExtHostSCMInputBox implements vscode.SourceControlInputBox {
private _value: string = '';
......@@ -140,6 +140,17 @@ export class ExtHostSCMInputBox {
this._placeholder = placeholder;
}
private _warningLength: number | undefined;
get warningLength(): number | undefined {
return this._warningLength;
}
set warningLength(warningLength: number) {
this._proxy.$setWarningLength(this._sourceControlHandle, warningLength);
this._warningLength = warningLength;
}
constructor(private _proxy: MainThreadSCMShape, private _sourceControlHandle: number) {
// noop
}
......
......@@ -45,7 +45,7 @@ import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace
import { IStorageService } from 'vs/platform/storage/common/storage';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { IExtensionsViewlet, VIEWLET_ID as EXTENSIONS_VIEWLET_ID } from 'vs/workbench/parts/extensions/common/extensions';
import { InputBox } from 'vs/base/browser/ui/inputbox/inputBox';
import { IMessage, InputBox, MessageType } from 'vs/base/browser/ui/inputbox/inputBox';
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
import { Command } from 'vs/editor/common/modes';
......@@ -753,7 +753,33 @@ export class RepositoryPanel extends ViewletPanel {
this.inputBox.setPlaceHolder(placeholder);
};
this.inputBox = new InputBox(this.inputBoxContainer, this.contextViewService, { flexibleHeight: true });
const validation = (text: string): IMessage => {
const warningLength = this.repository.input.warningLength;
if (warningLength === undefined) {
return {
content: localize('commitMessageInfo', "{0} characters", text.length),
type: MessageType.INFO
};
}
const charactersLeft = warningLength - text.length;
if (charactersLeft > 0) {
return {
content: localize('commitMessageCountdown', "{0} characters left", text.length),
type: MessageType.INFO
};
} else {
return {
content: localize('commitMessageWarning', "{0} characters over", text.length),
type: MessageType.WARNING
};
}
};
this.inputBox = new InputBox(this.inputBoxContainer, this.contextViewService, {
flexibleHeight: true,
validationOptions: { validation: validation }
});
this.disposables.push(attachInputBoxStyler(this.inputBox, this.themeService));
this.disposables.push(this.inputBox);
......
......@@ -74,6 +74,8 @@ export interface ISCMInput {
placeholder: string;
readonly onDidChangePlaceholder: Event<string>;
warningLength: number | undefined;
}
export interface ISCMRepository extends IDisposable {
......
......@@ -39,6 +39,16 @@ class SCMInput implements ISCMInput {
private _onDidChangePlaceholder = new Emitter<string>();
get onDidChangePlaceholder(): Event<string> { return this._onDidChangePlaceholder.event; }
private _warningLength: number | undefined;
get warningLength(): number | undefined {
return this._warningLength;
}
set warningLength(warningLength: number) {
this._warningLength = warningLength;
}
}
class SCMRepository implements ISCMRepository {
......@@ -106,4 +116,4 @@ export class SCMService implements ISCMService {
return repository;
}
}
\ No newline at end of file
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册