From 66d1ff189601531d347ba94f7e0a48f53da75fcd Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Sat, 29 Sep 2018 14:23:44 -0400 Subject: [PATCH] Adds pause/resume tracking support in file/line explorers --- images/dark/icon-location-filled.svg | 4 ++ images/dark/icon-location.svg | 4 ++ images/dark/icon-pin.svg | 4 ++ images/dark/icon-pinned.svg | 4 ++ images/light/icon-location-filled.svg | 4 ++ images/light/icon-location.svg | 4 ++ images/light/icon-pin.svg | 4 ++ images/light/icon-pinned.svg | 4 ++ package.json | 76 ++++++++++++++++++++++++++++++- src/constants.ts | 2 + src/views/fileHistoryExplorer.ts | 18 ++++++++ src/views/lineHistoryExplorer.ts | 18 ++++++++ src/views/nodes/explorerNode.ts | 21 ++++++++- src/views/nodes/fileHistoryTrackerNode.ts | 4 ++ src/views/nodes/lineHistoryTrackerNode.ts | 4 ++ 15 files changed, 172 insertions(+), 3 deletions(-) create mode 100644 images/dark/icon-location-filled.svg create mode 100644 images/dark/icon-location.svg create mode 100644 images/dark/icon-pin.svg create mode 100644 images/dark/icon-pinned.svg create mode 100644 images/light/icon-location-filled.svg create mode 100644 images/light/icon-location.svg create mode 100644 images/light/icon-pin.svg create mode 100644 images/light/icon-pinned.svg diff --git a/images/dark/icon-location-filled.svg b/images/dark/icon-location-filled.svg new file mode 100644 index 0000000..84a1920 --- /dev/null +++ b/images/dark/icon-location-filled.svg @@ -0,0 +1,4 @@ + + + + diff --git a/images/dark/icon-location.svg b/images/dark/icon-location.svg new file mode 100644 index 0000000..5761741 --- /dev/null +++ b/images/dark/icon-location.svg @@ -0,0 +1,4 @@ + + + + diff --git a/images/dark/icon-pin.svg b/images/dark/icon-pin.svg new file mode 100644 index 0000000..13e0881 --- /dev/null +++ b/images/dark/icon-pin.svg @@ -0,0 +1,4 @@ + + + + diff --git a/images/dark/icon-pinned.svg b/images/dark/icon-pinned.svg new file mode 100644 index 0000000..13999a1 --- /dev/null +++ b/images/dark/icon-pinned.svg @@ -0,0 +1,4 @@ + + + + diff --git a/images/light/icon-location-filled.svg b/images/light/icon-location-filled.svg new file mode 100644 index 0000000..b168078 --- /dev/null +++ b/images/light/icon-location-filled.svg @@ -0,0 +1,4 @@ + + + + diff --git a/images/light/icon-location.svg b/images/light/icon-location.svg new file mode 100644 index 0000000..18b8797 --- /dev/null +++ b/images/light/icon-location.svg @@ -0,0 +1,4 @@ + + + + diff --git a/images/light/icon-pin.svg b/images/light/icon-pin.svg new file mode 100644 index 0000000..0f31c67 --- /dev/null +++ b/images/light/icon-pin.svg @@ -0,0 +1,4 @@ + + + + diff --git a/images/light/icon-pinned.svg b/images/light/icon-pinned.svg new file mode 100644 index 0000000..7756285 --- /dev/null +++ b/images/light/icon-pinned.svg @@ -0,0 +1,4 @@ + + + + diff --git a/package.json b/package.json index 69adf5a..f85c3dc 100644 --- a/package.json +++ b/package.json @@ -2134,6 +2134,24 @@ "category": "GitLens" }, { + "command": "gitlens.fileHistoryExplorer.setEditorFollowingOn", + "title": "Resume File Tracking", + "category": "GitLens", + "icon": { + "dark": "images/dark/icon-location.svg", + "light": "images/light/icon-location.svg" + } + }, + { + "command": "gitlens.fileHistoryExplorer.setEditorFollowingOff", + "title": "Pause File Tracking", + "category": "GitLens", + "icon": { + "dark": "images/dark/icon-location-filled.svg", + "light": "images/light/icon-location-filled.svg" + } + }, + { "command": "gitlens.fileHistoryExplorer.setRenameFollowingOn", "title": "Follow Renames", "category": "GitLens" @@ -2158,6 +2176,24 @@ "category": "GitLens" }, { + "command": "gitlens.lineHistoryExplorer.setEditorFollowingOn", + "title": "Resume Line Tracking", + "category": "GitLens", + "icon": { + "dark": "images/dark/icon-location.svg", + "light": "images/light/icon-location.svg" + } + }, + { + "command": "gitlens.lineHistoryExplorer.setEditorFollowingOff", + "title": "Pause Line Tracking", + "category": "GitLens", + "icon": { + "dark": "images/dark/icon-location-filled.svg", + "light": "images/light/icon-location-filled.svg" + } + }, + { "command": "gitlens.lineHistoryExplorer.setRenameFollowingOn", "title": "Follow Renames", "category": "GitLens" @@ -2662,6 +2698,14 @@ "when": "false" }, { + "command": "gitlens.fileHistoryExplorer.setEditorFollowingOn", + "when": "false" + }, + { + "command": "gitlens.fileHistoryExplorer.setEditorFollowingOff", + "when": "false" + }, + { "command": "gitlens.fileHistoryExplorer.setRenameFollowingOn", "when": "false" }, @@ -2678,6 +2722,14 @@ "when": "false" }, { + "command": "gitlens.lineHistoryExplorer.setEditorFollowingOn", + "when": "false" + }, + { + "command": "gitlens.lineHistoryExplorer.setEditorFollowingOff", + "when": "false" + }, + { "command": "gitlens.lineHistoryExplorer.setRenameFollowingOn", "when": "false" }, @@ -2998,9 +3050,19 @@ "group": "2_gitlens" }, { + "command": "gitlens.fileHistoryExplorer.setEditorFollowingOn", + "when": "view =~ /^gitlens.fileHistoryExplorer:/ && !gitlens:fileHistoryExplorer:editorFollowing", + "group": "navigation@1" + }, + { + "command": "gitlens.fileHistoryExplorer.setEditorFollowingOff", + "when": "view =~ /^gitlens.fileHistoryExplorer:/ && gitlens:fileHistoryExplorer:editorFollowing", + "group": "navigation@1" + }, + { "command": "gitlens.fileHistoryExplorer.refresh", "when": "view =~ /^gitlens.fileHistoryExplorer:/", - "group": "navigation@1" + "group": "navigation@2" }, { "command": "gitlens.fileHistoryExplorer.setRenameFollowingOn", @@ -3013,9 +3075,19 @@ "group": "1_gitlens" }, { + "command": "gitlens.lineHistoryExplorer.setEditorFollowingOn", + "when": "view =~ /^gitlens.lineHistoryExplorer:/ && !gitlens:lineHistoryExplorer:editorFollowing", + "group": "navigation@1" + }, + { + "command": "gitlens.lineHistoryExplorer.setEditorFollowingOff", + "when": "view =~ /^gitlens.lineHistoryExplorer:/ && gitlens:lineHistoryExplorer:editorFollowing", + "group": "navigation@1" + }, + { "command": "gitlens.lineHistoryExplorer.refresh", "when": "view =~ /^gitlens.lineHistoryExplorer:/", - "group": "navigation@1" + "group": "navigation@2" }, { "command": "gitlens.lineHistoryExplorer.setRenameFollowingOn", diff --git a/src/constants.ts b/src/constants.ts index 988f457..e3bcb1a 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -34,7 +34,9 @@ export enum CommandContext { ExplorersCanCompare = 'gitlens:explorers:canCompare', HasRemotes = 'gitlens:hasRemotes', FileHistoryExplorer = 'gitlens:fileHistoryExplorer', + FileHistoryExplorerEditorFollowing = 'gitlens:fileHistoryExplorer:editorFollowing', LineHistoryExplorer = 'gitlens:lineHistoryExplorer', + LineHistoryExplorerEditorFollowing = 'gitlens:lineHistoryExplorer:editorFollowing', Key = 'gitlens:key', KeyMap = 'gitlens:keymap', RepositoriesExplorer = 'gitlens:repositoriesExplorer', diff --git a/src/views/fileHistoryExplorer.ts b/src/views/fileHistoryExplorer.ts index 542b7df..c221d4d 100644 --- a/src/views/fileHistoryExplorer.ts +++ b/src/views/fileHistoryExplorer.ts @@ -26,6 +26,16 @@ export class FileHistoryExplorer extends ExplorerBase { ); commands.registerCommand( + this.getQualifiedCommand('setEditorFollowingOn'), + () => this.setEditorFollowing(true), + this + ); + commands.registerCommand( + this.getQualifiedCommand('setEditorFollowingOff'), + () => this.setEditorFollowing(false), + this + ); + commands.registerCommand( this.getQualifiedCommand('setRenameFollowingOn'), () => this.setRenameFollowing(true), this @@ -56,6 +66,7 @@ export class FileHistoryExplorer extends ExplorerBase { configuration.changed(e, configuration.name('fileHistoryExplorer')('location').value) ) { setCommandContext(CommandContext.FileHistoryExplorer, this.config.enabled ? this.config.location : false); + setCommandContext(CommandContext.FileHistoryExplorerEditorFollowing, true); } if (initializing || configuration.changed(e, configuration.name('fileHistoryExplorer')('location').value)) { @@ -71,6 +82,13 @@ export class FileHistoryExplorer extends ExplorerBase { return { ...Container.config.explorers, ...Container.config.fileHistoryExplorer }; } + private setEditorFollowing(enabled: boolean) { + setCommandContext(CommandContext.FileHistoryExplorerEditorFollowing, enabled); + if (this._root !== undefined) { + this._root.setEditorFollowing(enabled); + } + } + private setRenameFollowing(enabled: boolean) { return configuration.updateEffective( configuration.name('advanced')('fileHistoryFollowsRenames').value, diff --git a/src/views/lineHistoryExplorer.ts b/src/views/lineHistoryExplorer.ts index c02fece..e94eb99 100644 --- a/src/views/lineHistoryExplorer.ts +++ b/src/views/lineHistoryExplorer.ts @@ -25,6 +25,16 @@ export class LineHistoryExplorer extends ExplorerBase { this ); commands.registerCommand( + this.getQualifiedCommand('setEditorFollowingOn'), + () => this.setEditorFollowing(true), + this + ); + commands.registerCommand( + this.getQualifiedCommand('setEditorFollowingOff'), + () => this.setEditorFollowing(false), + this + ); + commands.registerCommand( this.getQualifiedCommand('setRenameFollowingOn'), () => this.setRenameFollowing(true), this @@ -55,6 +65,7 @@ export class LineHistoryExplorer extends ExplorerBase { configuration.changed(e, configuration.name('lineHistoryExplorer')('location').value) ) { setCommandContext(CommandContext.LineHistoryExplorer, this.config.enabled ? this.config.location : false); + setCommandContext(CommandContext.LineHistoryExplorerEditorFollowing, true); } if (initializing || configuration.changed(e, configuration.name('lineHistoryExplorer')('location').value)) { @@ -70,6 +81,13 @@ export class LineHistoryExplorer extends ExplorerBase { return { ...Container.config.explorers, ...Container.config.lineHistoryExplorer }; } + private setEditorFollowing(enabled: boolean) { + setCommandContext(CommandContext.LineHistoryExplorerEditorFollowing, enabled); + if (this._root !== undefined) { + this._root.setEditorFollowing(enabled); + } + } + private setRenameFollowing(enabled: boolean) { return configuration.updateEffective( configuration.name('advanced')('fileHistoryFollowsRenames').value, diff --git a/src/views/nodes/explorerNode.ts b/src/views/nodes/explorerNode.ts index 26922ce..9afa5f8 100644 --- a/src/views/nodes/explorerNode.ts +++ b/src/views/nodes/explorerNode.ts @@ -130,6 +130,21 @@ export abstract class SubscribeableExplorerNode exte } } + private _canSubscribe: boolean = true; + protected get canSubscribe(): boolean { + return this._canSubscribe; + } + protected set canSubscribe(value: boolean) { + if (this._canSubscribe === value) return; + + this._canSubscribe = value; + + void this.ensureSubscription(); + if (value) { + void this.explorer.refreshNode(this); + } + } + protected abstract async subscribe(): Promise; protected unsubscribe(): void { if (this._subscription !== undefined) { @@ -152,7 +167,11 @@ export abstract class SubscribeableExplorerNode exte async ensureSubscription() { // We only need to subscribe if we are visible and if auto-refresh enabled (when supported) - if (!this.explorer.visible || (supportsAutoRefresh(this.explorer) && !this.explorer.autoRefresh)) { + if ( + !this.canSubscribe || + !this.explorer.visible || + (supportsAutoRefresh(this.explorer) && !this.explorer.autoRefresh) + ) { this.unsubscribe(); return; diff --git a/src/views/nodes/fileHistoryTrackerNode.ts b/src/views/nodes/fileHistoryTrackerNode.ts index c42c5b2..06f4a33 100644 --- a/src/views/nodes/fileHistoryTrackerNode.ts +++ b/src/views/nodes/fileHistoryTrackerNode.ts @@ -102,6 +102,10 @@ export class FileHistoryTrackerNode extends SubscribeableExplorerNode