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