summaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authorGlenn Smith <glenn@vector35.com>2020-10-02 20:52:15 -0400
committerGlenn Smith <glenn@vector35.com>2020-10-14 21:06:52 -0400
commit0de53b97ef6cec57ab4bdfbb9a9e1b6503eecfab (patch)
tree553a07d8233b614b771569e12a75115d69963adc /ui
parent02098f30b88f25953532cb4ae20c6c1161b74603 (diff)
UIContext notifications (eg file open/save)
Diffstat (limited to 'ui')
-rw-r--r--ui/uicontext.h36
1 files changed, 36 insertions, 0 deletions
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<UIContext*> m_contexts;
UIActionHandler m_globalActions;
+ static std::vector<UIContextNotification*> m_notifications;
static QPointer<PreviewWidget> 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);