1
0

Implemented browser menu location (closes #71) (#74)

This commit is contained in:
Patrick Gaskin
2020-08-05 00:54:35 -04:00
committed by GitHub
parent 397964e761
commit 8fb56eacdd
4 changed files with 22 additions and 12 deletions

View File

@@ -15,8 +15,9 @@
# Adds a menu item.
#
# <location> the menu to add the item to, one of:
# main - the menu in the top-left corner of the home screen
# reader - the overflow menu in the reader
# main - the menu in the top-left corner of the home screen
# reader - the overflow menu in the reader
# browser - the menu in the bottom-right of the web browser
# <label> the label to show on the menu item (must not contain :)
# <action> the type of action to run, one of:
# cmd_spawn - starts a command in the background

View File

@@ -305,7 +305,7 @@ nm_config_t *nm_config_parse(nm_config_file_t *files) {
}))) RETERR("error appending default action to empty config: %s", nm_config_parse__strerror(ret));
}
size_t mm = 0, rm = 0;
size_t mm = 0, rm = 0, bm = 0;
for (nm_config_t *cur = state.cfg_s; cur; cur = cur->next) {
switch (cur->type) {
case NM_CONFIG_TYPE_MENU_ITEM:
@@ -313,8 +313,9 @@ nm_config_t *nm_config_parse(nm_config_file_t *files) {
for (nm_menu_action_t *cur_act = cur->value.menu_item->action; cur_act; cur_act = cur_act->next)
NM_LOG("...cfg(NM_CONFIG_TYPE_MENU_ITEM) (%s%s%s) : %p:%s", cur_act->on_success ? "on_success" : "", (cur_act->on_success && cur_act->on_failure) ? ", " : "", cur_act->on_failure ? "on_failure" : "", cur_act->act, cur_act->arg);
switch (cur->value.menu_item->loc) {
case NM_MENU_LOCATION_MAIN_MENU: mm++; break;
case NM_MENU_LOCATION_READER_MENU: rm++; break;
case NM_MENU_LOCATION_MAIN_MENU: mm++; break;
case NM_MENU_LOCATION_READER_MENU: rm++; break;
case NM_MENU_LOCATION_BROWSER_MENU: bm++; break;
}
break;
case NM_CONFIG_TYPE_GENERATOR:
@@ -327,6 +328,8 @@ nm_config_t *nm_config_parse(nm_config_file_t *files) {
RETERR("too many menu items in main menu (> %d)", NM_CONFIG_MAX_MENU_ITEMS_PER_MENU);
if (rm > NM_CONFIG_MAX_MENU_ITEMS_PER_MENU)
RETERR("too many menu items in reader menu (> %d)", NM_CONFIG_MAX_MENU_ITEMS_PER_MENU);
if (bm > NM_CONFIG_MAX_MENU_ITEMS_PER_MENU)
RETERR("too many menu items in browser menu (> %d)", NM_CONFIG_MAX_MENU_ITEMS_PER_MENU);
return state.cfg_s;
}
@@ -340,9 +343,10 @@ static bool nm_config_parse__line_item(const char *type, char **line, nm_menu_it
*it_out = (nm_menu_item_t){0};
char *s_loc = strtrim(strsep(line, ":"));
if (!s_loc) NM_ERR_RET(NULL, "field 2: expected location, got end of line");
else if (!strcmp(s_loc, "main")) it_out->loc = NM_MENU_LOCATION_MAIN_MENU;
else if (!strcmp(s_loc, "reader")) it_out->loc = NM_MENU_LOCATION_READER_MENU;
if (!s_loc) NM_ERR_RET(NULL, "field 2: expected location, got end of line");
else if (!strcmp(s_loc, "main")) it_out->loc = NM_MENU_LOCATION_MAIN_MENU;
else if (!strcmp(s_loc, "reader")) it_out->loc = NM_MENU_LOCATION_READER_MENU;
else if (!strcmp(s_loc, "browser")) it_out->loc = NM_MENU_LOCATION_BROWSER_MENU;
else NM_ERR_RET(NULL, "field 2: unknown location '%s'", s_loc);
char *p_lbl = strtrim(strsep(line, ":"));

View File

@@ -10,8 +10,9 @@ extern "C" {
#include "action.h"
typedef enum {
NM_MENU_LOCATION_MAIN_MENU = 1,
NM_MENU_LOCATION_READER_MENU = 2,
NM_MENU_LOCATION_MAIN_MENU = 1,
NM_MENU_LOCATION_READER_MENU = 2,
NM_MENU_LOCATION_BROWSER_MENU = 3,
} nm_menu_location_t;
typedef struct nm_menu_action_t {

View File

@@ -140,8 +140,9 @@ extern "C" __attribute__((visibility("default"))) MenuTextItem* _nm_menu_hook(vo
NM_LOG("AbstractNickelMenuController::createMenuTextItem(%p, `%s`, %d, %d, `%s`)", menu, qPrintable(label), checkable, checked, qPrintable(thingy));
QString trmm = QCoreApplication::translate("StatusBarMenuController", "Settings");
QString trrm = QCoreApplication::translate("DictionaryActionProxy", "Dictionary");
NM_LOG("Comparing against '%s', '%s'", qPrintable(trmm), qPrintable(trrm));
QString trrm = QCoreApplication::translate("DictionaryActionProxy", "Set Page as Home");
QString trbm = QCoreApplication::translate("N3BrowserSettingsMenuController", "Keyboard");
NM_LOG("Comparing against '%s', '%s', '%s'", qPrintable(trmm), qPrintable(trrm), qPrintable(trbm));
nm_menu_location_t loc = {};
if (label == trmm && !checkable) {
@@ -150,6 +151,9 @@ extern "C" __attribute__((visibility("default"))) MenuTextItem* _nm_menu_hook(vo
} else if (label == trrm && !checkable) {
NM_LOG("Intercepting reader menu (label=Dictionary, checkable=false)...");
loc = NM_MENU_LOCATION_READER_MENU;
} else if (label == trbm && !checkable) {
NM_LOG("Intercepting browser menu (label=Keyboard, checkable=false)...");
loc = NM_MENU_LOCATION_BROWSER_MENU;
}
if (loc)