Browse Source

Adds a "show only changed files" command to command palette and graph (#2835)

* Adds a "show only changed files" command to command palette and graph

* Rewords command to 'open changed & close unchanged files'
main
Ramin Tadayon 1 year ago
committed by GitHub
parent
commit
a5e33e9655
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 187 additions and 0 deletions
  1. +40
    -0
      package.json
  2. +1
    -0
      src/commands.ts
  3. +85
    -0
      src/commands/openOnlyChangedFiles.ts
  4. +19
    -0
      src/commands/quickCommand.steps.ts
  5. +1
    -0
      src/constants.ts
  6. +20
    -0
      src/git/actions/commit.ts
  7. +10
    -0
      src/plus/webviews/graph/graphWebview.ts
  8. +11
    -0
      src/quickpicks/items/commits.ts

+ 40
- 0
package.json View File

@ -5280,6 +5280,11 @@
"category": "GitLens"
},
{
"command": "gitlens.openOnlyChangedFiles",
"title": "Open Changed & Close Unchanged Files",
"category": "GitLens"
},
{
"command": "gitlens.openBranchesOnRemote",
"title": "Open Branches on Remote",
"category": "GitLens",
@ -5868,6 +5873,11 @@
"category": "GitLens"
},
{
"command": "gitlens.views.openOnlyChangedFiles",
"title": "Open Changed & Close Unchanged Files",
"category": "GitLens"
},
{
"command": "gitlens.views.applyChanges",
"title": "Apply Changes",
"category": "GitLens",
@ -7461,6 +7471,11 @@
"category": "GitLens"
},
{
"command": "gitlens.graph.openOnlyChangedFiles",
"title": "Open Changed & Close Unchanged Files",
"category": "GitLens"
},
{
"command": "gitlens.graph.addAuthor",
"title": "Add as Co-author",
"category": "GitLens",
@ -8398,6 +8413,10 @@
"when": "gitlens:enabled"
},
{
"command": "gitlens.openOnlyChangedFiles",
"when": "gitlens:enabled"
},
{
"command": "gitlens.openBranchesOnRemote",
"when": "gitlens:hasRemotes"
},
@ -8774,6 +8793,10 @@
"when": "false"
},
{
"command": "gitlens.views.openOnlyChangedFiles",
"when": "false"
},
{
"command": "gitlens.views.applyChanges",
"when": "false"
},
@ -9874,6 +9897,10 @@
"when": "false"
},
{
"command": "gitlens.graph.openOnlyChangedFiles",
"when": "false"
},
{
"command": "gitlens.graph.addAuthor",
"when": "false"
},
@ -10400,6 +10427,11 @@
"command": "gitlens.closeUnchangedFiles",
"when": "gitlens:enabled && scmProvider == git && scmResourceGroup =~ /^(workingTree|index)$/ && config.gitlens.menus.scmGroup.openClose",
"group": "3_gitlens@2"
},
{
"command": "gitlens.openOnlyChangedFiles",
"when": "gitlens:enabled && scmProvider == git && scmResourceGroup =~ /^(workingTree|index)$/ && config.gitlens.menus.scmGroup.openClose",
"group": "3_gitlens@2"
}
],
"scm/resourceState/context": [
@ -13140,6 +13172,10 @@
{
"command": "gitlens.views.openChangedFileRevisions",
"group": "2_gitlens@2"
},
{
"command": "gitlens.views.openOnlyChangedFiles",
"group": "2_gitlens@3"
}
],
"gitlens/graph/commit/changes": [
@ -13159,6 +13195,10 @@
{
"command": "gitlens.graph.openChangedFileRevisions",
"group": "2_gitlens@2"
},
{
"command": "gitlens.graph.openOnlyChangedFiles",
"group": "2_gitlens@3"
}
],
"gitlens/commit/file/commit": [

+ 1
- 0
src/commands.ts View File

@ -49,6 +49,7 @@ export * from './commands/resetViewsLayout';
export * from './commands/searchCommits';
export * from './commands/showCommitsInView';
export * from './commands/showLastQuickPick';
export * from './commands/openOnlyChangedFiles';
export * from './commands/showQuickBranchHistory';
export * from './commands/showQuickCommit';
export * from './commands/showQuickCommitFile';

+ 85
- 0
src/commands/openOnlyChangedFiles.ts View File

@ -0,0 +1,85 @@
import type { Uri } from 'vscode';
import { TabInputCustom, TabInputNotebook, TabInputNotebookDiff, TabInputText, TabInputTextDiff, window } from 'vscode';
import { Commands } from '../constants';
import type { Container } from '../container';
import { showGenericErrorMessage } from '../messages';
import { getRepositoryOrShowPicker } from '../quickpicks/repositoryPicker';
import { filterMap } from '../system/array';
import { command } from '../system/command';
import { UriComparer } from '../system/comparers';
import { Logger } from '../system/logger';
import { findOrOpenEditors } from '../system/utils';
import { Command } from './base';
export interface OpenOnlyChangedFilesCommandArgs {
uris?: Uri[];
}
@command()
export class OpenOnlyChangedFilesCommand extends Command {
constructor(private readonly container: Container) {
super(Commands.OpenOnlyChangedFiles);
}
async execute(args?: OpenOnlyChangedFilesCommandArgs) {
args = { ...args };
try {
if (args.uris == null) {
const repository = await getRepositoryOrShowPicker('Open Changed & Close Unchanged Files');
if (repository == null) return;
const status = await this.container.git.getStatusForRepo(repository.uri);
if (status == null) {
void window.showWarningMessage('Unable to open changed & close unchanged files');
return;
}
args.uris = filterMap(status.files, f => (f.status !== 'D' ? f.uri : undefined));
}
const hasNoChangedFiles = args.uris.length === 0;
const openUris = new Set(args.uris);
let inputUri: Uri | undefined = undefined;
let matchingUri: Uri | undefined;
for (const group of window.tabGroups.all) {
for (const tab of group.tabs) {
if (hasNoChangedFiles) {
void window.tabGroups.close(tab, true);
continue;
}
if (
tab.input instanceof TabInputText ||
tab.input instanceof TabInputCustom ||
tab.input instanceof TabInputNotebook
) {
inputUri = tab.input.uri;
} else if (tab.input instanceof TabInputTextDiff || tab.input instanceof TabInputNotebookDiff) {
inputUri = tab.input.modified;
} else {
inputUri = undefined;
}
if (inputUri == null) continue;
// eslint-disable-next-line no-loop-func
matchingUri = args.uris.find(uri => UriComparer.equals(uri, inputUri));
if (matchingUri != null) {
openUris.delete(matchingUri);
} else {
void window.tabGroups.close(tab, true);
}
}
}
if (openUris.size > 0) {
findOrOpenEditors([...openUris]);
}
} catch (ex) {
Logger.error(ex, 'OpenOnlyChangedFilesCommand');
void showGenericErrorMessage('Unable to open changed & close unchanged files');
}
}
}

+ 19
- 0
src/commands/quickCommand.steps.ts View File

@ -63,6 +63,7 @@ import {
CommitOpenRevisionsCommandQuickPickItem,
CommitRestoreFileChangesCommandQuickPickItem,
OpenChangedFilesCommandQuickPickItem,
OpenOnlyChangedFilesCommandQuickPickItem,
} from '../quickpicks/items/commits';
import type { QuickPickSeparator } from '../quickpicks/items/common';
import { CommandQuickPickItem, createQuickPickSeparator } from '../quickpicks/items/common';
@ -2385,6 +2386,12 @@ function getShowRepositoryStatusStepItems<
computed.stagedAddsAndChanges.concat(computed.unstagedAddsAndChanges),
),
);
items.push(
new OpenOnlyChangedFilesCommandQuickPickItem(
computed.stagedAddsAndChanges.concat(computed.unstagedAddsAndChanges),
),
);
}
if (computed.staged > 0) {
@ -2393,6 +2400,12 @@ function getShowRepositoryStatusStepItems<
label: '$(files) Open Staged Files',
}),
);
items.push(
new OpenOnlyChangedFilesCommandQuickPickItem(computed.stagedAddsAndChanges, {
label: '$(files) Open Only Staged Files',
}),
);
}
if (computed.unstaged > 0) {
@ -2401,6 +2414,12 @@ function getShowRepositoryStatusStepItems<
label: '$(files) Open Unstaged Files',
}),
);
items.push(
new OpenOnlyChangedFilesCommandQuickPickItem(computed.unstagedAddsAndChanges, {
label: '$(files) Open Only Unstaged Files',
}),
);
}
if (context.status.files.length) {

+ 1
- 0
src/constants.ts View File

@ -246,6 +246,7 @@ export const enum Commands {
ShowLastQuickPick = 'gitlens.showLastQuickPick',
ShowLineCommitInView = 'gitlens.showLineCommitInView',
ShowLineHistoryView = 'gitlens.showLineHistoryView',
OpenOnlyChangedFiles = 'gitlens.openOnlyChangedFiles',
ShowQuickBranchHistory = 'gitlens.showQuickBranchHistory',
ShowQuickCommit = 'gitlens.showQuickCommitDetails',
ShowQuickCommitFile = 'gitlens.showQuickCommitFileDetails',

+ 20
- 0
src/git/actions/commit.ts View File

@ -5,6 +5,7 @@ import type {
DiffWithPreviousCommandArgs,
DiffWithWorkingCommandArgs,
OpenFileOnRemoteCommandArgs,
OpenOnlyChangedFilesCommandArgs,
OpenWorkingFileCommandArgs,
ShowQuickCommitCommandArgs,
ShowQuickCommitFileCommandArgs,
@ -610,3 +611,22 @@ export async function showInCommitGraph(
preserveFocus: options?.preserveFocus,
}));
}
export async function openOnlyChangedFiles(commit: GitCommit): Promise<void> {
await commit.ensureFullDetails();
const files = commit.files ?? [];
if (files.length > 10) {
const result = await window.showWarningMessage(
`Are you sure you want to open all ${files.length} files?`,
{ title: 'Yes' },
{ title: 'No', isCloseAffordance: true },
);
if (result == null || result.title === 'No') return;
}
void (await executeCommand<OpenOnlyChangedFilesCommandArgs>(Commands.OpenOnlyChangedFiles, {
uris: files.filter(f => f.status !== 'D').map(f => f.uri),
}));
}

+ 10
- 0
src/plus/webviews/graph/graphWebview.ts View File

@ -23,6 +23,7 @@ import {
openAllChangesWithWorking,
openFiles,
openFilesAtRevision,
openOnlyChangedFiles as openOnlyChangedFilesForCommit,
showGraphDetailsView,
} from '../../../git/actions/commit';
import * as ContributorActions from '../../../git/actions/contributor';
@ -448,6 +449,7 @@ export class GraphWebviewProvider implements WebviewProvider {
registerCommand('gitlens.graph.copyDeepLinkToTag', this.copyDeepLinkToTag, this),
registerCommand('gitlens.graph.openChangedFiles', this.openFiles, this),
registerCommand('gitlens.graph.openOnlyChangedFiles', this.openOnlyChangedFiles, this),
registerCommand('gitlens.graph.openChangedFileDiffs', this.openAllChanges, this),
registerCommand('gitlens.graph.openChangedFileDiffsWithWorking', this.openAllChangesWithWorking, this),
registerCommand('gitlens.graph.openChangedFileRevisions', this.openRevisions, this),
@ -2645,6 +2647,14 @@ export class GraphWebviewProvider implements WebviewProvider {
}
@debug()
private async openOnlyChangedFiles(item?: GraphItemContext) {
const commit = await this.getCommitFromGraphItemRef(item);
if (commit == null) return;
return openOnlyChangedFilesForCommit(commit);
}
@debug()
private addAuthor(item?: GraphItemContext) {
if (isGraphItemTypedContext(item, 'contributor')) {
const { repoPath, name, email, current } = item.webviewItemValue;

+ 11
- 0
src/quickpicks/items/commits.ts View File

@ -1,5 +1,6 @@
import type { QuickPickItem } from 'vscode';
import { window } from 'vscode';
import type { OpenOnlyChangedFilesCommandArgs } from '../../commands';
import type { OpenChangedFilesCommandArgs } from '../../commands/openChangedFiles';
import { RevealInSideBarQuickInputButton, ShowDetailsViewQuickInputButton } from '../../commands/quickCommand.buttons';
import type { Keys } from '../../constants';
@ -419,3 +420,13 @@ export class OpenChangedFilesCommandQuickPickItem extends CommandQuickPickItem {
super(item ?? '$(files) Open All Changed Files', Commands.OpenChangedFiles, [commandArgs]);
}
}
export class OpenOnlyChangedFilesCommandQuickPickItem extends CommandQuickPickItem {
constructor(files: GitStatusFile[], item?: QuickPickItem) {
const commandArgs: OpenOnlyChangedFilesCommandArgs = {
uris: files.map(f => f.uri),
};
super(item ?? '$(files) Open Changed & Close Unchanged Files', Commands.OpenOnlyChangedFiles, [commandArgs]);
}
}

||||||
x
 
000:0
Loading…
Cancel
Save