diff --git a/modules/fileicon/material.go b/modules/fileicon/material.go index adea625c06..aa31cd8d7c 100644 --- a/modules/fileicon/material.go +++ b/modules/fileicon/material.go @@ -62,7 +62,7 @@ func (m *MaterialIconProvider) loadData() { log.Debug("Loaded material icon rules and SVG images") } -func (m *MaterialIconProvider) renderFileIconSVG(ctx reqctx.RequestContext, name, svg string) template.HTML { +func (m *MaterialIconProvider) renderFileIconSVG(ctx reqctx.RequestContext, name, svg, extraClass string) template.HTML { data := ctx.GetData() renderedSVGs, _ := data["_RenderedSVGs"].(map[string]bool) if renderedSVGs == nil { @@ -75,7 +75,7 @@ func (m *MaterialIconProvider) renderFileIconSVG(ctx reqctx.RequestContext, name panic("Invalid SVG icon") } svgID := "svg-mfi-" + name - svgCommonAttrs := `class="svg fileicon" width="16" height="16" aria-hidden="true"` + svgCommonAttrs := `class="svg git-entry-icon ` + extraClass + `" width="16" height="16" aria-hidden="true"` posOuterBefore := strings.IndexByte(svg, '>') if renderedSVGs[svgID] && posOuterBefore != -1 { return template.HTML(``) @@ -92,7 +92,8 @@ func (m *MaterialIconProvider) FileIcon(ctx reqctx.RequestContext, entry *git.Tr if entry.IsLink() { if te, err := entry.FollowLink(); err == nil && te.IsDir() { - return svg.RenderHTML("material-folder-symlink") + // 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 } @@ -100,10 +101,19 @@ func (m *MaterialIconProvider) FileIcon(ctx reqctx.RequestContext, entry *git.Tr name := m.findIconNameByGit(entry) if name == "folder" { // the material icon pack's "folder" icon doesn't look good, so use our built-in one - return svg.RenderHTML("material-folder-generic") + // keep the old "octicon-xxx" class name to make some "theme plugin selector" could still work + return svg.RenderHTML("material-folder-generic", 16, "octicon-file-directory-fill") } if iconSVG, ok := m.svgs[name]; ok && iconSVG != "" { - return m.renderFileIconSVG(ctx, name, 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 = "octicon-file-directory-fill" + case entry.IsSubModule(): + extraClass = "octicon-file-submodule" + } + return m.renderFileIconSVG(ctx, name, iconSVG, extraClass) } return svg.RenderHTML("octicon-file") } diff --git a/web_src/css/modules/svg.css b/web_src/css/modules/svg.css index 432a321d59..738ec22cd3 100644 --- a/web_src/css/modules/svg.css +++ b/web_src/css/modules/svg.css @@ -4,7 +4,7 @@ fill: currentcolor; } -.svg.fileicon { +.svg.git-entry-icon { fill: transparent; /* some material icons have dark background fill, so need to reset */ }