Code::Blocks  SVN r11506
searchresultslog.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the Code::Blocks IDE and licensed under the GNU Lesser General Public License, version 3
3  * http://www.gnu.org/licenses/lgpl-3.0.html
4  *
5  * $Revision: 9203 $
6  * $Id: searchresultslog.cpp 9203 2013-07-08 23:07:22Z fuscated $
7  * $HeadURL: https://svn.code.sf.net/p/codeblocks/code/trunk/src/sdk/searchresultslog.cpp $
8  */
9 
10 #include "sdk_precomp.h"
11 
12 #ifndef CB_PRECOMP
13  #include <wx/arrstr.h>
14  #include <wx/filename.h>
15  #include <wx/listctrl.h>
16  #include "manager.h"
17  #include "editormanager.h"
18  #include "cbeditor.h"
19 #endif
20 #include "cbstyledtextctrl.h"
21 
22 #include "searchresultslog.h"
23 
24 namespace
25 {
26  const int ID_List = wxNewId();
27 }
28 
29 BEGIN_EVENT_TABLE(cbSearchResultsLog, wxEvtHandler)
30 //
31 END_EVENT_TABLE()
32 
34  : ListCtrlLogger(titles_in, widths_in)
35 {
36  //ctor
37 }
38 
40 {
41  //dtor
42 }
43 
45 {
47  control->SetId(ID_List);
48  Connect(ID_List, -1, wxEVT_COMMAND_LIST_ITEM_ACTIVATED,
49  (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction)
51  Manager::Get()->GetAppWindow()->PushEventHandler(this);
52  return control;
53 }
54 
56 {
57  if (index < (size_t)control->GetItemCount())
58  {
60  control->EnsureVisible(index);
61  SyncEditor(index);
62  }
63 }
64 
66 {
67  wxFileName filename(control->GetItemText(selIndex));
68  wxString file;
69  if (!filename.IsAbsolute())
70  filename.MakeAbsolute(m_Base);
71  file = filename.GetFullPath();
72 
73  wxListItem li;
74  li.m_itemId = selIndex;
75  li.m_col = 1;
76  li.m_mask = wxLIST_MASK_TEXT;
77  control->GetItem(li);
78  long line = 0;
79  li.m_text.ToLong(&line);
80  cbEditor* ed = Manager::Get()->GetEditorManager()->Open(file);
81  if (!line || !ed)
82  return;
83 
84  line -= 1;
85  ed->Activate();
86  ed->GotoLine(line);
87 
88  if (cbStyledTextCtrl* ctrl = ed->GetControl()) {
89  ctrl->EnsureVisible(line);
90  }
91 }
92 
94 {
95  // go to the relevant file/line
96  if (control->GetSelectedItemCount() == 0)
97  return;
98 
99  // find selected item index
100  int index = control->GetNextItem(-1,
103 
104  SyncEditor(index);
105 } // end of OnDoubleClick
int wxNewId()
int GetSelectedItemCount() const
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
~cbSearchResultsLog() override
long GetNextItem(long item, int geometry=wxLIST_NEXT_ALL, int state=wxLIST_STATE_DONTCARE) const
void GotoLine(int line, bool centerOnScreen=true) override
Move the caret at the specified line.
Definition: cbeditor.cpp:2223
a logger which prints messages to a wxListCtrl
Definition: loggers.h:120
virtual void Activate()
Activate this editor.
Definition: editorbase.cpp:175
#define wxLIST_STATE_SELECTED
wxWindow * GetAppWindow() const
Definition: manager.cpp:424
#define wxLIST_MASK_TEXT
EditorManager * GetEditorManager() const
Definition: manager.cpp:434
bool SetItemState(long item, long state, long stateMask)
cbStyledTextCtrl * GetControl() const
Returns a pointer to the underlying cbStyledTextCtrl object (which itself is the wxWindows implementa...
Definition: cbeditor.cpp:842
void FocusEntry(size_t index)
void OnDoubleClick(wxCommandEvent &event)
int GetItemCount() const
wxString GetItemText(long item, int col=0) const
wxListCtrl * control
Definition: loggers.h:124
cbEditor * Open(const wxString &filename, int pos=0, ProjectFile *data=nullptr)
wxWindow * CreateControl(wxWindow *parent) override
Definition: loggers.cpp:405
wxArray< int > wxArrayInt
A file editor.
Definition: cbeditor.h:43
void SyncEditor(int selIndex)
bool EnsureVisible(long item)
wxWindow * CreateControl(wxWindow *parent) override
bool GetItem(wxListItem &info) const
#define wxLIST_STATE_FOCUSED