summaryrefslogtreecommitdiffstats
path: root/kxsldbg/kxsldbgpart/qxsldbgdoc.cpp
blob: eac763e043a77fdd45369531e23fb943bf2bdd32 (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
/**
   File : qxsldbgdoc.cpp
   Author : Keith Isdale
   Date : 19th April 2002
   Description : The document to handle source and breakpoints
 */

#include "qxsldbgdoc.h"
#include <ktexteditor/markinterface.h>
#include <ktexteditor/editorchooser.h>
#include <tqfile.h>
#include <tqdir.h>
#include <tqtextstream.h>
#include <tqptrlist.h>


QXsldbgDoc::QXsldbgDoc(TQWidget *parent, KURL url)
    : TQObject(0L, "QXsldbgDoc"), kDoc(0L),kView(0L), locked(false) 
{
    kDoc = KTextEditor::createDocument("libkatepart", 0L,"KTextEditor::Document");
    connect(kDoc, TQT_SIGNAL(started(TDEIO::Job *)), this, TQT_SLOT(lockDoc()));
    connect(kDoc, TQT_SIGNAL(completed()), this, TQT_SLOT(unlockDoc()));
    if (kDoc){
	kView = kDoc->createView(parent, "QXsldbgDocView");
	KURL cleanUrl;
	// convert paths relative to PWD into a absolute path
	TQString relUrl = url.prettyURL();
	if (!relUrl.contains(":/")){
	    if (!(relUrl.left(1) == "/"))
		relUrl.prepend(TQDir::currentDirPath() + "/");
	    cleanUrl.setFileName(relUrl); 
	}else{
	    cleanUrl = url; 
	}
	kDoc->openURL(cleanUrl);
    }
}


QXsldbgDoc::~QXsldbgDoc()
{
    if (kDoc){
	if (kDoc->views().count() == 1){
	    	kDoc->closeURL(false);	
		delete kDoc;
	}
    }
}

void QXsldbgDoc::slotResult( TDEIO::Job *job )
{
    if ( job->error() != 0 ){
    }else{
    }
    emit docChanged();
}

KURL QXsldbgDoc::url() const
{
    if (kDoc)
	return kDoc->url();
    else
	return KURL();
}

void QXsldbgDoc::refresh()
{
    if (kDoc){
	KURL lastUrl = kDoc->url();	
	kDoc->closeURL(false);
	kDoc->openURL(lastUrl);
    }
}


void QXsldbgDoc::enableBreakPoint(uint lineNumber, bool state)
{
    if (locked)
	return;

    KTextEditor::MarkInterface *markIf = KTextEditor::markInterface(kDoc);
    if (markIf){
	if (state){
	    markIf->setMark(lineNumber, KTextEditor::MarkInterface::BreakpointActive);
        }else{
	    markIf->removeMark(lineNumber, KTextEditor::MarkInterface::BreakpointDisabled);
        }
    }
}

void QXsldbgDoc::addBreakPoint(uint lineNumber, bool enabled)
{
    if (locked)
	return;

    KTextEditor::MarkInterface *markIf = KTextEditor::markInterface(kDoc);
    if (markIf){
        if (enabled)
            markIf->setMark(lineNumber, KTextEditor::MarkInterface::BreakpointActive);
        else
            markIf->setMark(lineNumber, KTextEditor::MarkInterface::BreakpointDisabled);
    }
}

void QXsldbgDoc::deleteBreakPoint(uint lineNumber)
{
    if (locked)
	return;

    KTextEditor::MarkInterface *markIf = KTextEditor::markInterface(kDoc);
    if (markIf)
	markIf->clearMark(lineNumber);
}


void QXsldbgDoc::clearMarks(bool allMarkTypes)
{
    if (locked)
	return;

    KTextEditor::MarkInterface *markIf = KTextEditor::markInterface(kDoc);
    if (markIf){
        if (!allMarkTypes){
            TQPtrList<KTextEditor::Mark> marks = markIf->marks();
            while ( marks.current()) {
                markIf->removeMark(marks.current()->line, KTextEditor::MarkInterface::Execution);
                markIf->removeMark(marks.current()->line, KTextEditor::MarkInterface::BreakpointReached);
                marks.next();
            }
        }else {
            markIf->clearMarks();
        }
    }

}

void QXsldbgDoc::selectBreakPoint(uint lineNumber, bool reachedBreakPoint)
{
    if (locked)
	return;

    clearMarks(false);
    KTextEditor::MarkInterface *markIf = KTextEditor::markInterface(kDoc);
    if (markIf){
        if (reachedBreakPoint){
            //markIf->setMark(lineNumber, KTextEditor::MarkInterface::BreakpointReached);
        }else{
            markIf->setMark(lineNumber, KTextEditor::MarkInterface::Execution);
        }
    }
}

void QXsldbgDoc::lockDoc()
{
    locked = true;
}

void QXsldbgDoc::unlockDoc()
{
    locked = false;
}
#include "qxsldbgdoc.moc"