diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-03-16 22:13:50 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-03-16 22:13:50 +0200 |
commit | 9c6da385be908d454ead2056de9b9c31546411ef (patch) | |
tree | 607871ff9ece3cf9fb53b291e5bdb1b3f0e4b3fe /src/ui/util.c | |
parent | 5d3567bd26ad1031e4ec08ccd2c36f5f1f646ca7 (diff) |
Translation: Remember last used languages
Diffstat (limited to 'src/ui/util.c')
-rw-r--r-- | src/ui/util.c | 67 |
1 files changed, 44 insertions, 23 deletions
diff --git a/src/ui/util.c b/src/ui/util.c index c1e27751..400e65d4 100644 --- a/src/ui/util.c +++ b/src/ui/util.c | |||
@@ -1078,6 +1078,12 @@ static iWidget *makeValuePadding_(iWidget *value) { | |||
1078 | } | 1078 | } |
1079 | 1079 | ||
1080 | void finalizeSheet_Widget(iWidget *sheet) { | 1080 | void finalizeSheet_Widget(iWidget *sheet) { |
1081 | /* The sheet contents are completely rearranged and restyled on a phone. | ||
1082 | We'll set up a linear fullscreen arrangement of the widgets. Sheets are already | ||
1083 | scrollable so they can be taller than the display. In hindsight, it may have been | ||
1084 | easier to create phone versions of each dialog, but at least this works with any | ||
1085 | future changes to the UI (..."works"). At least this way it is possible to enforce | ||
1086 | a consistent styling. */ | ||
1081 | if (deviceType_App() == phone_AppDeviceType && parent_Widget(sheet) == get_Window()->root) { | 1087 | if (deviceType_App() == phone_AppDeviceType && parent_Widget(sheet) == get_Window()->root) { |
1082 | if (~flags_Widget(sheet) & keepOnTop_WidgetFlag) { | 1088 | if (~flags_Widget(sheet) & keepOnTop_WidgetFlag) { |
1083 | /* Already finalized. */ | 1089 | /* Already finalized. */ |
@@ -1085,11 +1091,6 @@ void finalizeSheet_Widget(iWidget *sheet) { | |||
1085 | postRefresh_App(); | 1091 | postRefresh_App(); |
1086 | return; | 1092 | return; |
1087 | } | 1093 | } |
1088 | /* The sheet contents are completely rearranged on a phone. We'll set up a linear | ||
1089 | fullscreen arrangement of the widgets. Sheets are already scrollable so they | ||
1090 | can be taller than the display. In hindsight, it may have been easier to | ||
1091 | create phone versions of each dialog, but at least this works with any future | ||
1092 | changes to the UI (..."works"). */ | ||
1093 | setFlags_Widget(sheet, | 1094 | setFlags_Widget(sheet, |
1094 | keepOnTop_WidgetFlag | | 1095 | keepOnTop_WidgetFlag | |
1095 | parentCannotResize_WidgetFlag | | 1096 | parentCannotResize_WidgetFlag | |
@@ -1366,6 +1367,9 @@ void finalizeSheet_Widget(iWidget *sheet) { | |||
1366 | /* Pick up the dialog buttons for the navbar. */ | 1367 | /* Pick up the dialog buttons for the navbar. */ |
1367 | iWidget *buttons = findChild_Widget(sheet, "dialogbuttons"); | 1368 | iWidget *buttons = findChild_Widget(sheet, "dialogbuttons"); |
1368 | iLabelWidget *cancel = findMenuItem_Widget(buttons, "cancel"); | 1369 | iLabelWidget *cancel = findMenuItem_Widget(buttons, "cancel"); |
1370 | // if (!cancel) { | ||
1371 | // cancel = findMenuItem_Widget(buttons, "translation.cancel"); | ||
1372 | // } | ||
1369 | if (cancel) { | 1373 | if (cancel) { |
1370 | updateText_LabelWidget(back, text_LabelWidget(cancel)); | 1374 | updateText_LabelWidget(back, text_LabelWidget(cancel)); |
1371 | setCommand_LabelWidget(back, command_LabelWidget(cancel)); | 1375 | setCommand_LabelWidget(back, command_LabelWidget(cancel)); |
@@ -2223,6 +2227,7 @@ static const iMenuItem languages[] = { | |||
2223 | }; | 2227 | }; |
2224 | 2228 | ||
2225 | static iBool translationHandler_(iWidget *dlg, const char *cmd) { | 2229 | static iBool translationHandler_(iWidget *dlg, const char *cmd) { |
2230 | iUnused(dlg); | ||
2226 | if (equal_Command(cmd, "xlt.lang")) { | 2231 | if (equal_Command(cmd, "xlt.lang")) { |
2227 | iLabelWidget *menuItem = pointer_Command(cmd); | 2232 | iLabelWidget *menuItem = pointer_Command(cmd); |
2228 | iWidget *button = parent_Widget(parent_Widget(menuItem)); | 2233 | iWidget *button = parent_Widget(parent_Widget(menuItem)); |
@@ -2242,6 +2247,15 @@ const char *languageId_String(const iString *menuItemLabel) { | |||
2242 | return ""; | 2247 | return ""; |
2243 | } | 2248 | } |
2244 | 2249 | ||
2250 | int languageIndex_CStr(const char *langId) { | ||
2251 | iForIndices(i, languages) { | ||
2252 | if (equal_Rangecc(range_Command(languages[i].command, "id"), langId)) { | ||
2253 | return i; | ||
2254 | } | ||
2255 | } | ||
2256 | return -1; | ||
2257 | } | ||
2258 | |||
2245 | iWidget *makeTranslation_Widget(iWidget *parent) { | 2259 | iWidget *makeTranslation_Widget(iWidget *parent) { |
2246 | iWidget *dlg = makeSheet_Widget("xlt"); | 2260 | iWidget *dlg = makeSheet_Widget("xlt"); |
2247 | setFlags_Widget(dlg, keepOnTop_WidgetFlag, iFalse); | 2261 | setFlags_Widget(dlg, keepOnTop_WidgetFlag, iFalse); |
@@ -2254,25 +2268,32 @@ iWidget *makeTranslation_Widget(iWidget *parent) { | |||
2254 | iWidget *page; | 2268 | iWidget *page; |
2255 | addChild_Widget(dlg, iClob(page = makeTwoColumnWidget_(&headings, &values))); | 2269 | addChild_Widget(dlg, iClob(page = makeTwoColumnWidget_(&headings, &values))); |
2256 | setId_Widget(page, "xlt.langs"); | 2270 | setId_Widget(page, "xlt.langs"); |
2257 | addChild_Widget(headings, iClob(makeHeading_Widget("From:"))); | ||
2258 | iLabelWidget *fromLang, *toLang; | 2271 | iLabelWidget *fromLang, *toLang; |
2259 | setId_Widget(addChildFlags_Widget(values, | 2272 | /* Source language. */ { |
2260 | iClob(fromLang = makeMenuButton_LabelWidget( | 2273 | addChild_Widget(headings, iClob(makeHeading_Widget("From:"))); |
2261 | "Portuguese", languages, iElemCount(languages))), | 2274 | setId_Widget( |
2262 | alignLeft_WidgetFlag), | 2275 | addChildFlags_Widget(values, |
2263 | "xlt.from"); | 2276 | iClob(fromLang = makeMenuButton_LabelWidget( |
2264 | updateTextCStr_LabelWidget(fromLang, "French"); /* TODO: Check source media type; remember last use. */ | 2277 | "Portuguese", languages, iElemCount(languages))), |
2265 | setBackgroundColor_Widget(findChild_Widget(as_Widget(fromLang), "menu"), | 2278 | alignLeft_WidgetFlag), |
2266 | uiBackgroundMenu_ColorId); | 2279 | "xlt.from"); |
2267 | addChild_Widget(headings, iClob(makeHeading_Widget("To:"))); | 2280 | iWidget *langMenu = findChild_Widget(as_Widget(fromLang), "menu"); |
2268 | setId_Widget(addChildFlags_Widget(values, | 2281 | updateText_LabelWidget(fromLang, |
2269 | iClob(toLang = makeMenuButton_LabelWidget( | 2282 | text_LabelWidget(child_Widget(langMenu, prefs_App()->langFrom))); |
2270 | "Portuguese", languages, iElemCount(languages))), | 2283 | setBackgroundColor_Widget(langMenu, uiBackgroundMenu_ColorId); |
2271 | alignLeft_WidgetFlag), | 2284 | } |
2272 | "xlt.to"); | 2285 | /* Target language. */ { |
2273 | setBackgroundColor_Widget(findChild_Widget(as_Widget(toLang), "menu"), | 2286 | addChild_Widget(headings, iClob(makeHeading_Widget("To:"))); |
2274 | uiBackgroundMenu_ColorId); | 2287 | setId_Widget(addChildFlags_Widget(values, |
2275 | updateTextCStr_LabelWidget(toLang, "English"); /* TODO: User preference. */ | 2288 | iClob(toLang = makeMenuButton_LabelWidget( |
2289 | "Portuguese", languages, iElemCount(languages))), | ||
2290 | alignLeft_WidgetFlag), | ||
2291 | "xlt.to"); | ||
2292 | iWidget *langMenu = findChild_Widget(as_Widget(toLang), "menu"); | ||
2293 | setBackgroundColor_Widget(langMenu, uiBackgroundMenu_ColorId); | ||
2294 | updateText_LabelWidget(toLang, | ||
2295 | text_LabelWidget(child_Widget(langMenu, prefs_App()->langTo))); | ||
2296 | } | ||
2276 | addChild_Widget(dlg, iClob(makePadding_Widget(lineHeight_Text(uiLabel_FontId)))); | 2297 | addChild_Widget(dlg, iClob(makePadding_Widget(lineHeight_Text(uiLabel_FontId)))); |
2277 | addChild_Widget( | 2298 | addChild_Widget( |
2278 | dlg, | 2299 | dlg, |