Improve coding style in renaming utility
Those changings have been created when adding JavaScript support to syncthingctl. Maybe implement this more like it works now in syncthingctl?
This commit is contained in:
parent
f39abd56db
commit
159d0a9739
|
@ -40,19 +40,20 @@ RenamingEngine::RenamingEngine(QObject *parent)
|
|||
#ifndef TAGEDITOR_NO_JSENGINE
|
||||
bool RenamingEngine::setProgram(const TAGEDITOR_JS_VALUE &program)
|
||||
{
|
||||
if (TAGEDITOR_JS_IS_VALID_PROG(program)) {
|
||||
if (program.isError()) {
|
||||
m_errorMessage = program.property(QStringLiteral("message")).toString();
|
||||
m_errorLineNumber = TAGEDITOR_JS_INT(program.property(QStringLiteral("lineNumber")));
|
||||
return false;
|
||||
} else if (!TAGEDITOR_JS_IS_VALID_PROG(program)) {
|
||||
m_errorMessage = tr("Program is not callable. Please don't close a function you didn't open.");
|
||||
m_errorLineNumber = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
m_errorMessage.clear();
|
||||
m_errorLineNumber = 0;
|
||||
m_program = program;
|
||||
return true;
|
||||
} else if (program.isError()) {
|
||||
m_errorMessage = program.property(QStringLiteral("message")).toString();
|
||||
m_errorLineNumber = TAGEDITOR_JS_INT(program.property(QStringLiteral("lineNumber")));
|
||||
} else {
|
||||
m_errorMessage = tr("Program is not callable.");
|
||||
m_errorLineNumber = 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -288,12 +289,14 @@ void RenamingEngine::executeScriptForItem(const QFileInfo &fileInfo, FileSystemI
|
|||
// make file info for the specified item available in the script
|
||||
m_tagEditorQObj->setFileInfo(fileInfo, item);
|
||||
// execute script
|
||||
auto scriptResult = m_program.call();
|
||||
const auto scriptResult(m_program.call());
|
||||
if (scriptResult.isError()) {
|
||||
// handle error
|
||||
item->setErrorOccured(true);
|
||||
item->setNote(scriptResult.toString());
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
// create preview for action
|
||||
const QString &newName = m_tagEditorQObj->newName();
|
||||
const QString &newRelativeDirectory = m_tagEditorQObj->newRelativeDirectory();
|
||||
|
@ -338,7 +341,6 @@ void RenamingEngine::executeScriptForItem(const QFileInfo &fileInfo, FileSystemI
|
|||
item->setNote(tr("skipped"));
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace RenamingUtility
|
||||
|
|
Loading…
Reference in New Issue