Code::Blocks  SVN r11506
compilermessages.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the Code::Blocks IDE and licensed under the GNU General Public License, version 3
3  * http://www.gnu.org/licenses/gpl-3.0.html
4  *
5  * $Revision: 11115 $
6  * $Id: compilermessages.cpp 11115 2017-07-22 15:52:09Z fuscated $
7  * $HeadURL: https://svn.code.sf.net/p/codeblocks/code/trunk/src/plugins/compilergcc/compilermessages.cpp $
8  */
9 
10 #include "sdk.h"
11 #ifndef CB_PRECOMP
12  #include <wx/intl.h>
13  #include <wx/listctrl.h>
14  #include <wx/menu.h>
15  #include <wx/string.h>
16  #include <wx/utils.h>
17  #include "globals.h"
18  #include "manager.h"
19  #include "configmanager.h"
20 #endif
21 #include <wx/clipbrd.h>
22 #include <wx/dataobj.h>
23 #include "compilererrors.h"
24 #include "compilermessages.h"
25 #include "prep.h"
26 
27 namespace
28 {
29  int idList = wxNewId();
30  int idMenuFit = wxNewId();
31  int idMenuAutoFit = wxNewId();
32 }
33 
34 BEGIN_EVENT_TABLE(CompilerMessages, wxEvtHandler)
35 END_EVENT_TABLE()
36 
37 CompilerMessages::CompilerMessages(const wxArrayString& titles_in, const wxArrayInt& widths_in)
38  : ListCtrlLogger(titles_in, widths_in, true)
39 {
40  m_autoFit = Manager::Get()->GetConfigManager(wxT("compiler"))->ReadBool(wxT("/autofit_during_build"), false);
41  //ctor
42 }
43 
45 {
46  //dtor
47  Disconnect(idList, -1, wxEVT_COMMAND_LIST_ITEM_SELECTED,
48  (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction)
50  Disconnect(idList, -1, wxEVT_COMMAND_LIST_ITEM_ACTIVATED,
51  (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction)
53  Disconnect(idMenuFit, -1, wxEVT_COMMAND_MENU_SELECTED,
54  (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction)
56  Disconnect(idMenuAutoFit, -1, wxEVT_COMMAND_MENU_SELECTED,
57  (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction)
59 }
60 
62 {
64  control->SetId(idList);
65  Connect(idList, -1, wxEVT_COMMAND_LIST_ITEM_SELECTED,
66  (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction)
68  Connect(idList, -1, wxEVT_COMMAND_LIST_ITEM_ACTIVATED,
69  (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction)
71  Connect(idMenuFit, -1, wxEVT_COMMAND_MENU_SELECTED,
72  (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction)
74  Connect(idMenuAutoFit, -1, wxEVT_COMMAND_MENU_SELECTED,
75  (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction)
77  Manager::Get()->GetAppWindow()->PushEventHandler(this);
78  return control;
79 }
80 
82 {
83  if ( !Manager::Get()->IsAppShuttingDown() )
84  {
85  Manager::Get()->GetAppWindow()->RemoveEventHandler(this);
86  }
87 }
88 
90 {
91  if (feature == Feature::Additional)
92  return true;
93  else
94  return ListCtrlLogger::HasFeature(feature);
95 }
96 
98 {
99  menu.Append(idMenuFit, _("Fit text"), _("Makes the whole text visible"));
100  menu.AppendCheckItem(idMenuAutoFit, _("Fit automatically"),
101  _("Automatically makes the whole text visible during compilation"));
102  menu.Check(idMenuAutoFit, m_autoFit);
103 }
104 
106 {
107  if (nr < 0 or nr >= control->GetItemCount())
108  return;
110  control->EnsureVisible(nr);
111 }
112 
114 {
115  // single and double-click, behave the same
116 
117  // a compiler message has been clicked
118  // go to the relevant file/line
119  if (control->GetSelectedItemCount() == 0 || !m_pErrors)
120  return;
121 
122  // find selected item index
123  int index = control->GetNextItem(-1,
126 
127  // call the CompilerErrors* ptr; it 'll do all the hard work ;)
128  m_pErrors->GotoError(index);
129 }
130 
132 {
133  // single and double-click, behave the same
134  OnClick(event);
135  return;
136 }
137 
139 {
140  FitColumns();
141 }
142 
144 {
145  m_autoFit = event.IsChecked();
146  Manager::Get()->GetConfigManager(wxT("compiler"))->Write(wxT("/autofit_during_build"), m_autoFit);
147 }
148 
149 void CompilerMessages::AutoFitColumns(int cb_unused column)
150 {
151  if (m_autoFit)
152  FitColumns();
153 }
154 
156 {
157  if (!control)
158  return;
159  int count = control->GetColumnCount();
160  for (int ii = 0; ii < count; ++ii)
162  int ctrlWidth = control->GetClientSize().x;
163  for (int ii = 1; ii < count; ++ii)
164  ctrlWidth -= control->GetColumnWidth(ii);
165  int width = control->GetColumnWidth(0);
166  if (width > ctrlWidth)
167  control->SetColumnWidth(0, ctrlWidth);
168 }
int GetColumnWidth(int col) const
int wxNewId()
int GetSelectedItemCount() const
ConfigManager * GetConfigManager(const wxString &name_space) const
Definition: manager.cpp:474
static Manager * Get()
Use Manager::Get() to get a pointer to its instance Manager::Get() is guaranteed to never return an i...
Definition: manager.cpp:182
long GetNextItem(long item, int geometry=wxLIST_NEXT_ALL, int state=wxLIST_STATE_DONTCARE) const
void GotoError(int nr)
virtual ~CompilerMessages()
bool ReadBool(const wxString &name, bool defaultVal=false)
a logger which prints messages to a wxListCtrl
Definition: loggers.h:120
void OnFit(wxCommandEvent &event)
wxMenuItem * Append(int id, const wxString &item=wxEmptyString, const wxString &helpString=wxEmptyString, wxItemKind kind=wxITEM_NORMAL)
#define wxLIST_STATE_SELECTED
void OnAutoFit(wxCommandEvent &event)
#define wxT(string)
wxWindow * GetAppWindow() const
Definition: manager.cpp:424
bool SetItemState(long item, long state, long stateMask)
void Write(const wxString &name, const wxString &value, bool ignoreEmpty=false)
void OnClick(wxCommandEvent &event)
void Check(int id, bool check)
bool HasFeature(Feature::Enum feature) const override
Definition: loggers.cpp:417
int GetItemCount() const
virtual void AppendAdditionalMenuItems(wxMenu &menu)
wxListCtrl * control
Definition: loggers.h:124
virtual wxWindow * CreateControl(wxWindow *parent)
const wxString & _(const wxString &string)
wxWindow * CreateControl(wxWindow *parent) override
Definition: loggers.cpp:405
wxArray< int > wxArrayInt
CompilerErrors * m_pErrors
virtual bool HasFeature(Feature::Enum feature) const
void OnDoubleClick(wxCommandEvent &event)
int GetColumnCount() const
bool SetColumnWidth(int col, int width)
void AutoFitColumns(int column)
bool EnsureVisible(long item)
virtual void FocusError(int nr)
#define wxLIST_STATE_FOCUSED
wxMenuItem * AppendCheckItem(int id, const wxString &item, const wxString &help=wxEmptyString)