@@ -9,11 +9,12 @@ import (
99 "strings"
1010 "sync"
1111
12- "code.gitea.io/gitea/modules/git"
1312 "code.gitea.io/gitea/modules/json"
1413 "code.gitea.io/gitea/modules/log"
1514 "code.gitea.io/gitea/modules/options"
15+ "code.gitea.io/gitea/modules/setting"
1616 "code.gitea.io/gitea/modules/svg"
17+ "code.gitea.io/gitea/modules/util"
1718)
1819
1920type materialIconRulesData struct {
@@ -69,41 +70,51 @@ func (m *MaterialIconProvider) renderFileIconSVG(p *RenderedIconPool, name, svg,
6970 }
7071 svgID := "svg-mfi-" + name
7172 svgCommonAttrs := `class="svg git-entry-icon ` + extraClass + `" width="16" height="16" aria-hidden="true"`
73+ svgHTML := template .HTML (`<svg id="` + svgID + `" ` + svgCommonAttrs + svg [4 :])
74+ if p == nil {
75+ return svgHTML
76+ }
7277 if p .IconSVGs [svgID ] == "" {
73- p .IconSVGs [svgID ] = template . HTML ( `<svg id="` + svgID + `" ` + svgCommonAttrs + svg [ 4 :])
78+ p .IconSVGs [svgID ] = svgHTML
7479 }
7580 return template .HTML (`<svg ` + svgCommonAttrs + `><use xlink:href="#` + svgID + `"></use></svg>` )
7681}
7782
78- func (m * MaterialIconProvider ) FileIcon (p * RenderedIconPool , entry * git. TreeEntry ) template.HTML {
83+ func (m * MaterialIconProvider ) EntryIconHTML (p * RenderedIconPool , entry * EntryInfo ) template.HTML {
7984 if m .rules == nil {
80- return BasicThemeIcon (entry )
85+ return BasicEntryIconHTML (entry )
8186 }
8287
83- if entry .IsLink () {
84- if te , err := entry .FollowLink (); err == nil && te .IsDir () {
88+ if entry .EntryMode . IsLink () {
89+ if entry .SymlinkToMode .IsDir () {
8590 // keep the old "octicon-xxx" class name to make some "theme plugin selector" could still work
8691 return svg .RenderHTML ("material-folder-symlink" , 16 , "octicon-file-directory-symlink" )
8792 }
8893 return svg .RenderHTML ("octicon-file-symlink-file" ) // TODO: find some better icons for them
8994 }
9095
91- name := m .findIconNameByGit (entry )
92- // the material icon pack's "folder" icon doesn't look good, so use our built-in one
93- // keep the old "octicon-xxx" class name to make some "theme plugin selector" could still work
94- if iconSVG , ok := m .svgs [name ]; ok && name != "folder" && iconSVG != "" {
95- // keep the old "octicon-xxx" class name to make some "theme plugin selector" could still work
96- extraClass := "octicon-file"
97- switch {
98- case entry .IsDir ():
99- extraClass = "octicon-file-directory-fill"
100- case entry .IsSubModule ():
101- extraClass = "octicon-file-submodule"
96+ name := m .FindIconName (entry )
97+ iconSVG := m .svgs [name ]
98+ if iconSVG == "" {
99+ name = "file"
100+ if entry .EntryMode .IsDir () {
101+ name = util .Iif (entry .IsOpen , "folder-open" , "folder" )
102+ }
103+ iconSVG = m .svgs [name ]
104+ if iconSVG == "" {
105+ setting .PanicInDevOrTesting ("missing file icon for %s" , name )
102106 }
103- return m .renderFileIconSVG (p , name , iconSVG , extraClass )
104107 }
105- // TODO: use an interface or wrapper for git.Entry to make the code testable.
106- return BasicThemeIcon (entry )
108+
109+ // keep the old "octicon-xxx" class name to make some "theme plugin selector" could still work
110+ extraClass := "octicon-file"
111+ switch {
112+ case entry .EntryMode .IsDir ():
113+ extraClass = BasicEntryIconName (entry )
114+ case entry .EntryMode .IsSubModule ():
115+ extraClass = "octicon-file-submodule"
116+ }
117+ return m .renderFileIconSVG (p , name , iconSVG , extraClass )
107118}
108119
109120func (m * MaterialIconProvider ) findIconNameWithLangID (s string ) string {
@@ -118,13 +129,17 @@ func (m *MaterialIconProvider) findIconNameWithLangID(s string) string {
118129 return ""
119130}
120131
121- func (m * MaterialIconProvider ) FindIconName (name string , isDir bool ) string {
122- fileNameLower := strings .ToLower (path .Base (name ))
123- if isDir {
132+ func (m * MaterialIconProvider ) FindIconName (entry * EntryInfo ) string {
133+ if entry .EntryMode .IsSubModule () {
134+ return "folder-git"
135+ }
136+
137+ fileNameLower := strings .ToLower (path .Base (entry .FullName ))
138+ if entry .EntryMode .IsDir () {
124139 if s , ok := m .rules .FolderNames [fileNameLower ]; ok {
125140 return s
126141 }
127- return "folder"
142+ return util . Iif ( entry . IsOpen , "folder-open" , "folder" )
128143 }
129144
130145 if s , ok := m .rules .FileNames [fileNameLower ]; ok {
@@ -146,10 +161,3 @@ func (m *MaterialIconProvider) FindIconName(name string, isDir bool) string {
146161
147162 return "file"
148163}
149-
150- func (m * MaterialIconProvider ) findIconNameByGit (entry * git.TreeEntry ) string {
151- if entry .IsSubModule () {
152- return "folder-git"
153- }
154- return m .FindIconName (entry .Name (), entry .IsDir ())
155- }
0 commit comments