Skip to content

Commit 96a92d3

Browse files
vcrypt: fix context menu now that its registered twice
1 parent c931343 commit 96a92d3

File tree

2 files changed

+32
-27
lines changed

2 files changed

+32
-27
lines changed

src/gui/plugins/previews/vcrypt/VCryptPreview.cpp

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -191,35 +191,35 @@ void VCryptPreview::initContextMenu(int contextMenuType, QMenu* contextMenu) {
191191
return;
192192
}
193193

194-
this->encryptionMenu = contextMenu->addMenu(this->getIcon(), "VCrypt");
195-
this->encryptICEAction = this->encryptionMenu->addAction(this->getIcon(), tr("Encrypt ICE"), [this] {
196-
for (const auto path : this->selectedPaths) {
194+
this->encryptionMenus.push_back(contextMenu->addMenu(this->getIcon(), "VCrypt"));
195+
this->encryptICEActions.push_back(this->encryptionMenus.back()->addAction(this->getIcon(), tr("Encrypt ICE"), [this] {
196+
for (const auto& path : this->selectedPaths) {
197197
if (path.endsWith(".txt") || path.endsWith(".kv") || path.endsWith(".nut")) {
198198
this->encryptICE(path);
199199
}
200200
}
201-
});
202-
this->decryptICEAction = this->encryptionMenu->addAction(this->getIcon(), tr("Decrypt ICE"), [this] {
203-
for (const auto path : this->selectedPaths) {
201+
}));
202+
this->decryptICEActions.push_back(this->encryptionMenus.back()->addAction(this->getIcon(), tr("Decrypt ICE"), [this] {
203+
for (const auto& path : this->selectedPaths) {
204204
if (path.endsWith(".ctx") || path.endsWith(".ekv") || path.endsWith(".nuc")) {
205205
this->decryptICE(path);
206206
}
207207
}
208-
});
209-
this->encryptFontAction = this->encryptionMenu->addAction(this->getIcon(), tr("Encrypt Font"), [this] {
210-
for (const auto path : this->selectedPaths) {
208+
}));
209+
this->encryptFontActions.push_back(this->encryptionMenus.back()->addAction(this->getIcon(), tr("Encrypt Font"), [this] {
210+
for (const auto& path : this->selectedPaths) {
211211
if (path.endsWith(".ttf")) {
212212
this->encryptFont(path);
213213
}
214214
}
215-
});
216-
this->decryptFontAction = this->encryptionMenu->addAction(this->getIcon(), tr("Decrypt Font"), [this] {
217-
for (const auto path : this->selectedPaths) {
215+
}));
216+
this->decryptFontActions.push_back(this->encryptionMenus.back()->addAction(this->getIcon(), tr("Decrypt Font"), [this] {
217+
for (const auto& path : this->selectedPaths) {
218218
if (path.endsWith(".vfont")) {
219219
this->decryptFont(path);
220220
}
221221
}
222-
});
222+
}));
223223
}
224224

225225
void VCryptPreview::updateContextMenu(int contextMenuType, const QStringList& paths) {
@@ -228,24 +228,29 @@ void VCryptPreview::updateContextMenu(int contextMenuType, const QStringList& pa
228228
}
229229
this->selectedPaths = paths;
230230

231-
this->encryptICEAction->setVisible(false);
232-
this->decryptICEAction->setVisible(false);
233-
this->encryptFontAction->setVisible(false);
234-
this->decryptFontAction->setVisible(false);
231+
bool encryptICEAction = false;
232+
bool decryptICEAction = false;
233+
bool encryptFontAction = false;
234+
bool decryptFontAction = false;
235235

236236
for (const auto& path : paths) {
237237
if (path.endsWith(".txt") || path.endsWith(".kv") || path.endsWith(".nut")) {
238-
this->encryptICEAction->setVisible(true);
238+
encryptICEAction = true;
239239
} else if (path.endsWith(".ctx") || path.endsWith(".ekv") || path.endsWith(".nuc")) {
240-
this->decryptICEAction->setVisible(true);
240+
decryptICEAction = true;
241241
} else if (path.endsWith(".ttf")) {
242-
this->encryptFontAction->setVisible(true);
242+
encryptFontAction = true;
243243
} else if (path.endsWith(".vfont")) {
244-
this->decryptFontAction->setVisible(true);
244+
decryptFontAction = true;
245245
}
246246
}
247247

248-
this->encryptionMenu->menuAction()->setVisible(this->encryptICEAction->isVisible() || this->decryptICEAction->isVisible() || this->encryptFontAction->isVisible() || this->decryptFontAction->isVisible());
248+
for (auto* action : this->encryptICEActions) { action->setVisible(encryptICEAction); }
249+
for (auto* action : this->decryptICEActions) { action->setVisible(decryptICEAction); }
250+
for (auto* action : this->encryptFontActions) { action->setVisible(encryptFontAction); }
251+
for (auto* action : this->decryptFontActions) { action->setVisible(decryptFontAction); }
252+
253+
for (const auto* menu : this->encryptionMenus) { menu->menuAction()->setVisible(encryptICEAction || decryptICEAction || encryptFontAction || decryptFontAction); }
249254
}
250255

251256
void VCryptPreview::encryptICE(const QString& path) const {

src/gui/plugins/previews/vcrypt/VCryptPreview.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ public slots:
7777
IVPKEditWindowAccess_V3* windowAccess = nullptr;
7878

7979
QStringList selectedPaths;
80-
QMenu* encryptionMenu = nullptr;
81-
QAction* encryptICEAction = nullptr;
82-
QAction* decryptICEAction = nullptr;
83-
QAction* encryptFontAction = nullptr;
84-
QAction* decryptFontAction = nullptr;
80+
QList<QMenu*> encryptionMenus;
81+
QList<QAction*> encryptICEActions;
82+
QList<QAction*> decryptICEActions;
83+
QList<QAction*> encryptFontActions;
84+
QList<QAction*> decryptFontActions;
8585
};

0 commit comments

Comments
 (0)