Change edit dialog to allow no preview (#869)

* Change edit dialog to allow no preview

* AStyle fixes

* More style fixes, forgot some files
This commit is contained in:
Rune Tynan 2018-10-23 01:06:26 -04:00 committed by Itay Cohen
parent 528adf429a
commit 3400314cd2
4 changed files with 21 additions and 14 deletions

View File

@ -2,10 +2,10 @@
#include "ui_EditInstructionDialog.h" #include "ui_EditInstructionDialog.h"
#include "Cutter.h" #include "Cutter.h"
EditInstructionDialog::EditInstructionDialog(QWidget *parent, bool isEditingBytes) : EditInstructionDialog::EditInstructionDialog(QWidget *parent, InstructionEditMode editMode) :
QDialog(parent), QDialog(parent),
ui(new Ui::EditInstructionDialog), ui(new Ui::EditInstructionDialog),
isEditingBytes(isEditingBytes) editMode(editMode)
{ {
ui->setupUi(this); ui->setupUi(this);
setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint)); setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
@ -40,9 +40,13 @@ void EditInstructionDialog::setInstruction(const QString &instruction)
void EditInstructionDialog::updatePreview(const QString &input) void EditInstructionDialog::updatePreview(const QString &input)
{ {
QString result; QString result;
if (isEditingBytes) {
if (editMode == EDIT_NONE) {
ui->instructionLabel->setText("");
return;
} else if (editMode == EDIT_BYTES) {
result = Core()->disassemble(input).trimmed(); result = Core()->disassemble(input).trimmed();
} else { } else if (editMode == EDIT_TEXT) {
result = Core()->assemble(input).trimmed(); result = Core()->assemble(input).trimmed();
} }

View File

@ -9,12 +9,16 @@ namespace Ui {
class EditInstructionDialog; class EditInstructionDialog;
} }
enum InstructionEditMode {
EDIT_NONE, EDIT_BYTES, EDIT_TEXT
};
class EditInstructionDialog : public QDialog class EditInstructionDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit EditInstructionDialog(QWidget *parent, bool isEditingBytes); explicit EditInstructionDialog(QWidget *parent, InstructionEditMode isEditingBytes);
~EditInstructionDialog(); ~EditInstructionDialog();
QString getInstruction(); QString getInstruction();
@ -29,7 +33,7 @@ private slots:
private: private:
std::unique_ptr<Ui::EditInstructionDialog> ui; std::unique_ptr<Ui::EditInstructionDialog> ui;
bool isEditingBytes; // true if editing intruction **bytes**; false if editing instruction **text** InstructionEditMode editMode; // true if editing intruction **bytes**; false if editing instruction **text**
}; };
#endif // EDITINSTRUCTIONDIALOG_H #endif // EDITINSTRUCTIONDIALOG_H

View File

@ -40,7 +40,7 @@ DisassemblyContextMenu::DisassemblyContextMenu(QWidget *parent)
addAction(&actionRename); addAction(&actionRename);
initAction(&actionEditFunction, tr("Edit function"), initAction(&actionEditFunction, tr("Edit function"),
SLOT(on_actionEditFunction_triggered())); SLOT(on_actionEditFunction_triggered()));
addAction(&actionEditFunction); addAction(&actionEditFunction);
initAction(&actionRenameUsedHere, tr("Rename Flag/Fcn/Var Used Here"), initAction(&actionRenameUsedHere, tr("Rename Flag/Fcn/Var Used Here"),
@ -234,7 +234,7 @@ void DisassemblyContextMenu::aboutToShowSlot()
{ {
// check if set immediate base menu makes sense // check if set immediate base menu makes sense
QJsonObject instObject = Core()->cmdj("aoj @ " + QString::number( QJsonObject instObject = Core()->cmdj("aoj @ " + QString::number(
offset)).array().first().toObject(); offset)).array().first().toObject();
auto keys = instObject.keys(); auto keys = instObject.keys();
bool immBase = keys.contains("val") || keys.contains("ptr"); bool immBase = keys.contains("val") || keys.contains("ptr");
setBaseMenu->menuAction()->setVisible(immBase); setBaseMenu->menuAction()->setVisible(immBase);
@ -355,7 +355,7 @@ QKeySequence DisassemblyContextMenu::getRenameUsedHereSequence() const
QKeySequence DisassemblyContextMenu::getRetypeSequence() const QKeySequence DisassemblyContextMenu::getRetypeSequence() const
{ {
return {Qt::Key_Y}; return {Qt::Key_Y};
} }
QKeySequence DisassemblyContextMenu::getXRefSequence() const QKeySequence DisassemblyContextMenu::getXRefSequence() const
@ -375,7 +375,7 @@ QList<QKeySequence> DisassemblyContextMenu::getAddBPSequence() const
void DisassemblyContextMenu::on_actionEditInstruction_triggered() void DisassemblyContextMenu::on_actionEditInstruction_triggered()
{ {
EditInstructionDialog *e = new EditInstructionDialog(this, false); EditInstructionDialog *e = new EditInstructionDialog(this, EDIT_TEXT);
e->setWindowTitle(tr("Edit Instruction at %1").arg(RAddressString(offset))); e->setWindowTitle(tr("Edit Instruction at %1").arg(RAddressString(offset)));
QString oldInstructionOpcode = Core()->getInstructionOpcode(offset); QString oldInstructionOpcode = Core()->getInstructionOpcode(offset);
@ -440,7 +440,7 @@ void DisassemblyContextMenu::on_actionJmpReverse_triggered()
void DisassemblyContextMenu::on_actionEditBytes_triggered() void DisassemblyContextMenu::on_actionEditBytes_triggered()
{ {
EditInstructionDialog *e = new EditInstructionDialog(this, true); EditInstructionDialog *e = new EditInstructionDialog(this, EDIT_BYTES);
e->setWindowTitle(tr("Edit Bytes at %1").arg(RAddressString(offset))); e->setWindowTitle(tr("Edit Bytes at %1").arg(RAddressString(offset)));
QString oldBytes = Core()->getInstructionBytes(offset); QString oldBytes = Core()->getInstructionBytes(offset);
@ -747,7 +747,7 @@ void DisassemblyContextMenu::setToData(int size, int repeat)
} }
QAction *DisassemblyContextMenu::addAnonymousAction(QString name, const char *slot, QAction *DisassemblyContextMenu::addAnonymousAction(QString name, const char *slot,
QKeySequence keySequence) QKeySequence keySequence)
{ {
auto action = new QAction(); auto action = new QAction();
addAction(action); addAction(action);

View File

@ -123,8 +123,7 @@ void StackWidget::editStack()
bool ok; bool ok;
int row = viewStack->selectionModel()->currentIndex().row(); int row = viewStack->selectionModel()->currentIndex().row();
QString offset = viewStack->selectionModel()->currentIndex().sibling(row, 0).data().toString(); QString offset = viewStack->selectionModel()->currentIndex().sibling(row, 0).data().toString();
// FIXME: This is not correct because there should be no preview of anything EditInstructionDialog *e = new EditInstructionDialog(this, EDIT_NONE);
EditInstructionDialog *e = new EditInstructionDialog(this, false);
e->setWindowTitle(tr("Edit stack at %1").arg(offset)); e->setWindowTitle(tr("Edit stack at %1").arg(offset));
QString oldBytes = viewStack->selectionModel()->currentIndex().sibling(row, 1).data().toString(); QString oldBytes = viewStack->selectionModel()->currentIndex().sibling(row, 1).data().toString();