-
Notifications
You must be signed in to change notification settings - Fork 0
/
markdown_editor.cpp
44 lines (38 loc) · 1.59 KB
/
markdown_editor.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
#include "markdown_editor.h"
#include "diae_application.h"
#include <QDebug>
MarkdownEditor::MarkdownEditor(QObject *parent)
: Editor(parent),
current_artefact(QSharedPointer<MarkdownArtefact>::create()) {
openArtefact();
}
MarkdownEditor::~MarkdownEditor() {}
void MarkdownEditor::openArtefact() {
QUrl fileUrl = diaeApp->artefact_manager->createArtefact("md");
openArtefact(fileUrl);
}
void MarkdownEditor::openArtefact(const QUrl &fileUrl) {
new_artefact_url = fileUrl;
connect(diaeApp->artefact_manager, &ArtefactManager::artefactLoaded, this,
&MarkdownEditor::artefactOpened);
diaeApp->artefact_manager->getArtefact(fileUrl);
}
void MarkdownEditor::artefactOpened(const QUrl &fileUrl,
QSharedPointer<Artefact> artefact) {
if (fileUrl == new_artefact_url) {
current_artefact_url = new_artefact_url;
disconnect(current_artefact.data(), &MarkdownArtefact::textChanged, this,
&MarkdownEditor::artefactTextChanged);
current_artefact = qSharedPointerCast<MarkdownArtefact>(artefact);
disconnect(diaeApp->artefact_manager, &ArtefactManager::artefactLoaded,
this, &MarkdownEditor::artefactOpened);
connect(current_artefact.data(), &MarkdownArtefact::textChanged, this,
&MarkdownEditor::artefactTextChanged);
emit urlChanged(current_artefact_url);
qInfo() << "artefact opened with text: " << text();
}
}
bool MarkdownEditor::isMyArtefactType(const QUrl &fileUrl) {
QString extension = ArtefactManager::getExtension(fileUrl);
return supported_extensions.contains(extension);
}