From 297a98bff289ecde90d808f6538c2c5edf804af6 Mon Sep 17 00:00:00 2001 From: 0cyn Date: Tue, 14 Apr 2026 05:03:15 -0400 Subject: Argument Assist Popup --- ui/scriptingconsole.h | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++ ui/uitypes.h | 4 ++-- 2 files changed, 64 insertions(+), 2 deletions(-) (limited to 'ui') diff --git a/ui/scriptingconsole.h b/ui/scriptingconsole.h index 9ebc0463..a403fbd9 100644 --- a/ui/scriptingconsole.h +++ b/ui/scriptingconsole.h @@ -11,7 +11,10 @@ #include #include #include +#include +#include #include +#include #include #include #include @@ -78,6 +81,33 @@ class BINARYNINJAUIAPI ScriptingCompletionPopup : public QDialog void complete(QString text); }; +/*! + Argument display popup. + + \ingroup scriptingconsole +*/ +class BINARYNINJAUIAPI ScriptingArgumentAssistPopup : public QDialog +{ + Q_OBJECT + + QTextBrowser* m_textDisplay; + QString m_text; + + Q_PROPERTY(QString text READ getText WRITE setText RESET unsetText) + + void updateText(); + +public: + ScriptingArgumentAssistPopup(QWidget* parent); + virtual ~ScriptingArgumentAssistPopup(); + void setText(const QString& text) { m_text = text; updateText(); } + QString getText() const { return m_text; } + void unsetText() { m_text.clear(); updateText(); } + +protected: + virtual bool eventFilter(QObject* obj, QEvent* event) override; +}; + /*! \ingroup scriptingconsole */ @@ -87,8 +117,17 @@ class BINARYNINJAUIAPI ScriptingConsoleEdit : public QTextEdit public: typedef std::function(const std::string&)> CompletionCallback; + typedef std::function CanDoCompleteArgumentsCallback; + typedef std::function(const std::string&)> CompleteArgumentsCallback; private: + struct ArgumentAssistRequestState + { + std::atomic latestRequest {0}; + std::mutex callbackMutex; + }; + static constexpr int ArgumentAssistDebounceInterval = 100; + ScriptingConsole* m_console; int m_charHeight; bool m_continuation; @@ -97,15 +136,33 @@ class BINARYNINJAUIAPI ScriptingConsoleEdit : public QTextEdit CompletionCallback m_completionCallback; ScriptingCompletionPopup* m_popup; + CanDoCompleteArgumentsCallback m_canDoArgumentCompletionCallback; + CompleteArgumentsCallback m_completeArgumentsCallback; + + ScriptingArgumentAssistPopup* m_argumentAssistPopup; + QTimer* m_argumentAssistUpdateTimer; + std::shared_ptr m_argumentAssistState; + bool m_argumentAssistRequestRunning; + bool m_argumentAssistRequestPending; + uint64_t m_argumentAssistPopupPosition; + uint64_t m_completionRegionStart; uint64_t m_completionRegionInitialStop; uint64_t m_completionRegionStop; + bool canShowArgumentAssistPopup() const; + void hideArgumentAssistPopup(); + void scheduleArgumentAssistPopupUpdate(); + void updateArgumentAssistPopup(); + void applyArgumentAssistPopup(const QString& text, uint64_t popupPosition); + public: ScriptingConsoleEdit(ScriptingConsole* parent); void setCharHeight(int height); void setContinuation(bool cont); void setCompletionCallback(CompletionCallback callback) { m_completionCallback = callback; } + void setCanDoCompleteArgumentsCallback(CanDoCompleteArgumentsCallback callback) { m_canDoArgumentCompletionCallback = callback; } + void setCompleteArgumentsCallback(CompleteArgumentsCallback callback) { m_completeArgumentsCallback = callback; } void insertFromMimeData(const QMimeData* source) override; @@ -114,6 +171,11 @@ class BINARYNINJAUIAPI ScriptingConsoleEdit : public QTextEdit protected: virtual void keyPressEvent(QKeyEvent* event) override; + virtual void resizeEvent(QResizeEvent* event) override; + virtual void scrollContentsBy(int dx, int dy) override; + virtual void focusOutEvent(QFocusEvent* event) override; + virtual void hideEvent(QHideEvent* event) override; + virtual void changeEvent(QEvent* event) override; }; /*! diff --git a/ui/uitypes.h b/ui/uitypes.h index f12a48e6..b3131c18 100644 --- a/ui/uitypes.h +++ b/ui/uitypes.h @@ -6,14 +6,14 @@ // there are changes to the API that affect linking, including new functions, // new types, modifications to existing functions or types, or new versions // of the Qt libraries. -#define BN_CURRENT_UI_ABI_VERSION 16 +#define BN_CURRENT_UI_ABI_VERSION 17 // Minimum ABI version that is supported for loading of plugins. Plugins that // are linked to an ABI version less than this will not be able to load and // will require rebuilding. The minimum version is increased when there are // incompatible changes that break binary compatibility, such as changes to // existing types or functions, or a new version of Qt. -#define BN_MINIMUM_UI_ABI_VERSION 16 +#define BN_MINIMUM_UI_ABI_VERSION 17 #ifdef __GNUC__ #ifdef BINARYNINJAUI_LIBRARY -- cgit v1.3.1