Skip to content

Commit

Permalink
Ensure default font size selected in Preferences
Browse files Browse the repository at this point in the history
This bug may have existed for a long time. In short the pop up button
does not select the default candidate font size (16 pt) when McBopomofo
is first installed. Since the user defaults are not yet populated, the
pop up button cannot find a value to select, and so an empty item is
added and selected instead. This commit fixes the issue.
  • Loading branch information
lukhnos committed Nov 24, 2023
1 parent b9009bf commit ff5a455
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Source/PreferencesWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,28 @@ fileprivate let kWindowTitleHeight: CGFloat = 78
window?.title = NSLocalizedString("Basic", comment: "")
use(view: basicSettingsView)

// When the `CandidateListTextSize` is not yet populated, the pop up
// button adds an empty item and selects that empty item. This code
// correctly sets the default text size, and removes the empty item
// at the end.
let selectedSizeTitle = fontSizePopUpButton.selectedItem?.title ?? ""
if selectedSizeTitle.isEmpty {
let intFontSizeStr = String.init(format: "%d", Int(Preferences.candidateListTextSize))
for item in fontSizePopUpButton.itemArray {
if item.title == intFontSizeStr {
fontSizePopUpButton.select(item)
break
}
}

let items = fontSizePopUpButton.itemArray
if let lastItem = items.last {
if lastItem.title.isEmpty {
fontSizePopUpButton.removeItem(at: items.count - 1)
}
}
}

let list = TISCreateInputSourceList(nil, true).takeRetainedValue() as! [TISInputSource]
var usKeyboardLayoutItem: NSMenuItem? = nil
var chosenItem: NSMenuItem? = nil
Expand Down

0 comments on commit ff5a455

Please sign in to comment.