165 lines
4.4 KiB
C++
165 lines
4.4 KiB
C++
|
|
|||
|
#pragma execution_character_set("utf-8")
|
|||
|
#include "CodeDisplayView.h"
|
|||
|
#include <QVBoxLayout>
|
|||
|
#include "Base.h"
|
|||
|
#include "SysManager.h"
|
|||
|
#include <QFileinfo>
|
|||
|
#include <QProcess>
|
|||
|
#include <QDesktopServices>
|
|||
|
|
|||
|
CodeDisplayView::CodeDisplayView(QWidget* parent)
|
|||
|
: QDialog(parent)
|
|||
|
{
|
|||
|
_webView = new WebEngineView(QUrl(BaseUrl + "#/codedisplay"), this);
|
|||
|
|
|||
|
QVBoxLayout* layout = new QVBoxLayout();
|
|||
|
layout->setContentsMargins(0, 0, 0, 0);
|
|||
|
setLayout(layout);
|
|||
|
layout->addWidget(_webView);
|
|||
|
|
|||
|
_eventModule = new SignalEventModule("CodeDisplayView");
|
|||
|
QObject::connect(_eventModule, &SignalEventModule::onmessage, this, &CodeDisplayView::onMessage);
|
|||
|
_webView->addEventModule(_eventModule);
|
|||
|
#ifdef Q_OS_WIN
|
|||
|
_frameless = std::move(std::unique_ptr<QFramelessHelper>(new QFramelessHelper(this, _webView, true, (QDialog*)this)));
|
|||
|
#endif
|
|||
|
}
|
|||
|
|
|||
|
CodeDisplayView::~CodeDisplayView()
|
|||
|
{
|
|||
|
}
|
|||
|
void CodeDisplayView::Close()
|
|||
|
{
|
|||
|
this->close();
|
|||
|
}
|
|||
|
|
|||
|
bool CodeDisplayView::onMessage(const std::string& eventName, json& parameter)
|
|||
|
{
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("CodeDisplayView receive message.......");
|
|||
|
LOG(INFO) << eventName;
|
|||
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|||
|
TRY{
|
|||
|
if (eventName == "close") {
|
|||
|
Close();
|
|||
|
return true;
|
|||
|
}
|
|||
|
else if (eventName == "opened") {
|
|||
|
updateFileList();
|
|||
|
return true;
|
|||
|
}
|
|||
|
else if (eventName == "open-file")
|
|||
|
{
|
|||
|
//Դ<><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
openCurFile(parameter);
|
|||
|
return true;
|
|||
|
}
|
|||
|
else if (eventName == "save-code-file")
|
|||
|
{
|
|||
|
saveCodeFile(parameter);
|
|||
|
}
|
|||
|
else if (eventName == "open-directory")
|
|||
|
{
|
|||
|
openDir(parameter);
|
|||
|
}
|
|||
|
}
|
|||
|
CATCH(parameter);
|
|||
|
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
|
|||
|
bool CodeDisplayView::nativeEvent(const QByteArray& eventType, void* message, qintptr* result)
|
|||
|
#else
|
|||
|
bool CodeDisplayView::nativeEvent(const QByteArray& eventType, void* message, long* result)
|
|||
|
#endif
|
|||
|
{
|
|||
|
if (_frameless && _frameless->nativeEvent(eventType, message, result))
|
|||
|
return true;
|
|||
|
return QDialog::nativeEvent(eventType, message, result);
|
|||
|
}
|
|||
|
void CodeDisplayView::updateFileList()
|
|||
|
{
|
|||
|
//std::vector<std::string> clist;
|
|||
|
//for (auto j : cfileList)
|
|||
|
//{
|
|||
|
// QFileInfo fileInfo(j);
|
|||
|
// clist.push_back(fileInfo.fileName().toStdString());
|
|||
|
//}
|
|||
|
|
|||
|
json data;
|
|||
|
data["CFileList"] = json::array();
|
|||
|
data["NetFileList"] = json::array();
|
|||
|
for (auto j : cfileList)
|
|||
|
{
|
|||
|
QFileInfo fileInfo(j);
|
|||
|
data["CFileList"].push_back(fileInfo.fileName().toStdString());
|
|||
|
}
|
|||
|
for (auto i : netfileList)
|
|||
|
{
|
|||
|
QFileInfo fileInfo(i);
|
|||
|
data["NetFileList"].push_back(fileInfo.fileName().toStdString());
|
|||
|
}
|
|||
|
|
|||
|
_eventModule->send("update-filelist", data);
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("<EFBFBD><EFBFBD>ǰ<EFBFBD>˷<EFBFBD><EFBFBD><EFBFBD> update-filelist message.......");
|
|||
|
LOG(INFO) << CommonHelper::jsonToString(data);
|
|||
|
}
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD>ļ<EFBFBD>
|
|||
|
void CodeDisplayView::openCurFile(json& parameter)
|
|||
|
{
|
|||
|
auto data = parameter["data"];
|
|||
|
QString filePath = CommonHelper::utf8ToQString(data["filePath"]);
|
|||
|
|
|||
|
SysManager& sysMgr = GetSysManager();
|
|||
|
QString fileFullPath = sysMgr._codeGeneratePath + "/" + filePath;
|
|||
|
// QTextCodec* codec = QTextCodec::codecForName("utf-8");
|
|||
|
QFile file(fileFullPath);
|
|||
|
if (file.open(QIODevice::ReadOnly))
|
|||
|
{
|
|||
|
QByteArray array = file.readAll();
|
|||
|
QString str = QString::fromLocal8Bit(array);
|
|||
|
parameter["response"] = CommonHelper::qstringToUtf8(str);
|
|||
|
file.close();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
LOG(ERROR) << CommonHelper::utf8ToStdString("CodeDisplayView::openCurFile<6C><65>openFile failed ");
|
|||
|
parameter["response"] = "";
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void CodeDisplayView::openDir(json& parameter)
|
|||
|
{
|
|||
|
auto data = parameter["data"];
|
|||
|
QString filename = CommonHelper::utf8ToQString(data["path"]);
|
|||
|
//<2F><><EFBFBD><EFBFBD>ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD>ɴ<EFBFBD><C9B4><EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7>λ<EFBFBD><CEBB>
|
|||
|
SysManager& sysMgr = GetSysManager();
|
|||
|
QString fileFullPath = sysMgr._codeGeneratePath + "/" + filename;
|
|||
|
|
|||
|
// QString folderPath = "D:/<2F><><EFBFBD><EFBFBD>db/DBConfig.dbp";
|
|||
|
QString cmd = QString("explorer.exe /select,%1").arg(fileFullPath.replace('/', '\\'));
|
|||
|
QProcess::startDetached(cmd);
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
void CodeDisplayView::saveCodeFile(json& parameter)
|
|||
|
{
|
|||
|
auto data = parameter["data"];
|
|||
|
QString content = CommonHelper::utf8ToQString(data["content"]);
|
|||
|
QString filename = CommonHelper::utf8ToQString(data["filePath"]);
|
|||
|
|
|||
|
SysManager& sysMgr = GetSysManager();
|
|||
|
QString fileFullPath = sysMgr._codeGeneratePath + "/" + filename;
|
|||
|
QFile sFile(fileFullPath);
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD>д<EFBFBD><D0B4>ֻд<D6BB><D0B4>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ļ<EFBFBD><C4BC>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD>Ŀ¼<C4BF>У<EFBFBD>
|
|||
|
if (!sFile.open(QIODevice::Truncate | QIODevice::WriteOnly | QIODevice::Text))
|
|||
|
printf("Open jsonfile failed!\n");
|
|||
|
|
|||
|
//д<><D0B4><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
sFile.write(content.toStdString().c_str());
|
|||
|
//<2F>ر<EFBFBD><D8B1>ļ<EFBFBD>
|
|||
|
sFile.close();
|
|||
|
}
|