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