@@ -9,11 +9,12 @@ import (
9
9
"strings"
10
10
"sync"
11
11
12
- "code.gitea.io/gitea/modules/git"
13
12
"code.gitea.io/gitea/modules/json"
14
13
"code.gitea.io/gitea/modules/log"
15
14
"code.gitea.io/gitea/modules/options"
15
+ "code.gitea.io/gitea/modules/setting"
16
16
"code.gitea.io/gitea/modules/svg"
17
+ "code.gitea.io/gitea/modules/util"
17
18
)
18
19
19
20
type materialIconRulesData struct {
@@ -69,41 +70,51 @@ func (m *MaterialIconProvider) renderFileIconSVG(p *RenderedIconPool, name, svg,
69
70
}
70
71
svgID := "svg-mfi-" + name
71
72
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
+ }
72
77
if p .IconSVGs [svgID ] == "" {
73
- p .IconSVGs [svgID ] = template . HTML ( `<svg id="` + svgID + `" ` + svgCommonAttrs + svg [ 4 :])
78
+ p .IconSVGs [svgID ] = svgHTML
74
79
}
75
80
return template .HTML (`<svg ` + svgCommonAttrs + `><use xlink:href="#` + svgID + `"></use></svg>` )
76
81
}
77
82
78
- func (m * MaterialIconProvider ) FileIcon (p * RenderedIconPool , entry * git. TreeEntry ) template.HTML {
83
+ func (m * MaterialIconProvider ) EntryIconHTML (p * RenderedIconPool , entry * EntryInfo ) template.HTML {
79
84
if m .rules == nil {
80
- return BasicThemeIcon (entry )
85
+ return BasicEntryIconHTML (entry )
81
86
}
82
87
83
- if entry .IsLink () {
84
- if te , err := entry .FollowLink (); err == nil && te .IsDir () {
88
+ if entry .EntryMode . IsLink () {
89
+ if entry .SymlinkToMode .IsDir () {
85
90
// keep the old "octicon-xxx" class name to make some "theme plugin selector" could still work
86
91
return svg .RenderHTML ("material-folder-symlink" , 16 , "octicon-file-directory-symlink" )
87
92
}
88
93
return svg .RenderHTML ("octicon-file-symlink-file" ) // TODO: find some better icons for them
89
94
}
90
95
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 )
102
106
}
103
- return m .renderFileIconSVG (p , name , iconSVG , extraClass )
104
107
}
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 )
107
118
}
108
119
109
120
func (m * MaterialIconProvider ) findIconNameWithLangID (s string ) string {
@@ -118,13 +129,17 @@ func (m *MaterialIconProvider) findIconNameWithLangID(s string) string {
118
129
return ""
119
130
}
120
131
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 () {
124
139
if s , ok := m .rules .FolderNames [fileNameLower ]; ok {
125
140
return s
126
141
}
127
- return "folder"
142
+ return util . Iif ( entry . IsOpen , "folder-open" , "folder" )
128
143
}
129
144
130
145
if s , ok := m .rules .FileNames [fileNameLower ]; ok {
@@ -146,10 +161,3 @@ func (m *MaterialIconProvider) FindIconName(name string, isDir bool) string {
146
161
147
162
return "file"
148
163
}
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