-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
base: main
Are you sure you want to change the base?
Conversation
This commit [888296b] is aimed at unifying the icons of folders on the UI. |
routers/web/repo/treelist.go
Outdated
entry, _ := headCommit.GetTreeEntryByPath(file.HeadPath) | ||
if entry == nil { | ||
entry, _ = baseCommit.GetTreeEntryByPath(file.HeadPath) | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
:
gitea/templates/repo/view_list.tmpl
Line 18 in d3c7992
{{ctx.RenderUtils.RenderFileIcon $entry}} |
gitea/modules/templates/util_render.go
Line 191 in d3c7992
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
gitea/routers/web/repo/treelist.go
Lines 62 to 69 in d98cae2
type FileDiffFile struct { | |
Name string | |
NameHash string | |
FileIcon template.HTML | |
IsSubmodule bool | |
IsViewed bool | |
Status string | |
} |
gitea/services/gitdiff/git_diff_tree.go
Lines 22 to 35 in d98cae2
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()
:
gitea/modules/fileicon/basic.go
Lines 24 to 38 in d98cae2
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) | |
} |
gitea/modules/fileicon/material.go
Lines 92 to 123 in d98cae2
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") | |
} |
gitea/modules/fileicon/material.go
Line 98 in d98cae2
if te, err := entry.FollowLink(); err == nil && te.IsDir() { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
templates/repo/view.tmpl
Outdated
<script type="module"> | ||
window.config.pageData.folderIcon = {{ctx.RenderUtils.RenderFolderIcon false}}; | ||
window.config.pageData.openFolderIcon = {{ctx.RenderUtils.RenderFolderIcon true}}; | ||
</script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why .........
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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"/> |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 #33914
before:

after:
