4 #include "moc_TextEditor.cpp"
8 : QWidget(parent, Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint),
13 setWindowTitle(QString(
"Edit \"") + QString::fromStdString(
Filename.string()) +
"\"");
15 if (this->Filename.extension().string() ==
".py")
24 if (!event->spontaneous())
34 QMessageBox::warning(
this,
"DynExp - Error", e.what());
36 QMetaObject::invokeMethod(
this,
"close", Qt::QueuedConnection);
41 ui.TEText->setPlainText(QString::fromStdString(Text));
57 QWidget::closeEvent(event);
60 if (
ui.TEText->toPlainText().toStdString() != Text)
62 auto Reply = QMessageBox::question(
this,
"DynExp - Save changes?",
63 QString::fromStdString(
"The file \"" +
Filename.string() +
"\" has been edited. Save the changes?"),
64 QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::No | QMessageBox::StandardButton::Abort,
65 QMessageBox::StandardButton::Abort);
67 if (Reply == QMessageBox::StandardButton::Abort)
73 else if (Reply == QMessageBox::StandardButton::Yes)
84 QWidget::closeEvent(event);
91 QMessageBox::warning(
this,
"DynExp - Error",
"Error writing data to file.");
Implements a dialog to edit and save small pieces of text or (Python) code.
Implementation of highlighting for Python code.
TextEditor(QWidget *parent, const std::filesystem::path &Filename)
QSyntaxHighlighter * SyntaxHighlighter
virtual void showEvent(QShowEvent *event) override
const std::filesystem::path Filename
bool DoSave()
Saves the editor's content to the file Filename.
virtual void closeEvent(QCloseEvent *event) override
Thrown when reading from or writing to a file failed.
bool SaveToFile(const QString &Filename, std::string_view Text)
Saves a std::string_view to a file (using QFile). Creates a new file or truncates an existing file's ...
std::string ReadFromFile(const QString &Filename)
Reads the entire content from a text file.
Accumulates include statements to provide a precompiled header.