Skip to content

Add Undo/Redo framework the the Python Editor

This PR adds the undo/redo feature to the python text editor. Several changes had to be made since I couldn't use the native undo/redo framework from the QTextEdit widget. The reason why comes from the pqPythonSyntaxHighlighter which calls the setHtml method to highlight the text which itself wipes the undo/redo history of the QTextEdit widget.

The solution adopted here is a custom undo/redo stack using the QUndoStack and QUndoCommand from Qt. The logic behind the highlight features also changed: the pqPythonSyntaxHighlighter doesn't automatically connect itself to the QTextEdit it acts on. Instead, a new method is provided to mimic the old behavior (which is called in some places in the code to connect the QTextEdit to the highlighter). For the pqPythonTextEditor, the syntax highlighter is called by the undo/redo command, which allows storing only the raw text rather than the full html pygment output.

For incoming mr, I also integrated a refactoring of the save file framework. The disk interaction of the editor widget is now encapsulated into its own class and attached to the pqPythonTextArea rather than the QMainWindow widget. This will be necessary when implementing the multiple tab behavior, where we will want to have different saving context for different tabs.

This mr is splitted into four commits:

Note: I had to change some test XMLs as the SaveFileDialog position in the hierarchy changed.

@keu-sciviz

Edited by Thomas Caissard

Merge request reports