From d01b7546988fb0a42b6e34fcc73f1023be371b51 Mon Sep 17 00:00:00 2001 From: Jag-Marcel Date: Tue, 13 Aug 2024 13:41:17 +0200 Subject: [PATCH] Added conjugation functionality to EN keyboard --- .../KeyboardViewController.swift | 93 +++++++++++++-- .../CommandVariables.swift | 2 +- .../ScribeFunctionality/Conjugate.swift | 35 +++++- .../English/ENCommandVariables.swift | 109 +++++++++++++++++- .../English/ENInterfaceVariables.swift | 8 +- 5 files changed, 227 insertions(+), 20 deletions(-) diff --git a/Keyboards/KeyboardsBase/KeyboardViewController.swift b/Keyboards/KeyboardsBase/KeyboardViewController.swift index 36985824..f4f19efc 100644 --- a/Keyboards/KeyboardsBase/KeyboardViewController.swift +++ b/Keyboards/KeyboardsBase/KeyboardViewController.swift @@ -1264,6 +1264,15 @@ class KeyboardViewController: UIInputViewController { .genitiveDefinite, .genitiveIndefinite, .genitiveDemonstrative ].contains(deCaseDeclensionState) { formsDisplayDimensions = .view2x2 + } else if controllerLanguage == "English" { + switch enConjugationState { + case .present, .presCont, .past, .future, .conditional: + formsDisplayDimensions = .view2x2 + case .presSimp, .presPerf, .presPerfCont: + formsDisplayDimensions = .view1x2 + case .pastCont: + formsDisplayDimensions = .view3x1 + } } else if commandState == .displayInformation { formsDisplayDimensions = .view1x1 } else { @@ -1423,7 +1432,7 @@ class KeyboardViewController: UIInputViewController { conjugationStateFxn = conjugationFxn } - if !["Russian", "Swedish"].contains(controllerLanguage) { + if !["English", "Russian", "Swedish"].contains(controllerLanguage) { formFPS = conjugationStateFxn() + "FPS" formSPS = conjugationStateFxn() + "SPS" formTPS = conjugationStateFxn() + "TPS" @@ -1451,6 +1460,24 @@ class KeyboardViewController: UIInputViewController { formTopRight = swedishTenses[1] formBottomLeft = swedishTenses[2] formBottomRight = swedishTenses[3] + } else if controllerLanguage == "English" { + if formsDisplayDimensions == .view2x2 { + let englishTenses = enGetConjugationState() + + formTopLeft = englishTenses[0] + formTopRight = englishTenses[1] + formBottomLeft = englishTenses[2] + formBottomRight = englishTenses[3] + } else if formsDisplayDimensions == .view1x2 { + let englishTenses = enGetConjugationState() + + formLeft = englishTenses[0] + formRight = englishTenses[1] + } else if formsDisplayDimensions == .view3x1 { + formTop = "presPart" + formMiddle = "pastSimpCont" + formBottom = "pastSimpPluralCont" + } } } @@ -1481,7 +1508,6 @@ class KeyboardViewController: UIInputViewController { } // Assign labels that have been set by SetConjugationLabels function. - // Other labels not assigned as they're not used in conjugation at this time. formLblFPS.setTitle(" " + (formLabelsDict["FPS"] ?? ""), for: .normal) formLblSPS.setTitle(" " + (formLabelsDict["SPS"] ?? ""), for: .normal) formLblTPS.setTitle(" " + (formLabelsDict["TPS"] ?? ""), for: .normal) @@ -1489,17 +1515,33 @@ class KeyboardViewController: UIInputViewController { formLblSPP.setTitle(" " + (formLabelsDict["SPP"] ?? ""), for: .normal) formLblTPP.setTitle(" " + (formLabelsDict["TPP"] ?? ""), for: .normal) + formLblTop.setTitle(" " + (formLabelsDict["Top"] ?? ""), for: .normal) + formLblMiddle.setTitle(" " + (formLabelsDict["Middle"] ?? ""), for: .normal) + formLblBottom.setTitle(" " + (formLabelsDict["Bottom"] ?? ""), for: .normal) + formLblTL.setTitle(" " + (formLabelsDict["TL"] ?? ""), for: .normal) formLblTR.setTitle(" " + (formLabelsDict["TR"] ?? ""), for: .normal) formLblBL.setTitle(" " + (formLabelsDict["BL"] ?? ""), for: .normal) formLblBR.setTitle(" " + (formLabelsDict["BR"] ?? ""), for: .normal) - if formsDisplayDimensions == .view3x2 { + formLblLeft.setTitle(" " + (formLabelsDict["Left"] ?? ""), for: .normal) + formLblRight.setTitle(" " + (formLabelsDict["Right"] ?? ""), for: .normal) + + switch formsDisplayDimensions { + case .view3x2: allConjugations = [formFPS, formSPS, formTPS, formFPP, formSPP, formTPP] allConjugationBtns = get3x2FormDisplayButtons() - } else { + case .view3x1: + allConjugations = [formTop, formMiddle, formBottom] + allConjugationBtns = get3x1FormDisplayButtons() + case .view2x2: allConjugations = [formTopLeft, formTopRight, formBottomLeft, formBottomRight] allConjugationBtns = get2x2FormDisplayButtons() + case .view1x2: + allConjugations = [formLeft, formRight] + allConjugationBtns = get1x2FormDisplayButtons() + case .view1x1: + break } // Populate conjugation view buttons. @@ -1511,8 +1553,12 @@ class KeyboardViewController: UIInputViewController { styleBtn(btn: allConjugationBtns[index], title: invalidCommandMsg, radius: keyCornerRadius) } else { conjugationToDisplay = conjugationsToDisplay[index] - if inputWordIsCapitalized && deConjugationState != .indicativePerfect { - conjugationToDisplay = conjugationToDisplay.capitalized + if inputWordIsCapitalized { + if controllerLanguage == "English", conjugationToDisplay.count(of: " ") > 0 { + conjugationToDisplay = conjugationToDisplay.capitalize() + } else if deConjugationState != .indicativePerfect { + conjugationToDisplay = conjugationToDisplay.capitalized + } } styleBtn(btn: allConjugationBtns[index], title: conjugationToDisplay, radius: keyCornerRadius) } @@ -2411,19 +2457,46 @@ class KeyboardViewController: UIInputViewController { loadKeys() case "formTopLeft": - returnConjugation(keyPressed: sender, requestedForm: formTopLeft) + if controllerLanguage == "English" && enConjugationState == .present { + enConjugationState = .presSimp + conjViewShiftButtonsState = .bothInactive + } else { + returnConjugation(keyPressed: sender, requestedForm: formTopLeft) + } loadKeys() case "formTopRight": - returnConjugation(keyPressed: sender, requestedForm: formTopRight) + if controllerLanguage == "English" { + if enConjugationState == .present { + enConjugationState = .presCont + conjViewShiftButtonsState = .bothInactive + } else if enConjugationState == .past { + enConjugationState = .pastCont + conjViewShiftButtonsState = .bothInactive + } else { + returnConjugation(keyPressed: sender, requestedForm: formTopRight) + } + } else { + returnConjugation(keyPressed: sender, requestedForm: formTopRight) + } loadKeys() case "formBottomLeft": - returnConjugation(keyPressed: sender, requestedForm: formBottomLeft) + if controllerLanguage == "English" && enConjugationState == .present { + enConjugationState = .presPerf + conjViewShiftButtonsState = .bothInactive + } else { + returnConjugation(keyPressed: sender, requestedForm: formBottomLeft) + } loadKeys() case "formBottomRight": - returnConjugation(keyPressed: sender, requestedForm: formBottomRight) + if controllerLanguage == "English" && enConjugationState == .present { + enConjugationState = .presPerfCont + conjViewShiftButtonsState = .bothInactive + } else { + returnConjugation(keyPressed: sender, requestedForm: formBottomRight) + } loadKeys() case "formLeft": diff --git a/Keyboards/KeyboardsBase/ScribeFunctionality/CommandVariables.swift b/Keyboards/KeyboardsBase/ScribeFunctionality/CommandVariables.swift index a8d65091..1eab39ca 100644 --- a/Keyboards/KeyboardsBase/ScribeFunctionality/CommandVariables.swift +++ b/Keyboards/KeyboardsBase/ScribeFunctionality/CommandVariables.swift @@ -155,8 +155,8 @@ var formLabelsDict = [ "SPP": "", "TPP": "", "Top": "", - "Bottom": "", "Middle": "", + "Bottom": "", "TL": "", "TR": "", "BL": "", diff --git a/Keyboards/KeyboardsBase/ScribeFunctionality/Conjugate.swift b/Keyboards/KeyboardsBase/ScribeFunctionality/Conjugate.swift index 740e7b6b..2e62b54b 100644 --- a/Keyboards/KeyboardsBase/ScribeFunctionality/Conjugate.swift +++ b/Keyboards/KeyboardsBase/ScribeFunctionality/Conjugate.swift @@ -257,12 +257,45 @@ func returnConjugation(keyPressed: UIButton, requestedForm: String) { } else { proxy.insertText(wordToReturn + getOptionalSpace()) } + } else if formsDisplayDimensions == .view3x1 { + wordToReturn = LanguageDBManager.shared.queryVerb(of: verbToConjugate, with: outputCols)[0] + potentialWordsToReturn = wordToReturn.components(separatedBy: getOptionalSpace()) + + if inputWordIsCapitalized { + if controllerLanguage == "English", potentialWordsToReturn.count > 1 { + // Don't return a space as well as we have a perfect verb and the cursor will be between. + proxy.insertText(wordToReturn.capitalize()) + } else { + proxy.insertText(wordToReturn.capitalized + getOptionalSpace()) + } + } else { + proxy.insertText(wordToReturn + getOptionalSpace()) + } } else if formsDisplayDimensions == .view2x2 { wordToReturn = LanguageDBManager.shared.queryVerb(of: verbToConjugate, with: outputCols)[0] potentialWordsToReturn = wordToReturn.components(separatedBy: " ") if inputWordIsCapitalized { - proxy.insertText(wordToReturn.capitalized + getOptionalSpace()) + if controllerLanguage == "English", potentialWordsToReturn.count > 1 { + // Don't return a space as well as we have a perfect verb and the cursor will be between. + proxy.insertText(wordToReturn.capitalize()) + } else { + proxy.insertText(wordToReturn.capitalized + getOptionalSpace()) + } + } else { + proxy.insertText(wordToReturn + getOptionalSpace()) + } + } else if formsDisplayDimensions == .view1x2 { + wordToReturn = LanguageDBManager.shared.queryVerb(of: verbToConjugate, with: outputCols)[0] + potentialWordsToReturn = wordToReturn.components(separatedBy: " ") + + if inputWordIsCapitalized { + if controllerLanguage == "English", potentialWordsToReturn.count > 1 { + // Don't return a space as well as we have a perfect verb and the cursor will be between. + proxy.insertText(wordToReturn.capitalize()) + } else { + proxy.insertText(wordToReturn.capitalized + getOptionalSpace()) + } } else { proxy.insertText(wordToReturn + getOptionalSpace()) } diff --git a/Keyboards/LanguageKeyboards/English/ENCommandVariables.swift b/Keyboards/LanguageKeyboards/English/ENCommandVariables.swift index 63cf7384..496eb8b0 100644 --- a/Keyboards/LanguageKeyboards/English/ENCommandVariables.swift +++ b/Keyboards/LanguageKeyboards/English/ENCommandVariables.swift @@ -22,23 +22,124 @@ func enSetConjugationLabels() { for k in formLabelsDict.keys { formLabelsDict[k] = "" } + + switch enConjugationState { + case .present, .past, .future, .conditional: + formLabelsDict["TL"] = "Simple" + formLabelsDict["TR"] = "Continuous" + formLabelsDict["BL"] = "Perfect" + formLabelsDict["BR"] = "Perfect Continuous" + case .presSimp, .presPerf, .presPerfCont: + formLabelsDict["Left"] = "I/you/plural" + formLabelsDict["Right"] = "he/she/it" + case .presCont: + formLabelsDict["TL"] = "Participle" + formLabelsDict["TR"] = "I" + formLabelsDict["BL"] = "you/plural" + formLabelsDict["BR"] = "he/she/it" + case .pastCont: + formLabelsDict["Top"] = "Participle" + formLabelsDict["Middle"] = "I/he/she/it" + formLabelsDict["Bottom"] = "you/plural" + } } /// What the conjugation state is for the conjugate feature. enum ENConjugationState { case present + case presSimp + case presCont + case presPerf + case presPerfCont + case past + case pastCont + case future + case conditional } var enConjugationState: ENConjugationState = .present /// Sets the title of the command bar when the keyboard is in conjugate mode. -func enGetConjugationTitle() {} +func enGetConjugationTitle() -> String { + if inputWordIsCapitalized { + verbToDisplay = verbToConjugate.capitalized + } else { + verbToDisplay = verbToConjugate + } + switch enConjugationState { + case .present: + return commandPromptSpacing + "Present: " + verbToDisplay + case .presSimp: + return commandPromptSpacing + "Pr. Simple: " + verbToDisplay + case .presCont: + return commandPromptSpacing + "Pr. Continuous: " + verbToDisplay + case .presPerf: + return commandPromptSpacing + "Pr. Perfect: " + verbToDisplay + case .presPerfCont: + return commandPromptSpacing + "Pr. Perf. Continuous: " + verbToDisplay + case .past: + return commandPromptSpacing + "Past: " + verbToDisplay + case .pastCont: + return commandPromptSpacing + "Past Continuous: " + verbToDisplay + case .future: + return commandPromptSpacing + "Future: " + verbToDisplay + case .conditional: + return commandPromptSpacing + "Conditional: " + verbToDisplay + } +} /// Returns the appropriate key in the verbs dictionary to access conjugations. -func enGetConjugationState() {} +func enGetConjugationState() -> [String] { + switch enConjugationState { + case .present: + return ["presSimp", "presFPSCont", "presPerfSimp", "presPerfSimpCont"] + case .presSimp: + return ["presSimp", "presTPS"] + case .presCont: + return ["presPart", "presFPSCont", "prePluralCont", "presTPSCont"] + case .presPerf: + return ["presPerfSimp", "presPerfTPS"] + case .presPerfCont: + return ["presPerfSimpCont", "presPerfTPSCont"] + case .past: + return ["pastSimp", "pastSimpCont", "pastPerf", "pastPerfCont"] + case .pastCont: + return ["presPart", "pastSimpCont", "pastSimpPluralCont"] + case .future: + return ["futSimp", "futCont", "futPerf", "futPerfCont"] + case .conditional: + return ["condSimp", "condCont", "condPerf", "condPerfCont"] + } +} /// Action associated with the left view switch button of the conjugation state. -func enConjugationStateLeft() {} +func enConjugationStateLeft() { + switch enConjugationState { + case .present, .presSimp, .presCont, .presPerf, .presPerfCont, .pastCont: + break + case .past: + conjViewShiftButtonsState = .leftInactive + enConjugationState = .present + case .future: + enConjugationState = .past + case .conditional: + conjViewShiftButtonsState = .bothActive + enConjugationState = .future + } +} /// Action associated with the right view switch button of the conjugation state. -func enConjugationStateRight() {} +func enConjugationStateRight() { + switch enConjugationState { + case .presSimp, .presCont, .presPerf, .presPerfCont, .pastCont, .conditional: + break + case .present: + conjViewShiftButtonsState = .bothActive + enConjugationState = .past + case .past: + enConjugationState = .future + case .future: + conjViewShiftButtonsState = .rightInactive + enConjugationState = .conditional + } +} diff --git a/Keyboards/LanguageKeyboards/English/ENInterfaceVariables.swift b/Keyboards/LanguageKeyboards/English/ENInterfaceVariables.swift index e2294733..9b39d02c 100644 --- a/Keyboards/LanguageKeyboards/English/ENInterfaceVariables.swift +++ b/Keyboards/LanguageKeyboards/English/ENInterfaceVariables.swift @@ -160,13 +160,13 @@ func setENKeyboardLayout() { numericAutosuggestions = ["is", "to", "and"] verbsAfterPronounsArray = ["have", "be", "can"] pronounAutosuggestionTenses = [ - "I": "presFPS", - "you": "presSPS", + "I": "presSimp", + "you": "presSimp", "he": "presTPS", "she": "presTPS", "it": "presTPS", - "we": "presFPP", - "they": "presTPP" + "we": "presSimp", + "they": "presSimp" ] translateKeyLbl = "Translate"