-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy patheditorhandler.cpp
98 lines (72 loc) · 2.07 KB
/
editorhandler.cpp
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
#include "editorhandler.h"
#include "traceentry.h"
#include "codeeditor.h"
#include "highlighter.h"
#include <QString>
#include <QFile>
#include "common.h"
namespace Templar {
EditorHandler::EditorHandler(CodeEditor *editor)
: editor(editor)
{
}
void EditorHandler::handleEvent(const TraceEntry &entry)
{
QColor color = (entry.isBegin)?
QColor(common::colors::BEGIN) :
QColor(common::colors::END);
highlightPos(entry.position, color);
undoList.push_back(std::make_pair(entry.position, color));
}
void EditorHandler::undoEvent()
{
if (undoList.empty())
return;
undoList.pop_back();
if (undoList.empty())
return;
highlightPos(undoList.back().first,
undoList.back().second);
}
void EditorHandler::inspect(const TraceEntry& entry)
{
highlightPos(entry.position, Qt::yellow);
}
void EditorHandler::reset()
{
undoList.clear();
}
void EditorHandler::forward(const std::vector<TraceEntry> &entryVec)
{
for (int i = 0; i < (int)entryVec.size() - 1; ++i)
{
const TraceEntry& entry = entryVec[i];
QColor color = (entry.isBegin)?
QColor(common::colors::BEGIN) :
QColor(common::colors::END);
undoList.push_back(std::make_pair(entry.position, color));
}
if (!entryVec.empty())
{
handleEvent(entryVec.back());
}
}
void EditorHandler::rewind(unsigned int count)
{
undoList.erase(undoList.end() - count + 1, undoList.end());
undoEvent();
}
void EditorHandler::highlightPos(const QString& fileLoc, const QColor& color) {
QStringList fileLocation = fileLoc.split("|");
QString fileName = fileLocation[0];
int lineNo = fileLocation[1].toInt();
//TODO unused variable: int charNo = fileLocation[2].toInt();
// TODO: throw exception if conversion fails
QFile file(fileName);
file.open(QIODevice::ReadOnly);
QString src(file.readAll());
editor->setPlainText(src);
editor->setDocumentTitle(fileName);
editor->highlightLine(lineNo, color);
}
} // namespace Templar