diff --git a/gui/gui.pro b/gui/gui.pro
index 68bad26c0..9a3d33e54 100644
--- a/gui/gui.pro
+++ b/gui/gui.pro
@@ -42,6 +42,7 @@ FORMS = about.ui \
main.ui \
projectfile.ui \
resultsview.ui \
+ scratchpad.ui \
settings.ui \
stats.ui \
selectfilesdialog.ui
@@ -87,6 +88,7 @@ HEADERS += aboutdialog.h \
report.h \
resultstree.h \
resultsview.h \
+ scratchpad.h \
settingsdialog.h \
showtypes.h \
statsdialog.h \
@@ -119,6 +121,7 @@ SOURCES += aboutdialog.cpp \
report.cpp \
resultstree.cpp \
resultsview.cpp \
+ scratchpad.cpp \
settingsdialog.cpp \
showtypes.cpp \
statsdialog.cpp \
diff --git a/gui/gui.qrc b/gui/gui.qrc
index 8852d3c10..c6d12b84c 100644
--- a/gui/gui.qrc
+++ b/gui/gui.qrc
@@ -15,6 +15,7 @@
images/showerrors.png
images/showstylewarnings.png
images/openproject.png
+ images/scratchpad.png
images/showwarnings.png
images/showperformance.png
images/utilities-system-monitor.png
diff --git a/gui/images/scratchpad.png b/gui/images/scratchpad.png
new file mode 100644
index 000000000..7ab61ad17
Binary files /dev/null and b/gui/images/scratchpad.png differ
diff --git a/gui/main.ui b/gui/main.ui
index 0898ea0e9..ecc81a396 100644
--- a/gui/main.ui
+++ b/gui/main.ui
@@ -112,6 +112,7 @@
+
@@ -165,6 +166,7 @@
+
@@ -424,6 +426,16 @@
Open P&roject File...
+
+
+
+ :/images/scratchpad.png:/images/scratchpad.png
+
+
+
+ Show S&cratchpad...
+
+
&New Project File...
diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp
index a9c9b9bcb..6b16ca452 100644
--- a/gui/mainwindow.cpp
+++ b/gui/mainwindow.cpp
@@ -35,8 +35,10 @@
#include "projectfile.h"
#include "project.h"
#include "report.h"
+#include "scratchpad.h"
#include "statsdialog.h"
#include "settingsdialog.h"
+#include "threadresult.h"
#include "translationhandler.h"
#include "logview.h"
#include "filelist.h"
@@ -50,6 +52,7 @@ MainWindow::MainWindow() :
mApplications(new ApplicationList(this)),
mTranslation(new TranslationHandler(this)),
mLogView(NULL),
+ mScratchPad(NULL),
mProject(NULL),
mPlatformActions(new QActionGroup(this)),
mExiting(false)
@@ -116,6 +119,7 @@ MainWindow::MainWindow() :
// File menu
connect(mUI.mActionNewProjectFile, SIGNAL(triggered()), this, SLOT(NewProjectFile()));
connect(mUI.mActionOpenProjectFile, SIGNAL(triggered()), this, SLOT(OpenProjectFile()));
+ connect(mUI.mActionShowScratchpad, SIGNAL(triggered()), this, SLOT(ShowScratchpad()));
connect(mUI.mActionCloseProjectFile, SIGNAL(triggered()), this, SLOT(CloseProjectFile()));
connect(mUI.mActionEditProjectFile, SIGNAL(triggered()), this, SLOT(EditProjectFile()));
@@ -182,6 +186,7 @@ MainWindow::~MainWindow()
{
delete mLogView;
delete mProject;
+ delete mScratchPad;
}
void MainWindow::HandleCLIParams(const QStringList ¶ms)
@@ -331,6 +336,32 @@ void MainWindow::DoCheckFiles(const QStringList &files)
mThread->Check(checkSettings, false);
}
+void MainWindow::CheckCode(const QString& code, const QString& filename)
+{
+ // Initialize dummy ThreadResult as ErrorLogger
+ ThreadResult result;
+ result.SetFiles(QStringList(filename));
+ connect(&result, SIGNAL(Progress(int, const QString&)),
+ mUI.mResults, SLOT(Progress(int, const QString&)));
+ connect(&result, SIGNAL(Error(const ErrorItem &)),
+ mUI.mResults, SLOT(Error(const ErrorItem &)));
+ connect(&result, SIGNAL(Log(const QString &)),
+ this, SLOT(Log(const QString &)));
+ connect(&result, SIGNAL(DebugError(const ErrorItem &)),
+ this, SLOT(DebugError(const ErrorItem &)));
+
+ // Create CppCheck instance
+ CppCheck cppcheck(result, true);
+ cppcheck.settings() = GetCppcheckSettings();
+
+ // Check
+ CheckLockDownUI();
+ ClearResults();
+ mUI.mResults->CheckingStarted(1);
+ cppcheck.check(filename.toStdString(), code.toStdString());
+ CheckDone();
+}
+
QStringList MainWindow::SelectFilesToCheck(QFileDialog::FileMode mode)
{
if (mProject) {
@@ -531,7 +562,8 @@ void MainWindow::CheckDone()
mUI.mActionCplusplus11->setEnabled(true);
mUI.mActionC99->setEnabled(true);
mUI.mActionPosix->setEnabled(true);
-
+ if (mScratchPad)
+ mScratchPad->setEnabled(true);
if (mUI.mResults->HasResults()) {
mUI.mActionClearResults->setEnabled(true);
@@ -558,6 +590,8 @@ void MainWindow::CheckLockDownUI()
mUI.mActionCplusplus11->setEnabled(false);
mUI.mActionC99->setEnabled(false);
mUI.mActionPosix->setEnabled(false);
+ if (mScratchPad)
+ mScratchPad->setEnabled(false);
for (int i = 0; i < MaxRecentProjects + 1; i++) {
if (mRecentProjectActs[i] != NULL)
@@ -895,6 +929,17 @@ void MainWindow::OpenProjectFile()
}
}
+void MainWindow::ShowScratchpad()
+{
+ if (!mScratchPad)
+ mScratchPad = new ScratchPad(*this);
+
+ mScratchPad->show();
+
+ if (!mScratchPad->isActiveWindow())
+ mScratchPad->activateWindow();
+}
+
void MainWindow::LoadProjectFile(const QString &filePath)
{
QFileInfo inf(filePath);
diff --git a/gui/mainwindow.h b/gui/mainwindow.h
index 62c6a5652..62566745c 100644
--- a/gui/mainwindow.h
+++ b/gui/mainwindow.h
@@ -32,6 +32,7 @@
class ThreadHandler;
class TranslationHandler;
+class ScratchPad;
class LogView;
class Project;
class ErrorItem;
@@ -187,6 +188,12 @@ public slots:
*/
void OpenProjectFile();
+ /**
+ * @brief Slot to open project file and start checking contained paths.
+ *
+ */
+ void ShowScratchpad();
+
/**
* @brief Slot to close open project file.
*
@@ -211,6 +218,14 @@ public slots:
*/
void ShowStatistics();
+ /**
+ * @brief Checks given code
+ *
+ * @param code Content of the (virtual) file to be checked
+ * @param filename Name of the (virtual) file to be checked - determines language.
+ */
+ void CheckCode(const QString& code, const QString& filename);
+
protected slots:
/**
@@ -453,6 +468,11 @@ protected:
*/
LogView *mLogView;
+ /**
+ * @brief Scratchpad.
+ */
+ ScratchPad* mScratchPad;
+
/**
* @brief Project (file).
*/
diff --git a/gui/scratchpad.cpp b/gui/scratchpad.cpp
new file mode 100644
index 000000000..940ca0c1d
--- /dev/null
+++ b/gui/scratchpad.cpp
@@ -0,0 +1,38 @@
+/*
+ * Cppcheck - A tool for static C/C++ code analysis
+ * Copyright (C) 2007-2012 Daniel Marjamäki and Cppcheck team.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include "scratchpad.h"
+#include "mainwindow.h"
+#include
+
+ScratchPad::ScratchPad(MainWindow& mainWindow)
+ : QDialog(&mainWindow)
+ , mMainWindow(mainWindow)
+{
+ mUI.setupUi(this);
+
+ connect(mUI.mCheckButton, SIGNAL(clicked()), this, SLOT(CheckButtonClicked()));
+}
+
+void ScratchPad::CheckButtonClicked()
+{
+ QString filename = mUI.lineEdit->text();
+ if (filename.size() == 0)
+ filename = "test.cpp";
+ mMainWindow.CheckCode(mUI.plainTextEdit->toPlainText(), filename);
+}
diff --git a/gui/scratchpad.h b/gui/scratchpad.h
new file mode 100644
index 000000000..0b8537537
--- /dev/null
+++ b/gui/scratchpad.h
@@ -0,0 +1,51 @@
+/*
+ * Cppcheck - A tool for static C/C++ code analysis
+ * Copyright (C) 2007-2012 Daniel Marjamäki and Cppcheck team.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#ifndef SCRATCHPAD_H
+#define SCRATCHPAD_H
+
+#include
+#include "ui_scratchpad.h"
+
+class MainWindow;
+
+/// @addtogroup GUI
+/// @{
+
+/**
+* @brief A window with a text field that .
+*/
+class ScratchPad : public QDialog {
+ Q_OBJECT
+public:
+ ScratchPad(MainWindow& mainWindow);
+
+private slots:
+ /**
+ * @brief Called when check button is clicked.
+ */
+ void CheckButtonClicked();
+
+private:
+ Ui::ScratchPad mUI;
+ MainWindow& mMainWindow;
+};
+
+/// @}
+
+#endif // SCRATCHPAD_H
diff --git a/gui/scratchpad.ui b/gui/scratchpad.ui
new file mode 100644
index 000000000..7543866d2
--- /dev/null
+++ b/gui/scratchpad.ui
@@ -0,0 +1,98 @@
+
+
+ ScratchPad
+
+
+
+ 0
+ 0
+ 500
+ 600
+
+
+
+ Scratchpad
+
+
+ -
+
+
+
+ Courier New
+ 10
+
+
+
+
+ -
+
+
+ 0
+
+
-
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+ -
+
+
+ filename
+
+
+
+ -
+
+
+ Check
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ Qt::Horizontal
+
+
+ QDialogButtonBox::Close
+
+
+
+
+
+
+
+
+
+
+ mButtonBox
+ rejected()
+ ScratchPad
+ reject()
+
+
+ 20
+ 20
+
+
+ 20
+ 20
+
+
+
+
+