Implemented actions widget and editing functionalities
This commit is contained in:
@@ -7,6 +7,8 @@
|
||||
#include <QTextBlock>
|
||||
#include <QMessageBox>
|
||||
#include <QSignalBlocker>
|
||||
#include <QFileDialog>
|
||||
#include <QFile>
|
||||
|
||||
#include "jshighlighter.h"
|
||||
|
||||
@@ -77,7 +79,7 @@ void CodeEditorDialog::reject()
|
||||
tr("Do you want to save your changes?"),
|
||||
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,
|
||||
QMessageBox::Save
|
||||
);
|
||||
);
|
||||
switch (result)
|
||||
{
|
||||
case QMessageBox::Save:
|
||||
@@ -120,17 +122,45 @@ void CodeEditorDialog::addToolbarWidget(QWidget *widget)
|
||||
|
||||
void CodeEditorDialog::load()
|
||||
{
|
||||
const auto path = QFileDialog::getOpenFileName(this, tr("Load Code from a Text File..."));
|
||||
if (path.isEmpty())
|
||||
return;
|
||||
|
||||
QFile file{path};
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
{
|
||||
QMessageBox::warning(this, tr("Could not open file!"), tr("Could not open file!") + "\n\n" + file.errorString());
|
||||
return;
|
||||
}
|
||||
|
||||
m_ui->codeEdit->setPlainText(QString::fromUtf8(file.readAll()));
|
||||
}
|
||||
|
||||
void CodeEditorDialog::save()
|
||||
{
|
||||
const auto path = QFileDialog::getSaveFileName(this, tr("Save Code to a Text File..."));
|
||||
if (path.isEmpty())
|
||||
return;
|
||||
|
||||
QFile file{path};
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate))
|
||||
{
|
||||
QMessageBox::warning(this, tr("Could not open file!"), tr("Could not open file!") + "\n\n" + file.errorString());
|
||||
return;
|
||||
}
|
||||
|
||||
auto asUtf8 = script().toUtf8();
|
||||
const auto size = asUtf8.size();
|
||||
if (const auto written = file.write(std::move(asUtf8)); written != size)
|
||||
{
|
||||
QMessageBox::warning(this, tr("Could not write file!"), tr("Could not write file!") + "\n\n" + tr("written(%0) != size(%1)") + "\n\n" + file.errorString());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void CodeEditorDialog::print()
|
||||
{
|
||||
|
||||
QMessageBox::warning(this, tr("Not yet implemented"), tr("Not yet implemented"));
|
||||
}
|
||||
|
||||
void CodeEditorDialog::updatePosition()
|
||||
|
||||
Reference in New Issue
Block a user