OSDN Git Service

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