| 1 |
////////////////////////////////////////////////////////////////////////////// |
| 2 |
////////////////////////////////////////////////////////////////////////////// |
| 3 |
// |
| 4 |
// copyright : (C) 2014 Eran Ifrah |
| 5 |
// file name : event_notifier.cpp |
| 6 |
// |
| 7 |
// ------------------------------------------------------------------------- |
| 8 |
// A |
| 9 |
// _____ _ _ _ _ |
| 10 |
// / __ \ | | | | (_) | |
| 11 |
// | / \/ ___ __| | ___| | _| |_ ___ |
| 12 |
// | | / _ \ / _ |/ _ \ | | | __/ _ ) |
| 13 |
// | \__/\ (_) | (_| | __/ |___| | || __/ |
| 14 |
// \____/\___/ \__,_|\___\_____/_|\__\___| |
| 15 |
// |
| 16 |
// F i l e |
| 17 |
// |
| 18 |
// This program is free software; you can redistribute it and/or modify |
| 19 |
// it under the terms of the GNU General Public License as published by |
| 20 |
// the Free Software Foundation; either version 2 of the License, or |
| 21 |
// (at your option) any later version. |
| 22 |
// |
| 23 |
////////////////////////////////////////////////////////////////////////////// |
| 24 |
////////////////////////////////////////////////////////////////////////////// |
| 25 |
|
| 26 |
#include "event_notifier.h" |
| 27 |
|
| 28 |
#include "codelite_events.h" |
| 29 |
|
| 30 |
#include <wx/app.h> |
| 31 |
|
| 32 |
static EventNotifier* eventNotifier = NULL; |
| 33 |
|
| 34 |
EventNotifier* EventNotifier::Get() |
| 35 |
{ |
| 36 |
if(eventNotifier == NULL) |
| 37 |
eventNotifier = new EventNotifier(); |
| 38 |
return eventNotifier; |
| 39 |
} |
| 40 |
|
| 41 |
void EventNotifier::Release() |
| 42 |
{ |
| 43 |
if(eventNotifier) |
| 44 |
delete eventNotifier; |
| 45 |
eventNotifier = NULL; |
| 46 |
} |
| 47 |
|
| 48 |
EventNotifier::EventNotifier() |
| 49 |
: _eventsDiabled(false) |
| 50 |
{ |
| 51 |
} |
| 52 |
|
| 53 |
EventNotifier::~EventNotifier() {} |
| 54 |
|
| 55 |
bool EventNotifier::SendCommandEvent(int eventId, void* clientData) |
| 56 |
{ |
| 57 |
if(_eventsDiabled) |
| 58 |
return false; |
| 59 |
|
| 60 |
wxCommandEvent evt(eventId); |
| 61 |
evt.SetClientData(clientData); |
| 62 |
return ProcessEvent(evt); |
| 63 |
} |
| 64 |
|
| 65 |
bool EventNotifier::SendCommandEvent(int eventId, void* clientData, const wxString& s) |
| 66 |
{ |
| 67 |
if(_eventsDiabled) |
| 68 |
return false; |
| 69 |
|
| 70 |
wxCommandEvent evt(eventId); |
| 71 |
evt.SetClientData(clientData); |
| 72 |
evt.SetString(s); |
| 73 |
return ProcessEvent(evt); |
| 74 |
} |
| 75 |
|
| 76 |
void EventNotifier::PostCommandEvent(int eventId, void* clientData) |
| 77 |
{ |
| 78 |
if(_eventsDiabled) |
| 79 |
return; |
| 80 |
|
| 81 |
wxCommandEvent evt(eventId); |
| 82 |
evt.SetClientData(clientData); |
| 83 |
AddPendingEvent(evt); |
| 84 |
} |
| 85 |
|
| 86 |
#if wxUSE_GUI |
| 87 |
wxFrame* EventNotifier::TopFrame() { return static_cast<wxFrame*>(wxTheApp->GetTopWindow()); } |
| 88 |
#endif |
| 89 |
|
| 90 |
void EventNotifier::PostFileSavedEvent(const wxString& filename) |
| 91 |
{ |
| 92 |
if(_eventsDiabled) |
| 93 |
return; |
| 94 |
|
| 95 |
clCommandEvent event{ wxEVT_FILE_SAVED }; |
| 96 |
event.SetString(filename); |
| 97 |
event.SetFileName(filename); |
| 98 |
AddPendingEvent(event); |
| 99 |
} |
| 100 |
|
| 101 |
void EventNotifier::PostReloadExternallyModifiedEvent(bool prompt) |
| 102 |
{ |
| 103 |
if(_eventsDiabled) |
| 104 |
return; |
| 105 |
wxCommandEvent event(prompt ? wxEVT_CMD_RELOAD_EXTERNALLY_MODIFIED : wxEVT_CMD_RELOAD_EXTERNALLY_MODIFIED_NOPROMPT); |
| 106 |
AddPendingEvent(event); |
| 107 |
} |
| 108 |
|
| 109 |
void EventNotifier::PostFileRemovedEvent(const wxArrayString& files) |
| 110 |
{ |
| 111 |
if(_eventsDiabled) |
| 112 |
return; |
| 113 |
clCommandEvent filesRemovedEvent(wxEVT_PROJ_FILE_REMOVED); |
| 114 |
filesRemovedEvent.SetStrings(files); |
| 115 |
AddPendingEvent(filesRemovedEvent); |
| 116 |
} |
| 117 |
|
| 118 |
void EventNotifier::NotifyWorkspaceReloadEndEvent(const wxString& workspaceFile) |
| 119 |
{ |
| 120 |
if(_eventsDiabled) |
| 121 |
return; |
| 122 |
clWorkspaceEvent event(wxEVT_WORKSPACE_RELOAD_ENDED); |
| 123 |
event.SetFileName(workspaceFile); |
| 124 |
ProcessEvent(event); |
| 125 |
} |
| 126 |
|
| 127 |
void EventNotifier::NotifyWorkspaceReloadStartEvet(const wxString& workspaceFile) |
| 128 |
{ |
| 129 |
if(_eventsDiabled) |
| 130 |
return; |
| 131 |
clWorkspaceEvent event(wxEVT_WORKSPACE_RELOAD_STARTED); |
| 132 |
event.SetFileName(workspaceFile); |
| 133 |
ProcessEvent(event); |
| 134 |
} |
| 135 |
|
| 136 |
void EventNotifier::AddPendingEvent(const wxEvent& event) |
| 137 |
{ |
| 138 |
if(_eventsDiabled) { |
| 139 |
return; |
| 140 |
} |
| 141 |
wxEvtHandler::AddPendingEvent(event); |
| 142 |
} |
| 143 |
|
| 144 |
bool EventNotifier::ProcessEvent(wxEvent& event) |
| 145 |
{ |
| 146 |
if(_eventsDiabled) { |
| 147 |
return false; |
| 148 |
} |
| 149 |
return wxEvtHandler::ProcessEvent(event); |
| 150 |
} |