File: undo_change_script.h

package info (click to toggle)
antimony 0.9.3-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,476 kB
  • sloc: cpp: 42,596; ansic: 28,661; python: 1,093; yacc: 128; lex: 114; sh: 90; makefile: 10
file content (48 lines) | stat: -rw-r--r-- 1,077 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#pragma once

#include <Python.h>

#include <QString>
#include <QPointer>
#include <QPlainTextEdit>

#include "undo/undo_command.h"

class ScriptNode;

class UndoChangeScript: public UndoCommand
{
public:
    /*
     *  Constructs an undo command that reverses a change to a script
     */
    UndoChangeScript(ScriptNode* n, QString before, QString after,
                     QPlainTextEdit* editor,
                     int cursor_before, int cursor_after);

    void redo() override;
    void undo() override;

    void swapPointer(Node* a, Node* b) const override;

protected:
    /*
     *  If we have a valid QPlainTextEdit pointer,
     *  set its cursor to the given position.
     */
    void setCursor(int pos);

    mutable ScriptNode* node;
    QString before;
    QString after;

    /*
     *  Store a QPointer to the relevant text document.
     *
     *  If the window is closed, the pointer will be set to NULL;
     *  this needs to be checked whenever it is used.
     */
    QPointer<QPlainTextEdit> editor;
    int cursor_before;
    int cursor_after;
};