Improve theme picker
Signed-off-by: Minecon724 <minecon724@noreply.git.m724.eu>
This commit is contained in:
parent
d986f7134f
commit
072688f419
3 changed files with 25 additions and 4 deletions
|
@ -16,6 +16,8 @@ const (
|
||||||
key string = "load-themes"
|
key string = "load-themes"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var FriendlyThemes map[string]string
|
||||||
|
|
||||||
var (
|
var (
|
||||||
group singleflight.Group
|
group singleflight.Group
|
||||||
assetFs *assetfs.LayeredFS
|
assetFs *assetfs.LayeredFS
|
||||||
|
@ -42,6 +44,7 @@ func LoadThemes() error {
|
||||||
group.Forget(key)
|
group.Forget(key)
|
||||||
} else {
|
} else {
|
||||||
setting.UI.Themes = themes
|
setting.UI.Themes = themes
|
||||||
|
FriendlyThemes = convertToFriendly(themes)
|
||||||
loaded = true
|
loaded = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,3 +81,20 @@ func loadThemesInner(assetFs *assetfs.LayeredFS) ([]string, error) {
|
||||||
return nil, fmt.Errorf("no themes found")
|
return nil, fmt.Errorf("no themes found")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func convertToFriendly(themes []string) map[string]string {
|
||||||
|
themesFriendly := make(map[string]string)
|
||||||
|
|
||||||
|
for _, theme := range themes {
|
||||||
|
friendly := theme
|
||||||
|
|
||||||
|
friendly = strings.ReplaceAll(friendly, "-", " ")
|
||||||
|
|
||||||
|
friendly = strings.ToLower(friendly)
|
||||||
|
friendly = strings.Title(friendly)
|
||||||
|
|
||||||
|
themesFriendly[theme] = friendly
|
||||||
|
}
|
||||||
|
|
||||||
|
return themesFriendly
|
||||||
|
}
|
||||||
|
|
|
@ -332,6 +332,7 @@ func Appearance(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Data["AllThemes"] = setting.UI.Themes
|
ctx.Data["AllThemes"] = setting.UI.Themes
|
||||||
|
ctx.Data["FriendlyThemes"] = theme.FriendlyThemes
|
||||||
|
|
||||||
ctx.Data["Title"] = ctx.Tr("settings.appearance")
|
ctx.Data["Title"] = ctx.Tr("settings.appearance")
|
||||||
ctx.Data["PageIsSettingsAppearance"] = true
|
ctx.Data["PageIsSettingsAppearance"] = true
|
||||||
|
|
|
@ -15,19 +15,19 @@
|
||||||
{{.CsrfTokenHtml}}
|
{{.CsrfTokenHtml}}
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label for="ui">{{ctx.Locale.Tr "settings.ui"}}</label>
|
<label for="ui">{{ctx.Locale.Tr "settings.ui"}}</label>
|
||||||
<div class="ui selection dropdown" id="ui">
|
<div class="ui search selection dropdown" id="ui">
|
||||||
<input name="theme" type="hidden" value="{{.SignedUser.Theme}}">
|
<input name="theme" type="hidden" value="{{.SignedUser.Theme}}">
|
||||||
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
|
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
|
||||||
<div class="text">
|
<div class="text">
|
||||||
{{range $i,$a := .AllThemes}}
|
{{range $i,$a := .AllThemes}}
|
||||||
{{if eq $.SignedUser.Theme $a}}{{$a}}{{end}}
|
{{if eq $.SignedUser.Theme $a}}{{index $.FriendlyThemes $a}}{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="menu">
|
<div class="menu">
|
||||||
{{range $i,$a := .AllThemes}}
|
{{range $i,$a := .AllThemes}}
|
||||||
<div class="item{{if eq $.SignedUser.Theme $a}} active selected{{end}}" data-value="{{$a}}">
|
<div class="item{{if eq $.SignedUser.Theme $a}} active selected{{end}}" data-value="{{$a}}">
|
||||||
{{$a}}
|
{{index $.FriendlyThemes $a}}
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
|
@ -52,7 +52,7 @@
|
||||||
</div>
|
</div>
|
||||||
{{.CsrfTokenHtml}}
|
{{.CsrfTokenHtml}}
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<div class="ui language selection dropdown" id="language">
|
<div class="ui search language selection dropdown" id="language">
|
||||||
<input name="language" type="hidden" value="{{.SignedUser.Language}}">
|
<input name="language" type="hidden" value="{{.SignedUser.Language}}">
|
||||||
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
|
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
|
||||||
<div class="text">{{range .AllLangs}}{{if eq $.SignedUser.Language .Lang}}{{.Name}}{{end}}{{end}}</div>
|
<div class="text">{{range .AllLangs}}{{if eq $.SignedUser.Language .Lang}}{{.Name}}{{end}}{{end}}</div>
|
||||||
|
|
Loading…
Add table
Reference in a new issue