diff --git a/Applications.cfg b/Applications.cfg index 21464798..28ddedd6 100644 --- a/Applications.cfg +++ b/Applications.cfg @@ -301,7 +301,7 @@ url="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/lib/GUI.lua", type="Library", preloadFile=true, - version=1.69, + version=1.70, }, { path="/lib/rayEngine.lua", @@ -545,7 +545,7 @@ type="Application", icon="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/Applications/Translate/Icon.pic", createShortcut="desktop", - version=1.00, + version=1.01, resources={ { path="/Logo.pic", diff --git a/Applications/Translate/Main.lua b/Applications/Translate/Main.lua index 8ad20d3e..53af6f45 100644 --- a/Applications/Translate/Main.lua +++ b/Applications/Translate/Main.lua @@ -60,25 +60,15 @@ local function getLanguageIndex(text) error("CYKA BLYAD LANG NOT FOUND") end -local function translate(text, direction) - if text then +local function translate() + if fromInputField.text and unicode.len(fromInputField.text) > 0 then infoLabel.text = "Отправка запроса на перевод..." mainContainer:draw() buffer.draw() - local first, second = fromComboBox:getItem(fromComboBox.selectedItem).text, toComboBox:getItem(toComboBox.selectedItem).text - if not direction then - first, second = second, first - end - - local result, reason = web.request("https://translate.yandex.net/api/v1.5/tr.json/translate?key=trnsl.1.1.20170831T153247Z.6ecf9d7198504994.8ce5a3aa9f9a2ecbe7b2377af37ffe5ad379f4ca&text=" .. string.optimizeForURLRequests(text) .. "&lang=" .. languages[getLanguageIndex(first)].short .. "-" .. languages[getLanguageIndex(second)].short) + local result, reason = web.request("https://translate.yandex.net/api/v1.5/tr.json/translate?key=trnsl.1.1.20170831T153247Z.6ecf9d7198504994.8ce5a3aa9f9a2ecbe7b2377af37ffe5ad379f4ca&text=" .. string.optimizeForURLRequests(fromInputField.text) .. "&lang=" .. languages[getLanguageIndex(fromComboBox:getItem(fromComboBox.selectedItem).text)].short .. "-" .. languages[getLanguageIndex(toComboBox:getItem(toComboBox.selectedItem).text)].short) if result then - result = json:decode(result).text[1] - if direction then - toInputField.text = result - else - fromInputField.text = result - end + toInputField.text = json:decode(result).text[1] infoLabel.text = " " else infoLabel.text = "Ошибка запроса на перевод: " .. tostring(reason) @@ -89,20 +79,25 @@ local function translate(text, direction) end end -fromInputField.onInputFinished = function() - translate(fromInputField.text, true) -end - -toInputField.onInputFinished = function() - translate(fromInputField.text, false) -end - switchButton.onTouch = function() fromComboBox.selectedItem, toComboBox.selectedItem = toComboBox.selectedItem, fromComboBox.selectedItem - mainContainer:draw() - buffer.draw() + translate() end +fromInputField.onInputFinished = function() + translate() +end + +fromComboBox.onItemSelected = function() + translate() +end + +toComboBox.onItemSelected = function() + translate() +end + +toInputField.eventHandler = nil + ------------------------------------------------------------------------------------------------------------------ updateLanguages() diff --git a/lib/GUI.lua b/lib/GUI.lua index 3fe4dff2..d5c5dbf4 100755 --- a/lib/GUI.lua +++ b/lib/GUI.lua @@ -1810,7 +1810,7 @@ local function dropDownMenuCalculateSizes(menu) totalHeight = totalHeight + (menu.itemsContainer.children[i].type == GUI.dropDownMenuElementTypes.separator and 1 or menu.itemHeight) menu.itemsContainer.children[i].width = menu.width end - menu.height = math.min(totalHeight, menu.maximumHeight) + menu.height = math.min(totalHeight, menu.maximumHeight, buffer.height - menu.y) menu.itemsContainer.width, menu.itemsContainer.height = menu.width, menu.height menu.nextButton.localPosition.y = menu.height