Skip to content

Commit b5deb13

Browse files
committed
Function signature table in edit function dialog
1 parent f24f8f5 commit b5deb13

File tree

3 files changed

+99
-32
lines changed

3 files changed

+99
-32
lines changed

ui/completioncombobox.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#pragma once
2+
3+
#include <QtGui/QKeyEvent>
4+
#include <QtWidgets/QComboBox>
5+
6+
//! CompletionComboBox is a subclass of QComboBox intended to have a more
7+
//! familiar user experience when working with auto-completion.
8+
//!
9+
//! Most notably, the <TAB> keypress is intercepted so that the tab key can be
10+
//! used to cycle through completion options. This is similar the behavior found
11+
//! in most text editors and IDEs.
12+
//!
13+
//! Additionally, the combo box is editable and uses case-sensitive matching,
14+
//! popup-style completion, and a "no insert" policy by default.
15+
class CompletionComboBox : public QComboBox {
16+
Q_OBJECT
17+
18+
bool m_forwardReturnEvents = true;
19+
20+
//! Manually cycle the selected completion suggestion, forward by default.
21+
bool cycleCompletion(bool forward = true);
22+
23+
protected:
24+
bool event(QEvent* event) override;
25+
26+
public:
27+
CompletionComboBox(QWidget* parent = nullptr);
28+
29+
void setForwardReturnEvents(bool forward) { m_forwardReturnEvents = forward; }
30+
31+
Q_SIGNALS:
32+
void enterPressed();
33+
};

ui/typecompletioncombobox.h

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#pragma once
2+
3+
#include <QtCore/QStringListModel>
4+
#ifndef BINARYNINJAUI_BINDINGS
5+
#include <QtCore/QThread>
6+
#endif
7+
#include <optional>
8+
#include "completioncombobox.h"
9+
#include "binaryninjaapi.h"
10+
#include "uitypes.h"
11+
12+
13+
/*!
14+
15+
\ingroup typedialog
16+
*/
17+
class BINARYNINJAUIAPI GetTypesListThread : public QThread
18+
{
19+
Q_OBJECT
20+
21+
QStringList m_allTypes;
22+
std::function<void()> m_completeFunc;
23+
std::mutex m_mutex;
24+
bool m_done;
25+
BinaryNinja::TypeContainer m_typeContainer;
26+
27+
protected:
28+
virtual void run() override;
29+
30+
public:
31+
GetTypesListThread(BinaryNinja::TypeContainer typeContainer, const std::function<void()>& completeFunc);
32+
void cancel();
33+
34+
const QStringList& getTypes() const { return m_allTypes; }
35+
};
36+
37+
//! A CompletionComboBox pre-configured for type name autocompletion.
38+
//!
39+
//! Fetches type names from a TypeContainer in a background thread and populates
40+
//! the completer model. Respects the ui.types.substring and
41+
//! ui.types.maxAutoFeaturesCount settings.
42+
//!
43+
//! Optionally manages a persistent input history stored in QSettings.
44+
class BINARYNINJAUIAPI TypeCompletionComboBox : public CompletionComboBox
45+
{
46+
Q_OBJECT
47+
48+
QStringListModel* m_model;
49+
GetTypesListThread* m_updateThread = nullptr;
50+
QStringList m_historyEntries;
51+
int m_historySize;
52+
53+
void customEvent(QEvent* event) override;
54+
55+
public:
56+
TypeCompletionComboBox(std::optional<BinaryNinja::TypeContainer> typeContainer, QWidget* parent = nullptr,
57+
QString existing = QString());
58+
~TypeCompletionComboBox();
59+
60+
//! Commit the current text to the persistent input history.
61+
void commitHistory();
62+
63+
QStringListModel* completionModel() const { return m_model; }
64+
};

ui/typedialog.h

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
#include <QtCore/QStringListModel>
66
#include <QtWidgets/QComboBox>
77
#include <QtCore/QTimer>
8-
#ifndef BINARYNINJAUI_BINDINGS
9-
#include <QtCore/QThread>
10-
#endif
118
#include "binaryninjaapi.h"
129
#include "uitypes.h"
10+
#include "typecompletioncombobox.h"
1311

1412

1513
#ifdef BINARYNINJAUI_BINDINGS
@@ -24,30 +22,6 @@ class ParseTypeThread;
2422
\ingroup uiapi
2523
*/
2624

27-
/*!
28-
29-
\ingroup typedialog
30-
*/
31-
class BINARYNINJAUIAPI GetTypesListThread : public QThread
32-
{
33-
Q_OBJECT
34-
35-
QStringList m_allTypes;
36-
std::function<void()> m_completeFunc;
37-
std::mutex m_mutex;
38-
bool m_done;
39-
BinaryNinja::TypeContainer m_typeContainer;
40-
41-
protected:
42-
virtual void run() override;
43-
44-
public:
45-
GetTypesListThread(BinaryNinja::TypeContainer typeContainer, const std::function<void()>& completeFunc);
46-
void cancel();
47-
48-
const QStringList& getTypes() const { return m_allTypes; }
49-
};
50-
5125
Q_DECLARE_METATYPE(BinaryNinja::QualifiedNameAndType);
5226

5327
/*! QThread subclass for handling type string parsing to avoid UI interruptions.
@@ -80,16 +54,13 @@ class BINARYNINJAUIAPI TypeDialog : public QDialog
8054
{
8155
Q_OBJECT
8256

83-
QComboBox* m_combo;
57+
TypeCompletionComboBox* m_combo;
8458
QStringListModel* m_model;
8559
QLabel* m_prompt;
8660
QString m_promptText;
8761
std::optional<BinaryNinja::TypeContainer> m_typeContainer;
8862
bool m_resultValid = true;
8963
bool m_resolved = false;
90-
QStringList m_historyEntries;
91-
int m_historySize;
92-
GetTypesListThread* m_updateThread = nullptr;
9364
BinaryNinja::QualifiedNameAndType m_type;
9465
QPushButton* m_acceptButton;
9566
QTimer* m_updateTimer;
@@ -99,7 +70,6 @@ class BINARYNINJAUIAPI TypeDialog : public QDialog
9970
QString m_parseError;
10071

10172
void commitHistory();
102-
void customEvent(QEvent* event);
10373
void saveLocation();
10474
void reject();
10575
void accept();

0 commit comments

Comments
 (0)