mirror of
https://github.com/Microsoft/vscode
synced 2024-08-28 05:19:39 +00:00
SCM - adopt observables for commitTemplate (#214021)
This commit is contained in:
parent
af1bd0264a
commit
11fd8ceab0
|
@ -25,6 +25,7 @@ import { IModelService } from 'vs/editor/common/services/model';
|
|||
import { ITextModelContentProvider, ITextModelService } from 'vs/editor/common/services/resolverService';
|
||||
import { Schemas } from 'vs/base/common/network';
|
||||
import { ITextModel } from 'vs/editor/common/model';
|
||||
import { observableValue } from 'vs/base/common/observable';
|
||||
|
||||
function getIconFromIconDto(iconDto?: UriComponents | { light: UriComponents; dark: UriComponents } | ThemeIcon): URI | { light: URI; dark: URI } | ThemeIcon | undefined {
|
||||
if (iconDto === undefined) {
|
||||
|
@ -224,7 +225,6 @@ class MainThreadSCMProvider implements ISCMProvider, QuickDiffProvider {
|
|||
get inputBoxTextModel(): ITextModel { return this._inputBoxTextModel; }
|
||||
get contextValue(): string { return this._providerId; }
|
||||
|
||||
get commitTemplate(): string { return this.features.commitTemplate || ''; }
|
||||
get historyProvider(): ISCMHistoryProvider | undefined { return this._historyProvider; }
|
||||
get acceptInputCommand(): Command | undefined { return this.features.acceptInputCommand; }
|
||||
get actionButton(): ISCMActionButtonDescriptor | undefined { return this.features.actionButton ?? undefined; }
|
||||
|
@ -234,8 +234,8 @@ class MainThreadSCMProvider implements ISCMProvider, QuickDiffProvider {
|
|||
private readonly _name: string | undefined;
|
||||
get name(): string { return this._name ?? this._label; }
|
||||
|
||||
private readonly _onDidChangeCommitTemplate = new Emitter<string>();
|
||||
readonly onDidChangeCommitTemplate: Event<string> = this._onDidChangeCommitTemplate.event;
|
||||
private readonly _commitTemplate = observableValue<string>(this, '');
|
||||
get commitTemplate() { return this._commitTemplate; }
|
||||
|
||||
private readonly _onDidChangeStatusBarCommands = new Emitter<readonly Command[]>();
|
||||
get onDidChangeStatusBarCommands(): Event<readonly Command[]> { return this._onDidChangeStatusBarCommands.event; }
|
||||
|
@ -277,7 +277,7 @@ class MainThreadSCMProvider implements ISCMProvider, QuickDiffProvider {
|
|||
this._onDidChange.fire();
|
||||
|
||||
if (typeof features.commitTemplate !== 'undefined') {
|
||||
this._onDidChangeCommitTemplate.fire(this.commitTemplate);
|
||||
this._commitTemplate.set(features.commitTemplate, undefined);
|
||||
}
|
||||
|
||||
if (typeof features.statusBarCommands !== 'undefined') {
|
||||
|
|
|
@ -109,6 +109,7 @@ import { IHoverService } from 'vs/platform/hover/browser/hover';
|
|||
import { OpenScmGroupAction } from 'vs/workbench/contrib/multiDiffEditor/browser/scmMultiDiffSourceResolver';
|
||||
import { HoverController } from 'vs/editor/contrib/hover/browser/hoverController';
|
||||
import { ITextModel } from 'vs/editor/common/model';
|
||||
import { autorun } from 'vs/base/common/observable';
|
||||
|
||||
// type SCMResourceTreeNode = IResourceNode<ISCMResource, ISCMResourceGroup>;
|
||||
// type SCMHistoryItemChangeResourceTreeNode = IResourceNode<SCMHistoryItemChangeTreeElement, SCMHistoryItemTreeElement>;
|
||||
|
@ -2352,24 +2353,21 @@ class SCMInputWidget {
|
|||
|
||||
// Update input template
|
||||
let commitTemplate = '';
|
||||
const updateTemplate = () => {
|
||||
if (typeof input.repository.provider.commitTemplate === 'undefined' || !input.visible) {
|
||||
this.repositoryDisposables.add(autorun(reader => {
|
||||
if (!input.visible) {
|
||||
return;
|
||||
}
|
||||
|
||||
const oldCommitTemplate = commitTemplate;
|
||||
commitTemplate = input.repository.provider.commitTemplate;
|
||||
commitTemplate = input.repository.provider.commitTemplate.read(reader);
|
||||
|
||||
const value = textModel.getValue();
|
||||
|
||||
if (value && value !== oldCommitTemplate) {
|
||||
return;
|
||||
}
|
||||
|
||||
textModel.setValue(commitTemplate);
|
||||
};
|
||||
this.repositoryDisposables.add(input.repository.provider.onDidChangeCommitTemplate(updateTemplate, this));
|
||||
updateTemplate();
|
||||
}));
|
||||
|
||||
// Update input enablement
|
||||
const updateEnablement = (enabled: boolean) => {
|
||||
|
|
|
@ -15,6 +15,7 @@ import { IMarkdownString } from 'vs/base/common/htmlContent';
|
|||
import { ResourceTree } from 'vs/base/common/resourceTree';
|
||||
import { ISCMHistoryProvider, ISCMHistoryProviderMenus } from 'vs/workbench/contrib/scm/common/history';
|
||||
import { ITextModel } from 'vs/editor/common/model';
|
||||
import { IObservable } from 'vs/base/common/observable';
|
||||
|
||||
export const VIEWLET_ID = 'workbench.view.scm';
|
||||
export const VIEW_PANE_ID = 'workbench.scm';
|
||||
|
@ -73,9 +74,8 @@ export interface ISCMProvider extends IDisposable {
|
|||
readonly rootUri?: URI;
|
||||
readonly inputBoxTextModel: ITextModel;
|
||||
readonly count?: number;
|
||||
readonly commitTemplate: string;
|
||||
readonly commitTemplate: IObservable<string>;
|
||||
readonly historyProvider?: ISCMHistoryProvider;
|
||||
readonly onDidChangeCommitTemplate: Event<string>;
|
||||
readonly onDidChangeHistoryProvider: Event<void>;
|
||||
readonly onDidChangeStatusBarCommands?: Event<readonly Command[]>;
|
||||
readonly acceptInputCommand?: Command;
|
||||
|
|
Loading…
Reference in a new issue