summaryrefslogtreecommitdiffstats
path: root/kxsldbg/kxsldbgpart/xsldbgbreakpointsimpl.cpp
blob: e7716a0b7b0d4c90958bf2c42aee16fd49328cd3 (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
194
195
196
197
198
199
200
201
202
/***************************************************************************
                          xsldbgbreakpointsimpl.cpp  -  description
                             -------------------
    begin                : Fri Jan 4 2002
    copyright            : (C) 2002 by Keith Isdale
    email                : [email protected]
 ***************************************************************************/

/***********************************************************************************
 *                                                                         										*
 *   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 <tdelocale.h>
#include <tqlistview.h>
#include <tqlineedit.h>
#include <tqmessagebox.h>
#include "xsldbgdebugger.h"
#include "xsldbgbreakpointsimpl.h"
#include "xsldbgbreakpointlistitem.h"
#include <kdebug.h> 


XsldbgBreakpointsImpl::XsldbgBreakpointsImpl(XsldbgDebugger *debugger,
	TQWidget *parent /*=0*/, const char *name /*=0*/)
		:  XsldbgBreakpoints(parent, name), XsldbgDialogBase()
{
	this->debugger = debugger;
	connect(debugger, TQ_SIGNAL(breakpointItem(TQString /* file*/,
                         int /*line number */, TQString /*templateName*/,
                         TQString /* modeName*/,
	                 bool /* enabled */, int /* id */)),
		this, TQ_SLOT(slotProcBreakpointItem(TQString /* file*/,
			 int /*line number */, TQString /*templateName*/,
			 TQString /* modeName */,
			 bool /* enabled */, int /* id */)));
	connect( breakpointListView,  TQ_SIGNAL(selectionChanged(TQListViewItem *)),
						this, TQ_SLOT(selectionChanged(TQListViewItem*)));
	show();
	refresh();
}

XsldbgBreakpointsImpl::~XsldbgBreakpointsImpl()
{
    debugger = 0L;
}

int XsldbgBreakpointsImpl::getLineNumber()
{
	bool isOk = false;
	int lineNo = lineNumberEdit->text().toInt(&isOk);
	if (isOk == false){
		lineNo = -1;
		kdDebug() << "Invalid line number" << endl;
	}

	return lineNo;
}

int XsldbgBreakpointsImpl::getId()
{
	bool isOk = false;
	int id = idEdit->text().toInt(&isOk);
	if (isOk == false){
		id = -1;
		kdDebug() << "Invalid line number" << endl;
	}

	return id;
}

void XsldbgBreakpointsImpl::slotAddBreakpoint()
{
	int lineNo = getLineNumber();
	if (lineNo != -1) {
	  if (!sourceFileEdit->text().isEmpty()){
	        debugger->slotBreakCmd(sourceFileEdit->text(), lineNo);
	  }else {
	      TQMessageBox::information(this, i18n("Operation Failed"),
		  i18n("A line number was provided without a file name."),
  	           TQMessageBox::Ok);
	  }
	}else if (!templateNameEdit->text().isEmpty() ||
		  !modeNameEdit->text().isEmpty()){
		debugger->slotBreakCmd(templateNameEdit->text(),
				       modeNameEdit->text());
	}else{
	    TQMessageBox::information(this, i18n("Operation Failed"),
		 i18n("No details provided or an invalid line number was supplied."),
  	          TQMessageBox::Ok);
	}
}

void  XsldbgBreakpointsImpl::slotAddAllTemplateBreakpoints()
{
  if (debugger != 0L){
    debugger->fakeInput("break *", true);
    debugger->fakeInput("show", true);
  }
}

void XsldbgBreakpointsImpl::slotDeleteBreakpoint()
{
	int lineNo = getLineNumber(), id = getId();
	if (id != -1){
		debugger->slotDeleteCmd(id);
	}else if (lineNo != -1) {
	  if (!sourceFileEdit->text().isEmpty()){
		debugger->slotDeleteCmd(sourceFileEdit->text(), lineNo);
	  }else {
	    TQMessageBox::information(this, i18n("Operation Failed"),
	         i18n("A line number was provided without a file name."),
  	         TQMessageBox::Ok);
	  }
	}else {
	    TQMessageBox::information(this, i18n("Operation Failed"),
		 i18n("No details provided or an invalid line or ID was supplied."),
  	          TQMessageBox::Ok);
	}
}

void  XsldbgBreakpointsImpl::slotDeleteAllBreakpoints()
{
  if (debugger != 0L){
    debugger->fakeInput("delete *", true);
    debugger->fakeInput("show", true);
  }
}

void XsldbgBreakpointsImpl::slotEnableBreakpoint()
{
	int lineNo = getLineNumber(), id = getId();
	if (id != -1){
		debugger->slotEnableCmd(id);
	}else if (lineNo != -1){
	  if (!sourceFileEdit->text().isEmpty()){
		debugger->slotEnableCmd(sourceFileEdit->text(), lineNo);
	  }else {
	       TQMessageBox::information(this, i18n("Operation Failed"),
	           i18n("A line number was provided without a file name."),
  	           TQMessageBox::Ok);
	  }
	}else {
	    TQMessageBox::information(this, i18n("Operation Failed"),
		 i18n("No details provided."),
  	          TQMessageBox::Ok);
	}
}

void XsldbgBreakpointsImpl::selectionChanged(TQListViewItem *item)
{
	XsldbgBreakpointListItem *breakItem =
	       dynamic_cast<XsldbgBreakpointListItem*>(item);
	if (breakItem){
	  idEdit->setText(TQString::number(breakItem->getId()));
	  templateNameEdit->setText(breakItem->getTemplateName());
	  modeNameEdit->setText(breakItem->getModeName());
	  sourceFileEdit->setText(breakItem->getFileName());
	  lineNumberEdit->setText(TQString::number(breakItem->getLineNumber()));		}
}


void XsldbgBreakpointsImpl::refresh()
{
	/* get xsldbg to tell what breakpoints are set,
	   we'll get the notification back via slotProcBreakpointItem */
	debugger->fakeInput("showbreak", true);
}


void XsldbgBreakpointsImpl::slotClear()
{
	idEdit->setText("");
	templateNameEdit->setText("");
	modeNameEdit->setText("");
 	sourceFileEdit->setText("");
 	lineNumberEdit->setText("");
}

void XsldbgBreakpointsImpl::slotProcBreakpointItem(TQString  fileName,
						   int lineNumber ,
						   TQString templateName,
						   TQString modeName,
						   bool enabled, int id )
{
	if (fileName.isNull())
		  breakpointListView->clear();
	else{
	  breakpointListView->insertItem(
	       new XsldbgBreakpointListItem(breakpointListView,
	       fileName, lineNumber,templateName, modeName, enabled, id));
	}
}




#include "xsldbgbreakpointsimpl.moc"