Select user's preferred mimetype in MessageViewer
This implements selecting the most preferred mimetype under the 'View->Alternatives' configuration setting when viewing a message. Mimetypes in the alternatives array are weighted by their position, where the lower the index in the array the higher the priority, so this is taken into account during selection. If no message part matches a mimetype in the alternatives array, then it selects the first mimetype in the message.
This commit is contained in:
parent
acfe7d7625
commit
dd178262bb
1 changed files with 13 additions and 2 deletions
|
@ -160,14 +160,25 @@ func createSwitcher(switcher *PartSwitcher, conf *config.AercConfig,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
switcher.selected = -1
|
selectedPriority := -1
|
||||||
for i, pv := range switcher.parts {
|
for i, pv := range switcher.parts {
|
||||||
pv.OnInvalidate(func(_ ui.Drawable) {
|
pv.OnInvalidate(func(_ ui.Drawable) {
|
||||||
switcher.Invalidate()
|
switcher.Invalidate()
|
||||||
})
|
})
|
||||||
// TODO: switch to user's preferred mimetype, if configured
|
// Switch to user's preferred mimetype
|
||||||
if switcher.selected == -1 && pv.part.MIMEType != "multipart" {
|
if switcher.selected == -1 && pv.part.MIMEType != "multipart" {
|
||||||
switcher.selected = i
|
switcher.selected = i
|
||||||
|
} else if selectedPriority == -1 {
|
||||||
|
for idx, m := range conf.Viewer.Alternatives {
|
||||||
|
if m != pv.part.MIMEType+"/"+pv.part.MIMESubType {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
priority := len(conf.Viewer.Alternatives) - idx
|
||||||
|
if priority > selectedPriority {
|
||||||
|
selectedPriority = priority
|
||||||
|
switcher.selected = i
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue