Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: add command and history properties to ctkConsole #945

Merged
merged 1 commit into from
Dec 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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("");
pieper marked this conversation as resolved.
Show resolved Hide resolved
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