1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #ifndef REFACTORINGCHANGES_H
34 #define REFACTORINGCHANGES_H
36 #include <utils/changeset.h>
37 #include <texteditor/texteditor_global.h>
39 #include <QtCore/QList>
40 #include <QtCore/QString>
42 QT_FORWARD_DECLARE_CLASS(QTextDocument)
44 namespace TextEditor {
45 class BaseTextEditorWidget;
46 class RefactoringChanges;
48 class TEXTEDITOR_EXPORT RefactoringFile
51 typedef Utils::ChangeSet::Range Range;
55 RefactoringFile(const QString &fileName, RefactoringChanges *refactoringChanges);
56 RefactoringFile(const RefactoringFile &other);
57 virtual ~RefactoringFile();
61 const QTextDocument *document() const;
62 const QTextCursor cursor() const;
63 QString fileName() const;
65 // converts 1-based line and column into 0-based offset
66 int position(unsigned line, unsigned column) const;
68 QChar charAt(int pos) const;
69 QString textOf(int start, int end) const;
70 QString textOf(const Range &range) const;
72 bool change(const Utils::ChangeSet &changeSet, bool openEditor = true);
73 bool indent(const Range &range, bool openEditor = true);
77 //const RefactoringFile &operator=(const RefactoringFile &other);
79 QTextDocument *mutableDocument() const;
83 RefactoringChanges *m_refactoringChanges;
84 mutable QTextDocument *m_document;
85 BaseTextEditorWidget *m_editor;
86 Utils::ChangeSet m_changes;
87 QList<Range> m_indentRanges;
92 This class batches changes to multiple file, which are applied as a single big
95 class TEXTEDITOR_EXPORT RefactoringChanges
98 typedef Utils::ChangeSet::Range Range;
101 RefactoringChanges();
102 virtual ~RefactoringChanges();
104 bool createFile(const QString &fileName, const QString &contents, bool reindent = true, bool openEditor = true);
105 bool removeFile(const QString &fileName);
107 RefactoringFile file(const QString &fileName);
109 BaseTextEditorWidget *openEditor(const QString &fileName, int pos = -1);
112 \param fileName the file to activate the editor for
113 \param line the line to put the cursor on (1-based)
114 \param column the column to put the cursor on (1-based)
116 void activateEditor(const QString &fileName, int line, int column);
120 static BaseTextEditorWidget *editorForFile(const QString &fileName,
121 bool openIfClosed = false);
123 static QList<QTextCursor> rangesToSelections(QTextDocument *document, const QList<Range> &ranges);
124 virtual void indentSelection(const QTextCursor &selection,
125 const QString &fileName,
126 const BaseTextEditorWidget *textEditor) const = 0;
127 virtual void fileChanged(const QString &fileName) = 0;
129 friend class RefactoringFile;
132 QString m_fileToOpen;
137 } // namespace TextEditor
139 #endif // REFACTORINGCHANGES_H