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