OSDN Git Service

e694a8bb8f97aba5c0af969ceee70b8b78c6384f
[qt-creator-jp/qt-creator-jp.git] / src / plugins / git / gitplugin.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 GITPLUGIN_H
35 #define GITPLUGIN_H
36
37 #include "settingspage.h"
38 #include "vcsbase/vcsbaseplugin.h"
39
40 #include <coreplugin/editormanager/ieditorfactory.h>
41 #include <extensionsystem/iplugin.h>
42
43 #include <QtCore/QObject>
44 #include <QtCore/QProcess>
45 #include <QtCore/QStringList>
46 #include <QtCore/QPointer>
47 #include <QtCore/QPair>
48 #include <QtCore/QVector>
49
50 QT_BEGIN_NAMESPACE
51 class QFile;
52 class QAction;
53 class QFileInfo;
54 QT_END_NAMESPACE
55
56 namespace Core {
57 class IEditorFactory;
58 class ICore;
59 class Command;
60 class Context;
61 class ActionManager;
62 class ActionContainer;
63 }
64 namespace Utils {
65 class ParameterAction;
66 }
67 namespace Locator {
68     class CommandLocator;
69 }
70 namespace Git {
71 namespace Internal {
72
73 class GitPlugin;
74 class GitVersionControl;
75 class GitClient;
76 class ChangeSelectionDialog;
77 class GitSubmitEditor;
78 struct CommitData;
79 struct GitSettings;
80 class StashDialog;
81 class BranchDialog;
82
83 typedef void (GitClient::*GitClientMemberFunc)(const QString &);
84
85 typedef QPair<QAction *, Core::Command* > ActionCommandPair;
86 typedef QPair<Utils::ParameterAction *, Core::Command* > ParameterActionCommandPair;
87
88 class GitPlugin : public VCSBase::VCSBasePlugin
89 {
90     Q_OBJECT
91
92 public:
93     GitPlugin();
94     ~GitPlugin();
95
96     static GitPlugin *instance();
97
98     virtual bool initialize(const QStringList &arguments, QString *error_message);
99
100     GitVersionControl *gitVersionControl() const;
101
102     GitSettings settings() const;
103     void setSettings(const GitSettings &s);
104
105     GitClient *gitClient() const;
106
107 private slots:
108     void diffCurrentFile();
109     void diffCurrentProject();
110     void diffRepository();
111     void submitEditorDiff(const QStringList &unstaged, const QStringList &staged);
112     void submitCurrentLog();
113     void logFile();
114     void blameFile();
115     void logProject();
116     void undoFileChanges(bool revertStaging = true);
117     void undoUnstagedFileChanges();
118     void undoRepositoryChanges();
119     void stageFile();
120     void unstageFile();
121     void cleanProject();
122     void cleanRepository();
123     void applyCurrentFilePatch();
124     void promptApplyPatch();
125     void gitClientMemberFuncRepositoryAction();
126
127     void showCommit();
128     void startCommit();
129     void startAmendCommit();
130     void stash();
131     void stashSnapshot();
132     void branchList();
133     void stashList();
134     void fetch();
135     void pull();
136     void push();
137
138 protected:
139     virtual void updateActions(VCSBase::VCSBasePlugin::ActionState);
140     virtual bool submitEditorAboutToClose(VCSBase::VCSBaseSubmitEditor *submitEditor);
141
142 private:
143     inline ParameterActionCommandPair
144             createParameterAction(Core::ActionManager *am, Core::ActionContainer *ac,
145                                   const QString &defaultText, const QString &parameterText,
146                                   const QString &id, const Core::Context &context, bool addToLocator);
147
148     inline ParameterActionCommandPair
149             createFileAction(Core::ActionManager *am, Core::ActionContainer *ac,
150                              const QString &defaultText, const QString &parameterText,
151                              const QString &id, const Core::Context &context, bool addToLocator,
152                              const char *pluginSlot);
153
154     inline ParameterActionCommandPair
155             createProjectAction(Core::ActionManager *am, Core::ActionContainer *ac,
156                                 const QString &defaultText, const QString &parameterText,
157                                 const QString &id, const Core::Context &context, bool addToLocator);
158
159     inline ParameterActionCommandPair
160                 createProjectAction(Core::ActionManager *am, Core::ActionContainer *ac,
161                                     const QString &defaultText, const QString &parameterText,
162                                     const QString &id, const Core::Context &context, bool addToLocator,
163                                     const char *pluginSlot);
164
165
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);
177
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);
184
185     static GitPlugin *m_instance;
186     Core::ICore *m_core;
187     Locator::CommandLocator *m_commandLocator;
188     QAction *m_createRepositoryAction;
189
190     QAction *m_showAction;
191
192     QAction *m_submitCurrentAction;
193     QAction *m_diffSelectedFilesAction;
194     QAction *m_undoAction;
195     QAction *m_redoAction;
196     QAction *m_menuAction;
197
198     QVector<Utils::ParameterAction *> m_fileActions;
199     QVector<Utils::ParameterAction *> m_projectActions;
200     QVector<QAction *> m_repositoryActions;
201     Utils::ParameterAction *m_applyCurrentFilePatchAction;
202
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;
213
214 };
215
216 } // namespace Git
217 } // namespace Internal
218
219 #endif // GITPLUGIN_H