summaryrefslogtreecommitdiff
path: root/LiteEditor/cpp_symbol_tree.cpp
blob: 6843fad83fe288401ed3367c97e304669ae10e3c (plain)
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
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright            : (C) 2008 by Eran Ifrah
// file name            : cpp_symbol_tree.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 "precompiled_header.h"
#include "globals.h"
#include "stringsearcher.h"
#include "stringsearcher.h"
#include "cl_editor.h"
#include "pluginmanager.h"

#include "cpp_symbol_tree.h"
#include "manager.h"
#include "frame.h"
#include <wx/xrc/xmlres.h>
#include <wx/imaglist.h>

IMPLEMENT_DYNAMIC_CLASS(CppSymbolTree, SymbolTree)

const wxEventType wxEVT_CMD_CPP_SYMBOL_ITEM_SELECTED = wxNewEventType();

//----------------------------------------------------------------
// accessory function
//----------------------------------------------------------------
wxImageList* CreateSymbolTreeImages()
{
    wxImageList* images = new wxImageList(16, 16, true);

    BitmapLoader* bmpLoader = PluginManager::Get()->GetStdIcons();
    images->Add(bmpLoader->LoadBitmap(wxT("mime/16/cpp")));              // 0
    images->Add(bmpLoader->LoadBitmap(wxT("cc/16/namespace")));          // 1
    images->Add(bmpLoader->LoadBitmap(wxT("cc/16/globals")));            // 2
    images->Add(bmpLoader->LoadBitmap(wxT("cc/16/class")));              // 3
    images->Add(bmpLoader->LoadBitmap(wxT("cc/16/struct")));             // 4
    images->Add(bmpLoader->LoadBitmap(wxT("cc/16/function_public")));    // 5
    images->Add(bmpLoader->LoadBitmap(wxT("cc/16/function_protected"))); // 6
    images->Add(bmpLoader->LoadBitmap(wxT("cc/16/function_private")));   // 7
    images->Add(bmpLoader->LoadBitmap(wxT("cc/16/member_public")));      // 8
    images->Add(bmpLoader->LoadBitmap(wxT("cc/16/member_protected")));   // 9
    images->Add(bmpLoader->LoadBitmap(wxT("cc/16/member_private")));     // 10
    images->Add(bmpLoader->LoadBitmap(wxT("cc/16/typedef")));            // 11
    images->Add(bmpLoader->LoadBitmap(wxT("cc/16/macro")));              // 12
    images->Add(bmpLoader->LoadBitmap(wxT("cc/16/enum")));               // 13
    images->Add(bmpLoader->LoadBitmap(wxT("cc/16/enumerator")));         // 14
    images->Add(bmpLoader->LoadBitmap(wxT("mime/16/cpp")));              // 15
    return images;
}

CppSymbolTree::CppSymbolTree() {}

CppSymbolTree::CppSymbolTree(wxWindow* parent, const wxWindowID id, const wxPoint& pos, const wxSize& size, long style)
    : SymbolTree(parent, id, pos, size, style)
{
    Bind(wxEVT_TREE_ITEM_ACTIVATED, &CppSymbolTree::OnItemActivated, this);
    MSWSetNativeTheme(this);
}


bool CppSymbolTree::DoItemActivated(wxTreeItemId item, wxEvent& event, bool notify)
{
    //-----------------------------------------------------
    // Each tree items, keeps a private user data that
    // holds the key for searching the its corresponding
    // node in the m_tree data structure
    //-----------------------------------------------------
    if(item.IsOk() == false) return false;

    MyTreeItemData* itemData = static_cast<MyTreeItemData*>(GetItemData(item));
    if(!itemData) {
        event.Skip();
        return false;
    }

    wxString filename = itemData->GetFileName();
    wxString project = ManagerST::Get()->GetProjectNameByFile(filename);
    wxString pattern = itemData->GetPattern();
    int lineno = itemData->GetLine();

    // Open the file and set the cursor to line number
    if(clMainFrame::Get()->GetMainBook()->OpenFile(filename, project, lineno - 1)) {
        // get the editor, and search for the pattern in the file
        LEditor* editor = clMainFrame::Get()->GetMainBook()->GetActiveEditor();
        if(editor) {
            FindAndSelect(editor, pattern, GetItemText(item));
        }
    }

    // post an event that an item was activated
    if(notify) {
        wxCommandEvent e(wxEVT_CMD_CPP_SYMBOL_ITEM_SELECTED);
        e.SetEventObject(this);
        wxPostEvent(GetEventHandler(), e);
    }
    return true;
}

void CppSymbolTree::OnItemActivated(wxTreeEvent& event) { DoItemActivated(event.GetItem(), event, true); }

void CppSymbolTree::FindAndSelect(LEditor* editor, wxString& pattern, const wxString& name)
{
    editor->FindAndSelectV(pattern, name);
}