File: LLDBTooltip.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 (124 lines) | stat: -rw-r--r-- 4,137 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
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
123
124
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright            : (C) 2014 Eran Ifrah
// file name            : LLDBTooltip.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 "LLDBTooltip.h"
#include "LLDBPlugin.h"
#include "macros.h"
#include "event_notifier.h"
#include <wx/wupdlock.h>
#include "cl_config.h"
#include "globals.h"

LLDBTooltip::LLDBTooltip(LLDBPlugin* plugin)
    : clResizableTooltip(plugin)
    , m_plugin(plugin)
{
    MSWSetNativeTheme(m_treeCtrl);
    m_plugin->GetLLDB()->Bind(wxEVT_LLDB_VARIABLE_EXPANDED, &LLDBTooltip::OnLLDBVariableExpanded, this);
}

LLDBTooltip::~LLDBTooltip()
{
    m_plugin->GetLLDB()->Unbind(wxEVT_LLDB_VARIABLE_EXPANDED, &LLDBTooltip::OnLLDBVariableExpanded, this);
}

void LLDBTooltip::OnItemExpanding(wxTreeEvent& event)
{
    CHECK_ITEM_RET(event.GetItem());
    LLDBVariableClientData* data = ItemData(event.GetItem());

    wxTreeItemIdValue cookie;
    wxTreeItemId child = m_treeCtrl->GetFirstChild(event.GetItem(), cookie);
    if(m_treeCtrl->GetItemText(child) == "<dummy>") {

        // dummy item, remove it
        m_treeCtrl->DeleteChildren(event.GetItem());
        m_plugin->GetLLDB()->RequestVariableChildren(data->GetVariable()->GetLldbId());

        // Store the treeitemid parent in cache
        m_itemsPendingExpansion.insert(std::make_pair(data->GetVariable()->GetLldbId(), event.GetItem()));

    } else {
        event.Skip();
    }
}

void LLDBTooltip::Show(const wxString& displayName, LLDBVariable::Ptr_t variable)
{
    DoCleanup();
    wxTreeItemId item = m_treeCtrl->AddRoot(
        variable->ToString(displayName), wxNOT_FOUND, wxNOT_FOUND, new LLDBVariableClientData(variable));
    if(variable->HasChildren()) {
        m_treeCtrl->AppendItem(item, "<dummy>");
    }
    clResizableTooltip::ShowTip();
}

void LLDBTooltip::DoCleanup()
{
    m_treeCtrl->DeleteAllItems();
    m_itemsPendingExpansion.clear();
}

LLDBVariableClientData* LLDBTooltip::ItemData(const wxTreeItemId& item) const
{
    return dynamic_cast<LLDBVariableClientData*>(m_treeCtrl->GetItemData(item));
}

void LLDBTooltip::OnLLDBVariableExpanded(LLDBEvent& event)
{
    int variableId = event.GetVariableId();
    wxUnusedVar(variableId);
    std::map<int, wxTreeItemId>::iterator iter = m_itemsPendingExpansion.find(event.GetVariableId());
    if(iter == m_itemsPendingExpansion.end()) {
        // does not belong to us
        event.Skip();
        return;
    }

    wxTreeItemId parentItem = iter->second;

    // add the variables to the tree
    for(size_t i = 0; i < event.GetVariables().size(); ++i) {
        DoAddVariable(parentItem, event.GetVariables().at(i));
    }

    // Expand the parent item
    if(m_treeCtrl->HasChildren(parentItem)) {
        m_treeCtrl->Expand(parentItem);
    }

    // remove it
    m_itemsPendingExpansion.erase(iter);
}

void LLDBTooltip::DoAddVariable(const wxTreeItemId& parent, LLDBVariable::Ptr_t variable)
{
    wxTreeItemId item = m_treeCtrl->AppendItem(
        parent, variable->ToString(), wxNOT_FOUND, wxNOT_FOUND, new LLDBVariableClientData(variable));
    if(variable->HasChildren()) {
        m_treeCtrl->AppendItem(item, "<dummy>");
    }
}