forked from jesperhh/teamfoundation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathteamfoundationplugin.cpp
More file actions
285 lines (231 loc) · 10.7 KB
/
teamfoundationplugin.cpp
File metadata and controls
285 lines (231 loc) · 10.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
/****************************************************************************
**
** Team Foundation Server plugin for Qt Creator
** Copyright (C) 2014 Jesper Hellesø Hansen
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License as published by the Free Software Foundation; either
** version 2.1 of the License, or (at your option) any later version.
**
** This library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public
** License along with this library; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
**
****************************************************************************/
#include "teamfoundationplugin.h"
#include "teamfoundationconstants.h"
#include "teamfoundationcontrol.h"
#include "teamfoundationclient.h"
#include "settingspage.h"
#include <coreplugin/icore.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/locator/commandlocator.h>
#include <QMenu>
#include <QFileInfo>
#include <utils/qtcassert.h>
#include <utils/parameteraction.h>
using namespace TeamFoundation::Internal;
const char TEAMFOUNDATION_CONTEXT[] = "Team Foundation Context";
TeamFoundationPlugin *TeamFoundationPlugin::m_teamFoundationPluginInstance = 0;
TeamFoundationPlugin::TeamFoundationPlugin()
{
// Create your members
}
TeamFoundationPlugin::~TeamFoundationPlugin()
{
// Unregister objects from the plugin manager's object pool
// Delete members
}
QAction* TeamFoundationPlugin::createFileAction(const Core::Context &context, Core::ActionContainer* container,
const QString &emptyText, const QString ¶meterText, const char *actionId)
{
Utils::ParameterAction *action = new Utils::ParameterAction(
emptyText, parameterText, Utils::ParameterAction::EnabledWithParameter, this);
Core::Command *command = Core::ActionManager::registerAction(action, Core::Id(actionId), context);
command->setAttribute(Core::Command::CA_UpdateText);
container->addAction(command);
m_commandLocator->appendCommand(command);
m_fileActionList.append(action);
return (action);
}
QAction* TeamFoundationPlugin::createRepositoryAction(Core::ActionContainer* container, Core::Context context,
const QString &actionText, const char *actionId)
{
QAction *action = new QAction(actionText, this);
m_projectActionList.append(action);
Core::Command *command = Core::ActionManager::registerAction(action, Core::Id(actionId), context);
m_commandLocator->appendCommand(command);
container->addAction(command);
return action;
}
void TeamFoundationPlugin::createMenus(const Core::Context &context)
{
Core::ActionContainer* container = Core::ActionManager::createMenu(Core::Id(Constants::MENU_ID));
const QString prefix = QLatin1String("tfs");
m_commandLocator = new Core::CommandLocator("Team Foundation", prefix, prefix);
addAutoReleasedObject(m_commandLocator);
QAction* action;
action = createFileAction(context, container, tr("Add current file"), tr("Add %1"), "TeamFoundation.Add");
connect(action, SIGNAL(triggered()), m_teamFoundationClient, SLOT(addCurrentFile()));
action = createFileAction(context, container, tr("Delete current file"), tr("Delete %1"), "TeamFoundation.Delete");
connect(action, SIGNAL(triggered()), m_teamFoundationClient, SLOT(deleteCurrentFile()));
action = createFileAction(context, container, tr("Compare current file"), tr("Compare %1"), "TeamFoundation.Compare");
connect(action, SIGNAL(triggered()), m_teamFoundationClient, SLOT(compareCurrentFile()));
action = createFileAction(context, container, tr("Undo current file"), tr("Undo %1"), "TeamFoundation.Undo");
connect(action, SIGNAL(triggered()), m_teamFoundationClient, SLOT(undoCurrentFile()));
action = createFileAction(context, container, tr("Check in current file"), tr("Check In %1"), "TeamFoundation.CheckIn");
connect(action, SIGNAL(triggered()), m_teamFoundationClient, SLOT(checkInCurrentFile()));
action = createFileAction(context, container, tr("Annotate current file"), tr("Annotate %1"), "TeamFoundation.Annotate");
connect(action, SIGNAL(triggered()), m_teamFoundationClient, SLOT(annotateCurrentFile()));
action = createFileAction(context, container, tr("History..."), tr("History for %1"), "TeamFoundation.History");
connect(action, SIGNAL(triggered()), m_teamFoundationClient, SLOT(historyCurrentFile()));
action = createFileAction(context, container, tr("Get latest..."), tr("Get latest %1"), "TeamFoundation.GetLatest");
connect(action, SIGNAL(triggered()), m_teamFoundationClient, SLOT(getLatestCurrentFile()));
container->addSeparator(context);
action = createRepositoryAction(container, context, tr("History (Repository)"), "TeamFoundation.HistoryProject");
connect(action, SIGNAL(triggered()), m_teamFoundationClient, SLOT(historyProject()));
action = createRepositoryAction(container, context, tr("Get latest (Repository)"), "TeamFoundation.GetLatestProject");
connect(action, SIGNAL(triggered()), m_teamFoundationClient, SLOT(getLatestProject()));
action = createRepositoryAction(container, context, tr("Undo (Repository)"), "TeamFoundation.UndoProject");
connect(action, SIGNAL(triggered()), m_teamFoundationClient, SLOT(undoProject()));
action = createRepositoryAction(container, context, tr("Compare (Repository)"), "TeamFoundation.CompareProject");
connect(action, SIGNAL(triggered()), m_teamFoundationClient, SLOT(compareProject()));
action = createRepositoryAction(container, context, tr("Check in (Repository)"), "TeamFoundation.CheckInProject");
connect(action, SIGNAL(triggered()), m_teamFoundationClient, SLOT(checkInProject()));
Core::ActionContainer *toolsMenu = Core::ActionManager::actionContainer(Core::Id(Core::Constants::M_TOOLS));
toolsMenu->addMenu(container);
QMenu *menu = container->menu();
menu->setTitle(tr("Team Foundation"));
m_menuAction = menu->menuAction();
}
bool TeamFoundationPlugin::initialize(const QStringList &arguments, QString *errorString)
{
Q_UNUSED(arguments)
Q_UNUSED(errorString)
Core::Context context(TEAMFOUNDATION_CONTEXT);
initializeVcs(new TeamFoundationControl(this), context);
m_teamFoundationPluginInstance = this;
m_settings.readSettings(Core::ICore::settings());
m_teamFoundationClient = new TeamFoundationClient(this);
addAutoReleasedObject(new SettingsPage);
createMenus(context);
return true;
}
TeamFoundationPlugin *TeamFoundationPlugin::instance()
{
QTC_ASSERT(m_teamFoundationPluginInstance, return m_teamFoundationPluginInstance);
return m_teamFoundationPluginInstance;
}
void TeamFoundationPlugin::emitChangedSignal(const QString &path) const
{
TeamFoundationControl* control = static_cast<TeamFoundationControl*>(versionControl());
QFileInfo info(path);
if (info.isFile())
{
control->emitFilesChanged(QStringList(path));
}
else if (info.isDir())
{
control->emitRepositoryChanged(path);
}
else if (path.isEmpty())
{
control->emitConfigurationChanged();
}
}
TeamFoundationSettings TeamFoundationPlugin::settings() const
{
return this->m_settings;
}
void TeamFoundationPlugin::setSettings(const TeamFoundationSettings &s)
{
if (s != m_settings) {
m_settings = s;
m_settings.writeSettings(Core::ICore::settings());
emitChangedSignal(QString());
}
}
const TeamFoundationClient *TeamFoundationPlugin::client() const
{
return this->m_teamFoundationClient;
}
bool TeamFoundationPlugin::submitEditorAboutToClose()
{
return true;
}
void TeamFoundationPlugin::updateActions(VcsBase::VcsBasePlugin::ActionState as)
{
if (!enableMenuAction(as, m_menuAction))
{
m_commandLocator->setEnabled(false);
return;
}
const bool hasTopLevel = currentState().hasTopLevel();
m_commandLocator->setEnabled(hasTopLevel);
const QString currentFile = currentState().currentFileName();
QList<Utils::ParameterAction*>::iterator iter;
for (iter = m_fileActionList.begin(); iter != m_fileActionList.end(); ++iter)
{
(*iter)->setParameter(currentFile);
}
}
#ifdef WITH_TESTS
#include <QTest>
void TeamFoundationPlugin::testGetRepositoryUrl_data()
{
QTest::addColumn<QString>("info_output");
QTest::addColumn<QString>("result");
QTest::newRow("Success 1")
<< QString(QLatin1String(
"Local information:\n"
" Local path :C:\\Code\\PluginTest\n"
" Server path:$/PluginTest\n"
" Changeset :2\n"
" Change :none\n"
" Type :folder\n"
"Server information:\n"
" Server path : $/PluginTest\n"
" Changeset : 2\n"
" Deletion ID : 0\n"
" Lock : none\n"
" Lock owner : \n"
" Last modified: 16. januar 2014 23:41:47\n"
" Type : folder\n"))
<< QString(QLatin1String ("$/PluginTest"));
QTest::newRow("Success 2")
<< QString(QLatin1String(
"Local information:\n"
" Local path : C:\\Code\\PluginTest\n"
" Server path : $/Plugin Test\n"
" Changeset : 2\n"
" Change : none\n"
" Type : folder\n"
"Server information:\n"
" Server path : $/PluginTest\n"
" Changeset : 2\n"
" Deletion ID : 0\n"
" Lock : none\n"
" Lock owner : \n"
" Last modified: 16. januar 2014 23:41:47\n"
" Type : folder\n"))
<< QString(QLatin1String ("$/PluginTest"));
QTest::newRow("Failure")
<< QString(QLatin1String("There is no working folder mapping for C:\\Code\\PluginTest\n"))
<< QString(QLatin1String (""));
}
void TeamFoundationPlugin::testGetRepositoryUrl()
{
QFETCH(QString, info_output);
QFETCH(QString, result);
const QString output = TeamFoundationClient::getRepositoryUrl(info_output);
QCOMPARE(output, result);
}
#endif