summaryrefslogtreecommitdiffstats
path: root/quanta/components/debugger/debuggerbreakpointview.cpp
blob: bf4911ad81ebb9ff8b5e4d6f899f69c7bb003eb6 (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/***************************************************************************
                        debuggerbreakpointview.cpp
                        --------------------------
    begin                : 2004-06-27
    copyright            : (C) 2004 Linus McCabe

 ***************************************************************************/

/****************************************************************************
 *                                                                          *
 *   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.                                    *
 *                                                                          *
 ***************************************************************************/

// KDE Includes
#include <klocale.h>
#include <kdebug.h>
#include <kiconloader.h>
#include <kdeversion.h>
#include <kinputdialog.h>
#include <klistview.h>

// Quanta includes
#include "debuggerbreakpointview.h"
#include "debuggerbreakpoint.h"
#include "debuggerclient.h"
#include "debuggermanager.h"
#include "resource.h"
#include "quanta.h"

namespace DebuggerBreakpointViewColumns
{
  // The enums must correspond to the order of the columns
  // If you change here, change the column adding
  enum Columns
  {
    Expression = 0,
    File,
    Class,
    Function,
    Line,
    Value
  };
}

DebuggerBreakpointViewItem::DebuggerBreakpointViewItem(DebuggerBreakpointView* view)
   : KListViewItem(view)
{
}


DebuggerBreakpointView::DebuggerBreakpointView(TQWidget *tqparent, const char *name)
    : KListView(tqparent, name)
{
  // If you change here, change the DebuggerBreakpointViewColumns enums above
  addColumn(i18n("Expression"));
  addColumn(i18n("File"));
  addColumn(i18n("Class"));
  addColumn(i18n("Function"));
  addColumn(i18n("Line"));
  addColumn(i18n("Value"));

  setResizeMode(TQListView::AllColumns);
  setAllColumnsShowFocus(true);

  m_breakpointPopup = new KPopupMenu(this);
  m_breakpointPopup->insertItem(SmallIcon("editdelete"), i18n("&Remove"), this, TQT_SLOT(slotRemoveSelected()));

  connect(this, TQT_SIGNAL( contextMenu( KListView *, TQListViewItem *, const TQPoint & ) ), this, TQT_SLOT(slotBreakpointContextMenu(KListView *, TQListViewItem *, const TQPoint &)));

  // Jump to bp
  connect(this, TQT_SIGNAL( doubleClicked( TQListViewItem *, const TQPoint &, int) ), this, TQT_SLOT(slotBreakpointDoubleClick( TQListViewItem *, const TQPoint &, int)));
}


DebuggerBreakpointView::~DebuggerBreakpointView()
{}

void DebuggerBreakpointView::deleteBreakpoint(const DebuggerBreakpoint &bp)
{
  TQListViewItem *item = findBreakpoint(bp, false);
  if(item)
  {
    delete item;
  }
}


void DebuggerBreakpointView::showBreakpoint(const DebuggerBreakpoint &bp)
{
  TQListViewItem *item = findBreakpoint(bp);
  if(!item)
    return;

  if(bp.type() == DebuggerBreakpoint::LineBreakpoint)
  {
    item->setText(DebuggerBreakpointViewColumns::Value, "");
    item->setText(DebuggerBreakpointViewColumns::Line, TQString::number(bp.line() + 1));
  }
  else
  {
    item->setText(DebuggerBreakpointViewColumns::Value, bp.value());
    item->setText(DebuggerBreakpointViewColumns::Line, "");
  }
  item->setText(DebuggerBreakpointViewColumns::File, bp.filePath());
  item->setText(DebuggerBreakpointViewColumns::Expression, bp.condition());
  item->setText(DebuggerBreakpointViewColumns::Class, bp.inClass());
  item->setText(DebuggerBreakpointViewColumns::Function, bp.inFunction());
}

TQListViewItem* DebuggerBreakpointView::findBreakpoint(const DebuggerBreakpoint& bp, bool addIfNotExist)
{
  // Find the old item if its there
  DebuggerBreakpointViewItem* item = dynamic_cast<DebuggerBreakpointViewItem*>(firstChild());
  while(item)
  {
    if(item->breakpoint() == bp)
      break;

    item =  dynamic_cast<DebuggerBreakpointViewItem*>(item->nextSibling());
  }

  // Insert a new item
  if(!item && addIfNotExist)
  {
    item = new DebuggerBreakpointViewItem(this);
    item->setBreakpoint(bp);
    insertItem(item);
  }

  return item;
}


DebuggerBreakpoint DebuggerBreakpointView::selected()
{
  DebuggerBreakpointViewItem* bpitem = dynamic_cast<DebuggerBreakpointViewItem*>(selectedItem());

  return bpitem->breakpoint();
}

void DebuggerBreakpointView::slotRemoveSelected()
{
  if(!selectedItem())
    return;

  DebuggerBreakpoint bp = selected();

  emit removeBreakpoint(&bp);
}

void DebuggerBreakpointView::keyPressEvent(TQKeyEvent *e)
{
  if(e->key() != TQt::Key_Delete)
  {
    e->ignore();
    return;
  }

  slotRemoveSelected();
}

void DebuggerBreakpointView::clear()
{
  KListView::clear();
}

void DebuggerBreakpointView::slotBreakpointDoubleClick(TQListViewItem *item, const TQPoint &, int )
{
  if(!item)
    return;

  DebuggerBreakpointViewItem* bpitem = dynamic_cast<DebuggerBreakpointViewItem*>(item);
  
  if(!bpitem->breakpoint().filePath().isEmpty())
  {
    quantaApp->gotoFileAndLine(bpitem->breakpoint().filePath(), bpitem->breakpoint().line(), 0);
  }

}

void DebuggerBreakpointView::slotBreakpointContextMenu(KListView *, TQListViewItem *, const TQPoint& point)
{
  if(!selectedItem())
    return;

  m_breakpointPopup->exec(point);
}

#include "debuggerbreakpointview.moc"