mirror of
https://github.com/akiyosi/goneovim.git
synced 2025-08-05 10:34:36 +02:00
Merge pull request #573 from akiyosi/improve_font_error
Improve font error display
This commit is contained in:
commit
229119cb69
2 changed files with 35 additions and 35 deletions
|
@ -109,7 +109,6 @@ type Editor struct {
|
|||
notifyStartPos *core.QPoint
|
||||
colors *ColorPalette
|
||||
notify chan *Notify
|
||||
fontCh chan []*Font
|
||||
cbChan chan *string
|
||||
chUiPrepared chan bool
|
||||
openingFileCh chan string
|
||||
|
@ -126,6 +125,8 @@ type Editor struct {
|
|||
opts Options
|
||||
font *Font
|
||||
fallbackfonts []*Font
|
||||
fontCh chan []*Font
|
||||
fontErrors []string
|
||||
notifications []*Notification
|
||||
workspaces []*Workspace
|
||||
args []string
|
||||
|
@ -256,6 +257,8 @@ func InitEditor(options Options, args []string) {
|
|||
e.app.SetDoubleClickInterval(0)
|
||||
e.putLog("finished generating the application")
|
||||
|
||||
e.initNotifications()
|
||||
|
||||
var cerr, lerr error
|
||||
e.initialColumns, cerr, e.initialLines, lerr = parseLinesAndColumns(args)
|
||||
if cerr == nil {
|
||||
|
@ -290,8 +293,6 @@ func InitEditor(options Options, args []string) {
|
|||
|
||||
e.initColorPalette()
|
||||
|
||||
e.initNotifications()
|
||||
|
||||
e.initSysTray()
|
||||
|
||||
e.initSpecialKeys()
|
||||
|
@ -456,15 +457,34 @@ func parseFont(families string, size int, weight string, stretch, linespace, let
|
|||
}
|
||||
|
||||
for _, f := range strings.Split(families, ",") {
|
||||
fonts = append(
|
||||
fonts,
|
||||
initFontNew(strings.TrimSpace(f), float64(size), fontWeight, stretch, linespace, letterspace),
|
||||
)
|
||||
font := initFontNew(strings.TrimSpace(f), float64(size), fontWeight, stretch, linespace, letterspace)
|
||||
fonts = append(fonts, font)
|
||||
|
||||
ok := checkValidFont(f)
|
||||
if !ok {
|
||||
editor.fontErrors = append(editor.fontErrors, f)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (e *Editor) showFontErrors() {
|
||||
if len(e.fontErrors) == 0 {
|
||||
return
|
||||
}
|
||||
for _, fontError := range e.fontErrors {
|
||||
go e.pushNotification(
|
||||
NotifyWarn,
|
||||
5,
|
||||
fmt.Sprintf("The specified font family '%s' was not found on this system.", fontError),
|
||||
notifyOptionArg([]*NotifyButton{}),
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// setAppDirPath
|
||||
// set application working directory path
|
||||
// TODO: This process is problematic and needs a better way to set up CWD
|
||||
|
|
|
@ -2123,6 +2123,7 @@ func (ws *Workspace) guiFont(args string) {
|
|||
ws.screen.fallbackfonts = nil
|
||||
|
||||
ws.parseAndApplyFont(args, &ws.screen.font, &ws.screen.fallbackfonts)
|
||||
editor.showFontErrors()
|
||||
ws.screen.purgeTextCacheForWins()
|
||||
|
||||
// When setting up a different font for a workspace other than the neovim drawing screen,
|
||||
|
@ -2182,13 +2183,12 @@ func (ws *Workspace) guiFontWide(args string) {
|
|||
}
|
||||
|
||||
func (ws *Workspace) parseAndApplyFont(str string, font *(*Font), fonts *([]*Font)) {
|
||||
errGfns := []string{}
|
||||
for i, gfn := range strings.Split(str, ",") {
|
||||
fontFamily, fontHeight, fontWeight, fontStretch := getFontFamilyAndHeightAndWeightAndStretch(gfn)
|
||||
|
||||
ok := checkValidFont(fontFamily)
|
||||
if !ok {
|
||||
errGfns = append(errGfns, fontFamily)
|
||||
editor.fontErrors = append(editor.fontErrors, fontFamily)
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -2217,23 +2217,6 @@ func (ws *Workspace) parseAndApplyFont(str string, font *(*Font), fonts *([]*Fon
|
|||
*fonts = append(*fonts, ff)
|
||||
}
|
||||
}
|
||||
|
||||
if len(errGfns) > 0 {
|
||||
s := ""
|
||||
for k, errgfn := range errGfns {
|
||||
s += "'" + errgfn + "'"
|
||||
if k < len(errGfns)-1 {
|
||||
s += ", "
|
||||
}
|
||||
}
|
||||
editor.pushNotification(
|
||||
NotifyWarn,
|
||||
4,
|
||||
fmt.Sprintf("The specified font family %s was not found on this system.", s),
|
||||
notifyOptionArg([]*NotifyButton{}),
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func getFontFamilyAndHeightAndWeightAndStretch(s string) (string, float64, gui.QFont__Weight, int) {
|
||||
|
@ -2295,22 +2278,19 @@ func getFontFamilyAndHeightAndWeightAndStretch(s string) (string, float64, gui.Q
|
|||
func checkValidFont(family string) bool {
|
||||
// f := gui.NewQFont2(family, 10.0, 1, false)
|
||||
f := gui.NewQFont()
|
||||
if editor.config.Editor.ManualFontFallback {
|
||||
f.SetStyleHint(gui.QFont__TypeWriter, gui.QFont__NoFontMerging)
|
||||
} else {
|
||||
f.SetStyleHint(gui.QFont__TypeWriter, gui.QFont__PreferDefault|gui.QFont__ForceIntegerMetrics)
|
||||
}
|
||||
|
||||
f.SetStyleHint(gui.QFont__TypeWriter, gui.QFont__NoFontMerging)
|
||||
f.SetFamily(family)
|
||||
f.SetPointSizeF(10.0)
|
||||
f.SetWeight(int(gui.QFont__Normal))
|
||||
|
||||
fi := gui.NewQFontInfo(f)
|
||||
|
||||
fname1 := fi.Family()
|
||||
fname2 := f.Family()
|
||||
|
||||
ret := strings.EqualFold(fname1, fname2)
|
||||
if !ret {
|
||||
editor.putLog(
|
||||
fmt.Sprintf("The specified font family '%s' was not found on this system.", family),
|
||||
)
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue