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 180 181 182 183 184 185
|
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright : (C) 2014 The CodeLite Team
// file name : debuggerasciiviewer.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 "debuggerasciiviewer.h"
#include "frame.h"
#include "debuggerpane.h"
#include "manager.h"
#include "debugger.h"
#include <event_notifier.h>
#include <plugin.h>
#include <lexer_configuration.h>
#include <editor_config.h>
static void sDefineMarker(wxStyledTextCtrl *s, int marker, int markerType, wxColor fore, wxColor back)
{
s->MarkerDefine(marker, markerType);
s->MarkerSetForeground(marker, fore);
s->MarkerSetBackground(marker, back);
}
DebuggerAsciiViewer::DebuggerAsciiViewer( wxWindow* parent )
: DebuggerAsciiViewerBase( parent )
{
EventNotifier::Get()->Connect(wxEVT_CL_THEME_CHANGED, wxCommandEventHandler(DebuggerAsciiViewer::OnThemeColourChanged), NULL, this);
LexerConf::Ptr_t cpp_lexer = EditorConfigST::Get()->GetLexer("C++");
if ( cpp_lexer ) {
cpp_lexer->Apply( m_textView );
m_textView->SetLexer(wxSTC_LEX_CPP);
} else {
// This code should not be called at all...
// but still - just in case
wxFont font(8, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
// hide all margins
m_textView->SetMarginWidth(0, 0);
m_textView->SetMarginWidth(1, 0);
m_textView->SetMarginWidth(2, 0);
m_textView->SetMarginWidth(3, 0);
m_textView->SetMarginWidth(4, 0);
m_textView->SetMarginSensitive(4, true);
m_textView->SetProperty(wxT("fold"), wxT("1"));
sDefineMarker(m_textView, wxSTC_MARKNUM_FOLDEROPEN, wxSTC_MARK_BOXMINUS, wxColor(0xff, 0xff, 0xff), wxColor(0x80, 0x80, 0x80));
sDefineMarker(m_textView, wxSTC_MARKNUM_FOLDER, wxSTC_MARK_BOXPLUS, wxColor(0xff, 0xff, 0xff), wxColor(0x80, 0x80, 0x80));
sDefineMarker(m_textView, wxSTC_MARKNUM_FOLDERSUB, wxSTC_MARK_VLINE, wxColor(0xff, 0xff, 0xff), wxColor(0x80, 0x80, 0x80));
sDefineMarker(m_textView, wxSTC_MARKNUM_FOLDERTAIL, wxSTC_MARK_LCORNER, wxColor(0xff, 0xff, 0xff), wxColor(0x80, 0x80, 0x80));
sDefineMarker(m_textView, wxSTC_MARKNUM_FOLDEREND, wxSTC_MARK_BOXPLUSCONNECTED, wxColor(0xff, 0xff, 0xff), wxColor(0x80, 0x80, 0x80));
sDefineMarker(m_textView, wxSTC_MARKNUM_FOLDEROPENMID, wxSTC_MARK_BOXMINUSCONNECTED, wxColor(0xff, 0xff, 0xff), wxColor(0x80, 0x80, 0x80));
sDefineMarker(m_textView, wxSTC_MARKNUM_FOLDERMIDTAIL, wxSTC_MARK_TCORNER, wxColor(0xff, 0xff, 0xff), wxColor(0x80, 0x80, 0x80));
// set wrapped line indicator
m_textView->SetWrapVisualFlags(1);
m_textView->SetWrapStartIndent(4);
m_textView->SetScrollWidthTracking(true);
m_textView->StyleSetForeground(wxSTC_STYLE_DEFAULT, wxT("GREY"));
// Set wrap mode on
m_textView->SetWrapMode(wxSTC_WRAP_WORD);
// Use NULL lexer
m_textView->SetLexer(wxSTC_LEX_CPP);
m_textView->SetMarginMask(4, wxSTC_MASK_FOLDERS);
// Set TELETYPE font (monospace)
m_textView->StyleSetFont(wxSTC_STYLE_DEFAULT, font);
m_textView->StyleSetSize(wxSTC_STYLE_DEFAULT, 12 );
}
m_textView->SetReadOnly(true);
wxTheApp->Connect(wxID_COPY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(DebuggerAsciiViewer::OnEdit), NULL, this);
wxTheApp->Connect(wxID_SELECTALL, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(DebuggerAsciiViewer::OnEdit), NULL, this);
wxTheApp->Connect(wxID_COPY, wxEVT_UPDATE_UI, wxUpdateUIEventHandler(DebuggerAsciiViewer::OnEditUI), NULL, this);
wxTheApp->Connect(wxID_SELECTALL, wxEVT_UPDATE_UI, wxUpdateUIEventHandler(DebuggerAsciiViewer::OnEditUI), NULL, this);
}
bool DebuggerAsciiViewer::IsFocused()
{
wxWindow *win = wxWindow::FindFocus();
return (win && win == m_textView);
}
void DebuggerAsciiViewer::UpdateView(const wxString &expr, const wxString &value)
{
m_textCtrlExpression->SetValue(expr);
wxString evaluated (value);
evaluated.Replace(wxT("\r\n"), wxT("\n"));
evaluated.Replace(wxT("\n,"), wxT(",\n"));
evaluated.Replace(wxT("\n\n"), wxT("\n"));
m_textView->SetReadOnly(false);
m_textView->ClearAll();
m_textView->SetText(evaluated);
m_textView->SetReadOnly(true);
}
void DebuggerAsciiViewer::OnClearView(wxCommandEvent& e)
{
wxUnusedVar(e);
UpdateView(wxT(""), wxT(""));
}
void DebuggerAsciiViewer::OnEditUI(wxUpdateUIEvent& e)
{
if ( !IsFocused() ) {
e.Skip();
return;
}
switch ( e.GetId() ) {
case wxID_SELECTALL:
e.Enable(true);
break;
case wxID_COPY:
e.Enable( m_textView->GetSelectedText().IsEmpty() == false );
break;
default:
e.Enable(false);
break;
}
}
void DebuggerAsciiViewer::OnEdit(wxCommandEvent& e)
{
if ( !IsFocused() ) {
e.Skip();
return;
}
switch ( e.GetId() ) {
case wxID_SELECTALL:
m_textView->SelectAll();
break;
case wxID_COPY:
m_textView->Copy();
break;
default:
break;
}
}
DebuggerAsciiViewer::~DebuggerAsciiViewer()
{
wxTheApp->Disconnect(wxID_COPY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(DebuggerAsciiViewer::OnEdit), NULL, this);
wxTheApp->Disconnect(wxID_SELECTALL, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(DebuggerAsciiViewer::OnEdit), NULL, this);
wxTheApp->Disconnect(wxID_COPY, wxEVT_UPDATE_UI, wxUpdateUIEventHandler(DebuggerAsciiViewer::OnEditUI), NULL, this);
wxTheApp->Disconnect(wxID_SELECTALL, wxEVT_UPDATE_UI, wxUpdateUIEventHandler(DebuggerAsciiViewer::OnEditUI), NULL, this);
EventNotifier::Get()->Disconnect(wxEVT_CL_THEME_CHANGED, wxCommandEventHandler(DebuggerAsciiViewer::OnThemeColourChanged), NULL, this);
}
void DebuggerAsciiViewer::OnThemeColourChanged(wxCommandEvent& e)
{
e.Skip();
// Re-apply C++ lexer
LexerConf::Ptr_t cpp_lexer = EditorConfigST::Get()->GetLexer("C++");
if ( cpp_lexer ) {
cpp_lexer->Apply( m_textView );
}
}
|