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) {
|
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));
|
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;
|
bool ismm, isrm;
|
||||||
if ((ismm = label == "Help" && !checkable))
|
if ((ismm = !label.compare("Help") && !checkable))
|
||||||
NMI_LOG("Intercepting main menu (label=Help, checkable=false)...");
|
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)...");
|
NMI_LOG("Intercepting reader menu (label=Dictionary, checkable=false)...");
|
||||||
|
|
||||||
bool add[_entries_n];
|
|
||||||
for (size_t i = 0; i < _entries_n; i++) {
|
for (size_t i = 0; i < _entries_n; i++) {
|
||||||
nmi_menu_entry_t *ent = &_entries[i];
|
nmi_menu_entry_t *ent = &_entries[i];
|
||||||
switch (_entries[i].loc) {
|
if (ent->loc == NMI_MENU_LOCATION_MAIN_MENU && !ismm)
|
||||||
case NMI_MENU_LOCATION_MAIN_MENU:
|
continue;
|
||||||
add[i] = ismm;
|
if (ent->loc == NMI_MENU_LOCATION_READER_MENU && !isrm)
|
||||||
case NMI_MENU_LOCATION_READER_MENU:
|
continue;
|
||||||
add[i] = isrm;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t i = 0; i < _entries_n; i++) {
|
NMI_LOG("Adding item '%s'...", ent->lbl);
|
||||||
nmi_menu_entry_t *ent = &_entries[i];
|
|
||||||
if (add[i]) {
|
|
||||||
NMI_LOG("Adding item '%s'...", ent->lbl);
|
|
||||||
|
|
||||||
QString lbl(ent->lbl);
|
QString lbl(ent->lbl);
|
||||||
MenuTextItem* item = AbstractNickelMenuController_createMenuTextItem_orig(_this, menu, lbl, false, false, "");
|
MenuTextItem* item = AbstractNickelMenuController_createMenuTextItem_orig(_this, menu, lbl, false, false, "");
|
||||||
QAction* action = AbstractNickelMenuController_createAction(_this, menu, item, true, true, 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
|
// 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){
|
QObject::connect(action, &QAction::triggered, std::function<void(bool)>([ent](bool checked){
|
||||||
NMI_LOG("Item '%s' pressed...", ent->lbl);
|
NMI_LOG("Item '%s' pressed...", ent->lbl);
|
||||||
char *err;
|
char *err;
|
||||||
if (ent->execute(ent->arg, &err) && err) {
|
if (ent->execute(ent->arg, &err) && err) {
|
||||||
NMI_LOG("Got error %s, displaying...", err);
|
NMI_LOG("Got error %s, displaying...", err);
|
||||||
QString title("nickel-menu-inject");
|
QString title("nickel-menu-inject");
|
||||||
QString text(err);
|
QString text(err);
|
||||||
ConfirmationDialogFactory_showOKDialog(title, text);
|
ConfirmationDialogFactory_showOKDialog(title, text);
|
||||||
free(err);
|
free(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
NMI_LOG("Success!", err);
|
NMI_LOG("Success!", err);
|
||||||
}));
|
}));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return AbstractNickelMenuController_createMenuTextItem_orig(_this, menu, label, checkable, checked, thingy);
|
return AbstractNickelMenuController_createMenuTextItem_orig(_this, menu, label, checkable, checked, thingy);
|
||||||
|
|||||||
Reference in New Issue
Block a user