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.

94 lines
3.3 KiB

  1. 'use strict';
  2. import { commands, ConfigurationChangeEvent } from 'vscode';
  3. import { configuration, LineHistoryViewConfig, ViewsConfig } from '../configuration';
  4. import { CommandContext, setCommandContext } from '../constants';
  5. import { Container } from '../container';
  6. import { LineHistoryTrackerNode } from './nodes';
  7. import { ViewBase } from './viewBase';
  8. export class LineHistoryView extends ViewBase<LineHistoryTrackerNode> {
  9. constructor() {
  10. super('gitlens.views.lineHistory');
  11. }
  12. getRoot() {
  13. return new LineHistoryTrackerNode(this);
  14. }
  15. protected get location(): string {
  16. return this.config.location;
  17. }
  18. protected registerCommands() {
  19. void Container.viewCommands;
  20. commands.registerCommand(this.getQualifiedCommand('refresh'), () => this.refresh(true), this);
  21. commands.registerCommand(this.getQualifiedCommand('changeBase'), () => this.changeBase(), this);
  22. commands.registerCommand(
  23. this.getQualifiedCommand('setEditorFollowingOn'),
  24. () => this.setEditorFollowing(true),
  25. this
  26. );
  27. commands.registerCommand(
  28. this.getQualifiedCommand('setEditorFollowingOff'),
  29. () => this.setEditorFollowing(false),
  30. this
  31. );
  32. commands.registerCommand(
  33. this.getQualifiedCommand('setRenameFollowingOn'),
  34. () => this.setRenameFollowing(true),
  35. this
  36. );
  37. commands.registerCommand(
  38. this.getQualifiedCommand('setRenameFollowingOff'),
  39. () => this.setRenameFollowing(false),
  40. this
  41. );
  42. }
  43. protected onConfigurationChanged(e: ConfigurationChangeEvent) {
  44. if (
  45. !configuration.changed(e, configuration.name('views')('lineHistory').value) &&
  46. !configuration.changed(e, configuration.name('views').value) &&
  47. !configuration.changed(e, configuration.name('defaultGravatarsStyle').value) &&
  48. !configuration.changed(e, configuration.name('advanced')('fileHistoryFollowsRenames').value)
  49. ) {
  50. return;
  51. }
  52. if (configuration.changed(e, configuration.name('views')('lineHistory')('enabled').value)) {
  53. setCommandContext(CommandContext.ViewsLineHistoryEditorFollowing, true);
  54. }
  55. if (configuration.changed(e, configuration.name('views')('lineHistory')('location').value)) {
  56. this.initialize(this.config.location);
  57. }
  58. if (!configuration.initializing(e) && this._root !== undefined) {
  59. void this.refresh(true);
  60. }
  61. }
  62. get config(): ViewsConfig & LineHistoryViewConfig {
  63. return { ...Container.config.views, ...Container.config.views.lineHistory };
  64. }
  65. private changeBase() {
  66. if (this._root !== undefined) {
  67. void this._root.changeBase();
  68. }
  69. }
  70. private setEditorFollowing(enabled: boolean) {
  71. setCommandContext(CommandContext.ViewsLineHistoryEditorFollowing, enabled);
  72. if (this._root !== undefined) {
  73. this._root.setEditorFollowing(enabled);
  74. }
  75. }
  76. private setRenameFollowing(enabled: boolean) {
  77. return configuration.updateEffective(
  78. configuration.name('advanced')('fileHistoryFollowsRenames').value,
  79. enabled
  80. );
  81. }
  82. }