From ab5b228e1dcde2a5ecf6380fa832663e0f5152f2 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Wed, 10 May 2023 15:37:55 -0400 Subject: [PATCH] Changes to use file theme icons for many views --- CHANGELOG.md | 10 ++ package.json | 181 +++++++++++++++++---- src/@types/vscode.git.uri.ts | 18 ++ src/config.ts | 2 +- src/git/gitUri.ts | 7 +- src/views/nodes/commitFileNode.ts | 38 +++-- src/views/nodes/commitNode.ts | 3 +- src/views/nodes/folderNode.ts | 5 +- src/views/nodes/stashFileNode.ts | 10 +- src/views/viewDecorationProvider.ts | 15 +- src/webviews/apps/commitDetails/commitDetails.ts | 1 + .../apps/settings/partials/views.branches.html | 12 ++ .../apps/settings/partials/views.commits.html | 12 ++ .../apps/settings/partials/views.contributors.html | 16 ++ .../apps/settings/partials/views.file-history.html | 35 ---- .../apps/settings/partials/views.line-history.html | 1 - .../apps/settings/partials/views.remotes.html | 12 ++ .../apps/settings/partials/views.repositories.html | 12 ++ .../settings/partials/views.searchAndCompare.html | 16 ++ .../apps/settings/partials/views.stashes.html | 12 ++ .../apps/settings/partials/views.tags.html | 12 ++ .../apps/settings/partials/views.worktrees.html | 12 ++ src/webviews/commitDetails/commitDetailsWebview.ts | 4 + 23 files changed, 346 insertions(+), 100 deletions(-) create mode 100644 src/@types/vscode.git.uri.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index fbc5b00..b248856 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,16 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p - Moves _Open \* on Remote_ commands into _Open on Remote (Web)_ submenu - Renames the _Commit Changes_ submenu to _Open Changes_ - Renames _Show Commit_ command to _Quick Show Commit_ and _Show Line Commit_ command to _Quick Show Line Commit_ for better clarity as it opens a quick pick menu +- Changes the file icons shown in many GitLens views to use the file type's theme icon (by default) rather than the status icon + - Adds a `gitlens.views.commits.files.icon` setting to specify how the _Commits_ view will display file icons + - Adds a `gitlens.views.repositories.files.icon` setting to specify how the _Repositories_ view will display file icons + - Adds a `gitlens.views.branches.files.icon` setting to specify how the _Branches_ view will display file icons + - Adds a `gitlens.views.remotes.files.icon` setting to specify how the _Remotes_ view will display file icons + - Adds a `gitlens.views.stashes.files.icon` setting to specify how the _Stashes_ view will display file icons + - Adds a `gitlens.views.tags.files.icon` setting to specify how the _Tags_ view will display file icons + - Adds a `gitlens.views.worktrees.files.icon` setting to specify how the _Worktrees_ view will display file icons + - Adds a `gitlens.views.contributors.files.icon` setting to specify how the _Contributors_ view will display file icons + - Adds a `gitlens.views.searchAndCompare.files.icon` setting to specify how the _Search & Compare_ view will display file icons - Renames _Delete Stash..._ command to _Drop Stash..._ in the _Stashes_ view - Removes the commit icon when hiding avatars in the _Commits_ view to allow for a more compact layout - Limits Git CodeLens on docker files — closes [#2153](https://github.com/gitkraken/vscode-gitlens/issues/2153) diff --git a/package.json b/package.json index 4facac6..bd3e625 100644 --- a/package.json +++ b/package.json @@ -779,6 +779,21 @@ "scope": "window", "order": 32 }, + "gitlens.views.commits.files.icon": { + "type": "string", + "default": "type", + "enum": [ + "status", + "type" + ], + "enumDescriptions": [ + "Shows the file's status as the icon", + "Shows the file's type (theme icon) as the icon" + ], + "markdownDescription": "Specifies how the _Commits_ view will display file icons", + "scope": "window", + "order": 33 + }, "gitlens.views.commits.avatars": { "type": "boolean", "default": true, @@ -852,6 +867,21 @@ "scope": "window", "order": 32 }, + "gitlens.views.commitDetails.files.icon": { + "type": "string", + "default": "type", + "enum": [ + "status", + "type" + ], + "enumDescriptions": [ + "Shows the file's status as the icon", + "Shows the file's type (theme icon) as the icon" + ], + "markdownDescription": "Specifies how the _Commit Details_ view will display file icons", + "scope": "window", + "order": 33 + }, "gitlens.views.commitDetails.avatars": { "type": "boolean", "default": true, @@ -1044,6 +1074,21 @@ "scope": "window", "order": 82 }, + "gitlens.views.repositories.files.icon": { + "type": "string", + "default": "type", + "enum": [ + "status", + "type" + ], + "enumDescriptions": [ + "Shows the file's status as the icon", + "Shows the file's type (theme icon) as the icon" + ], + "markdownDescription": "Specifies how the _Repositories_ view will display file icons", + "scope": "window", + "order": 83 + }, "gitlens.views.repositories.compact": { "type": "boolean", "default": false, @@ -1080,37 +1125,6 @@ "title": "File History View", "order": 24, "properties": { - "gitlens.views.fileHistory.files.layout": { - "type": "string", - "default": "auto", - "enum": [ - "auto", - "list", - "tree" - ], - "enumDescriptions": [ - "Automatically switches between displaying files as a `tree` or `list` based on the `#gitlens.views.fileHistory.files.threshold#` value and the number of files at each nesting level", - "Displays files as a list", - "Displays files as a tree" - ], - "markdownDescription": "Specifies how the _File History_ view will display files when showing the history of a folder", - "scope": "window", - "order": 10 - }, - "gitlens.views.fileHistory.files.threshold": { - "type": "number", - "default": 5, - "markdownDescription": "Specifies when to switch between displaying files as a `tree` or `list` based on the number of files in a nesting level in the _File History_ view. Only applies to folder history and when `#gitlens.views.fileHistory.files.layout#` is set to `auto`", - "scope": "window", - "order": 11 - }, - "gitlens.views.fileHistory.files.compact": { - "type": "boolean", - "default": true, - "markdownDescription": "Specifies whether to compact (flatten) unnecessary file nesting in the _File History_ view. Only applies to folder history and when `#gitlens.views.fileHistory.files.layout#` is set to `tree` or `auto`", - "scope": "window", - "order": 12 - }, "gitlens.views.fileHistory.avatars": { "type": "boolean", "default": true, @@ -1261,6 +1275,21 @@ "scope": "window", "order": 52 }, + "gitlens.views.branches.files.icon": { + "type": "string", + "default": "type", + "enum": [ + "status", + "type" + ], + "enumDescriptions": [ + "Shows the file's status as the icon", + "Shows the file's type (theme icon) as the icon" + ], + "markdownDescription": "Specifies how the _Branches_ view will display file icons", + "scope": "window", + "order": 53 + }, "gitlens.views.branches.avatars": { "type": "boolean", "default": true, @@ -1349,6 +1378,21 @@ "scope": "window", "order": 32 }, + "gitlens.views.remotes.files.icon": { + "type": "string", + "default": "type", + "enum": [ + "status", + "type" + ], + "enumDescriptions": [ + "Shows the file's status as the icon", + "Shows the file's type (theme icon) as the icon" + ], + "markdownDescription": "Specifies how the _Remotes_ view will display file icons", + "scope": "window", + "order": 33 + }, "gitlens.views.remotes.avatars": { "type": "boolean", "default": true, @@ -1401,6 +1445,21 @@ "scope": "window", "order": 12 }, + "gitlens.views.stashes.files.icon": { + "type": "string", + "default": "type", + "enum": [ + "status", + "type" + ], + "enumDescriptions": [ + "Shows the file's status as the icon", + "Shows the file's type (theme icon) as the icon" + ], + "markdownDescription": "Specifies how the _Stashes_ view will display file icons", + "scope": "window", + "order": 13 + }, "gitlens.views.stashes.reveal": { "type": "boolean", "default": true, @@ -1480,6 +1539,21 @@ "scope": "window", "order": 32 }, + "gitlens.views.tags.files.icon": { + "type": "string", + "default": "type", + "enum": [ + "status", + "type" + ], + "enumDescriptions": [ + "Shows the file's status as the icon", + "Shows the file's type (theme icon) as the icon" + ], + "markdownDescription": "Specifies how the _Tags_ view will display file icons", + "scope": "window", + "order": 33 + }, "gitlens.views.tags.avatars": { "type": "boolean", "default": true, @@ -1606,6 +1680,21 @@ "scope": "window", "order": 42 }, + "gitlens.views.worktrees.files.icon": { + "type": "string", + "default": "type", + "enum": [ + "status", + "type" + ], + "enumDescriptions": [ + "Shows the file's status as the icon", + "Shows the file's type (theme icon) as the icon" + ], + "markdownDescription": "Specifies how the _Worktrees_ view will display file icons", + "scope": "window", + "order": 43 + }, "gitlens.views.worktrees.avatars": { "type": "boolean", "default": true, @@ -1709,6 +1798,21 @@ "scope": "window", "order": 52 }, + "gitlens.views.contributors.files.icon": { + "type": "string", + "default": "type", + "enum": [ + "status", + "type" + ], + "enumDescriptions": [ + "Shows the file's status as the icon", + "Shows the file's type (theme icon) as the icon" + ], + "markdownDescription": "Specifies how the _Contributors_ view will display file icons", + "scope": "window", + "order": 53 + }, "gitlens.views.contributors.avatars": { "type": "boolean", "default": true, @@ -1775,6 +1879,21 @@ "scope": "window", "order": 22 }, + "gitlens.views.searchAndCompare.files.icon": { + "type": "string", + "default": "type", + "enum": [ + "status", + "type" + ], + "enumDescriptions": [ + "Shows the file's status as the icon", + "Shows the file's type (theme icon) as the icon" + ], + "markdownDescription": "Specifies how the _Search & Compare_ view will display file icons", + "scope": "window", + "order": 33 + }, "gitlens.views.searchAndCompare.avatars": { "type": "boolean", "default": true, diff --git a/src/@types/vscode.git.uri.ts b/src/@types/vscode.git.uri.ts new file mode 100644 index 0000000..e7b354c --- /dev/null +++ b/src/@types/vscode.git.uri.ts @@ -0,0 +1,18 @@ +import { Uri } from 'vscode'; +import { Schemes } from '../constants'; + +export interface GitUriQuery { + path: string; + ref: string; + + decoration?: string; +} + +export function getQueryDataFromScmGitUri(uri: Uri): GitUriQuery | undefined { + if (uri.scheme === Schemes.Git) { + try { + return JSON.parse(uri.query) as GitUriQuery; + } catch {} + } + return undefined; +} diff --git a/src/config.ts b/src/config.ts index 964178c..780404d 100644 --- a/src/config.ts +++ b/src/config.ts @@ -735,7 +735,6 @@ export interface ContributorsViewConfig { export interface FileHistoryViewConfig { avatars: boolean; - files: ViewsFilesConfig; } export interface LineHistoryViewConfig { @@ -821,6 +820,7 @@ export interface WorktreesViewConfig { export interface ViewsFilesConfig { compact: boolean; + icon: 'status' | 'type'; layout: ViewFilesLayout; threshold: number; } diff --git a/src/git/gitUri.ts b/src/git/gitUri.ts index 2011ed3..bc283f3 100644 --- a/src/git/gitUri.ts +++ b/src/git/gitUri.ts @@ -1,5 +1,6 @@ import { Uri } from 'vscode'; import { decodeUtf8Hex, encodeUtf8Hex } from '@env/hex'; +import { getQueryDataFromScmGitUri } from '../@types/vscode.git.uri'; import { Schemes } from '../constants'; import { Container } from '../container'; import type { GitHubAuthorityMetadata } from '../plus/remotehub'; @@ -253,11 +254,7 @@ export class GitUri extends (Uri as any as UriEx) { // If this is a git uri, find its repoPath if (uri.scheme === Schemes.Git) { - let data: { path: string; ref: string } | undefined; - try { - data = JSON.parse(uri.query); - } catch {} - + const data = getQueryDataFromScmGitUri(uri); if (data?.path) { const repository = await Container.instance.git.getOrOpenRepository(Uri.file(data.path)); if (repository == null) { diff --git a/src/views/nodes/commitFileNode.ts b/src/views/nodes/commitFileNode.ts index 9e91cab..7de3b18 100644 --- a/src/views/nodes/commitFileNode.ts +++ b/src/views/nodes/commitFileNode.ts @@ -1,7 +1,7 @@ import type { Command, Selection } from 'vscode'; import { MarkdownString, TreeItem, TreeItemCollapsibleState, Uri } from 'vscode'; import type { DiffWithPreviousCommandArgs } from '../../commands'; -import { Commands } from '../../constants'; +import { Commands, Schemes } from '../../constants'; import { StatusFileFormatter } from '../../git/formatters/statusFormatter'; import { GitUri } from '../../git/gitUri'; import type { GitBranch } from '../../git/models/branch'; @@ -10,12 +10,14 @@ import type { GitFile } from '../../git/models/file'; import { getGitFileStatusIcon } from '../../git/models/file'; import type { GitRevisionReference } from '../../git/models/reference'; import { joinPaths, relativeDir } from '../../system/path'; -import type { FileHistoryView } from '../fileHistoryView'; -import type { View, ViewsWithCommits } from '../viewBase'; +import type { StashesView } from '../stashesView'; +import type { ViewsWithCommits } from '../viewBase'; import type { ViewNode } from './viewNode'; import { ContextValues, ViewRefFileNode } from './viewNode'; -export class CommitFileNode extends ViewRefFileNode { +export class CommitFileNode< + TView extends ViewsWithCommits | StashesView = ViewsWithCommits | StashesView, +> extends ViewRefFileNode { static key = ':file'; static getId(parent: ViewNode, path: string): string { return `${parent.id}${this.key}(${path})`; @@ -76,15 +78,27 @@ export class CommitFileNode { + if (this.view instanceof FileHistoryView) return []; + if (this._children == null) { const commit = this.commit; @@ -80,7 +82,6 @@ export class CommitNode extends ViewRefNode; } -export class FolderNode extends ViewNode { +export class FolderNode extends ViewNode { static key = ':folder'; static getId(parent: ViewNode, path: string): string { return `${parent.id}${this.key}(${path})`; @@ -29,7 +28,7 @@ export class FolderNode extends ViewNode { +export class StashFileNode extends CommitFileNode { // eslint-disable-next-line @typescript-eslint/no-useless-constructor - constructor( - view: ViewsWithCommits | StashesView | RepositoriesView, - parent: ViewNode, - file: GitFile, - commit: GitStashCommit, - ) { + constructor(view: ViewsWithCommits | StashesView, parent: ViewNode, file: GitFile, commit: GitStashCommit) { super(view, parent, file, commit); } diff --git a/src/views/viewDecorationProvider.ts b/src/views/viewDecorationProvider.ts index 065a1a0..a8d8340 100644 --- a/src/views/viewDecorationProvider.ts +++ b/src/views/viewDecorationProvider.ts @@ -1,7 +1,8 @@ -import type { CancellationToken, Event, FileDecoration, FileDecorationProvider, Uri } from 'vscode'; -import { Disposable, EventEmitter, ThemeColor, window } from 'vscode'; +import type { CancellationToken, Event, FileDecoration, FileDecorationProvider } from 'vscode'; +import { Disposable, EventEmitter, ThemeColor, Uri, window } from 'vscode'; +import { getQueryDataFromScmGitUri } from '../@types/vscode.git.uri'; import type { Colors } from '../constants'; -import { GlyphChars } from '../constants'; +import { GlyphChars, Schemes } from '../constants'; import { GitBranchStatus } from '../git/models/branch'; export class ViewFileDecorationProvider implements FileDecorationProvider, Disposable { @@ -38,6 +39,12 @@ export class ViewFileDecorationProvider implements FileDecorationProvider, Dispo } provideFileDecoration(uri: Uri, token: CancellationToken): FileDecoration | undefined { + if (uri.scheme === Schemes.Git) { + const data = getQueryDataFromScmGitUri(uri); + if (data?.decoration != null) { + uri = Uri.parse(data?.decoration); + } + } if (uri.scheme !== 'gitlens-view') return undefined; switch (uri.authority) { @@ -87,6 +94,8 @@ export class ViewFileDecorationProvider implements FileDecorationProvider, Dispo case 'M': return { badge: 'M', + // Commented out until we can control the color to only apply to the badge, as the color is applied to the entire decoration and its too much + // https://github.com/microsoft/vscode/issues/182098 // color: new ThemeColor('gitlens.decorations.modifiedForegroundColor' satisfies Colors), tooltip: 'Modified', }; diff --git a/src/webviews/apps/commitDetails/commitDetails.ts b/src/webviews/apps/commitDetails/commitDetails.ts index 2ac843d..2183c44 100644 --- a/src/webviews/apps/commitDetails/commitDetails.ts +++ b/src/webviews/apps/commitDetails/commitDetails.ts @@ -193,6 +193,7 @@ export class CommitDetailsApp extends App> { layout: layout ?? ViewFilesLayout.Auto, compact: this.state.preferences?.files?.compact ?? true, threshold: this.state.preferences?.files?.threshold ?? 5, + icon: this.state.preferences?.files?.icon ?? 'type', }; this.state.preferences = { diff --git a/src/webviews/apps/settings/partials/views.branches.html b/src/webviews/apps/settings/partials/views.branches.html index ef86e5f..34f77fb 100644 --- a/src/webviews/apps/settings/partials/views.branches.html +++ b/src/webviews/apps/settings/partials/views.branches.html @@ -146,6 +146,18 @@
+ +
+ +
+
+
+ +
+
+ +
+ +
+
+
+ +
+
+ +
+ +
+
+
+ +
+
- -
- -
-
-

- Chooses the best layout based on the number of files at each nesting level -

-
- -
-
- - -
-

Compacts (flattens) unnecessary nesting when using a tree layouts

-
- -
-
diff --git a/src/webviews/apps/settings/partials/views.remotes.html b/src/webviews/apps/settings/partials/views.remotes.html index 5a5c916..b8147c3 100644 --- a/src/webviews/apps/settings/partials/views.remotes.html +++ b/src/webviews/apps/settings/partials/views.remotes.html @@ -127,6 +127,18 @@
+ +
+ +
+
+
+ +
+
+ +
+ +
+
+
+ +
+
+ +
+ +
+
+
+ +
+
+ +
+ +
+
+
+ +
+
+ +
+ +
+
+
+ +
+
+ +
+ +
+
+
+ +
+