|
31 | 31 | #include <utils/robotCommunication/networkCommunicationErrorReporter.h> |
32 | 32 | #include <qrgui/textEditor/qscintillaTextEdit.h> |
33 | 33 | #include <qrgui/textEditor/textManagerInterface.h> |
34 | | - |
| 34 | +#include <qrkernel/settingsManager.h> |
| 35 | +#include <qrutils/widgets/qRealMessageBox.h> |
35 | 36 | #include "trikQtsMasterGenerator.h" |
36 | 37 | #include "emptyShell.h" |
37 | 38 |
|
@@ -86,7 +87,7 @@ void TrikQtsGeneratorPluginBase::init(const kitBase::KitPluginConfigurator &conf |
86 | 87 | , this, &TrikQtsGeneratorPluginBase::onProtocolFinished); |
87 | 88 |
|
88 | 89 | connect(mUploadProgramProtocol.data(), &UploadProgramProtocol::success |
89 | | - , this, &TrikQtsGeneratorPluginBase::onProtocolFinished); |
| 90 | + , this, &TrikQtsGeneratorPluginBase::onUploadSuccess); |
90 | 91 | connect(mRunProgramProtocol.data(), &RunProgramProtocol::success |
91 | 92 | , this, &TrikQtsGeneratorPluginBase::onProtocolFinished); |
92 | 93 | connect(mStopRobotProtocol.data(), &StopRobotProtocol::success |
@@ -215,6 +216,9 @@ void TrikQtsGeneratorPluginBase::uploadProgram() |
215 | 216 | } |
216 | 217 | if (!files.isEmpty()) { |
217 | 218 | disableButtons(); |
| 219 | + if (auto code = dynamic_cast<text::QScintillaTextEdit *>(mMainWindowInterface->currentTab())) { |
| 220 | + mMainFile = QFileInfo(mTextManager->path(code)); |
| 221 | + } |
218 | 222 | mUploadProgramProtocol->run(files); |
219 | 223 | } else { |
220 | 224 | mMainWindowInterface->errorReporter()->addError( |
@@ -254,8 +258,41 @@ void TrikQtsGeneratorPluginBase::stopRobot() |
254 | 258 | } |
255 | 259 | } |
256 | 260 |
|
| 261 | +void TrikQtsGeneratorPluginBase::onUploadSuccess() |
| 262 | +{ |
| 263 | + auto runPolicy = static_cast<RunPolicy>(SettingsManager::value("trikRunPolicy").toInt()); |
| 264 | + switch (runPolicy) { |
| 265 | + case RunPolicy::Ask: |
| 266 | + if (utils::QRealMessageBox::question(mMainWindowInterface->windowWidget() |
| 267 | + , tr("The program has been uploaded") |
| 268 | + , tr("Do you want to run it?") |
| 269 | + ) != QMessageBox::Yes) { |
| 270 | + break; |
| 271 | + } |
| 272 | + Q_FALLTHROUGH(); |
| 273 | + case RunPolicy::AlwaysRun: |
| 274 | + if (mMainFile != QFileInfo()) { |
| 275 | + if (mRunProgramProtocol) { |
| 276 | + mRunProgramProtocol->run(mMainFile); |
| 277 | + return; |
| 278 | + } else { |
| 279 | + QLOG_ERROR() << "Run program protocol is not initialized"; |
| 280 | + } |
| 281 | + } else { |
| 282 | + utils::QRealMessageBox::question(mMainWindowInterface->windowWidget() |
| 283 | + ,tr("Error"), tr("Unknown file to run after upload, please run manually"), |
| 284 | + QMessageBox::Ok); |
| 285 | + } |
| 286 | + break; |
| 287 | + case RunPolicy::NeverRun: |
| 288 | + break; |
| 289 | + } |
| 290 | + onProtocolFinished(); |
| 291 | +} |
| 292 | + |
257 | 293 | void TrikQtsGeneratorPluginBase::onProtocolFinished() |
258 | 294 | { |
| 295 | + mMainFile = QFileInfo(); |
259 | 296 | mUploadProgramAction->setEnabled(true); |
260 | 297 | mRunProgramAction->setEnabled(true); |
261 | 298 | mStopRobotAction->setEnabled(true); |
|
0 commit comments