|
@@ -50,10 +50,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
// Qt includes
|
|
|
#include <QAbstractItemView>
|
|
|
+#include <QAction>
|
|
|
#include <QApplication>
|
|
|
#include <QClipboard>
|
|
|
#include <QCompleter>
|
|
|
#include <QKeyEvent>
|
|
|
+#include <QFile>
|
|
|
+#include <QFileDialog>
|
|
|
#include <QPointer>
|
|
|
#include <QTextCursor>
|
|
|
#include <QVBoxLayout>
|
|
@@ -124,6 +127,16 @@ void ctkConsolePrivate::init()
|
|
|
this->CommandHistory.append("");
|
|
|
this->CommandPosition = 0;
|
|
|
|
|
|
+ QAction* runFileAction = new QAction(q->tr("&Run file"),q);
|
|
|
+ runFileAction->setShortcut(q->tr("Ctrl+r"));
|
|
|
+ connect(runFileAction, SIGNAL(triggered()), q, SLOT(runFile()));
|
|
|
+ q->addAction(runFileAction);
|
|
|
+
|
|
|
+ QAction* printHelpAction = new QAction(q->tr("Print &help"),q);
|
|
|
+ printHelpAction->setShortcut(q->tr("Ctrl+h"));
|
|
|
+ connect(printHelpAction, SIGNAL(triggered()), q, SLOT(printHelp()));
|
|
|
+ q->addAction(printHelpAction);
|
|
|
+
|
|
|
QVBoxLayout * layout = new QVBoxLayout(q);
|
|
|
layout->setMargin(0);
|
|
|
layout->addWidget(this);
|
|
@@ -798,6 +811,41 @@ void ctkConsole::exec(const QString& command)
|
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
+void ctkConsole::runFile(const QString& filePath)
|
|
|
+{
|
|
|
+ QFile file(filePath);
|
|
|
+ if (!file.open(QIODevice::ReadOnly))
|
|
|
+ {
|
|
|
+ qWarning() << tr( "File '%1' can't be read.").arg(filePath);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (QTextStream fileStream(&file);!fileStream.atEnd();)
|
|
|
+ {
|
|
|
+ QString line = fileStream.readLine();
|
|
|
+ this->exec(line);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
+void ctkConsole::runFile()
|
|
|
+{
|
|
|
+ QString filePath =
|
|
|
+ QFileDialog::getOpenFileName(this, tr("Select a script file to run"));
|
|
|
+ if (!filePath.isEmpty())
|
|
|
+ {
|
|
|
+ this->runFile(filePath);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
+void ctkConsole::printHelp()
|
|
|
+{
|
|
|
+ this->printMessage("\n", Qt::gray);
|
|
|
+ this->printMessage(tr("CTRL+h: Print this help message\n"), Qt::gray);
|
|
|
+ this->printMessage(tr("CTRL+r: Oepn a file dialog to select a file to run\n"), Qt::gray);
|
|
|
+}
|
|
|
+
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
void ctkConsole::executeCommand(const QString& command)
|
|
|
{
|
|
|
qWarning() << "ctkConsole::executeCommand not implemented !";
|