2023-02-28 15:05:26 +00:00
|
|
|
#include "srcedit_defaulttext.h"
|
2023-02-28 12:19:45 +00:00
|
|
|
#include "keywordshighlighter.h"
|
2022-11-18 23:47:32 +00:00
|
|
|
#include <QComboBox>
|
|
|
|
#include <QFont>
|
2022-11-22 03:42:48 +00:00
|
|
|
#include <QGridLayout>
|
2022-11-18 05:43:27 +00:00
|
|
|
#include <QMenu>
|
2022-11-22 03:42:48 +00:00
|
|
|
#include <QSpinBox>
|
2023-02-26 14:44:00 +00:00
|
|
|
#include <QTextStream>
|
2022-11-17 08:26:05 +00:00
|
|
|
|
|
|
|
using namespace Components;
|
|
|
|
using namespace Parse::Result;
|
2022-11-18 05:43:27 +00:00
|
|
|
using namespace Enhancement;
|
2022-11-18 23:47:32 +00:00
|
|
|
using namespace Core;
|
2022-11-17 08:26:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2023-03-17 13:58:38 +00:00
|
|
|
DefaultTextEdit:: DefaultTextEdit()
|
2023-02-26 14:44:00 +00:00
|
|
|
:edit_square(new QTextEdit){}
|
2022-11-17 08:26:05 +00:00
|
|
|
|
|
|
|
|
2023-03-17 13:58:38 +00:00
|
|
|
void DefaultTextEdit::modeReset(const QString &) const
|
2022-11-17 08:26:05 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-03-17 13:58:38 +00:00
|
|
|
QList<QString> DefaultTextEdit::modes() const
|
2022-11-17 08:26:05 +00:00
|
|
|
{
|
|
|
|
return QList<QString>() << "文本";
|
|
|
|
}
|
|
|
|
|
2023-03-17 13:58:38 +00:00
|
|
|
QString DefaultTextEdit::currentMode() const
|
2022-11-17 08:26:05 +00:00
|
|
|
{
|
|
|
|
return modes()[0];
|
|
|
|
}
|
|
|
|
|
2023-03-17 13:58:38 +00:00
|
|
|
void DefaultTextEdit::jumpTo(const QList<QString> &path)
|
2022-11-17 08:26:05 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-03-17 13:58:38 +00:00
|
|
|
MakeTools::FilePresent::Features DefaultTextEdit::features()
|
2023-03-05 14:32:20 +00:00
|
|
|
{
|
|
|
|
return Features();
|
|
|
|
}
|
|
|
|
|
2023-03-17 13:58:38 +00:00
|
|
|
std::tuple<bool, QString> DefaultTextEdit::create(const QDir &target, const QString &name, const QString &suffix)
|
2022-11-17 08:26:05 +00:00
|
|
|
{
|
2023-02-26 14:44:00 +00:00
|
|
|
auto x = target.filePath(QString("%1.%2").arg(name, suffix));
|
|
|
|
if(QFileInfo::exists(x))
|
|
|
|
return std::make_tuple(false, x);
|
2022-11-17 08:26:05 +00:00
|
|
|
|
2023-02-26 14:44:00 +00:00
|
|
|
QFile xf(x);
|
|
|
|
if(!xf.open(QIODevice::WriteOnly|QIODevice::Text))
|
|
|
|
throw new std::exception(QString("指定文件无法建立:" + x).toLocal8Bit());
|
2022-11-17 08:26:05 +00:00
|
|
|
|
2023-02-26 14:44:00 +00:00
|
|
|
return std::make_tuple(true, target.relativeFilePath(x));
|
2022-11-17 08:26:05 +00:00
|
|
|
}
|
|
|
|
|
2023-03-17 13:58:38 +00:00
|
|
|
MakeTools::FilePresent * DefaultTextEdit::newInst() const
|
2022-11-25 07:30:33 +00:00
|
|
|
{
|
2023-03-17 13:58:38 +00:00
|
|
|
return new DefaultTextEdit();
|
2022-11-25 07:30:33 +00:00
|
|
|
}
|
|
|
|
|
2023-03-17 13:58:38 +00:00
|
|
|
void DefaultTextEdit::applySetting(const QString &name, Core::AppCore *core)
|
2022-11-17 08:26:05 +00:00
|
|
|
{
|
2023-02-26 14:44:00 +00:00
|
|
|
name_store = name;
|
2022-11-25 07:30:33 +00:00
|
|
|
}
|
|
|
|
|
2023-03-17 13:58:38 +00:00
|
|
|
QString DefaultTextEdit::name() const
|
2023-01-01 05:10:31 +00:00
|
|
|
{
|
2023-02-26 14:44:00 +00:00
|
|
|
return name_store;
|
2023-01-01 05:10:31 +00:00
|
|
|
}
|
|
|
|
|
2023-03-17 13:58:38 +00:00
|
|
|
void DefaultTextEdit::load(const QFileInfo &target_file)
|
2022-11-25 07:30:33 +00:00
|
|
|
{
|
2023-02-26 14:44:00 +00:00
|
|
|
if(!target_file.exists())
|
|
|
|
throw new std::exception(QString("指定文件未找到:%1").arg(target_file.absoluteFilePath()).toLocal8Bit());
|
2022-11-25 07:30:33 +00:00
|
|
|
|
2023-02-26 14:44:00 +00:00
|
|
|
target_file_path = target_file.canonicalFilePath();
|
|
|
|
QFile bin(target_file_path);
|
|
|
|
if(!bin.open(QIODevice::ReadOnly | QIODevice::Text))
|
|
|
|
throw new std::exception(QString("指定文件无法打开:%1").arg(target_file.absoluteFilePath()).toLocal8Bit());
|
2022-11-25 07:30:33 +00:00
|
|
|
|
2023-02-26 14:44:00 +00:00
|
|
|
QTextStream tin(&bin);
|
|
|
|
tin.setCodec("UTF-8");
|
|
|
|
auto content = tin.readAll();
|
|
|
|
this->edit_square->setText(content);
|
2022-11-17 08:26:05 +00:00
|
|
|
}
|
|
|
|
|
2023-03-17 13:58:38 +00:00
|
|
|
void DefaultTextEdit::saveAs(const QString &path)
|
2022-11-25 01:18:54 +00:00
|
|
|
{
|
2023-02-26 14:44:00 +00:00
|
|
|
if(!path.isEmpty())
|
|
|
|
target_file_path = path;
|
2022-11-25 01:18:54 +00:00
|
|
|
|
2023-02-26 14:44:00 +00:00
|
|
|
QFile bout(target_file_path);
|
|
|
|
if(!bout.open(QIODevice::WriteOnly|QIODevice::Text))
|
|
|
|
throw new std::exception(QString("指定文件无法打开:%1").arg(target_file_path).toLocal8Bit());
|
2022-11-25 01:18:54 +00:00
|
|
|
|
2023-02-26 14:44:00 +00:00
|
|
|
QTextStream tout(&bout);
|
|
|
|
tout.setCodec("UTF-8");
|
|
|
|
tout << this->edit_square->toPlainText();
|
|
|
|
tout.flush();
|
2022-11-17 08:26:05 +00:00
|
|
|
}
|
|
|
|
|
2023-03-17 13:58:38 +00:00
|
|
|
QString DefaultTextEdit::relativeTargetPath(const QDir &base) const
|
2022-11-17 08:26:05 +00:00
|
|
|
{
|
2023-02-26 14:44:00 +00:00
|
|
|
if(target_file_path == "")
|
|
|
|
return "";
|
2022-11-17 08:26:05 +00:00
|
|
|
|
2023-02-26 14:44:00 +00:00
|
|
|
return base.relativeFilePath(target_file_path);
|
2022-11-17 08:26:05 +00:00
|
|
|
}
|
|
|
|
|
2023-03-17 13:58:38 +00:00
|
|
|
bool DefaultTextEdit::isModified() const
|
2022-11-18 23:47:32 +00:00
|
|
|
{
|
2023-02-26 14:44:00 +00:00
|
|
|
return true;
|
2022-11-18 23:47:32 +00:00
|
|
|
}
|
|
|
|
|
2023-03-17 13:58:38 +00:00
|
|
|
QList<QString> DefaultTextEdit::suffixes() const
|
2022-11-18 23:47:32 +00:00
|
|
|
{
|
2023-02-26 14:44:00 +00:00
|
|
|
return QStringList() << "txt" << "*";
|
2022-11-18 23:47:32 +00:00
|
|
|
}
|
|
|
|
|
2023-03-17 13:58:38 +00:00
|
|
|
QString DefaultTextEdit::absoluteTargetPath() const
|
2022-11-18 23:47:32 +00:00
|
|
|
{
|
2023-02-26 14:44:00 +00:00
|
|
|
return target_file_path;
|
2022-11-18 23:47:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-17 13:58:38 +00:00
|
|
|
QWidget * DefaultTextEdit::widget() const
|
2022-11-18 23:47:32 +00:00
|
|
|
{
|
2023-02-26 14:44:00 +00:00
|
|
|
return edit_square;
|
2022-11-18 23:47:32 +00:00
|
|
|
}
|