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
|
#include "ClangOutputTab.h"
#include "event_notifier.h"
#include "ColoursAndFontsManager.h"
#include "lexer_configuration.h"
#include <codelite_events.h>
#include "tags_options_data.h"
#include "frame.h"
#include "clang_code_completion.h"
#include "ctags_manager.h"
#include "cl_config.h"
#include "globals.h"
ClangOutputTab::ClangOutputTab(wxWindow* parent)
: ClangOutputTabBase(parent)
{
EventNotifier::Get()->Connect(wxEVT_INIT_DONE, wxCommandEventHandler(ClangOutputTab::OnInitDone), NULL, this);
EventNotifier::Get()->Connect(wxEVT_BUILD_STARTED, clBuildEventHandler(ClangOutputTab::OnBuildStarted), NULL, this);
EventNotifier::Get()->Connect(
wxEVT_CLANG_CODE_COMPLETE_MESSAGE, clCommandEventHandler(ClangOutputTab::OnClangOutput), NULL, this);
LexerConf::Ptr_t lexer = ColoursAndFontsManager::Get().GetLexer("text");
if(lexer) {
lexer->Apply(m_stc);
}
EventNotifier::Get()->Bind(wxEVT_FILE_SAVED, &ClangOutputTab::OnFileSaved, this);
::clRecalculateSTCHScrollBar(m_stc);
// Get the initial value of the clang code completion
TagsOptionsData tod;
clConfig ccConfig("code-completion.conf");
ccConfig.ReadItem(&tod);
m_checkBoxEnableClang->SetValue(tod.GetClangOptions() & CC_CLANG_ENABLED);
}
ClangOutputTab::~ClangOutputTab()
{
EventNotifier::Get()->Connect(wxEVT_INIT_DONE, wxCommandEventHandler(ClangOutputTab::OnInitDone), NULL, this);
EventNotifier::Get()->Disconnect(
wxEVT_BUILD_STARTED, clBuildEventHandler(ClangOutputTab::OnBuildStarted), NULL, this);
EventNotifier::Get()->Disconnect(
wxEVT_CLANG_CODE_COMPLETE_MESSAGE, clCommandEventHandler(ClangOutputTab::OnClangOutput), NULL, this);
EventNotifier::Get()->Unbind(wxEVT_FILE_SAVED, &ClangOutputTab::OnFileSaved, this);
}
void ClangOutputTab::OnBuildStarted(clBuildEvent& event)
{
event.Skip(); // Must call this
DoClear();
}
void ClangOutputTab::OnClangOutput(clCommandEvent& event)
{
event.Skip();
DoClear();
DoAppendText(event.GetString());
const TagsOptionsData& options = clMainFrame::Get()->GetTagsOptions();
if(options.GetClangOptions() & CC_CLANG_INLINE_ERRORS) {
IEditor* editor = ::clGetManager()->GetActiveEditor();
// event.GetInt() == 1 means that this is a real error message and not just a status message
// these kind of messages are also shown in the editor
if(event.GetInt() && editor) {
editor->SetCodeCompletionAnnotation(event.GetString(), editor->GetCurrentLine());
}
}
}
void ClangOutputTab::DoAppendText(const wxString& text)
{
m_stc->SetReadOnly(false);
if(!m_stc->IsEmpty() && m_stc->GetCharAt(m_stc->GetLastPosition() - 1) != '\n') {
m_stc->AppendText("\n");
}
m_stc->AppendText(text);
int pos = m_stc->GetLastPosition();
m_stc->SetCurrentPos(pos);
m_stc->SetSelectionStart(pos);
m_stc->SetSelectionEnd(pos);
m_stc->ScrollToEnd();
m_stc->SetReadOnly(true);
::clRecalculateSTCHScrollBar(m_stc);
}
void ClangOutputTab::DoClear()
{
m_stc->SetReadOnly(false);
m_stc->ClearAll();
m_stc->SetReadOnly(true);
// Clear editor annotations
IEditor* editor = ::clGetManager()->GetActiveEditor();
if(editor) {
editor->GetCtrl()->AnnotationClearAll();
}
}
void ClangOutputTab::OnInitDone(wxCommandEvent& event)
{
event.Skip();
TagsOptionsData& options = clMainFrame::Get()->GetTagsOptions();
m_checkBoxEnableClang->SetValue(options.GetClangOptions() & CC_CLANG_ENABLED);
}
void ClangOutputTab::OnClearCache(wxCommandEvent& event)
{
wxUnusedVar(event);
#if HAS_LIBCLANG
ClangCodeCompletion::Instance()->ClearCache();
#endif
}
void ClangOutputTab::OnClearCacheUI(wxUpdateUIEvent& event)
{
#if HAS_LIBCLANG
event.Enable(!ClangCodeCompletion::Instance()->IsCacheEmpty() && m_checkBoxEnableClang->IsChecked());
#else
event.Enable(false);
#endif
}
void ClangOutputTab::OnClearText(wxCommandEvent& event)
{
wxUnusedVar(event);
DoClear();
}
void ClangOutputTab::OnClearTextUI(wxUpdateUIEvent& event) { event.Enable(!m_stc->IsEmpty()); }
void ClangOutputTab::OnEnableClang(wxCommandEvent& event)
{
TagsOptionsData& options = clMainFrame::Get()->GetTagsOptions();
size_t clangOptions = options.GetClangOptions();
if(event.IsChecked()) {
clangOptions |= CC_CLANG_ENABLED;
} else {
clangOptions &= ~CC_CLANG_ENABLED;
}
// Apply the changes
options.SetClangOptions(clangOptions);
TagsManagerST::Get()->SetCtagsOptions(options);
}
void ClangOutputTab::OnEnableClangUI(wxUpdateUIEvent& event)
{
const TagsOptionsData& options = clMainFrame::Get()->GetTagsOptions();
event.Check(options.GetClangOptions() & CC_CLANG_ENABLED);
}
void ClangOutputTab::OnShowAnnotations(wxCommandEvent& event)
{
TagsOptionsData& options = clMainFrame::Get()->GetTagsOptions();
size_t clangOptions = options.GetClangOptions();
if(event.IsChecked()) {
clangOptions |= CC_CLANG_INLINE_ERRORS;
} else {
clangOptions &= ~CC_CLANG_INLINE_ERRORS;
}
// Apply the changes
options.SetClangOptions(clangOptions);
TagsManagerST::Get()->SetCtagsOptions(options);
// Clear any annotations we have
IEditor* editor = ::clGetManager()->GetActiveEditor();
if(editor) {
editor->GetCtrl()->AnnotationClearAll();
}
}
void ClangOutputTab::OnShowAnnotationsUI(wxUpdateUIEvent& event)
{
const TagsOptionsData& options = clMainFrame::Get()->GetTagsOptions();
event.Enable(options.GetClangOptions() & CC_CLANG_ENABLED);
}
void ClangOutputTab::OnFileSaved(clCommandEvent& event)
{
event.Skip();
// Clear editor annotations
IEditor* editor = ::clGetManager()->GetActiveEditor();
if(editor) {
editor->GetCtrl()->AnnotationClearAll();
}
}
|