1
0
Fork 0

GUI: add auto completion to "Add exception breakpoint" dialog

This commit is contained in:
Georgeto 2017-08-21 18:29:38 +02:00 committed by Duncan Ogilvie
parent c78ffc38f1
commit 16b40aab5b
8 changed files with 305 additions and 7 deletions

View File

@ -4,7 +4,7 @@
#include "Breakpoints.h"
BreakpointsView::BreakpointsView(QWidget* parent)
: StdTable(parent)
: StdTable(parent), mExceptionMaxLength(0)
{
auto charWidth = [this](int count)
{
@ -187,7 +187,13 @@ void BreakpointsView::updateBreakpointsSlot()
BridgeList<CONSTANTINFO> exceptions;
DbgFunctions()->EnumExceptions(&exceptions);
for(int i = 0; i < exceptions.Count(); i++)
{
mExceptionMap.insert({exceptions[i].value, exceptions[i].name});
mExceptionList.append(QString(exceptions[i].name));
mExceptionMaxLength = std::max<int>(mExceptionMaxLength, strlen(exceptions[i].name));
}
mExceptionList.sort();
}
BPMAP bpmap;
DbgGetBpList(bp_none, &bpmap);
@ -650,7 +656,7 @@ void BreakpointsView::addDllBreakpointSlot()
void BreakpointsView::addExceptionBreakpointSlot()
{
QString fileName;
if(SimpleInputBox(this, tr("Enter the exception code"), "", fileName, tr("Example: EXCEPTION_ACCESS_VIOLATION"), &DIcon("breakpoint.png")) && !fileName.isEmpty())
DbgCmdExec((QString("SetExceptionBPX ") + fileName));
QString exception;
if(SimpleChoiceBox(this, tr("Enter the exception code"), "", mExceptionList, exception, true, tr("Example: EXCEPTION_ACCESS_VIOLATION"), &DIcon("breakpoint.png"), mExceptionMaxLength) && !exception.isEmpty())
DbgCmdExec((QString("SetExceptionBPX ") + exception));
}

View File

@ -48,6 +48,8 @@ private:
};
std::unordered_map<duint, const char*> mExceptionMap;
QStringList mExceptionList;
int mExceptionMaxLength;
std::vector<BRIDGEBP> mBps;
std::vector<std::pair<RichTextPainter::List, RichTextPainter::List>> mRich;
QColor mDisasmBackgroundColor;

View File

@ -0,0 +1,92 @@
#include "ComboBoxDialog.h"
#include "ui_ComboBoxDialog.h"
#include <QLineEdit>
#include <QStringListModel>
#include <QListView>
#include <QCompleter>
ComboBoxDialog::ComboBoxDialog(QWidget* parent) : QDialog(parent), ui(new Ui::ComboBoxDialog)
{
ui->setupUi(this);
setModal(true);
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint | Qt::MSWindowsFixedSizeDialogHint);
setModal(true); //modal window
ui->comboBox->setInsertPolicy(QComboBox::NoInsert);
ui->comboBox->setEditable(false);
ui->comboBox->setModel(new QStringListModel(this));
ui->checkBox->hide();
bChecked = false;
ui->label->setVisible(false);
}
ComboBoxDialog::~ComboBoxDialog()
{
delete ui;
}
void ComboBoxDialog::setEditable(bool editable)
{
ui->comboBox->setEditable(editable);
if(editable)
ui->comboBox->completer()->setCompletionMode(QCompleter::PopupCompletion);
}
void ComboBoxDialog::setItems(const QStringList & items)
{
((QStringListModel*)ui->comboBox->model())->setStringList(items);
}
void ComboBoxDialog::setMinimumContentsLength(int characters)
{
ui->comboBox->setMinimumContentsLength(characters);
// For performance reasons use this policy on large models.
ui->comboBox->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon);
}
QString ComboBoxDialog::currentText()
{
return ui->comboBox->currentText();
}
void ComboBoxDialog::setText(const QString & text)
{
if(ui->comboBox->isEditable())
{
ui->comboBox->setEditText(text);
ui->comboBox->lineEdit()->selectAll();
}
else
{
ui->comboBox->setCurrentIndex(ui->comboBox->findText(text));
}
}
void ComboBoxDialog::setPlaceholderText(const QString & text)
{
if(ui->comboBox->isEditable())
ui->comboBox->lineEdit()->setPlaceholderText(text);
}
void ComboBoxDialog::enableCheckBox(bool bEnable)
{
if(bEnable)
ui->checkBox->show();
else
ui->checkBox->hide();
}
void ComboBoxDialog::setCheckBox(bool bSet)
{
ui->checkBox->setChecked(bSet);
bChecked = bSet;
}
void ComboBoxDialog::setCheckBoxText(const QString & text)
{
ui->checkBox->setText(text);
}
void ComboBoxDialog::on_checkBox_toggled(bool checked)
{
bChecked = checked;
}

View File

@ -0,0 +1,38 @@
#ifndef COMBOBOXDIALOG_H
#define COMBOBOXDIALOG_H
#include <QDialog>
namespace Ui
{
class ComboBoxDialog;
}
class ComboBoxDialog : public QDialog
{
Q_OBJECT
public:
explicit ComboBoxDialog(QWidget* parent = 0);
~ComboBoxDialog();
bool bChecked;
QString currentText();
void setEditable(bool editable);
void setItems(const QStringList & items);
// Minimum number of characters that should fit into the combobox.
// Use for large models, so that the length is not computed from its items.
void setMinimumContentsLength(int characters);
void setText(const QString & text);
void setPlaceholderText(const QString & text);
void enableCheckBox(bool bEnable);
void setCheckBox(bool bSet);
void setCheckBoxText(const QString & text);
private slots:
void on_checkBox_toggled(bool checked);
private:
Ui::ComboBoxDialog* ui;
};
#endif // COMBOBOXDIALOG_H

View File

@ -0,0 +1,134 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ComboBoxDialog</class>
<widget class="QDialog" name="ComboBoxDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>414</width>
<height>72</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<property name="windowIcon">
<iconset resource="../../resource.qrc">
<normaloff>:/icons/images/ui-combo-box-edit.png</normaloff>:/icons/images/ui-combo-box-edit.png</iconset>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QComboBox" name="comboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="minimumSize">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox">
<property name="text">
<string>CheckBox</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="buttonOk">
<property name="text">
<string>&amp;OK</string>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonCancel">
<property name="text">
<string>&amp;Cancel</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<resources>
<include location="../../resource.qrc"/>
</resources>
<connections>
<connection>
<sender>buttonOk</sender>
<signal>clicked()</signal>
<receiver>ComboBoxDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>243</x>
<y>49</y>
</hint>
<hint type="destinationlabel">
<x>150</x>
<y>57</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonCancel</sender>
<signal>clicked()</signal>
<receiver>ComboBoxDialog</receiver>
<slot>close()</slot>
<hints>
<hint type="sourcelabel">
<x>320</x>
<y>51</y>
</hint>
<hint type="destinationlabel">
<x>150</x>
<y>41</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -1,6 +1,7 @@
#include "MiscUtil.h"
#include <windows.h>
#include "LineEditDialog.h"
#include "ComboBoxDialog.h"
#include <QMessageBox>
#include "StringUtil.h"
@ -40,6 +41,27 @@ bool SimpleInputBox(QWidget* parent, const QString & title, QString defaultValue
return false;
}
bool SimpleChoiceBox(QWidget* parent, const QString & title, QString defaultValue, const QStringList & choices, QString & output, bool editable, const QString & placeholderText, QIcon* icon, int minimumContentsLength)
{
ComboBoxDialog mChoice(parent);
mChoice.setWindowIcon(icon ? *icon : parent->windowIcon());
mChoice.setEditable(editable);
mChoice.setItems(choices);
mChoice.setText(defaultValue);
mChoice.setPlaceholderText(placeholderText);
mChoice.setWindowTitle(title);
mChoice.setCheckBox(false);
if(minimumContentsLength >= 0)
mChoice.setMinimumContentsLength(minimumContentsLength);
if(mChoice.exec() == QDialog::Accepted)
{
output = mChoice.currentText();
return true;
}
else
return false;
}
void SimpleErrorBox(QWidget* parent, const QString & title, const QString & text)
{
QMessageBox msg(QMessageBox::Critical, title, text, QMessageBox::NoButton, parent);

View File

@ -10,6 +10,7 @@ class QByteArray;
void SetApplicationIcon(WId winId);
QByteArray & ByteReverse(QByteArray & array);
bool SimpleInputBox(QWidget* parent, const QString & title, QString defaultValue, QString & output, const QString & placeholderText, QIcon* icon = nullptr);
bool SimpleChoiceBox(QWidget* parent, const QString & title, QString defaultValue, const QStringList & choices, QString & output, bool editable, const QString & placeholderText, QIcon* icon = nullptr, int minimumContentsLength = -1);
void SimpleErrorBox(QWidget* parent, const QString & title, const QString & text);
void SimpleWarningBox(QWidget* parent, const QString & title, const QString & text);
void SimpleInfoBox(QWidget* parent, const QString & title, const QString & text);

View File

@ -179,7 +179,8 @@ SOURCES += \
Src/Gui/LocalVarsView.cpp \
Src/Gui/MessagesBreakpoints.cpp \
Src/Gui/AboutDialog.cpp \
Src/Gui/BreakpointMenu.cpp
Src/Gui/BreakpointMenu.cpp \
Src/Gui/ComboBoxDialog.cpp
HEADERS += \
@ -293,7 +294,8 @@ HEADERS += \
Src/Gui/LocalVarsView.h \
Src/Gui/MessagesBreakpoints.h \
Src/Gui/AboutDialog.h \
Src/Gui/BreakpointMenu.h
Src/Gui/BreakpointMenu.h \
Src/Gui/ComboBoxDialog.h
FORMS += \
@ -334,7 +336,8 @@ FORMS += \
Src/Gui/StructWidget.ui \
Src/Gui/SimpleTraceDialog.ui \
Src/Gui/MessagesBreakpoints.ui \
Src/Gui/AboutDialog.ui
Src/Gui/AboutDialog.ui \
Src/Gui/ComboBoxDialog.ui
##
## Libraries