Added support for checking files via commandline arguments.
This commit is contained in:
parent
cffa4772b0
commit
962757c257
|
@ -31,8 +31,6 @@ int main(int argc, char *argv[])
|
|||
QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
|
||||
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
|
||||
|
||||
|
||||
|
||||
MainWindow window;
|
||||
window.show();
|
||||
return app.exec();
|
||||
|
|
|
@ -91,7 +91,13 @@ MainWindow::MainWindow() :
|
|||
|
||||
|
||||
|
||||
|
||||
QStringList args = QCoreApplication::arguments();
|
||||
//Remove the application itself
|
||||
args.removeFirst();
|
||||
if (!args.isEmpty())
|
||||
{
|
||||
DoCheckFiles(args);
|
||||
}
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
|
@ -185,43 +191,18 @@ void MainWindow::SaveSettings()
|
|||
mUI.mResults->SaveSettings();
|
||||
}
|
||||
|
||||
void MainWindow::DoCheckFiles(QFileDialog::FileMode mode)
|
||||
void MainWindow::DoCheckFiles(const QStringList &files)
|
||||
{
|
||||
QStringList selected;
|
||||
|
||||
// NOTE: we use QFileDialog::getOpenFileNames() and
|
||||
// QFileDialog::getExistingDirectory() because they show native Windows
|
||||
// selection dialog which is a lot more usable than QT:s own dialog.
|
||||
if (mode == QFileDialog::ExistingFiles)
|
||||
if (files.isEmpty())
|
||||
{
|
||||
selected = QFileDialog::getOpenFileNames(this,
|
||||
tr("Select files to check"),
|
||||
mSettings->value(SETTINGS_CHECK_PATH, "").toString());
|
||||
if (selected.isEmpty())
|
||||
mCurrentDirectory.clear();
|
||||
FormatAndSetTitle();
|
||||
return;
|
||||
}
|
||||
else if (mode == QFileDialog::DirectoryOnly)
|
||||
{
|
||||
QString dir = QFileDialog::getExistingDirectory(this,
|
||||
tr("Select directory to check"),
|
||||
mSettings->value(SETTINGS_CHECK_PATH, "").toString());
|
||||
if (!dir.isEmpty())
|
||||
{
|
||||
mCurrentDirectory = dir;
|
||||
selected.append(dir);
|
||||
FormatAndSetTitle(dir);
|
||||
}
|
||||
}
|
||||
|
||||
if (selected.count() > 0)
|
||||
{
|
||||
ClearResults();
|
||||
|
||||
QStringList fileNames;
|
||||
QString selection;
|
||||
|
||||
foreach(selection, selected)
|
||||
foreach(selection, files)
|
||||
{
|
||||
fileNames << RemoveUnacceptedFiles(GetFilesRecursively(selection));
|
||||
}
|
||||
|
@ -253,17 +234,49 @@ void MainWindow::DoCheckFiles(QFileDialog::FileMode mode)
|
|||
|
||||
Settings checkSettings = GetCppcheckSettings();
|
||||
mThread->Check(checkSettings, false);
|
||||
}
|
||||
|
||||
|
||||
QStringList MainWindow::SelectFilesToCheck(QFileDialog::FileMode mode)
|
||||
{
|
||||
QStringList selected;
|
||||
|
||||
// NOTE: we use QFileDialog::getOpenFileNames() and
|
||||
// QFileDialog::getExistingDirectory() because they show native Windows
|
||||
// selection dialog which is a lot more usable than QT:s own dialog.
|
||||
if (mode == QFileDialog::ExistingFiles)
|
||||
{
|
||||
selected = QFileDialog::getOpenFileNames(this,
|
||||
tr("Select files to check"),
|
||||
mSettings->value(SETTINGS_CHECK_PATH, "").toString());
|
||||
if (selected.isEmpty())
|
||||
mCurrentDirectory.clear();
|
||||
FormatAndSetTitle();
|
||||
}
|
||||
else if (mode == QFileDialog::DirectoryOnly)
|
||||
{
|
||||
QString dir = QFileDialog::getExistingDirectory(this,
|
||||
tr("Select directory to check"),
|
||||
mSettings->value(SETTINGS_CHECK_PATH, "").toString());
|
||||
if (!dir.isEmpty())
|
||||
{
|
||||
mCurrentDirectory = dir;
|
||||
selected.append(dir);
|
||||
FormatAndSetTitle(dir);
|
||||
}
|
||||
}
|
||||
|
||||
return selected;
|
||||
}
|
||||
|
||||
void MainWindow::CheckFiles()
|
||||
{
|
||||
DoCheckFiles(QFileDialog::ExistingFiles);
|
||||
DoCheckFiles(SelectFilesToCheck(QFileDialog::ExistingFiles));
|
||||
}
|
||||
|
||||
void MainWindow::CheckDirectory()
|
||||
{
|
||||
DoCheckFiles(QFileDialog::DirectoryOnly);
|
||||
DoCheckFiles(SelectFilesToCheck(QFileDialog::DirectoryOnly));
|
||||
}
|
||||
|
||||
Settings MainWindow::GetCppcheckSettings()
|
||||
|
|
|
@ -205,8 +205,16 @@ protected:
|
|||
* directory to check. Use native dialogs instead of QT:s own dialogs.
|
||||
*
|
||||
* @param mode Dialog open mode (files or directories)
|
||||
* @return QStringList of files or directories that were selected to check
|
||||
*/
|
||||
void DoCheckFiles(QFileDialog::FileMode mode);
|
||||
QStringList SelectFilesToCheck(QFileDialog::FileMode mode);
|
||||
|
||||
/**
|
||||
* @brief Check all files specified in parameter files
|
||||
*
|
||||
* @param files List of files and/or directories to check
|
||||
*/
|
||||
void DoCheckFiles(const QStringList &files);
|
||||
|
||||
/**
|
||||
* @brief Get all files recursively from given path
|
||||
|
|
|
@ -1793,7 +1793,7 @@ bool Tokenizer::simplifyConditionOperator()
|
|||
}
|
||||
else
|
||||
{
|
||||
tok->insertToken(str.substr(pos1, pos2-pos1).c_str());
|
||||
tok->insertToken(str.substr(pos1, pos2 - pos1).c_str());
|
||||
pos1 = pos2 + 1;
|
||||
}
|
||||
tok = tok->next();
|
||||
|
|
Loading…
Reference in New Issue