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 **************************************************************************/
37 #include "settingspage.h"
38 #include "vcsbase/vcsbaseplugin.h"
40 #include <coreplugin/editormanager/ieditorfactory.h>
41 #include <extensionsystem/iplugin.h>
43 #include <QtCore/QObject>
44 #include <QtCore/QProcess>
45 #include <QtCore/QStringList>
46 #include <QtCore/QPointer>
47 #include <QtCore/QPair>
48 #include <QtCore/QVector>
62 class ActionContainer;
65 class ParameterAction;
74 class GitVersionControl;
76 class ChangeSelectionDialog;
77 class GitSubmitEditor;
83 typedef void (GitClient::*GitClientMemberFunc)(const QString &);
85 typedef QPair<QAction *, Core::Command* > ActionCommandPair;
86 typedef QPair<Utils::ParameterAction *, Core::Command* > ParameterActionCommandPair;
88 class GitPlugin : public VCSBase::VCSBasePlugin
96 static GitPlugin *instance();
98 virtual bool initialize(const QStringList &arguments, QString *error_message);
100 GitVersionControl *gitVersionControl() const;
102 GitSettings settings() const;
103 void setSettings(const GitSettings &s);
105 GitClient *gitClient() const;
108 void diffCurrentFile();
109 void diffCurrentProject();
110 void diffRepository();
111 void submitEditorDiff(const QStringList &unstaged, const QStringList &staged);
112 void submitCurrentLog();
116 void undoFileChanges(bool revertStaging = true);
117 void undoUnstagedFileChanges();
118 void undoRepositoryChanges();
122 void cleanRepository();
123 void applyCurrentFilePatch();
124 void promptApplyPatch();
125 void gitClientMemberFuncRepositoryAction();
129 void startAmendCommit();
131 void stashSnapshot();
139 virtual void updateActions(VCSBase::VCSBasePlugin::ActionState);
140 virtual bool submitEditorAboutToClose(VCSBase::VCSBaseSubmitEditor *submitEditor);
143 inline ParameterActionCommandPair
144 createParameterAction(Core::ActionManager *am, Core::ActionContainer *ac,
145 const QString &defaultText, const QString ¶meterText,
146 const QString &id, const Core::Context &context, bool addToLocator);
148 inline ParameterActionCommandPair
149 createFileAction(Core::ActionManager *am, Core::ActionContainer *ac,
150 const QString &defaultText, const QString ¶meterText,
151 const QString &id, const Core::Context &context, bool addToLocator,
152 const char *pluginSlot);
154 inline ParameterActionCommandPair
155 createProjectAction(Core::ActionManager *am, Core::ActionContainer *ac,
156 const QString &defaultText, const QString ¶meterText,
157 const QString &id, const Core::Context &context, bool addToLocator);
159 inline ParameterActionCommandPair
160 createProjectAction(Core::ActionManager *am, Core::ActionContainer *ac,
161 const QString &defaultText, const QString ¶meterText,
162 const QString &id, const Core::Context &context, bool addToLocator,
163 const char *pluginSlot);
166 inline ActionCommandPair createRepositoryAction(Core::ActionManager *am, Core::ActionContainer *ac,
167 const QString &text, const QString &id,
168 const Core::Context &context, bool addToLocator);
169 inline ActionCommandPair createRepositoryAction(Core::ActionManager *am, Core::ActionContainer *ac,
170 const QString &text, const QString &id,
171 const Core::Context &context,
172 bool addToLocator, const char *pluginSlot);
173 inline ActionCommandPair createRepositoryAction(Core::ActionManager *am, Core::ActionContainer *ac,
174 const QString &text, const QString &id,
175 const Core::Context &context,
176 bool addToLocator, GitClientMemberFunc);
178 bool isCommitEditorOpen() const;
179 Core::IEditor *openSubmitEditor(const QString &fileName, const CommitData &cd, bool amend);
180 void cleanCommitMessageFile();
181 void cleanRepository(const QString &directory);
182 void applyPatch(const QString &workingDirectory, QString file = QString());
183 void startCommit(bool amend);
185 static GitPlugin *m_instance;
187 Locator::CommandLocator *m_commandLocator;
188 QAction *m_createRepositoryAction;
190 QAction *m_showAction;
192 QAction *m_submitCurrentAction;
193 QAction *m_diffSelectedFilesAction;
194 QAction *m_undoAction;
195 QAction *m_redoAction;
196 QAction *m_menuAction;
198 QVector<Utils::ParameterAction *> m_fileActions;
199 QVector<Utils::ParameterAction *> m_projectActions;
200 QVector<QAction *> m_repositoryActions;
201 Utils::ParameterAction *m_applyCurrentFilePatchAction;
203 GitClient *m_gitClient;
204 ChangeSelectionDialog *m_changeSelectionDialog;
205 QPointer<StashDialog> m_stashDialog;
206 QPointer<BranchDialog> m_branchDialog;
207 QString m_submitRepository;
208 QStringList m_submitOrigCommitFiles;
209 QStringList m_submitOrigDeleteFiles;
210 QString m_commitMessageFileName;
211 QString m_commitAmendSHA1;
212 bool m_submitActionTriggered;
217 } // namespace Internal
219 #endif // GITPLUGIN_H