Skip to content

Commit

Permalink
Merge pull request #945 from pieper/console-enh
Browse files Browse the repository at this point in the history
ENH: add command and history properties to ctkConsole
  • Loading branch information
pieper authored Dec 31, 2020
2 parents ac0cadf + 9413e18 commit 1f577aa
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Libs/Widgets/ctkConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,36 @@ void ctkConsole::setRunFileOptions(const RunFileOptions& newOptions)
d->RunFileAction->setEnabled(newOptions.testFlag(ctkConsole::RunFileShortcut));
}

//-----------------------------------------------------------------------------
const QString& ctkConsole::commandBuffer()
{
Q_D(ctkConsole);
return d->commandBuffer();
}

//-----------------------------------------------------------------------------
void ctkConsole::setCommandBuffer(const QString& command)
{
Q_D(ctkConsole);
d->replaceCommandBuffer(command);
}

//-----------------------------------------------------------------------------
const QStringList& ctkConsole::commandHistory()
{
Q_D(ctkConsole);
return d->CommandHistory;
}

//-----------------------------------------------------------------------------
void ctkConsole::setCommandHistory(const QStringList& commandHistory)
{
Q_D(ctkConsole);
d->CommandHistory = commandHistory;
d->CommandHistory.append("");
d->CommandPosition = d->CommandHistory.size()-1;
}

//-----------------------------------------------------------------------------
void ctkConsole::exec(const QString& command)
{
Expand Down
19 changes: 19 additions & 0 deletions Libs/Widgets/ctkConsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ class CTK_WIDGETS_EXPORT ctkConsole : public QWidget
Q_FLAGS(RunFileOption RunFileOptions)
Q_PROPERTY(RunFileOptions runFileOptions READ runFileOptions WRITE setRunFileOptions)
Q_PROPERTY(int maxVisibleCompleterItems READ maxVisibleCompleterItems WRITE setMaxVisibleCompleterItems)
Q_PROPERTY(QString commandBuffer READ commandBuffer WRITE setCommandBuffer)
Q_PROPERTY(QStringList commandHistory READ commandHistory WRITE setCommandHistory)

public:

Expand Down Expand Up @@ -226,6 +228,15 @@ class CTK_WIDGETS_EXPORT ctkConsole : public QWidget
/// \sa runFileOptions()
void setRunFileOptions(const RunFileOptions& newOptions);

/// Get the current command buffer (text on current input line, not yet executed)
/// \sa setCommandBuffer()
virtual const QString& commandBuffer();

/// Get the command history list (previously executed commands)
/// \sa commandBuffer()
/// \sa setCommandBuffer()
virtual const QStringList& commandHistory();

Q_SIGNALS:

/// This signal emitted before and after a command is executed
Expand All @@ -244,6 +255,14 @@ public Q_SLOTS:
/// Clears the contents of the console and display welcome message
virtual void reset();

/// Set the the command buffer (pending command for user)
/// \sa commandBuffer()
virtual void setCommandBuffer(const QString&);

/// Set the command history (e.g. if restored from file)
/// \sa commandHistory()
virtual void setCommandHistory(const QStringList&);

/// Exec the contents of the last console line
/// \sa openFile(), runFile(QString)
virtual void exec(const QString&);
Expand Down

0 comments on commit 1f577aa

Please sign in to comment.