1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
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
16 ** GNU Lesser General Public License Usage
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.
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.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #ifndef VCSBASE_SUBMITEDITOR_H
35 #define VCSBASE_SUBMITEDITOR_H
37 #include "vcsbase_global.h"
39 #include <coreplugin/editormanager/ieditor.h>
41 #include <QtGui/QAbstractItemView>
45 class QAbstractItemModel;
50 class SubmitEditorWidget;
55 struct CommonVcsSettings;
57 struct VCSBaseSubmitEditorPrivate;
59 /* Utility struct to parametrize a VCSBaseSubmitEditor. */
60 struct VCSBASE_EXPORT VCSBaseSubmitEditorParameters {
63 const char *displayName;
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
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
77 * For the given context, there must be only one instance of the editor
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
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. */
89 class VCSBASE_EXPORT VCSBaseSubmitEditor : public Core::IEditor
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)
100 explicit VCSBaseSubmitEditor(const VCSBaseSubmitEditorParameters *parameters,
101 Utils::SubmitEditorWidget *editorWidget);
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);
110 virtual ~VCSBaseSubmitEditor();
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,
122 bool forcePrompt = false,
123 bool canCommitOnFailure = true) const;
125 int fileNameColumn() const;
126 void setFileNameColumn(int c);
128 QAbstractItemView::SelectionMode fileListSelectionMode() const;
129 void setFileListSelectionMode(QAbstractItemView::SelectionMode sm);
131 // 'Commit' action enabled despite empty file list
132 bool isEmptyFileListEnabled() const;
133 void setEmptyFileListEnabled(bool e);
135 bool lineWrap() const;
136 void setLineWrap(bool);
138 int lineWrapWidth() const;
139 void setLineWrapWidth(int);
141 QString checkScriptWorkingDirectory() const;
142 void setCheckScriptWorkingDirectory(const QString &);
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;
154 virtual QWidget *toolBar();
155 virtual Core::Context context() const;
156 virtual QWidget *widget();
158 virtual QByteArray saveState() const;
159 virtual bool restoreState(const QByteArray &state);
161 QStringList checkedFiles() const;
163 void setFileModel(QAbstractItemModel *m);
164 QAbstractItemModel *fileModel() const;
166 // Utilities returning some predefined icons for actions
167 static QIcon diffIcon();
168 static QIcon submitIcon();
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);
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);
178 virtual bool isTemporary() const { return true; }
180 // Helper to raise an already open submit editor to prevent opening twice.
181 static bool raiseSubmitEditor();
184 void diffSelectedFiles(const QStringList &files);
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 &);
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);
203 void createUserFields(const QString &fieldConfigFile);
204 bool checkSubmitMessage(QString *errorMessage) const;
205 bool runSubmitMessageCheckScript(const QString &script, QString *errorMessage) const;
206 QString promptForNickName();
208 VCSBaseSubmitEditorPrivate *m_d;
211 } // namespace VCSBase
213 #endif // VCSBASE_SUBMITEDITOR_H