|
|
|
@ -1,6 +1,5 @@ |
|
|
|
|
#include "Manager.h" |
|
|
|
|
#include "ui_Manager.h" |
|
|
|
|
#include "config.h" |
|
|
|
|
#include "MdiManager.h" |
|
|
|
|
#include "IWin/IWinStatus.h" |
|
|
|
|
#include "ConfigMgr.h" |
|
|
|
@ -27,7 +26,7 @@ ScriptManager::ScriptManager(MdiManager* mdiManager, QWidget *parent) : |
|
|
|
|
for (const QString& path : cfg.scripts()) { |
|
|
|
|
bool ok = loadFromFile(path); |
|
|
|
|
if (!ok) { |
|
|
|
|
auto btn = QMessageBox::warning(this, tr("Load failed"), tr("The script located at:\n%1\nFailed to load. Keep the entry in the manager?").arg(path), |
|
|
|
|
auto btn = QMessageBox::warning(this, tr("Load script"), tr("The script located at:\n%1\nFailed to load. Keep the entry in the manager?").arg(path), |
|
|
|
|
QMessageBox::Yes | QMessageBox::No); |
|
|
|
|
if (btn == QMessageBox::No) { |
|
|
|
|
m_scripts.pop_back(); |
|
|
|
@ -94,11 +93,6 @@ ScriptManager* ScriptManager::instance() |
|
|
|
|
return *Instance; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
MdiManager* ScriptManager::getMdiManager() |
|
|
|
|
{ |
|
|
|
|
return (*Instance)->mdiManager; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
IWinStatus* ScriptManager::getContext() |
|
|
|
|
{ |
|
|
|
|
return (*Instance)->m_context; |
|
|
|
@ -151,20 +145,11 @@ bool ScriptManager::runCommand(const QString& command) |
|
|
|
|
bool ScriptManager::loadFromFile(const QString& path) |
|
|
|
|
{ |
|
|
|
|
auto fixedPath = path; |
|
|
|
|
|
|
|
|
|
#if defined(Q_OS_LINUX) |
|
|
|
|
if (path[0] != '/') |
|
|
|
|
fixedPath = QStringLiteral("%1/%2").arg(LOCAL_PATH, path); |
|
|
|
|
#elif defined(Q_OS_WIN32) | defined(Q_OS_WIN64) |
|
|
|
|
if (path[1] != ':') |
|
|
|
|
fixedPath = QStringLiteral("%1/%2").arg(LOCAL_PATH, path); |
|
|
|
|
#else |
|
|
|
|
#error Unsupported platform! Update Script/Manager.cpp (ScriptManager::loadFromFile) accordingly. |
|
|
|
|
#endif |
|
|
|
|
MAKE_FIXED_PATH(path, fixedPath); |
|
|
|
|
|
|
|
|
|
QFile f(fixedPath); |
|
|
|
|
if (!f.open(QIODevice::ReadOnly)) { |
|
|
|
|
QMessageBox::warning(this, tr("Open script"), tr("Unable to open script file from\n%1").arg(fixedPath)); |
|
|
|
|
QMessageBox::warning(this, tr("Load script"), tr("Unable to open script file from\n%1").arg(fixedPath)); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
QByteArray data(f.readAll()); |
|
|
|
@ -236,9 +221,12 @@ void ScriptManager::printError(const std::string& msg) |
|
|
|
|
|
|
|
|
|
void ScriptManager::reloadScript(Script& script, const QString& pathToScript) |
|
|
|
|
{ |
|
|
|
|
QFile f(pathToScript); |
|
|
|
|
auto fixedPath = pathToScript; |
|
|
|
|
MAKE_FIXED_PATH(pathToScript, fixedPath); |
|
|
|
|
|
|
|
|
|
QFile f(fixedPath); |
|
|
|
|
if (!f.open(QIODevice::ReadOnly)) { |
|
|
|
|
QMessageBox::warning(this, tr("Open script"), tr("Unable to open script file from\n%1").arg(pathToScript)); |
|
|
|
|
QMessageBox::warning(this, tr("Reload script"), tr("Unable to open script file for reloading\n%1").arg(fixedPath)); |
|
|
|
|
m_listModel.markWarning(pathToScript); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
@ -261,7 +249,7 @@ void ScriptManager::on_btnLoad_clicked() |
|
|
|
|
|
|
|
|
|
QModelIndex existingIdx = m_listModel.pathIndex(path); |
|
|
|
|
if (existingIdx.isValid()) { |
|
|
|
|
auto btn = QMessageBox::warning(this, tr("Script already loaded"), tr("The script located at:\n%1\nIs already loaded. Reload script instead?").arg(path), |
|
|
|
|
auto btn = QMessageBox::warning(this, tr("Load script"), tr("The script located at:\n%1\nIs already loaded. Reload script instead?").arg(path), |
|
|
|
|
QMessageBox::Yes | QMessageBox::No); |
|
|
|
|
if (btn == QMessageBox::Yes) { |
|
|
|
|
auto it = m_scripts.begin(); |
|
|
|
@ -275,7 +263,7 @@ void ScriptManager::on_btnLoad_clicked() |
|
|
|
|
|
|
|
|
|
bool ok = loadFromFile(path); |
|
|
|
|
if (!ok) { |
|
|
|
|
auto btn = QMessageBox::warning(this, tr("Load failed"), tr("The script located at:\n%1\nFailed to load. Keep the entry in the manager?").arg(path), |
|
|
|
|
auto btn = QMessageBox::warning(this, tr("Load script"), tr("The script located at:\n%1\nFailed to load. Keep the entry in the manager?").arg(path), |
|
|
|
|
QMessageBox::Yes | QMessageBox::No); |
|
|
|
|
if (btn == QMessageBox::No) { |
|
|
|
|
m_scripts.pop_back(); |
|
|
|
@ -312,7 +300,7 @@ void ScriptManager::on_btnRemove_clicked() |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
const auto button = QMessageBox::question(this, tr("Confirm unload"), tr("Are you sure you want to unload the selected script?")); |
|
|
|
|
const auto button = QMessageBox::question(this, tr("Unload script"), tr("Are you sure you want to unload the selected script?")); |
|
|
|
|
if (button == QMessageBox::No) |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|