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.

84 line
2.9 KiB

  1. 'use strict';
  2. import { CancellationTokenSource, QuickPickOptions, window } from 'vscode';
  3. import { Commands, StashSaveCommandArgs } from '../commands';
  4. import { GlyphChars } from '../constants';
  5. import { Container } from '../container';
  6. import { GitStash } from '../git/gitService';
  7. import { KeyNoopCommand } from '../keyboard';
  8. import { Iterables, Strings } from '../system';
  9. import {
  10. CommandQuickPickItem,
  11. CommitQuickPickItem,
  12. getQuickPickIgnoreFocusOut,
  13. showQuickPickProgress
  14. } from './commonQuickPicks';
  15. export class StashListQuickPick {
  16. static showProgress(mode: 'list' | 'apply') {
  17. const message =
  18. mode === 'apply'
  19. ? `Apply stashed changes to your working tree${GlyphChars.Ellipsis}`
  20. : `stashed changes ${GlyphChars.Dash} search by message, filename, or commit id`;
  21. return showQuickPickProgress(message, {
  22. left: KeyNoopCommand,
  23. ',': KeyNoopCommand,
  24. '.': KeyNoopCommand
  25. });
  26. }
  27. static async show(
  28. stash: GitStash,
  29. mode: 'list' | 'apply',
  30. progressCancellation: CancellationTokenSource,
  31. goBackCommand?: CommandQuickPickItem,
  32. currentCommand?: CommandQuickPickItem
  33. ): Promise<CommitQuickPickItem | CommandQuickPickItem | undefined> {
  34. const items = ((stash && Array.from(Iterables.map(stash.commits.values(), c => new CommitQuickPickItem(c)))) ||
  35. []) as (CommitQuickPickItem | CommandQuickPickItem)[];
  36. if (mode === 'list') {
  37. items.splice(
  38. 0,
  39. 0,
  40. new CommandQuickPickItem(
  41. {
  42. label: `$(plus) Stash Changes`,
  43. description: `${Strings.pad(GlyphChars.Dash, 2, 3)} stashes all changes`
  44. },
  45. Commands.StashSave,
  46. [
  47. {
  48. goBackCommand: currentCommand
  49. } as StashSaveCommandArgs
  50. ]
  51. )
  52. );
  53. }
  54. if (goBackCommand) {
  55. items.splice(0, 0, goBackCommand);
  56. }
  57. if (progressCancellation.token.isCancellationRequested) return undefined;
  58. const scope = await Container.keyboard.beginScope({ left: goBackCommand });
  59. progressCancellation.cancel();
  60. const pick = await window.showQuickPick(items, {
  61. matchOnDescription: true,
  62. placeHolder:
  63. mode === 'apply'
  64. ? `Apply stashed changes to your working tree${GlyphChars.Ellipsis}`
  65. : `stashed changes ${GlyphChars.Dash} search by message, filename, or commit id`,
  66. ignoreFocusOut: getQuickPickIgnoreFocusOut()
  67. // onDidSelectItem: (item: QuickPickItem) => {
  68. // scope.setKeyCommand('right', item);
  69. // }
  70. } as QuickPickOptions);
  71. await scope.dispose();
  72. return pick;
  73. }
  74. }