File: quick_outline_dlg.cpp

package info (click to toggle)
codelite 12.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 95,112 kB
  • sloc: cpp: 424,040; ansic: 18,284; php: 9,569; lex: 4,186; yacc: 2,820; python: 2,294; sh: 312; makefile: 51; xml: 13
file content (65 lines) | stat: -rw-r--r-- 2,088 bytes parent folder | download | duplicates (3)
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
#include "precompiled_header.h"
#include "quick_outline_dlg.h"
#include <globals.h>
#include <imanager.h>
#include <ieditor.h>
#include <windowattrmanager.h>

PHPQuickOutlineDlg::PHPQuickOutlineDlg(wxWindow* parent, IEditor* editor, IManager* manager)
    : QuickOutlineDlgBase(parent)
    , m_editor(editor)
    , m_mgr(manager)
{
    // Parse the current file
    m_treeCtrlLayout->SetManager(m_mgr);
    m_treeCtrlLayout->SetEditor(m_editor);
    m_treeCtrlLayout->Construct();

    m_treeCtrlLayout->Connect(
        wxEVT_COMMAND_TREE_ITEM_ACTIVATED, wxTreeEventHandler(PHPQuickOutlineDlg::OnItemActivated), NULL, this);
    m_treeCtrlLayout->SetFocus();
    m_treeCtrlLayout->Bind(wxEVT_KEY_DOWN, &PHPQuickOutlineDlg::OnKeyDown, this);
    SetName("PHPQuickOutlineDlg");
    WindowAttrManager::Load(this);
    CenterOnParent();
}

PHPQuickOutlineDlg::~PHPQuickOutlineDlg()
{
    m_treeCtrlLayout->Unbind(wxEVT_KEY_DOWN, &PHPQuickOutlineDlg::OnKeyDown, this);
}

void PHPQuickOutlineDlg::OnKeyDown(wxKeyEvent& event)
{
    event.Skip();
    if(event.GetKeyCode() == WXK_ESCAPE) {
        event.Skip(false);
        Close();
    }
}

void PHPQuickOutlineDlg::OnItemActivated(wxTreeEvent& event) { DoItemSelected(event.GetItem()); }

void PHPQuickOutlineDlg::DoItemSelected(const wxTreeItemId& item)
{
    if(item.IsOk()) {
        QItemData* data = dynamic_cast<QItemData*>(m_treeCtrlLayout->GetItemData(item));
        if(data && data->m_entry) {
            DoSelectMatch(data->m_entry->GetFilename().GetFullPath(),
                          data->m_entry->GetLine() - 1,
                          data->m_entry->GetShortName());
            Close();
        }
    }
}

void PHPQuickOutlineDlg::DoSelectMatch(const wxString& filename, int line, const wxString& what)
{
    if(m_mgr->OpenFile(filename, wxT(""), line)) {
        IEditor* editor = m_mgr->GetActiveEditor();
        if(editor) {
            m_mgr->FindAndSelect(what, what, editor->PosFromLine(line));
            editor->SetActive();
        }
    }
}