Fixed everything
It works perfectly now!
This commit is contained in:
58
src/menu.cc
58
src/menu.cc
@@ -60,48 +60,40 @@ extern "C" int nmi_menu_hook(void *libnickel, nmi_menu_entry_t *entries, size_t
|
||||
extern "C" MenuTextItem* _nmi_menu_hook(void* _this, QMenu* menu, QString const& label, bool checkable, bool checked, QString const& thingy) {
|
||||
NMI_LOG("AbstractNickelMenuController::createMenuTextItem(%p, `%s`, %d, %d, `%s`)", menu, qPrintable(label), checkable, checked, qPrintable(thingy));
|
||||
|
||||
// TODO: test on other locales
|
||||
// TODO: handle other locales (either parse the translations file, call tr, or something else)
|
||||
bool ismm, isrm;
|
||||
if ((ismm = label == "Help" && !checkable))
|
||||
if ((ismm = !label.compare("Help") && !checkable))
|
||||
NMI_LOG("Intercepting main menu (label=Help, checkable=false)...");
|
||||
if ((isrm = label == "Dictionary" && !checkable))
|
||||
if ((isrm = !label.compare("Dictionary") && !checkable))
|
||||
NMI_LOG("Intercepting reader menu (label=Dictionary, checkable=false)...");
|
||||
|
||||
bool add[_entries_n];
|
||||
for (size_t i = 0; i < _entries_n; i++) {
|
||||
nmi_menu_entry_t *ent = &_entries[i];
|
||||
switch (_entries[i].loc) {
|
||||
case NMI_MENU_LOCATION_MAIN_MENU:
|
||||
add[i] = ismm;
|
||||
case NMI_MENU_LOCATION_READER_MENU:
|
||||
add[i] = isrm;
|
||||
}
|
||||
}
|
||||
if (ent->loc == NMI_MENU_LOCATION_MAIN_MENU && !ismm)
|
||||
continue;
|
||||
if (ent->loc == NMI_MENU_LOCATION_READER_MENU && !isrm)
|
||||
continue;
|
||||
|
||||
for (size_t i = 0; i < _entries_n; i++) {
|
||||
nmi_menu_entry_t *ent = &_entries[i];
|
||||
if (add[i]) {
|
||||
NMI_LOG("Adding item '%s'...", ent->lbl);
|
||||
NMI_LOG("Adding item '%s'...", ent->lbl);
|
||||
|
||||
QString lbl(ent->lbl);
|
||||
MenuTextItem* item = AbstractNickelMenuController_createMenuTextItem_orig(_this, menu, lbl, false, false, "");
|
||||
QAction* action = AbstractNickelMenuController_createAction(_this, menu, item, true, true, false);
|
||||
QString lbl(ent->lbl);
|
||||
MenuTextItem* item = AbstractNickelMenuController_createMenuTextItem_orig(_this, menu, lbl, false, false, "");
|
||||
QAction* action = AbstractNickelMenuController_createAction(_this, menu, item, true, true, false);
|
||||
|
||||
// note: we're capturing by value, i.e. the pointer to the global variable, rather then the stack variable, so this is safe
|
||||
QObject::connect(action, &QAction::triggered, std::function<void(bool)>([ent](bool checked){
|
||||
NMI_LOG("Item '%s' pressed...", ent->lbl);
|
||||
char *err;
|
||||
if (ent->execute(ent->arg, &err) && err) {
|
||||
NMI_LOG("Got error %s, displaying...", err);
|
||||
QString title("nickel-menu-inject");
|
||||
QString text(err);
|
||||
ConfirmationDialogFactory_showOKDialog(title, text);
|
||||
free(err);
|
||||
return;
|
||||
}
|
||||
NMI_LOG("Success!", err);
|
||||
}));
|
||||
}
|
||||
// note: we're capturing by value, i.e. the pointer to the global variable, rather then the stack variable, so this is safe
|
||||
QObject::connect(action, &QAction::triggered, std::function<void(bool)>([ent](bool checked){
|
||||
NMI_LOG("Item '%s' pressed...", ent->lbl);
|
||||
char *err;
|
||||
if (ent->execute(ent->arg, &err) && err) {
|
||||
NMI_LOG("Got error %s, displaying...", err);
|
||||
QString title("nickel-menu-inject");
|
||||
QString text(err);
|
||||
ConfirmationDialogFactory_showOKDialog(title, text);
|
||||
free(err);
|
||||
return;
|
||||
}
|
||||
NMI_LOG("Success!", err);
|
||||
}));
|
||||
}
|
||||
|
||||
return AbstractNickelMenuController_createMenuTextItem_orig(_this, menu, label, checkable, checked, thingy);
|
||||
|
||||
Reference in New Issue
Block a user