Browse Source

Expands only the active or starred repos

Commits view will also expand repos with changes
main
Eric Amodio 4 years ago
parent
commit
2d73fccfe3
3 changed files with 33 additions and 6 deletions
  1. +16
    -0
      src/git/gitService.ts
  2. +9
    -4
      src/views/commitsView.ts
  3. +8
    -2
      src/views/nodes/viewNode.ts

+ 16
- 0
src/git/gitService.ts View File

@ -3427,6 +3427,22 @@ export class GitService implements Disposable {
return repository.hasTrackingBranch(); return repository.hasTrackingBranch();
} }
@log({
args: {
1: (editor: TextEditor) =>
editor != null ? `TextEditor(${Logger.toLoggable(editor.document.uri)})` : 'undefined',
},
})
async isActiveRepoPath(repoPath: string | undefined, editor?: TextEditor): Promise<boolean> {
if (repoPath == null) return false;
editor = editor ?? window.activeTextEditor;
if (editor == null) return false;
const doc = await Container.tracker.getOrAdd(editor.document.uri);
return repoPath === doc?.uri.repoPath;
}
isTrackable(scheme: string): boolean; isTrackable(scheme: string): boolean;
isTrackable(uri: Uri): boolean; isTrackable(uri: Uri): boolean;
isTrackable(schemeOruri: string | Uri): boolean { isTrackable(schemeOruri: string | Uri): boolean {

+ 9
- 4
src/views/commitsView.ts View File

@ -67,13 +67,18 @@ export class CommitsRepositoryNode extends RepositoryFolderNode
async getTreeItem(): Promise<TreeItem> { async getTreeItem(): Promise<TreeItem> {
this.splatted = false; this.splatted = false;
const branch = await this.repo.getBranch();
let expand = this.repo.starred;
const [active, branch] = await Promise.all([
expand ? undefined : Container.git.isActiveRepoPath(this.uri.repoPath),
this.repo.getBranch(),
]);
if (!expand && (active || (branch?.state.ahead ?? 0) > 0 || (branch?.state.behind ?? 0) > 0)) {
expand = true;
}
const item = new TreeItem( const item = new TreeItem(
this.repo.formattedName ?? this.uri.repoPath ?? '', this.repo.formattedName ?? this.uri.repoPath ?? '',
(branch?.state.ahead ?? 0) > 0 || (branch?.state.behind ?? 0) > 0
? TreeItemCollapsibleState.Expanded
: TreeItemCollapsibleState.Collapsed,
expand ? TreeItemCollapsibleState.Expanded : TreeItemCollapsibleState.Collapsed,
); );
item.contextValue = `${ContextValues.RepositoryFolder}${this.repo.starred ? '+starred' : ''}`; item.contextValue = `${ContextValues.RepositoryFolder}${this.repo.starred ? '+starred' : ''}`;

+ 8
- 2
src/views/nodes/viewNode.ts View File

@ -1,5 +1,6 @@
'use strict'; 'use strict';
import { Command, Disposable, Event, TreeItem, TreeItemCollapsibleState, TreeViewVisibilityChangeEvent } from 'vscode'; import { Command, Disposable, Event, TreeItem, TreeItemCollapsibleState, TreeViewVisibilityChangeEvent } from 'vscode';
import { Container } from '../../container';
import { import {
GitFile, GitFile,
GitReference, GitReference,
@ -322,12 +323,17 @@ export abstract class RepositoryFolderNode<
return RepositoryFolderNode.getId(this.repo.path); return RepositoryFolderNode.getId(this.repo.path);
} }
getTreeItem(): TreeItem | Promise<TreeItem> {
async getTreeItem(): Promise<TreeItem> {
this.splatted = false; this.splatted = false;
let expand = this.repo.starred;
if (!expand) {
expand = await Container.git.isActiveRepoPath(this.uri.repoPath);
}
const item = new TreeItem( const item = new TreeItem(
this.repo.formattedName ?? this.uri.repoPath ?? '', this.repo.formattedName ?? this.uri.repoPath ?? '',
TreeItemCollapsibleState.Expanded,
expand ? TreeItemCollapsibleState.Expanded : TreeItemCollapsibleState.Collapsed,
); );
item.contextValue = `${ContextValues.RepositoryFolder}${this.repo.starred ? '+starred' : ''}`; item.contextValue = `${ContextValues.RepositoryFolder}${this.repo.starred ? '+starred' : ''}`;
item.tooltip = `${ item.tooltip = `${

Loading…
Cancel
Save