Skip to content

Commit d78a046

Browse files
committed
Add Event Filtering Hooks To The App
Update the application and event-notifier plumbing to support event-type filter registration and filtering at the wxApp level. This introduces a callback-based filter registry in EventNotifier, exposes a new FilterEvent override on CodeLiteApp, and wires the app through to the notifier so future event interception can be centralized. The app class declaration was also reorganized to place members and method declarations under clearer access sections, and the bundled wxTerminalEmulator submodule was advanced to a newer commit. * Core event handling * App lifecycle and class layout * Submodule update **Generated by CodeLite** Signed-off-by: Eran Ifrah <eran@codelite.org>
1 parent a974861 commit d78a046

File tree

5 files changed

+99
-37
lines changed

5 files changed

+99
-37
lines changed

CodeLite/event_notifier.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,42 @@ void EventNotifier::NotifyWorkspaceReloadStartEvet(const wxString& workspaceFile
102102
void EventNotifier::AddPendingEvent(const wxEvent& event) { wxEvtHandler::AddPendingEvent(event); }
103103

104104
bool EventNotifier::ProcessEvent(wxEvent& event) { return wxEvtHandler::ProcessEvent(event); }
105+
106+
EventFilterCallbackToken EventNotifier::AddEventTypeFilter(wxEventType type, EventFilterCallback callback)
107+
{
108+
static EventFilterCallbackToken event_filter_id{0};
109+
auto& callbacks = m_eventFilterCallbacks[type];
110+
// Place it first
111+
++event_filter_id;
112+
EventFilterCallbackContainer container{.id = event_filter_id, .callback = std::move(callback)};
113+
callbacks.insert(callbacks.begin(), std::move(container));
114+
return event_filter_id;
115+
}
116+
117+
void EventNotifier::RemoveEventTypeFilter(wxEventType type, EventFilterCallbackToken token)
118+
{
119+
auto iter = m_eventFilterCallbacks.find(type);
120+
if (iter == m_eventFilterCallbacks.end()) {
121+
return;
122+
}
123+
124+
auto& v = iter->second;
125+
size_t count = std::erase_if(v, [token](const EventFilterCallbackContainer& c) { return c.id == token; });
126+
if (count && v.empty()) {
127+
m_eventFilterCallbacks.erase(iter);
128+
}
129+
}
130+
131+
int EventNotifier::FilterEvent(wxEvent& event)
132+
{
133+
if (m_eventFilterCallbacks.empty()) {
134+
return wxEventFilter::Event_Skip;
135+
}
136+
137+
auto iter = m_eventFilterCallbacks.find(event.GetEventType());
138+
if (iter == m_eventFilterCallbacks.end()) {
139+
return wxEventFilter::Event_Skip;
140+
}
141+
142+
return wxEventFilter::Event_Skip;
143+
}

CodeLite/event_notifier.h

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@
2626
#ifndef EVENTNOTIFIER_H
2727
#define EVENTNOTIFIER_H
2828

29+
#include <functional>
2930
#include <future>
31+
#include <unordered_map>
3032
#include <wx/event.h>
33+
#include <wx/eventfilter.h>
3134
#include <wx/thread.h>
3235

3336
#if wxUSE_GUI
@@ -36,12 +39,16 @@
3639

3740
#include "codelite_exports.h"
3841

42+
using EventFilterCallback = std::function<bool(wxEvent&)>;
43+
using EventFilterCallbackToken = size_t;
44+
45+
struct WXDLLIMPEXP_CL EventFilterCallbackContainer {
46+
EventFilterCallbackToken id{0};
47+
EventFilterCallback callback;
48+
};
49+
3950
class WXDLLIMPEXP_CL EventNotifier : public wxEvtHandler
4051
{
41-
private:
42-
EventNotifier() = default;
43-
virtual ~EventNotifier() = default;
44-
4552
public:
4653
static EventNotifier* Get();
4754
static void Release();
@@ -115,6 +122,17 @@ class WXDLLIMPEXP_CL EventNotifier : public wxEvtHandler
115122
}
116123
return f.get();
117124
}
125+
126+
EventFilterCallbackToken AddEventTypeFilter(wxEventType type, EventFilterCallback callback);
127+
void RemoveEventTypeFilter(wxEventType type, EventFilterCallbackToken token);
128+
129+
int FilterEvent(wxEvent& event);
130+
131+
private:
132+
EventNotifier() = default;
133+
virtual ~EventNotifier() = default;
134+
135+
std::unordered_map<wxEventType, std::vector<EventFilterCallbackContainer>> m_eventFilterCallbacks;
118136
};
119137

120138
#endif // EVENTNOTIFIER_H

LiteEditor/app.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include "app.h"
2727

28+
#include <algorithm>
2829
#ifdef __WXGTK__
2930
#include "exelocator.h"
3031
#endif
@@ -1183,3 +1184,7 @@ void CodeLiteApp::FinalizeShutdown()
11831184
wxFileName::Rmdir(clStandardPaths::Get().GetTempDir(), wxPATH_RMDIR_RECURSIVE);
11841185
clDEBUG() << "Finalizing shutdown...success" << endl;
11851186
}
1187+
1188+
int CodeLiteApp::FilterEvent(wxEvent& event) {
1189+
return EventNotifier::Get()->FilterEvent(event);
1190+
}

LiteEditor/app.h

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "clPersistenceManager.h"
2828
#include "frame.h"
2929

30+
#include <functional>
3031
#include <memory>
3132
#include <wx/cmdline.h>
3233
#include <wx/snglinst.h>
@@ -36,35 +37,6 @@ class CodeLiteApp : public wxApp
3637
public:
3738
enum PluginPolicy { PP_None = 0, PP_All, PP_FromList };
3839

39-
protected:
40-
clMainFrame* m_pMainFrame;
41-
wxSingleInstanceChecker* m_singleInstance;
42-
wxArrayString m_parserPaths;
43-
wxLocale m_locale;
44-
wxArrayString m_allowedPlugins;
45-
PluginPolicy m_pluginLoadPolicy;
46-
std::unique_ptr<clPersistenceManager> m_persistenceManager;
47-
bool m_startedInDebuggerMode;
48-
49-
// When starting in debugger mode
50-
wxString m_exeToDebug;
51-
wxString m_debuggerArgs;
52-
wxString m_debuggerWorkingDirectory;
53-
static bool m_restartCodeLite;
54-
static wxString m_restartCommand;
55-
static wxString m_restartWD;
56-
wxCmdLineParser m_parser;
57-
58-
private: // Methods
59-
bool CopySettings(const wxString& destDir, wxString& installPath);
60-
bool IsSingleInstance(const wxCmdLineParser& parser);
61-
void DoCopyGdbPrinters();
62-
void MSWReadRegistry();
63-
wxString DoFindMenuFile(const wxString& installDirectory);
64-
void AdjustPathForCygwinIfNeeded();
65-
void AdjustPathForMSYSIfNeeded();
66-
void PrintUsage(const wxCmdLineParser& parser);
67-
6840
public:
6941
CodeLiteApp();
7042
virtual ~CodeLiteApp();
@@ -104,11 +76,39 @@ class CodeLiteApp : public wxApp
10476

10577
void ProcessCommandLineParams();
10678

79+
private: // Methods
80+
bool CopySettings(const wxString& destDir, wxString& installPath);
81+
bool IsSingleInstance(const wxCmdLineParser& parser);
82+
void DoCopyGdbPrinters();
83+
void MSWReadRegistry();
84+
wxString DoFindMenuFile(const wxString& installDirectory);
85+
void AdjustPathForCygwinIfNeeded();
86+
void AdjustPathForMSYSIfNeeded();
87+
void PrintUsage(const wxCmdLineParser& parser);
88+
int FilterEvent(wxEvent& event) override;
89+
10790
protected:
108-
virtual bool OnInit();
109-
virtual int OnExit();
110-
virtual void OnFatalException();
91+
bool OnInit() override;
92+
int OnExit() override;
93+
void OnFatalException() override;
11194
void OpenFolder(const wxString& path);
11295
void OpenFile(const wxString& path, long lineNumber);
11396
void OpenItem(const wxString& path, long lineNumber);
97+
clMainFrame* m_pMainFrame;
98+
wxSingleInstanceChecker* m_singleInstance;
99+
wxArrayString m_parserPaths;
100+
wxLocale m_locale;
101+
wxArrayString m_allowedPlugins;
102+
PluginPolicy m_pluginLoadPolicy;
103+
std::unique_ptr<clPersistenceManager> m_persistenceManager;
104+
bool m_startedInDebuggerMode;
105+
106+
// When starting in debugger mode
107+
wxString m_exeToDebug;
108+
wxString m_debuggerArgs;
109+
wxString m_debuggerWorkingDirectory;
110+
static bool m_restartCodeLite;
111+
static wxString m_restartCommand;
112+
static wxString m_restartWD;
113+
wxCmdLineParser m_parser;
114114
};

0 commit comments

Comments
 (0)