feat: 完善插件系统和测试插件;更新上游组件;

This commit is contained in:
寂静的羽夏 2024-12-21 21:02:45 +08:00
parent 4a6febadf2
commit 542055796d
15 changed files with 840 additions and 275 deletions

@ -1 +1 @@
Subproject commit b3e7421d4a55ce85124db2e2ae712040cc758f0a
Subproject commit 147afda646faa0a8b10309dd2716b961bcb54051

2
3rdparty/json vendored

@ -1 +1 @@
Subproject commit a006a7a48bb30a247f0344b788c62c2806edd90b
Subproject commit 663058e7d18241338aec42846d4f77995275ccf6

2
3rdparty/qwindowkit vendored

@ -1 +1 @@
Subproject commit ba8e8a32fc6e909ad0a2c152e36b6660c01fdad5
Subproject commit 782a52020a9823bb7dc744ab20849f2558b64652

View File

@ -494,7 +494,7 @@ if(WINGHEX_USE_FRAMELESS)
QJsonModel
angelscript
nlohmann_json::nlohmann_json
qt${QT_VERSION_MAJOR}advanceddocking)
qtadvanceddocking-qt${QT_VERSION_MAJOR})
else()
target_link_libraries(
${CMAKE_PROJECT_NAME}
@ -511,7 +511,7 @@ else()
QJsonModel
angelscript
nlohmann_json::nlohmann_json
qt${QT_VERSION_MAJOR}advanceddocking)
qtadvanceddocking-qt${QT_VERSION_MAJOR})
endif()
target_include_directories(

View File

@ -128,7 +128,7 @@
<message>
<location filename="../testform.ui" line="97"/>
<location filename="../testform.ui" line="194"/>
<location filename="../testform.ui" line="521"/>
<location filename="../testform.ui" line="693"/>
<source>Text</source>
<translation> </translation>
</message>
@ -142,9 +142,9 @@
<location filename="../testform.ui" line="131"/>
<location filename="../testform.ui" line="228"/>
<location filename="../testform.ui" line="293"/>
<location filename="../testform.ui" line="344"/>
<location filename="../testform.ui" line="811"/>
<location filename="../testform.ui" line="972"/>
<location filename="../testform.ui" line="444"/>
<location filename="../testform.ui" line="983"/>
<location filename="../testform.ui" line="1144"/>
<source>Clear</source>
<translation></translation>
</message>
@ -155,7 +155,7 @@
</message>
<message>
<location filename="../testform.ui" line="184"/>
<location filename="../testform.ui" line="558"/>
<location filename="../testform.ui" line="730"/>
<source>Icon</source>
<translation></translation>
</message>
@ -166,151 +166,152 @@
</message>
<message>
<location filename="../testform.ui" line="305"/>
<source>EditorAttr</source>
<translation></translation>
</message>
<message>
<location filename="../testform.ui" line="369"/>
<source>Visible</source>
<translation></translation>
</message>
<message>
<location filename="../testform.ui" line="382"/>
<source>Invisible</source>
<translation></translation>
</message>
<message>
<location filename="../testform.ui" line="405"/>
<source>Controller</source>
<translation></translation>
</message>
<message>
<location filename="../testform.ui" line="356"/>
<location filename="../testform.ui" line="456"/>
<source>MutiFile</source>
<translation></translation>
</message>
<message>
<location filename="../testform.ui" line="368"/>
<source>Hangle</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../testform.ui" line="391"/>
<location filename="../testform.ui" line="480"/>
<source>Operation</source>
<translation type="unfinished"></translation>
<translation></translation>
</message>
<message>
<location filename="../testform.ui" line="403"/>
<source>NewFile</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../testform.ui" line="416"/>
<source>OpenFile</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../testform.ui" line="429"/>
<source>Switch</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../testform.ui" line="442"/>
<source>CloseAll</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../testform.ui" line="449"/>
<location filename="../testform.ui" line="621"/>
<source>Metadata</source>
<translation type="unfinished"></translation>
<translation></translation>
</message>
<message>
<location filename="../testform.ui" line="454"/>
<location filename="../testform.ui" line="626"/>
<source>BookMark</source>
<translation type="unfinished"></translation>
<translation></translation>
</message>
<message>
<location filename="../testform.ui" line="459"/>
<location filename="../testform.ui" line="490"/>
<location filename="../testform.ui" line="631"/>
<location filename="../testform.ui" line="662"/>
<source>MessageBox</source>
<translation></translation>
</message>
<message>
<location filename="../testform.ui" line="467"/>
<location filename="../testform.ui" line="504"/>
<location filename="../testform.ui" line="681"/>
<location filename="../testform.ui" line="639"/>
<location filename="../testform.ui" line="676"/>
<location filename="../testform.ui" line="853"/>
<source>Title</source>
<translation></translation>
</message>
<message>
<location filename="../testform.ui" line="538"/>
<location filename="../testform.ui" line="710"/>
<source>Buttons</source>
<translation></translation>
</message>
<message>
<location filename="../testform.ui" line="548"/>
<location filename="../testform.ui" line="720"/>
<source>DefaultButton</source>
<translation></translation>
</message>
<message>
<location filename="../testform.ui" line="659"/>
<location filename="../testform.ui" line="831"/>
<source>InputBox</source>
<translation></translation>
</message>
<message>
<location filename="../testform.ui" line="674"/>
<location filename="../testform.ui" line="846"/>
<source>Label</source>
<translation></translation>
</message>
<message>
<location filename="../testform.ui" line="710"/>
<location filename="../testform.ui" line="884"/>
<location filename="../testform.ui" line="1073"/>
<location filename="../testform.ui" line="311"/>
<location filename="../testform.ui" line="882"/>
<location filename="../testform.ui" line="1056"/>
<location filename="../testform.ui" line="1245"/>
<source>Type</source>
<translation></translation>
</message>
<message>
<location filename="../testform.ui" line="823"/>
<location filename="../testform.ui" line="469"/>
<source>Handle</source>
<translation></translation>
</message>
<message>
<location filename="../testform.ui" line="995"/>
<source>FileDialog</source>
<translation></translation>
</message>
<message>
<location filename="../testform.ui" line="838"/>
<location filename="../testform.ui" line="1010"/>
<source>Filter</source>
<translation></translation>
</message>
<message>
<location filename="../testform.ui" line="845"/>
<location filename="../testform.ui" line="998"/>
<location filename="../testform.ui" line="1017"/>
<location filename="../testform.ui" line="1170"/>
<source>Caption</source>
<translation></translation>
</message>
<message>
<location filename="../testform.ui" line="866"/>
<location filename="../testform.ui" line="1038"/>
<source>Options</source>
<translation></translation>
</message>
<message>
<location filename="../testform.ui" line="984"/>
<location filename="../testform.ui" line="1156"/>
<source>ColorDialog</source>
<translation></translation>
</message>
<message>
<location filename="../testform.ui" line="1012"/>
<location filename="../testform.ui" line="1184"/>
<source>Color</source>
<translation></translation>
</message>
<message>
<location filename="../testform.ui" line="1058"/>
<location filename="../testform.ui" line="1230"/>
<source>DataVisual</source>
<translation></translation>
</message>
<message>
<location filename="../testform.cpp" line="338"/>
<location filename="../testform.cpp" line="348"/>
<location filename="../testform.cpp" line="345"/>
<location filename="../testform.cpp" line="355"/>
<source>UpdateTextTreeError</source>
<translation></translation>
</message>
<message>
<location filename="../testform.cpp" line="363"/>
<location filename="../testform.cpp" line="370"/>
<source>UpdateTextListByModelError</source>
<translation></translation>
</message>
<message>
<location filename="../testform.cpp" line="373"/>
<location filename="../testform.cpp" line="380"/>
<source>UpdateTextTableByModelError</source>
<translation></translation>
</message>
<message>
<location filename="../testform.cpp" line="384"/>
<location filename="../testform.cpp" line="391"/>
<source>UpdateTextTreeByModelError</source>
<translation></translation>
</message>
<message>
<location filename="../testform.cpp" line="492"/>
<source>Choose</source>
<translation></translation>
</message>
</context>
<context>
<name>TestPlugin</name>

View File

@ -51,6 +51,7 @@ TestForm::TestForm(WingHex::IWingPlugin *plg, QWidget *parent)
initMsgBoxCheckedBtnCombo();
initMsgBoxIconCombo();
initFileDialogOps();
initFileHandleListWidget();
_click = std::bind(&TestForm::onDVClicked, this, std::placeholders::_1);
_dblclick =
@ -123,6 +124,12 @@ void TestForm::initFileDialogOps() {
}
}
void TestForm::initFileHandleListWidget() {
auto item = new QListWidgetItem(QStringLiteral("HexEditor_Current (-1)"));
item->setData(Qt::UserRole, int(-1));
ui->lwHandle->addItem(item);
}
QMessageBox::StandardButtons TestForm::getMsgButtons() const {
QMessageBox::StandardButtons buttons =
QMessageBox::StandardButton::NoButton;
@ -384,3 +391,140 @@ void TestForm::on_btnTextTreeByModel_clicked() {
tr("UpdateTextTreeByModelError"));
}
}
void TestForm::on_btnStatusVisible_clicked() {
if (ui->rbLockedFile->isChecked()) {
Q_UNUSED(emit _plg->controller.setLockedFile(true));
} else if (ui->rbAddressVisible->isChecked()) {
Q_UNUSED(emit _plg->controller.setAddressVisible(true));
} else if (ui->rbHeaderVisible->isChecked()) {
Q_UNUSED(emit _plg->controller.setHeaderVisible(true));
} else if (ui->rbKeepSize->isChecked()) {
Q_UNUSED(emit _plg->controller.setKeepSize(true));
} else if (ui->rbStringVisible->isChecked()) {
Q_UNUSED(emit _plg->controller.setStringVisible(true));
}
}
void TestForm::on_btnStatusInvisible_clicked() {
if (ui->rbLockedFile->isChecked()) {
Q_UNUSED(emit _plg->controller.setLockedFile(false));
} else if (ui->rbAddressVisible->isChecked()) {
Q_UNUSED(emit _plg->controller.setAddressVisible(false));
} else if (ui->rbHeaderVisible->isChecked()) {
Q_UNUSED(emit _plg->controller.setHeaderVisible(false));
} else if (ui->rbKeepSize->isChecked()) {
Q_UNUSED(emit _plg->controller.setKeepSize(false));
} else if (ui->rbStringVisible->isChecked()) {
Q_UNUSED(emit _plg->controller.setStringVisible(false));
}
}
void TestForm::on_btnSwitch_clicked() {
auto item = ui->lwHandle->currentItem();
auto handle = item->data(Qt::UserRole).toInt();
auto ret = emit _plg->controller.switchDocument(handle);
if (!ret) {
}
}
void TestForm::on_btnNewFile_clicked() {
auto h = emit _plg->controller.newFile();
if (h < 0) {
auto e = QMetaEnum::fromType<WingHex::ErrFile>();
emit _plg->msgbox.critical(this, QStringLiteral("Error"),
e.valueToKey(h));
} else {
auto item = new QListWidgetItem(QStringLiteral("NewFile (%1)").arg(h));
item->setData(Qt::UserRole, h);
ui->lwHandle->addItem(item);
}
}
void TestForm::on_btnOpenFile_clicked() {
auto filename =
emit _plg->filedlg.getOpenFileName(this, QStringLiteral("Test"));
if (filename.isEmpty()) {
return;
}
auto h = emit _plg->controller.openFile(filename);
if (h < 0) {
auto e = QMetaEnum::fromType<WingHex::ErrFile>();
emit _plg->msgbox.critical(this, QStringLiteral("Error"),
e.valueToKey(h));
} else {
auto item = new QListWidgetItem(QStringLiteral("%1 (%2)")
.arg(QFileInfo(filename).fileName())
.arg(h));
item->setData(Qt::UserRole, h);
ui->lwHandle->addItem(item);
}
}
void TestForm::on_btnOpenRegionFile_clicked() {
auto filename =
emit _plg->filedlg.getOpenFileName(this, QStringLiteral("Test"));
if (filename.isEmpty()) {
return;
}
auto h = emit _plg->controller.openWorkSpace(filename);
if (h < 0) {
auto e = QMetaEnum::fromType<WingHex::ErrFile>();
emit _plg->msgbox.critical(this, QStringLiteral("Error"),
e.valueToKey(h));
} else {
auto item = new QListWidgetItem(QStringLiteral("WS - %1 (%2)")
.arg(QFileInfo(filename).fileName())
.arg(h));
item->setData(Qt::UserRole, h);
ui->lwHandle->addItem(item);
}
}
void TestForm::on_btnOpenWorkSpace_clicked() {}
void TestForm::on_btnOpenDriver_clicked() {
auto drivers = emit _plg->reader.getStorageDrivers();
bool ok;
auto dr = emit _plg->inputbox.getItem(this, QStringLiteral("Test"),
tr("Choose"), drivers, 0, false, &ok);
if (!ok) {
return;
}
auto h = emit _plg->controller.openDriver(dr);
if (h < 0) {
auto e = QMetaEnum::fromType<WingHex::ErrFile>();
emit _plg->msgbox.critical(this, QStringLiteral("Error"),
e.valueToKey(h));
} else {
auto item =
new QListWidgetItem(QStringLiteral("%1 (%2)").arg(dr).arg(h));
item->setData(Qt::UserRole, h);
ui->lwHandle->addItem(item);
}
}
void TestForm::on_btnSaveFile_clicked() {}
void TestForm::on_btnSaveAsFile_clicked() {}
void TestForm::on_btnExportFile_clicked() {}
void TestForm::on_btnCloseFile_clicked() {
auto item = ui->lwHandle->currentItem();
auto handle = item->data(Qt::UserRole).toInt();
auto ret = emit _plg->controller.closeFile(handle);
if (ret == WingHex::ErrFile::Success) {
if (handle >= 0) {
ui->lwHandle->removeItemWidget(item);
delete item;
}
} else {
auto e = QMetaEnum::fromType<WingHex::ErrFile>();
emit _plg->msgbox.critical(this, QStringLiteral("Error"),
e.valueToKey(ret));
}
}

View File

@ -101,6 +101,30 @@ private slots:
void on_btnTextTreeByModel_clicked();
void on_btnStatusVisible_clicked();
void on_btnStatusInvisible_clicked();
void on_btnSwitch_clicked();
void on_btnNewFile_clicked();
void on_btnOpenFile_clicked();
void on_btnOpenRegionFile_clicked();
void on_btnOpenWorkSpace_clicked();
void on_btnOpenDriver_clicked();
void on_btnSaveFile_clicked();
void on_btnSaveAsFile_clicked();
void on_btnExportFile_clicked();
void on_btnCloseFile_clicked();
private:
void initLogCombo();
@ -114,6 +138,8 @@ private:
void initFileDialogOps();
void initFileHandleListWidget();
private:
QMessageBox::StandardButtons getMsgButtons() const;

View File

@ -23,7 +23,7 @@
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>2</number>
<number>4</number>
</property>
<widget class="QWidget" name="tab_2">
<attribute name="title">
@ -300,6 +300,106 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_12">
<attribute name="title">
<string>EditorAttr</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_21">
<item>
<widget class="QGroupBox" name="groupBox_8">
<property name="title">
<string>Type</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<property name="sizeConstraint">
<enum>QLayout::SetMinAndMaxSize</enum>
</property>
<item>
<widget class="QRadioButton" name="rbLockedFile">
<property name="text">
<string notr="true">LockedFile</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="rbKeepSize">
<property name="text">
<string notr="true">KeepSize</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="rbStringVisible">
<property name="text">
<string notr="true">StringVisible</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="rbAddressVisible">
<property name="text">
<string notr="true">AddressVisible</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="rbHeaderVisible">
<property name="text">
<string notr="true">HeaderVisible</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QPushButton" name="btnStatusVisible">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="text">
<string>Visible</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnStatusInvisible">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="text">
<string>Invisible</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_3">
<attribute name="title">
<string>Controller</string>
@ -355,94 +455,166 @@
<attribute name="title">
<string>MutiFile</string>
</attribute>
<widget class="QLabel" name="label_14">
<property name="geometry">
<rect>
<x>40</x>
<y>30</y>
<width>40</width>
<height>12</height>
</rect>
</property>
<property name="text">
<string>Hangle</string>
</property>
</widget>
<widget class="QListWidget" name="listWidget">
<property name="geometry">
<rect>
<x>40</x>
<y>50</y>
<width>211</width>
<height>191</height>
</rect>
</property>
</widget>
<widget class="QGroupBox" name="groupBox_7">
<property name="geometry">
<rect>
<x>290</x>
<y>30</y>
<width>241</width>
<height>211</height>
</rect>
</property>
<property name="title">
<string>Operation</string>
</property>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>20</x>
<y>60</y>
<width>171</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>NewFile</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_2">
<property name="geometry">
<rect>
<x>20</x>
<y>90</y>
<width>171</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>OpenFile</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_3">
<property name="geometry">
<rect>
<x>20</x>
<y>30</y>
<width>171</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>Switch</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_4">
<property name="geometry">
<rect>
<x>20</x>
<y>120</y>
<width>171</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>CloseAll</string>
</property>
</widget>
</widget>
<layout class="QVBoxLayout" name="verticalLayout_24">
<item>
<widget class="QSplitter" name="splitter_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QWidget" name="layoutWidget">
<layout class="QVBoxLayout" name="verticalLayout_23">
<item>
<widget class="QLabel" name="label_14">
<property name="text">
<string>Handle</string>
</property>
</widget>
</item>
<item>
<widget class="QListWidget" name="lwHandle"/>
</item>
</layout>
</widget>
<widget class="QGroupBox" name="groupBox_7">
<property name="title">
<string>Operation</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_22">
<item>
<widget class="QPushButton" name="btnSwitch">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="text">
<string notr="true">Switch</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnNewFile">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="text">
<string notr="true">NewFile</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnOpenFile">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="text">
<string notr="true">OpenFile</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnOpenRegionFile">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="text">
<string notr="true">OpenRegionFile</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnOpenWorkSpace">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="text">
<string notr="true">OpenWorkSpace</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnOpenDriver">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="text">
<string notr="true">OpenDriver</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnSaveFile">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="text">
<string notr="true">SaveFile</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnSaveAsFile">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="text">
<string notr="true">SaveAsFile</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnExportFile">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="text">
<string notr="true">ExportFile</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnCloseFile">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="text">
<string notr="true">Close</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_10">
<attribute name="title">

View File

@ -1613,12 +1613,12 @@
<translation></translation>
</message>
<message>
<location filename="../../src/dialog/mainwindow.cpp" line="3061"/>
<location filename="../../src/dialog/mainwindow.cpp" line="3074"/>
<source>ConfirmSave</source>
<translation></translation>
</message>
<message>
<location filename="../../src/dialog/mainwindow.cpp" line="3102"/>
<location filename="../../src/dialog/mainwindow.cpp" line="3115"/>
<source>ConfirmAPPSave</source>
<translation></translation>
</message>
@ -1992,57 +1992,62 @@
<translation></translation>
</message>
<message>
<location filename="../../src/plugin/pluginsystem.cpp" line="310"/>
<location filename="../../src/plugin/pluginsystem.cpp" line="217"/>
<source>RegisteredFnDup</source>
<translation></translation>
</message>
<message>
<location filename="../../src/plugin/pluginsystem.cpp" line="340"/>
<source>ErrLoadPluginSign</source>
<translation></translation>
</message>
<message>
<location filename="../../src/plugin/pluginsystem.cpp" line="314"/>
<location filename="../../src/plugin/pluginsystem.cpp" line="344"/>
<source>ErrLoadPluginSDKVersion</source>
<translation> SDK </translation>
</message>
<message>
<location filename="../../src/plugin/pluginsystem.cpp" line="318"/>
<location filename="../../src/plugin/pluginsystem.cpp" line="348"/>
<source>ErrLoadPluginNoName</source>
<translation></translation>
</message>
<message>
<location filename="../../src/plugin/pluginsystem.cpp" line="323"/>
<location filename="../../src/plugin/pluginsystem.cpp" line="353"/>
<source>ErrLoadLoadedPlugin</source>
<translation></translation>
</message>
<message>
<location filename="../../src/plugin/pluginsystem.cpp" line="343"/>
<location filename="../../src/plugin/pluginsystem.cpp" line="373"/>
<source>ErrLoadInitPlugin</source>
<translation></translation>
</message>
<message>
<location filename="../../src/plugin/pluginsystem.cpp" line="350"/>
<location filename="../../src/plugin/pluginsystem.cpp" line="380"/>
<source>PluginName :</source>
<translation></translation>
</message>
<message>
<location filename="../../src/plugin/pluginsystem.cpp" line="351"/>
<location filename="../../src/plugin/pluginsystem.cpp" line="381"/>
<source>PluginAuthor :</source>
<translation></translation>
</message>
<message>
<location filename="../../src/plugin/pluginsystem.cpp" line="352"/>
<location filename="../../src/plugin/pluginsystem.cpp" line="382"/>
<source>PluginWidgetRegister</source>
<translation></translation>
</message>
<message>
<location filename="../../src/plugin/pluginsystem.cpp" line="1878"/>
<source>Creating UI widget is not allowed in non-UI thread</source>
<translation>线</translation>
<location filename="../../src/plugin/pluginsystem.cpp" line="2060"/>
<source>Not allowed operation in non-UI thread</source>
<translation> UI 线</translation>
</message>
<message>
<location filename="../../src/plugin/pluginsystem.cpp" line="1929"/>
<location filename="../../src/plugin/pluginsystem.cpp" line="2111"/>
<source>FoundPluginCount</source>
<translation></translation>
</message>
<message>
<location filename="../../src/plugin/pluginsystem.cpp" line="1942"/>
<location filename="../../src/plugin/pluginsystem.cpp" line="2124"/>
<source>PluginLoadingFinished</source>
<translation></translation>
</message>
@ -2500,17 +2505,17 @@ Do you wish to keep up to date by reloading the file?</source>
<context>
<name>QObject</name>
<message>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="193"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="201"/>
<source>List All Tabs</source>
<translation></translation>
</message>
<message>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="204"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="212"/>
<source>Detach Group</source>
<translation></translation>
</message>
<message>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="231"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="239"/>
<source>Minimize</source>
<translation></translation>
</message>
@ -5065,42 +5070,42 @@ Do you wish to keep up to date by reloading the file?</source>
<context>
<name>ads::CAutoHideTab</name>
<message>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/AutoHideTab.cpp" line="383"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/AutoHideTab.cpp" line="394"/>
<source>Detach</source>
<translation></translation>
</message>
<message>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/AutoHideTab.cpp" line="388"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/AutoHideTab.cpp" line="399"/>
<source>Pin To...</source>
<translation></translation>
</message>
<message>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/AutoHideTab.cpp" line="390"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/AutoHideTab.cpp" line="401"/>
<source>Top</source>
<translation></translation>
</message>
<message>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/AutoHideTab.cpp" line="391"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/AutoHideTab.cpp" line="402"/>
<source>Left</source>
<translation></translation>
</message>
<message>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/AutoHideTab.cpp" line="392"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/AutoHideTab.cpp" line="403"/>
<source>Right</source>
<translation></translation>
</message>
<message>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/AutoHideTab.cpp" line="393"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/AutoHideTab.cpp" line="404"/>
<source>Bottom</source>
<translation></translation>
</message>
<message>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/AutoHideTab.cpp" line="395"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/AutoHideTab.cpp" line="406"/>
<source>Unpin (Dock)</source>
<translation></translation>
</message>
<message>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/AutoHideTab.cpp" line="397"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/AutoHideTab.cpp" line="408"/>
<source>Close</source>
<translation></translation>
</message>
@ -5108,83 +5113,83 @@ Do you wish to keep up to date by reloading the file?</source>
<context>
<name>ads::CDockAreaTitleBar</name>
<message>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="774"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="801"/>
<source>Detach</source>
<translation></translation>
</message>
<message>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="774"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="801"/>
<source>Detach Group</source>
<translation></translation>
</message>
<message>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="779"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="836"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="806"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="862"/>
<source>Unpin (Dock)</source>
<translation></translation>
</message>
<message>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="779"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="841"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="806"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="867"/>
<source>Pin Group</source>
<translation></translation>
</message>
<message>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="785"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="812"/>
<source>Pin Group To...</source>
<translation></translation>
</message>
<message>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="787"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="814"/>
<source>Top</source>
<translation></translation>
</message>
<message>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="788"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="815"/>
<source>Left</source>
<translation></translation>
</message>
<message>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="789"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="816"/>
<source>Right</source>
<translation></translation>
</message>
<message>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="790"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="817"/>
<source>Bottom</source>
<translation></translation>
</message>
<message>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="798"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="853"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="825"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="879"/>
<source>Minimize</source>
<translation></translation>
</message>
<message>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="799"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="803"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="853"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="826"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="830"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="879"/>
<source>Close</source>
<translation></translation>
</message>
<message>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="803"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="862"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="830"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="888"/>
<source>Close Group</source>
<translation></translation>
</message>
<message>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="809"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="836"/>
<source>Close Other Groups</source>
<translation></translation>
</message>
<message>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="845"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="871"/>
<source>Pin Active Tab (Press Ctrl to Pin Group)</source>
<translation> Ctrl </translation>
</message>
<message>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="858"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockAreaTitleBar.cpp" line="884"/>
<source>Close Active Tab</source>
<translation></translation>
</message>
@ -5192,7 +5197,7 @@ Do you wish to keep up to date by reloading the file?</source>
<context>
<name>ads::CDockManager</name>
<message>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockManager.cpp" line="513"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockManager.cpp" line="518"/>
<source>Show View</source>
<translation></translation>
</message>
@ -5200,47 +5205,47 @@ Do you wish to keep up to date by reloading the file?</source>
<context>
<name>ads::CDockWidgetTab</name>
<message>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockWidgetTab.cpp" line="543"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockWidgetTab.cpp" line="551"/>
<source>Detach</source>
<translation></translation>
</message>
<message>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockWidgetTab.cpp" line="547"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockWidgetTab.cpp" line="555"/>
<source>Pin</source>
<translation></translation>
</message>
<message>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockWidgetTab.cpp" line="551"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockWidgetTab.cpp" line="559"/>
<source>Pin To...</source>
<translation></translation>
</message>
<message>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockWidgetTab.cpp" line="553"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockWidgetTab.cpp" line="561"/>
<source>Top</source>
<translation></translation>
</message>
<message>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockWidgetTab.cpp" line="554"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockWidgetTab.cpp" line="562"/>
<source>Left</source>
<translation></translation>
</message>
<message>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockWidgetTab.cpp" line="555"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockWidgetTab.cpp" line="563"/>
<source>Right</source>
<translation></translation>
</message>
<message>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockWidgetTab.cpp" line="556"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockWidgetTab.cpp" line="564"/>
<source>Bottom</source>
<translation></translation>
</message>
<message>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockWidgetTab.cpp" line="561"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockWidgetTab.cpp" line="569"/>
<source>Close</source>
<translation></translation>
</message>
<message>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockWidgetTab.cpp" line="565"/>
<location filename="../../3rdparty/Qt-Advanced-Docking-System/src/DockWidgetTab.cpp" line="573"/>
<source>Close Others</source>
<translation></translation>
</message>

View File

@ -1115,7 +1115,7 @@ void WingAngelAPI::installHexControllerAPI(asIScriptEngine *engine) {
registerAPI<void()>(
engine,
std::bind(&WingHex::WingPlugin::Controller::closeAllPluginFiles, ctl),
"void closeAllPluginFiles()");
"bool closeAllPluginFiles()");
engine->SetDefaultNamespace("");
}

View File

@ -347,7 +347,7 @@ void MainWindow::buildUpDockSystem(QWidget *container) {
qApp->processEvents();
CDockWidget *CentralDockWidget =
new CDockWidget(QStringLiteral("CentralWidget"));
m_dock->createDockWidget(QStringLiteral("CentralWidget"));
CentralDockWidget->setWidget(label);
CentralDockWidget->setFeature(ads::CDockWidget::DockWidgetFocusable, false);
CentralDockWidget->setFeature(ads::CDockWidget::NoTab, true);
@ -2517,7 +2517,7 @@ ads::CDockWidget *MainWindow::buildDockWidget(ads::CDockManager *dock,
QWidget *content,
ToolButtonIndex index) {
using namespace ads;
auto dw = new CDockWidget(displayName, dock);
auto dw = dock->createDockWidget(displayName, dock);
dw->setObjectName(widgetName);
dw->setFeatures(CDockWidget::DockWidgetMovable |
CDockWidget::DockWidgetClosable |
@ -2775,10 +2775,10 @@ void MainWindow::openFiles(const QStringList &files) {
ErrFile MainWindow::openFile(const QString &file, EditorView **editor) {
auto e = findEditorView(file);
if (editor) {
*editor = e;
}
if (e) {
if (editor) {
*editor = e;
}
return ErrFile::AlreadyOpened;
}
@ -2800,16 +2800,19 @@ ErrFile MainWindow::openFile(const QString &file, EditorView **editor) {
m_views.insert(ev, QString());
registerEditorView(ev);
if (editor) {
*editor = ev;
}
m_dock->addDockWidget(ads::CenterDockWidgetArea, ev, editorViewArea());
return ErrFile::Success;
}
ErrFile MainWindow::openDriver(const QString &driver, EditorView **editor) {
auto e = findEditorView(driver);
if (editor) {
*editor = e;
}
if (e) {
if (editor) {
*editor = e;
}
return ErrFile::AlreadyOpened;
}
@ -2828,16 +2831,20 @@ ErrFile MainWindow::openDriver(const QString &driver, EditorView **editor) {
m_views.insert(ev, QString());
registerEditorView(ev);
if (editor) {
*editor = ev;
}
m_dock->addDockWidget(ads::CenterDockWidgetArea, ev, editorViewArea());
return ErrFile::Success;
}
ErrFile MainWindow::openWorkSpace(const QString &file, EditorView **editor) {
auto e = findEditorView(file);
if (editor) {
*editor = e;
}
if (e) {
if (editor) {
*editor = e;
}
return ErrFile::AlreadyOpened;
}
@ -2859,6 +2866,9 @@ ErrFile MainWindow::openWorkSpace(const QString &file, EditorView **editor) {
m_views.insert(ev, file);
registerEditorView(ev);
if (editor) {
*editor = ev;
}
m_dock->addDockWidget(ads::CenterDockWidgetArea, ev, editorViewArea());
return ErrFile::Success;
}
@ -2866,10 +2876,10 @@ ErrFile MainWindow::openWorkSpace(const QString &file, EditorView **editor) {
ErrFile MainWindow::openRegionFile(QString file, EditorView **editor,
qsizetype start, qsizetype length) {
auto e = findEditorView(file);
if (editor) {
*editor = e;
}
if (e) {
if (editor) {
*editor = e;
}
return ErrFile::AlreadyOpened;
}
@ -2890,6 +2900,9 @@ ErrFile MainWindow::openRegionFile(QString file, EditorView **editor,
}
registerEditorView(ev);
if (editor) {
*editor = ev;
}
m_dock->addDockWidget(ads::CenterDockWidgetArea, ev, editorViewArea());
return ErrFile::Success;
}

View File

@ -16,9 +16,9 @@
*/
#include "scriptingdialog.h"
#include "DockSplitter.h"
#include "QWingRibbon/ribbontabcontent.h"
#include "Qt-Advanced-Docking-System/src/DockAreaWidget.h"
#include "Qt-Advanced-Docking-System/src/DockSplitter.h"
#include "aboutsoftwaredialog.h"
#include "class/langservice.h"
#include "class/languagemanager.h"
@ -679,7 +679,7 @@ void ScriptingDialog::buildUpDockSystem(QWidget *container) {
label->setPicture(backimg);
label->setAlignment(Qt::AlignCenter);
CDockWidget *CentralDockWidget =
new CDockWidget(QStringLiteral("CentralWidget"));
m_dock->createDockWidget(QStringLiteral("CentralWidget"));
CentralDockWidget->setWidget(label);
CentralDockWidget->setFeature(ads::CDockWidget::DockWidgetFocusable, false);
CentralDockWidget->setFeature(ads::CDockWidget::NoTab, true);
@ -730,7 +730,7 @@ ads::CDockWidget *ScriptingDialog::buildDockWidget(ads::CDockManager *dock,
QWidget *content,
ToolButtonIndex index) {
using namespace ads;
auto dw = new CDockWidget(displayName, dock);
auto dw = dock->createDockWidget(displayName, dock);
dw->setObjectName(widgetName);
dw->setFeatures(CDockWidget::DockWidgetMovable |
CDockWidget::DockWidgetClosable |

View File

@ -75,7 +75,8 @@ enum ErrFile : int {
SourceFileChanged = -9,
ClonedFile = -10,
InvalidFormat = -11,
TooManyOpenedFile = -12
TooManyOpenedFile = -12,
NotAllowedInNoneGUIThread = -13
};
Q_ENUM_NS(ErrFile)
@ -287,7 +288,7 @@ signals:
Q_REQUIRED_RESULT bool setCurrentEncoding(const QString &encoding);
// extension
void closeAllPluginFiles();
bool closeAllPluginFiles();
};
class MessageBox : public QObject {

View File

@ -112,38 +112,33 @@ EditorView *PluginSystem::handle2EditorView(IWingPlugin *plg, int handle) {
return nullptr;
}
PluginSystem::UniqueId
PluginSystem::SharedUniqueId
PluginSystem::assginHandleForPluginView(IWingPlugin *plg, EditorView *view) {
if (plg == nullptr || view == nullptr) {
return {};
}
if (m_plgHandles.contains(plg)) {
auto id = m_idGen.get();
m_plgHandles[plg].append(qMakePair(id, view));
m_viewBindings[view].append(plg);
return id;
}
return {};
auto id = m_idGen.get();
m_plgHandles[plg].append(qMakePair(id, view));
m_viewBindings[view].append(plg);
return id;
}
bool PluginSystem::checkPluginCanOpenedFile(IWingPlugin *plg) {
if (plg == nullptr) {
return false;
}
if (m_plgHandles.contains(plg)) {
return m_plgHandles.value(plg).size() <= RAND_MAX;
}
return false;
return m_plgHandles[plg].size() <= UCHAR_MAX;
}
bool PluginSystem::checkPluginHasAlreadyOpened(IWingPlugin *plg,
EditorView *view) {
auto &maps = m_plgHandles[plg];
auto ret =
std::find_if(maps.begin(), maps.end(),
[view](const QPair<UniqueId, EditorView *> &content) {
return content.second == view;
});
auto ret = std::find_if(
maps.begin(), maps.end(),
[view](const QPair<SharedUniqueId, EditorView *> &content) {
return content.second == view;
});
return ret != maps.end();
}
@ -171,6 +166,41 @@ void PluginSystem::cleanUpEditorViewHandle(EditorView *view) {
}
}
bool PluginSystem::closeEditor(IWingPlugin *plg, int handle, bool force) {
if (handle >= 0) {
auto &handles = m_plgHandles[plg];
auto r = std::find_if(
handles.begin(), handles.end(),
[handle](const QPair<SharedUniqueId, EditorView *> &d) {
return (*d.first) == handle;
});
if (r == handles.end()) {
return false;
}
auto &bind = m_viewBindings[r->second];
bind.removeOne(plg);
if (bind.isEmpty()) {
_win->closeEditor(r->second, force);
}
} else {
if (_win->m_curEditor == nullptr) {
return false;
}
auto &bind = m_viewBindings[_win->m_curEditor];
bind.removeOne(plg);
if (bind.isEmpty()) {
_win->closeEditor(_win->m_curEditor, force);
}
}
m_plgviewMap.remove(plg);
m_plgHandles.remove(plg);
return true;
}
void PluginSystem::registerFns(IWingPlugin *plg) {
Q_ASSERT(plg);
auto fns = plg->registeredScriptFn();
@ -184,7 +214,7 @@ void PluginSystem::registerFns(IWingPlugin *plg) {
auto &fn = p->second;
auto sig = getScriptFnSig(p->first, fn);
if (rfns.find(sig) != rfns.end()) {
Logger::warning(tr(""));
Logger::warning(tr("RegisteredFnDup"));
continue;
}
rfns.insert(sig, p->second);
@ -508,6 +538,9 @@ void PluginSystem::connectLoadingInterface(IWingPlugin *plg) {
void PluginSystem::connectBaseInterface(IWingPlugin *plg) {
connect(plg, &IWingPlugin::toast, this,
[=](const QPixmap &icon, const QString &message) {
if (!checkThreadAff()) {
return;
}
if (message.isEmpty()) {
return;
}
@ -532,6 +565,9 @@ void PluginSystem::connectBaseInterface(IWingPlugin *plg) {
});
connect(plg, &IWingPlugin::createDialog, this,
[=](QWidget *w) -> QDialog * {
if (!checkThreadAff()) {
return nullptr;
}
if (w) {
auto d = new FramelessDialogBase;
d->buildUpContent(w);
@ -752,7 +788,9 @@ void PluginSystem::connectReaderInterface(IWingPlugin *plg) {
[=](qsizetype offset, qsizetype len) -> QByteArray {
auto e = pluginCurrentEditor(plg);
if (e) {
return e->hexEditor()->document()->read(offset, len);
_rwlock.lockForRead();
auto ret = e->hexEditor()->document()->read(offset, len);
return ret;
}
return {};
});
@ -785,6 +823,7 @@ void PluginSystem::connectReaderInterface(IWingPlugin *plg) {
[=](qsizetype offset, const QString &encoding) -> QString {
auto e = pluginCurrentEditor(plg);
if (e) {
_rwlock.lockForRead();
auto hexeditor = e->hexEditor();
auto doc = hexeditor->document();
auto render = hexeditor->renderer();
@ -802,6 +841,7 @@ void PluginSystem::connectReaderInterface(IWingPlugin *plg) {
enco = render->encoding();
}
_rwlock.unlock();
return toByteArray(buffer, enco);
}
return QString();
@ -905,6 +945,9 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
auto pctl = &plg->controller;
connect(pctl, &WingPlugin::Controller::switchDocument, _win,
[=](int handle) -> bool {
if (!checkThreadAff()) {
return false;
}
if (handle < 0) {
m_plgviewMap[plg] = nullptr;
} else {
@ -923,6 +966,10 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
});
connect(pctl, &WingPlugin::Controller::raiseDocument, _win,
[=](int handle) -> bool {
if (!checkThreadAff()) {
return false;
}
if (handle < 0) {
auto cur = _win->m_curEditor;
if (cur) {
@ -946,6 +993,9 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
});
connect(pctl, &WingPlugin::Controller::setLockedFile, _win,
[=](bool b) -> bool {
if (!checkThreadAff()) {
return false;
}
auto e = pluginCurrentEditor(plg);
if (e) {
return e->hexEditor()->document()->setLockedFile(b);
@ -954,6 +1004,9 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
});
connect(pctl, &WingPlugin::Controller::setKeepSize, _win,
[=](bool b) -> bool {
if (!checkThreadAff()) {
return false;
}
auto e = pluginCurrentEditor(plg);
if (e) {
return e->hexEditor()->document()->setKeepSize(b);
@ -962,6 +1015,9 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
});
connect(pctl, &WingPlugin::Controller::setStringVisible, _win,
[=](bool b) -> bool {
if (!checkThreadAff()) {
return false;
}
auto e = pluginCurrentEditor(plg);
if (e) {
e->hexEditor()->setAsciiVisible(b);
@ -971,6 +1027,9 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
});
connect(pctl, &WingPlugin::Controller::setHeaderVisible, _win,
[=](bool b) -> bool {
if (!checkThreadAff()) {
return false;
}
auto e = pluginCurrentEditor(plg);
if (e) {
e->hexEditor()->setHeaderVisible(b);
@ -980,6 +1039,9 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
});
connect(pctl, &WingPlugin::Controller::setAddressVisible, _win,
[=](bool b) -> bool {
if (!checkThreadAff()) {
return false;
}
auto e = pluginCurrentEditor(plg);
if (e) {
e->hexEditor()->setAddressVisible(b);
@ -989,6 +1051,9 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
});
connect(pctl, &WingPlugin::Controller::setAddressBase, _win,
[=](quintptr base) -> bool {
if (!checkThreadAff()) {
return false;
}
auto e = pluginCurrentEditor(plg);
if (e) {
e->hexEditor()->setAddressBase(base);
@ -1000,7 +1065,10 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
[=](qsizetype offset, const QByteArray &data) -> bool {
auto e = pluginCurrentEditor(plg);
if (e) {
return e->hexEditor()->document()->insert(offset, data);
_rwlock.lockForWrite();
auto ret = e->hexEditor()->document()->insert(offset, data);
_rwlock.unlock();
return ret;
}
return false;
});
@ -1008,7 +1076,11 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
[=](qsizetype offset, const QByteArray &data) -> bool {
auto e = pluginCurrentEditor(plg);
if (e) {
return e->hexEditor()->document()->replace(offset, data);
_rwlock.lockForWrite();
auto ret =
e->hexEditor()->document()->replace(offset, data);
_rwlock.unlock();
return ret;
}
return false;
});
@ -1053,7 +1125,11 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
}
auto unicode = toByteArray(value, enco);
return doc->insert(offset, unicode);
_rwlock.lockForWrite();
auto ret = doc->insert(offset, unicode);
_rwlock.unlock();
return ret;
}
return false;
});
@ -1098,7 +1174,10 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
}
auto unicode = toByteArray(value, enco);
return doc->replace(offset, unicode);
_rwlock.lockForWrite();
auto ret = doc->replace(offset, unicode);
_rwlock.unlock();
return ret;
}
return false;
});
@ -1142,7 +1221,10 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
}
auto unicode = toByteArray(value, enco);
return doc->insert(offset, unicode);
_rwlock.lockForWrite();
auto ret = doc->insert(offset, unicode);
_rwlock.unlock();
return ret;
}
return false;
});
@ -1152,7 +1234,10 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
auto e = pluginCurrentEditor(plg);
if (e) {
auto doc = e->hexEditor()->document();
return doc->remove(offset, len);
_rwlock.lockForWrite();
auto ret = doc->remove(offset, len);
_rwlock.unlock();
return ret;
}
return false;
});
@ -1161,7 +1246,10 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
if (e) {
auto doc = e->hexEditor()->document();
auto len = doc->length();
return doc->remove(0, len);
_rwlock.lockForWrite();
auto ret = doc->remove(0, len);
_rwlock.unlock();
return ret;
}
return false;
});
@ -1171,6 +1259,9 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
_win,
[=](qsizetype line, qsizetype column, int nibbleindex,
bool clearSelection) -> bool {
if (!checkThreadAff()) {
return false;
}
auto e = pluginCurrentEditor(plg);
if (e) {
e->hexEditor()->cursor()->moveTo(line, column, nibbleindex,
@ -1182,6 +1273,9 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
connect(pctl,
QOverload<qsizetype, bool>::of(&WingPlugin::Controller::moveTo),
_win, [=](qsizetype offset, bool clearSelection) -> bool {
if (!checkThreadAff()) {
return false;
}
auto e = pluginCurrentEditor(plg);
if (e) {
e->hexEditor()->cursor()->moveTo(offset, clearSelection);
@ -1192,6 +1286,9 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
connect(
pctl, &WingPlugin::Controller::select, _win,
[=](qsizetype offset, qsizetype length, SelectionMode mode) -> bool {
if (!checkThreadAff()) {
return false;
}
auto e = pluginCurrentEditor(plg);
if (e) {
auto cursor = e->hexEditor()->cursor();
@ -1215,6 +1312,9 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
});
connect(pctl, &WingPlugin::Controller::setInsertionMode, _win,
[=](bool isinsert) -> bool {
if (!checkThreadAff()) {
return false;
}
auto e = pluginCurrentEditor(plg);
if (e) {
e->hexEditor()->cursor()->setInsertionMode(
@ -1230,6 +1330,9 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
_win,
[=](qsizetype begin, qusizetype length, const QColor &fgcolor,
const QColor &bgcolor, const QString &comment) -> bool {
if (!checkThreadAff()) {
return false;
}
auto e = pluginCurrentEditor(plg);
if (e) {
auto doc = e->hexEditor()->document();
@ -1244,6 +1347,9 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
_win,
[=](qsizetype begin, qusizetype length, const QColor &fgcolor,
const QColor &bgcolor, const QString &comment) -> bool {
if (!checkThreadAff()) {
return false;
}
auto e = pluginCurrentEditor(plg);
if (e) {
auto doc = e->hexEditor()->document();
@ -1254,6 +1360,9 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
});
connect(pctl, &WingPlugin::Controller::removeMetadata, _win,
[=](qsizetype offset) -> bool {
if (!checkThreadAff()) {
return false;
}
auto e = pluginCurrentEditor(plg);
if (e) {
auto doc = e->hexEditor()->document();
@ -1263,6 +1372,9 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
return false;
});
connect(pctl, &WingPlugin::Controller::clearMetadata, _win, [=]() -> bool {
if (!checkThreadAff()) {
return false;
}
auto e = pluginCurrentEditor(plg);
if (e) {
auto doc = e->hexEditor()->document();
@ -1274,6 +1386,9 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
connect(pctl, &WingPlugin::Controller::comment, _win,
[=](qsizetype begin, qusizetype length,
const QString &comment) -> bool {
if (!checkThreadAff()) {
return false;
}
auto e = pluginCurrentEditor(plg);
if (e) {
auto doc = e->hexEditor()->document();
@ -1285,6 +1400,9 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
connect(
pctl, &WingPlugin::Controller::foreground, _win,
[=](qsizetype begin, qusizetype length, const QColor &fgcolor) -> bool {
if (!checkThreadAff()) {
return false;
}
auto e = pluginCurrentEditor(plg);
if (e) {
auto doc = e->hexEditor()->document();
@ -1296,6 +1414,9 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
connect(
pctl, &WingPlugin::Controller::background, _win,
[=](qsizetype begin, qusizetype length, const QColor &bgcolor) -> bool {
if (!checkThreadAff()) {
return false;
}
auto e = pluginCurrentEditor(plg);
if (e) {
auto doc = e->hexEditor()->document();
@ -1306,6 +1427,9 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
});
connect(pctl, &WingPlugin::Controller::setMetaVisible, _win,
[=](bool b) -> bool {
if (!checkThreadAff()) {
return false;
}
auto e = pluginCurrentEditor(plg);
if (e) {
auto doc = e->hexEditor()->document();
@ -1318,6 +1442,9 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
});
connect(pctl, &WingPlugin::Controller::setMetafgVisible, _win,
[=](bool b) -> bool {
if (!checkThreadAff()) {
return false;
}
auto e = pluginCurrentEditor(plg);
if (e) {
auto doc = e->hexEditor()->document();
@ -1328,6 +1455,9 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
});
connect(pctl, &WingPlugin::Controller::setMetabgVisible, _win,
[=](bool b) -> bool {
if (!checkThreadAff()) {
return false;
}
auto e = pluginCurrentEditor(plg);
if (e) {
auto doc = e->hexEditor()->document();
@ -1338,6 +1468,9 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
});
connect(pctl, &WingPlugin::Controller::setMetaCommentVisible, _win,
[=](bool b) -> bool {
if (!checkThreadAff()) {
return false;
}
auto e = pluginCurrentEditor(plg);
if (e) {
auto doc = e->hexEditor()->document();
@ -1348,6 +1481,9 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
});
connect(pctl, &WingPlugin::Controller::setCurrentEncoding, _win,
[=](const QString &encoding) -> bool {
if (!checkThreadAff()) {
return false;
}
auto e = pluginCurrentEditor(plg);
if (e) {
return e->hexEditor()->renderer()->setEncoding(encoding);
@ -1357,6 +1493,9 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
connect(pctl, &WingPlugin::Controller::addBookMark, _win,
[=](qsizetype pos, const QString &comment) -> bool {
if (!checkThreadAff()) {
return false;
}
auto e = pluginCurrentEditor(plg);
if (e) {
auto doc = e->hexEditor()->document();
@ -1366,6 +1505,9 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
});
connect(pctl, &WingPlugin::Controller::modBookMark, _win,
[=](qsizetype pos, const QString &comment) -> bool {
if (!checkThreadAff()) {
return false;
}
auto e = pluginCurrentEditor(plg);
if (e) {
auto doc = e->hexEditor()->document();
@ -1375,6 +1517,9 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
});
connect(pctl, &WingPlugin::Controller::removeBookMark, _win,
[=](qsizetype pos) -> bool {
if (!checkThreadAff()) {
return false;
}
auto e = pluginCurrentEditor(plg);
if (e) {
auto doc = e->hexEditor()->document();
@ -1383,6 +1528,9 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
return false;
});
connect(pctl, &WingPlugin::Controller::clearBookMark, _win, [=]() -> bool {
if (!checkThreadAff()) {
return false;
}
auto e = pluginCurrentEditor(plg);
if (e) {
auto doc = e->hexEditor()->document();
@ -1393,6 +1541,9 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
// mainwindow
connect(pctl, &WingPlugin::Controller::newFile, _win, [=]() -> ErrFile {
if (!checkThreadAff()) {
return ErrFile::NotAllowedInNoneGUIThread;
}
if (!checkPluginCanOpenedFile(plg)) {
return ErrFile::TooManyOpenedFile;
}
@ -1407,6 +1558,9 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
});
connect(pctl, &WingPlugin::Controller::openWorkSpace, _win,
[=](const QString &filename) -> ErrFile {
if (!checkThreadAff()) {
return ErrFile::NotAllowedInNoneGUIThread;
}
EditorView *view = nullptr;
if (!checkPluginCanOpenedFile(plg)) {
return ErrFile::TooManyOpenedFile;
@ -1426,6 +1580,9 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
});
connect(pctl, &WingPlugin::Controller::openFile, _win,
[=](const QString &filename) -> ErrFile {
if (!checkThreadAff()) {
return ErrFile::NotAllowedInNoneGUIThread;
}
EditorView *view = nullptr;
if (!checkPluginCanOpenedFile(plg)) {
return ErrFile::TooManyOpenedFile;
@ -1446,6 +1603,9 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
connect(pctl, &WingPlugin::Controller::openRegionFile, _win,
[=](const QString &filename, qsizetype start,
qsizetype length) -> ErrFile {
if (!checkThreadAff()) {
return ErrFile::NotAllowedInNoneGUIThread;
}
EditorView *view = nullptr;
if (!checkPluginCanOpenedFile(plg)) {
return ErrFile::TooManyOpenedFile;
@ -1465,6 +1625,9 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
});
connect(pctl, &WingPlugin::Controller::openDriver, _win,
[=](const QString &driver) -> ErrFile {
if (!checkThreadAff()) {
return ErrFile::NotAllowedInNoneGUIThread;
}
EditorView *view = nullptr;
auto ret = _win->openDriver(driver, &view);
if (!checkPluginCanOpenedFile(plg)) {
@ -1484,15 +1647,19 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
});
connect(pctl, &WingPlugin::Controller::closeFile, _win,
[=](int handle, bool force) -> ErrFile {
auto view = handle2EditorView(plg, handle);
if (view) {
_win->closeEditor(view, force);
if (!checkThreadAff()) {
return ErrFile::NotAllowedInNoneGUIThread;
}
if (closeEditor(plg, handle, force)) {
return ErrFile::Success;
}
return ErrFile::NotExist;
});
connect(pctl, &WingPlugin::Controller::saveFile, _win,
[=](int handle, bool ignoreMd5) -> ErrFile {
if (!checkThreadAff()) {
return ErrFile::NotAllowedInNoneGUIThread;
}
auto view = handle2EditorView(plg, handle);
if (view) {
_win->saveEditor(view, {}, ignoreMd5);
@ -1503,6 +1670,9 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
connect(
pctl, &WingPlugin::Controller::exportFile, _win,
[=](int handle, const QString &savename, bool ignoreMd5) -> ErrFile {
if (!checkThreadAff()) {
return ErrFile::NotAllowedInNoneGUIThread;
}
auto view = handle2EditorView(plg, handle);
if (view) {
_win->saveEditor(view, savename, ignoreMd5, true);
@ -1514,6 +1684,9 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
connect(
pctl, &WingPlugin::Controller::saveAsFile, _win,
[=](int handle, const QString &savename, bool ignoreMd5) -> ErrFile {
if (!checkThreadAff()) {
return ErrFile::NotAllowedInNoneGUIThread;
}
auto view = handle2EditorView(plg, handle);
if (view) {
_win->saveEditor(view, savename, ignoreMd5);
@ -1524,6 +1697,9 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
connect(pctl, &WingPlugin::Controller::closeCurrentFile, _win,
[=](bool force) -> ErrFile {
if (!checkThreadAff()) {
return ErrFile::NotAllowedInNoneGUIThread;
}
auto view = getCurrentPluginView(plg);
if (view == nullptr) {
return ErrFile::NotExist;
@ -1533,6 +1709,9 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
});
connect(pctl, &WingPlugin::Controller::saveCurrentFile, _win,
[=](bool ignoreMd5) -> ErrFile {
if (!checkThreadAff()) {
return ErrFile::NotAllowedInNoneGUIThread;
}
auto view = getCurrentPluginView(plg);
if (view) {
auto ws = _win->m_views.value(view);
@ -1544,7 +1723,10 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
});
connect(pctl, &WingPlugin::Controller::closeAllPluginFiles, _win,
[=]() -> void {
[=]() -> bool {
if (!checkThreadAff()) {
return false;
}
auto &maps = m_plgHandles[plg];
for (auto &item : maps) {
auto &bind = m_viewBindings[item.second];
@ -1555,6 +1737,7 @@ void PluginSystem::connectControllerInterface(IWingPlugin *plg) {
}
m_plgviewMap.remove(plg);
m_plgHandles.remove(plg);
return true;
});
}
@ -1874,8 +2057,7 @@ void PluginSystem::connectUIInterface(IWingPlugin *plg) {
bool PluginSystem::checkThreadAff() {
if (QThread::currentThread() != qApp->thread()) {
Logger::warning(
tr("Creating UI widget is not allowed in non-UI thread"));
Logger::warning(tr("Not allowed operation in non-UI thread"));
return false;
}
return true;

View File

@ -88,7 +88,8 @@ private:
QQueue<int> releasedIds;
};
using UniqueId = QExplicitlySharedDataPointer<UniqueIdGenerator::UniqueId>;
using SharedUniqueId =
QExplicitlySharedDataPointer<UniqueIdGenerator::UniqueId>;
public:
static PluginSystem &instance();
@ -109,7 +110,8 @@ public:
EditorView *handle2EditorView(IWingPlugin *plg, int handle);
UniqueId assginHandleForPluginView(IWingPlugin *plg, EditorView *view);
SharedUniqueId assginHandleForPluginView(IWingPlugin *plg,
EditorView *view);
bool checkPluginCanOpenedFile(IWingPlugin *plg);
@ -117,6 +119,8 @@ public:
void cleanUpEditorViewHandle(EditorView *view);
bool closeEditor(IWingPlugin *plg, int handle, bool force);
private:
void registerFns(IWingPlugin *plg);
@ -150,10 +154,15 @@ private:
Q_STATIC_ASSERT(std::is_integral_v<T> || std::is_floating_point_v<T>);
auto e = pluginCurrentEditor(plg);
if (e) {
_rwlock.lockForRead();
auto buffer = e->hexEditor()->document()->read(offset, sizeof(T));
auto pb = reinterpret_cast<const T *>(buffer.constData());
return *pb;
if (buffer.size() == sizeof(T)) {
auto pb = reinterpret_cast<const T *>(buffer.constData());
_rwlock.unlock();
return *pb;
}
}
if constexpr (std::is_floating_point_v<T>) {
return qQNaN();
} else {
@ -167,9 +176,12 @@ private:
Q_STATIC_ASSERT(std::is_integral_v<T> || std::is_floating_point_v<T>);
auto e = pluginCurrentEditor(plg);
if (e) {
_rwlock.lockForWrite();
auto doc = e->hexEditor()->document();
auto buffer = reinterpret_cast<const char *>(&value);
return doc->insert(offset, QByteArray(buffer, sizeof(T)));
auto ret = doc->insert(offset, QByteArray(buffer, sizeof(T)));
_rwlock.unlock();
return ret;
}
return false;
}
@ -180,9 +192,12 @@ private:
Q_STATIC_ASSERT(std::is_integral_v<T> || std::is_floating_point_v<T>);
auto e = pluginCurrentEditor(plg);
if (e) {
_rwlock.lockForWrite();
auto doc = e->hexEditor()->document();
auto buffer = reinterpret_cast<const char *>(&value);
return doc->replace(offset, QByteArray(buffer, sizeof(T)));
auto ret = doc->replace(offset, QByteArray(buffer, sizeof(T)));
_rwlock.unlock();
return ret;
}
return false;
}
@ -192,11 +207,14 @@ private:
Q_STATIC_ASSERT(std::is_integral_v<T> || std::is_floating_point_v<T>);
auto e = pluginCurrentEditor(plg);
if (e) {
_rwlock.lockForWrite();
auto doc = e->hexEditor()->document();
auto offset = doc->length();
auto buffer = reinterpret_cast<const char *>(&value);
QByteArray data(buffer, sizeof(T));
return doc->insert(offset, data);
auto ret = doc->insert(offset, data);
_rwlock.unlock();
return ret;
}
return false;
}
@ -213,15 +231,18 @@ private:
QStringList loadedpuid;
QList<IWingPlugin *> loadedplgs;
QMap<IWingPlugin *, EditorView *> m_plgviewMap;
QMap<IWingPlugin *, QList<QPair<UniqueId, EditorView *>>> m_plgHandles;
QMap<EditorView *, QList<IWingPlugin *>> m_viewBindings;
QHash<IWingPlugin *, EditorView *> m_plgviewMap;
QHash<IWingPlugin *, QList<QPair<SharedUniqueId, EditorView *>>>
m_plgHandles;
QHash<EditorView *, QList<IWingPlugin *>> m_viewBindings;
UniqueIdGenerator m_idGen;
QHash<QString, QHash<QString, WingAngelAPI::ScriptFnInfo>> _scfns;
WingAngelAPI *_angelplg = nullptr;
QReadWriteLock _rwlock;
};
#endif // PLUGINSYSTEM_H