Unify parents of dialogs shown by DecompilerContextMenu (#3066)

When triggered through a keyboard shortcut, the dialogs shown here would
be positioned at the last position of the context menu or (0, 0), which
is not desired. Using a currently shown widget as the parent fixes this.
This commit is contained in:
Florian Märkl 2023-01-04 18:23:07 +01:00 committed by GitHub
parent d47eb1c41f
commit 2d7fd02a62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 11 deletions

View File

@ -69,6 +69,11 @@ DecompilerContextMenu::DecompilerContextMenu(QWidget *parent, MainWindow *mainWi
DecompilerContextMenu::~DecompilerContextMenu() {} DecompilerContextMenu::~DecompilerContextMenu() {}
QWidget *DecompilerContextMenu::parentForDialog()
{
return parentWidget();
}
void DecompilerContextMenu::setAnnotationHere(RzCodeAnnotation *annotation) void DecompilerContextMenu::setAnnotationHere(RzCodeAnnotation *annotation)
{ {
annotationHere = annotation; annotationHere = annotation;
@ -404,14 +409,15 @@ void DecompilerContextMenu::actionRenameThingHereTriggered()
RzAnalysisFunction *func = Core()->functionAt(func_addr); RzAnalysisFunction *func = Core()->functionAt(func_addr);
if (func == NULL) { if (func == NULL) {
QString function_name = QInputDialog::getText( QString function_name = QInputDialog::getText(
this, tr("Define this function at %2").arg(RzAddressString(func_addr)), parentForDialog(),
tr("Define this function at %2").arg(RzAddressString(func_addr)),
tr("Function name:"), QLineEdit::Normal, currentName, &ok); tr("Function name:"), QLineEdit::Normal, currentName, &ok);
if (ok && !function_name.isEmpty()) { if (ok && !function_name.isEmpty()) {
Core()->createFunctionAt(func_addr, function_name); Core()->createFunctionAt(func_addr, function_name);
} }
} else { } else {
QString newName = QInputDialog::getText( QString newName = QInputDialog::getText(
this->mainWindow, tr("Rename function %2").arg(currentName), parentForDialog(), tr("Rename function %2").arg(currentName),
tr("Function name:"), QLineEdit::Normal, currentName, &ok); tr("Function name:"), QLineEdit::Normal, currentName, &ok);
if (ok && !newName.isEmpty()) { if (ok && !newName.isEmpty()) {
Core()->renameFunction(func_addr, newName); Core()->renameFunction(func_addr, newName);
@ -421,16 +427,16 @@ void DecompilerContextMenu::actionRenameThingHereTriggered()
RVA var_addr = annotationHere->reference.offset; RVA var_addr = annotationHere->reference.offset;
RzFlagItem *flagDetails = rz_flag_get_i(core->flags, var_addr); RzFlagItem *flagDetails = rz_flag_get_i(core->flags, var_addr);
if (flagDetails) { if (flagDetails) {
QString newName = QInputDialog::getText(this, tr("Rename %2").arg(flagDetails->name), QString newName = QInputDialog::getText(
tr("Enter name"), QLineEdit::Normal, parentForDialog(), tr("Rename %2").arg(flagDetails->name), tr("Enter name"),
flagDetails->name, &ok); QLineEdit::Normal, flagDetails->name, &ok);
if (ok && !newName.isEmpty()) { if (ok && !newName.isEmpty()) {
Core()->renameFlag(flagDetails->name, newName); Core()->renameFlag(flagDetails->name, newName);
} }
} else { } else {
QString newName = QInputDialog::getText( QString newName = QInputDialog::getText(
this, tr("Add name to %2").arg(curHighlightedWord), tr("Enter name"), parentForDialog(), tr("Add name to %2").arg(curHighlightedWord),
QLineEdit::Normal, curHighlightedWord, &ok); tr("Enter name"), QLineEdit::Normal, curHighlightedWord, &ok);
if (ok && !newName.isEmpty()) { if (ok && !newName.isEmpty()) {
Core()->addFlag(var_addr, newName, 1); Core()->addFlag(var_addr, newName, 1);
} }
@ -439,14 +445,14 @@ void DecompilerContextMenu::actionRenameThingHereTriggered()
if (!variablePresentInRizin()) { if (!variablePresentInRizin()) {
// Show can't rename this variable dialog // Show can't rename this variable dialog
QMessageBox::critical( QMessageBox::critical(
this, parentForDialog(),
tr("Rename local variable %1").arg(QString(annotationHere->variable.name)), tr("Rename local variable %1").arg(QString(annotationHere->variable.name)),
tr("Can't rename this variable. " tr("Can't rename this variable. "
"Only local variables defined in disassembly can be renamed.")); "Only local variables defined in disassembly can be renamed."));
return; return;
} }
QString oldName(annotationHere->variable.name); QString oldName(annotationHere->variable.name);
QString newName = QInputDialog::getText(this, tr("Rename %2").arg(oldName), QString newName = QInputDialog::getText(parentForDialog(), tr("Rename %2").arg(oldName),
tr("Enter name"), QLineEdit::Normal, oldName, &ok); tr("Enter name"), QLineEdit::Normal, oldName, &ok);
if (ok && !newName.isEmpty()) { if (ok && !newName.isEmpty()) {
Core()->renameFunctionVariable(newName, oldName, decompiledFunctionAddress); Core()->renameFunctionVariable(newName, oldName, decompiledFunctionAddress);
@ -465,13 +471,14 @@ void DecompilerContextMenu::actionEditFunctionVariablesTriggered()
return; return;
} else if (!variablePresentInRizin()) { } else if (!variablePresentInRizin()) {
QMessageBox::critical( QMessageBox::critical(
this, tr("Edit local variable %1").arg(QString(annotationHere->variable.name)), parentForDialog(),
tr("Edit local variable %1").arg(QString(annotationHere->variable.name)),
tr("Can't edit this variable. " tr("Can't edit this variable. "
"Only local variables defined in disassembly can be edited.")); "Only local variables defined in disassembly can be edited."));
return; return;
} }
EditVariablesDialog dialog(decompiledFunctionAddress, QString(annotationHere->variable.name), EditVariablesDialog dialog(decompiledFunctionAddress, QString(annotationHere->variable.name),
this); parentForDialog());
dialog.exec(); dialog.exec();
} }

View File

@ -111,6 +111,12 @@ private:
QAction actionSetPC; QAction actionSetPC;
// Private Functions // Private Functions
/**
* \return widget that should be used as parent for presenting dialogs
*/
QWidget *parentForDialog();
/** /**
* @brief Sets the shortcut context in all the actions contained * @brief Sets the shortcut context in all the actions contained
* in the specified QMenu to Qt::WidgetWithChildrenShortcut. * in the specified QMenu to Qt::WidgetWithChildrenShortcut.