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 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
|
#include "NodeJSDebuggerBreakpointManager.h"
#include "globals.h"
#include "imanager.h"
#include "ieditor.h"
#include "bookmark_manager.h"
#include "codelite_events.h"
#include "event_notifier.h"
#include "NodeJSWorkspaceUserConfiguration.h"
#include "NoteJSWorkspace.h"
#include "bookmark_manager.h"
#include "macros.h"
#include <wx/stc/stc.h>
#include "ieditor.h"
#include <algorithm>
NodeJSBptManager::NodeJSBptManager()
{
EventNotifier::Get()->Bind(wxEVT_WORKSPACE_LOADED, &NodeJSBptManager::OnWorkspaceOpened, this);
EventNotifier::Get()->Bind(wxEVT_WORKSPACE_CLOSED, &NodeJSBptManager::OnWorkspaceClosed, this);
EventNotifier::Get()->Bind(wxEVT_ACTIVE_EDITOR_CHANGED, &NodeJSBptManager::OnEditorChanged, this);
}
NodeJSBptManager::~NodeJSBptManager()
{
EventNotifier::Get()->Unbind(wxEVT_WORKSPACE_LOADED, &NodeJSBptManager::OnWorkspaceOpened, this);
EventNotifier::Get()->Unbind(wxEVT_WORKSPACE_CLOSED, &NodeJSBptManager::OnWorkspaceClosed, this);
EventNotifier::Get()->Unbind(wxEVT_ACTIVE_EDITOR_CHANGED, &NodeJSBptManager::OnEditorChanged, this);
}
void NodeJSBptManager::OnEditorChanged(wxCommandEvent& e)
{
e.Skip();
// Apply breakpoints for this editor
if(clGetManager()) {
IEditor* editor = clGetManager()->GetActiveEditor();
if(editor) {
NodeJSBreakpoint::List_t bps;
if(GetBreakpointsForFile(editor->GetFileName().GetFullPath(), bps)) {
NodeJSBreakpoint::List_t::iterator iter = bps.begin();
for(; iter != bps.end(); ++iter) {
int markerMask = editor->GetCtrl()->MarkerGet(iter->GetLine() - 1);
if(!(markerMask & mmt_breakpoint)) {
// No marker on this line yet
// add one
editor->GetCtrl()->MarkerAdd(iter->GetLine() - 1, smt_breakpoint);
}
}
}
}
}
}
size_t NodeJSBptManager::GetBreakpointsForFile(const wxString& filename, NodeJSBreakpoint::List_t& bps) const
{
bps.clear();
NodeJSBreakpoint::List_t::const_iterator iter = m_breakpoints.begin();
for(; iter != m_breakpoints.end(); ++iter) {
if(iter->GetFilename() == filename) {
bps.push_back(*iter);
}
}
return bps.size();
}
void NodeJSBptManager::OnWorkspaceClosed(wxCommandEvent& event)
{
event.Skip();
// Save the breakpoints to the file system
if(m_workspaceFile.IsOk() && m_workspaceFile.Exists()) {
NodeJSWorkspaceUser userWorkspace(m_workspaceFile.GetFullPath());
userWorkspace.Load().SetBreakpoints(m_breakpoints).Save();
m_workspaceFile.Clear();
}
}
void NodeJSBptManager::OnWorkspaceOpened(wxCommandEvent& event)
{
event.Skip();
m_workspaceFile.Clear();
wxFileName fileName = event.GetString();
if(FileExtManager::GetType(fileName.GetFullPath()) == FileExtManager::TypeWorkspaceNodeJS) {
m_workspaceFile = fileName;
NodeJSWorkspaceUser userConf(m_workspaceFile.GetFullPath());
m_breakpoints = userConf.Load().GetBreakpoints();
}
}
void NodeJSBptManager::SetBreakpoints(IEditor* editor)
{
CHECK_PTR_RET(editor);
editor->GetCtrl()->MarkerDeleteAll(smt_breakpoint);
NodeJSBreakpoint::List_t bps;
GetBreakpointsForFile(editor->GetFileName().GetFullPath(), bps);
NodeJSBreakpoint::List_t::const_iterator iter = bps.begin();
for(; iter != bps.end(); ++iter) {
editor->GetCtrl()->MarkerAdd(iter->GetLine() - 1, smt_breakpoint);
}
}
void NodeJSBptManager::AddBreakpoint(const wxFileName& filename, int line)
{
NodeJSBreakpoint::List_t::const_iterator iter =
std::find_if(m_breakpoints.begin(), m_breakpoints.end(), [&](const NodeJSBreakpoint& bp) {
if(bp.GetFilename() == filename.GetFullPath() && bp.GetLine() == line) return true;
return false;
});
if(iter == m_breakpoints.end()) {
// new breakpoint
NodeJSBreakpoint bp;
bp.SetFilename(filename.GetFullPath());
bp.SetLine(line);
m_breakpoints.push_back(bp);
}
}
void NodeJSBptManager::DeleteBreakpoint(const wxFileName& filename, int line)
{
NodeJSBreakpoint::List_t::iterator iter =
std::find_if(m_breakpoints.begin(), m_breakpoints.end(), [&](const NodeJSBreakpoint& bp) {
if(bp.GetFilename() == filename.GetFullPath() && bp.GetLine() == line) return true;
return false;
});
if(iter != m_breakpoints.end()) {
m_breakpoints.erase(iter);
}
}
bool NodeJSBptManager::HasBreakpoint(const wxFileName& filename, int line) const
{
NodeJSBreakpoint::List_t::const_iterator iter =
std::find_if(m_breakpoints.begin(), m_breakpoints.end(), [&](const NodeJSBreakpoint& bp) {
if(bp.GetFilename() == filename.GetFullPath() && bp.GetLine() == line) return true;
return false;
});
return iter != m_breakpoints.end();
}
const NodeJSBreakpoint& NodeJSBptManager::GetBreakpoint(const wxFileName& filename, int line) const
{
static NodeJSBreakpoint nullBreakpoint;
NodeJSBreakpoint::List_t::const_iterator iter =
std::find_if(m_breakpoints.begin(), m_breakpoints.end(), [&](const NodeJSBreakpoint& bp) {
if(bp.GetFilename() == filename.GetFullPath() && bp.GetLine() == line) return true;
return false;
});
if(m_breakpoints.end() == iter) {
return nullBreakpoint;
}
return *iter;
}
NodeJSBreakpoint& NodeJSBptManager::GetBreakpoint(const wxFileName& filename, int line)
{
static NodeJSBreakpoint nullBreakpoint;
NodeJSBreakpoint::List_t::iterator iter =
std::find_if(m_breakpoints.begin(), m_breakpoints.end(), [&](const NodeJSBreakpoint& bp) {
if(bp.GetFilename() == filename.GetFullPath() && bp.GetLine() == line) return true;
return false;
});
if(m_breakpoints.end() == iter) {
return nullBreakpoint;
}
return *iter;
}
void NodeJSBptManager::Save()
{
// Save the breakpoints to the file system
if(m_workspaceFile.Exists()) {
NodeJSWorkspaceUser userWorkspace(m_workspaceFile.GetFullPath());
userWorkspace.Load().SetBreakpoints(m_breakpoints).Save();
}
}
|