Chris@57
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
jtkorhonen@0
|
2
|
Chris@57
|
3 /*
|
Chris@57
|
4 EasyMercurial
|
Chris@57
|
5
|
Chris@98
|
6 Based on hgExplorer by Jari Korhonen
|
Chris@57
|
7 Copyright (c) 2010 Jari Korhonen
|
Chris@244
|
8 Copyright (c) 2011 Chris Cannam
|
Chris@244
|
9 Copyright (c) 2011 Queen Mary, University of London
|
Chris@57
|
10
|
Chris@57
|
11 This program is free software; you can redistribute it and/or
|
Chris@57
|
12 modify it under the terms of the GNU General Public License as
|
Chris@57
|
13 published by the Free Software Foundation; either version 2 of the
|
Chris@57
|
14 License, or (at your option) any later version. See the file
|
Chris@57
|
15 COPYING included with this distribution for more information.
|
Chris@57
|
16 */
|
Chris@50
|
17
|
jtkorhonen@0
|
18 #include <QStringList>
|
jtkorhonen@0
|
19 #include <QDir>
|
jtkorhonen@24
|
20 #include <QNetworkInterface>
|
jtkorhonen@17
|
21 #include <QHostAddress>
|
jtkorhonen@17
|
22 #include <QHostInfo>
|
jtkorhonen@34
|
23 #include <QDesktopServices>
|
Chris@50
|
24 #include <QStatusBar>
|
Chris@50
|
25 #include <QMessageBox>
|
Chris@50
|
26 #include <QMenuBar>
|
Chris@50
|
27 #include <QApplication>
|
Chris@50
|
28 #include <QToolBar>
|
Chris@61
|
29 #include <QToolButton>
|
Chris@50
|
30 #include <QSettings>
|
Chris@90
|
31 #include <QInputDialog>
|
Chris@359
|
32 #include <QWidgetAction>
|
Chris@125
|
33 #include <QRegExp>
|
Chris@199
|
34 #include <QShortcut>
|
Chris@237
|
35 #include <QUrl>
|
Chris@476
|
36 #include <QDialogButtonBox>
|
Chris@238
|
37 #include <QTimer>
|
Chris@494
|
38 #include <QTextBrowser>
|
jtkorhonen@0
|
39
|
Chris@53
|
40 #include "mainwindow.h"
|
Chris@69
|
41 #include "multichoicedialog.h"
|
Chris@64
|
42 #include "startupdialog.h"
|
Chris@53
|
43 #include "colourset.h"
|
Chris@62
|
44 #include "debug.h"
|
Chris@74
|
45 #include "logparser.h"
|
Chris@103
|
46 #include "confirmcommentdialog.h"
|
Chris@125
|
47 #include "incomingdialog.h"
|
Chris@175
|
48 #include "settingsdialog.h"
|
Chris@275
|
49 #include "moreinformationdialog.h"
|
Chris@331
|
50 #include "annotatedialog.h"
|
Chris@229
|
51 #include "version.h"
|
Chris@287
|
52 #include "workstatuswidget.h"
|
Chris@414
|
53 #include "hgignoredialog.h"
|
Chris@491
|
54 #include "versiontester.h"
|
Chris@540
|
55 #include "fswatcher.h"
|
Chris@554
|
56 #include "findwidget.h"
|
Chris@53
|
57
|
jtkorhonen@0
|
58
|
Chris@172
|
59 MainWindow::MainWindow(QString myDirPath) :
|
Chris@238
|
60 m_myDirPath(myDirPath),
|
Chris@540
|
61 m_helpDialog(0)
|
jtkorhonen@0
|
62 {
|
Chris@197
|
63 setWindowIcon(QIcon(":images/easyhg-icon.png"));
|
Chris@197
|
64
|
jtkorhonen@0
|
65 QString wndTitle;
|
jtkorhonen@0
|
66
|
Chris@284
|
67 m_showAllFiles = false;
|
Chris@273
|
68
|
Chris@540
|
69 m_fsWatcher = new FsWatcher();
|
Chris@540
|
70 m_fsWatcherToken = m_fsWatcher->getNewToken();
|
Chris@540
|
71 m_commandSequenceInProgress = false;
|
Chris@541
|
72 connect(m_fsWatcher, SIGNAL(changed()), this, SLOT(checkFilesystem()));
|
Chris@540
|
73
|
Chris@284
|
74 m_commitsSincePush = 0;
|
Chris@284
|
75 m_shouldHgStat = true;
|
Chris@90
|
76
|
jtkorhonen@0
|
77 createActions();
|
jtkorhonen@0
|
78 createMenus();
|
jtkorhonen@0
|
79 createToolBars();
|
jtkorhonen@0
|
80 createStatusBar();
|
jtkorhonen@0
|
81
|
Chris@284
|
82 m_runner = new HgRunner(m_myDirPath, this);
|
Chris@284
|
83 connect(m_runner, SIGNAL(commandStarting(HgAction)),
|
Chris@241
|
84 this, SLOT(commandStarting(HgAction)));
|
Chris@284
|
85 connect(m_runner, SIGNAL(commandCompleted(HgAction, QString)),
|
Chris@109
|
86 this, SLOT(commandCompleted(HgAction, QString)));
|
Chris@537
|
87 connect(m_runner, SIGNAL(commandFailed(HgAction, QString, QString)),
|
Chris@537
|
88 this, SLOT(commandFailed(HgAction, QString, QString)));
|
Chris@284
|
89 statusBar()->addPermanentWidget(m_runner);
|
jtkorhonen@0
|
90
|
Chris@61
|
91 setWindowTitle(tr("EasyMercurial"));
|
jtkorhonen@0
|
92
|
Chris@284
|
93 m_remoteRepoPath = "";
|
Chris@284
|
94 m_workFolderPath = "";
|
jtkorhonen@0
|
95
|
jtkorhonen@0
|
96 readSettings();
|
jtkorhonen@0
|
97
|
Chris@284
|
98 m_justMerged = false;
|
Chris@210
|
99
|
Chris@210
|
100 QWidget *central = new QWidget(this);
|
Chris@210
|
101 setCentralWidget(central);
|
Chris@210
|
102
|
Chris@210
|
103 QGridLayout *cl = new QGridLayout(central);
|
Chris@287
|
104 int row = 0;
|
Chris@210
|
105
|
Chris@210
|
106 #ifndef Q_OS_MAC
|
Chris@210
|
107 cl->setMargin(0);
|
Chris@210
|
108 #endif
|
jtkorhonen@0
|
109
|
Chris@287
|
110 m_workStatus = new WorkStatusWidget(this);
|
Chris@554
|
111 cl->addWidget(m_workStatus, row, 0);
|
Chris@554
|
112
|
Chris@554
|
113 m_findWidget = new FindWidget(this);
|
Chris@554
|
114 cl->addWidget(m_findWidget, row++, 1, Qt::AlignRight | Qt::AlignTop);
|
Chris@287
|
115
|
Chris@287
|
116 m_hgTabs = new HgTabWidget(central, m_workFolderPath);
|
Chris@287
|
117 connectTabsSignals();
|
Chris@287
|
118
|
Chris@554
|
119 cl->addWidget(m_hgTabs, row++, 0, 1, 2);
|
Chris@287
|
120
|
Chris@284
|
121 connect(m_hgTabs, SIGNAL(selectionChanged()),
|
Chris@95
|
122 this, SLOT(enableDisableActions()));
|
Chris@484
|
123 connect(m_hgTabs, SIGNAL(showAllChanged()),
|
Chris@484
|
124 this, SLOT(showAllChanged()));
|
Chris@95
|
125
|
jtkorhonen@0
|
126 setUnifiedTitleAndToolBarOnMac(true);
|
jtkorhonen@0
|
127 connectActions();
|
Chris@120
|
128 clearState();
|
jtkorhonen@0
|
129 enableDisableActions();
|
jtkorhonen@0
|
130
|
Chris@284
|
131 if (m_firstStart) {
|
Chris@64
|
132 startupDialog();
|
jtkorhonen@0
|
133 }
|
jtkorhonen@0
|
134
|
Chris@239
|
135 SettingsDialog::findDefaultLocations(m_myDirPath);
|
Chris@112
|
136
|
Chris@64
|
137 ColourSet *cs = ColourSet::instance();
|
Chris@64
|
138 cs->clearDefaultNames();
|
Chris@64
|
139 cs->addDefaultName("");
|
Chris@153
|
140 cs->addDefaultName("default");
|
Chris@64
|
141 cs->addDefaultName(getUserInfo());
|
Chris@62
|
142
|
Chris@491
|
143 VersionTester *vt = new VersionTester
|
Chris@507
|
144 ("easyhg.org", "/latest-version.txt", EASYHG_VERSION);
|
Chris@491
|
145 connect(vt, SIGNAL(newerVersionAvailable(QString)),
|
Chris@491
|
146 this, SLOT(newerVersionAvailable(QString)));
|
Chris@491
|
147
|
Chris@175
|
148 hgTest();
|
Chris@359
|
149 updateRecentMenu();
|
jtkorhonen@0
|
150 }
|
jtkorhonen@0
|
151
|
jtkorhonen@0
|
152
|
jtkorhonen@0
|
153 void MainWindow::closeEvent(QCloseEvent *)
|
jtkorhonen@0
|
154 {
|
jtkorhonen@0
|
155 writeSettings();
|
Chris@284
|
156 delete m_fsWatcher;
|
jtkorhonen@0
|
157 }
|
jtkorhonen@0
|
158
|
jtkorhonen@0
|
159
|
Chris@554
|
160 void MainWindow::resizeEvent(QResizeEvent *)
|
Chris@554
|
161 {
|
Chris@554
|
162 }
|
Chris@554
|
163
|
Chris@554
|
164
|
Chris@64
|
165 QString MainWindow::getUserInfo() const
|
Chris@64
|
166 {
|
Chris@64
|
167 QSettings settings;
|
Chris@64
|
168 settings.beginGroup("User Information");
|
Chris@64
|
169 QString name = settings.value("name", getUserRealName()).toString();
|
Chris@64
|
170 QString email = settings.value("email", "").toString();
|
Chris@64
|
171
|
Chris@64
|
172 QString identifier;
|
Chris@64
|
173
|
Chris@64
|
174 if (email != "") {
|
Chris@64
|
175 identifier = QString("%1 <%2>").arg(name).arg(email);
|
Chris@64
|
176 } else {
|
Chris@64
|
177 identifier = name;
|
Chris@64
|
178 }
|
Chris@64
|
179
|
Chris@64
|
180 return identifier;
|
Chris@64
|
181 }
|
Chris@64
|
182
|
jtkorhonen@0
|
183 void MainWindow::about()
|
jtkorhonen@0
|
184 {
|
Chris@97
|
185 QMessageBox::about(this, tr("About EasyMercurial"),
|
Chris@229
|
186 tr("<qt><h2>EasyMercurial v%1</h2>"
|
Chris@228
|
187 #ifdef Q_OS_MAC
|
Chris@228
|
188 "<font size=-1>"
|
Chris@228
|
189 #endif
|
Chris@97
|
190 "<p>EasyMercurial is a simple user interface for the "
|
Chris@186
|
191 "Mercurial</a> version control system.</p>"
|
Chris@186
|
192 "<h4>Credits and Copyright</h4>"
|
Chris@186
|
193 "<p>Development carried out by Chris Cannam for "
|
Chris@186
|
194 "SoundSoftware.ac.uk at the Centre for Digital Music, "
|
Chris@186
|
195 "Queen Mary, University of London.</p>"
|
Chris@186
|
196 "<p>EasyMercurial is based on HgExplorer by "
|
Chris@186
|
197 "Jari Korhonen, with thanks.</p>"
|
Chris@186
|
198 "<p style=\"margin-left: 2em;\">"
|
Chris@244
|
199 "Copyright © 2011 Queen Mary, University of London.<br>"
|
Chris@186
|
200 "Copyright © 2010 Jari Korhonen.<br>"
|
Chris@244
|
201 "Copyright © 2011 Chris Cannam."
|
Chris@186
|
202 "</p>"
|
Chris@186
|
203 "<p style=\"margin-left: 2em;\">"
|
Chris@186
|
204 "This program requires Mercurial, by Matt Mackall and others.<br>"
|
Chris@186
|
205 "This program uses Qt by Nokia.<br>"
|
Chris@186
|
206 "This program uses Nuvola icons by David Vignoni.<br>"
|
Chris@186
|
207 "This program may use KDiff3 by Joachim Eibl.<br>"
|
Chris@186
|
208 "This program may use PyQt by River Bank Computing.<br>"
|
Chris@186
|
209 "Packaging for Mercurial and other dependencies on Windows is derived from TortoiseHg by Steve Borho and others."
|
Chris@186
|
210 "</p>"
|
Chris@186
|
211 "<h4>License</h4>"
|
Chris@186
|
212 "<p>This program is free software; you can redistribute it and/or "
|
Chris@97
|
213 "modify it under the terms of the GNU General Public License as "
|
Chris@97
|
214 "published by the Free Software Foundation; either version 2 of the "
|
Chris@97
|
215 "License, or (at your option) any later version. See the file "
|
Chris@223
|
216 "COPYING included with this distribution for more information.</p>"
|
Chris@228
|
217 #ifdef Q_OS_MAC
|
Chris@228
|
218 "</font>"
|
Chris@228
|
219 #endif
|
Chris@229
|
220 ).arg(EASYHG_VERSION));
|
jtkorhonen@0
|
221 }
|
jtkorhonen@0
|
222
|
Chris@94
|
223 void MainWindow::clearSelections()
|
Chris@94
|
224 {
|
Chris@284
|
225 m_hgTabs->clearSelections();
|
Chris@94
|
226 }
|
jtkorhonen@0
|
227
|
Chris@484
|
228 void MainWindow::showAllChanged()
|
Chris@199
|
229 {
|
Chris@199
|
230 hgQueryPaths();
|
Chris@199
|
231 }
|
Chris@199
|
232
|
Chris@120
|
233 void MainWindow::hgRefresh()
|
Chris@120
|
234 {
|
Chris@120
|
235 clearState();
|
Chris@120
|
236 hgQueryPaths();
|
Chris@120
|
237 }
|
Chris@120
|
238
|
Chris@175
|
239 void MainWindow::hgTest()
|
Chris@175
|
240 {
|
Chris@175
|
241 QStringList params;
|
Chris@175
|
242 params << "--version";
|
Chris@382
|
243 // The path is not necessarily set here, but we need something for
|
Chris@382
|
244 // this test or else HgRunner will (cautiously) refuse to run
|
Chris@382
|
245 QString path = m_myDirPath;
|
Chris@382
|
246 if (path == "") path = QDir::homePath();
|
Chris@382
|
247 m_runner->requestAction(HgAction(ACT_TEST_HG, path, params));
|
Chris@175
|
248 }
|
Chris@175
|
249
|
Chris@200
|
250 void MainWindow::hgTestExtension()
|
Chris@200
|
251 {
|
Chris@200
|
252 QStringList params;
|
Chris@200
|
253 params << "--version";
|
Chris@382
|
254 // The path is not necessarily set here, but we need something for
|
Chris@382
|
255 // this test or else HgRunner will (cautiously) refuse to run
|
Chris@382
|
256 QString path = m_myDirPath;
|
Chris@382
|
257 if (path == "") path = QDir::homePath();
|
Chris@382
|
258 m_runner->requestAction(HgAction(ACT_TEST_HG_EXT, path, params));
|
Chris@200
|
259 }
|
Chris@200
|
260
|
jtkorhonen@0
|
261 void MainWindow::hgStat()
|
jtkorhonen@0
|
262 {
|
Chris@109
|
263 QStringList params;
|
Chris@199
|
264
|
Chris@542
|
265 // We always stat all files, regardless of whether we're showing
|
Chris@542
|
266 // them all, because we need them for the filesystem monitor
|
Chris@542
|
267 params << "stat" << "-A";
|
Chris@153
|
268
|
Chris@284
|
269 m_lastStatOutput = "";
|
Chris@273
|
270
|
Chris@541
|
271 // We're about to do a stat, so we can silently bring ourselves
|
Chris@541
|
272 // up-to-date on any file changes to this point
|
Chris@541
|
273 (void)m_fsWatcher->getChangedPaths(m_fsWatcherToken);
|
Chris@541
|
274
|
Chris@284
|
275 m_runner->requestAction(HgAction(ACT_STAT, m_workFolderPath, params));
|
jtkorhonen@0
|
276 }
|
jtkorhonen@0
|
277
|
Chris@109
|
278 void MainWindow::hgQueryPaths()
|
Chris@74
|
279 {
|
Chris@484
|
280 m_showAllFiles = m_hgTabs->shouldShowAll();
|
Chris@484
|
281
|
Chris@210
|
282 // Quickest is to just read the file
|
Chris@198
|
283
|
Chris@284
|
284 QFileInfo hgrc(m_workFolderPath + "/.hg/hgrc");
|
Chris@198
|
285
|
Chris@210
|
286 QString path;
|
Chris@210
|
287
|
Chris@198
|
288 if (hgrc.exists()) {
|
Chris@198
|
289 QSettings s(hgrc.canonicalFilePath(), QSettings::IniFormat);
|
Chris@198
|
290 s.beginGroup("paths");
|
Chris@210
|
291 path = s.value("default").toString();
|
Chris@210
|
292 }
|
Chris@198
|
293
|
Chris@553
|
294 std::cerr << "hgQueryPaths: setting m_remoteRepoPath to " << m_remoteRepoPath << " from file " << hgrc.absoluteFilePath() << std::endl;
|
Chris@553
|
295
|
Chris@284
|
296 m_remoteRepoPath = path;
|
Chris@198
|
297
|
Chris@210
|
298 // We have to do this here, because commandCompleted won't be called
|
Chris@284
|
299 MultiChoiceDialog::addRecentArgument("local", m_workFolderPath);
|
Chris@284
|
300 MultiChoiceDialog::addRecentArgument("remote", m_remoteRepoPath);
|
Chris@287
|
301 updateWorkFolderAndRepoNames();
|
Chris@210
|
302
|
Chris@210
|
303 hgQueryBranch();
|
Chris@210
|
304 return;
|
Chris@210
|
305
|
Chris@210
|
306 /* The classic method!
|
Chris@198
|
307
|
Chris@109
|
308 QStringList params;
|
Chris@109
|
309 params << "paths";
|
Chris@284
|
310 m_runner->requestAction(HgAction(ACT_QUERY_PATHS, m_workFolderPath, params));
|
Chris@210
|
311 */
|
Chris@74
|
312 }
|
Chris@74
|
313
|
Chris@109
|
314 void MainWindow::hgQueryBranch()
|
Chris@106
|
315 {
|
Chris@210
|
316 // Quickest is to just read the file
|
Chris@198
|
317
|
Chris@284
|
318 QFile hgbr(m_workFolderPath + "/.hg/branch");
|
Chris@198
|
319
|
Chris@210
|
320 QString br = "default";
|
Chris@210
|
321
|
Chris@198
|
322 if (hgbr.exists() && hgbr.open(QFile::ReadOnly)) {
|
Chris@210
|
323 QByteArray ba = hgbr.readLine();
|
Chris@210
|
324 br = QString::fromUtf8(ba).trimmed();
|
Chris@210
|
325 }
|
Chris@210
|
326
|
Chris@284
|
327 m_currentBranch = br;
|
Chris@210
|
328
|
Chris@210
|
329 // We have to do this here, because commandCompleted won't be called
|
Chris@210
|
330 hgStat();
|
Chris@210
|
331 return;
|
Chris@198
|
332
|
Chris@210
|
333 /* The classic method!
|
Chris@198
|
334
|
Chris@109
|
335 QStringList params;
|
Chris@109
|
336 params << "branch";
|
Chris@284
|
337 m_runner->requestAction(HgAction(ACT_QUERY_BRANCH, m_workFolderPath, params));
|
Chris@210
|
338 */
|
Chris@106
|
339 }
|
Chris@106
|
340
|
Chris@506
|
341 void MainWindow::hgQueryHeadsActive()
|
Chris@506
|
342 {
|
Chris@506
|
343 QStringList params;
|
Chris@514
|
344 params << "heads";
|
Chris@506
|
345 m_runner->requestAction(HgAction(ACT_QUERY_HEADS_ACTIVE, m_workFolderPath, params));
|
Chris@506
|
346 }
|
Chris@506
|
347
|
Chris@109
|
348 void MainWindow::hgQueryHeads()
|
jtkorhonen@0
|
349 {
|
Chris@109
|
350 QStringList params;
|
Chris@137
|
351 // On empty repos, "hg heads" will fail -- we don't care about
|
Chris@137
|
352 // that. Use --closed option so as to include closed branches;
|
Chris@137
|
353 // otherwise we'll be stuck if the user updates into one, and our
|
Chris@137
|
354 // incremental log will end up with spurious stuff in it because
|
Chris@137
|
355 // we won't be pruning at the ends of closed branches
|
Chris@137
|
356 params << "heads" << "--closed";
|
Chris@284
|
357 m_runner->requestAction(HgAction(ACT_QUERY_HEADS, m_workFolderPath, params));
|
jtkorhonen@0
|
358 }
|
jtkorhonen@0
|
359
|
jtkorhonen@0
|
360 void MainWindow::hgLog()
|
jtkorhonen@0
|
361 {
|
Chris@109
|
362 QStringList params;
|
Chris@109
|
363 params << "log";
|
Chris@109
|
364 params << "--template";
|
Chris@125
|
365 params << Changeset::getLogTemplate();
|
Chris@109
|
366
|
Chris@284
|
367 m_runner->requestAction(HgAction(ACT_LOG, m_workFolderPath, params));
|
Chris@109
|
368 }
|
Chris@109
|
369
|
Chris@150
|
370 void MainWindow::hgLogIncremental(QStringList prune)
|
Chris@120
|
371 {
|
Chris@305
|
372 // Sometimes we can be called with prune empty -- it represents
|
Chris@305
|
373 // the current heads, but if we have none already and for some
|
Chris@305
|
374 // reason are being prompted for an incremental update, we may run
|
Chris@305
|
375 // into trouble. In that case, make this a full log instead
|
Chris@305
|
376
|
Chris@305
|
377 if (prune.empty()) {
|
Chris@305
|
378 hgLog();
|
Chris@305
|
379 return;
|
Chris@305
|
380 }
|
Chris@305
|
381
|
Chris@120
|
382 QStringList params;
|
Chris@120
|
383 params << "log";
|
Chris@120
|
384
|
Chris@150
|
385 foreach (QString p, prune) {
|
Chris@153
|
386 params << "--prune" << Changeset::hashOf(p);
|
Chris@120
|
387 }
|
Chris@120
|
388
|
Chris@120
|
389 params << "--template";
|
Chris@125
|
390 params << Changeset::getLogTemplate();
|
Chris@120
|
391
|
Chris@284
|
392 m_runner->requestAction(HgAction(ACT_LOG_INCREMENTAL, m_workFolderPath, params));
|
Chris@120
|
393 }
|
Chris@109
|
394
|
Chris@109
|
395 void MainWindow::hgQueryParents()
|
Chris@109
|
396 {
|
Chris@109
|
397 QStringList params;
|
Chris@109
|
398 params << "parents";
|
Chris@284
|
399 m_runner->requestAction(HgAction(ACT_QUERY_PARENTS, m_workFolderPath, params));
|
Chris@109
|
400 }
|
Chris@109
|
401
|
Chris@326
|
402 void MainWindow::hgAnnotateFiles(QStringList files)
|
Chris@326
|
403 {
|
Chris@326
|
404 QStringList params;
|
Chris@326
|
405
|
Chris@326
|
406 if (!files.isEmpty()) {
|
Chris@332
|
407 params << "annotate" << "-udqc" << "--" << files;
|
Chris@326
|
408 m_runner->requestAction(HgAction(ACT_ANNOTATE, m_workFolderPath, params));
|
Chris@326
|
409 }
|
Chris@326
|
410 }
|
Chris@326
|
411
|
Chris@109
|
412 void MainWindow::hgResolveList()
|
Chris@109
|
413 {
|
Chris@109
|
414 QStringList params;
|
jtkorhonen@0
|
415
|
Chris@109
|
416 params << "resolve" << "--list";
|
Chris@284
|
417 m_runner->requestAction(HgAction(ACT_RESOLVE_LIST, m_workFolderPath, params));
|
Chris@109
|
418 }
|
Chris@109
|
419
|
Chris@109
|
420 void MainWindow::hgAdd()
|
jtkorhonen@0
|
421 {
|
Chris@109
|
422 // hgExplorer permitted adding "all" files -- I'm not sure
|
Chris@109
|
423 // that one is a good idea, let's require the user to select
|
jtkorhonen@0
|
424
|
Chris@326
|
425 hgAddFiles(m_hgTabs->getSelectedAddableFiles());
|
Chris@326
|
426 }
|
Chris@326
|
427
|
Chris@326
|
428 void MainWindow::hgAddFiles(QStringList files)
|
Chris@326
|
429 {
|
Chris@326
|
430 QStringList params;
|
Chris@109
|
431
|
Chris@109
|
432 if (!files.empty()) {
|
Chris@109
|
433 params << "add" << "--" << files;
|
Chris@284
|
434 m_runner->requestAction(HgAction(ACT_ADD, m_workFolderPath, params));
|
jtkorhonen@0
|
435 }
|
jtkorhonen@0
|
436 }
|
jtkorhonen@0
|
437
|
Chris@98
|
438 void MainWindow::hgRemove()
|
Chris@98
|
439 {
|
Chris@326
|
440 hgRemoveFiles(m_hgTabs->getSelectedRemovableFiles());
|
Chris@326
|
441 }
|
Chris@326
|
442
|
Chris@326
|
443 void MainWindow::hgRemoveFiles(QStringList files)
|
Chris@326
|
444 {
|
Chris@109
|
445 QStringList params;
|
Chris@98
|
446
|
Chris@109
|
447 if (!files.empty()) {
|
Chris@109
|
448 params << "remove" << "--after" << "--force" << "--" << files;
|
Chris@284
|
449 m_runner->requestAction(HgAction(ACT_REMOVE, m_workFolderPath, params));
|
Chris@109
|
450 }
|
jtkorhonen@0
|
451 }
|
jtkorhonen@0
|
452
|
jtkorhonen@0
|
453 void MainWindow::hgCommit()
|
jtkorhonen@0
|
454 {
|
Chris@326
|
455 hgCommitFiles(QStringList());
|
Chris@326
|
456 }
|
Chris@326
|
457
|
Chris@326
|
458 void MainWindow::hgCommitFiles(QStringList files)
|
Chris@326
|
459 {
|
Chris@109
|
460 QStringList params;
|
Chris@109
|
461 QString comment;
|
Chris@94
|
462
|
Chris@284
|
463 if (m_justMerged) {
|
Chris@284
|
464 comment = m_mergeCommitComment;
|
Chris@157
|
465 }
|
Chris@157
|
466
|
Chris@284
|
467 QStringList allFiles = m_hgTabs->getAllCommittableFiles();
|
Chris@127
|
468 QStringList reportFiles = files;
|
Chris@237
|
469 if (reportFiles.empty()) {
|
Chris@237
|
470 reportFiles = allFiles;
|
Chris@237
|
471 }
|
Chris@103
|
472
|
Chris@237
|
473 QString subsetNote;
|
Chris@237
|
474 if (reportFiles != allFiles) {
|
Chris@237
|
475 subsetNote = tr("<p><b>Note:</b> you are committing only the files you have selected, not all of the files that have been changed!");
|
Chris@237
|
476 }
|
Chris@237
|
477
|
Chris@155
|
478 QString cf(tr("Commit files"));
|
Chris@155
|
479
|
Chris@311
|
480 QString branchText;
|
Chris@311
|
481 if (m_currentBranch == "" || m_currentBranch == "default") {
|
Chris@311
|
482 branchText = tr("the default branch");
|
Chris@311
|
483 } else {
|
Chris@311
|
484 branchText = tr("branch \"%1\"").arg(m_currentBranch);
|
Chris@311
|
485 }
|
Chris@311
|
486
|
Chris@109
|
487 if (ConfirmCommentDialog::confirmAndGetLongComment
|
Chris@109
|
488 (this,
|
Chris@155
|
489 cf,
|
Chris@237
|
490 tr("<h3>%1</h3><p>%2%3").arg(cf)
|
Chris@473
|
491 .arg(tr("You are about to commit changes to the following files in %1:").arg(branchText))
|
Chris@237
|
492 .arg(subsetNote),
|
Chris@237
|
493 tr("<h3>%1</h3><p>%2%3").arg(cf)
|
Chris@473
|
494 .arg(tr("You are about to commit changes to %n file(s) in %1.", "", reportFiles.size()).arg(branchText))
|
Chris@237
|
495 .arg(subsetNote),
|
Chris@127
|
496 reportFiles,
|
Chris@193
|
497 comment,
|
Chris@365
|
498 tr("Co&mmit"))) {
|
Chris@103
|
499
|
Chris@284
|
500 if (!m_justMerged && !files.empty()) {
|
Chris@157
|
501 // User wants to commit selected file(s) (and this is not
|
Chris@157
|
502 // merge commit, which would fail if we selected files)
|
Chris@157
|
503 params << "commit" << "--message" << comment
|
Chris@157
|
504 << "--user" << getUserInfo() << "--" << files;
|
Chris@109
|
505 } else {
|
Chris@109
|
506 // Commit all changes
|
Chris@157
|
507 params << "commit" << "--message" << comment
|
Chris@157
|
508 << "--user" << getUserInfo();
|
jtkorhonen@0
|
509 }
|
Chris@109
|
510
|
Chris@284
|
511 m_runner->requestAction(HgAction(ACT_COMMIT, m_workFolderPath, params));
|
Chris@284
|
512 m_mergeCommitComment = "";
|
jtkorhonen@0
|
513 }
|
jtkorhonen@0
|
514 }
|
jtkorhonen@0
|
515
|
jtkorhonen@34
|
516 QString MainWindow::filterTag(QString tag)
|
jtkorhonen@34
|
517 {
|
Chris@278
|
518 for(int i = 0; i < tag.size(); i++) {
|
Chris@278
|
519 if (tag[i].isLower() || tag[i].isUpper() ||
|
Chris@278
|
520 tag[i].isDigit() || (tag[i] == QChar('.'))) {
|
jtkorhonen@34
|
521 //ok
|
Chris@278
|
522 } else {
|
jtkorhonen@34
|
523 tag[i] = QChar('_');
|
jtkorhonen@34
|
524 }
|
jtkorhonen@34
|
525 }
|
jtkorhonen@34
|
526 return tag;
|
jtkorhonen@34
|
527 }
|
jtkorhonen@34
|
528
|
jtkorhonen@34
|
529
|
Chris@311
|
530 void MainWindow::hgNewBranch()
|
Chris@278
|
531 {
|
Chris@278
|
532 QStringList params;
|
Chris@278
|
533 QString branch;
|
Chris@278
|
534
|
Chris@278
|
535 if (ConfirmCommentDialog::confirmAndGetShortComment
|
Chris@278
|
536 (this,
|
Chris@278
|
537 tr("New Branch"),
|
Chris@278
|
538 tr("Enter new branch name:"),
|
Chris@278
|
539 branch,
|
Chris@365
|
540 tr("Start &Branch"))) {
|
Chris@278
|
541 if (!branch.isEmpty()) {//!!! do something better if it is empty
|
Chris@278
|
542
|
Chris@278
|
543 params << "branch" << filterTag(branch);
|
Chris@307
|
544 m_runner->requestAction(HgAction(ACT_NEW_BRANCH, m_workFolderPath, params));
|
Chris@278
|
545 }
|
Chris@278
|
546 }
|
Chris@278
|
547 }
|
Chris@278
|
548
|
Chris@311
|
549 void MainWindow::hgNoBranch()
|
Chris@311
|
550 {
|
Chris@311
|
551 if (m_currentParents.empty()) return;
|
Chris@311
|
552
|
Chris@311
|
553 QString parentBranch = m_currentParents[0]->branch();
|
Chris@311
|
554 if (parentBranch == "") parentBranch = "default";
|
Chris@311
|
555
|
Chris@311
|
556 QStringList params;
|
Chris@311
|
557 params << "branch" << parentBranch;
|
Chris@311
|
558 m_runner->requestAction(HgAction(ACT_NEW_BRANCH, m_workFolderPath, params));
|
Chris@311
|
559 }
|
Chris@311
|
560
|
Chris@514
|
561 void MainWindow::hgCloseBranch()
|
Chris@514
|
562 {
|
Chris@514
|
563 QStringList params;
|
Chris@514
|
564
|
Chris@514
|
565 //!!! how to ensure this doesn't happen when uncommitted changes present?
|
Chris@514
|
566
|
Chris@514
|
567 QString cf(tr("Close branch"));
|
Chris@514
|
568 QString comment;
|
Chris@514
|
569
|
Chris@514
|
570 QString defaultWarning;
|
Chris@514
|
571
|
Chris@514
|
572 QString branchText;
|
Chris@514
|
573 if (m_currentBranch == "" || m_currentBranch == "default") {
|
Chris@514
|
574 branchText = tr("the default branch");
|
Chris@514
|
575 defaultWarning = tr("<p><b>Warning:</b> you are asking to close the default branch. This is not usually a good idea!</p>");
|
Chris@514
|
576 } else {
|
Chris@514
|
577 branchText = tr("branch \"%1\"").arg(m_currentBranch);
|
Chris@514
|
578 }
|
Chris@514
|
579
|
Chris@514
|
580 if (ConfirmCommentDialog::confirmAndGetLongComment
|
Chris@514
|
581 (this,
|
Chris@514
|
582 cf,
|
Chris@514
|
583 tr("<h3>%1</h3><p>%2%3").arg(cf)
|
Chris@518
|
584 .arg(tr("You are about to close %1.<p>This branch will be marked as closed and hidden from the history view.<p>You will still be able to see if it you select \"Show closed branches\" in the history view, and it will be reopened if you commit to it.<p>Please enter your comment for the commit log:").arg(branchText))
|
Chris@514
|
585 .arg(defaultWarning),
|
Chris@514
|
586 comment,
|
Chris@514
|
587 tr("C&lose branch"))) {
|
Chris@514
|
588
|
Chris@514
|
589 params << "commit" << "--message" << comment
|
Chris@514
|
590 << "--user" << getUserInfo() << "--close-branch";
|
Chris@514
|
591
|
Chris@514
|
592 m_runner->requestAction(HgAction(ACT_CLOSE_BRANCH, m_workFolderPath, params));
|
Chris@514
|
593 }
|
Chris@514
|
594 }
|
Chris@514
|
595
|
Chris@164
|
596 void MainWindow::hgTag(QString id)
|
jtkorhonen@34
|
597 {
|
Chris@109
|
598 QStringList params;
|
Chris@109
|
599 QString tag;
|
jtkorhonen@34
|
600
|
Chris@109
|
601 if (ConfirmCommentDialog::confirmAndGetShortComment
|
Chris@109
|
602 (this,
|
Chris@109
|
603 tr("Tag"),
|
Chris@109
|
604 tr("Enter tag:"),
|
Chris@193
|
605 tag,
|
Chris@365
|
606 tr("Add &Tag"))) {
|
Chris@164
|
607 if (!tag.isEmpty()) {//!!! do something better if it is empty
|
Chris@164
|
608
|
Chris@164
|
609 params << "tag" << "--user" << getUserInfo();
|
Chris@164
|
610 params << "--rev" << Changeset::hashOf(id) << filterTag(tag);
|
Chris@109
|
611
|
Chris@284
|
612 m_runner->requestAction(HgAction(ACT_TAG, m_workFolderPath, params));
|
jtkorhonen@34
|
613 }
|
jtkorhonen@34
|
614 }
|
jtkorhonen@34
|
615 }
|
jtkorhonen@34
|
616
|
Chris@417
|
617 void MainWindow::initHgIgnore()
|
jtkorhonen@34
|
618 {
|
Chris@284
|
619 if (!QDir(m_workFolderPath).exists()) return;
|
Chris@417
|
620 QString hgIgnorePath = m_workFolderPath + "/.hgignore";
|
Chris@417
|
621
|
Chris@249
|
622 QFile f(hgIgnorePath);
|
Chris@249
|
623 if (!f.exists()) {
|
Chris@249
|
624 f.open(QFile::WriteOnly);
|
Chris@249
|
625 QTextStream *ts = new QTextStream(&f);
|
Chris@249
|
626 *ts << "syntax: glob\n";
|
Chris@249
|
627 delete ts;
|
Chris@249
|
628 f.close();
|
Chris@249
|
629 }
|
Chris@417
|
630 }
|
Chris@417
|
631
|
Chris@425
|
632 void MainWindow::hgIgnore()
|
Chris@425
|
633 {
|
Chris@425
|
634 // hgExplorer permitted adding "all" files -- I'm not sure
|
Chris@425
|
635 // that one is a good idea, let's require the user to select
|
Chris@425
|
636
|
Chris@425
|
637 hgIgnoreFiles(m_hgTabs->getSelectedAddableFiles());
|
Chris@425
|
638 }
|
Chris@425
|
639
|
Chris@417
|
640 void MainWindow::hgEditIgnore()
|
Chris@417
|
641 {
|
Chris@417
|
642 if (!QDir(m_workFolderPath).exists()) return;
|
Chris@417
|
643
|
Chris@417
|
644 initHgIgnore();
|
Chris@417
|
645
|
Chris@417
|
646 QString hgIgnorePath = m_workFolderPath + "/.hgignore";
|
Chris@476
|
647
|
Chris@476
|
648 QFile f(hgIgnorePath);
|
Chris@476
|
649 if (!f.exists()) return; // shouldn't happen (after initHgIgnore called)
|
Chris@476
|
650
|
Chris@476
|
651 if (!f.open(QFile::ReadOnly)) return;
|
Chris@476
|
652 QTextStream sin(&f);
|
Chris@476
|
653 QString all = sin.readAll();
|
Chris@476
|
654 f.close();
|
Chris@476
|
655
|
Chris@476
|
656 QDialog d;
|
Chris@476
|
657 QGridLayout layout;
|
Chris@476
|
658 d.setLayout(&layout);
|
Chris@476
|
659
|
Chris@476
|
660 int row = 0;
|
Chris@476
|
661 layout.addWidget(new QLabel(tr("<qt><h3>Ignored File Patterns</h3></qt>")), row++, 0);//!!! todo: link to Hg docs?
|
Chris@476
|
662
|
Chris@476
|
663 QTextEdit ed;
|
Chris@476
|
664 ed.setAcceptRichText(false);
|
Chris@476
|
665 ed.setLineWrapMode(QTextEdit::NoWrap);
|
Chris@476
|
666 layout.setRowStretch(row, 10);
|
Chris@476
|
667 layout.addWidget(&ed, row++, 0);
|
Chris@179
|
668
|
Chris@476
|
669 QDialogButtonBox bb(QDialogButtonBox::Save | QDialogButtonBox::Cancel);
|
Chris@476
|
670 connect(bb.button(QDialogButtonBox::Save), SIGNAL(clicked()),
|
Chris@476
|
671 &d, SLOT(accept()));
|
Chris@476
|
672 connect(bb.button(QDialogButtonBox::Cancel), SIGNAL(clicked()),
|
Chris@476
|
673 &d, SLOT(reject()));
|
Chris@476
|
674 layout.addWidget(&bb, row++, 0);
|
Chris@476
|
675
|
Chris@476
|
676 ed.document()->setPlainText(all);
|
Chris@476
|
677
|
Chris@476
|
678 d.resize(QSize(300, 400));
|
Chris@476
|
679
|
Chris@476
|
680 if (d.exec() == QDialog::Accepted) {
|
Chris@476
|
681 if (!f.open(QFile::WriteOnly | QFile::Truncate)) {
|
Chris@476
|
682 QMessageBox::critical(this, tr("Write failed"),
|
Chris@476
|
683 tr("Failed to open file %1 for writing")
|
Chris@476
|
684 .arg(f.fileName()));
|
Chris@476
|
685 return;
|
Chris@476
|
686 }
|
Chris@476
|
687 QTextStream sout(&f);
|
Chris@476
|
688 sout << ed.document()->toPlainText();
|
Chris@476
|
689 f.close();
|
Chris@179
|
690 }
|
Chris@179
|
691 }
|
Chris@179
|
692
|
Chris@421
|
693 static QString regexEscape(QString filename)
|
Chris@421
|
694 {
|
Chris@421
|
695 return filename
|
Chris@421
|
696 .replace(".", "\\.")
|
Chris@421
|
697 .replace("[", "\\[")
|
Chris@421
|
698 .replace("]", "\\]")
|
Chris@421
|
699 .replace("(", "\\(")
|
Chris@421
|
700 .replace(")", "\\)")
|
Chris@421
|
701 .replace("?", "\\?");
|
Chris@421
|
702 }
|
Chris@421
|
703
|
Chris@326
|
704 void MainWindow::hgIgnoreFiles(QStringList files)
|
Chris@326
|
705 {
|
Chris@417
|
706 if (!QDir(m_workFolderPath).exists() || files.empty()) return;
|
Chris@413
|
707
|
Chris@413
|
708 // we should:
|
Chris@413
|
709 //
|
Chris@413
|
710 // * show the user the list of file names selected
|
Chris@413
|
711 //
|
Chris@413
|
712 // * offer a choice (depending on the files selected?)
|
Chris@413
|
713 //
|
Chris@413
|
714 // - ignore only these files
|
Chris@413
|
715 //
|
Chris@413
|
716 // - ignore files with these names, in any subdirectories?
|
Chris@413
|
717 //
|
Chris@413
|
718 // - ignore all files with this extension (if they have a common
|
Chris@413
|
719 // extension)?
|
Chris@413
|
720 //
|
Chris@413
|
721 // - ignore all files with these extensions (if they have any
|
Chris@413
|
722 // extensions?)
|
Chris@413
|
723
|
Chris@414
|
724 DEBUG << "MainWindow::hgIgnoreFiles: File names are:" << endl;
|
Chris@414
|
725 foreach (QString file, files) DEBUG << file << endl;
|
Chris@414
|
726
|
Chris@414
|
727 QSet<QString> suffixes;
|
Chris@414
|
728 foreach (QString file, files) {
|
Chris@414
|
729 QString s = QFileInfo(file).suffix();
|
Chris@414
|
730 if (s != "") suffixes.insert(s);
|
Chris@414
|
731 }
|
Chris@414
|
732
|
Chris@419
|
733 QString directory;
|
Chris@429
|
734 int dirCount = 0;
|
Chris@419
|
735 foreach (QString file, files) {
|
Chris@419
|
736 QString d = QFileInfo(file).path();
|
Chris@419
|
737 if (d != directory) {
|
Chris@419
|
738 ++dirCount;
|
Chris@419
|
739 directory = d;
|
Chris@419
|
740 }
|
Chris@419
|
741 }
|
Chris@421
|
742 if (dirCount != 1 || directory == ".") directory = "";
|
Chris@419
|
743
|
Chris@414
|
744 HgIgnoreDialog::IgnoreType itype =
|
Chris@415
|
745 HgIgnoreDialog::confirmIgnore
|
Chris@419
|
746 (this, files, QStringList::fromSet(suffixes), directory);
|
Chris@414
|
747
|
Chris@416
|
748 DEBUG << "hgIgnoreFiles: Ignore type is " << itype << endl;
|
Chris@417
|
749
|
Chris@421
|
750 if (itype == HgIgnoreDialog::IgnoreNothing) return;
|
Chris@421
|
751
|
Chris@417
|
752 // Now, .hgignore can be switched from regex to glob syntax
|
Chris@417
|
753 // part-way through -- and glob is much simpler for us, so we
|
Chris@417
|
754 // should do that if it's in regex mode at the end of the file.
|
Chris@417
|
755
|
Chris@417
|
756 initHgIgnore();
|
Chris@417
|
757
|
Chris@417
|
758 QString hgIgnorePath = m_workFolderPath + "/.hgignore";
|
Chris@417
|
759
|
Chris@417
|
760 // hgignore file should now exist (initHgIgnore should have
|
Chris@417
|
761 // created it if it didn't). Check for glob status first
|
Chris@417
|
762
|
Chris@417
|
763 QFile f(hgIgnorePath);
|
Chris@417
|
764 if (!f.exists()) {
|
Chris@417
|
765 std::cerr << "MainWindow::ignoreFiles: Internal error: .hgignore file not found (even though we were supposed to have created it)" << std::endl;
|
Chris@417
|
766 return;
|
Chris@417
|
767 }
|
Chris@417
|
768
|
Chris@417
|
769 f.open(QFile::ReadOnly);
|
Chris@417
|
770 bool glob = false;
|
Chris@417
|
771 while (!f.atEnd()) {
|
Chris@417
|
772 QByteArray ba = f.readLine();
|
Chris@417
|
773 QString s = QString::fromLocal8Bit(ba).trimmed();
|
Chris@417
|
774 if (s.startsWith("syntax:")) {
|
Chris@417
|
775 if (s.endsWith("glob")) {
|
Chris@417
|
776 glob = true;
|
Chris@417
|
777 } else {
|
Chris@417
|
778 glob = false;
|
Chris@417
|
779 }
|
Chris@417
|
780 }
|
Chris@417
|
781 }
|
Chris@417
|
782 f.close();
|
Chris@417
|
783
|
Chris@417
|
784 f.open(QFile::Append);
|
Chris@417
|
785 QTextStream out(&f);
|
Chris@417
|
786
|
Chris@417
|
787 if (!glob) {
|
Chris@417
|
788 out << "syntax: glob" << endl;
|
Chris@417
|
789 }
|
Chris@417
|
790
|
Chris@421
|
791 QString info = "<qt><h3>" + tr("Ignored files") + "</h3><p>";
|
Chris@421
|
792 info += tr("The following lines have been added to the .hgignore file for this working copy:");
|
Chris@421
|
793 info += "</p><code>";
|
Chris@421
|
794
|
Chris@421
|
795 QStringList args;
|
Chris@417
|
796 if (itype == HgIgnoreDialog::IgnoreAllFilesOfGivenSuffixes) {
|
Chris@421
|
797 args = QStringList::fromSet(suffixes);
|
Chris@421
|
798 } else if (itype == HgIgnoreDialog::IgnoreGivenFilesOnly) {
|
Chris@421
|
799 args = files;
|
Chris@421
|
800 } else if (itype == HgIgnoreDialog::IgnoreAllFilesOfGivenNames) {
|
Chris@421
|
801 QSet<QString> names;
|
Chris@421
|
802 foreach (QString f, files) {
|
Chris@421
|
803 names << QFileInfo(f).fileName();
|
Chris@417
|
804 }
|
Chris@421
|
805 args = QStringList::fromSet(names);
|
Chris@421
|
806 } else if (itype == HgIgnoreDialog::IgnoreWholeDirectory) {
|
Chris@421
|
807 args << directory;
|
Chris@421
|
808 }
|
Chris@421
|
809
|
Chris@421
|
810 bool first = true;
|
Chris@421
|
811
|
Chris@421
|
812 foreach (QString a, args) {
|
Chris@421
|
813 QString line;
|
Chris@421
|
814 if (itype == HgIgnoreDialog::IgnoreAllFilesOfGivenSuffixes) {
|
Chris@421
|
815 line = "*." + a;
|
Chris@421
|
816 } else if (itype == HgIgnoreDialog::IgnoreGivenFilesOnly) {
|
Chris@421
|
817 // Doesn't seem to be possible to do this with a glob,
|
Chris@421
|
818 // because the glob is always unanchored and there is no
|
Chris@421
|
819 // equivalent of ^ to anchor it
|
chris@423
|
820 line = "re:^" + regexEscape(a) + "$";
|
Chris@421
|
821 } else if (itype == HgIgnoreDialog::IgnoreAllFilesOfGivenNames) {
|
Chris@421
|
822 line = a;
|
Chris@421
|
823 } else if (itype == HgIgnoreDialog::IgnoreWholeDirectory) {
|
Chris@421
|
824 line = "re:^" + regexEscape(a) + "/";
|
Chris@418
|
825 }
|
Chris@421
|
826 if (line != "") {
|
Chris@421
|
827 out << line << endl;
|
Chris@421
|
828 if (!first) info += "<br>";
|
Chris@421
|
829 first = false;
|
Chris@421
|
830 info += xmlEncode(line);
|
Chris@417
|
831 }
|
Chris@417
|
832 }
|
Chris@417
|
833
|
Chris@419
|
834 f.close();
|
Chris@419
|
835
|
Chris@421
|
836 info += "</code></qt>";
|
Chris@421
|
837
|
Chris@421
|
838 QMessageBox::information(this, tr("Ignored files"),
|
Chris@421
|
839 info);
|
Chris@421
|
840
|
Chris@417
|
841 hgRefresh();
|
Chris@326
|
842 }
|
Chris@326
|
843
|
Chris@326
|
844 void MainWindow::hgUnIgnoreFiles(QStringList files)
|
Chris@326
|
845 {
|
Chris@421
|
846 // Not implemented: edit the .hgignore instead
|
Chris@421
|
847 hgEditIgnore();
|
Chris@326
|
848 }
|
Chris@326
|
849
|
Chris@239
|
850 QString MainWindow::getDiffBinaryName()
|
Chris@179
|
851 {
|
Chris@179
|
852 QSettings settings;
|
Chris@179
|
853 settings.beginGroup("Locations");
|
Chris@239
|
854 return settings.value("extdiffbinary", "").toString();
|
Chris@179
|
855 }
|
Chris@179
|
856
|
Chris@239
|
857 QString MainWindow::getMergeBinaryName()
|
Chris@179
|
858 {
|
Chris@179
|
859 QSettings settings;
|
Chris@179
|
860 settings.beginGroup("Locations");
|
Chris@239
|
861 return settings.value("mergebinary", "").toString();
|
Chris@179
|
862 }
|
Chris@179
|
863
|
Chris@168
|
864 void MainWindow::hgShowSummary()
|
Chris@168
|
865 {
|
Chris@168
|
866 QStringList params;
|
Chris@168
|
867
|
Chris@168
|
868 params << "diff" << "--stat";
|
Chris@168
|
869
|
Chris@288
|
870 m_runner->requestAction(HgAction(ACT_UNCOMMITTED_SUMMARY, m_workFolderPath, params));
|
Chris@168
|
871 }
|
Chris@168
|
872
|
jtkorhonen@0
|
873 void MainWindow::hgFolderDiff()
|
jtkorhonen@0
|
874 {
|
Chris@326
|
875 hgDiffFiles(QStringList());
|
Chris@326
|
876 }
|
Chris@326
|
877
|
Chris@326
|
878 void MainWindow::hgDiffFiles(QStringList files)
|
Chris@326
|
879 {
|
Chris@239
|
880 QString diff = getDiffBinaryName();
|
Chris@179
|
881 if (diff == "") return;
|
Chris@112
|
882
|
Chris@109
|
883 QStringList params;
|
jtkorhonen@0
|
884
|
Chris@112
|
885 // Diff parent against working folder (folder diff)
|
Chris@112
|
886
|
Chris@148
|
887 params << "--config" << "extensions.extdiff=" << "extdiff";
|
Chris@179
|
888 params << "--program" << diff;
|
Chris@109
|
889
|
Chris@331
|
890 params << "--" << files; // may be none: whole dir
|
Chris@273
|
891
|
Chris@284
|
892 m_runner->requestAction(HgAction(ACT_FOLDERDIFF, m_workFolderPath, params));
|
jtkorhonen@0
|
893 }
|
jtkorhonen@0
|
894
|
Chris@148
|
895 void MainWindow::hgDiffToCurrent(QString id)
|
jtkorhonen@0
|
896 {
|
Chris@239
|
897 QString diff = getDiffBinaryName();
|
Chris@179
|
898 if (diff == "") return;
|
Chris@163
|
899
|
Chris@148
|
900 QStringList params;
|
jtkorhonen@0
|
901
|
Chris@148
|
902 // Diff given revision against working folder
|
jtkorhonen@0
|
903
|
Chris@148
|
904 params << "--config" << "extensions.extdiff=" << "extdiff";
|
Chris@179
|
905 params << "--program" << diff;
|
Chris@153
|
906 params << "--rev" << Changeset::hashOf(id);
|
Chris@148
|
907
|
Chris@284
|
908 m_runner->requestAction(HgAction(ACT_FOLDERDIFF, m_workFolderPath, params));
|
jtkorhonen@0
|
909 }
|
jtkorhonen@0
|
910
|
Chris@148
|
911 void MainWindow::hgDiffToParent(QString child, QString parent)
|
Chris@148
|
912 {
|
Chris@239
|
913 QString diff = getDiffBinaryName();
|
Chris@179
|
914 if (diff == "") return;
|
Chris@163
|
915
|
Chris@148
|
916 QStringList params;
|
Chris@148
|
917
|
Chris@281
|
918 // Diff given revision against parent revision
|
Chris@148
|
919
|
Chris@148
|
920 params << "--config" << "extensions.extdiff=" << "extdiff";
|
Chris@179
|
921 params << "--program" << diff;
|
Chris@153
|
922 params << "--rev" << Changeset::hashOf(parent)
|
Chris@153
|
923 << "--rev" << Changeset::hashOf(child);
|
Chris@148
|
924
|
Chris@284
|
925 m_runner->requestAction(HgAction(ACT_CHGSETDIFF, m_workFolderPath, params));
|
Chris@273
|
926 }
|
Chris@326
|
927
|
Chris@273
|
928
|
Chris@289
|
929 void MainWindow::hgShowSummaryFor(Changeset *cs)
|
Chris@288
|
930 {
|
Chris@288
|
931 QStringList params;
|
Chris@288
|
932
|
Chris@289
|
933 // This will pick a default parent if there is more than one
|
Chris@289
|
934 // (whereas with diff we need to supply one). But it does need a
|
Chris@289
|
935 // bit more parsing
|
Chris@289
|
936 params << "log" << "--stat" << "--rev" << Changeset::hashOf(cs->id());
|
Chris@289
|
937
|
Chris@289
|
938 m_runner->requestAction(HgAction(ACT_DIFF_SUMMARY, m_workFolderPath,
|
Chris@289
|
939 params, cs));
|
Chris@148
|
940 }
|
Chris@148
|
941
|
jtkorhonen@0
|
942
|
jtkorhonen@0
|
943 void MainWindow::hgUpdate()
|
jtkorhonen@0
|
944 {
|
Chris@109
|
945 QStringList params;
|
jtkorhonen@0
|
946
|
Chris@109
|
947 params << "update";
|
Chris@109
|
948
|
Chris@284
|
949 m_runner->requestAction(HgAction(ACT_UPDATE, m_workFolderPath, params));
|
jtkorhonen@0
|
950 }
|
jtkorhonen@0
|
951
|
jtkorhonen@0
|
952
|
Chris@148
|
953 void MainWindow::hgUpdateToRev(QString id)
|
jtkorhonen@0
|
954 {
|
Chris@148
|
955 QStringList params;
|
jtkorhonen@0
|
956
|
Chris@153
|
957 params << "update" << "--rev" << Changeset::hashOf(id) << "--check";
|
jtkorhonen@0
|
958
|
Chris@284
|
959 m_runner->requestAction(HgAction(ACT_UPDATE, m_workFolderPath, params));
|
jtkorhonen@0
|
960 }
|
jtkorhonen@0
|
961
|
jtkorhonen@0
|
962
|
jtkorhonen@0
|
963 void MainWindow::hgRevert()
|
jtkorhonen@0
|
964 {
|
Chris@326
|
965 hgRevertFiles(QStringList());
|
Chris@326
|
966 }
|
Chris@326
|
967
|
Chris@326
|
968 void MainWindow::hgRevertFiles(QStringList files)
|
Chris@326
|
969 {
|
Chris@109
|
970 QStringList params;
|
Chris@109
|
971 QString comment;
|
Chris@237
|
972 bool all = false;
|
Chris@98
|
973
|
Chris@284
|
974 QStringList allFiles = m_hgTabs->getAllRevertableFiles();
|
Chris@237
|
975 if (files.empty() || files == allFiles) {
|
Chris@237
|
976 files = allFiles;
|
Chris@237
|
977 all = true;
|
Chris@237
|
978 }
|
Chris@237
|
979
|
Chris@237
|
980 QString subsetNote;
|
Chris@237
|
981 if (!all) {
|
Chris@237
|
982 subsetNote = tr("<p><b>Note:</b> you are reverting only the files you have selected, not all of the files that have been changed!");
|
Chris@237
|
983 }
|
Chris@155
|
984
|
Chris@155
|
985 QString rf(tr("Revert files"));
|
Chris@237
|
986
|
Chris@237
|
987 // Set up params before asking for confirmation, because there is
|
Chris@237
|
988 // a failure case here that we would need to report on early
|
Chris@237
|
989
|
Chris@284
|
990 DEBUG << "hgRevert: m_justMerged = " << m_justMerged << ", m_mergeTargetRevision = " << m_mergeTargetRevision << endl;
|
Chris@273
|
991
|
Chris@284
|
992 if (m_justMerged) {
|
Chris@237
|
993
|
Chris@237
|
994 // This is a little fiddly. The proper way to "revert" the
|
Chris@237
|
995 // whole of an uncommitted merge is with "hg update --clean ."
|
Chris@237
|
996 // But if the user has selected only some files, we're sort of
|
Chris@237
|
997 // promising to revert only those, which means we need to
|
Chris@237
|
998 // specify which parent to revert to. We can only do that if
|
Chris@237
|
999 // we have a record of it, which we do if you just did the
|
Chris@237
|
1000 // merge from within easyhg but don't if you've exited and
|
Chris@237
|
1001 // restarted, or changed repository, since then. Hmmm.
|
Chris@237
|
1002
|
Chris@237
|
1003 if (all) {
|
Chris@237
|
1004 params << "update" << "--clean" << ".";
|
Chris@237
|
1005 } else {
|
Chris@284
|
1006 if (m_mergeTargetRevision != "") {
|
Chris@237
|
1007 params << "revert" << "--rev"
|
Chris@284
|
1008 << Changeset::hashOf(m_mergeTargetRevision)
|
Chris@237
|
1009 << "--" << files;
|
Chris@237
|
1010 } else {
|
Chris@237
|
1011 QMessageBox::information
|
Chris@237
|
1012 (this, tr("Unable to revert"),
|
Chris@237
|
1013 tr("<qt><b>Sorry, unable to revert these files</b><br><br>EasyMercurial can only revert a subset of files during a merge if it still has a record of which parent was the original merge target; that information is no longer available.<br><br>This is a limitation of EasyMercurial. Consider reverting all files, or using hg revert with a specific revision at the command-line instead.</qt>"));
|
Chris@237
|
1014 return;
|
Chris@237
|
1015 }
|
Chris@237
|
1016 }
|
Chris@237
|
1017 } else {
|
Chris@237
|
1018 params << "revert" << "--" << files;
|
Chris@237
|
1019 }
|
Chris@237
|
1020
|
Chris@109
|
1021 if (ConfirmCommentDialog::confirmDangerousFilesAction
|
Chris@109
|
1022 (this,
|
Chris@155
|
1023 rf,
|
Chris@237
|
1024 tr("<h3>%1</h3><p>%2%3").arg(rf)
|
Chris@237
|
1025 .arg(tr("You are about to <b>revert</b> the following files to their previous committed state.<br><br>This will <b>throw away any changes</b> that you have made to these files but have not committed."))
|
Chris@237
|
1026 .arg(subsetNote),
|
Chris@237
|
1027 tr("<h3>%1</h3><p>%2%3").arg(rf)
|
Chris@237
|
1028 .arg(tr("You are about to <b>revert</b> %n file(s).<br><br>This will <b>throw away any changes</b> that you have made to these files but have not committed.", "", files.size()))
|
Chris@237
|
1029 .arg(subsetNote),
|
Chris@193
|
1030 files,
|
Chris@365
|
1031 tr("Re&vert"))) {
|
Chris@163
|
1032
|
Chris@284
|
1033 m_lastRevertedFiles = files;
|
Chris@109
|
1034
|
Chris@284
|
1035 m_runner->requestAction(HgAction(ACT_REVERT, m_workFolderPath, params));
|
jtkorhonen@0
|
1036 }
|
jtkorhonen@0
|
1037 }
|
jtkorhonen@0
|
1038
|
Chris@163
|
1039
|
Chris@361
|
1040 void MainWindow::hgRenameFiles(QStringList files)
|
Chris@361
|
1041 {
|
Chris@361
|
1042 QString renameTo;
|
Chris@361
|
1043
|
Chris@361
|
1044 QString file;
|
Chris@361
|
1045 if (files.empty()) return;
|
Chris@361
|
1046 file = files[0];
|
Chris@361
|
1047
|
Chris@361
|
1048 if (ConfirmCommentDialog::confirmAndGetShortComment
|
Chris@361
|
1049 (this,
|
Chris@361
|
1050 tr("Rename"),
|
Chris@361
|
1051 tr("Rename <code>%1</code> to:").arg(xmlEncode(file)),
|
Chris@361
|
1052 renameTo,
|
Chris@365
|
1053 tr("Re&name"))) {
|
Chris@361
|
1054
|
Chris@361
|
1055 if (renameTo != "" && renameTo != file) {
|
Chris@361
|
1056
|
Chris@361
|
1057 QStringList params;
|
Chris@361
|
1058
|
Chris@361
|
1059 params << "rename" << "--" << file << renameTo;
|
Chris@361
|
1060
|
Chris@361
|
1061 m_runner->requestAction(HgAction(ACT_RENAME_FILE, m_workFolderPath, params));
|
Chris@361
|
1062 }
|
Chris@361
|
1063 }
|
Chris@361
|
1064 }
|
Chris@361
|
1065
|
Chris@361
|
1066
|
Chris@361
|
1067 void MainWindow::hgCopyFiles(QStringList files)
|
Chris@361
|
1068 {
|
Chris@361
|
1069 QString copyTo;
|
Chris@361
|
1070
|
Chris@361
|
1071 QString file;
|
Chris@361
|
1072 if (files.empty()) return;
|
Chris@361
|
1073 file = files[0];
|
Chris@361
|
1074
|
Chris@361
|
1075 if (ConfirmCommentDialog::confirmAndGetShortComment
|
Chris@361
|
1076 (this,
|
Chris@361
|
1077 tr("Copy"),
|
Chris@361
|
1078 tr("Copy <code>%1</code> to:").arg(xmlEncode(file)),
|
Chris@361
|
1079 copyTo,
|
Chris@365
|
1080 tr("Co&py"))) {
|
Chris@361
|
1081
|
Chris@361
|
1082 if (copyTo != "" && copyTo != file) {
|
Chris@361
|
1083
|
Chris@361
|
1084 QStringList params;
|
Chris@361
|
1085
|
Chris@361
|
1086 params << "copy" << "--" << file << copyTo;
|
Chris@361
|
1087
|
Chris@361
|
1088 m_runner->requestAction(HgAction(ACT_COPY_FILE, m_workFolderPath, params));
|
Chris@361
|
1089 }
|
Chris@361
|
1090 }
|
Chris@361
|
1091 }
|
Chris@361
|
1092
|
Chris@361
|
1093
|
Chris@326
|
1094 void MainWindow::hgMarkFilesResolved(QStringList files)
|
Chris@163
|
1095 {
|
Chris@163
|
1096 QStringList params;
|
Chris@163
|
1097
|
Chris@163
|
1098 params << "resolve" << "--mark";
|
Chris@163
|
1099
|
Chris@163
|
1100 if (files.empty()) {
|
Chris@163
|
1101 params << "--all";
|
Chris@163
|
1102 } else {
|
Chris@164
|
1103 params << "--" << files;
|
Chris@163
|
1104 }
|
Chris@163
|
1105
|
Chris@284
|
1106 m_runner->requestAction(HgAction(ACT_RESOLVE_MARK, m_workFolderPath, params));
|
Chris@163
|
1107 }
|
Chris@163
|
1108
|
Chris@163
|
1109
|
Chris@326
|
1110 void MainWindow::hgRedoMerge()
|
Chris@326
|
1111 {
|
Chris@326
|
1112 hgRedoFileMerges(QStringList());
|
Chris@326
|
1113 }
|
Chris@326
|
1114
|
Chris@326
|
1115
|
Chris@326
|
1116 void MainWindow::hgRedoFileMerges(QStringList files)
|
jtkorhonen@33
|
1117 {
|
Chris@109
|
1118 QStringList params;
|
jtkorhonen@33
|
1119
|
Chris@163
|
1120 params << "resolve";
|
Chris@163
|
1121
|
Chris@239
|
1122 QString merge = getMergeBinaryName();
|
Chris@179
|
1123 if (merge != "") {
|
Chris@179
|
1124 params << "--tool" << merge;
|
Chris@163
|
1125 }
|
Chris@163
|
1126
|
Chris@163
|
1127 if (files.empty()) {
|
Chris@163
|
1128 params << "--all";
|
Chris@163
|
1129 } else {
|
Chris@164
|
1130 params << "--" << files;
|
Chris@163
|
1131 }
|
Chris@163
|
1132
|
Chris@284
|
1133 if (m_currentParents.size() == 1) {
|
Chris@284
|
1134 m_mergeTargetRevision = m_currentParents[0]->id();
|
Chris@237
|
1135 }
|
Chris@237
|
1136
|
Chris@284
|
1137 m_runner->requestAction(HgAction(ACT_RETRY_MERGE, m_workFolderPath, params));
|
Chris@273
|
1138
|
Chris@284
|
1139 m_mergeCommitComment = tr("Merge");
|
jtkorhonen@33
|
1140 }
|
Chris@326
|
1141
|
jtkorhonen@33
|
1142
|
jtkorhonen@0
|
1143 void MainWindow::hgMerge()
|
jtkorhonen@0
|
1144 {
|
Chris@284
|
1145 if (m_hgTabs->canResolve()) {
|
Chris@326
|
1146 hgRedoMerge();
|
Chris@163
|
1147 return;
|
Chris@163
|
1148 }
|
Chris@163
|
1149
|
Chris@109
|
1150 QStringList params;
|
jtkorhonen@0
|
1151
|
Chris@109
|
1152 params << "merge";
|
Chris@163
|
1153
|
Chris@239
|
1154 QString merge = getMergeBinaryName();
|
Chris@179
|
1155 if (merge != "") {
|
Chris@179
|
1156 params << "--tool" << merge;
|
Chris@163
|
1157 }
|
Chris@163
|
1158
|
Chris@284
|
1159 if (m_currentParents.size() == 1) {
|
Chris@284
|
1160 m_mergeTargetRevision = m_currentParents[0]->id();
|
Chris@163
|
1161 }
|
Chris@163
|
1162
|
Chris@284
|
1163 m_runner->requestAction(HgAction(ACT_MERGE, m_workFolderPath, params));
|
Chris@273
|
1164
|
Chris@284
|
1165 m_mergeCommitComment = tr("Merge");
|
jtkorhonen@0
|
1166 }
|
jtkorhonen@0
|
1167
|
jtkorhonen@0
|
1168
|
Chris@148
|
1169 void MainWindow::hgMergeFrom(QString id)
|
Chris@148
|
1170 {
|
Chris@148
|
1171 QStringList params;
|
Chris@148
|
1172
|
Chris@148
|
1173 params << "merge";
|
Chris@153
|
1174 params << "--rev" << Changeset::hashOf(id);
|
Chris@163
|
1175
|
Chris@239
|
1176 QString merge = getMergeBinaryName();
|
Chris@179
|
1177 if (merge != "") {
|
Chris@179
|
1178 params << "--tool" << merge;
|
Chris@163
|
1179 }
|
Chris@148
|
1180
|
Chris@284
|
1181 if (m_currentParents.size() == 1) {
|
Chris@284
|
1182 m_mergeTargetRevision = m_currentParents[0]->id();
|
Chris@237
|
1183 }
|
Chris@237
|
1184
|
Chris@284
|
1185 m_runner->requestAction(HgAction(ACT_MERGE, m_workFolderPath, params));
|
Chris@273
|
1186
|
Chris@284
|
1187 m_mergeCommitComment = "";
|
Chris@273
|
1188
|
Chris@284
|
1189 foreach (Changeset *cs, m_currentHeads) {
|
Chris@284
|
1190 if (cs->id() == id && !cs->isOnBranch(m_currentBranch)) {
|
Chris@157
|
1191 if (cs->branch() == "" || cs->branch() == "default") {
|
Chris@284
|
1192 m_mergeCommitComment = tr("Merge from the default branch");
|
Chris@157
|
1193 } else {
|
Chris@284
|
1194 m_mergeCommitComment = tr("Merge from branch \"%1\"").arg(cs->branch());
|
Chris@157
|
1195 }
|
Chris@157
|
1196 }
|
Chris@157
|
1197 }
|
Chris@157
|
1198
|
Chris@284
|
1199 if (m_mergeCommitComment == "") {
|
Chris@284
|
1200 m_mergeCommitComment = tr("Merge from %1").arg(id);
|
Chris@157
|
1201 }
|
Chris@148
|
1202 }
|
Chris@148
|
1203
|
Chris@148
|
1204
|
jtkorhonen@0
|
1205 void MainWindow::hgCloneFromRemote()
|
jtkorhonen@0
|
1206 {
|
Chris@109
|
1207 QStringList params;
|
jtkorhonen@0
|
1208
|
Chris@284
|
1209 if (!QDir(m_workFolderPath).exists()) {
|
Chris@284
|
1210 if (!QDir().mkpath(m_workFolderPath)) {
|
Chris@109
|
1211 DEBUG << "hgCloneFromRemote: Failed to create target path "
|
Chris@284
|
1212 << m_workFolderPath << endl;
|
Chris@109
|
1213 //!!! report error
|
Chris@109
|
1214 return;
|
Chris@104
|
1215 }
|
Chris@109
|
1216 }
|
Chris@104
|
1217
|
Chris@284
|
1218 params << "clone" << m_remoteRepoPath << m_workFolderPath;
|
Chris@109
|
1219
|
Chris@287
|
1220 updateWorkFolderAndRepoNames();
|
Chris@284
|
1221 m_hgTabs->updateWorkFolderFileList("");
|
Chris@273
|
1222
|
Chris@284
|
1223 m_runner->requestAction(HgAction(ACT_CLONEFROMREMOTE, m_workFolderPath, params));
|
jtkorhonen@0
|
1224 }
|
jtkorhonen@0
|
1225
|
jtkorhonen@0
|
1226 void MainWindow::hgInit()
|
jtkorhonen@0
|
1227 {
|
Chris@109
|
1228 QStringList params;
|
jtkorhonen@0
|
1229
|
Chris@109
|
1230 params << "init";
|
Chris@284
|
1231 params << m_workFolderPath;
|
Chris@273
|
1232
|
Chris@284
|
1233 m_runner->requestAction(HgAction(ACT_INIT, m_workFolderPath, params));
|
jtkorhonen@0
|
1234 }
|
jtkorhonen@0
|
1235
|
jtkorhonen@0
|
1236 void MainWindow::hgIncoming()
|
jtkorhonen@0
|
1237 {
|
Chris@109
|
1238 QStringList params;
|
jtkorhonen@0
|
1239
|
Chris@284
|
1240 params << "incoming" << "--newest-first" << m_remoteRepoPath;
|
Chris@125
|
1241 params << "--template" << Changeset::getLogTemplate();
|
jtkorhonen@0
|
1242
|
Chris@284
|
1243 m_runner->requestAction(HgAction(ACT_INCOMING, m_workFolderPath, params));
|
jtkorhonen@0
|
1244 }
|
jtkorhonen@0
|
1245
|
jtkorhonen@0
|
1246 void MainWindow::hgPull()
|
jtkorhonen@0
|
1247 {
|
Chris@193
|
1248 if (ConfirmCommentDialog::confirm
|
Chris@126
|
1249 (this, tr("Confirm pull"),
|
Chris@299
|
1250 tr("<qt><h3>Pull from remote repository?</h3></qt>"),
|
Chris@299
|
1251 tr("<qt><p>You are about to pull changes from the remote repository at <code>%1</code>.</p></qt>").arg(xmlEncode(m_remoteRepoPath)),
|
Chris@365
|
1252 tr("&Pull"))) {
|
jtkorhonen@0
|
1253
|
Chris@126
|
1254 QStringList params;
|
Chris@284
|
1255 params << "pull" << m_remoteRepoPath;
|
Chris@284
|
1256 m_runner->requestAction(HgAction(ACT_PULL, m_workFolderPath, params));
|
Chris@126
|
1257 }
|
jtkorhonen@0
|
1258 }
|
jtkorhonen@0
|
1259
|
jtkorhonen@0
|
1260 void MainWindow::hgPush()
|
jtkorhonen@0
|
1261 {
|
Chris@363
|
1262 if (m_remoteRepoPath.isEmpty()) {
|
Chris@363
|
1263 changeRemoteRepo(true);
|
Chris@363
|
1264 if (m_remoteRepoPath.isEmpty()) return;
|
Chris@363
|
1265 }
|
Chris@363
|
1266
|
Chris@356
|
1267 QString uncommittedNote;
|
Chris@356
|
1268 if (m_hgTabs->canCommit()) {
|
Chris@356
|
1269 uncommittedNote = tr("<p><b>Note:</b> You have uncommitted changes. If you want to push these changes to the remote repository, you need to commit them first.");
|
Chris@356
|
1270 }
|
Chris@356
|
1271
|
Chris@193
|
1272 if (ConfirmCommentDialog::confirm
|
Chris@126
|
1273 (this, tr("Confirm push"),
|
Chris@299
|
1274 tr("<qt><h3>Push to remote repository?</h3></qt>"),
|
Chris@356
|
1275 tr("<qt><p>You are about to push your commits to the remote repository at <code>%1</code>.</p>%2</qt>").arg(xmlEncode(m_remoteRepoPath)).arg(uncommittedNote),
|
Chris@365
|
1276 tr("&Push"))) {
|
jtkorhonen@0
|
1277
|
Chris@126
|
1278 QStringList params;
|
Chris@284
|
1279 params << "push" << "--new-branch" << m_remoteRepoPath;
|
Chris@284
|
1280 m_runner->requestAction(HgAction(ACT_PUSH, m_workFolderPath, params));
|
Chris@126
|
1281 }
|
jtkorhonen@0
|
1282 }
|
jtkorhonen@0
|
1283
|
Chris@182
|
1284 QStringList MainWindow::listAllUpIpV4Addresses()
|
jtkorhonen@26
|
1285 {
|
Chris@182
|
1286 QStringList ret;
|
jtkorhonen@26
|
1287 QList<QNetworkInterface> ifaces = QNetworkInterface::allInterfaces();
|
jtkorhonen@26
|
1288
|
Chris@182
|
1289 for (int i = 0; i < ifaces.count(); i++) {
|
jtkorhonen@26
|
1290 QNetworkInterface iface = ifaces.at(i);
|
Chris@182
|
1291 if (iface.flags().testFlag(QNetworkInterface::IsUp)
|
Chris@182
|
1292 && !iface.flags().testFlag(QNetworkInterface::IsLoopBack)) {
|
Chris@182
|
1293 for (int j=0; j<iface.addressEntries().count(); j++) {
|
jtkorhonen@28
|
1294 QHostAddress tmp = iface.addressEntries().at(j).ip();
|
Chris@182
|
1295 if (QAbstractSocket::IPv4Protocol == tmp.protocol()) {
|
Chris@182
|
1296 ret.push_back(tmp.toString());
|
jtkorhonen@24
|
1297 }
|
jtkorhonen@24
|
1298 }
|
jtkorhonen@22
|
1299 }
|
jtkorhonen@17
|
1300 }
|
jtkorhonen@28
|
1301 return ret;
|
jtkorhonen@28
|
1302 }
|
jtkorhonen@17
|
1303
|
Chris@120
|
1304 void MainWindow::clearState()
|
Chris@120
|
1305 {
|
Chris@305
|
1306 DEBUG << "MainWindow::clearState" << endl;
|
Chris@284
|
1307 foreach (Changeset *cs, m_currentParents) delete cs;
|
Chris@284
|
1308 m_currentParents.clear();
|
Chris@284
|
1309 foreach (Changeset *cs, m_currentHeads) delete cs;
|
Chris@284
|
1310 m_currentHeads.clear();
|
Chris@506
|
1311 m_closedHeadIds.clear();
|
Chris@284
|
1312 m_currentBranch = "";
|
Chris@284
|
1313 m_lastStatOutput = "";
|
Chris@284
|
1314 m_lastRevertedFiles.clear();
|
Chris@284
|
1315 m_mergeTargetRevision = "";
|
Chris@284
|
1316 m_mergeCommitComment = "";
|
Chris@284
|
1317 m_stateUnknown = true;
|
Chris@284
|
1318 m_needNewLog = true;
|
Chris@120
|
1319 }
|
jtkorhonen@17
|
1320
|
jtkorhonen@11
|
1321 void MainWindow::hgServe()
|
jtkorhonen@11
|
1322 {
|
Chris@109
|
1323 QStringList params;
|
Chris@109
|
1324 QString msg;
|
jtkorhonen@11
|
1325
|
Chris@182
|
1326 QStringList addrs = listAllUpIpV4Addresses();
|
Chris@182
|
1327
|
Chris@182
|
1328 if (addrs.empty()) {
|
Chris@182
|
1329 QMessageBox::critical
|
Chris@182
|
1330 (this, tr("Serve"), tr("Failed to identify an active IPv4 address"));
|
Chris@182
|
1331 return;
|
Chris@182
|
1332 }
|
Chris@182
|
1333
|
Chris@526
|
1334 // See #202. We really want to display the port that the server
|
Chris@526
|
1335 // ends up using -- but we don't get that information until after
|
Chris@526
|
1336 // it has exited! However, we can improve the likelihood of
|
Chris@526
|
1337 // showing the right port by at least checking whether a port is
|
Chris@526
|
1338 // defined in the hgrc file.
|
Chris@526
|
1339
|
Chris@526
|
1340 QFileInfo hgrc(QDir::homePath() + "/.hgrc");
|
Chris@526
|
1341 QString path;
|
Chris@526
|
1342 int port = 8000; // the default
|
Chris@526
|
1343 if (hgrc.exists()) {
|
Chris@526
|
1344 QSettings s(hgrc.canonicalFilePath(), QSettings::IniFormat);
|
Chris@526
|
1345 s.beginGroup("web");
|
Chris@527
|
1346 int p = s.value("port").toInt();
|
Chris@527
|
1347 if (p) port = p;
|
Chris@526
|
1348 }
|
Chris@182
|
1349
|
Chris@182
|
1350 QTextStream ts(&msg);
|
Chris@429
|
1351 ts << QString("<qt><h3>%1</h3><p>%2</p>")
|
Chris@425
|
1352 .arg(tr("Sharing Repository"))
|
Chris@429
|
1353 .arg(tr("Your local repository is now being made temporarily available via HTTP for workgroup access."));
|
Chris@429
|
1354 if (addrs.size() > 1) {
|
Chris@429
|
1355 ts << QString("<p>%3</p>")
|
Chris@429
|
1356 .arg(tr("Users who have network access to your computer can now clone your repository, by using one of the following URLs as a remote location:"));
|
Chris@429
|
1357 } else {
|
Chris@429
|
1358 ts << QString("<p>%3</p>")
|
Chris@429
|
1359 .arg(tr("Users who have network access to your computer can now clone your repository, by using the following URL as a remote location:"));
|
Chris@429
|
1360 }
|
Chris@182
|
1361 foreach (QString addr, addrs) {
|
Chris@526
|
1362 ts << QString("<pre> http://%1:%2</pre>").arg(xmlEncode(addr)).arg(port);
|
Chris@182
|
1363 }
|
Chris@425
|
1364 ts << tr("<p>Press Close to terminate this server, end remote access, and return.</p>");
|
Chris@182
|
1365 ts.flush();
|
Chris@182
|
1366
|
Chris@109
|
1367 params << "serve";
|
jtkorhonen@11
|
1368
|
Chris@284
|
1369 m_runner->requestAction(HgAction(ACT_SERVE, m_workFolderPath, params));
|
Chris@109
|
1370
|
Chris@425
|
1371 QMessageBox::information(this, tr("Share Repository"), msg, QMessageBox::Close);
|
Chris@182
|
1372
|
Chris@284
|
1373 m_runner->killCurrentActions();
|
jtkorhonen@11
|
1374 }
|
jtkorhonen@11
|
1375
|
Chris@64
|
1376 void MainWindow::startupDialog()
|
Chris@64
|
1377 {
|
Chris@64
|
1378 StartupDialog *dlg = new StartupDialog(this);
|
Chris@284
|
1379 if (dlg->exec()) m_firstStart = false;
|
Chris@344
|
1380 else exit(0);
|
Chris@64
|
1381 }
|
jtkorhonen@11
|
1382
|
Chris@69
|
1383 void MainWindow::open()
|
Chris@69
|
1384 {
|
Chris@86
|
1385 bool done = false;
|
Chris@69
|
1386
|
Chris@86
|
1387 while (!done) {
|
Chris@69
|
1388
|
Chris@86
|
1389 MultiChoiceDialog *d = new MultiChoiceDialog
|
Chris@86
|
1390 (tr("Open Repository"),
|
Chris@86
|
1391 tr("<qt><big>What would you like to open?</big></qt>"),
|
Chris@86
|
1392 this);
|
Chris@69
|
1393
|
Chris@345
|
1394 d->addChoice("remote",
|
Chris@345
|
1395 tr("<qt><center><img src=\":images/browser-64.png\"><br>Remote repository</center></qt>"),
|
Chris@345
|
1396 tr("Open a remote Mercurial repository, by cloning from its URL into a local folder."),
|
Chris@345
|
1397 MultiChoiceDialog::UrlToDirectoryArg);
|
Chris@345
|
1398
|
Chris@339
|
1399 d->addChoice("local",
|
Chris@339
|
1400 tr("<qt><center><img src=\":images/hglogo-64.png\"><br>Local repository</center></qt>"),
|
Chris@339
|
1401 tr("Open an existing local Mercurial repository."),
|
Chris@339
|
1402 MultiChoiceDialog::DirectoryArg);
|
Chris@339
|
1403
|
Chris@339
|
1404 d->addChoice("init",
|
Chris@339
|
1405 tr("<qt><center><img src=\":images/hdd_unmount-64.png\"><br>File folder</center></qt>"),
|
Chris@339
|
1406 tr("Open a local folder, by creating a Mercurial repository in it."),
|
Chris@339
|
1407 MultiChoiceDialog::DirectoryArg);
|
Chris@339
|
1408
|
Chris@248
|
1409 QSettings settings;
|
Chris@484
|
1410 settings.beginGroup("");
|
Chris@359
|
1411 QString lastChoice = settings.value("lastopentype", "remote").toString();
|
Chris@248
|
1412 if (lastChoice != "local" &&
|
Chris@248
|
1413 lastChoice != "remote" &&
|
Chris@248
|
1414 lastChoice != "init") {
|
Chris@359
|
1415 lastChoice = "remote";
|
Chris@248
|
1416 }
|
Chris@248
|
1417
|
Chris@248
|
1418 d->setCurrentChoice(lastChoice);
|
Chris@86
|
1419
|
Chris@86
|
1420 if (d->exec() == QDialog::Accepted) {
|
Chris@86
|
1421
|
Chris@86
|
1422 QString choice = d->getCurrentChoice();
|
Chris@248
|
1423 settings.setValue("lastopentype", choice);
|
Chris@248
|
1424
|
Chris@86
|
1425 QString arg = d->getArgument().trimmed();
|
Chris@86
|
1426
|
Chris@86
|
1427 bool result = false;
|
Chris@86
|
1428
|
Chris@86
|
1429 if (choice == "local") {
|
Chris@86
|
1430 result = openLocal(arg);
|
Chris@86
|
1431 } else if (choice == "remote") {
|
Chris@86
|
1432 result = openRemote(arg, d->getAdditionalArgument().trimmed());
|
Chris@86
|
1433 } else if (choice == "init") {
|
Chris@86
|
1434 result = openInit(arg);
|
Chris@86
|
1435 }
|
Chris@86
|
1436
|
Chris@86
|
1437 if (result) {
|
Chris@86
|
1438 enableDisableActions();
|
Chris@120
|
1439 clearState();
|
Chris@109
|
1440 hgQueryPaths();
|
Chris@91
|
1441 done = true;
|
Chris@91
|
1442 }
|
Chris@86
|
1443
|
Chris@86
|
1444 } else {
|
Chris@86
|
1445
|
Chris@86
|
1446 // cancelled
|
Chris@86
|
1447 done = true;
|
Chris@69
|
1448 }
|
Chris@79
|
1449
|
Chris@86
|
1450 delete d;
|
Chris@69
|
1451 }
|
Chris@69
|
1452 }
|
Chris@69
|
1453
|
Chris@359
|
1454 void MainWindow::recentMenuActivated()
|
Chris@359
|
1455 {
|
Chris@359
|
1456 QAction *a = qobject_cast<QAction *>(sender());
|
Chris@359
|
1457 if (!a) return;
|
Chris@359
|
1458 QString local = a->text();
|
Chris@359
|
1459 open(local);
|
Chris@359
|
1460 }
|
Chris@359
|
1461
|
Chris@182
|
1462 void MainWindow::changeRemoteRepo()
|
Chris@182
|
1463 {
|
Chris@363
|
1464 changeRemoteRepo(false);
|
Chris@363
|
1465 }
|
Chris@363
|
1466
|
Chris@363
|
1467 void MainWindow::changeRemoteRepo(bool initial)
|
Chris@363
|
1468 {
|
Chris@183
|
1469 // This will involve rewriting the local .hgrc
|
Chris@183
|
1470
|
Chris@284
|
1471 QDir hgDir(m_workFolderPath + "/.hg");
|
Chris@184
|
1472 if (!hgDir.exists()) {
|
Chris@184
|
1473 //!!! visible error!
|
Chris@184
|
1474 return;
|
Chris@184
|
1475 }
|
Chris@184
|
1476
|
Chris@284
|
1477 QFileInfo hgrc(m_workFolderPath + "/.hg/hgrc");
|
Chris@184
|
1478 if (hgrc.exists() && !hgrc.isWritable()) {
|
Chris@183
|
1479 //!!! visible error!
|
Chris@183
|
1480 return;
|
Chris@183
|
1481 }
|
Chris@183
|
1482
|
Chris@183
|
1483 MultiChoiceDialog *d = new MultiChoiceDialog
|
Chris@363
|
1484 (tr("Set Remote Location"),
|
Chris@363
|
1485 tr("<qt><big>Set the remote location</big></qt>"),
|
Chris@183
|
1486 this);
|
Chris@183
|
1487
|
Chris@363
|
1488 QString explanation;
|
Chris@363
|
1489 if (initial) {
|
Chris@363
|
1490 explanation = tr("Provide a URL to use for push and pull actions from the current local repository.<br>This will be the default for subsequent pushes and pulls.<br>You can change it using “Set Remote Location” on the File menu.");
|
Chris@363
|
1491 } else {
|
Chris@363
|
1492 explanation = tr("Provide a new URL to use for push and pull actions from the current local repository.");
|
Chris@363
|
1493 }
|
Chris@363
|
1494
|
Chris@183
|
1495 d->addChoice("remote",
|
Chris@183
|
1496 tr("<qt><center><img src=\":images/browser-64.png\"><br>Remote repository</center></qt>"),
|
Chris@363
|
1497 explanation,
|
Chris@553
|
1498 MultiChoiceDialog::UrlArg,
|
Chris@553
|
1499 true); // default empty
|
Chris@183
|
1500
|
Chris@183
|
1501 if (d->exec() == QDialog::Accepted) {
|
Chris@210
|
1502
|
Chris@210
|
1503 // New block to ensure QSettings is deleted before
|
Chris@210
|
1504 // hgQueryPaths called. NB use of absoluteFilePath instead of
|
Chris@210
|
1505 // canonicalFilePath, which would fail if the file did not yet
|
Chris@210
|
1506 // exist
|
Chris@210
|
1507
|
Chris@210
|
1508 {
|
Chris@210
|
1509 QSettings s(hgrc.absoluteFilePath(), QSettings::IniFormat);
|
Chris@210
|
1510 s.beginGroup("paths");
|
Chris@210
|
1511 s.setValue("default", d->getArgument());
|
Chris@210
|
1512 }
|
Chris@210
|
1513
|
Chris@284
|
1514 m_stateUnknown = true;
|
Chris@183
|
1515 hgQueryPaths();
|
Chris@183
|
1516 }
|
Chris@183
|
1517
|
Chris@183
|
1518 delete d;
|
Chris@182
|
1519 }
|
Chris@182
|
1520
|
Chris@145
|
1521 void MainWindow::open(QString local)
|
Chris@145
|
1522 {
|
Chris@145
|
1523 if (openLocal(local)) {
|
Chris@145
|
1524 enableDisableActions();
|
Chris@145
|
1525 clearState();
|
Chris@145
|
1526 hgQueryPaths();
|
Chris@145
|
1527 }
|
Chris@145
|
1528 }
|
Chris@145
|
1529
|
Chris@79
|
1530 bool MainWindow::complainAboutFilePath(QString arg)
|
Chris@79
|
1531 {
|
Chris@79
|
1532 QMessageBox::critical
|
Chris@79
|
1533 (this, tr("File chosen"),
|
Chris@84
|
1534 tr("<qt><b>Folder required</b><br><br>You asked to open \"%1\".<br>This is a file; to open a repository, you need to choose a folder.</qt>").arg(xmlEncode(arg)));
|
Chris@79
|
1535 return false;
|
Chris@79
|
1536 }
|
Chris@79
|
1537
|
Chris@248
|
1538 bool MainWindow::askAboutUnknownFolder(QString arg)
|
Chris@248
|
1539 {
|
Chris@248
|
1540 bool result = (QMessageBox::question
|
Chris@248
|
1541 (this, tr("Path does not exist"),
|
Chris@248
|
1542 tr("<qt><b>Path does not exist: create it?</b><br><br>You asked to open a remote repository by cloning it to \"%1\". This folder does not exist, and neither does its parent.<br><br>Would you like to create the parent folder as well?</qt>").arg(xmlEncode(arg)),
|
Chris@248
|
1543 QMessageBox::Ok | QMessageBox::Cancel,
|
Chris@248
|
1544 QMessageBox::Cancel)
|
Chris@248
|
1545 == QMessageBox::Ok);
|
Chris@248
|
1546 if (result) {
|
Chris@248
|
1547 QDir dir(arg);
|
Chris@248
|
1548 dir.cdUp();
|
Chris@248
|
1549 if (!dir.mkpath(dir.absolutePath())) {
|
Chris@248
|
1550 QMessageBox::critical
|
Chris@248
|
1551 (this, tr("Failed to create folder"),
|
Chris@248
|
1552 tr("<qt><b>Failed to create folder</b><br><br>Sorry, the path for the parent folder \"%1\" could not be created.</qt>").arg(dir.absolutePath()));
|
Chris@248
|
1553 return false;
|
Chris@248
|
1554 }
|
Chris@248
|
1555 return true;
|
Chris@248
|
1556 }
|
Chris@248
|
1557 return false;
|
Chris@248
|
1558 }
|
Chris@248
|
1559
|
Chris@79
|
1560 bool MainWindow::complainAboutUnknownFolder(QString arg)
|
Chris@79
|
1561 {
|
Chris@79
|
1562 QMessageBox::critical
|
Chris@79
|
1563 (this, tr("Folder does not exist"),
|
Chris@84
|
1564 tr("<qt><b>Folder does not exist</b><br><br>You asked to open \"%1\".<br>This folder does not exist, and it cannot be created because its parent does not exist either.</qt>").arg(xmlEncode(arg)));
|
Chris@84
|
1565 return false;
|
Chris@84
|
1566 }
|
Chris@84
|
1567
|
Chris@84
|
1568 bool MainWindow::complainAboutInitInRepo(QString arg)
|
Chris@84
|
1569 {
|
Chris@84
|
1570 QMessageBox::critical
|
Chris@84
|
1571 (this, tr("Path is in existing repository"),
|
Chris@84
|
1572 tr("<qt><b>Path is in an existing repository</b><br><br>You asked to initialise a repository at \"%1\".<br>This path is already inside an existing repository.</qt>").arg(xmlEncode(arg)));
|
Chris@84
|
1573 return false;
|
Chris@84
|
1574 }
|
Chris@84
|
1575
|
Chris@84
|
1576 bool MainWindow::complainAboutInitFile(QString arg)
|
Chris@84
|
1577 {
|
Chris@84
|
1578 QMessageBox::critical
|
Chris@84
|
1579 (this, tr("Path is a file"),
|
Chris@84
|
1580 tr("<qt><b>Path is a file</b><br><br>You asked to initialise a repository at \"%1\".<br>This is an existing file; it is only possible to initialise in folders.</qt>").arg(xmlEncode(arg)));
|
Chris@84
|
1581 return false;
|
Chris@84
|
1582 }
|
Chris@84
|
1583
|
Chris@84
|
1584 bool MainWindow::complainAboutCloneToExisting(QString arg)
|
Chris@84
|
1585 {
|
Chris@84
|
1586 QMessageBox::critical
|
Chris@84
|
1587 (this, tr("Path is in existing repository"),
|
Chris@237
|
1588 tr("<qt><b>Local path is in an existing repository</b><br><br>You asked to open a remote repository by cloning it to the local path \"%1\".<br>This path is already inside an existing repository.<br>Please provide a different folder name for the local repository.</qt>").arg(xmlEncode(arg)));
|
Chris@84
|
1589 return false;
|
Chris@84
|
1590 }
|
Chris@84
|
1591
|
Chris@84
|
1592 bool MainWindow::complainAboutCloneToFile(QString arg)
|
Chris@84
|
1593 {
|
Chris@84
|
1594 QMessageBox::critical
|
Chris@84
|
1595 (this, tr("Path is a file"),
|
Chris@84
|
1596 tr("<qt><b>Local path is a file</b><br><br>You asked to open a remote repository by cloning it to the local path \"%1\".<br>This path is an existing file.<br>Please provide a new folder name for the local repository.</qt>").arg(xmlEncode(arg)));
|
Chris@84
|
1597 return false;
|
Chris@84
|
1598 }
|
Chris@84
|
1599
|
Chris@237
|
1600 QString MainWindow::complainAboutCloneToExistingFolder(QString arg, QString remote)
|
Chris@84
|
1601 {
|
Chris@348
|
1602 // If the directory "arg" exists but is empty, then we accept it.
|
Chris@348
|
1603
|
Chris@348
|
1604 // If the directory "arg" exists and is non-empty, but "arg" plus
|
Chris@348
|
1605 // the last path component of "remote" does not exist, then offer
|
Chris@348
|
1606 // the latter as an alternative path.
|
Chris@237
|
1607
|
Chris@237
|
1608 QString offer;
|
Chris@237
|
1609
|
Chris@237
|
1610 QDir d(arg);
|
Chris@348
|
1611
|
Chris@237
|
1612 if (d.exists()) {
|
Chris@348
|
1613
|
Chris@348
|
1614 if (d.entryList(QDir::Dirs | QDir::Files |
|
Chris@348
|
1615 QDir::NoDotAndDotDot |
|
Chris@348
|
1616 QDir::Hidden | QDir::System).empty()) {
|
Chris@348
|
1617 // directory is empty; accept it
|
Chris@348
|
1618 return arg;
|
Chris@348
|
1619 }
|
Chris@348
|
1620
|
Chris@237
|
1621 if (QRegExp("^\\w+://").indexIn(remote) >= 0) {
|
Chris@237
|
1622 QString rpath = QUrl(remote).path();
|
Chris@237
|
1623 if (rpath != "") {
|
Chris@237
|
1624 rpath = QDir(rpath).dirName();
|
Chris@237
|
1625 if (rpath != "" && !d.exists(rpath)) {
|
Chris@237
|
1626 offer = d.filePath(rpath);
|
Chris@237
|
1627 }
|
Chris@237
|
1628 }
|
Chris@237
|
1629 }
|
Chris@237
|
1630 }
|
Chris@237
|
1631
|
Chris@237
|
1632 if (offer != "") {
|
Chris@237
|
1633 bool result = (QMessageBox::question
|
Chris@237
|
1634 (this, tr("Folder exists"),
|
Chris@237
|
1635 tr("<qt><b>Local folder already exists</b><br><br>You asked to open a remote repository by cloning it to \"%1\", but this folder already exists and so cannot be cloned to.<br><br>Would you like to create the new folder \"%2\" instead?</qt>")
|
Chris@237
|
1636 .arg(xmlEncode(arg)).arg(xmlEncode(offer)),
|
Chris@237
|
1637 QMessageBox::Ok | QMessageBox::Cancel,
|
Chris@237
|
1638 QMessageBox::Cancel)
|
Chris@237
|
1639 == QMessageBox::Ok);
|
Chris@237
|
1640 if (result) return offer;
|
Chris@237
|
1641 else return "";
|
Chris@237
|
1642 }
|
Chris@237
|
1643
|
Chris@84
|
1644 QMessageBox::critical
|
Chris@84
|
1645 (this, tr("Folder exists"),
|
Chris@237
|
1646 tr("<qt><b>Local folder already exists</b><br><br>You asked to open a remote repository by cloning it to \"%1\", but this file or folder already exists and so cannot be cloned to.<br>Please provide a different folder name for the local repository.</qt>").arg(xmlEncode(arg)));
|
Chris@237
|
1647 return "";
|
Chris@79
|
1648 }
|
Chris@79
|
1649
|
Chris@79
|
1650 bool MainWindow::askToOpenParentRepo(QString arg, QString parent)
|
Chris@79
|
1651 {
|
Chris@79
|
1652 return (QMessageBox::question
|
Chris@84
|
1653 (this, tr("Path is inside a repository"),
|
Chris@86
|
1654 tr("<qt><b>Open the repository that contains this path?</b><br><br>You asked to open \"%1\".<br>This is not the root folder of a repository.<br>But it is inside a repository, whose root is at \"%2\". <br><br>Would you like to open that repository instead?</qt>")
|
Chris@79
|
1655 .arg(xmlEncode(arg)).arg(xmlEncode(parent)),
|
Chris@79
|
1656 QMessageBox::Ok | QMessageBox::Cancel,
|
Chris@79
|
1657 QMessageBox::Ok)
|
Chris@79
|
1658 == QMessageBox::Ok);
|
Chris@79
|
1659 }
|
Chris@79
|
1660
|
Chris@79
|
1661 bool MainWindow::askToInitExisting(QString arg)
|
Chris@79
|
1662 {
|
Chris@79
|
1663 return (QMessageBox::question
|
Chris@84
|
1664 (this, tr("Folder has no repository"),
|
Chris@359
|
1665 tr("<qt><b>Initialise a repository here?</b><br><br>You asked to open \"%1\".<br>This folder is not a Mercurial working copy.<br><br>Would you like to initialise a repository here?</qt>")
|
Chris@79
|
1666 .arg(xmlEncode(arg)),
|
Chris@79
|
1667 QMessageBox::Ok | QMessageBox::Cancel,
|
Chris@79
|
1668 QMessageBox::Ok)
|
Chris@79
|
1669 == QMessageBox::Ok);
|
Chris@79
|
1670 }
|
Chris@79
|
1671
|
Chris@79
|
1672 bool MainWindow::askToInitNew(QString arg)
|
Chris@79
|
1673 {
|
Chris@79
|
1674 return (QMessageBox::question
|
Chris@84
|
1675 (this, tr("Folder does not exist"),
|
Chris@84
|
1676 tr("<qt><b>Initialise a new repository?</b><br><br>You asked to open \"%1\".<br>This folder does not yet exist.<br><br>Would you like to create the folder and initialise a new empty repository in it?</qt>")
|
Chris@84
|
1677 .arg(xmlEncode(arg)),
|
Chris@84
|
1678 QMessageBox::Ok | QMessageBox::Cancel,
|
Chris@84
|
1679 QMessageBox::Ok)
|
Chris@84
|
1680 == QMessageBox::Ok);
|
Chris@84
|
1681 }
|
Chris@84
|
1682
|
Chris@84
|
1683 bool MainWindow::askToOpenInsteadOfInit(QString arg)
|
Chris@84
|
1684 {
|
Chris@84
|
1685 return (QMessageBox::question
|
Chris@84
|
1686 (this, tr("Repository exists"),
|
Chris@84
|
1687 tr("<qt><b>Open existing repository?</b><br><br>You asked to initialise a new repository at \"%1\".<br>This folder already contains a repository. Would you like to open it?</qt>")
|
Chris@79
|
1688 .arg(xmlEncode(arg)),
|
Chris@79
|
1689 QMessageBox::Ok | QMessageBox::Cancel,
|
Chris@79
|
1690 QMessageBox::Ok)
|
Chris@79
|
1691 == QMessageBox::Ok);
|
Chris@79
|
1692 }
|
Chris@79
|
1693
|
Chris@79
|
1694 bool MainWindow::openLocal(QString local)
|
Chris@79
|
1695 {
|
Chris@79
|
1696 DEBUG << "open " << local << endl;
|
Chris@79
|
1697
|
Chris@79
|
1698 FolderStatus status = getFolderStatus(local);
|
Chris@79
|
1699 QString containing = getContainingRepoFolder(local);
|
Chris@79
|
1700
|
Chris@79
|
1701 switch (status) {
|
Chris@79
|
1702
|
Chris@79
|
1703 case FolderHasRepo:
|
Chris@79
|
1704 // fine
|
Chris@79
|
1705 break;
|
Chris@79
|
1706
|
Chris@79
|
1707 case FolderExists:
|
Chris@79
|
1708 if (containing != "") {
|
Chris@79
|
1709 if (!askToOpenParentRepo(local, containing)) return false;
|
Chris@84
|
1710 local = containing;
|
Chris@79
|
1711 } else {
|
Chris@86
|
1712 //!!! No -- this is likely to happen far more by accident
|
Chris@86
|
1713 // than because the user actually wanted to init something.
|
Chris@86
|
1714 // Don't ask, just politely reject.
|
Chris@79
|
1715 if (!askToInitExisting(local)) return false;
|
Chris@79
|
1716 return openInit(local);
|
Chris@79
|
1717 }
|
Chris@79
|
1718 break;
|
Chris@79
|
1719
|
Chris@79
|
1720 case FolderParentExists:
|
Chris@79
|
1721 if (containing != "") {
|
Chris@79
|
1722 if (!askToOpenParentRepo(local, containing)) return false;
|
Chris@84
|
1723 local = containing;
|
Chris@79
|
1724 } else {
|
Chris@79
|
1725 if (!askToInitNew(local)) return false;
|
Chris@79
|
1726 return openInit(local);
|
Chris@79
|
1727 }
|
Chris@79
|
1728 break;
|
Chris@79
|
1729
|
Chris@79
|
1730 case FolderUnknown:
|
Chris@84
|
1731 if (containing != "") {
|
Chris@84
|
1732 if (!askToOpenParentRepo(local, containing)) return false;
|
Chris@84
|
1733 local = containing;
|
Chris@84
|
1734 } else {
|
Chris@84
|
1735 return complainAboutUnknownFolder(local);
|
Chris@84
|
1736 }
|
Chris@84
|
1737 break;
|
Chris@79
|
1738
|
Chris@79
|
1739 case FolderIsFile:
|
Chris@79
|
1740 return complainAboutFilePath(local);
|
Chris@79
|
1741 }
|
Chris@79
|
1742
|
Chris@284
|
1743 m_workFolderPath = local;
|
Chris@284
|
1744 m_remoteRepoPath = "";
|
Chris@79
|
1745 return true;
|
Chris@79
|
1746 }
|
Chris@79
|
1747
|
Chris@79
|
1748 bool MainWindow::openRemote(QString remote, QString local)
|
Chris@79
|
1749 {
|
Chris@79
|
1750 DEBUG << "clone " << remote << " to " << local << endl;
|
Chris@84
|
1751
|
Chris@84
|
1752 FolderStatus status = getFolderStatus(local);
|
Chris@84
|
1753 QString containing = getContainingRepoFolder(local);
|
Chris@84
|
1754
|
Chris@84
|
1755 DEBUG << "status = " << status << ", containing = " << containing << endl;
|
Chris@84
|
1756
|
Chris@84
|
1757 if (status == FolderHasRepo || containing != "") {
|
Chris@84
|
1758 return complainAboutCloneToExisting(local);
|
Chris@84
|
1759 }
|
Chris@84
|
1760
|
Chris@84
|
1761 if (status == FolderIsFile) {
|
Chris@84
|
1762 return complainAboutCloneToFile(local);
|
Chris@84
|
1763 }
|
Chris@84
|
1764
|
Chris@84
|
1765 if (status == FolderUnknown) {
|
Chris@248
|
1766 if (!askAboutUnknownFolder(local)) {
|
Chris@248
|
1767 return false;
|
Chris@248
|
1768 }
|
Chris@84
|
1769 }
|
Chris@84
|
1770
|
Chris@84
|
1771 if (status == FolderExists) {
|
Chris@237
|
1772 local = complainAboutCloneToExistingFolder(local, remote);
|
Chris@237
|
1773 if (local == "") return false;
|
Chris@84
|
1774 }
|
Chris@84
|
1775
|
Chris@284
|
1776 m_workFolderPath = local;
|
Chris@284
|
1777 m_remoteRepoPath = remote;
|
Chris@84
|
1778 hgCloneFromRemote();
|
Chris@84
|
1779
|
Chris@79
|
1780 return true;
|
Chris@79
|
1781 }
|
Chris@79
|
1782
|
Chris@84
|
1783 bool MainWindow::openInit(QString local)
|
Chris@79
|
1784 {
|
Chris@84
|
1785 DEBUG << "openInit " << local << endl;
|
Chris@84
|
1786
|
Chris@84
|
1787 FolderStatus status = getFolderStatus(local);
|
Chris@84
|
1788 QString containing = getContainingRepoFolder(local);
|
Chris@84
|
1789
|
Chris@84
|
1790 DEBUG << "status = " << status << ", containing = " << containing << endl;
|
Chris@84
|
1791
|
Chris@84
|
1792 if (status == FolderHasRepo) {
|
Chris@84
|
1793 if (!askToOpenInsteadOfInit(local)) return false;
|
Chris@552
|
1794 return openLocal(local);
|
Chris@84
|
1795 }
|
Chris@84
|
1796
|
Chris@84
|
1797 if (containing != "") {
|
Chris@84
|
1798 return complainAboutInitInRepo(local);
|
Chris@84
|
1799 }
|
Chris@84
|
1800
|
Chris@84
|
1801 if (status == FolderIsFile) {
|
Chris@84
|
1802 return complainAboutInitFile(local);
|
Chris@84
|
1803 }
|
Chris@84
|
1804
|
Chris@84
|
1805 if (status == FolderUnknown) {
|
Chris@84
|
1806 return complainAboutUnknownFolder(local);
|
Chris@84
|
1807 }
|
Chris@84
|
1808
|
Chris@284
|
1809 m_workFolderPath = local;
|
Chris@284
|
1810 m_remoteRepoPath = "";
|
Chris@84
|
1811 hgInit();
|
Chris@79
|
1812 return true;
|
Chris@79
|
1813 }
|
Chris@79
|
1814
|
jtkorhonen@0
|
1815 void MainWindow::settings()
|
jtkorhonen@0
|
1816 {
|
Chris@472
|
1817 settings(SettingsDialog::PersonalDetailsTab);
|
Chris@472
|
1818 }
|
Chris@472
|
1819
|
Chris@472
|
1820 void MainWindow::settings(SettingsDialog::Tab tab)
|
Chris@472
|
1821 {
|
jtkorhonen@0
|
1822 SettingsDialog *settingsDlg = new SettingsDialog(this);
|
Chris@472
|
1823 settingsDlg->setCurrentTab(tab);
|
jtkorhonen@0
|
1824 settingsDlg->exec();
|
Chris@230
|
1825
|
Chris@230
|
1826 if (settingsDlg->presentationChanged()) {
|
Chris@284
|
1827 m_hgTabs->updateFileStates();
|
Chris@230
|
1828 updateToolBarStyle();
|
Chris@273
|
1829 hgRefresh();
|
Chris@230
|
1830 }
|
jtkorhonen@0
|
1831 }
|
jtkorhonen@0
|
1832
|
Chris@541
|
1833 void MainWindow::updateFsWatcher()
|
Chris@541
|
1834 {
|
Chris@541
|
1835 m_fsWatcher->setWorkDirPath(m_workFolderPath);
|
Chris@541
|
1836 m_fsWatcher->setTrackedFilePaths(m_hgTabs->getFileStates().trackedFiles());
|
Chris@541
|
1837 }
|
Chris@541
|
1838
|
Chris@238
|
1839 void MainWindow::checkFilesystem()
|
Chris@238
|
1840 {
|
Chris@238
|
1841 DEBUG << "MainWindow::checkFilesystem" << endl;
|
Chris@541
|
1842 if (!m_commandSequenceInProgress) {
|
Chris@541
|
1843 if (!m_fsWatcher->getChangedPaths(m_fsWatcherToken).empty()) {
|
Chris@541
|
1844 hgRefresh();
|
Chris@541
|
1845 return;
|
Chris@541
|
1846 }
|
Chris@549
|
1847 updateFsWatcher();
|
Chris@541
|
1848 }
|
Chris@90
|
1849 }
|
Chris@90
|
1850
|
Chris@275
|
1851 QString MainWindow::format1(QString head)
|
Chris@275
|
1852 {
|
Chris@275
|
1853 return QString("<qt><h3>%1</h3></qt>").arg(head);
|
Chris@275
|
1854 }
|
Chris@275
|
1855
|
Chris@125
|
1856 QString MainWindow::format3(QString head, QString intro, QString code)
|
Chris@125
|
1857 {
|
Chris@196
|
1858 code = xmlEncode(code).replace("\n", "<br>")
|
Chris@196
|
1859 #ifndef Q_OS_WIN32
|
Chris@196
|
1860 // The hard hyphen comes out funny on Windows
|
Chris@196
|
1861 .replace("-", "‑")
|
Chris@196
|
1862 #endif
|
Chris@196
|
1863 .replace(" ", " ");
|
Chris@125
|
1864 if (intro == "") {
|
Chris@168
|
1865 return QString("<qt><h3>%1</h3><p><code>%2</code></p>")
|
Chris@168
|
1866 .arg(head).arg(code);
|
Chris@126
|
1867 } else if (code == "") {
|
Chris@126
|
1868 return QString("<qt><h3>%1</h3><p>%2</p>")
|
Chris@126
|
1869 .arg(head).arg(intro);
|
Chris@125
|
1870 } else {
|
Chris@168
|
1871 return QString("<qt><h3>%1</h3><p>%2</p><p><code>%3</code></p>")
|
Chris@168
|
1872 .arg(head).arg(intro).arg(code);
|
Chris@125
|
1873 }
|
Chris@125
|
1874 }
|
Chris@125
|
1875
|
Chris@120
|
1876 void MainWindow::showIncoming(QString output)
|
Chris@120
|
1877 {
|
Chris@284
|
1878 m_runner->hide();
|
Chris@125
|
1879 IncomingDialog *d = new IncomingDialog(this, output);
|
Chris@125
|
1880 d->exec();
|
Chris@125
|
1881 delete d;
|
Chris@125
|
1882 }
|
Chris@125
|
1883
|
Chris@125
|
1884 int MainWindow::extractChangeCount(QString text)
|
Chris@125
|
1885 {
|
Chris@125
|
1886 QRegExp re("added (\\d+) ch\\w+ with (\\d+) ch\\w+ to (\\d+) f\\w+");
|
Chris@125
|
1887 if (re.indexIn(text) >= 0) {
|
Chris@125
|
1888 return re.cap(1).toInt();
|
Chris@125
|
1889 } else if (text.contains("no changes")) {
|
Chris@125
|
1890 return 0;
|
Chris@125
|
1891 } else {
|
Chris@125
|
1892 return -1; // unknown
|
Chris@125
|
1893 }
|
Chris@120
|
1894 }
|
Chris@120
|
1895
|
Chris@120
|
1896 void MainWindow::showPushResult(QString output)
|
Chris@120
|
1897 {
|
Chris@291
|
1898 QString head;
|
Chris@125
|
1899 QString report;
|
Chris@125
|
1900 int n = extractChangeCount(output);
|
Chris@125
|
1901 if (n > 0) {
|
Chris@291
|
1902 head = tr("Pushed %n changeset(s)", "", n);
|
Chris@300
|
1903 report = tr("<qt>Successfully pushed to the remote repository at <code>%1</code>.</qt>").arg(xmlEncode(m_remoteRepoPath));
|
Chris@125
|
1904 } else if (n == 0) {
|
Chris@291
|
1905 head = tr("No changes to push");
|
Chris@291
|
1906 report = tr("The remote repository already contains all changes that have been committed locally.");
|
Chris@294
|
1907 if (m_hgTabs->canCommit()) {
|
Chris@291
|
1908 report = tr("%1<p>You do have some uncommitted changes. If you wish to push those to the remote repository, commit them locally first.").arg(report);
|
Chris@291
|
1909 }
|
Chris@125
|
1910 } else {
|
Chris@291
|
1911 head = tr("Push complete");
|
Chris@125
|
1912 }
|
Chris@284
|
1913 m_runner->hide();
|
Chris@291
|
1914
|
Chris@291
|
1915 MoreInformationDialog::information(this, tr("Push complete"),
|
Chris@291
|
1916 head, report, output);
|
Chris@120
|
1917 }
|
Chris@120
|
1918
|
Chris@120
|
1919 void MainWindow::showPullResult(QString output)
|
Chris@120
|
1920 {
|
Chris@291
|
1921 QString head;
|
Chris@125
|
1922 QString report;
|
Chris@125
|
1923 int n = extractChangeCount(output);
|
Chris@125
|
1924 if (n > 0) {
|
Chris@291
|
1925 head = tr("Pulled %n changeset(s)", "", n);
|
Chris@322
|
1926 report = tr("New changes will be highlighted in yellow in the history.");
|
Chris@125
|
1927 } else if (n == 0) {
|
Chris@291
|
1928 head = tr("No changes to pull");
|
Chris@291
|
1929 report = tr("Your local repository already contains all changes found in the remote repository.");
|
Chris@125
|
1930 } else {
|
Chris@291
|
1931 head = tr("Pull complete");
|
Chris@125
|
1932 }
|
Chris@284
|
1933 m_runner->hide();
|
Chris@275
|
1934
|
Chris@275
|
1935 MoreInformationDialog::information(this, tr("Pull complete"),
|
Chris@291
|
1936 head, report, output);
|
Chris@120
|
1937 }
|
Chris@120
|
1938
|
Chris@174
|
1939 void MainWindow::reportNewRemoteHeads(QString output)
|
Chris@174
|
1940 {
|
Chris@174
|
1941 bool headsAreLocal = false;
|
Chris@174
|
1942
|
Chris@284
|
1943 if (m_currentParents.size() == 1) {
|
Chris@506
|
1944 int currentBranchActiveHeads = 0;
|
Chris@174
|
1945 bool parentIsHead = false;
|
Chris@284
|
1946 Changeset *parent = m_currentParents[0];
|
Chris@506
|
1947 foreach (Changeset *head, m_activeHeads) {
|
Chris@284
|
1948 if (head->isOnBranch(m_currentBranch)) {
|
Chris@506
|
1949 ++currentBranchActiveHeads;
|
Chris@174
|
1950 }
|
Chris@174
|
1951 if (parent->id() == head->id()) {
|
Chris@174
|
1952 parentIsHead = true;
|
Chris@174
|
1953 }
|
Chris@174
|
1954 }
|
Chris@506
|
1955 if (currentBranchActiveHeads == 2 && parentIsHead) {
|
Chris@174
|
1956 headsAreLocal = true;
|
Chris@174
|
1957 }
|
Chris@174
|
1958 }
|
Chris@174
|
1959
|
Chris@174
|
1960 if (headsAreLocal) {
|
Chris@291
|
1961 MoreInformationDialog::warning
|
Chris@291
|
1962 (this,
|
Chris@291
|
1963 tr("Push failed"),
|
Chris@291
|
1964 tr("Push failed"),
|
Chris@291
|
1965 tr("Your local repository could not be pushed to the remote repository.<br><br>You may need to merge the changes locally first."),
|
Chris@291
|
1966 output);
|
Chris@318
|
1967 } else if (m_hgTabs->canCommit() && m_currentParents.size() > 1) {
|
Chris@318
|
1968 MoreInformationDialog::warning
|
Chris@318
|
1969 (this,
|
Chris@318
|
1970 tr("Push failed"),
|
Chris@318
|
1971 tr("Push failed"),
|
Chris@318
|
1972 tr("Your local repository could not be pushed to the remote repository.<br><br>You have an uncommitted merge in your local folder. You probably need to commit it before you push."),
|
Chris@318
|
1973 output);
|
Chris@174
|
1974 } else {
|
Chris@291
|
1975 MoreInformationDialog::warning
|
Chris@291
|
1976 (this,
|
Chris@291
|
1977 tr("Push failed"),
|
Chris@291
|
1978 tr("Push failed"),
|
Chris@291
|
1979 tr("Your local repository could not be pushed to the remote repository.<br><br>The remote repository may have been changed by someone else since you last pushed. Try pulling and merging their changes into your local repository first."),
|
Chris@291
|
1980 output);
|
Chris@174
|
1981 }
|
Chris@174
|
1982 }
|
Chris@174
|
1983
|
Chris@353
|
1984 void MainWindow::reportAuthFailed(QString output)
|
Chris@353
|
1985 {
|
Chris@353
|
1986 MoreInformationDialog::warning
|
Chris@353
|
1987 (this,
|
Chris@353
|
1988 tr("Authorization failed"),
|
Chris@353
|
1989 tr("Authorization failed"),
|
Chris@353
|
1990 tr("You may have entered an incorrect user name or password, or the remote URL may be wrong.<br><br>Or you may lack the necessary permissions on the remote repository.<br><br>Check with the administrator of your remote repository if necessary."),
|
Chris@353
|
1991 output);
|
Chris@353
|
1992 }
|
Chris@353
|
1993
|
Chris@238
|
1994 void MainWindow::commandStarting(HgAction action)
|
Chris@238
|
1995 {
|
Chris@540
|
1996 m_commandSequenceInProgress = true;
|
Chris@238
|
1997 }
|
Chris@238
|
1998
|
Chris@546
|
1999 void MainWindow::commandFailed(HgAction action, QString stdErr, QString stdOut)
|
Chris@62
|
2000 {
|
Chris@62
|
2001 DEBUG << "MainWindow::commandFailed" << endl;
|
Chris@540
|
2002
|
Chris@540
|
2003 m_commandSequenceInProgress = false;
|
Chris@74
|
2004
|
Chris@210
|
2005 QString setstr;
|
Chris@210
|
2006 #ifdef Q_OS_MAC
|
Chris@210
|
2007 setstr = tr("Preferences");
|
Chris@210
|
2008 #else
|
Chris@210
|
2009 setstr = tr("Settings");
|
Chris@210
|
2010 #endif
|
Chris@210
|
2011
|
Chris@353
|
2012 // Some commands we just have to ignore bad return values from,
|
Chris@353
|
2013 // and some output gets special treatment.
|
Chris@353
|
2014
|
Chris@353
|
2015 // Note our fallback case should always be to report a
|
Chris@353
|
2016 // non-specific error and show the text -- in case output scraping
|
Chris@353
|
2017 // fails (as it surely will). Note also that we must force the
|
Chris@353
|
2018 // locale in order to ensure the output is scrapable; this happens
|
Chris@353
|
2019 // in HgRunner and may break some system encodings.
|
Chris@113
|
2020
|
Chris@113
|
2021 switch(action.action) {
|
Chris@113
|
2022 case ACT_NONE:
|
Chris@113
|
2023 // uh huh
|
Chris@113
|
2024 return;
|
Chris@175
|
2025 case ACT_TEST_HG:
|
Chris@291
|
2026 MoreInformationDialog::warning
|
Chris@291
|
2027 (this,
|
Chris@291
|
2028 tr("Failed to run Mercurial"),
|
Chris@291
|
2029 tr("Failed to run Mercurial"),
|
Chris@483
|
2030 tr("The Mercurial program either could not be found or failed to run.<br><br>Check that the Mercurial program path is correct in %1.").arg(setstr),
|
Chris@545
|
2031 stdErr);
|
Chris@472
|
2032 settings(SettingsDialog::PathsTab);
|
Chris@200
|
2033 return;
|
Chris@200
|
2034 case ACT_TEST_HG_EXT:
|
Chris@309
|
2035 MoreInformationDialog::warning
|
Chris@291
|
2036 (this,
|
Chris@291
|
2037 tr("Failed to run Mercurial"),
|
Chris@291
|
2038 tr("Failed to run Mercurial with extension enabled"),
|
Chris@310
|
2039 tr("The Mercurial program failed to run with the EasyMercurial interaction extension enabled.<br>This may indicate an installation problem.<br><br>You may be able to continue working if you switch off “Use EasyHg Mercurial Extension” in %1. Note that remote repositories that require authentication might not work if you do this.").arg(setstr),
|
Chris@545
|
2040 stdErr);
|
Chris@472
|
2041 settings(SettingsDialog::PathsTab);
|
Chris@175
|
2042 return;
|
Chris@252
|
2043 case ACT_CLONEFROMREMOTE:
|
Chris@252
|
2044 // if clone fails, we have no repo
|
Chris@284
|
2045 m_workFolderPath = "";
|
Chris@252
|
2046 enableDisableActions();
|
Chris@330
|
2047 break; // go on to default report
|
Chris@113
|
2048 case ACT_INCOMING:
|
Chris@545
|
2049 if (stdErr.contains("authorization failed")) {
|
Chris@545
|
2050 reportAuthFailed(stdErr);
|
Chris@353
|
2051 return;
|
Chris@545
|
2052 } else if (stdErr.contains("entry cancelled")) {
|
Chris@358
|
2053 // ignore this, user cancelled username or password dialog
|
Chris@358
|
2054 return;
|
Chris@353
|
2055 } else {
|
Chris@545
|
2056 // Incoming returns non-zero code and no stdErr if the
|
Chris@353
|
2057 // check was successful but there are no changes
|
Chris@353
|
2058 // pending. This is the only case where we need to remove
|
Chris@353
|
2059 // warning messages, because it's the only case where a
|
Chris@353
|
2060 // non-zero code can be returned even though the command
|
Chris@353
|
2061 // has for our purposes succeeded
|
Chris@545
|
2062 QString replaced = stdErr;
|
Chris@352
|
2063 while (1) {
|
Chris@352
|
2064 QString r1 = replaced;
|
Chris@352
|
2065 r1.replace(QRegExp("warning: [^\\n]*"), "");
|
Chris@352
|
2066 if (r1 == replaced) break;
|
Chris@352
|
2067 replaced = r1.trimmed();
|
Chris@352
|
2068 }
|
Chris@352
|
2069 if (replaced == "") {
|
Chris@352
|
2070 showIncoming("");
|
Chris@352
|
2071 return;
|
Chris@352
|
2072 }
|
Chris@211
|
2073 }
|
Chris@330
|
2074 break; // go on to default report
|
Chris@353
|
2075 case ACT_PULL:
|
Chris@545
|
2076 if (stdErr.contains("authorization failed")) {
|
Chris@545
|
2077 reportAuthFailed(stdErr);
|
Chris@353
|
2078 return;
|
Chris@545
|
2079 } else if (stdErr.contains("entry cancelled")) {
|
Chris@358
|
2080 // ignore this, user cancelled username or password dialog
|
Chris@358
|
2081 return;
|
Chris@546
|
2082 } else if (stdErr.contains("no changes found") || stdOut.contains("no changes found")) {
|
Chris@537
|
2083 // success: hg 2.1 starts returning failure code for empty pull/push
|
Chris@540
|
2084 m_commandSequenceInProgress = true; // there may be further commands
|
Chris@546
|
2085 commandCompleted(action, stdOut);
|
Chris@537
|
2086 return;
|
Chris@353
|
2087 }
|
Chris@353
|
2088 break; // go on to default report
|
Chris@353
|
2089 case ACT_PUSH:
|
Chris@545
|
2090 if (stdErr.contains("creates new remote head")) {
|
Chris@545
|
2091 reportNewRemoteHeads(stdErr);
|
Chris@353
|
2092 return;
|
Chris@545
|
2093 } else if (stdErr.contains("authorization failed")) {
|
Chris@545
|
2094 reportAuthFailed(stdErr);
|
Chris@353
|
2095 return;
|
Chris@545
|
2096 } else if (stdErr.contains("entry cancelled")) {
|
Chris@358
|
2097 // ignore this, user cancelled username or password dialog
|
Chris@358
|
2098 return;
|
Chris@546
|
2099 } else if (stdErr.contains("no changes found") || stdOut.contains("no changes found")) {
|
Chris@537
|
2100 // success: hg 2.1 starts returning failure code for empty pull/push
|
Chris@540
|
2101 m_commandSequenceInProgress = true; // there may be further commands
|
Chris@546
|
2102 commandCompleted(action, stdOut);
|
Chris@537
|
2103 return;
|
Chris@353
|
2104 }
|
Chris@353
|
2105 break; // go on to default report
|
Chris@506
|
2106 case ACT_QUERY_HEADS_ACTIVE:
|
Chris@162
|
2107 case ACT_QUERY_HEADS:
|
Chris@162
|
2108 // fails if repo is empty; we don't care (if there's a genuine
|
Chris@202
|
2109 // problem, something else will fail too). Pretend it
|
Chris@202
|
2110 // succeeded, so that any further actions that are contingent
|
Chris@202
|
2111 // on the success of the heads query get carried out properly.
|
Chris@540
|
2112 m_commandSequenceInProgress = true; // there may be further commands
|
Chris@202
|
2113 commandCompleted(action, "");
|
Chris@162
|
2114 return;
|
Chris@113
|
2115 case ACT_FOLDERDIFF:
|
Chris@113
|
2116 case ACT_CHGSETDIFF:
|
Chris@545
|
2117 // external program, unlikely to be anything useful in stdErr
|
Chris@113
|
2118 // and some return with failure codes when something as basic
|
Chris@113
|
2119 // as the user closing the window via the wm happens
|
Chris@113
|
2120 return;
|
Chris@328
|
2121 case ACT_MERGE:
|
Chris@545
|
2122 if (stdErr.contains("working directory ancestor")) {
|
Chris@530
|
2123 // arguably we should prevent this upfront, but that's
|
Chris@530
|
2124 // trickier!
|
Chris@530
|
2125 MoreInformationDialog::information
|
Chris@530
|
2126 (this, tr("Merge"), tr("Merge has no effect"),
|
Chris@530
|
2127 tr("You asked to merge a revision with one of its ancestors.<p>This has no effect, because the ancestor's changes already exist in both revisions."),
|
Chris@545
|
2128 stdErr);
|
Chris@530
|
2129 return;
|
Chris@530
|
2130 }
|
Chris@530
|
2131 // else fall through
|
Chris@328
|
2132 case ACT_RETRY_MERGE:
|
Chris@328
|
2133 MoreInformationDialog::information
|
Chris@328
|
2134 (this, tr("Merge"), tr("Merge failed"),
|
Chris@328
|
2135 tr("Some files were not merged successfully.<p>You can Merge again to repeat the interactive merge; use Revert to abandon the merge entirely; or edit the files that are in conflict in an editor and, when you are happy with them, choose Mark Resolved in each file's right-button menu."),
|
Chris@545
|
2136 stdErr);
|
Chris@378
|
2137 m_mergeCommitComment = "";
|
Chris@328
|
2138 return;
|
Chris@199
|
2139 case ACT_STAT:
|
Chris@330
|
2140 break; // go on to default report
|
Chris@113
|
2141 default:
|
Chris@114
|
2142 break;
|
Chris@113
|
2143 }
|
Chris@113
|
2144
|
Chris@113
|
2145 QString command = action.executable;
|
Chris@113
|
2146 if (command == "") command = "hg";
|
Chris@113
|
2147 foreach (QString arg, action.params) {
|
Chris@113
|
2148 command += " " + arg;
|
Chris@113
|
2149 }
|
Chris@113
|
2150
|
Chris@309
|
2151 MoreInformationDialog::warning
|
Chris@309
|
2152 (this,
|
Chris@309
|
2153 tr("Command failed"),
|
Chris@309
|
2154 tr("Command failed"),
|
Chris@545
|
2155 (stdErr == "" ?
|
Chris@483
|
2156 tr("A Mercurial command failed to run correctly. This may indicate an installation problem or some other problem with EasyMercurial.") :
|
Chris@483
|
2157 tr("A Mercurial command failed to run correctly. This may indicate an installation problem or some other problem with EasyMercurial.<br><br>See “More Details” for the command output.")),
|
Chris@545
|
2158 stdErr);
|
Chris@62
|
2159 }
|
Chris@62
|
2160
|
Chris@109
|
2161 void MainWindow::commandCompleted(HgAction completedAction, QString output)
|
jtkorhonen@0
|
2162 {
|
Chris@521
|
2163 // std::cerr << "commandCompleted: " << completedAction.action << std::endl;
|
Chris@519
|
2164
|
Chris@109
|
2165 HGACTIONS action = completedAction.action;
|
Chris@109
|
2166
|
Chris@109
|
2167 if (action == ACT_NONE) return;
|
Chris@109
|
2168
|
Chris@519
|
2169 output.replace("\r\n", "\n");
|
Chris@519
|
2170
|
Chris@150
|
2171 bool headsChanged = false;
|
Chris@150
|
2172 QStringList oldHeadIds;
|
Chris@150
|
2173
|
Chris@150
|
2174 switch (action) {
|
Chris@109
|
2175
|
Chris@175
|
2176 case ACT_TEST_HG:
|
Chris@377
|
2177 {
|
Chris@377
|
2178 QRegExp versionRE("^Mercurial.*version ([\\d+])\\.([\\d+])");
|
Chris@377
|
2179 int pos = versionRE.indexIn(output);
|
Chris@377
|
2180 if (pos >= 0) {
|
Chris@377
|
2181 int major = versionRE.cap(1).toInt();
|
Chris@377
|
2182 int minor = versionRE.cap(2).toInt();
|
Chris@377
|
2183 // We need v1.7 or newer
|
Chris@377
|
2184 if (major < 1 || (major == 1 && minor < 7)) {
|
Chris@377
|
2185 MoreInformationDialog::warning
|
Chris@377
|
2186 (this,
|
Chris@377
|
2187 tr("Newer Mercurial version required"),
|
Chris@377
|
2188 tr("Newer Mercurial version required"),
|
Chris@377
|
2189 tr("To use EasyMercurial, you should have at least Mercurial v1.7 installed.<br><br>The version found on this system (v%1.%2) does not support all of the features required by EasyMercurial.").arg(major).arg(minor),
|
Chris@377
|
2190 output);
|
Chris@377
|
2191 }
|
Chris@377
|
2192 }
|
Chris@175
|
2193 break;
|
Chris@377
|
2194 }
|
Chris@175
|
2195
|
Chris@200
|
2196 case ACT_TEST_HG_EXT:
|
Chris@200
|
2197 break;
|
Chris@200
|
2198
|
Chris@109
|
2199 case ACT_QUERY_PATHS:
|
jtkorhonen@0
|
2200 {
|
Chris@109
|
2201 DEBUG << "stdout is " << output << endl;
|
Chris@109
|
2202 LogParser lp(output, "=");
|
Chris@109
|
2203 LogList ll = lp.parse();
|
Chris@109
|
2204 DEBUG << ll.size() << " results" << endl;
|
Chris@109
|
2205 if (!ll.empty()) {
|
Chris@284
|
2206 m_remoteRepoPath = lp.parse()[0]["default"].trimmed();
|
Chris@284
|
2207 DEBUG << "Set remote path to " << m_remoteRepoPath << endl;
|
Chris@210
|
2208 } else {
|
Chris@284
|
2209 m_remoteRepoPath = "";
|
Chris@109
|
2210 }
|
Chris@284
|
2211 MultiChoiceDialog::addRecentArgument("local", m_workFolderPath);
|
Chris@284
|
2212 MultiChoiceDialog::addRecentArgument("remote", m_remoteRepoPath);
|
Chris@287
|
2213 updateWorkFolderAndRepoNames();
|
Chris@109
|
2214 break;
|
Chris@109
|
2215 }
|
jtkorhonen@0
|
2216
|
Chris@109
|
2217 case ACT_QUERY_BRANCH:
|
Chris@284
|
2218 m_currentBranch = output.trimmed();
|
Chris@109
|
2219 break;
|
jtkorhonen@0
|
2220
|
Chris@109
|
2221 case ACT_STAT:
|
Chris@284
|
2222 m_lastStatOutput = output;
|
Chris@109
|
2223 break;
|
Chris@163
|
2224
|
Chris@163
|
2225 case ACT_RESOLVE_LIST:
|
Chris@505
|
2226 // This happens on every update, after the stat (above)
|
Chris@163
|
2227 if (output != "") {
|
Chris@163
|
2228 // Remove lines beginning with R (they are resolved,
|
Chris@163
|
2229 // and the file stat parser treats R as removed)
|
Chris@163
|
2230 QStringList outList = output.split('\n');
|
Chris@163
|
2231 QStringList winnowed;
|
Chris@163
|
2232 foreach (QString line, outList) {
|
Chris@163
|
2233 if (!line.startsWith("R ")) winnowed.push_back(line);
|
Chris@163
|
2234 }
|
Chris@163
|
2235 output = winnowed.join("\n");
|
Chris@163
|
2236 }
|
Chris@284
|
2237 DEBUG << "m_lastStatOutput = " << m_lastStatOutput << endl;
|
Chris@199
|
2238 DEBUG << "resolve output = " << output << endl;
|
Chris@284
|
2239 m_hgTabs->updateWorkFolderFileList(m_lastStatOutput + output);
|
Chris@163
|
2240 break;
|
Chris@163
|
2241
|
Chris@163
|
2242 case ACT_RESOLVE_MARK:
|
Chris@284
|
2243 m_shouldHgStat = true;
|
Chris@163
|
2244 break;
|
Chris@109
|
2245
|
Chris@109
|
2246 case ACT_INCOMING:
|
Chris@120
|
2247 showIncoming(output);
|
Chris@120
|
2248 break;
|
Chris@120
|
2249
|
Chris@109
|
2250 case ACT_ANNOTATE:
|
Chris@331
|
2251 {
|
Chris@331
|
2252 AnnotateDialog dialog(this, output);
|
Chris@331
|
2253 dialog.exec();
|
Chris@284
|
2254 m_shouldHgStat = true;
|
Chris@109
|
2255 break;
|
Chris@331
|
2256 }
|
Chris@109
|
2257
|
Chris@109
|
2258 case ACT_PULL:
|
Chris@120
|
2259 showPullResult(output);
|
Chris@284
|
2260 m_shouldHgStat = true;
|
Chris@109
|
2261 break;
|
Chris@109
|
2262
|
Chris@109
|
2263 case ACT_PUSH:
|
Chris@120
|
2264 showPushResult(output);
|
Chris@109
|
2265 break;
|
Chris@109
|
2266
|
Chris@109
|
2267 case ACT_INIT:
|
Chris@284
|
2268 MultiChoiceDialog::addRecentArgument("init", m_workFolderPath);
|
Chris@284
|
2269 MultiChoiceDialog::addRecentArgument("local", m_workFolderPath);
|
Chris@109
|
2270 enableDisableActions();
|
Chris@284
|
2271 m_shouldHgStat = true;
|
Chris@109
|
2272 break;
|
Chris@109
|
2273
|
Chris@109
|
2274 case ACT_CLONEFROMREMOTE:
|
Chris@284
|
2275 MultiChoiceDialog::addRecentArgument("local", m_workFolderPath);
|
Chris@284
|
2276 MultiChoiceDialog::addRecentArgument("remote", m_remoteRepoPath);
|
Chris@284
|
2277 MultiChoiceDialog::addRecentArgument("remote", m_workFolderPath, true);
|
Chris@291
|
2278 MoreInformationDialog::information
|
Chris@291
|
2279 (this,
|
Chris@291
|
2280 tr("Clone"),
|
Chris@384
|
2281 tr("Open successful"),
|
Chris@295
|
2282 tr("The remote repository was successfully cloned to the local folder <code>%1</code>.").arg(xmlEncode(m_workFolderPath)),
|
Chris@291
|
2283 output);
|
Chris@109
|
2284 enableDisableActions();
|
Chris@284
|
2285 m_shouldHgStat = true;
|
Chris@109
|
2286 break;
|
Chris@109
|
2287
|
Chris@109
|
2288 case ACT_LOG:
|
Chris@284
|
2289 m_hgTabs->setNewLog(output);
|
Chris@284
|
2290 m_needNewLog = false;
|
Chris@120
|
2291 break;
|
Chris@120
|
2292
|
Chris@120
|
2293 case ACT_LOG_INCREMENTAL:
|
Chris@284
|
2294 m_hgTabs->addIncrementalLog(output);
|
Chris@109
|
2295 break;
|
Chris@109
|
2296
|
Chris@109
|
2297 case ACT_QUERY_PARENTS:
|
Chris@152
|
2298 {
|
Chris@284
|
2299 foreach (Changeset *cs, m_currentParents) delete cs;
|
Chris@284
|
2300 m_currentParents = Changeset::parseChangesets(output);
|
Chris@284
|
2301 QStringList parentIds = Changeset::getIds(m_currentParents);
|
Chris@284
|
2302 m_hgTabs->setCurrent(parentIds, m_currentBranch);
|
Chris@152
|
2303 }
|
Chris@109
|
2304 break;
|
Chris@109
|
2305
|
Chris@506
|
2306 case ACT_QUERY_HEADS_ACTIVE:
|
Chris@506
|
2307 foreach (Changeset *cs, m_activeHeads) delete cs;
|
Chris@506
|
2308 m_activeHeads = Changeset::parseChangesets(output);
|
Chris@506
|
2309 break;
|
Chris@506
|
2310
|
Chris@109
|
2311 case ACT_QUERY_HEADS:
|
Chris@150
|
2312 {
|
Chris@284
|
2313 oldHeadIds = Changeset::getIds(m_currentHeads);
|
Chris@150
|
2314 Changesets newHeads = Changeset::parseChangesets(output);
|
Chris@150
|
2315 QStringList newHeadIds = Changeset::getIds(newHeads);
|
Chris@150
|
2316 if (oldHeadIds != newHeadIds) {
|
Chris@150
|
2317 DEBUG << "Heads changed, will prompt an incremental log if appropriate" << endl;
|
Chris@305
|
2318 DEBUG << "Old heads: " << oldHeadIds.join(",") << endl;
|
Chris@305
|
2319 DEBUG << "New heads: " << newHeadIds.join(",") << endl;
|
Chris@150
|
2320 headsChanged = true;
|
Chris@284
|
2321 foreach (Changeset *cs, m_currentHeads) delete cs;
|
Chris@284
|
2322 m_currentHeads = newHeads;
|
Chris@506
|
2323 updateClosedHeads();
|
Chris@150
|
2324 }
|
Chris@150
|
2325 }
|
Chris@109
|
2326 break;
|
Chris@130
|
2327
|
Chris@130
|
2328 case ACT_COMMIT:
|
Chris@347
|
2329 if (m_currentParents.empty()) {
|
Chris@347
|
2330 // first commit to empty repo
|
Chris@347
|
2331 m_needNewLog = true;
|
Chris@347
|
2332 }
|
Chris@284
|
2333 m_hgTabs->clearSelections();
|
Chris@284
|
2334 m_justMerged = false;
|
Chris@284
|
2335 m_shouldHgStat = true;
|
Chris@130
|
2336 break;
|
Chris@163
|
2337
|
Chris@514
|
2338 case ACT_CLOSE_BRANCH:
|
Chris@514
|
2339 m_hgTabs->clearSelections();
|
Chris@514
|
2340 m_justMerged = false;
|
Chris@514
|
2341 m_shouldHgStat = true;
|
Chris@514
|
2342 break;
|
Chris@514
|
2343
|
Chris@163
|
2344 case ACT_REVERT:
|
Chris@326
|
2345 hgMarkFilesResolved(m_lastRevertedFiles);
|
Chris@284
|
2346 m_justMerged = false;
|
Chris@163
|
2347 break;
|
Chris@109
|
2348
|
Chris@109
|
2349 case ACT_REMOVE:
|
Chris@109
|
2350 case ACT_ADD:
|
Chris@284
|
2351 m_hgTabs->clearSelections();
|
Chris@284
|
2352 m_shouldHgStat = true;
|
Chris@116
|
2353 break;
|
Chris@116
|
2354
|
Chris@164
|
2355 case ACT_TAG:
|
Chris@284
|
2356 m_needNewLog = true;
|
Chris@284
|
2357 m_shouldHgStat = true;
|
Chris@164
|
2358 break;
|
Chris@164
|
2359
|
Chris@278
|
2360 case ACT_NEW_BRANCH:
|
Chris@307
|
2361 m_shouldHgStat = true;
|
Chris@278
|
2362 break;
|
Chris@278
|
2363
|
Chris@288
|
2364 case ACT_UNCOMMITTED_SUMMARY:
|
Chris@168
|
2365 QMessageBox::information(this, tr("Change summary"),
|
Chris@168
|
2366 format3(tr("Summary of uncommitted changes"),
|
Chris@168
|
2367 "",
|
Chris@168
|
2368 output));
|
Chris@168
|
2369 break;
|
Chris@168
|
2370
|
Chris@288
|
2371 case ACT_DIFF_SUMMARY:
|
Chris@289
|
2372 {
|
Chris@289
|
2373 // Output has log info first, diff following after a blank line
|
Chris@289
|
2374 QStringList olist = output.split("\n\n", QString::SkipEmptyParts);
|
Chris@289
|
2375 if (olist.size() > 1) output = olist[1];
|
Chris@289
|
2376
|
Chris@289
|
2377 Changeset *cs = (Changeset *)completedAction.extraData;
|
Chris@289
|
2378 if (cs) {
|
Chris@289
|
2379 QMessageBox::information
|
Chris@289
|
2380 (this, tr("Change summary"),
|
Chris@289
|
2381 format3(tr("Summary of changes"),
|
Chris@289
|
2382 cs->formatHtml(),
|
Chris@289
|
2383 output));
|
Chris@289
|
2384 } else if (output == "") {
|
Chris@289
|
2385 // Can happen, for a merge commit (depending on parent)
|
Chris@288
|
2386 QMessageBox::information(this, tr("Change summary"),
|
Chris@288
|
2387 format3(tr("Summary of changes"),
|
Chris@288
|
2388 tr("No changes"),
|
Chris@288
|
2389 output));
|
Chris@288
|
2390 } else {
|
Chris@288
|
2391 QMessageBox::information(this, tr("Change summary"),
|
Chris@288
|
2392 format3(tr("Summary of changes"),
|
Chris@288
|
2393 "",
|
Chris@288
|
2394 output));
|
Chris@288
|
2395 }
|
Chris@288
|
2396 break;
|
Chris@289
|
2397 }
|
Chris@288
|
2398
|
Chris@109
|
2399 case ACT_FOLDERDIFF:
|
Chris@109
|
2400 case ACT_CHGSETDIFF:
|
Chris@109
|
2401 case ACT_SERVE:
|
Chris@109
|
2402 case ACT_HG_IGNORE:
|
Chris@284
|
2403 m_shouldHgStat = true;
|
Chris@109
|
2404 break;
|
Chris@109
|
2405
|
Chris@109
|
2406 case ACT_UPDATE:
|
Chris@162
|
2407 QMessageBox::information(this, tr("Update"), tr("<qt><h3>Update successful</h3><p>%1</p>").arg(xmlEncode(output)));
|
Chris@284
|
2408 m_shouldHgStat = true;
|
Chris@109
|
2409 break;
|
Chris@109
|
2410
|
Chris@109
|
2411 case ACT_MERGE:
|
Chris@294
|
2412 MoreInformationDialog::information
|
Chris@294
|
2413 (this, tr("Merge"), tr("Merge successful"),
|
Chris@302
|
2414 tr("Remember to test and commit the result before making any further changes."),
|
Chris@294
|
2415 output);
|
Chris@284
|
2416 m_shouldHgStat = true;
|
Chris@284
|
2417 m_justMerged = true;
|
Chris@109
|
2418 break;
|
Chris@109
|
2419
|
Chris@109
|
2420 case ACT_RETRY_MERGE:
|
Chris@163
|
2421 QMessageBox::information(this, tr("Resolved"),
|
Chris@302
|
2422 tr("<qt><h3>Merge resolved</h3><p>Merge resolved successfully.<br>Remember to test and commit the result before making any further changes.</p>"));
|
Chris@284
|
2423 m_shouldHgStat = true;
|
Chris@284
|
2424 m_justMerged = true;
|
Chris@109
|
2425 break;
|
Chris@109
|
2426
|
Chris@109
|
2427 default:
|
Chris@109
|
2428 break;
|
Chris@109
|
2429 }
|
Chris@108
|
2430
|
Chris@121
|
2431 // Sequence when no full log required:
|
Chris@520
|
2432 // paths -> branch -> stat -> resolve-list -> heads ->
|
Chris@150
|
2433 // incremental-log (only if heads changed) -> parents
|
Chris@150
|
2434 //
|
Chris@121
|
2435 // Sequence when full log required:
|
Chris@520
|
2436 // paths -> branch -> stat -> resolve-list -> heads ->
|
Chris@519
|
2437 // parents -> log
|
Chris@150
|
2438 //
|
Chris@150
|
2439 // Note we want to call enableDisableActions only once, at the end
|
Chris@150
|
2440 // of whichever sequence is in use.
|
Chris@150
|
2441
|
Chris@156
|
2442 bool noMore = false;
|
Chris@156
|
2443
|
Chris@150
|
2444 switch (action) {
|
Chris@175
|
2445
|
Chris@175
|
2446 case ACT_TEST_HG:
|
Chris@248
|
2447 {
|
Chris@248
|
2448 QSettings settings;
|
Chris@248
|
2449 if (settings.value("useextension", true).toBool()) {
|
Chris@248
|
2450 hgTestExtension();
|
Chris@284
|
2451 } else if (m_workFolderPath == "") {
|
Chris@248
|
2452 open();
|
Chris@248
|
2453 } else {
|
Chris@248
|
2454 hgQueryPaths();
|
Chris@248
|
2455 }
|
Chris@200
|
2456 break;
|
Chris@248
|
2457 }
|
Chris@200
|
2458
|
Chris@200
|
2459 case ACT_TEST_HG_EXT:
|
Chris@284
|
2460 if (m_workFolderPath == "") {
|
Chris@248
|
2461 open();
|
Chris@248
|
2462 } else{
|
Chris@248
|
2463 hgQueryPaths();
|
Chris@248
|
2464 }
|
Chris@175
|
2465 break;
|
Chris@150
|
2466
|
Chris@150
|
2467 case ACT_QUERY_PATHS:
|
Chris@519
|
2468 // NB this call is duplicated in hgQueryPaths
|
Chris@109
|
2469 hgQueryBranch();
|
Chris@150
|
2470 break;
|
Chris@150
|
2471
|
Chris@150
|
2472 case ACT_QUERY_BRANCH:
|
Chris@519
|
2473 // NB this call is duplicated in hgQueryBranch
|
Chris@109
|
2474 hgStat();
|
Chris@150
|
2475 break;
|
Chris@150
|
2476
|
Chris@150
|
2477 case ACT_STAT:
|
Chris@163
|
2478 hgResolveList();
|
Chris@163
|
2479 break;
|
Chris@519
|
2480
|
Chris@163
|
2481 case ACT_RESOLVE_LIST:
|
Chris@506
|
2482 hgQueryHeadsActive();
|
Chris@506
|
2483 break;
|
Chris@506
|
2484
|
Chris@506
|
2485 case ACT_QUERY_HEADS_ACTIVE:
|
Chris@150
|
2486 hgQueryHeads();
|
Chris@150
|
2487 break;
|
Chris@150
|
2488
|
Chris@150
|
2489 case ACT_QUERY_HEADS:
|
Chris@284
|
2490 if (headsChanged && !m_needNewLog) {
|
Chris@150
|
2491 hgLogIncremental(oldHeadIds);
|
Chris@121
|
2492 } else {
|
Chris@150
|
2493 hgQueryParents();
|
Chris@121
|
2494 }
|
Chris@150
|
2495 break;
|
Chris@150
|
2496
|
Chris@150
|
2497 case ACT_LOG_INCREMENTAL:
|
Chris@109
|
2498 hgQueryParents();
|
Chris@150
|
2499 break;
|
Chris@150
|
2500
|
Chris@150
|
2501 case ACT_QUERY_PARENTS:
|
Chris@284
|
2502 if (m_needNewLog) {
|
Chris@120
|
2503 hgLog();
|
Chris@150
|
2504 } else {
|
Chris@150
|
2505 // we're done
|
Chris@156
|
2506 noMore = true;
|
Chris@120
|
2507 }
|
Chris@150
|
2508 break;
|
Chris@150
|
2509
|
Chris@150
|
2510 case ACT_LOG:
|
Chris@150
|
2511 // we're done
|
Chris@156
|
2512 noMore = true;
|
Chris@198
|
2513 break;
|
Chris@150
|
2514
|
Chris@150
|
2515 default:
|
Chris@284
|
2516 if (m_shouldHgStat) {
|
Chris@284
|
2517 m_shouldHgStat = false;
|
Chris@109
|
2518 hgQueryPaths();
|
Chris@150
|
2519 } else {
|
Chris@156
|
2520 noMore = true;
|
jtkorhonen@0
|
2521 }
|
Chris@150
|
2522 break;
|
Chris@150
|
2523 }
|
Chris@156
|
2524
|
Chris@156
|
2525 if (noMore) {
|
Chris@540
|
2526 m_commandSequenceInProgress = false;
|
Chris@284
|
2527 m_stateUnknown = false;
|
Chris@156
|
2528 enableDisableActions();
|
Chris@284
|
2529 m_hgTabs->updateHistory();
|
Chris@359
|
2530 updateRecentMenu();
|
Chris@541
|
2531 checkFilesystem();
|
Chris@156
|
2532 }
|
jtkorhonen@0
|
2533 }
|
jtkorhonen@0
|
2534
|
jtkorhonen@0
|
2535 void MainWindow::connectActions()
|
jtkorhonen@0
|
2536 {
|
Chris@284
|
2537 connect(m_exitAct, SIGNAL(triggered()), this, SLOT(close()));
|
Chris@284
|
2538 connect(m_aboutAct, SIGNAL(triggered()), this, SLOT(about()));
|
Chris@494
|
2539 connect(m_helpAct, SIGNAL(triggered()), this, SLOT(help()));
|
Chris@273
|
2540
|
Chris@284
|
2541 connect(m_hgRefreshAct, SIGNAL(triggered()), this, SLOT(hgRefresh()));
|
Chris@284
|
2542 connect(m_hgRemoveAct, SIGNAL(triggered()), this, SLOT(hgRemove()));
|
Chris@284
|
2543 connect(m_hgAddAct, SIGNAL(triggered()), this, SLOT(hgAdd()));
|
Chris@284
|
2544 connect(m_hgCommitAct, SIGNAL(triggered()), this, SLOT(hgCommit()));
|
Chris@425
|
2545 connect(m_hgIgnoreAct, SIGNAL(triggered()), this, SLOT(hgIgnore()));
|
Chris@425
|
2546 connect(m_hgEditIgnoreAct, SIGNAL(triggered()), this, SLOT(hgEditIgnore()));
|
Chris@284
|
2547 connect(m_hgFolderDiffAct, SIGNAL(triggered()), this, SLOT(hgFolderDiff()));
|
Chris@284
|
2548 connect(m_hgUpdateAct, SIGNAL(triggered()), this, SLOT(hgUpdate()));
|
Chris@284
|
2549 connect(m_hgRevertAct, SIGNAL(triggered()), this, SLOT(hgRevert()));
|
Chris@284
|
2550 connect(m_hgMergeAct, SIGNAL(triggered()), this, SLOT(hgMerge()));
|
Chris@273
|
2551
|
Chris@284
|
2552 connect(m_settingsAct, SIGNAL(triggered()), this, SLOT(settings()));
|
Chris@284
|
2553 connect(m_openAct, SIGNAL(triggered()), this, SLOT(open()));
|
Chris@284
|
2554 connect(m_changeRemoteRepoAct, SIGNAL(triggered()), this, SLOT(changeRemoteRepo()));
|
Chris@273
|
2555
|
Chris@284
|
2556 connect(m_hgIncomingAct, SIGNAL(triggered()), this, SLOT(hgIncoming()));
|
Chris@284
|
2557 connect(m_hgPullAct, SIGNAL(triggered()), this, SLOT(hgPull()));
|
Chris@284
|
2558 connect(m_hgPushAct, SIGNAL(triggered()), this, SLOT(hgPush()));
|
Chris@273
|
2559
|
Chris@284
|
2560 connect(m_hgServeAct, SIGNAL(triggered()), this, SLOT(hgServe()));
|
jtkorhonen@0
|
2561 }
|
Chris@141
|
2562
|
Chris@141
|
2563 void MainWindow::connectTabsSignals()
|
Chris@141
|
2564 {
|
Chris@327
|
2565 connect(m_hgTabs, SIGNAL(currentChanged(int)),
|
Chris@327
|
2566 this, SLOT(enableDisableActions()));
|
Chris@327
|
2567
|
Chris@284
|
2568 connect(m_hgTabs, SIGNAL(commit()),
|
Chris@141
|
2569 this, SLOT(hgCommit()));
|
Chris@141
|
2570
|
Chris@284
|
2571 connect(m_hgTabs, SIGNAL(revert()),
|
Chris@141
|
2572 this, SLOT(hgRevert()));
|
Chris@141
|
2573
|
Chris@284
|
2574 connect(m_hgTabs, SIGNAL(diffWorkingFolder()),
|
Chris@141
|
2575 this, SLOT(hgFolderDiff()));
|
Chris@168
|
2576
|
Chris@284
|
2577 connect(m_hgTabs, SIGNAL(showSummary()),
|
Chris@168
|
2578 this, SLOT(hgShowSummary()));
|
Chris@311
|
2579
|
Chris@311
|
2580 connect(m_hgTabs, SIGNAL(newBranch()),
|
Chris@311
|
2581 this, SLOT(hgNewBranch()));
|
Chris@311
|
2582
|
Chris@311
|
2583 connect(m_hgTabs, SIGNAL(noBranch()),
|
Chris@311
|
2584 this, SLOT(hgNoBranch()));
|
Chris@148
|
2585
|
Chris@284
|
2586 connect(m_hgTabs, SIGNAL(updateTo(QString)),
|
Chris@148
|
2587 this, SLOT(hgUpdateToRev(QString)));
|
Chris@141
|
2588
|
Chris@284
|
2589 connect(m_hgTabs, SIGNAL(diffToCurrent(QString)),
|
Chris@148
|
2590 this, SLOT(hgDiffToCurrent(QString)));
|
Chris@141
|
2591
|
Chris@284
|
2592 connect(m_hgTabs, SIGNAL(diffToParent(QString, QString)),
|
Chris@148
|
2593 this, SLOT(hgDiffToParent(QString, QString)));
|
Chris@141
|
2594
|
Chris@289
|
2595 connect(m_hgTabs, SIGNAL(showSummary(Changeset *)),
|
Chris@289
|
2596 this, SLOT(hgShowSummaryFor(Changeset *)));
|
Chris@288
|
2597
|
Chris@284
|
2598 connect(m_hgTabs, SIGNAL(mergeFrom(QString)),
|
Chris@148
|
2599 this, SLOT(hgMergeFrom(QString)));
|
Chris@164
|
2600
|
Chris@307
|
2601 connect(m_hgTabs, SIGNAL(newBranch(QString)),
|
Chris@311
|
2602 this, SLOT(hgNewBranch()));
|
Chris@278
|
2603
|
Chris@514
|
2604 connect(m_hgTabs, SIGNAL(closeBranch(QString)),
|
Chris@514
|
2605 this, SLOT(hgCloseBranch()));
|
Chris@514
|
2606
|
Chris@284
|
2607 connect(m_hgTabs, SIGNAL(tag(QString)),
|
Chris@148
|
2608 this, SLOT(hgTag(QString)));
|
Chris@326
|
2609
|
Chris@326
|
2610 connect(m_hgTabs, SIGNAL(annotateFiles(QStringList)),
|
Chris@326
|
2611 this, SLOT(hgAnnotateFiles(QStringList)));
|
Chris@326
|
2612
|
Chris@326
|
2613 connect(m_hgTabs, SIGNAL(diffFiles(QStringList)),
|
Chris@326
|
2614 this, SLOT(hgDiffFiles(QStringList)));
|
Chris@326
|
2615
|
Chris@326
|
2616 connect(m_hgTabs, SIGNAL(commitFiles(QStringList)),
|
Chris@326
|
2617 this, SLOT(hgCommitFiles(QStringList)));
|
Chris@326
|
2618
|
Chris@326
|
2619 connect(m_hgTabs, SIGNAL(revertFiles(QStringList)),
|
Chris@326
|
2620 this, SLOT(hgRevertFiles(QStringList)));
|
Chris@326
|
2621
|
Chris@361
|
2622 connect(m_hgTabs, SIGNAL(renameFiles(QStringList)),
|
Chris@361
|
2623 this, SLOT(hgRenameFiles(QStringList)));
|
Chris@361
|
2624
|
Chris@361
|
2625 connect(m_hgTabs, SIGNAL(copyFiles(QStringList)),
|
Chris@361
|
2626 this, SLOT(hgCopyFiles(QStringList)));
|
Chris@361
|
2627
|
Chris@326
|
2628 connect(m_hgTabs, SIGNAL(addFiles(QStringList)),
|
Chris@326
|
2629 this, SLOT(hgAddFiles(QStringList)));
|
Chris@326
|
2630
|
Chris@326
|
2631 connect(m_hgTabs, SIGNAL(removeFiles(QStringList)),
|
Chris@326
|
2632 this, SLOT(hgRemoveFiles(QStringList)));
|
Chris@326
|
2633
|
Chris@326
|
2634 connect(m_hgTabs, SIGNAL(redoFileMerges(QStringList)),
|
Chris@326
|
2635 this, SLOT(hgRedoFileMerges(QStringList)));
|
Chris@326
|
2636
|
Chris@326
|
2637 connect(m_hgTabs, SIGNAL(markFilesResolved(QStringList)),
|
Chris@326
|
2638 this, SLOT(hgMarkFilesResolved(QStringList)));
|
Chris@326
|
2639
|
Chris@326
|
2640 connect(m_hgTabs, SIGNAL(ignoreFiles(QStringList)),
|
Chris@326
|
2641 this, SLOT(hgIgnoreFiles(QStringList)));
|
Chris@326
|
2642
|
Chris@326
|
2643 connect(m_hgTabs, SIGNAL(unIgnoreFiles(QStringList)),
|
Chris@326
|
2644 this, SLOT(hgUnIgnoreFiles(QStringList)));
|
Chris@141
|
2645 }
|
Chris@141
|
2646
|
jtkorhonen@0
|
2647 void MainWindow::enableDisableActions()
|
jtkorhonen@0
|
2648 {
|
Chris@90
|
2649 DEBUG << "MainWindow::enableDisableActions" << endl;
|
Chris@90
|
2650
|
Chris@284
|
2651 QString dirname = QDir(m_workFolderPath).dirName();
|
Chris@340
|
2652
|
Chris@340
|
2653 if (m_workFolderPath != "") { // dirname of "" is ".", so test path instead
|
Chris@202
|
2654 setWindowTitle(tr("EasyMercurial: %1").arg(dirname));
|
Chris@202
|
2655 } else {
|
Chris@202
|
2656 setWindowTitle(tr("EasyMercurial"));
|
Chris@202
|
2657 }
|
Chris@202
|
2658
|
Chris@115
|
2659 //!!! should also do things like set the status texts for the
|
Chris@115
|
2660 //!!! actions appropriately by context
|
Chris@115
|
2661
|
jtkorhonen@0
|
2662 QDir localRepoDir;
|
jtkorhonen@0
|
2663 QDir workFolderDir;
|
jtkorhonen@0
|
2664
|
Chris@284
|
2665 m_remoteRepoActionsEnabled = true;
|
Chris@284
|
2666 if (m_remoteRepoPath.isEmpty()) {
|
Chris@284
|
2667 m_remoteRepoActionsEnabled = false;
|
jtkorhonen@0
|
2668 }
|
jtkorhonen@0
|
2669
|
Chris@284
|
2670 m_localRepoActionsEnabled = true;
|
Chris@284
|
2671 if (m_workFolderPath.isEmpty()) {
|
Chris@284
|
2672 m_localRepoActionsEnabled = false;
|
jtkorhonen@0
|
2673 }
|
jtkorhonen@0
|
2674
|
Chris@284
|
2675 if (m_workFolderPath == "" || !workFolderDir.exists(m_workFolderPath)) {
|
Chris@284
|
2676 m_localRepoActionsEnabled = false;
|
jtkorhonen@0
|
2677 }
|
jtkorhonen@0
|
2678
|
Chris@284
|
2679 if (!localRepoDir.exists(m_workFolderPath + "/.hg")) {
|
Chris@284
|
2680 m_localRepoActionsEnabled = false;
|
jtkorhonen@0
|
2681 }
|
jtkorhonen@0
|
2682
|
Chris@179
|
2683 bool haveDiff = false;
|
Chris@179
|
2684 QSettings settings;
|
Chris@179
|
2685 settings.beginGroup("Locations");
|
Chris@179
|
2686 if (settings.value("extdiffbinary", "").toString() != "") {
|
Chris@179
|
2687 haveDiff = true;
|
Chris@179
|
2688 }
|
Chris@179
|
2689 settings.endGroup();
|
Chris@112
|
2690
|
Chris@505
|
2691 m_hgTabs->setHaveMerge(m_currentParents.size() == 2);
|
Chris@505
|
2692
|
Chris@365
|
2693 m_hgRefreshAct->setEnabled(m_localRepoActionsEnabled);
|
Chris@365
|
2694 m_hgFolderDiffAct->setEnabled(m_localRepoActionsEnabled && haveDiff);
|
Chris@365
|
2695 m_hgRevertAct->setEnabled(m_localRepoActionsEnabled);
|
Chris@365
|
2696 m_hgAddAct->setEnabled(m_localRepoActionsEnabled);
|
Chris@365
|
2697 m_hgRemoveAct->setEnabled(m_localRepoActionsEnabled);
|
Chris@425
|
2698 m_hgIgnoreAct->setEnabled(m_localRepoActionsEnabled);
|
Chris@365
|
2699 m_hgUpdateAct->setEnabled(m_localRepoActionsEnabled);
|
Chris@365
|
2700 m_hgCommitAct->setEnabled(m_localRepoActionsEnabled);
|
Chris@365
|
2701 m_hgMergeAct->setEnabled(m_localRepoActionsEnabled);
|
Chris@365
|
2702 m_hgServeAct->setEnabled(m_localRepoActionsEnabled);
|
Chris@413
|
2703 m_hgEditIgnoreAct->setEnabled(m_localRepoActionsEnabled);
|
Chris@273
|
2704
|
Chris@284
|
2705 DEBUG << "m_localRepoActionsEnabled = " << m_localRepoActionsEnabled << endl;
|
Chris@284
|
2706 DEBUG << "canCommit = " << m_hgTabs->canCommit() << endl;
|
Chris@273
|
2707
|
Chris@284
|
2708 m_hgAddAct->setEnabled(m_localRepoActionsEnabled && m_hgTabs->canAdd());
|
Chris@284
|
2709 m_hgRemoveAct->setEnabled(m_localRepoActionsEnabled && m_hgTabs->canRemove());
|
Chris@284
|
2710 m_hgCommitAct->setEnabled(m_localRepoActionsEnabled && m_hgTabs->canCommit());
|
Chris@284
|
2711 m_hgRevertAct->setEnabled(m_localRepoActionsEnabled && m_hgTabs->canRevert());
|
Chris@284
|
2712 m_hgFolderDiffAct->setEnabled(m_localRepoActionsEnabled && m_hgTabs->canDiff());
|
Chris@425
|
2713 m_hgIgnoreAct->setEnabled(m_localRepoActionsEnabled && m_hgTabs->canIgnore());
|
Chris@90
|
2714
|
Chris@108
|
2715 // A default merge makes sense if:
|
Chris@108
|
2716 // * there is only one parent (if there are two, we have an uncommitted merge) and
|
Chris@108
|
2717 // * there are exactly two heads that have the same branch as the current branch and
|
Chris@108
|
2718 // * our parent is one of those heads
|
Chris@108
|
2719 //
|
Chris@108
|
2720 // A default update makes sense if:
|
Chris@108
|
2721 // * there is only one parent and
|
Chris@108
|
2722 // * the parent is not one of the current heads
|
Chris@156
|
2723
|
Chris@108
|
2724 bool canMerge = false;
|
Chris@108
|
2725 bool canUpdate = false;
|
Chris@156
|
2726 bool haveMerge = false;
|
Chris@162
|
2727 bool emptyRepo = false;
|
Chris@225
|
2728 bool noWorkingCopy = false;
|
Chris@235
|
2729 bool newBranch = false;
|
Chris@506
|
2730 bool closedBranch = false;
|
Chris@506
|
2731 int currentBranchActiveHeads = 0;
|
Chris@273
|
2732
|
Chris@284
|
2733 if (m_currentParents.size() == 1) {
|
Chris@156
|
2734 bool parentIsHead = false;
|
Chris@506
|
2735 bool parentIsActiveHead = false;
|
Chris@284
|
2736 Changeset *parent = m_currentParents[0];
|
Chris@506
|
2737 foreach (Changeset *head, m_activeHeads) {
|
Chris@284
|
2738 if (head->isOnBranch(m_currentBranch)) {
|
Chris@506
|
2739 ++currentBranchActiveHeads;
|
Chris@235
|
2740 }
|
Chris@235
|
2741 if (parent->id() == head->id()) {
|
Chris@506
|
2742 parentIsActiveHead = parentIsHead = true;
|
Chris@108
|
2743 }
|
Chris@108
|
2744 }
|
Chris@506
|
2745 if (!parentIsActiveHead) {
|
Chris@506
|
2746 foreach (Changeset *head, m_currentHeads) {
|
Chris@506
|
2747 if (parent->id() == head->id()) {
|
Chris@506
|
2748 parentIsHead = true;
|
Chris@506
|
2749 }
|
Chris@506
|
2750 }
|
Chris@506
|
2751 }
|
Chris@506
|
2752 if (currentBranchActiveHeads == 2 && parentIsActiveHead) {
|
Chris@108
|
2753 canMerge = true;
|
Chris@108
|
2754 }
|
Chris@506
|
2755 if (currentBranchActiveHeads == 0 && parentIsActiveHead) {
|
Chris@235
|
2756 // Just created a new branch
|
Chris@235
|
2757 newBranch = true;
|
Chris@235
|
2758 }
|
Chris@108
|
2759 if (!parentIsHead) {
|
Chris@108
|
2760 canUpdate = true;
|
Chris@108
|
2761 DEBUG << "parent id = " << parent->id() << endl;
|
Chris@108
|
2762 DEBUG << " head ids "<<endl;
|
Chris@284
|
2763 foreach (Changeset *h, m_currentHeads) {
|
Chris@108
|
2764 DEBUG << "head id = " << h->id() << endl;
|
Chris@108
|
2765 }
|
Chris@506
|
2766 } else if (!parentIsActiveHead) {
|
Chris@506
|
2767 closedBranch = true;
|
Chris@108
|
2768 }
|
Chris@284
|
2769 m_justMerged = false;
|
Chris@284
|
2770 } else if (m_currentParents.size() == 0) {
|
Chris@284
|
2771 if (m_currentHeads.size() == 0) {
|
Chris@225
|
2772 // No heads -> empty repo
|
Chris@225
|
2773 emptyRepo = true;
|
Chris@225
|
2774 } else {
|
Chris@225
|
2775 // Heads, but no parents -> no working copy, e.g. we have
|
Chris@225
|
2776 // just converted this repo but haven't updated in it yet.
|
Chris@225
|
2777 // Uncommon but confusing; probably merits a special case
|
Chris@225
|
2778 noWorkingCopy = true;
|
Chris@225
|
2779 canUpdate = true;
|
Chris@225
|
2780 }
|
Chris@284
|
2781 m_justMerged = false;
|
Chris@156
|
2782 } else {
|
Chris@156
|
2783 haveMerge = true;
|
Chris@284
|
2784 m_justMerged = true;
|
Chris@108
|
2785 }
|
Chris@505
|
2786
|
Chris@363
|
2787 m_hgIncomingAct->setEnabled(m_remoteRepoActionsEnabled);
|
Chris@363
|
2788 m_hgPullAct->setEnabled(m_remoteRepoActionsEnabled);
|
Chris@363
|
2789 // permit push even if no remote yet; we'll ask for one
|
Chris@363
|
2790 m_hgPushAct->setEnabled(m_localRepoActionsEnabled && !emptyRepo);
|
Chris@363
|
2791
|
Chris@284
|
2792 m_hgMergeAct->setEnabled(m_localRepoActionsEnabled &&
|
Chris@506
|
2793 (canMerge || m_hgTabs->canResolve()));
|
Chris@284
|
2794 m_hgUpdateAct->setEnabled(m_localRepoActionsEnabled &&
|
Chris@506
|
2795 (canUpdate && !m_hgTabs->haveChangesToCommit()));
|
Chris@115
|
2796
|
Chris@115
|
2797 // Set the state field on the file status widget
|
Chris@115
|
2798
|
Chris@115
|
2799 QString branchText;
|
Chris@284
|
2800 if (m_currentBranch == "" || m_currentBranch == "default") {
|
Chris@115
|
2801 branchText = tr("the default branch");
|
Chris@115
|
2802 } else {
|
Chris@284
|
2803 branchText = tr("branch \"%1\"").arg(m_currentBranch);
|
Chris@115
|
2804 }
|
Chris@156
|
2805
|
Chris@284
|
2806 if (m_stateUnknown) {
|
Chris@284
|
2807 if (m_workFolderPath == "") {
|
Chris@287
|
2808 m_workStatus->setState(tr("No repository open"));
|
Chris@248
|
2809 } else {
|
Chris@287
|
2810 m_workStatus->setState(tr("(Examining repository)"));
|
Chris@248
|
2811 }
|
Chris@173
|
2812 } else if (emptyRepo) {
|
Chris@287
|
2813 m_workStatus->setState(tr("Nothing committed to this repository yet"));
|
Chris@225
|
2814 } else if (noWorkingCopy) {
|
Chris@287
|
2815 m_workStatus->setState(tr("No working copy yet: consider updating"));
|
Chris@162
|
2816 } else if (canMerge) {
|
Chris@287
|
2817 m_workStatus->setState(tr("<b>Awaiting merge</b> on %1").arg(branchText));
|
Chris@284
|
2818 } else if (!m_hgTabs->getAllUnresolvedFiles().empty()) {
|
Chris@287
|
2819 m_workStatus->setState(tr("Have unresolved files following merge on %1").arg(branchText));
|
Chris@156
|
2820 } else if (haveMerge) {
|
Chris@287
|
2821 m_workStatus->setState(tr("Have merged but not yet committed on %1").arg(branchText));
|
Chris@235
|
2822 } else if (newBranch) {
|
Chris@287
|
2823 m_workStatus->setState(tr("On %1. New branch: has not yet been committed").arg(branchText));
|
Chris@506
|
2824 } else if (closedBranch) {
|
Chris@506
|
2825 if (canUpdate) {
|
Chris@506
|
2826 m_workStatus->setState(tr("On a closed branch. Not at the head of the branch"));
|
Chris@506
|
2827 } else {
|
Chris@506
|
2828 m_workStatus->setState(tr("At the head of a closed branch"));
|
Chris@506
|
2829 }
|
Chris@156
|
2830 } else if (canUpdate) {
|
Chris@284
|
2831 if (m_hgTabs->haveChangesToCommit()) {
|
Chris@163
|
2832 // have uncommitted changes
|
Chris@287
|
2833 m_workStatus->setState(tr("On %1. Not at the head of the branch").arg(branchText));
|
Chris@163
|
2834 } else {
|
Chris@163
|
2835 // no uncommitted changes
|
Chris@287
|
2836 m_workStatus->setState(tr("On %1. Not at the head of the branch: consider updating").arg(branchText));
|
Chris@163
|
2837 }
|
Chris@506
|
2838 } else if (currentBranchActiveHeads > 1) {
|
Chris@506
|
2839 m_workStatus->setState(tr("At one of %n heads of %1", "", currentBranchActiveHeads).arg(branchText));
|
Chris@115
|
2840 } else {
|
Chris@287
|
2841 m_workStatus->setState(tr("At the head of %1").arg(branchText));
|
Chris@115
|
2842 }
|
jtkorhonen@0
|
2843 }
|
jtkorhonen@0
|
2844
|
Chris@359
|
2845
|
Chris@506
|
2846 void MainWindow::updateClosedHeads()
|
Chris@506
|
2847 {
|
Chris@506
|
2848 m_closedHeadIds.clear();
|
Chris@506
|
2849 QSet<QString> activeIds;
|
Chris@506
|
2850 foreach (Changeset *cs, m_activeHeads) {
|
Chris@506
|
2851 activeIds.insert(cs->id());
|
Chris@506
|
2852 }
|
Chris@506
|
2853 foreach (Changeset *cs, m_currentHeads) {
|
Chris@506
|
2854 if (!activeIds.contains(cs->id())) {
|
Chris@506
|
2855 m_closedHeadIds.insert(cs->id());
|
Chris@506
|
2856 }
|
Chris@506
|
2857 }
|
Chris@506
|
2858 m_hgTabs->setClosedHeadIds(m_closedHeadIds);
|
Chris@506
|
2859 }
|
Chris@506
|
2860
|
Chris@359
|
2861 void MainWindow::updateRecentMenu()
|
Chris@359
|
2862 {
|
Chris@359
|
2863 m_recentMenu->clear();
|
Chris@359
|
2864 RecentFiles rf("Recent-local");
|
Chris@359
|
2865 QStringList recent = rf.getRecent();
|
Chris@359
|
2866 if (recent.empty()) {
|
Chris@359
|
2867 QLabel *label = new QLabel(tr("No recent local repositories"));
|
Chris@359
|
2868 QWidgetAction *wa = new QWidgetAction(m_recentMenu);
|
Chris@359
|
2869 wa->setDefaultWidget(label);
|
Chris@359
|
2870 return;
|
Chris@359
|
2871 }
|
Chris@359
|
2872 foreach (QString r, recent) {
|
Chris@359
|
2873 QAction *a = m_recentMenu->addAction(r);
|
Chris@359
|
2874 connect(a, SIGNAL(activated()), this, SLOT(recentMenuActivated()));
|
Chris@359
|
2875 }
|
Chris@359
|
2876 }
|
Chris@359
|
2877
|
jtkorhonen@0
|
2878 void MainWindow::createActions()
|
jtkorhonen@0
|
2879 {
|
jtkorhonen@0
|
2880 //File actions
|
Chris@365
|
2881 m_openAct = new QAction(QIcon(":/images/fileopen.png"), tr("&Open..."), this);
|
Chris@365
|
2882 m_openAct->setStatusTip(tr("Open an existing repository or working folder"));
|
Chris@365
|
2883 m_openAct->setShortcut(tr("Ctrl+O"));
|
Chris@365
|
2884
|
Chris@365
|
2885 m_changeRemoteRepoAct = new QAction(tr("Set Remote &Location..."), this);
|
Chris@363
|
2886 m_changeRemoteRepoAct->setStatusTip(tr("Set or change the default remote repository for pull and push actions"));
|
Chris@273
|
2887
|
Chris@365
|
2888 m_settingsAct = new QAction(QIcon(":/images/settings.png"), tr("&Settings..."), this);
|
Chris@365
|
2889 m_settingsAct->setStatusTip(tr("View and change application settings"));
|
Chris@273
|
2890
|
Chris@343
|
2891 #ifdef Q_OS_WIN32
|
Chris@365
|
2892 m_exitAct = new QAction(QIcon(":/images/exit.png"), tr("E&xit"), this);
|
Chris@343
|
2893 #else
|
Chris@365
|
2894 m_exitAct = new QAction(QIcon(":/images/exit.png"), tr("&Quit"), this);
|
Chris@343
|
2895 #endif
|
Chris@284
|
2896 m_exitAct->setShortcuts(QKeySequence::Quit);
|
Chris@365
|
2897 m_exitAct->setStatusTip(tr("Exit EasyMercurial"));
|
jtkorhonen@0
|
2898
|
jtkorhonen@0
|
2899 //Repository actions
|
Chris@544
|
2900 m_hgRefreshAct = new QAction(QIcon(":/images/status.png"), tr("&Re-Read Working Folder"), this);
|
Chris@365
|
2901 m_hgRefreshAct->setShortcut(tr("Ctrl+R"));
|
Chris@284
|
2902 m_hgRefreshAct->setStatusTip(tr("Refresh the window to show the current state of the working folder"));
|
Chris@273
|
2903
|
Chris@365
|
2904 m_hgIncomingAct = new QAction(QIcon(":/images/incoming.png"), tr("Pre&view Incoming Changes"), this);
|
Chris@365
|
2905 m_hgIncomingAct->setIconText(tr("Preview"));
|
Chris@365
|
2906 m_hgIncomingAct->setStatusTip(tr("See what changes are available in the remote repository waiting to be pulled"));
|
Chris@365
|
2907
|
Chris@365
|
2908 m_hgPullAct = new QAction(QIcon(":/images/pull.png"), tr("Pu&ll from Remote Repository"), this);
|
Chris@365
|
2909 m_hgPullAct->setIconText(tr("Pull"));
|
Chris@365
|
2910 m_hgPullAct->setShortcut(tr("Ctrl+L"));
|
Chris@365
|
2911 m_hgPullAct->setStatusTip(tr("Pull changes from the remote repository to the local repository"));
|
Chris@365
|
2912
|
Chris@365
|
2913 m_hgPushAct = new QAction(QIcon(":/images/push.png"), tr("Pus&h to Remote Repository"), this);
|
Chris@365
|
2914 m_hgPushAct->setIconText(tr("Push"));
|
Chris@365
|
2915 m_hgPushAct->setShortcut(tr("Ctrl+H"));
|
Chris@284
|
2916 m_hgPushAct->setStatusTip(tr("Push changes from the local repository to the remote repository"));
|
jtkorhonen@0
|
2917
|
jtkorhonen@0
|
2918 //Workfolder actions
|
Chris@365
|
2919 m_hgFolderDiffAct = new QAction(QIcon(":/images/folderdiff.png"), tr("&Diff"), this);
|
Chris@365
|
2920 m_hgFolderDiffAct->setIconText(tr("Diff"));
|
Chris@365
|
2921 m_hgFolderDiffAct->setShortcut(tr("Ctrl+D"));
|
Chris@284
|
2922 m_hgFolderDiffAct->setStatusTip(tr("See what has changed in the working folder compared with the last committed state"));
|
Chris@273
|
2923
|
Chris@365
|
2924 m_hgRevertAct = new QAction(QIcon(":/images/undo.png"), tr("Re&vert"), this);
|
Chris@284
|
2925 m_hgRevertAct->setStatusTip(tr("Throw away your changes and return to the last committed state"));
|
Chris@273
|
2926
|
Chris@365
|
2927 m_hgAddAct = new QAction(QIcon(":/images/add.png"), tr("&Add Files"), this);
|
Chris@365
|
2928 m_hgAddAct->setIconText(tr("Add"));
|
Chris@365
|
2929 m_hgAddAct->setShortcut(tr("+"));
|
Chris@365
|
2930 m_hgAddAct->setStatusTip(tr("Mark the selected files to be added on the next commit"));
|
Chris@365
|
2931
|
Chris@365
|
2932 m_hgRemoveAct = new QAction(QIcon(":/images/remove.png"), tr("&Remove Files"), this);
|
Chris@365
|
2933 m_hgRemoveAct->setIconText(tr("Remove"));
|
Chris@365
|
2934 m_hgRemoveAct->setShortcut(tr("Del"));
|
Chris@365
|
2935 m_hgRemoveAct->setStatusTip(tr("Mark the selected files to be removed from version control on the next commit"));
|
Chris@365
|
2936
|
Chris@425
|
2937 m_hgIgnoreAct = new QAction(tr("&Ignore Files..."), this);
|
Chris@425
|
2938 m_hgIgnoreAct->setStatusTip(tr("Add the selected filenames to the ignored list, of files that should never be tracked in this repository"));
|
Chris@425
|
2939
|
Chris@425
|
2940 m_hgEditIgnoreAct = new QAction(tr("Edit Ignored List"), this);
|
Chris@425
|
2941 m_hgEditIgnoreAct->setStatusTip(tr("Edit the .hgignore file, containing the names of files that should be ignored by Mercurial"));
|
Chris@425
|
2942
|
Chris@365
|
2943 m_hgUpdateAct = new QAction(QIcon(":/images/update.png"), tr("&Update to Branch Head"), this);
|
Chris@365
|
2944 m_hgUpdateAct->setIconText(tr("Update"));
|
Chris@365
|
2945 m_hgUpdateAct->setShortcut(tr("Ctrl+U"));
|
Chris@284
|
2946 m_hgUpdateAct->setStatusTip(tr("Update the working folder to the head of the current repository branch"));
|
jtkorhonen@0
|
2947
|
Chris@365
|
2948 m_hgCommitAct = new QAction(QIcon(":/images/commit.png"), tr("&Commit..."), this);
|
Chris@365
|
2949 m_hgCommitAct->setShortcut(tr("Ctrl+Return"));
|
Chris@284
|
2950 m_hgCommitAct->setStatusTip(tr("Commit your changes to the local repository"));
|
Chris@273
|
2951
|
Chris@365
|
2952 m_hgMergeAct = new QAction(QIcon(":/images/merge.png"), tr("&Merge"), this);
|
Chris@365
|
2953 m_hgMergeAct->setShortcut(tr("Ctrl+M"));
|
Chris@284
|
2954 m_hgMergeAct->setStatusTip(tr("Merge the two independent sets of changes in the local repository into the working folder"));
|
jtkorhonen@0
|
2955
|
Chris@425
|
2956 m_hgServeAct = new QAction(tr("Share Repository"), this);
|
Chris@425
|
2957 m_hgServeAct->setStatusTip(tr("Serve local repository temporarily via HTTP for workgroup access"));
|
jtkorhonen@11
|
2958
|
jtkorhonen@0
|
2959 //Help actions
|
Chris@494
|
2960 #ifdef Q_OS_MAC
|
Chris@494
|
2961 m_helpAct = new QAction(tr("EasyMercurial Help"), this);
|
Chris@494
|
2962 #else
|
Chris@494
|
2963 m_helpAct = new QAction(tr("Help Topics"), this);
|
Chris@494
|
2964 #endif
|
Chris@494
|
2965 m_helpAct->setShortcuts(QKeySequence::HelpContents);
|
Chris@284
|
2966 m_aboutAct = new QAction(tr("About EasyMercurial"), this);
|
Chris@94
|
2967
|
Chris@94
|
2968 // Miscellaneous
|
Chris@199
|
2969 QShortcut *clearSelectionsShortcut = new QShortcut(Qt::Key_Escape, this);
|
Chris@199
|
2970 connect(clearSelectionsShortcut, SIGNAL(activated()),
|
Chris@199
|
2971 this, SLOT(clearSelections()));
|
jtkorhonen@0
|
2972 }
|
jtkorhonen@0
|
2973
|
jtkorhonen@0
|
2974 void MainWindow::createMenus()
|
jtkorhonen@0
|
2975 {
|
Chris@365
|
2976 m_fileMenu = menuBar()->addMenu(tr("&File"));
|
Chris@365
|
2977
|
Chris@365
|
2978 m_fileMenu->addAction(m_openAct);
|
Chris@365
|
2979 m_recentMenu = m_fileMenu->addMenu(tr("Open Re¢"));
|
Chris@365
|
2980 m_fileMenu->addAction(m_hgRefreshAct);
|
Chris@365
|
2981 m_fileMenu->addSeparator();
|
Chris@425
|
2982 m_fileMenu->addAction(m_hgServeAct);
|
Chris@425
|
2983 m_fileMenu->addSeparator();
|
Chris@365
|
2984 m_fileMenu->addAction(m_settingsAct);
|
Chris@365
|
2985 m_fileMenu->addSeparator();
|
Chris@365
|
2986 m_fileMenu->addAction(m_exitAct);
|
Chris@365
|
2987
|
Chris@365
|
2988 QMenu *workMenu;
|
Chris@365
|
2989 workMenu = menuBar()->addMenu(tr("&Work"));
|
Chris@365
|
2990 workMenu->addAction(m_hgFolderDiffAct);
|
Chris@365
|
2991 workMenu->addSeparator();
|
Chris@365
|
2992 workMenu->addAction(m_hgUpdateAct);
|
Chris@365
|
2993 workMenu->addAction(m_hgCommitAct);
|
Chris@365
|
2994 workMenu->addAction(m_hgMergeAct);
|
Chris@365
|
2995 workMenu->addSeparator();
|
Chris@365
|
2996 workMenu->addAction(m_hgAddAct);
|
Chris@365
|
2997 workMenu->addAction(m_hgRemoveAct);
|
Chris@365
|
2998 workMenu->addSeparator();
|
Chris@425
|
2999 workMenu->addAction(m_hgIgnoreAct);
|
Chris@425
|
3000 workMenu->addAction(m_hgEditIgnoreAct);
|
Chris@425
|
3001 workMenu->addSeparator();
|
Chris@365
|
3002 workMenu->addAction(m_hgRevertAct);
|
Chris@365
|
3003
|
Chris@365
|
3004 QMenu *remoteMenu;
|
Chris@365
|
3005 remoteMenu = menuBar()->addMenu(tr("&Remote"));
|
Chris@425
|
3006 remoteMenu->addAction(m_changeRemoteRepoAct);
|
Chris@425
|
3007 remoteMenu->addSeparator();
|
Chris@365
|
3008 remoteMenu->addAction(m_hgIncomingAct);
|
Chris@365
|
3009 remoteMenu->addSeparator();
|
Chris@365
|
3010 remoteMenu->addAction(m_hgPullAct);
|
Chris@365
|
3011 remoteMenu->addAction(m_hgPushAct);
|
Chris@273
|
3012
|
Chris@378
|
3013 m_helpMenu = menuBar()->addMenu(tr("&Help"));
|
Chris@494
|
3014 m_helpMenu->addAction(m_helpAct);
|
Chris@284
|
3015 m_helpMenu->addAction(m_aboutAct);
|
jtkorhonen@0
|
3016 }
|
jtkorhonen@0
|
3017
|
jtkorhonen@0
|
3018 void MainWindow::createToolBars()
|
jtkorhonen@0
|
3019 {
|
Chris@442
|
3020 int sz = 32;
|
Chris@442
|
3021
|
Chris@543
|
3022 bool spacingReqd = false;
|
chris@550
|
3023 QString spacer = "";
|
Chris@543
|
3024 #ifndef Q_OS_MAC
|
Chris@543
|
3025 spacingReqd = true;
|
chris@550
|
3026 spacer = " ";
|
chris@550
|
3027 #ifdef Q_OS_WIN32
|
chris@550
|
3028 spacer = " ";
|
chris@550
|
3029 #endif
|
Chris@543
|
3030 #endif
|
Chris@273
|
3031
|
Chris@442
|
3032 m_workFolderToolBar = addToolBar(tr("Work"));
|
Chris@284
|
3033 addToolBar(Qt::LeftToolBarArea, m_workFolderToolBar);
|
Chris@442
|
3034 m_workFolderToolBar->setIconSize(QSize(sz, sz));
|
Chris@543
|
3035 if (spacingReqd) {
|
Chris@543
|
3036 QWidget *w = new QWidget;
|
Chris@543
|
3037 w->setFixedHeight(6);
|
Chris@543
|
3038 m_workFolderToolBar->addWidget(w);
|
Chris@543
|
3039 }
|
Chris@284
|
3040 m_workFolderToolBar->addAction(m_hgFolderDiffAct);
|
Chris@284
|
3041 m_workFolderToolBar->addSeparator();
|
Chris@284
|
3042 m_workFolderToolBar->addAction(m_hgRevertAct);
|
Chris@284
|
3043 m_workFolderToolBar->addAction(m_hgUpdateAct);
|
Chris@284
|
3044 m_workFolderToolBar->addAction(m_hgCommitAct);
|
Chris@284
|
3045 m_workFolderToolBar->addAction(m_hgMergeAct);
|
Chris@284
|
3046 m_workFolderToolBar->addSeparator();
|
Chris@284
|
3047 m_workFolderToolBar->addAction(m_hgAddAct);
|
Chris@284
|
3048 m_workFolderToolBar->addAction(m_hgRemoveAct);
|
Chris@365
|
3049 m_workFolderToolBar->setMovable(false);
|
Chris@61
|
3050
|
Chris@543
|
3051 m_repoToolBar = addToolBar(tr("Remote"));
|
Chris@543
|
3052 m_repoToolBar->setIconSize(QSize(sz, sz));
|
chris@550
|
3053 m_repoToolBar->addWidget(new QLabel(spacer));
|
Chris@543
|
3054 m_repoToolBar->addAction(m_openAct);
|
chris@550
|
3055 m_repoToolBar->addWidget(new QLabel(spacer));
|
Chris@543
|
3056 m_repoToolBar->addSeparator();
|
Chris@543
|
3057 m_repoToolBar->addAction(m_hgIncomingAct);
|
Chris@543
|
3058 m_repoToolBar->addAction(m_hgPullAct);
|
Chris@543
|
3059 m_repoToolBar->addAction(m_hgPushAct);
|
Chris@543
|
3060 m_repoToolBar->setMovable(false);
|
Chris@543
|
3061
|
Chris@230
|
3062 updateToolBarStyle();
|
jtkorhonen@0
|
3063 }
|
jtkorhonen@0
|
3064
|
Chris@230
|
3065 void MainWindow::updateToolBarStyle()
|
Chris@230
|
3066 {
|
Chris@230
|
3067 QSettings settings;
|
Chris@230
|
3068 settings.beginGroup("Presentation");
|
Chris@230
|
3069 bool showText = settings.value("showiconlabels", true).toBool();
|
Chris@230
|
3070 settings.endGroup();
|
Chris@230
|
3071
|
Chris@230
|
3072 foreach (QToolButton *tb, findChildren<QToolButton *>()) {
|
Chris@230
|
3073 tb->setToolButtonStyle(showText ?
|
Chris@230
|
3074 Qt::ToolButtonTextUnderIcon :
|
Chris@230
|
3075 Qt::ToolButtonIconOnly);
|
Chris@230
|
3076 }
|
Chris@230
|
3077 }
|
jtkorhonen@0
|
3078
|
Chris@287
|
3079 void MainWindow::updateWorkFolderAndRepoNames()
|
Chris@287
|
3080 {
|
Chris@287
|
3081 m_hgTabs->setLocalPath(m_workFolderPath);
|
Chris@287
|
3082
|
Chris@287
|
3083 m_workStatus->setLocalPath(m_workFolderPath);
|
Chris@287
|
3084 m_workStatus->setRemoteURL(m_remoteRepoPath);
|
Chris@287
|
3085 }
|
Chris@287
|
3086
|
jtkorhonen@0
|
3087 void MainWindow::createStatusBar()
|
jtkorhonen@0
|
3088 {
|
jtkorhonen@0
|
3089 statusBar()->showMessage(tr("Ready"));
|
jtkorhonen@0
|
3090 }
|
jtkorhonen@0
|
3091
|
jtkorhonen@0
|
3092 void MainWindow::readSettings()
|
jtkorhonen@0
|
3093 {
|
jtkorhonen@0
|
3094 QDir workFolder;
|
jtkorhonen@0
|
3095
|
Chris@61
|
3096 QSettings settings;
|
jtkorhonen@0
|
3097
|
Chris@284
|
3098 m_workFolderPath = settings.value("workfolderpath", "").toString();
|
Chris@553
|
3099 if (!workFolder.exists(m_workFolderPath)) {
|
Chris@284
|
3100 m_workFolderPath = "";
|
jtkorhonen@0
|
3101 }
|
jtkorhonen@0
|
3102
|
jtkorhonen@0
|
3103 QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
|
Chris@340
|
3104 QSize size = settings.value("size", QSize(550, 550)).toSize();
|
Chris@284
|
3105 m_firstStart = settings.value("firststart", QVariant(true)).toBool();
|
jtkorhonen@0
|
3106
|
jtkorhonen@0
|
3107 resize(size);
|
jtkorhonen@0
|
3108 move(pos);
|
jtkorhonen@0
|
3109 }
|
jtkorhonen@0
|
3110
|
jtkorhonen@0
|
3111 void MainWindow::writeSettings()
|
jtkorhonen@0
|
3112 {
|
Chris@61
|
3113 QSettings settings;
|
jtkorhonen@0
|
3114 settings.setValue("pos", pos());
|
jtkorhonen@0
|
3115 settings.setValue("size", size());
|
Chris@284
|
3116 settings.setValue("remoterepopath", m_remoteRepoPath);
|
Chris@284
|
3117 settings.setValue("workfolderpath", m_workFolderPath);
|
Chris@284
|
3118 settings.setValue("firststart", m_firstStart);
|
jtkorhonen@0
|
3119 }
|
jtkorhonen@0
|
3120
|
Chris@491
|
3121 void MainWindow::newerVersionAvailable(QString version)
|
Chris@491
|
3122 {
|
Chris@491
|
3123 QSettings settings;
|
Chris@491
|
3124 settings.beginGroup("NewerVersionWarning");
|
Chris@491
|
3125 QString tag = QString("version-%1-available-show").arg(version);
|
Chris@491
|
3126 if (settings.value(tag, true).toBool()) {
|
Chris@491
|
3127 QString title(tr("Newer version available"));
|
Chris@491
|
3128 QString text(tr("<h3>Newer version available</h3><p>You are using version %1 of EasyMercurial, but version %3 is now available.</p><p>Please see the <a href=\"http://easymercurial.org/\">EasyMercurial website</a> for more information.</p>").arg(EASYHG_VERSION).arg(version));
|
Chris@491
|
3129 QMessageBox::information(this, title, text);
|
Chris@491
|
3130 settings.setValue(tag, false);
|
Chris@491
|
3131 }
|
Chris@491
|
3132 settings.endGroup();
|
Chris@491
|
3133 }
|
Chris@491
|
3134
|
Chris@494
|
3135 void MainWindow::help()
|
Chris@494
|
3136 {
|
Chris@494
|
3137 if (!m_helpDialog) {
|
Chris@494
|
3138 m_helpDialog = new QDialog;
|
Chris@494
|
3139 QGridLayout *layout = new QGridLayout;
|
Chris@494
|
3140 m_helpDialog->setLayout(layout);
|
Chris@498
|
3141 QPushButton *home = new QPushButton;
|
Chris@498
|
3142 home->setIcon(QIcon(":images/home.png"));
|
Chris@498
|
3143 layout->addWidget(home, 0, 0);
|
Chris@498
|
3144 QPushButton *back = new QPushButton;
|
Chris@498
|
3145 back->setIcon(QIcon(":images/back.png"));
|
Chris@498
|
3146 layout->addWidget(back, 0, 1);
|
Chris@498
|
3147 QPushButton *fwd = new QPushButton;
|
Chris@498
|
3148 fwd->setIcon(QIcon(":images/forward.png"));
|
Chris@498
|
3149 layout->addWidget(fwd, 0, 2);
|
Chris@494
|
3150 QTextBrowser *text = new QTextBrowser;
|
Chris@494
|
3151 text->setOpenExternalLinks(true);
|
Chris@498
|
3152 layout->addWidget(text, 1, 0, 1, 4);
|
Chris@494
|
3153 text->setSource(QUrl("qrc:help/topics.html"));
|
Chris@494
|
3154 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Close);
|
Chris@494
|
3155 connect(bb, SIGNAL(rejected()), m_helpDialog, SLOT(hide()));
|
Chris@498
|
3156 connect(text, SIGNAL(backwardAvailable(bool)),
|
Chris@498
|
3157 back, SLOT(setEnabled(bool)));
|
Chris@498
|
3158 connect(text, SIGNAL(forwardAvailable(bool)),
|
Chris@498
|
3159 fwd, SLOT(setEnabled(bool)));
|
Chris@498
|
3160 connect(home, SIGNAL(clicked()), text, SLOT(home()));
|
Chris@498
|
3161 connect(back, SIGNAL(clicked()), text, SLOT(backward()));
|
Chris@498
|
3162 connect(fwd, SIGNAL(clicked()), text, SLOT(forward()));
|
Chris@498
|
3163 back->setEnabled(false);
|
Chris@498
|
3164 fwd->setEnabled(false);
|
Chris@498
|
3165 layout->addWidget(bb, 2, 0, 1, 4);
|
Chris@498
|
3166 layout->setColumnStretch(3, 20);
|
Chris@494
|
3167 m_helpDialog->resize(450, 500);
|
Chris@494
|
3168 }
|
Chris@494
|
3169 QTextBrowser *tb = m_helpDialog->findChild<QTextBrowser *>();
|
Chris@494
|
3170 if (tb) tb->home();
|
Chris@494
|
3171 m_helpDialog->show();
|
Chris@494
|
3172 m_helpDialog->raise();
|
Chris@494
|
3173 }
|
Chris@494
|
3174
|