Skip to content

Commit

Permalink
Changes to use decoration for default indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Mar 9, 2021
1 parent 3c57b6f commit 94bea80
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
10 changes: 4 additions & 6 deletions src/views/nodes/remoteNode.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { ThemeIcon, TreeItem, TreeItemCollapsibleState, Uri } from 'vscode';
import { BranchNode } from './branchNode';
import { BranchOrTagFolderNode } from './branchOrTagFolderNode';
import { MessageNode } from './common';
Expand Down Expand Up @@ -106,10 +106,7 @@ export class RemoteNode extends ViewNode<RemotesView | RepositoriesView> {
arrows = GlyphChars.Dash;
}

const item = new TreeItem(
`${this.remote.default ? `${GlyphChars.Check} ${GlyphChars.Space}` : ''}${this.remote.name}`,
TreeItemCollapsibleState.Collapsed,
);
const item = new TreeItem(this.remote.name, TreeItemCollapsibleState.Collapsed);

if (this.remote.provider != null) {
const { provider } = this.remote;
Expand All @@ -123,7 +120,7 @@ export class RemoteNode extends ViewNode<RemotesView | RepositoriesView> {
if (provider.hasApi()) {
const connected = provider.maybeConnected ?? (await provider.isConnected());

item.contextValue += `${ContextValues.Remote}${connected ? '+connected' : '+disconnected'}`;
item.contextValue = `${ContextValues.Remote}${connected ? '+connected' : '+disconnected'}`;
item.tooltip = `${this.remote.name} (${provider.name} ${GlyphChars.Dash} ${
connected ? 'connected' : 'not connected'
})\n${provider.displayPath}\n`;
Expand All @@ -144,6 +141,7 @@ export class RemoteNode extends ViewNode<RemotesView | RepositoriesView> {

if (this.remote.default) {
item.contextValue += '+default';
item.resourceUri = Uri.parse('gitlens-view://remote/default');
}

item.id = this.id;
Expand Down
23 changes: 21 additions & 2 deletions src/views/viewDecorationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,17 @@ export class ViewFileDecorationProvider implements FileDecorationProvider, Dispo
// Register the current branch decorator separately (since we can only have 2 char's per decoration)
window.registerFileDecorationProvider({
provideFileDecoration: (uri, token) => {
if (uri.scheme !== 'gitlens-view' || uri.authority !== 'branch') return undefined;
if (uri.scheme !== 'gitlens-view') return undefined;

return this.provideBranchCurrentDecoration(uri, token);
if (uri.authority === 'branch') {
return this.provideBranchCurrentDecoration(uri, token);
}

if (uri.authority === 'remote') {
return this.provideRemoteDefaultDecoration(uri, token);
}

return undefined;
},
}),
window.registerFileDecorationProvider(this),
Expand Down Expand Up @@ -171,4 +179,15 @@ export class ViewFileDecorationProvider implements FileDecorationProvider, Dispo
tooltip: 'Current Branch',
};
}

provideRemoteDefaultDecoration(uri: Uri, _token: CancellationToken): FileDecoration | undefined {
const [, isDefault] = uri.path.split('/');

if (!isDefault) return undefined;

return {
badge: GlyphChars.Check,
tooltip: 'Default Remote',
};
}
}

0 comments on commit 94bea80

Please sign in to comment.