Skip to content

Commit

Permalink
vscode: added enabled support for SourceControlInputBox (#12069)
Browse files Browse the repository at this point in the history
The commit adds support for the `enabled` property for `SourceControlInputBox`.

Signed-off-by: Jonah Iden <jonah.iden@typefox.io>
  • Loading branch information
jonah-iden authored Jan 16, 2023
1 parent 056dca7 commit aca9a26
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/plugin-ext/src/common/plugin-api-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,7 @@ export interface ScmMain {
$setInputBoxValue(sourceControlHandle: number, value: string): void;
$setInputBoxPlaceholder(sourceControlHandle: number, placeholder: string): void;
$setInputBoxVisible(sourceControlHandle: number, visible: boolean): void;
$setInputBoxEnabled(sourceControlHandle: number, enabled: boolean): void;
}

export interface SourceControlProviderFeatures {
Expand Down
10 changes: 10 additions & 0 deletions packages/plugin-ext/src/main/browser/scm-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,4 +440,14 @@ export class ScmMainImpl implements ScmMain {

repository.input.visible = visible;
}

$setInputBoxEnabled(sourceControlHandle: number, enabled: boolean): void {
const repository = this.repositories.get(sourceControlHandle);

if (!repository) {
return;
}

repository.input.enabled = enabled;
}
}
11 changes: 11 additions & 0 deletions packages/plugin-ext/src/plugin/scm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,17 @@ export class ScmInputBoxImpl implements theia.SourceControlInputBox {
this._visible = visible;
}

private _enabled: boolean;

get enabled(): boolean {
return this._enabled;
}

set enabled(enabled: boolean) {
this.proxy.$setInputBoxEnabled(this.sourceControlHandle, enabled);
this._enabled = enabled;
}

private _validateInput: ValidateInput | undefined;

get validateInput(): ValidateInput | undefined {
Expand Down
5 changes: 5 additions & 0 deletions packages/plugin/src/theia.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10831,6 +10831,11 @@ export module '@theia/plugin' {
* Controls whether the input box is visible (default is true).
*/
visible: boolean;

/**
* Controls whether the input box is enabled (default is `true`).
*/
enabled: boolean;
}

interface QuickDiffProvider {
Expand Down
1 change: 1 addition & 0 deletions packages/scm/src/browser/scm-commit-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export class ScmCommitWidget extends ReactWidget implements StatefulWidget {
spellCheck={false}
autoFocus={true}
value={input.value}
disabled={!input.enabled}
onChange={this.setInputValue}
ref={this.inputRef}
rows={1}
Expand Down
24 changes: 19 additions & 5 deletions packages/scm/src/browser/scm-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ export interface ScmInputValidator {
}

export interface ScmInputOptions {
placeholder?: string
validator?: ScmInputValidator
visible?: boolean
placeholder?: string;
validator?: ScmInputValidator;
visible?: boolean;
enabled?: boolean;
}

export interface ScmInputData {
value?: string
issue?: ScmInputIssue
value?: string;
issue?: ScmInputIssue;
}

export class ScmInput implements Disposable {
Expand Down Expand Up @@ -108,6 +109,19 @@ export class ScmInput implements Disposable {
this.validate();
}

protected _enabled = this.options.enabled ?? true;
get enabled(): boolean {
return this._enabled;
}
set enabled(enabled: boolean) {
if (this._enabled === enabled) {
return;
}
this._enabled = enabled;
this.fireDidChange();
this.validate();
}

protected _issue: ScmInputIssue | undefined;
get issue(): ScmInputIssue | undefined {
return this._issue;
Expand Down

0 comments on commit aca9a26

Please sign in to comment.