From 05ed3df9b8066c1ecf792cb6ce621c44f6e3bf66 Mon Sep 17 00:00:00 2001 From: Josh Leeb-du Toit Date: Fri, 15 Mar 2019 16:33:05 +1100 Subject: [PATCH] Add option to hide git sync button in status bar This PR adds the option `git.statusBarSync.enabled` which when set to `false` will hide the `SyncStatusBar` icon that is, by default, visible in the status bar. --- extensions/git/package.json | 5 +++++ extensions/git/package.nls.json | 1 + extensions/git/src/statusbar.ts | 20 ++++++++++++++++++-- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/extensions/git/package.json b/extensions/git/package.json index b6f31076e76a5..6a5c93314d0ca 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -1149,6 +1149,11 @@ "default": true, "description": "%config.decorations.enabled%" }, + "git.statusBarSync.enabled": { + "type": "boolean", + "default": true, + "description": "%config.statusBarSync.enabled%" + }, "git.promptToSaveFilesBeforeCommit": { "type": "boolean", "scope": "resource", diff --git a/extensions/git/package.nls.json b/extensions/git/package.nls.json index 21ac86d8fbda2..53b22c8f72145 100644 --- a/extensions/git/package.nls.json +++ b/extensions/git/package.nls.json @@ -91,6 +91,7 @@ "config.enableCommitSigning": "Enables commit signing with GPG.", "config.discardAllScope": "Controls what changes are discarded by the `Discard all changes` command. `all` discards all changes. `tracked` discards only tracked files. `prompt` shows a prompt dialog every time the action is run.", "config.decorations.enabled": "Controls whether Git contributes colors and badges to the explorer and the open editors view.", + "config.statusBarSync.enabled": "Controls whether Git sync appears in the status bar.", "config.promptToSaveFilesBeforeCommit": "Controls whether Git should check for unsaved files before committing.", "config.postCommitCommand": "Runs a git command after a successful commit.", "config.postCommitCommand.none": "Don't run any command after a commit.", diff --git a/extensions/git/src/statusbar.ts b/extensions/git/src/statusbar.ts index cc007172d5f7b..e89e1ff9c9b11 100644 --- a/extensions/git/src/statusbar.ts +++ b/extensions/git/src/statusbar.ts @@ -5,7 +5,7 @@ import { Disposable, Command, EventEmitter, Event, workspace, Uri } from 'vscode'; import { Repository, Operation } from './repository'; -import { anyEvent, dispose } from './util'; +import { anyEvent, dispose, filterEvent } from './util'; import * as nls from 'vscode-nls'; import { Branch } from './api/git'; @@ -39,6 +39,7 @@ class CheckoutStatusBar { } interface SyncStatusBarState { + isEnabled: boolean; isSyncRunning: boolean; hasRemotes: boolean; HEAD: Branch | undefined; @@ -47,6 +48,7 @@ interface SyncStatusBarState { class SyncStatusBar { private static StartState: SyncStatusBarState = { + isEnabled: true, isSyncRunning: false, hasRemotes: false, HEAD: undefined @@ -66,9 +68,23 @@ class SyncStatusBar { constructor(private repository: Repository) { repository.onDidRunGitStatus(this.onModelChange, this, this.disposables); repository.onDidChangeOperations(this.onOperationsChange, this, this.disposables); + + const onEnablementChange = filterEvent(workspace.onDidChangeConfiguration, e => e.affectsConfiguration('git.statusBarSync.enabled')); + onEnablementChange(this.updateEnablement, this, this.disposables); + this._onDidChange.fire(); } + private updateEnablement(): void { + const isEnabled = workspace.getConfiguration('git').get('statusBarSync.enabled'); + + if (isEnabled) { + this.state = { ... this.state, isEnabled: true }; + } else { + this.state = { ... this.state, isEnabled: false }; + } + } + private onOperationsChange(): void { const isSyncRunning = this.repository.operations.isRunning(Operation.Sync) || this.repository.operations.isRunning(Operation.Push) || @@ -86,7 +102,7 @@ class SyncStatusBar { } get command(): Command | undefined { - if (!this.state.hasRemotes) { + if (!this.state.isEnabled || !this.state.hasRemotes) { return undefined; }