OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / texteditor / refactoringchanges.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
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.
18 **
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.
22 **
23 ** Other Usage
24 **
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.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #ifndef REFACTORINGCHANGES_H
34 #define REFACTORINGCHANGES_H
35
36 #include <utils/changeset.h>
37 #include <texteditor/texteditor_global.h>
38
39 #include <QtCore/QList>
40 #include <QtCore/QString>
41
42 QT_FORWARD_DECLARE_CLASS(QTextDocument)
43
44 namespace TextEditor {
45 class BaseTextEditorWidget;
46 class RefactoringChanges;
47
48 class TEXTEDITOR_EXPORT RefactoringFile
49 {
50 public:
51     typedef Utils::ChangeSet::Range Range;
52
53 public:
54     RefactoringFile();
55     RefactoringFile(const QString &fileName, RefactoringChanges *refactoringChanges);
56     RefactoringFile(const RefactoringFile &other);
57     virtual ~RefactoringFile();
58
59     bool isValid() const;
60
61     const QTextDocument *document() const;
62     const QTextCursor cursor() const;
63     QString fileName() const;
64
65     // converts 1-based line and column into 0-based offset
66     int position(unsigned line, unsigned column) const;
67
68     QChar charAt(int pos) const;
69     QString textOf(int start, int end) const;
70     QString textOf(const Range &range) const;
71
72     bool change(const Utils::ChangeSet &changeSet, bool openEditor = true);
73     bool indent(const Range &range, bool openEditor = true);
74
75 protected:
76     // not assignable
77     //const RefactoringFile &operator=(const RefactoringFile &other);
78
79     QTextDocument *mutableDocument() const;
80
81 protected:
82     QString m_fileName;
83     RefactoringChanges *m_refactoringChanges;
84     mutable QTextDocument *m_document;
85     BaseTextEditorWidget *m_editor;
86     Utils::ChangeSet m_changes;
87     QList<Range> m_indentRanges;
88     bool m_openEditor;
89 };
90
91  /*!
92     This class batches changes to multiple file, which are applied as a single big
93     change.
94  */
95 class TEXTEDITOR_EXPORT RefactoringChanges
96 {
97 public:
98     typedef Utils::ChangeSet::Range Range;
99
100 public:
101     RefactoringChanges();
102     virtual ~RefactoringChanges();
103
104     bool createFile(const QString &fileName, const QString &contents, bool reindent = true, bool openEditor = true);
105     bool removeFile(const QString &fileName);
106
107     RefactoringFile file(const QString &fileName);
108
109     BaseTextEditorWidget *openEditor(const QString &fileName, int pos = -1);
110
111     /*!
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)
115      */
116     void activateEditor(const QString &fileName, int line, int column);
117
118
119 private:
120     static BaseTextEditorWidget *editorForFile(const QString &fileName,
121                                          bool openIfClosed = false);
122
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;
128
129     friend class RefactoringFile;
130
131 private:
132     QString m_fileToOpen;
133     int m_lineToOpen;
134     int m_columnToOpen;
135 };
136
137 } // namespace TextEditor
138
139 #endif // REFACTORINGCHANGES_H