mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-13 04:09:25 +00:00
we should always be able to remove a lexical model
LexicalModelPickerViewController can be used to view all LMs or just those for a language In language settings, don't assume the current model is relevant to this language launch the LexicalModelsView from language settings, not the LM Info view directly remember the user's chosen currentLexicalModelID if no preference, register the first one
This commit is contained in:
parent
337c3128dd
commit
7fa69b2d5d
3 changed files with 67 additions and 21 deletions
|
|
@ -15,6 +15,7 @@ private let toolbarActivityIndicatorTag = 102
|
|||
|
||||
class LexicalModelPickerViewController: UITableViewController, UIAlertViewDelegate {
|
||||
private var userLexicalModels: [InstallableLexicalModel] = [InstallableLexicalModel]()
|
||||
public var language: Language? = nil
|
||||
private var updateQueue: [InstallableLexicalModel]?
|
||||
private var _isDoneButtonEnabled = false
|
||||
private var isDidUpdateCheck = false
|
||||
|
|
@ -112,13 +113,7 @@ class LexicalModelPickerViewController: UITableViewController, UIAlertViewDelega
|
|||
return false
|
||||
}
|
||||
|
||||
if !Manager.shared.canRemoveDefaultLexicalModel {
|
||||
return indexPath.row != 0
|
||||
}
|
||||
if indexPath.row > 0 {
|
||||
return true
|
||||
}
|
||||
return userLexicalModels.count > 1
|
||||
return true
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle,
|
||||
|
|
@ -127,7 +122,8 @@ class LexicalModelPickerViewController: UITableViewController, UIAlertViewDelega
|
|||
return
|
||||
}
|
||||
|
||||
if Manager.shared.removeLexicalModel(at: indexPath.row) {
|
||||
let globalIndex = local2globalIndex(indexPath.row)
|
||||
if Manager.shared.removeLexicalModel(at: globalIndex) {
|
||||
loadUserLexicalModels()
|
||||
}
|
||||
setIsDoneButtonEnabled(true)
|
||||
|
|
@ -146,7 +142,7 @@ class LexicalModelPickerViewController: UITableViewController, UIAlertViewDelega
|
|||
let infoView = LexicalModelInfoViewController()
|
||||
infoView.title = lm.name
|
||||
infoView.lexicalModelCount = userLexicalModels.count
|
||||
infoView.lexicalModelIndex = index
|
||||
infoView.lexicalModelIndex = local2globalIndex(index)
|
||||
infoView.lexicalModelID = lm.id
|
||||
infoView.languageID = lm.languageID
|
||||
infoView.lexicalModelVersion = version
|
||||
|
|
@ -167,7 +163,7 @@ class LexicalModelPickerViewController: UITableViewController, UIAlertViewDelega
|
|||
if Manager.shared.currentLexicalModelID == lm.fullID {
|
||||
cell.selectionStyle = .blue
|
||||
cell.isSelected = true
|
||||
cell.accessoryType = .detailDisclosureButton
|
||||
cell.accessoryType = .checkmark
|
||||
} else {
|
||||
cell.selectionStyle = .none
|
||||
cell.isSelected = false
|
||||
|
|
@ -179,6 +175,19 @@ class LexicalModelPickerViewController: UITableViewController, UIAlertViewDelega
|
|||
switchLexicalModel(indexPath.row)
|
||||
}
|
||||
|
||||
func local2globalIndex(_ localIndex: Int) -> Int {
|
||||
let globalIndex: Int
|
||||
if let lang = self.language {
|
||||
let lm = userLexicalModels[localIndex]
|
||||
globalIndex = Storage.active.userDefaults.userLexicalModels?.firstIndex(where: {
|
||||
$0.languageID == lang.id && $0.id == lm.id
|
||||
}) ?? 0
|
||||
} else {
|
||||
globalIndex = localIndex
|
||||
}
|
||||
return globalIndex
|
||||
}
|
||||
|
||||
private func lexicalModelDownloadStarted(_ lexicalModels: [InstallableLexicalModel]) {
|
||||
view.isUserInteractionEnabled = false
|
||||
navigationItem.leftBarButtonItem?.isEnabled = false
|
||||
|
|
@ -275,8 +284,15 @@ class LexicalModelPickerViewController: UITableViewController, UIAlertViewDelega
|
|||
}
|
||||
}
|
||||
|
||||
// if we have a language set, filter models down to those of that language
|
||||
private func loadUserLexicalModels() {
|
||||
userLexicalModels = Storage.active.userDefaults.userLexicalModels ?? []
|
||||
if let lang = self.language {
|
||||
userLexicalModels = Storage.active.userDefaults.userLexicalModels?.filter({
|
||||
$0.languageID == lang.id
|
||||
}) ?? []
|
||||
} else {
|
||||
userLexicalModels = Storage.active.userDefaults.userLexicalModels ?? []
|
||||
}
|
||||
tableView.reloadData()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -134,7 +134,24 @@ public class Manager: NSObject, HTTPDownloadDelegate, UIGestureRecognizerDelegat
|
|||
public var openURL: ((URL) -> Bool)?
|
||||
|
||||
var currentKeyboardID: FullKeyboardID?
|
||||
var currentLexicalModelID: FullLexicalModelID?
|
||||
private var _currentLexicalModelID: FullLexicalModelID?
|
||||
var currentLexicalModelID: FullLexicalModelID? {
|
||||
get {
|
||||
if _currentLexicalModelID == nil {
|
||||
let userData = Util.isSystemKeyboard ? UserDefaults.standard : Storage.active.userDefaults
|
||||
_currentLexicalModelID = userData.currentLexicalModelID
|
||||
}
|
||||
return _currentLexicalModelID
|
||||
}
|
||||
|
||||
set(value) {
|
||||
_currentLexicalModelID = value
|
||||
let userData = Util.isSystemKeyboard ? UserDefaults.standard : Storage.active.userDefaults
|
||||
userData.currentLexicalModelID = _currentLexicalModelID
|
||||
userData.synchronize()
|
||||
}
|
||||
}
|
||||
|
||||
var currentRequest: HTTPDownloadRequest?
|
||||
var shouldReloadKeyboard = false
|
||||
var shouldReloadLexicalModel = false
|
||||
|
|
@ -280,8 +297,11 @@ public class Manager: NSObject, HTTPDownloadDelegate, UIGestureRecognizerDelegat
|
|||
// If we have a lexical model for the keyboard's language, activate it.
|
||||
if let valid_models = Storage.active.userDefaults.userLexicalModels(forLanguage: kb.languageID) {
|
||||
if valid_models.count > 0 {
|
||||
//let lm = Storage.active.userDefaults.userLexicalModel(withFullID: valid_models[0].fullID)!
|
||||
_ = Manager.shared.registerLexicalModel(valid_models[0])
|
||||
if let lm = self.currentLexicalModel {
|
||||
_ = Manager.shared.registerLexicalModel(lm)
|
||||
} else {
|
||||
_ = Manager.shared.registerLexicalModel(valid_models[0])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -338,10 +358,6 @@ public class Manager: NSObject, HTTPDownloadDelegate, UIGestureRecognizerDelegat
|
|||
|
||||
inputViewController.registerLexicalModel(lm)
|
||||
|
||||
let userData = Util.isSystemKeyboard ? UserDefaults.standard : Storage.active.userDefaults
|
||||
userData.currentLexicalModelID = lm.fullID
|
||||
userData.synchronize()
|
||||
|
||||
if isKeymanHelpOn {
|
||||
inputViewController.showHelpBubble(afterDelay: 1.5)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -125,8 +125,15 @@ class LanguageSettingsViewController: UITableViewController {
|
|||
case 2:
|
||||
cell.textLabel?.text = "Model"
|
||||
cell.accessoryType = .disclosureIndicator
|
||||
if let currentModel = language.lexicalModels?[safe: 0] {
|
||||
cell.detailTextLabel?.text = currentModel.name
|
||||
if let currentModel = Manager.shared.currentLexicalModel {
|
||||
// if language.id == currentModel.id {
|
||||
if language.lexicalModels?.contains(where: {
|
||||
$0.id == currentModel.id
|
||||
}) ?? false {
|
||||
cell.detailTextLabel?.text = currentModel.name
|
||||
} else {
|
||||
cell.detailTextLabel?.text = "<current model is not for this language>"
|
||||
}
|
||||
} else {
|
||||
cell.detailTextLabel?.text = "<no current model>"
|
||||
}
|
||||
|
|
@ -153,7 +160,7 @@ class LanguageSettingsViewController: UITableViewController {
|
|||
case 1:
|
||||
switch indexPath.row {
|
||||
case 2:
|
||||
showLexicalModelInfoView()
|
||||
showLexicalModelsView()
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
|
@ -195,6 +202,13 @@ class LanguageSettingsViewController: UITableViewController {
|
|||
}
|
||||
}
|
||||
|
||||
func showLexicalModelsView() {
|
||||
//LanguageLexicalModelPickerViewController? (should show just the models for this language)
|
||||
let lmListView = LexicalModelPickerViewController()
|
||||
lmListView.language = self.language
|
||||
navigationController?.pushViewController(lmListView, animated: true)
|
||||
}
|
||||
|
||||
func showLexicalModelInfoView() {
|
||||
if let lm = language.lexicalModels?[safe: 0] {
|
||||
let version = lm.version
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue