Commit 59a8c9f1 authored by Alexander A. Maly's avatar Alexander A. Maly

Allowed Robot fields with spaces in file path

Allowed Robot fields with spaces in file path/name to open properly
from 'Recent fields' menu.
Show one-time info message that semicolons are still not allowed in file paths
of Robot fields in 'Recent fields' menu.
parent 50ade9dc
Pipeline #1912 passed with stages
in 6 minutes and 13 seconds
...@@ -1201,21 +1201,18 @@ int RobotModule::SaveToFile(QString p_FileName) ...@@ -1201,21 +1201,18 @@ int RobotModule::SaveToFile(QString p_FileName)
void RobotModule::createRescentMenu() void RobotModule::createRescentMenu()
{ {
QString sFiles = mySettings()->value("Robot/LastFiles").toString();
QStringList lFiles = sFiles.split(';', QString::SkipEmptyParts);
qDebug() << lFiles;
rescentMenu->clear(); rescentMenu->clear();
QStringList lastFiles = mySettings()->value("Robot/LastFiles").toString().split(";"); rescentMenu->setEnabled(lFiles.count() > 0);
qDebug() << lastFiles;
if (lastFiles.count() == 0) {
rescentMenu->setEnabled(false);
} else {
rescentMenu->setEnabled(true);
}
for (int i = 0; i < lastFiles.count(); i++) { for (int i = 0; i < lFiles.count(); i++) {
if (lastFiles[i] == "") { rescentMenu->addAction(
continue; "&" + QString::number(i + 1) + " " + lFiles[i],
} this, SLOT(openRecent())
QAction *action = rescentMenu->addAction("&" + QString::number(i + 1) + " " + lastFiles[i], this, SLOT(openRecent())); );
Q_UNUSED(action);
} }
} }
...@@ -1263,8 +1260,18 @@ void RobotModule::setWindowSize() ...@@ -1263,8 +1260,18 @@ void RobotModule::setWindowSize()
void RobotModule::openRecent() void RobotModule::openRecent()
{ {
QAction *s = qobject_cast<QAction *>(sender()); QString RobotFile;
QString txt = s->text(); {
QAction *s = qobject_cast<QAction *>(sender());
QString txt = s->text();
int pos = txt.indexOf(' ', 2);
if (pos < 0)
return;
RobotFile = txt.mid(pos + 1);
}
if (RobotFile.isEmpty())
return;
if (field->WasEdit()) { if (field->WasEdit()) {
QMessageBox::StandardButton r; QMessageBox::StandardButton r;
QMessageBox messageBox( QMessageBox messageBox(
...@@ -1278,8 +1285,8 @@ void RobotModule::openRecent() ...@@ -1278,8 +1285,8 @@ void RobotModule::openRecent()
QMessageBox::AcceptRole); QMessageBox::AcceptRole);
QPushButton *btnDiscard = messageBox.addButton(tr("Don't save"), QPushButton *btnDiscard = messageBox.addButton(tr("Don't save"),
QMessageBox::DestructiveRole); QMessageBox::DestructiveRole);
QPushButton *btnCancel = QPushButton *btnCancel = messageBox.addButton(tr("Cancel"),
messageBox.addButton(tr("Cancel"), QMessageBox::RejectRole); QMessageBox::RejectRole);
messageBox.setDefaultButton(btnSave); messageBox.setDefaultButton(btnSave);
messageBox.exec(); messageBox.exec();
...@@ -1305,34 +1312,43 @@ void RobotModule::openRecent() ...@@ -1305,34 +1312,43 @@ void RobotModule::openRecent()
} }
} }
txt.remove(0, 1);
QStringList words = txt.split(" ");
if (words.count() < 2)
return;
QString RobotFile = words[1];
if (LoadFromFile(RobotFile) != 0) { if (LoadFromFile(RobotFile) != 0) {
QMessageBox::information(mainWidget(), "", QString::fromUtf8("Ошибка открытия файла! ") + RobotFile, 0, 0, 0); QMessageBox::warning(
mainWidget(), "",
QString::fromUtf8("Ошибка открытия файла '%1'!").arg(RobotFile)
);
} }
reset(); reset();
view->setWindowSize(view->size()); view->setWindowSize(view->size());
} }
void RobotModule::updateLastFiles(const QString newFile) void RobotModule::updateLastFiles(QString newFile)
{ {
QStringList lastFiles = RobotModule::robotSettings()->value("Robot/LastFiles").toString().split(";"); if (newFile.isEmpty())
if (lastFiles.indexOf(newFile) < 0) { return;
lastFiles.prepend(newFile);
if (newFile.contains(';')) {
static bool warned = false;
if (!warned) {
QMessageBox::information(
mainWidget(), "",
QString::fromUtf8("Силам добра противен символ ';' в имени файла!")
);
warned = true;
}
return;
} }
int max_fid = std::min(lastFiles.count(), 11);
QString sett = ""; QString sFiles = RobotModule::robotSettings()->value("Robot/LastFiles").toString();
for (int i = 0; i < max_fid; i++) { QStringList lFiles = sFiles.split(';', QString::SkipEmptyParts);
sett += lastFiles.at(i) + ";"; if (!lFiles.contains(newFile)) {
lFiles.prepend(newFile);
lFiles = lFiles.mid(0, 11);
sFiles = lFiles.join(QChar(';'));
RobotModule::robotSettings()->setValue("Robot/LastFiles", sFiles);
createRescentMenu();
} }
RobotModule::robotSettings()->setValue("Robot/LastFiles", sett);
createRescentMenu();
} }
void RobotModule::updateRobot() void RobotModule::updateRobot()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment