You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.1 KiB

  1. 'use strict';
  2. import { Uri, window } from 'vscode';
  3. import { Command, command, Commands, findOrOpenEditors, getRepoPathOrPrompt } from './common';
  4. import { Container } from '../container';
  5. import { Logger } from '../logger';
  6. import { Messages } from '../messages';
  7. import { Arrays } from '../system';
  8. export interface OpenChangedFilesCommandArgs {
  9. uris?: Uri[];
  10. }
  11. @command()
  12. export class OpenChangedFilesCommand extends Command {
  13. constructor() {
  14. super(Commands.OpenChangedFiles);
  15. }
  16. async execute(args?: OpenChangedFilesCommandArgs) {
  17. args = { ...args };
  18. try {
  19. if (args.uris == null) {
  20. const repoPath = await getRepoPathOrPrompt('Open All Changed Files');
  21. if (!repoPath) return;
  22. const status = await Container.git.getStatusForRepo(repoPath);
  23. if (status == null) {
  24. void window.showWarningMessage('Unable to open changed files');
  25. return;
  26. }
  27. args.uris = Arrays.filterMap(status.files, f => (f.status !== 'D' ? f.uri : undefined));
  28. }
  29. findOrOpenEditors(args.uris);
  30. } catch (ex) {
  31. Logger.error(ex, 'OpenChangedFilesCommand');
  32. void Messages.showGenericErrorMessage('Unable to open all changed files');
  33. }
  34. }
  35. }