Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Also show file-specific icons in the PR file tree #33921

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

kerwin612
Copy link
Member

@kerwin612 kerwin612 commented Mar 17, 2025

Fix #33914

before:
3000-gogitea-gitea-y4ulxr46c4k ws-us118 gitpod io_test_test gitea_src_branch_main_ gitmodules

after:
3000-gogitea-gitea-y4ulxr46c4k ws-us118 gitpod io_test_test gitea_src_branch_main_README md

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Mar 17, 2025
@pull-request-size pull-request-size bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Mar 17, 2025
@github-actions github-actions bot added modifies/go Pull requests that update Go code modifies/frontend labels Mar 17, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@pull-request-size pull-request-size bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 18, 2025
@kerwin612
Copy link
Member Author

file diff

before:
3000-gogitea-gitea-y4ulxr46c4k ws-us118 gitpod io_test_test_compare_main test_diff_fileicon (1)

after:
3000-gogitea-gitea-y4ulxr46c4k ws-us118 gitpod io_test_test_compare_main test_diff_fileicon

@lutinglt
Copy link

Perhaps it would be better to use Material Icons for the folder as well?
The Material Icons for GitHub browser plugin follows this logic

image

@lunny lunny changed the title Optimize File Icons in file-tree to Match Those in file-list Optimize File Icons in file-tree to Match Those in file-list and also in file-tree in pull request changed files. Mar 18, 2025
@lunny lunny changed the title Optimize File Icons in file-tree to Match Those in file-list and also in file-tree in pull request changed files. Optimize file icons in file-tree to match those in file-list and also in file-tree of pull request changed files. Mar 18, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
fix
@github-actions github-actions bot added the modifies/templates This PR modifies the template files label Mar 19, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@kerwin612
Copy link
Member Author

Perhaps it would be better to use Material Icons for the folder as well? The Material Icons for GitHub browser plugin follows this logic

This commit [888296b] is aimed at unifying the icons of folders on the UI.

before:
image

image

after:
image
image

@lunny lunny added this to the 1.24.0 milestone Mar 19, 2025
@lunny lunny added type/bug topic/ui Change the appearance of the Gitea UI skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features. labels Mar 19, 2025
@delvh delvh changed the title Optimize file icons in file-tree to match those in file-list and also in file-tree of pull request changed files. Also show file-specific icons in the PR file tree Mar 19, 2025
Comment on lines 80 to 83
entry, _ := headCommit.GetTreeEntryByPath(file.HeadPath)
if entry == nil {
entry, _ = baseCommit.GetTreeEntryByPath(file.HeadPath)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need this extra call to collect information?

The diff tree file should already have enough information: dir or not, submodule or not, etc.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After carefully reviewing the current code, I found that the file icons on the file list page are derived from RenderUtils.RenderFileIcon:

{{ctx.RenderUtils.RenderFileIcon $entry}}

func (ut *RenderUtils) RenderFileIcon(entry *git.TreeEntry) template.HTML {

To standardize the global file icons, we should unify their usage to RenderUtils.RenderFileIcon. Since this method requires a parameter of type TreeEntry, we need to obtain the entry object here.
I initially attempted to simplify the RenderFileIcon function by using only entryMode to retrieve the icon. However, after tracing and analysis, it was found that this approach is not feasible. The function's logic relies on multiple fields, making it more appropriate to use the entry object directly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Abstraction, if the diff tree files already provide enough information you need.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diff-files only provides name, isSubmodule, isViewed, status:

type FileDiffFile struct {
Name string
NameHash string
FileIcon template.HTML
IsSubmodule bool
IsViewed bool
Status string
}

type DiffTreeRecord struct {
// Status is one of 'added', 'deleted', 'modified', 'renamed', 'copied', 'typechanged', 'unmerged', 'unknown'
Status string
// For renames and copies, the percentage of similarity between the source and target of the move/rename.
Score uint8
HeadPath string
BasePath string
HeadMode git.EntryMode
BaseMode git.EntryMode
HeadBlobID string
BaseBlobID string
}

Meanwhile, RenderFileIcon involves entry.Name(), entry.entryMode(), and entry.FollowLink():

func BasicThemeIcon(entry *git.TreeEntry) template.HTML {
svgName := "octicon-file"
switch {
case entry.IsLink():
svgName = "octicon-file-symlink-file"
if te, err := entry.FollowLink(); err == nil && te.IsDir() {
svgName = "octicon-file-directory-symlink"
}
case entry.IsDir():
svgName = BasicThemeFolderIconName(false)
case entry.IsSubModule():
svgName = "octicon-file-submodule"
}
return svg.RenderHTML(svgName)
}

func (m *MaterialIconProvider) FileIcon(ctx reqctx.RequestContext, entry *git.TreeEntry) template.HTML {
if m.rules == nil {
return BasicThemeIcon(entry)
}
if entry.IsLink() {
if te, err := entry.FollowLink(); err == nil && te.IsDir() {
// keep the old "octicon-xxx" class name to make some "theme plugin selector" could still work
return svg.RenderHTML("material-folder-symlink", 16, "octicon-file-directory-symlink")
}
return svg.RenderHTML("octicon-file-symlink-file") // TODO: find some better icons for them
}
name := m.findIconNameByGit(entry)
if name == "folder" {
// the material icon pack's "folder" icon doesn't look good, so use our built-in one
// keep the old "octicon-xxx" class name to make some "theme plugin selector" could still work
return m.FolderIcon(ctx, false)
}
if iconSVG, ok := m.svgs[name]; ok && iconSVG != "" {
// keep the old "octicon-xxx" class name to make some "theme plugin selector" could still work
extraClass := "octicon-file"
switch {
case entry.IsDir():
extraClass = BasicThemeFolderIconName(false)
case entry.IsSubModule():
extraClass = "octicon-file-submodule"
}
return m.renderFileIconSVG(ctx, name, iconSVG, extraClass)
}
return svg.RenderHTML("octicon-file")
}

if te, err := entry.FollowLink(); err == nil && te.IsDir() {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diff-files only provides name, isSubmodule, isViewed, status:

Because current "diff tree list" only contains files. You could know whether it is a link by the diff tree item, and you don't need to know whether it is a dir or need to follow link, the frontend doesn't support it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please take another look at this commit to see if it aligns with your expectations for an appropriate solution?
4db35ba

Comment on lines 2 to 5
<script type="module">
window.config.pageData.folderIcon = {{ctx.RenderUtils.RenderFolderIcon false}};
window.config.pageData.openFolderIcon = {{ctx.RenderUtils.RenderFolderIcon true}};
</script>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why .........

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned earlier, in order to unify the icon sources (you can refer to the screenshots in the PR description. The "before" screenshot shows the current situation, and the "after" screenshot shows the situation after the modification, where the icon styles of folders have also been unified).

It is precisely this modification that enables the unification of folder icons.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you are trying to "unify the icon sources"

But why inline scripts?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this part involves the integration of templates and Vue components, and the icons are used within the Vue components, but RenderFileIcon cannot be directly used in the Vue components.
Therefore, i follow the common practice widely adopted in the current project:
① First, obtain the icon values in the template, and then cache them using pageData.
② Then, retrieve the icons from pageData in the Vue component.

<span v-else-if="isDirectory && !collapsed" class="item-icon" v-html="pageData.openFolderIcon"/>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think it is right.

You need to provide the open/closed icons for each entry item

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, this is truly the only implementation method that comes to my mind. 😅

fix
fix
fix
fix
fix
fix

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
fix
fix
@kerwin612 kerwin612 requested a review from wxiaoguang March 21, 2025 01:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. modifies/frontend modifies/go Pull requests that update Go code modifies/templates This PR modifies the template files size/L Denotes a PR that changes 100-499 lines, ignoring generated files. skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features. topic/ui Change the appearance of the Gitea UI type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add icons to the sidebar of the file list and diff list
5 participants