~efargaspro/+junk/codeblocks-16.01-release

« back to all changes in this revision

Viewing changes to src/sdk/searchresultslog.cpp

  • Committer: damienlmoore at gmail
  • Date: 2016-02-02 02:43:22 UTC
  • Revision ID: damienlmoore@gmail.com-20160202024322-yql5qmtbwdyamdwd
Code::BlocksĀ 16.01

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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: http://svn.code.sf.net/p/codeblocks/code/branches/release-16.xx/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
 
 
33
cbSearchResultsLog::cbSearchResultsLog(const wxArrayString& titles_in, wxArrayInt& widths_in)
 
34
    : ListCtrlLogger(titles_in, widths_in)
 
35
{
 
36
    //ctor
 
37
}
 
38
 
 
39
cbSearchResultsLog::~cbSearchResultsLog()
 
40
{
 
41
    //dtor
 
42
}
 
43
 
 
44
wxWindow* cbSearchResultsLog::CreateControl(wxWindow* parent)
 
45
{
 
46
    ListCtrlLogger::CreateControl(parent);
 
47
    control->SetId(ID_List);
 
48
    Connect(ID_List, -1, wxEVT_COMMAND_LIST_ITEM_ACTIVATED,
 
49
            (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction)
 
50
            &cbSearchResultsLog::OnDoubleClick);
 
51
    Manager::Get()->GetAppWindow()->PushEventHandler(this);
 
52
    return control;
 
53
}
 
54
 
 
55
void cbSearchResultsLog::FocusEntry(size_t index)
 
56
{
 
57
    if (index < (size_t)control->GetItemCount())
 
58
    {
 
59
        control->SetItemState(index, wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED, wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED);
 
60
        control->EnsureVisible(index);
 
61
        SyncEditor(index);
 
62
    }
 
63
}
 
64
 
 
65
void cbSearchResultsLog::SyncEditor(int selIndex)
 
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
 
 
93
void cbSearchResultsLog::OnDoubleClick(cb_unused wxCommandEvent& event)
 
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,
 
101
                                     wxLIST_NEXT_ALL,
 
102
                                     wxLIST_STATE_SELECTED);
 
103
 
 
104
    SyncEditor(index);
 
105
} // end of OnDoubleClick