Skip to content

Commit

Permalink
Don't add 'exec(Path(...))' entries to console history when running s…
Browse files Browse the repository at this point in the history
…cripts

These just clutter the history
  • Loading branch information
nyalldawson committed Mar 28, 2023
1 parent 85d4001 commit b9b06b0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion python/console/console_sci.py
Expand Up @@ -303,7 +303,7 @@ def runFile(self, filename):

try:
# Run the file
self.runCommand("exec(Path('{0}').read_text())".format(filename))
self.runCommand("exec(Path('{0}').read_text())".format(filename), skipHistory=True)
finally:
# Remove the directory from the path and delete the __file__ variable
self._interpreter.execCommandImpl("del __file__", False)
Expand Down
5 changes: 4 additions & 1 deletion python/gui/auto_generated/codeeditors/qgscodeeditor.sip.in
Expand Up @@ -329,12 +329,15 @@ is in the QgsCodeEditor.Mode.CommandInput mode.

public slots:

void runCommand( const QString &command );
void runCommand( const QString &command, bool skipHistory = false );
%Docstring
Runs a command in the editor.

An :py:func:`~QgsCodeEditor.interpreter` must be set.

Since QGIS 3.32, if ``skipHistory`` is ``True`` then the command will not be automatically
added to the widget's history.

.. versionadded:: 3.30
%End

Expand Down
5 changes: 3 additions & 2 deletions src/gui/codeeditors/qgscodeeditor.cpp
Expand Up @@ -758,9 +758,10 @@ QStringList QgsCodeEditor::history() const
return mHistory;
}

void QgsCodeEditor::runCommand( const QString &command )
void QgsCodeEditor::runCommand( const QString &command, bool skipHistory )
{
updateHistory( { command } );
if ( !skipHistory )
updateHistory( { command } );

if ( mInterpreter )
mInterpreter->exec( command );
Expand Down
5 changes: 4 additions & 1 deletion src/gui/codeeditors/qgscodeeditor.h
Expand Up @@ -366,9 +366,12 @@ class GUI_EXPORT QgsCodeEditor : public QsciScintilla
*
* An interpreter() must be set.
*
* Since QGIS 3.32, if \a skipHistory is TRUE then the command will not be automatically
* added to the widget's history.
*
* \since QGIS 3.30
*/
void runCommand( const QString &command );
void runCommand( const QString &command, bool skipHistory = false );

/**
* Moves the cursor to the start of the document and scrolls to ensure
Expand Down

0 comments on commit b9b06b0

Please sign in to comment.