OSDN Git Service

74f0f49d3a4c966113a282f32eeb9f4c00919a74
[qt-creator-jp/qt-creator-jp.git] / src / plugins / vcsbase / vcsbasesubmiteditor.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 (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #ifndef VCSBASE_SUBMITEDITOR_H
35 #define VCSBASE_SUBMITEDITOR_H
36
37 #include "vcsbase_global.h"
38
39 #include <coreplugin/editormanager/ieditor.h>
40
41 #include <QtGui/QAbstractItemView>
42
43 QT_BEGIN_NAMESPACE
44 class QIcon;
45 class QAbstractItemModel;
46 class QAction;
47 QT_END_NAMESPACE
48
49 namespace Utils {
50     class SubmitEditorWidget;
51 }
52
53 namespace VCSBase {
54 namespace Internal {
55     struct CommonVcsSettings;
56 }
57 struct VCSBaseSubmitEditorPrivate;
58
59 /* Utility struct to parametrize a VCSBaseSubmitEditor. */
60 struct VCSBASE_EXPORT VCSBaseSubmitEditorParameters {
61     const char *mimeType;
62     const char *id;
63     const char *displayName;
64     const char *context;
65 };
66
67 /* Base class for a submit editor based on the Utils::SubmitEditorWidget
68  * that presents the commit message in a text editor and an
69  * checkable list of modified files in a list window. The user can delete
70  * files from the list by pressing unchecking them or diff the selection
71  * by doubleclicking.
72  *
73  * The action matching the the ids (unless 0) of the parameter struct will be
74  * registered with the EditorWidget and submit/diff actions will be added to
75  * a toolbar.
76  *
77  * For the given context, there must be only one instance of the editor
78  * active.
79  * To start a submit, set the submit template on the editor and the output
80  * of the VCS status command listing the modified files as fileList and open
81  * it.
82  * The submit process is started by listening on the editor close
83  * signal and then asking the IFile interface of the editor to save the file
84  * within a IFileManager::blockFileChange() section
85  * and to launch the submit process. In addition, the action registered
86  * for submit should be connected to a slot triggering the close of the
87  * current editor in the editor manager. */
88
89 class VCSBASE_EXPORT VCSBaseSubmitEditor : public Core::IEditor
90 {
91     Q_OBJECT
92     Q_PROPERTY(int fileNameColumn READ fileNameColumn WRITE setFileNameColumn DESIGNABLE false)
93     Q_PROPERTY(QAbstractItemView::SelectionMode fileListSelectionMode READ fileListSelectionMode WRITE setFileListSelectionMode DESIGNABLE true)
94     Q_PROPERTY(bool lineWrap READ lineWrap WRITE setLineWrap DESIGNABLE true)
95     Q_PROPERTY(int lineWrapWidth READ lineWrapWidth WRITE setLineWrapWidth DESIGNABLE true)
96     Q_PROPERTY(QString checkScriptWorkingDirectory READ checkScriptWorkingDirectory WRITE setCheckScriptWorkingDirectory DESIGNABLE true)
97     Q_PROPERTY(bool emptyFileListEnabled READ isEmptyFileListEnabled WRITE setEmptyFileListEnabled DESIGNABLE true)
98
99 protected:
100     explicit VCSBaseSubmitEditor(const VCSBaseSubmitEditorParameters *parameters,
101                                  Utils::SubmitEditorWidget *editorWidget);
102
103 public:
104     // Register the actions with the submit editor widget.
105     void registerActions(QAction *editorUndoAction,  QAction *editorRedoAction,
106                          QAction *submitAction = 0, QAction *diffAction = 0);
107     void unregisterActions(QAction *editorUndoAction,  QAction *editorRedoAction,
108                            QAction *submitAction = 0, QAction *diffAction = 0);
109
110     virtual ~VCSBaseSubmitEditor();
111
112     // A utility routine to be called when closing a submit editor.
113     // Runs checks on the message and prompts according to configuration.
114     // Force prompt should be true if it is invoked by closing an editor
115     // as opposed to invoking the "Submit" button.
116     // 'promptSetting' points to a bool variable containing the plugin's
117     // prompt setting. The user can uncheck it from the message box.
118     enum PromptSubmitResult { SubmitConfirmed, SubmitCanceled, SubmitDiscarded };
119     PromptSubmitResult promptSubmit(const QString &title, const QString &question,
120                                     const QString &checkFailureQuestion,
121                                     bool *promptSetting,
122                                     bool forcePrompt = false,
123                                     bool canCommitOnFailure = true) const;
124
125     int fileNameColumn() const;
126     void setFileNameColumn(int c);
127
128     QAbstractItemView::SelectionMode fileListSelectionMode() const;
129     void setFileListSelectionMode(QAbstractItemView::SelectionMode sm);
130
131     // 'Commit' action enabled despite empty file list
132     bool isEmptyFileListEnabled() const;
133     void setEmptyFileListEnabled(bool e);
134
135     bool lineWrap() const;
136     void setLineWrap(bool);
137
138     int lineWrapWidth() const;
139     void setLineWrapWidth(int);
140
141     QString checkScriptWorkingDirectory() const;
142     void setCheckScriptWorkingDirectory(const QString &);
143
144     // Core::IEditor
145     virtual bool createNew(const QString &contents);
146     virtual bool open(const QString &fileName);
147     virtual Core::IFile *file();
148     virtual QString displayName() const;
149     virtual void setDisplayName(const QString &title);
150     virtual bool duplicateSupported() const;
151     virtual Core::IEditor *duplicate(QWidget * parent);
152     virtual QString id() const;
153
154     virtual QWidget *toolBar();
155     virtual Core::Context context() const;
156     virtual QWidget *widget();
157
158     virtual QByteArray saveState() const;
159     virtual bool restoreState(const QByteArray &state);
160
161     QStringList checkedFiles() const;
162
163     void setFileModel(QAbstractItemModel *m);
164     QAbstractItemModel *fileModel() const;
165
166     // Utilities returning some predefined icons for actions
167     static QIcon diffIcon();
168     static QIcon submitIcon();
169
170     // Utility returning all project files in case submit lists need to
171     // be restricted to them
172     static QStringList currentProjectFiles(bool nativeSeparators, QString *name = 0);
173
174     // Reduce a list of untracked files reported by a VCS down to the files
175     // that are actually part of the current project(s).
176     static void filterUntrackedFilesOfProject(const QString &repositoryDirectory, QStringList *untrackedFiles);
177
178     virtual bool isTemporary() const { return true; }
179
180     // Helper to raise an already open submit editor to prevent opening twice.
181     static bool raiseSubmitEditor();
182
183 signals:
184     void diffSelectedFiles(const QStringList &files);
185
186 private slots:
187     void slotDiffSelectedVCSFiles(const QStringList &rawList);
188     bool save(const QString &fileName);
189     void slotDescriptionChanged();
190     void slotCheckSubmitMessage();
191     void slotInsertNickName();
192     void slotSetFieldNickName(int);
193     void slotUpdateEditorSettings(const VCSBase::Internal::CommonVcsSettings &);
194
195 protected:
196     /* These hooks allow for modifying the contents that goes to
197      * the file. The default implementation uses the text
198      * of the description editor. */
199     virtual QString fileContents() const;
200     virtual bool setFileContents(const QString &contents);
201
202 private:
203     void createUserFields(const QString &fieldConfigFile);
204     bool checkSubmitMessage(QString *errorMessage) const;
205     bool runSubmitMessageCheckScript(const QString &script, QString *errorMessage) const;
206     QString promptForNickName();
207
208     VCSBaseSubmitEditorPrivate *m_d;
209 };
210
211 } // namespace VCSBase
212
213 #endif // VCSBASE_SUBMITEDITOR_H