From 0de53b97ef6cec57ab4bdfbb9a9e1b6503eecfab Mon Sep 17 00:00:00 2001 From: Glenn Smith Date: Fri, 2 Oct 2020 20:52:15 -0400 Subject: UIContext notifications (eg file open/save) --- ui/uicontext.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'ui') diff --git a/ui/uicontext.h b/ui/uicontext.h index e2a6e0a5..bc88a71b 100644 --- a/ui/uicontext.h +++ b/ui/uicontext.h @@ -17,6 +17,24 @@ class ViewFrame; class UIActionHandler; class FileContext; +class BINARYNINJAUIAPI UIContextNotification +{ +public: + virtual void OnContextOpen(UIContext* context) { (void)context; } + virtual void OnContextClose(UIContext* context) { (void)context; } + + virtual bool OnBeforeOpenDatabase(UIContext* context, FileMetadataRef metadata) { (void)context; (void)metadata; return true; } + virtual bool OnAfterOpenDatabase(UIContext* context, FileMetadataRef metadata, BinaryViewRef data) { (void)context; (void)metadata; (void)data; return true; } + virtual bool OnBeforeOpenFile(UIContext* context, FileContext* file) { (void)context; (void)file; return true; } + virtual void OnAfterOpenFile(UIContext* context, FileContext* file, ViewFrame* frame) { (void)context; (void)file; (void)frame; } + virtual bool OnBeforeSaveFile(UIContext* context, FileContext* file, ViewFrame* frame) { (void)context; (void)file; (void)frame; return true; } + virtual void OnAfterSaveFile(UIContext* context, FileContext* file, ViewFrame* frame) { (void)context; (void)file; (void)frame; } + virtual bool OnBeforeCloseFile(UIContext* context, FileContext* file, ViewFrame* frame) { (void)context; (void)file; (void)frame; return true; } + virtual void OnAfterCloseFile(UIContext* context, FileContext* file, ViewFrame* frame) { (void)context; (void)file; (void)frame; } + + virtual void OnViewChange(UIContext* context, ViewFrame* frame, const QString& type) { (void)context; (void)frame; (void)type; } +}; + class BINARYNINJAUIAPI UIContextHandler { public: @@ -31,6 +49,7 @@ class BINARYNINJAUIAPI UIContext static UIContextHandler* m_handler; static std::set m_contexts; UIActionHandler m_globalActions; + static std::vector m_notifications; static QPointer m_currentPreview; @@ -51,6 +70,23 @@ public: UIActionHandler* globalActions() { return &m_globalActions; } virtual UIActionHandler* contentActionHandler() = 0; + static void registerNotification(UIContextNotification* notification); + static void unregisterNotification(UIContextNotification* notification); + + void NotifyOnContextOpen(); + void NotifyOnContextClose(); + + bool NotifyOnBeforeOpenDatabase(FileMetadataRef metadata); + bool NotifyOnAfterOpenDatabase(FileMetadataRef metadata, BinaryViewRef data); + bool NotifyOnBeforeOpenFile(FileContext* file); + void NotifyOnAfterOpenFile(FileContext* file, ViewFrame* frame); + bool NotifyOnBeforeSaveFile(FileContext* file, ViewFrame* frame); + void NotifyOnAfterSaveFile(FileContext* file, ViewFrame* frame); + bool NotifyOnBeforeCloseFile(FileContext* file, ViewFrame* frame); + void NotifyOnAfterCloseFile(FileContext* file, ViewFrame* frame); + + void NotifyOnViewChange(ViewFrame* frame, const QString& type); + static void setHandler(UIContextHandler* handler); static QSize getScaledWindowSize(int x, int y); -- cgit v1.3.1