Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to hide git sync button in status bar #70536

Merged
merged 1 commit into from
Aug 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions extensions/git/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions extensions/git/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
20 changes: 18 additions & 2 deletions extensions/git/src/statusbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -39,6 +39,7 @@ class CheckoutStatusBar {
}

interface SyncStatusBarState {
isEnabled: boolean;
isSyncRunning: boolean;
hasRemotes: boolean;
HEAD: Branch | undefined;
Expand All @@ -47,6 +48,7 @@ interface SyncStatusBarState {
class SyncStatusBar {

private static StartState: SyncStatusBarState = {
isEnabled: true,
isSyncRunning: false,
hasRemotes: false,
HEAD: undefined
Expand All @@ -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 };
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joshleeb are you think about this suggestion? Without this one if isn't simpler?

this.state = { ... this.state, isEnabled: isEnabled };

}

private onOperationsChange(): void {
const isSyncRunning = this.repository.operations.isRunning(Operation.Sync) ||
this.repository.operations.isRunning(Operation.Push) ||
Expand All @@ -86,7 +102,7 @@ class SyncStatusBar {
}

get command(): Command | undefined {
if (!this.state.hasRemotes) {
if (!this.state.isEnabled || !this.state.hasRemotes) {
return undefined;
}

Expand Down