Skip to content

Commit

Permalink
Allow scc providers hide commit input box.
Browse files Browse the repository at this point in the history
Fix for #51808.
  • Loading branch information
Ilya Biryukov committed Oct 5, 2018
1 parent 1bf1bc2 commit 212aade
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 54 deletions.
5 changes: 5 additions & 0 deletions src/vs/vscode.proposed.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,11 @@ declare module 'vscode' {
* An event signaling when the selection state changes.
*/
readonly onDidChangeSelection: Event<boolean>;

/**
* Whether the input box is hidden.
*/
hideInputBox: boolean;
}

//#endregion
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/api/electron-browser/mainThreadSCM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class MainThreadSCMProvider implements ISCMProvider {
get acceptInputCommand(): Command | undefined { return this.features.acceptInputCommand; }
get statusBarCommands(): Command[] | undefined { return this.features.statusBarCommands; }
get count(): number | undefined { return this.features.count; }
get hideInputBox(): boolean | undefined { return this.features.hideInputBox; }

private _onDidChangeCommitTemplate = new Emitter<string>();
get onDidChangeCommitTemplate(): Event<string> { return this._onDidChangeCommitTemplate.event; }
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/api/node/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ export interface SCMProviderFeatures {
commitTemplate?: string;
acceptInputCommand?: modes.Command;
statusBarCommands?: modes.Command[];
hideInputBox?: boolean;
}

export interface SCMGroupFeatures {
Expand Down
11 changes: 11 additions & 0 deletions src/vs/workbench/api/node/extHostSCM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,17 @@ class ExtHostSourceControl implements vscode.SourceControl {
return this._selected;
}

private _hideInputBox: boolean = false;

get hideInputBox(): boolean {
return this._hideInputBox;
}

set hideInputBox(hideInputBox: boolean | undefined) {
this._hideInputBox = hideInputBox;
this._proxy.$updateSourceControl(this.handle, { hideInputBox: !!hideInputBox });
}

private _onDidChangeSelection = new Emitter<boolean>();
readonly onDidChangeSelection = this._onDidChangeSelection.event;

Expand Down
114 changes: 60 additions & 54 deletions src/vs/workbench/parts/scm/electron-browser/scmViewlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -816,57 +816,59 @@ export class RepositoryPanel extends ViewletPanel {
this.disposables.push(focusTracker);

// Input
this.inputBoxContainer = append(container, $('.scm-editor'));

const updatePlaceholder = () => {
const binding = this.keybindingService.lookupKeybinding('scm.acceptInput');
const label = binding ? binding.getLabel() : (platform.isMacintosh ? 'Cmd+Enter' : 'Ctrl+Enter');
const placeholder = format(this.repository.input.placeholder, label);

this.inputBox.setPlaceHolder(placeholder);
};

const validationDelayer = new ThrottledDelayer<any>(200);
const validate = () => {
return this.repository.input.validateInput(this.inputBox.value, this.inputBox.inputElement.selectionStart).then(result => {
if (!result) {
this.inputBox.inputElement.removeAttribute('aria-invalid');
this.inputBox.hideMessage();
} else {
this.inputBox.inputElement.setAttribute('aria-invalid', 'true');
this.inputBox.showMessage({ content: result.message, type: convertValidationType(result.type) });
}
});
};

const triggerValidation = () => validationDelayer.trigger(validate);

this.inputBox = new InputBox(this.inputBoxContainer, this.contextViewService, { flexibleHeight: true });
this.disposables.push(attachInputBoxStyler(this.inputBox, this.themeService));
this.disposables.push(this.inputBox);

this.inputBox.onDidChange(triggerValidation, null, this.disposables);

const onKeyUp = domEvent(this.inputBox.inputElement, 'keyup');
const onMouseUp = domEvent(this.inputBox.inputElement, 'mouseup');
anyEvent<any>(onKeyUp, onMouseUp)(triggerValidation, null, this.disposables);

this.inputBox.value = this.repository.input.value;
this.inputBox.onDidChange(value => this.repository.input.value = value, null, this.disposables);
this.repository.input.onDidChange(value => this.inputBox.value = value, null, this.disposables);

updatePlaceholder();
this.repository.input.onDidChangePlaceholder(updatePlaceholder, null, this.disposables);
this.keybindingService.onDidUpdateKeybindings(updatePlaceholder, null, this.disposables);

this.disposables.push(this.inputBox.onDidHeightChange(() => this.layoutBody()));
if (!this.repository.provider.hideInputBox) {
this.inputBoxContainer = append(container, $('.scm-editor'));

const updatePlaceholder = () => {
const binding = this.keybindingService.lookupKeybinding('scm.acceptInput');
const label = binding ? binding.getLabel() : (platform.isMacintosh ? 'Cmd+Enter' : 'Ctrl+Enter');
const placeholder = format(this.repository.input.placeholder, label);

this.inputBox.setPlaceHolder(placeholder);
};

const validationDelayer = new ThrottledDelayer<any>(200);
const validate = () => {
return this.repository.input.validateInput(this.inputBox.value, this.inputBox.inputElement.selectionStart).then(result => {
if (!result) {
this.inputBox.inputElement.removeAttribute('aria-invalid');
this.inputBox.hideMessage();
} else {
this.inputBox.inputElement.setAttribute('aria-invalid', 'true');
this.inputBox.showMessage({ content: result.message, type: convertValidationType(result.type) });
}
});
};

const triggerValidation = () => validationDelayer.trigger(validate);

this.inputBox = new InputBox(this.inputBoxContainer, this.contextViewService, { flexibleHeight: true });
this.disposables.push(attachInputBoxStyler(this.inputBox, this.themeService));
this.disposables.push(this.inputBox);

this.inputBox.onDidChange(triggerValidation, null, this.disposables);

const onKeyUp = domEvent(this.inputBox.inputElement, 'keyup');
const onMouseUp = domEvent(this.inputBox.inputElement, 'mouseup');
anyEvent<any>(onKeyUp, onMouseUp)(triggerValidation, null, this.disposables);

this.inputBox.value = this.repository.input.value;
this.inputBox.onDidChange(value => this.repository.input.value = value, null, this.disposables);
this.repository.input.onDidChange(value => this.inputBox.value = value, null, this.disposables);

updatePlaceholder();
this.repository.input.onDidChangePlaceholder(updatePlaceholder, null, this.disposables);
this.keybindingService.onDidUpdateKeybindings(updatePlaceholder, null, this.disposables);

this.disposables.push(this.inputBox.onDidHeightChange(() => this.layoutBody()));

if (this.repository.provider.onDidChangeCommitTemplate) {
this.repository.provider.onDidChangeCommitTemplate(this.updateInputBox, this, this.disposables);
}

if (this.repository.provider.onDidChangeCommitTemplate) {
this.repository.provider.onDidChangeCommitTemplate(this.updateInputBox, this, this.disposables);
this.updateInputBox();
}

this.updateInputBox();

// List

this.listContainer = append(container, $('.scm-status.show-file-icons'));
Expand Down Expand Up @@ -920,20 +922,24 @@ export class RepositoryPanel extends ViewletPanel {
}

this.cachedHeight = height;
this.inputBox.layout();
if (this.inputBox) {
this.inputBox.layout();
}

const editorHeight = this.inputBox.height;
const listHeight = height - (editorHeight + 12 /* margin */);
const editorHeight = this.inputBox ? this.inputBox.height : 0;
const listHeight = height - (editorHeight + (editorHeight ? 12 : 0) /* margin */);
this.listContainer.style.height = `${listHeight}px`;
this.list.layout(listHeight);

toggleClass(this.inputBoxContainer, 'scroll', editorHeight >= 134);
if (this.inputBoxContainer) {
toggleClass(this.inputBoxContainer, 'scroll', editorHeight >= 134);
}
}

focus(): void {
super.focus();

if (this.isExpanded()) {
if (this.isExpanded() && this.inputBox) {
this.inputBox.focus();
}
}
Expand Down Expand Up @@ -993,7 +999,7 @@ export class RepositoryPanel extends ViewletPanel {
}

private updateInputBox(): void {
if (typeof this.repository.provider.commitTemplate === 'undefined' || this.inputBox.value) {
if (typeof this.repository.provider.commitTemplate === 'undefined' || !this.inputBox || this.inputBox.value) {
return;
}

Expand Down
2 changes: 2 additions & 0 deletions src/vs/workbench/services/scm/common/scm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ export interface ISCMProvider extends IDisposable {
readonly statusBarCommands?: Command[];
readonly onDidChange: Event<void>;

readonly hideInputBox?: boolean | undefined;

getOriginalResource(uri: URI): TPromise<URI>;
}

Expand Down

0 comments on commit 212aade

Please sign in to comment.