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 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156
|
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright : (C) 2014 Eran Ifrah
// file name : new_build_tab.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 "BuildTabTopPanel.h"
#include "ColoursAndFontsManager.h"
#include "Notebook.h"
#include "attribute_style.h"
#include "bitmap_loader.h"
#include "build_settings_config.h"
#include "buildtabsettingsdata.h"
#include "clSingleChoiceDialog.h"
#include "clStrings.h"
#include "cl_command_event.h"
#include "cl_editor.h"
#include "editor_config.h"
#include "environmentconfig.h"
#include "event_notifier.h"
#include "file_logger.h"
#include "frame.h"
#include "globals.h"
#include "lexer_configuration.h"
#include "macros.h"
#include "manager.h"
#include "new_build_tab.h"
#include "optionsconfig.h"
#include "output_pane.h"
#include "pluginmanager.h"
#include "shell_command.h"
#include "workspace.h"
#include <wx/choicdlg.h>
#include <wx/dataview.h>
#include <wx/dcmemory.h>
#include <wx/fdrepdlg.h>
#include <wx/regex.h>
#include <wx/settings.h>
#include "clFileSystemWorkspace.hpp"
#include "clFileSystemWorkspaceConfig.hpp"
#define IS_VALID_LINE(lineNumber) ((lineNumber >= 0 && lineNumber < m_view->GetLineCount()))
#ifdef __WXMSW__
#define IS_WINDOWS true
#else
#define IS_WINDOWS false
#endif
// Helper function to post an event to the frame
void SetActive(clEditor* editor)
{
wxCHECK_RET(editor, wxT("Null editor parameter"));
wxCommandEvent event(wxEVT_ACTIVATE_EDITOR);
event.SetEventObject(editor);
wxPostEvent(clMainFrame::Get(), event);
}
//////////////////////////////////////////////////////////////
struct AnnotationInfo {
int line;
LINE_SEVERITY severity;
std::set<wxString> text;
};
typedef std::map<int, AnnotationInfo> AnnotationInfoByLineMap_t;
#define LEX_GCC_DEFAULT 0
#define LEX_GCC_ERROR 1
#define LEX_GCC_WARNING 2
#define LEX_GCC_INFO 3
#define LEX_GCC_MARKER 1
NewBuildTab::NewBuildTab(wxWindow* parent)
: wxPanel(parent)
, m_warnCount(0)
, m_errorCount(0)
, m_buildInterrupted(false)
, m_autoHide(false)
, m_showMe(BuildTabSettingsData::ShowOnStart)
, m_skipWarnings(false)
, m_buildpaneScrollTo(ScrollToFirstError)
, m_buildInProgress(false)
, m_maxlineWidth(wxNOT_FOUND)
, m_lastLineColoured(wxNOT_FOUND)
{
SetSize(wxNOT_FOUND, 400);
m_curError = m_errorsAndWarningsList.end();
wxBoxSizer* bs = new wxBoxSizer(wxVERTICAL);
SetSizer(bs);
m_view = new wxStyledTextCtrl(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE);
// We dont really want to collect undo in the output tabs...
InitView();
Bind(wxEVT_IDLE, &NewBuildTab::OnIdle, this);
m_view->Bind(wxEVT_STC_HOTSPOT_CLICK, &NewBuildTab::OnHotspotClicked, this);
EventNotifier::Get()->Bind(wxEVT_CL_THEME_CHANGED, &NewBuildTab::OnThemeChanged, this);
bs->Add(m_view, 1, wxEXPAND | wxALL);
BuildTabTopPanel* toolbox = new BuildTabTopPanel(this);
bs->Insert(0, toolbox, 0, wxEXPAND);
EventNotifier::Get()->Connect(wxEVT_SHELL_COMMAND_STARTED, clCommandEventHandler(NewBuildTab::OnBuildStarted), NULL,
this);
EventNotifier::Get()->Connect(wxEVT_SHELL_COMMAND_STARTED_NOCLEAN,
clCommandEventHandler(NewBuildTab::OnBuildStarted), NULL, this);
EventNotifier::Get()->Connect(wxEVT_SHELL_COMMAND_ADDLINE, clCommandEventHandler(NewBuildTab::OnBuildAddLine), NULL,
this);
EventNotifier::Get()->Connect(wxEVT_SHELL_COMMAND_PROCESS_ENDED, clCommandEventHandler(NewBuildTab::OnBuildEnded),
NULL, this);
EventNotifier::Get()->Connect(wxEVT_WORKSPACE_LOADED, wxCommandEventHandler(NewBuildTab::OnWorkspaceLoaded), NULL,
this);
EventNotifier::Get()->Connect(wxEVT_WORKSPACE_CLOSED, wxCommandEventHandler(NewBuildTab::OnWorkspaceClosed), NULL,
this);
wxTheApp->Connect(XRCID("next_build_error"), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(NewBuildTab::OnNextBuildError), NULL, this);
wxTheApp->Connect(XRCID("next_build_error"), wxEVT_UPDATE_UI,
wxUpdateUIEventHandler(NewBuildTab::OnNextBuildErrorUI), NULL, this);
}
NewBuildTab::~NewBuildTab()
{
EventNotifier::Get()->Unbind(wxEVT_CL_THEME_CHANGED, &NewBuildTab::OnThemeChanged, this);
EventNotifier::Get()->Disconnect(wxEVT_SHELL_COMMAND_STARTED, clCommandEventHandler(NewBuildTab::OnBuildStarted),
NULL, this);
EventNotifier::Get()->Disconnect(wxEVT_SHELL_COMMAND_STARTED_NOCLEAN,
clCommandEventHandler(NewBuildTab::OnBuildStarted), NULL, this);
EventNotifier::Get()->Disconnect(wxEVT_SHELL_COMMAND_ADDLINE, clCommandEventHandler(NewBuildTab::OnBuildAddLine),
NULL, this);
EventNotifier::Get()->Disconnect(wxEVT_SHELL_COMMAND_PROCESS_ENDED,
clCommandEventHandler(NewBuildTab::OnBuildEnded), NULL, this);
wxTheApp->Disconnect(XRCID("next_build_error"), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(NewBuildTab::OnNextBuildError), NULL, this);
wxTheApp->Disconnect(XRCID("next_build_error"), wxEVT_UPDATE_UI,
wxUpdateUIEventHandler(NewBuildTab::OnNextBuildErrorUI), NULL, this);
}
void NewBuildTab::OnBuildEnded(clCommandEvent& e)
{
e.Skip();
CL_DEBUG("Build Ended!");
m_buildInProgress = false;
DoProcessOutput(true, false);
std::vector<clEditor*> editors;
clMainFrame::Get()->GetMainBook()->GetAllEditors(editors, MainBook::kGetAll_Default);
for(size_t i = 0; i < editors.size(); i++) {
MarkEditor(editors.at(i));
}
// Add a summary line
wxString problemcount =
wxString::Format(wxT("%d %s, %d %s"), m_errorCount, _("errors"), m_warnCount, _("warnings"));
wxString term = problemcount;
long elapsed = m_sw.Time() / 1000;
if(elapsed > 10) {
long sec = elapsed % 60;
long hours = elapsed / 3600;
long minutes = (elapsed % 3600) / 60;
term << wxString::Format(wxT(", %s: %02ld:%02ld:%02ld %s"), _("total time"), hours, minutes, sec, _("seconds"));
}
m_output = term;
DoProcessOutput(true, true);
if(m_buildInterrupted) {
wxString InterruptedMsg;
InterruptedMsg << _("(Build Cancelled)") << wxT("\n\n");
m_output = InterruptedMsg;
DoProcessOutput(true, false);
}
// Hide / Show the build tab according to the settings
DoToggleWindow();
// make it invalid
m_curError = m_errorsAndWarningsList.begin();
CL_DEBUG("Posting wxEVT_BUILD_ENDED event");
// 0 = first error
// 1 = first error or warning
// 2 = to the end
if(m_buildTabSettings.GetBuildPaneScrollDestination() == ScrollToFirstError && !m_errorsList.empty()) {
BuildLineInfo* bli = m_errorsList.front();
DoSelectAndOpen(bli->GetLineInBuildTab(), true);
}
if(m_buildTabSettings.GetBuildPaneScrollDestination() == ScrollToFirstItem && !m_errorsAndWarningsList.empty()) {
BuildLineInfo* bli = m_errorsAndWarningsList.front();
DoSelectAndOpen(bli->GetLineInBuildTab(), true);
}
if(m_buildTabSettings.GetBuildPaneScrollDestination() == ScrollToEnd) { m_view->ScrollToEnd(); }
// notify the plugins that the build has ended
clBuildEvent buildEvent(wxEVT_BUILD_ENDED);
buildEvent.SetErrorCount(m_errorCount);
buildEvent.SetWarningCount(m_warnCount);
EventNotifier::Get()->AddPendingEvent(buildEvent);
}
void NewBuildTab::OnBuildStarted(clCommandEvent& e)
{
e.Skip();
if(IS_WINDOWS) {
m_cygwinRoot.Clear();
EnvSetter es;
wxString cmd;
cmd << "cygpath -w /";
wxArrayString arrOut;
ProcUtils::SafeExecuteCommand(cmd, arrOut);
if(arrOut.IsEmpty() == false) { m_cygwinRoot = arrOut.Item(0); }
}
m_buildInProgress = true;
// Reload the build settings data
EditorConfigST::Get()->ReadObject(wxT("build_tab_settings"), &m_buildTabSettings);
InitView();
m_autoHide = m_buildTabSettings.GetAutoHide();
m_showMe = (BuildTabSettingsData::ShowBuildPane)m_buildTabSettings.GetShowBuildPane();
m_skipWarnings = m_buildTabSettings.GetSkipWarnings();
if(e.GetEventType() != wxEVT_SHELL_COMMAND_STARTED_NOCLEAN) {
DoClear();
DoCacheRegexes();
}
// Show the tab if needed
OutputPane* opane = clMainFrame::Get()->GetOutputPane();
wxWindow* win(NULL);
int sel = opane->GetNotebook()->GetSelection();
if(sel != wxNOT_FOUND) { win = opane->GetNotebook()->GetPage(sel); }
if(m_showMe == BuildTabSettingsData::ShowOnStart) {
ManagerST::Get()->ShowOutputPane(BUILD_WIN, true);
} else if(m_showMe == BuildTabSettingsData::ShowOnEnd && m_autoHide &&
ManagerST::Get()->IsPaneVisible(opane->GetCaption()) && win == this) {
// user prefers to see build/errors tabs only at end of unsuccessful build
ManagerST::Get()->HidePane(opane->GetName());
}
m_sw.Start();
m_cmp.Reset(NULL);
BuildEventDetails* bed = dynamic_cast<BuildEventDetails*>(e.GetClientObject());
if(bed) {
BuildConfigPtr buildConfig =
clCxxWorkspaceST::Get()->GetProjBuildConf(bed->GetProjectName(), bed->GetConfiguration());
if(buildConfig) { m_cmp = buildConfig->GetCompiler(); }
// notify the plugins that the build had started
clBuildEvent buildEvent(wxEVT_BUILD_STARTED);
buildEvent.SetProjectName(bed->GetProjectName());
buildEvent.SetConfigurationName(bed->GetConfiguration());
EventNotifier::Get()->AddPendingEvent(buildEvent);
} else if(clFileSystemWorkspace::Get().IsOpen() && clFileSystemWorkspace::Get().GetSettings().GetSelectedConfig()) {
const wxString& cmpname = clFileSystemWorkspace::Get().GetSettings().GetSelectedConfig()->GetCompiler();
m_cmp = BuildSettingsConfigST::Get()->GetCompiler(cmpname);
}
}
void NewBuildTab::OnBuildAddLine(clCommandEvent& e)
{
e.Skip(); // Always call skip..
m_output << e.GetString();
DoProcessOutput(false, false);
}
BuildLineInfo* NewBuildTab::DoProcessLine(const wxString& line)
{
BuildLineInfo* buildLineInfo = new BuildLineInfo();
LINE_SEVERITY severity;
// Get the matching regex for this line
CmpPatternPtr cmpPatterPtr = GetMatchingRegex(line, severity);
buildLineInfo->SetSeverity(severity);
BuildLineInfo bli;
if(cmpPatterPtr && cmpPatterPtr->Matches(line, bli)) {
buildLineInfo->SetFilename(bli.GetFilename());
buildLineInfo->SetSeverity(bli.GetSeverity());
buildLineInfo->SetLineNumber(bli.GetLineNumber());
buildLineInfo->NormalizeFilename(m_directories, m_cygwinRoot);
buildLineInfo->SetRegexLineMatch(bli.GetRegexLineMatch());
buildLineInfo->SetColumn(bli.GetColumn());
if(severity == SV_WARNING) {
// Warning
m_errorsAndWarningsList.push_back(buildLineInfo);
m_warnCount++;
} else {
// Error
m_errorsAndWarningsList.push_back(buildLineInfo);
m_errorsList.push_back(buildLineInfo);
m_errorCount++;
}
}
return buildLineInfo;
}
void NewBuildTab::DoCacheRegexes()
{
m_cmpPatterns.clear();
// Loop over all known compilers and cache the regular expressions
BuildSettingsConfigCookie cookie;
CompilerPtr cmp = BuildSettingsConfigST::Get()->GetFirstCompiler(cookie);
while(cmp) {
CmpPatterns cmpPatterns;
const Compiler::CmpListInfoPattern& errPatterns = cmp->GetErrPatterns();
const Compiler::CmpListInfoPattern& warnPatterns = cmp->GetWarnPatterns();
Compiler::CmpListInfoPattern::const_iterator iter;
for(iter = errPatterns.begin(); iter != errPatterns.end(); iter++) {
CmpPatternPtr compiledPatternPtr(new CmpPattern(new wxRegEx(iter->pattern, wxRE_ADVANCED | wxRE_ICASE),
iter->fileNameIndex, iter->lineNumberIndex,
iter->columnIndex, SV_ERROR));
if(compiledPatternPtr->GetRegex()->IsValid()) { cmpPatterns.errorsPatterns.push_back(compiledPatternPtr); }
}
for(iter = warnPatterns.begin(); iter != warnPatterns.end(); iter++) {
CmpPatternPtr compiledPatternPtr(new CmpPattern(new wxRegEx(iter->pattern, wxRE_ADVANCED | wxRE_ICASE),
iter->fileNameIndex, iter->lineNumberIndex,
iter->columnIndex, SV_WARNING));
if(compiledPatternPtr->GetRegex()->IsValid()) { cmpPatterns.warningPatterns.push_back(compiledPatternPtr); }
}
m_cmpPatterns.insert(std::make_pair(cmp->GetName(), cmpPatterns));
cmp = BuildSettingsConfigST::Get()->GetNextCompiler(cookie);
}
}
bool NewBuildTab::DoGetCompilerPatterns(const wxString& compilerName, CmpPatterns& patterns)
{
MapCmpPatterns_t::iterator iter = m_cmpPatterns.find(compilerName);
if(iter == m_cmpPatterns.end()) { return false; }
patterns = iter->second;
return true;
}
void NewBuildTab::DoClear()
{
wxFont font = DoGetFont();
m_lastLineColoured = wxNOT_FOUND;
m_maxlineWidth = wxNOT_FOUND;
m_buildInterrupted = false;
m_directories.Clear();
m_buildInfoPerFile.clear();
m_warnCount = 0;
m_errorCount = 0;
m_errorsAndWarningsList.clear();
m_errorsList.clear();
m_cmpPatterns.clear();
// Delete all the user data
std::for_each(m_viewData.begin(), m_viewData.end(), [&](std::pair<int, BuildLineInfo*> p) { delete p.second; });
m_viewData.clear();
m_view->SetEditable(true);
m_view->ClearAll();
m_view->SetEditable(false);
// Clear all markers from open editors
std::vector<clEditor*> editors;
clMainFrame::Get()->GetMainBook()->GetAllEditors(editors, MainBook::kGetAll_Default);
for(size_t i = 0; i < editors.size(); i++) {
editors.at(i)->DelAllCompilerMarkers();
editors.at(i)->AnnotationClearAll();
}
m_curError = m_errorsAndWarningsList.end();
}
void NewBuildTab::MarkEditor(clEditor* editor)
{
if(!editor) return;
editor->DelAllCompilerMarkers();
editor->AnnotationClearAll();
editor->AnnotationSetVisible(2); // Visible with box around it
BuildTabSettingsData options;
EditorConfigST::Get()->ReadObject(wxT("build_tab_settings"), &options);
// Are markers or annotations enabled?
if(options.GetErrorWarningStyle() == BuildTabSettingsData::EWS_NoMarkers) { return; }
std::pair<MultimapBuildInfo_t::iterator, MultimapBuildInfo_t::iterator> iter =
m_buildInfoPerFile.equal_range(editor->GetFileName().GetFullPath());
if(iter.first == iter.second) {
// could not find any, try the fullname
iter = m_buildInfoPerFile.equal_range(editor->GetFileName().GetFullName());
#if defined(__WXGTK__)
if(iter.first == iter.second) {
// Nope. Perhaps it's a symlink
iter = m_buildInfoPerFile.equal_range(CLRealPath(editor->GetFileName().GetFullPath()));
}
#endif
}
// Merge all the errors from the same line into a single error
AnnotationInfoByLineMap_t annotations;
for(; iter.first != iter.second; ++iter.first) {
BuildLineInfo* bli = iter.first->second;
wxString text = m_view->GetLine(bli->GetLineInBuildTab()).Trim().Trim(false);
// remove the line part from the text
text = text.Mid(bli->GetRegexLineMatch());
// if the line starts with ':' remove it as well
text.StartsWith(":", &text);
text.Trim().Trim(false);
if(!text.IsEmpty()) {
if(bli && (bli->GetSeverity() == SV_ERROR || bli->GetSeverity() == SV_WARNING)) {
const auto annotationIter = annotations.lower_bound(bli->GetLineNumber());
if((annotationIter == annotations.end()) || (annotationIter->first != bli->GetLineNumber())) {
// insert new one
AnnotationInfo info;
info.line = bli->GetLineNumber();
info.severity = bli->GetSeverity();
info.text.emplace(std::move(text));
annotations.emplace_hint(annotationIter, bli->GetLineNumber(), std::move(info));
} else {
// we already have an error on this line, concatenate the message
AnnotationInfo& info = annotationIter->second;
info.text.emplace(std::move(text));
if(bli->GetSeverity() == SV_ERROR) {
// override the severity to ERROR
info.severity = SV_ERROR;
}
}
}
}
}
AnnotationInfoByLineMap_t::iterator annIter = annotations.begin();
for(; annIter != annotations.end(); ++annIter) {
wxString concatText;
for(auto& text : annIter->second.text) {
if(!concatText.IsEmpty()) concatText << "\n";
concatText << text;
}
if(annIter->second.severity == SV_ERROR) {
editor->SetErrorMarker(annIter->first, concatText);
} else {
editor->SetWarningMarker(annIter->first, concatText);
}
}
// now place the errors
editor->Refresh();
}
void NewBuildTab::DoSearchForDirectory(const wxString& line)
{
// Check for makefile directory changes lines
if(line.Contains(wxT("Entering directory `"))) {
wxString currentDir = line.AfterFirst(wxT('`'));
currentDir = currentDir.BeforeLast(wxT('\''));
// Collect the m_baseDir
m_directories.Add(currentDir);
} else if(line.Contains(wxT("Entering directory '"))) {
wxString currentDir = line.AfterFirst(wxT('\''));
currentDir = currentDir.BeforeLast(wxT('\''));
// Collect the m_baseDir
m_directories.Add(currentDir);
}
}
void NewBuildTab::OnWorkspaceClosed(wxCommandEvent& e)
{
e.Skip();
DoClear();
InitView();
}
void NewBuildTab::OnWorkspaceLoaded(wxCommandEvent& e)
{
e.Skip();
DoClear();
InitView();
}
void NewBuildTab::DoProcessOutput(bool compilationEnded, bool isSummaryLine)
{
wxUnusedVar(isSummaryLine);
if(!compilationEnded && m_output.Find(wxT("\n")) == wxNOT_FOUND) {
// still dont have a complete line
return;
}
wxArrayString lines = ::wxStringTokenize(m_output, wxT("\n"), wxTOKEN_RET_DELIMS);
m_output.Clear();
// Process only completed lines (i.e. a line that ends with '\n')
for(size_t i = 0; i < lines.GetCount(); ++i) {
if(!compilationEnded && !lines.Item(i).EndsWith(wxT("\n"))) {
m_output << lines.Item(i);
return;
}
wxString buildLine = lines.Item(i); //.Trim().Trim(false);
// If this is a line similar to 'Entering directory `'
// add the path in the directories array
DoSearchForDirectory(buildLine);
BuildLineInfo* buildLineInfo = DoProcessLine(buildLine);
// keep the line info
if(buildLineInfo->GetFilename().IsEmpty() == false) {
m_buildInfoPerFile.insert(std::make_pair(buildLineInfo->GetFilename(), buildLineInfo));
}
if(isSummaryLine) {
buildLine.Trim();
buildLine.Prepend("====");
buildLine.Append("====");
buildLineInfo->SetSeverity(SV_NONE);
}
// Keep the line number in the build tab
buildLineInfo->SetLineInBuildTab(m_view->GetLineCount() - 1); // -1 because the view always has 1 extra "\n"
// Store the line info *before* we add the text
// it is needed in the OnStyle function
m_viewData.insert(std::make_pair(buildLineInfo->GetLineInBuildTab(), buildLineInfo));
m_view->SetEditable(true);
buildLine.Trim();
wxString modText;
::clStripTerminalColouring(buildLine, modText);
int curline = m_view->GetLineCount() - 1;
m_view->AppendText(modText + "\n");
// get the newly added line width
int endPosition = m_view->GetLineEndPosition(curline); // get character position from begin
int beginPosition = m_view->PositionFromLine(curline); // and end of line
wxPoint beginPos = m_view->PointFromPosition(beginPosition);
wxPoint endPos = m_view->PointFromPosition(endPosition);
int curLen = (endPos.x - beginPos.x) + 10;
m_maxlineWidth = wxMax(m_maxlineWidth, curLen);
if(m_maxlineWidth > 0) { m_view->SetScrollWidth(m_maxlineWidth); }
m_view->SetEditable(false);
if(clConfig::Get().Read(kConfigBuildAutoScroll, true)) { m_view->ScrollToEnd(); }
}
}
void NewBuildTab::CenterLineInView(int line)
{
if(line > m_view->GetLineCount()) return;
int linesOnScreen = m_view->LinesOnScreen();
// To place our line in the middle, the first visible line should be
// the: line - (linesOnScreen / 2)
int firstVisibleLine = line - (linesOnScreen / 2);
if(firstVisibleLine < 0) { firstVisibleLine = 0; }
m_view->EnsureVisible(firstVisibleLine);
m_view->SetFirstVisibleLine(firstVisibleLine);
m_view->ClearSelections();
m_view->SetCurrentPos(m_view->PositionFromLine(line));
}
void NewBuildTab::DoToggleWindow()
{
bool success = m_errorCount == 0 && (m_skipWarnings || m_warnCount == 0);
bool viewing = ManagerST::Get()->IsPaneVisible(wxT("Output View")) &&
(clMainFrame::Get()->GetOutputPane()->GetNotebook()->GetCurrentPage() == this);
bool skipwarnings(false);
if(!success) {
if(viewing) {
if(m_buildpaneScrollTo != ScrollToEnd) {
// The user may have opted to go to the first error, the first item, or /dev/null
skipwarnings = (m_errorCount > 0) && (m_buildpaneScrollTo == ScrollToFirstError);
BuildLineInfo* bli = NULL;
if(skipwarnings && !m_errorsList.empty()) {
bli = m_errorsList.front();
} else if(!m_errorsAndWarningsList.empty()) {
bli = m_errorsAndWarningsList.front();
}
// Sanity
if(bli) { CenterLineInView(bli->GetLineInBuildTab()); }
}
}
} else if(m_autoHide && viewing && !m_buildInterrupted) {
ManagerST::Get()->HidePane(clMainFrame::Get()->GetOutputPane()->GetCaption());
} else if(m_showMe == BuildTabSettingsData::ShowOnEnd && !m_autoHide) {
ManagerST::Get()->ShowOutputPane(BUILD_WIN);
}
}
void NewBuildTab::OnNextBuildError(wxCommandEvent& e)
{
// if we are here, we have at least something in the list of errors
if(m_errorsAndWarningsList.empty()) return;
EditorConfigST::Get()->ReadObject(wxT("build_tab_settings"), &m_buildTabSettings);
bool skipWarnings = m_buildTabSettings.GetSkipWarnings();
if(m_curError == m_errorsAndWarningsList.end()) {
m_curError = m_errorsAndWarningsList.begin();
if(m_curError == m_errorsAndWarningsList.end())
// nothing to point to
return;
}
// m_curError is valid
if(skipWarnings) {
do {
if((*m_curError)->GetSeverity() == SV_ERROR) {
// get the wxDataViewItem
int line = (*m_curError)->GetLineInBuildTab();
if(IS_VALID_LINE(line)) {
DoSelectAndOpen(line, true);
++m_curError;
return;
}
} else {
++m_curError;
}
} while(m_curError != m_errorsAndWarningsList.end());
} else {
int line = (*m_curError)->GetLineInBuildTab();
if(IS_VALID_LINE(line)) {
DoSelectAndOpen(line, true);
++m_curError;
}
}
}
void NewBuildTab::OnNextBuildErrorUI(wxUpdateUIEvent& e)
{
e.Enable(!m_errorsAndWarningsList.empty() && !m_buildInProgress);
}
bool NewBuildTab::DoSelectAndOpen(int buildViewLine, bool centerLine)
{
if(!m_viewData.count(buildViewLine)) { return false; }
BuildLineInfo* bli = m_viewData.find(buildViewLine)->second;
if(bli) {
wxFileName fn(bli->GetFilename());
// Highlight the clicked line on the view
m_view->MarkerDeleteAll(LEX_GCC_MARKER);
m_view->MarkerAdd(bli->GetLineInBuildTab(), LEX_GCC_MARKER);
if(!fn.IsAbsolute()) {
std::set<wxString> files;
std::vector<wxFileName> candidates;
ManagerST::Get()->GetWorkspaceFiles(files);
std::for_each(files.begin(), files.end(), [&](const wxString& filepath) {
wxFileName fnFilePath(filepath);
if(fnFilePath.GetFullName() == fn.GetFullName()) { candidates.push_back(fnFilePath); }
});
if(candidates.empty()) { return false; }
if(candidates.size() == 1) {
fn = candidates.at(0);
} else {
// prompt the user
wxArrayString fileArr;
for(size_t i = 0; i < candidates.size(); ++i) {
fileArr.Add(candidates.at(i).GetFullPath());
}
clSingleChoiceDialog dlg(EventNotifier::Get()->TopFrame(), fileArr);
dlg.SetLabel(_("Select a file to open"));
if(dlg.ShowModal() != wxID_OK) return false;
wxString selection = dlg.GetSelection();
if(selection.IsEmpty()) return false;
fn = wxFileName(selection);
// if we resolved it now, open the file there is no point in searching this file
// in m_buildInfoPerFile since the key on this map is kept as full name
clEditor* editor = clMainFrame::Get()->GetMainBook()->FindEditor(fn.GetFullPath());
if(!editor) {
editor = clMainFrame::Get()->GetMainBook()->OpenFile(fn.GetFullPath(), wxT(""),
bli->GetLineNumber(), wxNOT_FOUND, OF_AddJump);
}
if(editor) {
DoCentreErrorLine(bli, editor, centerLine);
return true;
}
}
}
if(fn.IsAbsolute()) {
// try to locate the editor first
clEditor* editor = clMainFrame::Get()->GetMainBook()->FindEditor(fn.GetFullPath());
if(!editor) {
// Open it
editor = clMainFrame::Get()->GetMainBook()->OpenFile(bli->GetFilename(), wxT(""), bli->GetLineNumber(),
wxNOT_FOUND, OF_AddJump);
}
if(editor) {
if(!editor->HasCompilerMarkers()) MarkEditor(editor);
int lineNumber = bli->GetLineNumber();
if(lineNumber > 0) { lineNumber--; }
DoCentreErrorLine(bli, editor, centerLine);
return true;
}
}
}
return false;
}
wxString NewBuildTab::GetBuildContent() const { return m_view->GetText(); }
wxFont NewBuildTab::DoGetFont() const
{
wxFont font = wxNullFont;
LexerConf::Ptr_t lexerConf = EditorConfigST::Get()->GetLexer("C++");
if(lexerConf) { font = lexerConf->GetFontForSyle(wxSTC_C_DEFAULT, this); }
if(font.IsOk() == false) { font = wxSystemSettings::GetFont(wxSYS_ANSI_FIXED_FONT); }
// if the user selected a font in the settings, use it instead
wxFont userFont = m_buildTabSettings.GetBuildFont();
if(userFont.IsOk()) { font = userFont; }
return font;
}
void NewBuildTab::OnMenu(wxContextMenuEvent& e)
{
wxMenu menu;
menu.Append(wxID_COPY, _("Copy Selected Line"));
menu.Append(XRCID("copy_all"), _("Copy Entire Build Output To Clipboard"));
menu.Append(wxID_PASTE, _("Open Build Output in an Empty Editor"));
menu.AppendSeparator();
menu.Append(wxID_CLEAR, _("Clear"));
m_view->PopupMenu(&menu);
}
void NewBuildTab::OnOpenInEditor(wxCommandEvent& e)
{
wxString content = this->GetBuildContent();
clEditor* editor = clMainFrame::Get()->GetMainBook()->NewEditor();
if(editor) { editor->SetText(content); }
}
void NewBuildTab::OnOpenInEditorUI(wxUpdateUIEvent& e) { e.Enable(!m_buildInProgress && !m_view->IsEmpty()); }
void NewBuildTab::OnClear(wxCommandEvent& e) { Clear(); }
void NewBuildTab::OnClearUI(wxUpdateUIEvent& e) { e.Enable(!m_buildInProgress && !IsEmpty()); }
void NewBuildTab::ScrollToBottom() { m_view->ScrollToEnd(); }
void NewBuildTab::AppendLine(const wxString& text)
{
m_output << text;
DoProcessOutput(false, false);
}
void NewBuildTab::OnStyleNeeded(wxStyledTextEvent& event)
{
int startPos = m_view->GetEndStyled();
int endPos = event.GetPosition();
wxString text = m_view->GetTextRange(startPos, endPos);
#if wxCHECK_VERSION(3, 1, 1) && !defined(__WXOSX__)
// The scintilla syntax in e.g. wx3.1.1 changed
m_view->StartStyling(startPos);
#else
m_view->StartStyling(startPos, 0x1f);
#endif
int curline = m_view->GetLineCount();
curline -= 1; // The view always ends with a "\n", we don't count it as a line
wxArrayString lines = ::wxStringTokenize(text, wxT("\n"), wxTOKEN_RET_DELIMS);
// the last line that we coloured
curline -= lines.size();
for(size_t i = 0; i < lines.size(); ++i) {
const wxString& strLine = lines.Item(i);
if(m_viewData.count(curline)) {
BuildLineInfo* b = m_viewData.find(curline)->second;
switch(b->GetSeverity()) {
case SV_WARNING:
m_view->SetStyling(strLine.length(), LEX_GCC_WARNING);
break;
case SV_ERROR:
m_view->SetStyling(strLine.length(), LEX_GCC_ERROR);
break;
case SV_SUCCESS:
m_view->SetStyling(strLine.length(), LEX_GCC_DEFAULT);
break;
case SV_DIR_CHANGE:
m_view->SetStyling(strLine.length(), LEX_GCC_INFO);
break;
case SV_NONE:
default:
m_view->SetStyling(strLine.length(), LEX_GCC_DEFAULT);
break;
}
} else {
m_view->SetStyling(strLine.length(), LEX_GCC_DEFAULT);
}
++curline;
}
}
void NewBuildTab::InitView(const wxString& theme)
{
LexerConf::Ptr_t lexText = ColoursAndFontsManager::Get().GetLexer("text", theme);
lexText->Apply(m_view);
m_view->SetUndoCollection(false);
m_view->EmptyUndoBuffer();
m_view->HideSelection(true);
m_view->SetEditable(false);
StyleProperty::Map_t& props = lexText->GetLexerProperties();
const StyleProperty& defaultStyle = lexText->GetProperty(0);
// reset the styles
m_view->SetLexer(wxSTC_LEX_CONTAINER);
wxFont defaultFont = lexText->GetFontForSyle(0, this);
for(size_t i = 0; i < wxSTC_STYLE_MAX; ++i) {
m_view->StyleSetForeground(i, defaultStyle.GetFgColour());
m_view->StyleSetBackground(i, defaultStyle.GetBgColour());
m_view->StyleSetFont(i, defaultFont);
}
bool is_dark = DrawingUtils::IsDark(props[0].GetBgColour());
wxColour textColour = props[0].GetFgColour();
wxColour infoMsgColour = textColour.ChangeLightness(is_dark ? 50 : 150);
m_view->StyleSetForeground(LEX_GCC_INFO, infoMsgColour);
m_view->StyleSetForeground(LEX_GCC_DEFAULT, textColour);
m_view->StyleSetForeground(LEX_GCC_WARNING, this->m_buildTabSettings.GetWarnColour());
m_view->StyleSetForeground(LEX_GCC_ERROR, this->m_buildTabSettings.GetErrorColour());
m_view->StyleSetHotSpot(LEX_GCC_ERROR, true);
m_view->StyleSetHotSpot(LEX_GCC_WARNING, true);
m_view->SetHotspotActiveUnderline(false); // No underline
m_view->MarkerDefine(LEX_GCC_MARKER, wxSTC_MARK_BACKGROUND);
if(lexText->IsDark()) {
m_view->MarkerSetBackground(LEX_GCC_MARKER, wxColour(defaultStyle.GetBgColour()).ChangeLightness(110));
} else {
m_view->MarkerSetBackground(LEX_GCC_MARKER, wxColour(defaultStyle.GetBgColour()).ChangeLightness(90));
}
// Hide all margins
for(int i = 0; i <= wxSTC_MARGIN_RTEXT; ++i) {
m_view->SetMarginWidth(i, 0);
}
// make the symbol margin 5 pixel width
m_view->SetMarginType(0, wxSTC_MARGIN_SYMBOL);
m_view->SetMarginWidth(0, 5);
}
void NewBuildTab::OnHotspotClicked(wxStyledTextEvent& event)
{
long pos = event.GetPosition();
int line = m_view->LineFromPosition(pos);
DoSelectAndOpen(line, false);
}
void NewBuildTab::OnThemeChanged(wxCommandEvent& event)
{
event.Skip();
InitView();
}
void NewBuildTab::DoCentreErrorLine(BuildLineInfo* bli, clEditor* editor, bool centerLine)
{
// We already got compiler markers set here, just goto the line
clMainFrame::Get()->GetMainBook()->SelectPage(editor);
CHECK_PTR_RET(bli);
// Convert the compiler column to scintilla's position
if(bli->GetColumn() != wxNOT_FOUND) {
editor->CenterLine(bli->GetLineNumber(), bli->GetColumn() - 1);
} else {
editor->CenterLine(bli->GetLineNumber());
}
if(centerLine) {
// If the line in the build error tab is not visible, ensure it is
int linesOnScreen = m_view->LinesOnScreen();
// Our line is not visible
int firstVisibleLine = bli->GetLineInBuildTab() - (linesOnScreen / 2);
if(firstVisibleLine < 0) { firstVisibleLine = 0; }
m_view->EnsureVisible(firstVisibleLine);
m_view->SetFirstVisibleLine(firstVisibleLine);
}
SetActive(editor);
}
void NewBuildTab::ColourOutput()
{
// Loop over the lines and colour them
int fromLine = (m_lastLineColoured == wxNOT_FOUND) ? 0 : m_lastLineColoured;
int untilLine = (m_view->GetLineCount() - 1);
if(fromLine == untilLine) { return; }
for(int i = fromLine; (i < untilLine) && (untilLine >= fromLine); ++i) {
int startPos = m_view->PositionFromLine(i);
int lineEndPos = m_view->GetLineEndPosition(i);
#if wxCHECK_VERSION(3, 1, 1) && !defined(__WXOSX__)
// The scintilla syntax in e.g. wx3.1.1 changed
m_view->StartStyling(startPos);
#else
m_view->StartStyling(startPos, 0x1f);
#endif
// Run the regexes
wxString lineText = m_view->GetLine(i);
LINE_SEVERITY severity;
GetMatchingRegex(lineText, severity);
switch(severity) {
case SV_WARNING:
m_view->SetStyling((lineEndPos - startPos), LEX_GCC_WARNING);
break;
case SV_ERROR:
m_view->SetStyling((lineEndPos - startPos), LEX_GCC_ERROR);
break;
case SV_SUCCESS:
m_view->SetStyling((lineEndPos - startPos), LEX_GCC_DEFAULT);
break;
case SV_DIR_CHANGE:
m_view->SetStyling((lineEndPos - startPos), LEX_GCC_INFO);
break;
case SV_NONE:
default:
m_view->SetStyling((lineEndPos - startPos), LEX_GCC_DEFAULT);
break;
}
}
m_lastLineColoured = untilLine;
}
CmpPatternPtr NewBuildTab::GetMatchingRegex(const wxString& lineText, LINE_SEVERITY& severity)
{
if(lineText.Lower().Contains("entering directory") || lineText.Lower().Contains("leaving directory")) {
severity = SV_DIR_CHANGE;
return NULL;
} else if(lineText.StartsWith("====")) {
severity = SV_NONE;
return NULL;
} else {
// Find *warnings* first
bool isWarning = false;
if(!m_cmp) {
severity = SV_NONE;
return NULL;
}
CmpPatterns cmpPatterns;
if(!DoGetCompilerPatterns(m_cmp->GetName(), cmpPatterns)) {
severity = SV_NONE;
return NULL;
}
// If it is not an error, maybe it's a warning
for(size_t i = 0; i < cmpPatterns.warningPatterns.size(); i++) {
CmpPatternPtr cmpPatterPtr = cmpPatterns.warningPatterns.at(i);
BuildLineInfo bli;
if(cmpPatterPtr->Matches(lineText, bli)) {
severity = SV_WARNING;
return cmpPatterPtr;
}
}
if(!isWarning) {
for(size_t i = 0; i < cmpPatterns.errorsPatterns.size(); i++) {
BuildLineInfo bli;
CmpPatternPtr cmpPatterPtr = cmpPatterns.errorsPatterns.at(i);
if(cmpPatterPtr->Matches(lineText, bli)) {
severity = SV_ERROR;
return cmpPatterPtr;
}
}
}
}
// Default
severity = SV_NONE;
return NULL;
}
void NewBuildTab::OnIdle(wxIdleEvent& event)
{
if(m_view->IsEmpty()) { return; }
ColourOutput();
}
////////////////////////////////////////////
// CmpPatter
bool CmpPattern::Matches(const wxString& line, BuildLineInfo& lineInfo)
{
long fidx, lidx;
if(!m_fileIndex.ToLong(&fidx) || !m_lineIndex.ToLong(&lidx)) return false;
if(!m_regex || !m_regex->IsValid()) return false;
if(!m_regex->Matches(line)) return false;
long colIndex;
if(!m_colIndex.ToLong(&colIndex)) return false;
lineInfo.SetSeverity(m_severity);
if(m_regex->GetMatchCount() > (size_t)fidx) { lineInfo.SetFilename(m_regex->GetMatch(line, fidx)); }
// keep the match length
lineInfo.SetRegexLineMatch(m_regex->GetMatch(line, 0).length());
if(m_regex->GetMatchCount() > (size_t)lidx) {
long lineNumber;
wxString strLine = m_regex->GetMatch(line, lidx);
strLine.ToLong(&lineNumber);
lineInfo.SetLineNumber(--lineNumber);
}
if(m_regex->GetMatchCount() > (size_t)colIndex) {
long column;
wxString strCol = m_regex->GetMatch(line, colIndex);
if(strCol.StartsWith(":")) { strCol.Remove(0, 1); }
if(!strCol.IsEmpty() && strCol.ToLong(&column)) { lineInfo.SetColumn(column); }
}
return true;
}
void BuildLineInfo::NormalizeFilename(const wxArrayString& directories, const wxString& cygwinPath)
{
wxFileName fn(this->GetFilename());
if(fn.IsAbsolute()) {
SetFilename(fn.GetFullPath());
return;
} else if(fn.IsAbsolute(wxPATH_UNIX) && IS_WINDOWS && !cygwinPath.IsEmpty()) {
wxFileName cygfile(fn);
wxString path = cygwinPath + cygfile.GetFullPath();
SetFilename(wxFileName(path).GetFullPath());
return;
}
if(directories.IsEmpty()) {
SetFilename(fn.GetFullName());
return;
}
// we got a relative file name
int dircount = directories.GetCount();
for(int i = dircount - 1; i >= 0; --i) {
wxFileName tmp = fn;
if(tmp.Normalize(wxPATH_NORM_ALL & ~wxPATH_NORM_LONG)) {
// Windows sanity
if(IS_WINDOWS && tmp.GetVolume().length() > 1) {
// Invalid file path
SetFilename("");
return;
}
if(tmp.FileExists() && tmp.MakeAbsolute(directories.Item(i))) {
SetFilename(tmp.GetFullPath());
return;
}
}
}
// One more try: the above will fail if the project isn't stored in the cwd that Normalize() assumes
// So see if one of 'directories' is the correct path to use
for(int i = dircount - 1; i >= 0; --i) {
wxFileName tmp = fn;
if(tmp.Normalize(wxPATH_NORM_ALL & ~wxPATH_NORM_LONG, directories.Item(i))) {
// Windows sanity
if(IS_WINDOWS && tmp.GetVolume().length() > 1) {
// Invalid file path
SetFilename("");
return;
}
if(tmp.FileExists()) {
SetFilename(tmp.GetFullPath());
return;
}
}
}
// failed.. keep it as fullname only
SetFilename(fn.GetFullName());
}
void BuildLineInfo::SetFilename(const wxString& filename)
{
#if defined(__WXGTK__)
// CLRealPath copes with any symlinks in the filepath
m_filename = CLRealPath(filename);
#else
this->m_filename = filename;
#endif
}
|