mirror of
https://github.com/go-gitea/gitea.git
synced 2025-07-24 10:44:32 -04:00
Update the hard-coded "octicon-file-directory-fill" to follow the configured icon.
This commit is contained in:
parent
cfa983eeea
commit
f8efcb9986
@ -17,6 +17,10 @@ func BasicThemeFolderIconName(isOpen bool) string {
|
||||
return "octicon-file-directory-fill"
|
||||
}
|
||||
|
||||
func BasicThemeFolderIconWithOpenStatus(isOpen bool) template.HTML {
|
||||
return svg.RenderHTML(BasicThemeFolderIconName(isOpen))
|
||||
}
|
||||
|
||||
func BasicThemeIconWithOpenStatus(entry *git.TreeEntry, isOpen bool) template.HTML {
|
||||
// TODO: add "open icon" support
|
||||
svgName := "octicon-file"
|
||||
|
@ -69,12 +69,17 @@ func (m *MaterialIconProvider) renderFileIconSVG(p *RenderedIconPool, name, svg,
|
||||
}
|
||||
svgID := "svg-mfi-" + name
|
||||
svgCommonAttrs := `class="svg git-entry-icon ` + extraClass + `" width="16" height="16" aria-hidden="true"`
|
||||
if p.IconSVGs[svgID] == "" {
|
||||
if p != nil && p.IconSVGs[svgID] == "" {
|
||||
p.IconSVGs[svgID] = template.HTML(`<svg id="` + svgID + `" ` + svgCommonAttrs + svg[4:])
|
||||
}
|
||||
return template.HTML(`<svg ` + svgCommonAttrs + `><use xlink:href="#` + svgID + `"></use></svg>`)
|
||||
}
|
||||
|
||||
func (m *MaterialIconProvider) FolderIconWithOpenStatus(p *RenderedIconPool, isOpen bool) template.HTML {
|
||||
name := m.FindIconName("folder", true, isOpen)
|
||||
return m.renderFileIconSVG(p, name, m.svgs[name], BasicThemeFolderIconName(isOpen))
|
||||
}
|
||||
|
||||
func (m *MaterialIconProvider) FileIconWithOpenStatus(p *RenderedIconPool, entry *git.TreeEntry, isOpen bool) template.HTML {
|
||||
if m.rules == nil {
|
||||
return BasicThemeIconWithOpenStatus(entry, isOpen)
|
||||
@ -89,10 +94,10 @@ func (m *MaterialIconProvider) FileIconWithOpenStatus(p *RenderedIconPool, entry
|
||||
}
|
||||
|
||||
// TODO: add "open icon" support
|
||||
name := m.findIconNameByGit(entry)
|
||||
name := m.findIconNameByGit(entry, isOpen)
|
||||
// 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
|
||||
if iconSVG, ok := m.svgs[name]; ok && name != "folder" && iconSVG != "" {
|
||||
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 {
|
||||
@ -119,12 +124,15 @@ func (m *MaterialIconProvider) findIconNameWithLangID(s string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *MaterialIconProvider) FindIconName(name string, isDir bool) string {
|
||||
func (m *MaterialIconProvider) FindIconName(name string, isDir, isOpen bool) string {
|
||||
fileNameLower := strings.ToLower(path.Base(name))
|
||||
if isDir {
|
||||
if s, ok := m.rules.FolderNames[fileNameLower]; ok {
|
||||
return s
|
||||
}
|
||||
if isOpen {
|
||||
return "folder-open"
|
||||
}
|
||||
return "folder"
|
||||
}
|
||||
|
||||
@ -148,9 +156,9 @@ func (m *MaterialIconProvider) FindIconName(name string, isDir bool) string {
|
||||
return "file"
|
||||
}
|
||||
|
||||
func (m *MaterialIconProvider) findIconNameByGit(entry *git.TreeEntry) string {
|
||||
func (m *MaterialIconProvider) findIconNameByGit(entry *git.TreeEntry, isOpen bool) string {
|
||||
if entry.IsSubModule() {
|
||||
return "folder-git"
|
||||
}
|
||||
return m.FindIconName(entry.Name(), entry.IsDir())
|
||||
return m.FindIconName(entry.Name(), entry.IsDir(), isOpen)
|
||||
}
|
||||
|
@ -19,8 +19,8 @@ func TestMain(m *testing.M) {
|
||||
func TestFindIconName(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
p := fileicon.DefaultMaterialIconProvider()
|
||||
assert.Equal(t, "php", p.FindIconName("foo.php", false))
|
||||
assert.Equal(t, "php", p.FindIconName("foo.PHP", false))
|
||||
assert.Equal(t, "javascript", p.FindIconName("foo.js", false))
|
||||
assert.Equal(t, "visualstudio", p.FindIconName("foo.vba", false))
|
||||
assert.Equal(t, "php", p.FindIconName("foo.php", false, false))
|
||||
assert.Equal(t, "php", p.FindIconName("foo.PHP", false, false))
|
||||
assert.Equal(t, "javascript", p.FindIconName("foo.js", false, false))
|
||||
assert.Equal(t, "visualstudio", p.FindIconName("foo.vba", false, false))
|
||||
}
|
||||
|
@ -59,11 +59,12 @@ func NewFuncMap() template.FuncMap {
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
// svg / avatar / icon / color
|
||||
"svg": svg.RenderHTML,
|
||||
"MigrationIcon": migrationIcon,
|
||||
"ActionIcon": actionIcon,
|
||||
"SortArrow": sortArrow,
|
||||
"ContrastColor": util.ContrastColor,
|
||||
"svg": svg.RenderHTML,
|
||||
"folderIconHTMLByOpenStatus": folderIconHTMLByOpenStatus,
|
||||
"MigrationIcon": migrationIcon,
|
||||
"ActionIcon": actionIcon,
|
||||
"SortArrow": sortArrow,
|
||||
"ContrastColor": util.ContrastColor,
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
// time / number / format
|
||||
|
@ -14,11 +14,13 @@ import (
|
||||
|
||||
activities_model "code.gitea.io/gitea/models/activities"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/modules/fileicon"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
giturl "code.gitea.io/gitea/modules/git/url"
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/repository"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/svg"
|
||||
|
||||
"github.com/editorconfig/editorconfig-core-go/v2"
|
||||
@ -192,3 +194,10 @@ func tabSizeClass(ec *editorconfig.Editorconfig, filename string) string {
|
||||
}
|
||||
return "tab-size-4"
|
||||
}
|
||||
|
||||
func folderIconHTMLByOpenStatus(isOpen bool) template.HTML {
|
||||
if setting.UI.FileIconTheme == "material" {
|
||||
return fileicon.DefaultMaterialIconProvider().FolderIconWithOpenStatus(nil, isOpen)
|
||||
}
|
||||
return fileicon.BasicThemeFolderIconWithOpenStatus(isOpen)
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
</div>
|
||||
{{if .HasParentPath}}
|
||||
<a class="repo-file-line parent-link silenced" href="{{.BranchLink}}{{if .ParentPath}}{{PathEscapeSegments .ParentPath}}{{end}}">
|
||||
{{svg "octicon-file-directory-fill"}} ..
|
||||
{{folderIconHTMLByOpenStatus false}} ..
|
||||
</a>
|
||||
{{end}}
|
||||
{{$.FileIconPoolHTML}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user