feat(color): key shortcuts and quick menu favorites can be set to run stand alone Lua tools (#7083)
Co-authored-by: elecpower <elecpower@users.noreply.github.com>
This commit is contained in:
@@ -21,13 +21,9 @@
|
||||
|
||||
#include "sourcechoice.h"
|
||||
|
||||
#include "dataconstants.h"
|
||||
#include "lcd.h"
|
||||
#include "menu.h"
|
||||
#include "menutoolbar.h"
|
||||
#include "edgetx.h"
|
||||
#include "strhelpers.h"
|
||||
#include "switches.h"
|
||||
|
||||
class SourceChoiceMenuToolbar : public MenuToolbar
|
||||
{
|
||||
|
||||
@@ -26,8 +26,6 @@
|
||||
|
||||
class SourceChoiceMenuToolbar;
|
||||
|
||||
bool isSourceAvailable(int source);
|
||||
|
||||
class SourceChoice : public Choice
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -20,12 +20,9 @@
|
||||
*/
|
||||
#include "switchchoice.h"
|
||||
|
||||
#include "dataconstants.h"
|
||||
#include "menu.h"
|
||||
#include "menutoolbar.h"
|
||||
#include "edgetx.h"
|
||||
#include "strhelpers.h"
|
||||
#include "switches.h"
|
||||
|
||||
class SwitchChoiceMenuToolbar : public MenuToolbar
|
||||
{
|
||||
|
||||
@@ -294,7 +294,7 @@ class MenuWindowContent : public NavWindow
|
||||
{
|
||||
setWindowFlag(OPAQUE);
|
||||
|
||||
coord_t w = (popupWidth > MENUS_WIDTH) ? popupWidth : MENUS_WIDTH;
|
||||
coord_t w = (popupWidth > 0) ? popupWidth : MENUS_WIDTH;
|
||||
|
||||
lv_obj_center(lvobj);
|
||||
setFlexLayout(LV_FLEX_FLOW_COLUMN, PAD_ZERO, w, LV_SIZE_CONTENT);
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "mainwindow.h"
|
||||
#include "model_select.h"
|
||||
#include "quick_menu.h"
|
||||
#include "radio_tools.h"
|
||||
#include "screen_setup.h"
|
||||
#include "topbar.h"
|
||||
#include "view_channels.h"
|
||||
@@ -227,7 +228,9 @@ void ViewMain::updateTopbarVisibility()
|
||||
void ViewMain::doKeyShortcut(event_t event)
|
||||
{
|
||||
QMPage pg = g_eeGeneral.getKeyShortcut(event);
|
||||
if (pg == QM_OPEN_QUICK_MENU) {
|
||||
if (pg == QM_APP) {
|
||||
runLuaTool(g_eeGeneral.getKeyToolName(event));
|
||||
} else if (pg == QM_OPEN_QUICK_MENU) {
|
||||
QuickMenu::openQuickMenu();
|
||||
} else {
|
||||
QuickMenu::openPage(pg);
|
||||
|
||||
@@ -33,7 +33,206 @@
|
||||
#include "etx_lv_theme.h"
|
||||
#include "lib_file.h"
|
||||
|
||||
extern uint8_t g_moduleIdx;
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
inline bool tool_compare_nocase(const ToolEntry& first, const ToolEntry& second)
|
||||
{
|
||||
return strcasecmp(first.label.c_str(), second.label.c_str()) < 0;
|
||||
}
|
||||
|
||||
#if defined(LUA)
|
||||
std::vector<ToolEntry> luaTools;
|
||||
static bool luaToolsLoaded = false;
|
||||
|
||||
static void run_lua_tool(const std::string& path)
|
||||
{
|
||||
char toolPath[FF_MAX_LFN + 1];
|
||||
strncpy(toolPath, path.c_str(), sizeof(toolPath) - 1);
|
||||
*((char*)getBasename(toolPath) - 1) = '\0';
|
||||
f_chdir(toolPath);
|
||||
|
||||
luaExecStandalone(path.c_str());
|
||||
}
|
||||
|
||||
void unloadLuaTools()
|
||||
{
|
||||
luaTools.clear();
|
||||
luaToolsLoaded = false;
|
||||
}
|
||||
|
||||
// LUA scripts in TOOLS
|
||||
void loadLuaTools()
|
||||
{
|
||||
if (!luaToolsLoaded) {
|
||||
luaToolsLoaded = true;
|
||||
|
||||
FILINFO fno;
|
||||
DIR dir;
|
||||
|
||||
FRESULT res = f_opendir(&dir, SCRIPTS_TOOLS_PATH);
|
||||
if (res == FR_OK) {
|
||||
for (;;) {
|
||||
res = f_readdir(&dir, &fno); /* Read a directory item */
|
||||
if (res != FR_OK || fno.fname[0] == 0)
|
||||
break; /* Break on error or end of dir */
|
||||
if (fno.fattrib & (AM_HID | AM_SYS))
|
||||
continue; // skip hidden files and system files
|
||||
if (fno.fname[0] == '.') continue; /* Ignore UNIX hidden files */
|
||||
|
||||
bool inFolder = (fno.fattrib & AM_DIR);
|
||||
|
||||
char path[FF_MAX_LFN + 1] = SCRIPTS_TOOLS_PATH "/";
|
||||
strcat(path, fno.fname);
|
||||
if (inFolder) {
|
||||
// check if .lua with same name exists - skip folder to avoid duplicate entries
|
||||
auto plen = strlen(path);
|
||||
strcat(path, ".lua");
|
||||
if (f_stat(path, nullptr) == FR_OK)
|
||||
continue;
|
||||
path[plen] = 0;
|
||||
strcat(path, "/main.lua");
|
||||
if (f_stat(path, nullptr) != FR_OK)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isRadioScriptTool(path)) {
|
||||
char toolName[RADIO_TOOL_NAME_MAXLEN + 1] = {0};
|
||||
const char* label;
|
||||
if (readToolName(toolName, path)) {
|
||||
label = toolName;
|
||||
} else {
|
||||
if (!inFolder) {
|
||||
char* ext = (char*)getFileExtension(fno.fname);
|
||||
if (ext) *ext = '\0';
|
||||
}
|
||||
label = fno.fname;
|
||||
}
|
||||
luaTools.emplace_back(ToolEntry{label, path, run_lua_tool});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::sort(luaTools.begin(), luaTools.end(), tool_compare_nocase);
|
||||
}
|
||||
}
|
||||
|
||||
// LUA scripts in TOOLS
|
||||
static void scanLuaTools(std::list<ToolEntry>& scripts)
|
||||
{
|
||||
loadLuaTools();
|
||||
|
||||
for (auto t : luaTools)
|
||||
scripts.emplace_back(t);
|
||||
}
|
||||
#endif
|
||||
|
||||
const ToolEntry* getLuaTool(int n)
|
||||
{
|
||||
if (n >= 0 && n < (int)luaTools.size())
|
||||
return &luaTools[n];
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int getLuaToolId(const std::string name)
|
||||
{
|
||||
int id = 0;
|
||||
for (auto t : luaTools) {
|
||||
if (t.label == name)
|
||||
return id;
|
||||
id += 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void runLuaTool(const std::string name)
|
||||
{
|
||||
for (auto t : luaTools) {
|
||||
if (t.label == name) {
|
||||
t.exec(t.path);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void getLuaToolNames(std::vector<std::string>& nameList)
|
||||
{
|
||||
loadLuaTools();
|
||||
std::string s(STR_QM_APPS);
|
||||
s += " - ";
|
||||
for (size_t i = 0; i < luaTools.size(); i += 1) {
|
||||
nameList.emplace_back(s + luaTools[i].label);
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
static bool isModelGPSSensorPresent()
|
||||
{
|
||||
for (int i = 0; i < MAX_TELEMETRY_SENSORS; i++) {
|
||||
if (isGPSSensor(i+1)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void run_gpstool(const std::string&)
|
||||
{
|
||||
new RadioGpsTool();
|
||||
}
|
||||
|
||||
#if defined(PXX2) || defined(MULTIMODULE)
|
||||
|
||||
#if defined(HARDWARE_INTERNAL_MODULE)
|
||||
static void run_spektrum_int(const std::string&)
|
||||
{
|
||||
new RadioSpectrumAnalyser(INTERNAL_MODULE);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(HARDWARE_EXTERNAL_MODULE)
|
||||
static void run_spektrum_ext(const std::string&)
|
||||
{
|
||||
new RadioSpectrumAnalyser(EXTERNAL_MODULE);
|
||||
}
|
||||
#endif
|
||||
#endif // defined(PXX2) || defined(MULTIMODULE)
|
||||
|
||||
#if defined(INTERNAL_MODULE_PXX2)
|
||||
static void run_pxx2_power(const std::string&)
|
||||
{
|
||||
#if 0 // disabled Power Meter: not yet implemented
|
||||
new RadioPowerMeter(INTERNAL_MODULE);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(GHOST)
|
||||
static void run_ghost_config(const std::string&)
|
||||
{
|
||||
new RadioGhostModuleConfig(EXTERNAL_MODULE);
|
||||
}
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
struct ToolButton : public TextButton {
|
||||
ToolButton(Window* parent, const ToolEntry& tool) :
|
||||
TextButton(parent, rect_t{}, tool.label, [=]() {
|
||||
tool.exec(tool.path);
|
||||
return 0;
|
||||
})
|
||||
{
|
||||
setWidth(TOOLS_BTN_W);
|
||||
setHeight(TOOLS_BTN_H);
|
||||
|
||||
lv_obj_set_width(label, lv_pct(100));
|
||||
etx_obj_add_style(label, styles->text_align_center, LV_PART_MAIN);
|
||||
lv_label_set_long_mode(label, LV_LABEL_LONG_WRAP);
|
||||
}
|
||||
|
||||
static LAYOUT_ORIENTATION(TOOLS_BTN_W, (LCD_W - PAD_LARGE * 3) / 3, (LCD_W - PAD_LARGE * 2) / 2)
|
||||
static LAYOUT_VAL_SCALED(TOOLS_BTN_H, 48)
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
RadioToolsPage::RadioToolsPage(const PageDef& pageDef) : PageGroupItem(pageDef) {}
|
||||
|
||||
@@ -81,147 +280,6 @@ void RadioToolsPage::checkEvents()
|
||||
PageGroupItem::checkEvents();
|
||||
}
|
||||
|
||||
typedef void (*ToolExec)(Window* parent, const std::string& path);
|
||||
|
||||
struct ToolEntry {
|
||||
std::string label;
|
||||
std::string path;
|
||||
ToolExec exec;
|
||||
};
|
||||
|
||||
inline bool tool_compare_nocase(const ToolEntry& first, const ToolEntry& second)
|
||||
{
|
||||
return strcasecmp(first.label.c_str(), second.label.c_str()) < 0;
|
||||
}
|
||||
|
||||
#if defined(LUA)
|
||||
static void run_lua_tool(Window* parent, const std::string& path)
|
||||
{
|
||||
char toolPath[FF_MAX_LFN + 1];
|
||||
strncpy(toolPath, path.c_str(), sizeof(toolPath) - 1);
|
||||
*((char*)getBasename(toolPath) - 1) = '\0';
|
||||
f_chdir(toolPath);
|
||||
|
||||
luaExecStandalone(path.c_str());
|
||||
}
|
||||
|
||||
// LUA scripts in TOOLS
|
||||
static void scanLuaTools(std::list<ToolEntry>& scripts)
|
||||
{
|
||||
FILINFO fno;
|
||||
DIR dir;
|
||||
|
||||
FRESULT res = f_opendir(&dir, SCRIPTS_TOOLS_PATH);
|
||||
if (res == FR_OK) {
|
||||
for (;;) {
|
||||
res = f_readdir(&dir, &fno); /* Read a directory item */
|
||||
if (res != FR_OK || fno.fname[0] == 0)
|
||||
break; /* Break on error or end of dir */
|
||||
if (fno.fattrib & (AM_HID | AM_SYS))
|
||||
continue; // skip hidden files and system files
|
||||
if (fno.fname[0] == '.') continue; /* Ignore UNIX hidden files */
|
||||
|
||||
bool inFolder = (fno.fattrib & AM_DIR);
|
||||
|
||||
char path[FF_MAX_LFN + 1] = SCRIPTS_TOOLS_PATH "/";
|
||||
strcat(path, fno.fname);
|
||||
if (inFolder) {
|
||||
// check if .lua with same name exists - skip folder to avoid duplicate entries
|
||||
auto plen = strlen(path);
|
||||
strcat(path, ".lua");
|
||||
if (f_stat(path, nullptr) == FR_OK)
|
||||
continue;
|
||||
path[plen] = 0;
|
||||
strcat(path, "/main.lua");
|
||||
if (f_stat(path, nullptr) != FR_OK)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isRadioScriptTool(path)) {
|
||||
char toolName[RADIO_TOOL_NAME_MAXLEN + 1] = {0};
|
||||
const char* label;
|
||||
if (readToolName(toolName, path)) {
|
||||
label = toolName;
|
||||
} else {
|
||||
if (!inFolder) {
|
||||
char* ext = (char*)getFileExtension(fno.fname);
|
||||
if (ext) *ext = '\0';
|
||||
}
|
||||
label = fno.fname;
|
||||
}
|
||||
|
||||
scripts.emplace_back(ToolEntry{label, path, run_lua_tool});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static bool isModelGPSSensorPresent()
|
||||
{
|
||||
for (int i = 0; i < MAX_TELEMETRY_SENSORS; i++) {
|
||||
if (isGPSSensor(i+1)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void run_gpstool(Window* parent, const std::string&)
|
||||
{
|
||||
new RadioGpsTool();
|
||||
}
|
||||
|
||||
#if defined(PXX2) || defined(MULTIMODULE)
|
||||
|
||||
#if defined(HARDWARE_INTERNAL_MODULE)
|
||||
static void run_spektrum_int(Window* parent, const std::string&)
|
||||
{
|
||||
new RadioSpectrumAnalyser(INTERNAL_MODULE);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(HARDWARE_EXTERNAL_MODULE)
|
||||
static void run_spektrum_ext(Window* parent, const std::string&)
|
||||
{
|
||||
new RadioSpectrumAnalyser(EXTERNAL_MODULE);
|
||||
}
|
||||
#endif
|
||||
#endif // defined(PXX2) || defined(MULTIMODULE)
|
||||
|
||||
#if defined(INTERNAL_MODULE_PXX2)
|
||||
static void run_pxx2_power(Window* parent, const std::string&)
|
||||
{
|
||||
#if 0 // disabled Power Meter: not yet implemented
|
||||
new RadioPowerMeter(INTERNAL_MODULE);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(GHOST)
|
||||
static void run_ghost_config(Window* parent, const std::string&)
|
||||
{
|
||||
new RadioGhostModuleConfig(EXTERNAL_MODULE);
|
||||
}
|
||||
#endif
|
||||
|
||||
struct ToolButton : public TextButton {
|
||||
ToolButton(Window* parent, const ToolEntry& tool) :
|
||||
TextButton(parent, rect_t{}, tool.label, [=]() {
|
||||
tool.exec(parent, tool.path);
|
||||
return 0;
|
||||
})
|
||||
{
|
||||
setWidth(TOOLS_BTN_W);
|
||||
setHeight(TOOLS_BTN_H);
|
||||
|
||||
lv_obj_set_width(label, lv_pct(100));
|
||||
etx_obj_add_style(label, styles->text_align_center, LV_PART_MAIN);
|
||||
lv_label_set_long_mode(label, LV_LABEL_LONG_WRAP);
|
||||
}
|
||||
|
||||
static LAYOUT_ORIENTATION(TOOLS_BTN_W, (LCD_W - PAD_LARGE * 3) / 3, (LCD_W - PAD_LARGE * 2) / 2)
|
||||
static LAYOUT_VAL_SCALED(TOOLS_BTN_H, 48)
|
||||
};
|
||||
|
||||
void RadioToolsPage::rebuild(Window* window)
|
||||
{
|
||||
window->clear();
|
||||
|
||||
@@ -23,6 +23,20 @@
|
||||
|
||||
#include "pagegroup.h"
|
||||
|
||||
typedef void (*ToolExec)(const std::string& path);
|
||||
|
||||
struct ToolEntry {
|
||||
std::string label;
|
||||
std::string path;
|
||||
ToolExec exec;
|
||||
};
|
||||
|
||||
extern void loadLuaTools();
|
||||
extern void getLuaToolNames(std::vector<std::string>& nameList);
|
||||
extern const ToolEntry* getLuaTool(int n);
|
||||
extern int getLuaToolId(const std::string nm);
|
||||
extern void runLuaTool(const std::string nm);
|
||||
|
||||
class RadioToolsPage : public PageGroupItem
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
#include "edgetx.h"
|
||||
#include "getset_helpers.h"
|
||||
#include "pagegroup.h"
|
||||
#include "qmpagechoice.h"
|
||||
#include "radio_tools.h"
|
||||
|
||||
#define SET_DIRTY() storageDirty(EE_GENERAL)
|
||||
|
||||
@@ -46,21 +48,35 @@ void QMKeyShortcutsPage::addKey(event_t event, std::vector<std::string> qmPages,
|
||||
event = keyMapping(event);
|
||||
|
||||
setupLine(nm, [=](Window* parent, coord_t x, coord_t y) {
|
||||
auto c = new Choice(
|
||||
parent, {LCD_W / 4, y, LCD_W * 2 / 3, 0}, qmPages, QM_NONE, QM_TOOLS_DEBUG,
|
||||
GET_DEFAULT(g_eeGeneral.getKeyShortcut(event)),
|
||||
auto c = new QMPageChoice(
|
||||
parent, {LCD_W / 4, y, LCD_W * 2 / 3, 0}, qmPages, QM_NONE, qmPages.size() - 1,
|
||||
[=]() -> int {
|
||||
auto pg = g_eeGeneral.getKeyShortcut(event);
|
||||
if (pg < QM_APP)
|
||||
return pg;
|
||||
std::string nm = g_eeGeneral.getKeyToolName(event);
|
||||
int idx = getLuaToolId(nm);
|
||||
if (idx >= 0)
|
||||
return pg + idx;
|
||||
return QM_NONE;
|
||||
},
|
||||
[=](int32_t newValue) {
|
||||
g_eeGeneral.setKeyShortcut(event, (QMPage)newValue);
|
||||
if (newValue < QM_APP) {
|
||||
g_eeGeneral.setKeyShortcut(event, (QMPage)newValue);
|
||||
g_eeGeneral.setKeyToolName(event, "");
|
||||
} else {
|
||||
g_eeGeneral.setKeyShortcut(event, QM_APP);
|
||||
g_eeGeneral.setKeyToolName(event, getLuaTool(newValue - QM_APP)->label);
|
||||
}
|
||||
SET_DIRTY();
|
||||
}, STR_KEY_SHORTCUTS);
|
||||
|
||||
c->setPopupWidth(LCD_W * 3 / 4);
|
||||
c->setAvailableHandler(
|
||||
[=](int newValue) {
|
||||
if (newValue == QM_NONE) return true;
|
||||
if (g_eeGeneral.hasKeyShortcut((QMPage)newValue))
|
||||
[=](int pg) {
|
||||
if (pg == QM_NONE) return true;
|
||||
if (g_eeGeneral.hasKeyShortcut((QMPage)pg, event))
|
||||
return false;
|
||||
return newValue <= QM_UI_SCREEN1 || newValue > QM_UI_ADD_PG; }
|
||||
return pg <= QM_UI_SCREEN1 || pg > QM_UI_ADD_PG; }
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -69,7 +85,7 @@ void QMKeyShortcutsPage::addKey(event_t event, std::vector<std::string> qmPages,
|
||||
QMKeyShortcutsPage::QMKeyShortcutsPage():
|
||||
SubPage(ICON_RADIO, STR_MAIN_MENU_RADIO_SETTINGS, STR_KEY_SHORTCUTS, true)
|
||||
{
|
||||
std::vector<std::string> qmPages = QuickMenu::menuPageNames(false);
|
||||
auto qmPages = QuickMenu::menuPageNames(false);
|
||||
|
||||
setupLine(STR_SHORT_PRESS, nullptr);
|
||||
addKey(EVT_KEY_BREAK(KEY_SYS), qmPages, "SYS");
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "mainwindow.h"
|
||||
#include "model_select.h"
|
||||
#include "os/time.h"
|
||||
#include "radio_tools.h"
|
||||
#include "screen_setup.h"
|
||||
#include "theme_manager.h"
|
||||
#include "topbar.h"
|
||||
@@ -393,7 +394,10 @@ void PageGroupBase::setCurrentTab(unsigned index)
|
||||
void PageGroupBase::doKeyShortcut(event_t event)
|
||||
{
|
||||
QMPage pg = g_eeGeneral.getKeyShortcut(event);
|
||||
if (pg == QM_OPEN_QUICK_MENU) {
|
||||
if (pg == QM_APP) {
|
||||
onCancel();
|
||||
runLuaTool(g_eeGeneral.getKeyToolName(event));
|
||||
} else if (pg == QM_OPEN_QUICK_MENU) {
|
||||
QuickMenu::openQuickMenu();
|
||||
} else {
|
||||
if (QuickMenu::subMenuIcon(pg) == icon) {
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "qmpagechoice.h"
|
||||
|
||||
#include "edgetx.h"
|
||||
#include "menu.h"
|
||||
#include "menutoolbar.h"
|
||||
|
||||
class QMPageChoiceMenuToolbar : public MenuToolbar
|
||||
{
|
||||
public:
|
||||
QMPageChoiceMenuToolbar(Choice* choice, Menu* menu) :
|
||||
MenuToolbar(choice, menu, 3)
|
||||
{
|
||||
addButton(STR_MAIN_MENU_MODEL_SETTINGS, QM_MODEL_SETUP, QM_MODEL_NOTES, nullptr, STR_MAIN_MENU_MODEL_SETTINGS, true);
|
||||
addButton(STR_MAIN_MENU_RADIO_SETTINGS, QM_RADIO_SETUP, QM_RADIO_VERSION, nullptr, STR_MAIN_MENU_RADIO_SETTINGS, true);
|
||||
addButton(STR_MAIN_MENU_SCREEN_SETTINGS, QM_UI_THEMES, QM_UI_ADD_PG, nullptr, STR_MAIN_MENU_SCREEN_SETTINGS, true);
|
||||
addButton(STR_QM_TOOLS, QM_TOOLS_APPS, QM_TOOLS_DEBUG, nullptr, STR_QM_TOOLS, true);
|
||||
addButton(STR_MAIN_MENU_APPS, QM_APP, QM_APP+9999, nullptr, STR_MAIN_MENU_APPS, true);
|
||||
|
||||
addButton(STR_SELECT_MENU_CLR, 0, 0, nullptr, nullptr, true);
|
||||
}
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
QMPageChoice::QMPageChoice(Window* parent, const rect_t& rect,
|
||||
std::vector<std::string> values,
|
||||
int16_t vmin, int16_t vmax,
|
||||
std::function<int16_t()> getValue,
|
||||
std::function<void(int16_t)> setValue,
|
||||
const char *title) :
|
||||
Choice(parent, rect, values, vmin, vmax, getValue, setValue, title)
|
||||
{
|
||||
setPopupWidth(TABLE_WIDTH);
|
||||
}
|
||||
|
||||
void QMPageChoice::openMenu()
|
||||
{
|
||||
setEditMode(true); // this needs to be done first before menu is created.
|
||||
|
||||
auto menu = new Menu(false, popupWidth);
|
||||
if (menuTitle) menu->setTitle(menuTitle);
|
||||
|
||||
auto tb = new QMPageChoiceMenuToolbar(this, menu);
|
||||
menu->setToolbar(tb);
|
||||
|
||||
// fillMenu(menu); - called by MenuToolbar
|
||||
|
||||
menu->setCloseHandler([=]() { setEditMode(false); });
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "choice.h"
|
||||
#include "form.h"
|
||||
|
||||
class QMPageChoiceMenuToolbar;
|
||||
|
||||
class QMPageChoice : public Choice
|
||||
{
|
||||
public:
|
||||
QMPageChoice(Window* parent, const rect_t& rect,
|
||||
std::vector<std::string> values,
|
||||
int16_t vmin, int16_t vmax,
|
||||
std::function<int16_t()> getValue,
|
||||
std::function<void(int16_t)> setValue,
|
||||
const char *title);
|
||||
|
||||
static LAYOUT_ORIENTATION(TABLE_WIDTH, LCD_W * 5 / 8, LCD_W / 2 + PAD_LARGE * 3)
|
||||
|
||||
protected:
|
||||
friend QMPageChoiceMenuToolbar;
|
||||
|
||||
void openMenu() override;
|
||||
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
std::string getName() const override { return "QMPageChoice"; }
|
||||
#endif
|
||||
};
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "mainwindow.h"
|
||||
#include "model_select.h"
|
||||
#include "quick_menu_group.h"
|
||||
#include "radio_tools.h"
|
||||
#include "screen_setup.h"
|
||||
#include "theme_manager.h"
|
||||
#include "view_channels.h"
|
||||
@@ -145,7 +146,14 @@ class QuickSubMenu
|
||||
subMenu = new QuickMenuGroup(parent);
|
||||
|
||||
for (int i = 0; mainDef->subMenuItems[i].icon < EDGETX_ICONS_COUNT; i += 1) {
|
||||
subMenu->addButton(mainDef->subMenuItems[i].icon, STR_VAL(mainDef->subMenuItems[i].qmTitle),
|
||||
auto pg = mainDef->subMenuItems[i].qmPage;
|
||||
const char* title;
|
||||
if (pg < QM_APP) {
|
||||
title = STR_VAL(mainDef->subMenuItems[i].qmTitle);
|
||||
} else {
|
||||
title = getLuaTool(pg - QM_APP)->label.c_str();
|
||||
}
|
||||
subMenu->addButton(mainDef->subMenuItems[i].icon, title,
|
||||
std::bind(&QuickSubMenu::onPress, this, i),
|
||||
mainDef->subMenuItems[i].enabled,
|
||||
[=](bool focus) { if (focus) QuickMenu::setCurrentPage(mainDef->subMenuItems[i].qmPage, mainDef->icon); });
|
||||
@@ -430,10 +438,11 @@ std::string replaceAll(std::string str, const std::string& from, const std::stri
|
||||
return str;
|
||||
}
|
||||
|
||||
std::vector<std::string> QuickMenu::menuPageNames(bool forFavorites)
|
||||
std::vector<std::string>& QuickMenu::menuPageNames(bool forFavorites)
|
||||
{
|
||||
std::vector<std::string> qmPages;
|
||||
static std::vector<std::string> qmPages;
|
||||
|
||||
qmPages.clear();
|
||||
qmPages.emplace_back(STR_NONE);
|
||||
qmPages.emplace_back(STR_OPEN_QUICK_MENU);
|
||||
|
||||
@@ -455,6 +464,10 @@ std::vector<std::string> QuickMenu::menuPageNames(bool forFavorites)
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(LUA)
|
||||
getLuaToolNames(qmPages);
|
||||
#endif
|
||||
|
||||
return qmPages;
|
||||
}
|
||||
|
||||
@@ -467,12 +480,12 @@ void QuickMenu::resetFavorites()
|
||||
|
||||
void QuickMenu::updateFavorites()
|
||||
{
|
||||
loadLuaTools();
|
||||
|
||||
int f = 0;
|
||||
for (int i = 0; i < MAX_QM_FAVORITES; i += 1) {
|
||||
if (g_eeGeneral.qmFavorites[i].shortcut != QM_NONE) {
|
||||
setupFavorite((QMPage)g_eeGeneral.qmFavorites[i].shortcut, f);
|
||||
if (setupFavorite(i, f))
|
||||
f += 1;
|
||||
}
|
||||
}
|
||||
favoritesMenuItems[f].icon = EDGETX_ICONS_COUNT;
|
||||
|
||||
@@ -480,9 +493,30 @@ void QuickMenu::updateFavorites()
|
||||
subMenus[0]->clearSubMenu();
|
||||
}
|
||||
|
||||
void QuickMenu::setupFavorite(QMPage page, int f)
|
||||
bool QuickMenu::setupFavorite(int favIdx, int favBtn)
|
||||
{
|
||||
PageDef& fav = favoritesMenuItems[f];
|
||||
auto page = g_eeGeneral.qmFavorites[favIdx].shortcut;
|
||||
PageDef& fav = favoritesMenuItems[favBtn];
|
||||
|
||||
if (page == QM_NONE)
|
||||
return false;
|
||||
|
||||
if (page == QM_APP) {
|
||||
std::string nm = g_eeGeneral.getFavoriteToolName(favIdx);
|
||||
int idx = getLuaToolId(nm);
|
||||
if (idx >= 0) {
|
||||
fav.icon = ICON_TOOLS_APPS;
|
||||
fav.qmTitle = nullptr; // retreived on use (no translation strings)
|
||||
fav.title = nullptr; // retrieved on use (no translation strings)
|
||||
fav.pageAction = PAGE_ACTION;
|
||||
fav.qmPage = (QMPage)(page + idx);
|
||||
fav.create = nullptr;
|
||||
fav.enabled = nullptr;
|
||||
fav.action = [=]() { runLuaTool(nm); };
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = FIRST_SEARCH_IDX; qmTopItems[i].icon != EDGETX_ICONS_COUNT; i += 1) {
|
||||
if (qmTopItems[i].pageAction == QM_ACTION) {
|
||||
@@ -495,7 +529,7 @@ void QuickMenu::setupFavorite(QMPage page, int f)
|
||||
fav.create = nullptr;
|
||||
fav.enabled = nullptr;
|
||||
fav.action = qmTopItems[i].action;
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
const PageDef* sub = qmTopItems[i].subMenuItems;
|
||||
@@ -509,11 +543,13 @@ void QuickMenu::setupFavorite(QMPage page, int f)
|
||||
fav.create = sub[j].create;
|
||||
fav.enabled = sub[j].enabled;
|
||||
fav.action = sub[j].action;
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -580,7 +616,10 @@ void QuickMenu::enableSubMenu()
|
||||
void QuickMenu::doKeyShortcut(event_t event)
|
||||
{
|
||||
QMPage pg = g_eeGeneral.getKeyShortcut(event);
|
||||
if (pg == QM_OPEN_QUICK_MENU) {
|
||||
if (pg == QM_APP) {
|
||||
closeQM();
|
||||
runLuaTool(g_eeGeneral.getKeyToolName(event));
|
||||
} else if (pg == QM_OPEN_QUICK_MENU) {
|
||||
closeQM();
|
||||
} else {
|
||||
onSelect(true);
|
||||
|
||||
@@ -96,7 +96,7 @@ class QuickMenu : public NavWindow
|
||||
static void openPage(QMPage page);
|
||||
static EdgeTxIcon subMenuIcon(QMPage page);
|
||||
static int pageIndex(QMPage page);
|
||||
static std::vector<std::string> menuPageNames(bool forFavorites);
|
||||
static std::vector<std::string>& menuPageNames(bool forFavorites);
|
||||
|
||||
#if VERSION_MAJOR > 2
|
||||
static void resetFavorites();
|
||||
@@ -168,7 +168,7 @@ class QuickMenu : public NavWindow
|
||||
|
||||
#if VERSION_MAJOR > 2
|
||||
void updateFavorites();
|
||||
void setupFavorite(QMPage page, int f);
|
||||
bool setupFavorite(int fav, int favBtn);
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
@@ -68,4 +68,6 @@ enum QMPage {
|
||||
QM_TOOLS_LS_MON,
|
||||
QM_TOOLS_STATS,
|
||||
QM_TOOLS_DEBUG,
|
||||
// Key shortcut & Favorites APP
|
||||
QM_APP,
|
||||
};
|
||||
|
||||
@@ -25,34 +25,59 @@
|
||||
#include "edgetx.h"
|
||||
#include "getset_helpers.h"
|
||||
#include "pagegroup.h"
|
||||
#include "qmpagechoice.h"
|
||||
#include "radio_tools.h"
|
||||
|
||||
#define SET_DIRTY() storageDirty(EE_GENERAL)
|
||||
|
||||
QMFavoritesPage::QMFavoritesPage():
|
||||
SubPage(ICON_RADIO, STR_MAIN_MENU_RADIO_SETTINGS, STR_QUICK_MENU_FAVORITES, true)
|
||||
{
|
||||
std::vector<std::string> qmPages = QuickMenu::menuPageNames(true);
|
||||
auto qmPages = QuickMenu::menuPageNames(true);
|
||||
|
||||
for (int i = 0; i < MAX_QM_FAVORITES; i += 1) {
|
||||
char nm[50];
|
||||
strAppendUnsigned(strAppend(strAppend(nm, "#"), " "), i + 1);
|
||||
setupLine(nm, [=](Window* parent, coord_t x, coord_t y) {
|
||||
auto c = new Choice(
|
||||
parent, {LCD_W / 4, y, LCD_W * 2 / 3, 0}, qmPages, QM_NONE, QM_TOOLS_DEBUG,
|
||||
GET_DEFAULT(g_eeGeneral.qmFavorites[i].shortcut),
|
||||
auto c = new QMPageChoice(
|
||||
parent, {LCD_W / 4, y, LCD_W * 2 / 3, 0}, qmPages, QM_NONE, qmPages.size() - 1,
|
||||
[=]() -> int {
|
||||
auto pg = g_eeGeneral.qmFavorites[i].shortcut;
|
||||
if (pg < QM_APP)
|
||||
return pg;
|
||||
std::string nm = g_eeGeneral.getFavoriteToolName(i);
|
||||
int idx = getLuaToolId(nm);
|
||||
if (idx >= 0)
|
||||
return pg + idx;
|
||||
return QM_NONE;
|
||||
},
|
||||
[=](int32_t pg) {
|
||||
g_eeGeneral.qmFavorites[i].shortcut = (QMPage)pg;
|
||||
if (pg < QM_APP) {
|
||||
g_eeGeneral.qmFavorites[i].shortcut = (QMPage)pg;
|
||||
g_eeGeneral.setFavoriteToolName(i, "");
|
||||
} else {
|
||||
g_eeGeneral.qmFavorites[i].shortcut = QM_APP;
|
||||
g_eeGeneral.setFavoriteToolName(i, getLuaTool(pg - QM_APP)->label);
|
||||
}
|
||||
changed = true;
|
||||
SET_DIRTY();
|
||||
}, STR_QUICK_MENU_FAVORITES);
|
||||
|
||||
c->setPopupWidth(LCD_W * 3 / 4);
|
||||
c->setAvailableHandler(
|
||||
[=](int pg) {
|
||||
if (pg == QM_NONE) return true;
|
||||
for (int i = 0; i < MAX_QM_FAVORITES; i += 1)
|
||||
if (g_eeGeneral.qmFavorites[i].shortcut == (QMPage)pg)
|
||||
return false;
|
||||
if (pg < QM_APP) {
|
||||
for (int n = 0; n < MAX_QM_FAVORITES; n += 1)
|
||||
if (g_eeGeneral.qmFavorites[n].shortcut == (QMPage)pg)
|
||||
return n == i;
|
||||
} else {
|
||||
for (int n = 0; n < MAX_QM_FAVORITES; n += 1)
|
||||
if (g_eeGeneral.qmFavorites[n].shortcut == QM_APP) {
|
||||
int idx = getLuaToolId(g_eeGeneral.getFavoriteToolName(n)) + QM_APP;
|
||||
if (idx == pg)
|
||||
return n == i;
|
||||
}
|
||||
}
|
||||
return pg != QM_OPEN_QUICK_MENU; }
|
||||
);
|
||||
});
|
||||
|
||||
@@ -188,6 +188,9 @@ void QuickMenuGroup::deleteLater()
|
||||
|
||||
void QuickMenuGroup::setFocus()
|
||||
{
|
||||
if (!curBtn && btns.size() > 0)
|
||||
curBtn = btns[0];
|
||||
|
||||
if (curBtn) {
|
||||
lv_event_send(curBtn->getLvObj(), LV_EVENT_FOCUSED, nullptr);
|
||||
lv_group_focus_obj(curBtn->getLvObj());
|
||||
|
||||
Reference in New Issue
Block a user