-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpdialog.cpp
102 lines (97 loc) · 2.42 KB
/
helpdialog.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
99
100
101
102
#include "helpdialog.h"
#include <QFile>
#include <QDir>
#include "settings.h"
#include "blocklist.h"
#include "ui_helpdialog.h"
HelpDialog::HelpDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::HelpDialog)
{
ui->setupUi(this);
ui->mainContent->hd=this;
connect(ui->mainContent,SIGNAL(linkClicked(QString)),this,SLOT(openLink(QString)));
}
HelpDialog::~HelpDialog()
{
delete ui;
}
void HelpDialog::openLink(QString link)
{
if(!((last.length()>0)&&(last.last()==link)))
last.append(link);
QString data=getFile(link);
if(data.isEmpty())
data="ERROR";
ui->mainContent->setText(data);
}
QString HelpDialog::getFile(QString url)
{
QString data;
QString file=url;
file.remove(0,7);
QDir dir(Settings::final()->applicationDir());
dir.cd("help");
if(file=="blocks")
{
QFile file(dir.absoluteFilePath("blocks.md"));
file.open(QFile::ReadOnly);
data=file.readAll();
file.close();
QByteArray list;
dir.cd("blocks");
for(auto block:BlockList::blocks)
if(block->subItem==false)
{
QDir dir2(QFile(((LuaBlock*)block)->fileName).fileName());
dir2.cdUp();
QString fn=dir2.relativeFilePath(((LuaBlock*)block)->fileName);
fn.replace(".lua","");
list+="- ["+block->name+"](help://blocks/"+fn+")\n";
}
list+="</ul>";
data.replace("__BLOCKS__",list);
}
else if(file.startsWith("blocks/"))
{
dir.cd("blocks");
file.remove(0,7);
QFile filef(dir.absoluteFilePath(file+".md"));
qDebug()<<file;
filef.open(QFile::ReadOnly);
data=filef.readAll();
filef.close();
QDir dir2(Settings::final()->applicationDir());
dir2.cd("modules");
QString search=dir2.absoluteFilePath(file+".lua");
Block* block=NULL;
for(auto b2:BlockList::blocks)
{
if(((LuaBlock*)b2)->fileName==search)
{
block=b2;
}
}
if(block!=NULL)
{
data.replace("__BLOCK_NAME__",block->name.toUtf8());
}
else
{
data="INTERNAL ERROR";
}
}
else
{
data="Not Found";
}
return data;
}
void HelpDialog::on_back_clicked()
{
if(last.length()>1)
{
last.removeLast();
openLink(last.takeLast());
}
}