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@57
|
8 Copyright (c) 2010 Chris Cannam
|
Chris@57
|
9 Copyright (c) 2010 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@125
|
32 #include <QRegExp>
|
Chris@199
|
33 #include <QShortcut>
|
jtkorhonen@0
|
34
|
Chris@53
|
35 #include "mainwindow.h"
|
Chris@69
|
36 #include "multichoicedialog.h"
|
Chris@64
|
37 #include "startupdialog.h"
|
Chris@53
|
38 #include "colourset.h"
|
Chris@62
|
39 #include "debug.h"
|
Chris@74
|
40 #include "logparser.h"
|
Chris@103
|
41 #include "confirmcommentdialog.h"
|
Chris@125
|
42 #include "incomingdialog.h"
|
Chris@175
|
43 #include "settingsdialog.h"
|
Chris@53
|
44
|
jtkorhonen@0
|
45
|
Chris@172
|
46 MainWindow::MainWindow(QString myDirPath) :
|
Chris@172
|
47 m_myDirPath(myDirPath)
|
jtkorhonen@0
|
48 {
|
Chris@197
|
49 setWindowIcon(QIcon(":images/easyhg-icon.png"));
|
Chris@197
|
50
|
jtkorhonen@0
|
51 QString wndTitle;
|
jtkorhonen@0
|
52
|
Chris@199
|
53 showAllFiles = false;
|
Chris@199
|
54
|
Chris@90
|
55 fsWatcher = 0;
|
Chris@133
|
56 commitsSincePush = 0;
|
Chris@163
|
57 shouldHgStat = true;
|
Chris@90
|
58
|
jtkorhonen@0
|
59 createActions();
|
jtkorhonen@0
|
60 createMenus();
|
jtkorhonen@0
|
61 createToolBars();
|
jtkorhonen@0
|
62 createStatusBar();
|
jtkorhonen@0
|
63
|
Chris@172
|
64 runner = new HgRunner(myDirPath, this);
|
Chris@109
|
65 connect(runner, SIGNAL(commandCompleted(HgAction, QString)),
|
Chris@109
|
66 this, SLOT(commandCompleted(HgAction, QString)));
|
Chris@109
|
67 connect(runner, SIGNAL(commandFailed(HgAction, QString)),
|
Chris@109
|
68 this, SLOT(commandFailed(HgAction, QString)));
|
jtkorhonen@0
|
69 statusBar()->addPermanentWidget(runner);
|
jtkorhonen@0
|
70
|
Chris@61
|
71 setWindowTitle(tr("EasyMercurial"));
|
jtkorhonen@0
|
72
|
jtkorhonen@0
|
73 remoteRepoPath = "";
|
jtkorhonen@0
|
74 workFolderPath = "";
|
jtkorhonen@0
|
75
|
jtkorhonen@0
|
76 readSettings();
|
jtkorhonen@0
|
77
|
jtkorhonen@33
|
78 justMerged = false;
|
Chris@210
|
79
|
Chris@210
|
80 QWidget *central = new QWidget(this);
|
Chris@210
|
81 setCentralWidget(central);
|
Chris@210
|
82
|
Chris@210
|
83 hgTabs = new HgTabWidget(central, remoteRepoPath, workFolderPath);
|
Chris@141
|
84 connectTabsSignals();
|
Chris@210
|
85
|
Chris@210
|
86 // Instead of setting the tab widget as our central widget
|
Chris@210
|
87 // directly, put it in a layout, so that we can have some space
|
Chris@210
|
88 // around it on the Mac where it looks very strange without
|
Chris@210
|
89
|
Chris@210
|
90 QGridLayout *cl = new QGridLayout(central);
|
Chris@210
|
91 cl->addWidget(hgTabs, 0, 0);
|
Chris@210
|
92
|
Chris@210
|
93 #ifndef Q_OS_MAC
|
Chris@210
|
94 cl->setMargin(0);
|
Chris@210
|
95 #endif
|
jtkorhonen@0
|
96
|
Chris@98
|
97 connect(hgTabs, SIGNAL(selectionChanged()),
|
Chris@95
|
98 this, SLOT(enableDisableActions()));
|
Chris@199
|
99 connect(hgTabs, SIGNAL(showAllChanged(bool)),
|
Chris@199
|
100 this, SLOT(showAllChanged(bool)));
|
Chris@95
|
101
|
jtkorhonen@0
|
102 setUnifiedTitleAndToolBarOnMac(true);
|
jtkorhonen@0
|
103 connectActions();
|
Chris@120
|
104 clearState();
|
jtkorhonen@0
|
105 enableDisableActions();
|
jtkorhonen@0
|
106
|
Chris@64
|
107 if (firstStart) {
|
Chris@64
|
108 startupDialog();
|
jtkorhonen@0
|
109 }
|
jtkorhonen@0
|
110
|
Chris@179
|
111 (void)findDiffBinaryName();
|
Chris@179
|
112 (void)findMergeBinaryName();
|
Chris@179
|
113 (void)findEditorBinaryName();
|
Chris@112
|
114
|
Chris@64
|
115 ColourSet *cs = ColourSet::instance();
|
Chris@64
|
116 cs->clearDefaultNames();
|
Chris@64
|
117 cs->addDefaultName("");
|
Chris@153
|
118 cs->addDefaultName("default");
|
Chris@64
|
119 cs->addDefaultName(getUserInfo());
|
Chris@62
|
120
|
Chris@72
|
121 if (workFolderPath == "") {
|
Chris@72
|
122 open();
|
Chris@72
|
123 }
|
Chris@72
|
124
|
Chris@175
|
125 hgTest();
|
jtkorhonen@0
|
126 }
|
jtkorhonen@0
|
127
|
jtkorhonen@0
|
128
|
jtkorhonen@0
|
129 void MainWindow::closeEvent(QCloseEvent *)
|
jtkorhonen@0
|
130 {
|
jtkorhonen@0
|
131 writeSettings();
|
Chris@90
|
132 delete fsWatcher;
|
jtkorhonen@0
|
133 }
|
jtkorhonen@0
|
134
|
jtkorhonen@0
|
135
|
Chris@64
|
136 QString MainWindow::getUserInfo() const
|
Chris@64
|
137 {
|
Chris@64
|
138 QSettings settings;
|
Chris@64
|
139 settings.beginGroup("User Information");
|
Chris@64
|
140 QString name = settings.value("name", getUserRealName()).toString();
|
Chris@64
|
141 QString email = settings.value("email", "").toString();
|
Chris@64
|
142
|
Chris@64
|
143 QString identifier;
|
Chris@64
|
144
|
Chris@64
|
145 if (email != "") {
|
Chris@64
|
146 identifier = QString("%1 <%2>").arg(name).arg(email);
|
Chris@64
|
147 } else {
|
Chris@64
|
148 identifier = name;
|
Chris@64
|
149 }
|
Chris@64
|
150
|
Chris@64
|
151 return identifier;
|
Chris@64
|
152 }
|
Chris@64
|
153
|
jtkorhonen@0
|
154 void MainWindow::about()
|
jtkorhonen@0
|
155 {
|
Chris@97
|
156 QMessageBox::about(this, tr("About EasyMercurial"),
|
Chris@97
|
157 tr("<qt><h2>About EasyMercurial</h2>"
|
Chris@223
|
158 #ifdef Q_OS_MAC
|
Chris@223
|
159 "<font size=-1>"
|
Chris@223
|
160 #endif
|
Chris@97
|
161 "<p>EasyMercurial is a simple user interface for the "
|
Chris@186
|
162 "Mercurial</a> version control system.</p>"
|
Chris@186
|
163 "<h4>Credits and Copyright</h4>"
|
Chris@186
|
164 "<p>Development carried out by Chris Cannam for "
|
Chris@186
|
165 "SoundSoftware.ac.uk at the Centre for Digital Music, "
|
Chris@186
|
166 "Queen Mary, University of London.</p>"
|
Chris@186
|
167 "<p>EasyMercurial is based on HgExplorer by "
|
Chris@186
|
168 "Jari Korhonen, with thanks.</p>"
|
Chris@186
|
169 "<p style=\"margin-left: 2em;\">"
|
Chris@186
|
170 "Copyright © 2010 Queen Mary, University of London.<br>"
|
Chris@186
|
171 "Copyright © 2010 Jari Korhonen.<br>"
|
Chris@186
|
172 "Copyright © 2010 Chris Cannam."
|
Chris@186
|
173 "</p>"
|
Chris@186
|
174 "<p style=\"margin-left: 2em;\">"
|
Chris@186
|
175 "This program requires Mercurial, by Matt Mackall and others.<br>"
|
Chris@186
|
176 "This program uses Qt by Nokia.<br>"
|
Chris@186
|
177 "This program uses Nuvola icons by David Vignoni.<br>"
|
Chris@186
|
178 "This program may use KDiff3 by Joachim Eibl.<br>"
|
Chris@186
|
179 "This program may use PyQt by River Bank Computing.<br>"
|
Chris@186
|
180 "Packaging for Mercurial and other dependencies on Windows is derived from TortoiseHg by Steve Borho and others."
|
Chris@186
|
181 "</p>"
|
Chris@186
|
182 "<h4>License</h4>"
|
Chris@186
|
183 "<p>This program is free software; you can redistribute it and/or "
|
Chris@97
|
184 "modify it under the terms of the GNU General Public License as "
|
Chris@97
|
185 "published by the Free Software Foundation; either version 2 of the "
|
Chris@97
|
186 "License, or (at your option) any later version. See the file "
|
Chris@223
|
187 "COPYING included with this distribution for more information.</p>"
|
Chris@223
|
188 #ifdef Q_OS_MAC
|
Chris@223
|
189 "</font>"
|
Chris@223
|
190 #endif
|
Chris@223
|
191 ));
|
jtkorhonen@0
|
192 }
|
jtkorhonen@0
|
193
|
Chris@94
|
194 void MainWindow::clearSelections()
|
Chris@94
|
195 {
|
Chris@98
|
196 hgTabs->clearSelections();
|
Chris@94
|
197 }
|
jtkorhonen@0
|
198
|
Chris@199
|
199 void MainWindow::showAllChanged(bool s)
|
Chris@199
|
200 {
|
Chris@199
|
201 showAllFiles = s;
|
Chris@199
|
202 hgQueryPaths();
|
Chris@199
|
203 }
|
Chris@199
|
204
|
Chris@120
|
205 void MainWindow::hgRefresh()
|
Chris@120
|
206 {
|
Chris@120
|
207 clearState();
|
Chris@120
|
208 hgQueryPaths();
|
Chris@120
|
209 }
|
Chris@120
|
210
|
Chris@175
|
211 void MainWindow::hgTest()
|
Chris@175
|
212 {
|
Chris@175
|
213 QStringList params;
|
Chris@207
|
214 //!!! should we test version output? Really we want at least 1.7.x
|
Chris@207
|
215 //!!! for options such as merge --tool
|
Chris@175
|
216 params << "--version";
|
Chris@175
|
217 runner->requestAction(HgAction(ACT_TEST_HG, m_myDirPath, params));
|
Chris@175
|
218 }
|
Chris@175
|
219
|
Chris@200
|
220 void MainWindow::hgTestExtension()
|
Chris@200
|
221 {
|
Chris@200
|
222 QStringList params;
|
Chris@200
|
223 params << "--version";
|
Chris@200
|
224 runner->requestAction(HgAction(ACT_TEST_HG_EXT, m_myDirPath, params));
|
Chris@200
|
225 }
|
Chris@200
|
226
|
jtkorhonen@0
|
227 void MainWindow::hgStat()
|
jtkorhonen@0
|
228 {
|
Chris@109
|
229 QStringList params;
|
Chris@199
|
230
|
Chris@199
|
231 if (showAllFiles) {
|
Chris@199
|
232 params << "stat" << "-A";
|
Chris@199
|
233 } else {
|
Chris@199
|
234 params << "stat" << "-ardum";
|
Chris@199
|
235 }
|
Chris@153
|
236
|
Chris@163
|
237 lastStatOutput = "";
|
Chris@163
|
238
|
Chris@153
|
239 // annoyingly, hg stat actually modifies the working directory --
|
Chris@153
|
240 // it creates files called hg-checklink and hg-checkexec to test
|
Chris@153
|
241 // properties of the filesystem
|
Chris@153
|
242 if (fsWatcher) fsWatcher->blockSignals(true);
|
Chris@153
|
243
|
Chris@109
|
244 runner->requestAction(HgAction(ACT_STAT, workFolderPath, params));
|
jtkorhonen@0
|
245 }
|
jtkorhonen@0
|
246
|
Chris@109
|
247 void MainWindow::hgQueryPaths()
|
Chris@74
|
248 {
|
Chris@210
|
249 // Quickest is to just read the file
|
Chris@198
|
250
|
Chris@198
|
251 QFileInfo hgrc(workFolderPath + "/.hg/hgrc");
|
Chris@198
|
252
|
Chris@210
|
253 QString path;
|
Chris@210
|
254
|
Chris@198
|
255 if (hgrc.exists()) {
|
Chris@198
|
256 QSettings s(hgrc.canonicalFilePath(), QSettings::IniFormat);
|
Chris@198
|
257 s.beginGroup("paths");
|
Chris@210
|
258 path = s.value("default").toString();
|
Chris@210
|
259 }
|
Chris@198
|
260
|
Chris@210
|
261 remoteRepoPath = path;
|
Chris@198
|
262
|
Chris@210
|
263 // We have to do this here, because commandCompleted won't be called
|
Chris@210
|
264 MultiChoiceDialog::addRecentArgument("local", workFolderPath);
|
Chris@210
|
265 MultiChoiceDialog::addRecentArgument("remote", remoteRepoPath);
|
Chris@210
|
266 hgTabs->setWorkFolderAndRepoNames(workFolderPath, remoteRepoPath);
|
Chris@210
|
267
|
Chris@210
|
268 hgQueryBranch();
|
Chris@210
|
269 return;
|
Chris@210
|
270
|
Chris@210
|
271 /* The classic method!
|
Chris@198
|
272
|
Chris@109
|
273 QStringList params;
|
Chris@109
|
274 params << "paths";
|
Chris@109
|
275 runner->requestAction(HgAction(ACT_QUERY_PATHS, workFolderPath, params));
|
Chris@210
|
276 */
|
Chris@74
|
277 }
|
Chris@74
|
278
|
Chris@109
|
279 void MainWindow::hgQueryBranch()
|
Chris@106
|
280 {
|
Chris@210
|
281 // Quickest is to just read the file
|
Chris@198
|
282
|
Chris@198
|
283 QFile hgbr(workFolderPath + "/.hg/branch");
|
Chris@198
|
284
|
Chris@210
|
285 QString br = "default";
|
Chris@210
|
286
|
Chris@198
|
287 if (hgbr.exists() && hgbr.open(QFile::ReadOnly)) {
|
Chris@210
|
288 QByteArray ba = hgbr.readLine();
|
Chris@210
|
289 br = QString::fromUtf8(ba).trimmed();
|
Chris@210
|
290 }
|
Chris@210
|
291
|
Chris@210
|
292 currentBranch = br;
|
Chris@210
|
293
|
Chris@210
|
294 // We have to do this here, because commandCompleted won't be called
|
Chris@210
|
295 hgStat();
|
Chris@210
|
296 return;
|
Chris@198
|
297
|
Chris@210
|
298 /* The classic method!
|
Chris@198
|
299
|
Chris@109
|
300 QStringList params;
|
Chris@109
|
301 params << "branch";
|
Chris@109
|
302 runner->requestAction(HgAction(ACT_QUERY_BRANCH, workFolderPath, params));
|
Chris@210
|
303 */
|
Chris@106
|
304 }
|
Chris@106
|
305
|
Chris@109
|
306 void MainWindow::hgQueryHeads()
|
jtkorhonen@0
|
307 {
|
Chris@109
|
308 QStringList params;
|
Chris@137
|
309 // On empty repos, "hg heads" will fail -- we don't care about
|
Chris@137
|
310 // that. Use --closed option so as to include closed branches;
|
Chris@137
|
311 // otherwise we'll be stuck if the user updates into one, and our
|
Chris@137
|
312 // incremental log will end up with spurious stuff in it because
|
Chris@137
|
313 // we won't be pruning at the ends of closed branches
|
Chris@137
|
314 params << "heads" << "--closed";
|
Chris@109
|
315 runner->requestAction(HgAction(ACT_QUERY_HEADS, workFolderPath, params));
|
jtkorhonen@0
|
316 }
|
jtkorhonen@0
|
317
|
jtkorhonen@0
|
318 void MainWindow::hgLog()
|
jtkorhonen@0
|
319 {
|
Chris@109
|
320 QStringList params;
|
Chris@109
|
321 params << "log";
|
Chris@109
|
322 params << "--template";
|
Chris@125
|
323 params << Changeset::getLogTemplate();
|
Chris@109
|
324
|
Chris@109
|
325 runner->requestAction(HgAction(ACT_LOG, workFolderPath, params));
|
Chris@109
|
326 }
|
Chris@109
|
327
|
Chris@150
|
328 void MainWindow::hgLogIncremental(QStringList prune)
|
Chris@120
|
329 {
|
Chris@120
|
330 QStringList params;
|
Chris@120
|
331 params << "log";
|
Chris@120
|
332
|
Chris@150
|
333 foreach (QString p, prune) {
|
Chris@153
|
334 params << "--prune" << Changeset::hashOf(p);
|
Chris@120
|
335 }
|
Chris@120
|
336
|
Chris@120
|
337 params << "--template";
|
Chris@125
|
338 params << Changeset::getLogTemplate();
|
Chris@120
|
339
|
Chris@120
|
340 runner->requestAction(HgAction(ACT_LOG_INCREMENTAL, workFolderPath, params));
|
Chris@120
|
341 }
|
Chris@109
|
342
|
Chris@109
|
343 void MainWindow::hgQueryParents()
|
Chris@109
|
344 {
|
Chris@109
|
345 QStringList params;
|
Chris@109
|
346 params << "parents";
|
Chris@109
|
347 runner->requestAction(HgAction(ACT_QUERY_PARENTS, workFolderPath, params));
|
Chris@109
|
348 }
|
Chris@109
|
349
|
Chris@109
|
350 void MainWindow::hgAnnotate()
|
Chris@109
|
351 {
|
Chris@109
|
352 QStringList params;
|
Chris@109
|
353 QString currentFile;//!!! = hgTabs -> getCurrentFileListLine();
|
Chris@109
|
354
|
Chris@109
|
355 if (!currentFile.isEmpty())
|
jtkorhonen@0
|
356 {
|
Chris@109
|
357 params << "annotate" << "--" << currentFile.mid(2); //Jump over status marker characters (e.g "M ")
|
jtkorhonen@0
|
358
|
Chris@109
|
359 runner->requestAction(HgAction(ACT_ANNOTATE, workFolderPath, params));
|
jtkorhonen@0
|
360 }
|
jtkorhonen@0
|
361 }
|
jtkorhonen@0
|
362
|
Chris@109
|
363 void MainWindow::hgResolveList()
|
Chris@109
|
364 {
|
Chris@109
|
365 QStringList params;
|
jtkorhonen@0
|
366
|
Chris@109
|
367 params << "resolve" << "--list";
|
Chris@109
|
368 runner->requestAction(HgAction(ACT_RESOLVE_LIST, workFolderPath, params));
|
Chris@109
|
369 }
|
Chris@109
|
370
|
Chris@109
|
371 void MainWindow::hgAdd()
|
jtkorhonen@0
|
372 {
|
Chris@109
|
373 QStringList params;
|
jtkorhonen@0
|
374
|
Chris@109
|
375 // hgExplorer permitted adding "all" files -- I'm not sure
|
Chris@109
|
376 // that one is a good idea, let's require the user to select
|
jtkorhonen@0
|
377
|
Chris@109
|
378 QStringList files = hgTabs->getSelectedAddableFiles();
|
Chris@109
|
379
|
Chris@109
|
380 if (!files.empty()) {
|
Chris@109
|
381 params << "add" << "--" << files;
|
Chris@109
|
382 runner->requestAction(HgAction(ACT_ADD, workFolderPath, params));
|
jtkorhonen@0
|
383 }
|
jtkorhonen@0
|
384 }
|
jtkorhonen@0
|
385
|
jtkorhonen@0
|
386
|
Chris@98
|
387 void MainWindow::hgRemove()
|
Chris@98
|
388 {
|
Chris@109
|
389 QStringList params;
|
Chris@98
|
390
|
Chris@109
|
391 QStringList files = hgTabs->getSelectedRemovableFiles();
|
Chris@98
|
392
|
Chris@109
|
393 //!!! todo: confirmation dialog (with file list in it) (or do we
|
Chris@109
|
394 // need that? all it does is move the files to the removed
|
Chris@109
|
395 // list... doesn't it?)
|
Chris@98
|
396
|
Chris@109
|
397 if (!files.empty()) {
|
Chris@109
|
398 params << "remove" << "--after" << "--force" << "--" << files;
|
Chris@109
|
399 runner->requestAction(HgAction(ACT_REMOVE, workFolderPath, params));
|
Chris@109
|
400 }
|
jtkorhonen@0
|
401 }
|
jtkorhonen@0
|
402
|
jtkorhonen@0
|
403 void MainWindow::hgCommit()
|
jtkorhonen@0
|
404 {
|
Chris@109
|
405 QStringList params;
|
Chris@109
|
406 QString comment;
|
Chris@94
|
407
|
Chris@157
|
408 if (justMerged) {
|
Chris@157
|
409 comment = mergeCommitComment;
|
Chris@157
|
410 }
|
Chris@157
|
411
|
Chris@109
|
412 QStringList files = hgTabs->getSelectedCommittableFiles();
|
Chris@127
|
413 QStringList reportFiles = files;
|
Chris@127
|
414 if (reportFiles.empty()) reportFiles = hgTabs->getAllCommittableFiles();
|
Chris@103
|
415
|
Chris@155
|
416 QString cf(tr("Commit files"));
|
Chris@155
|
417
|
Chris@109
|
418 if (ConfirmCommentDialog::confirmAndGetLongComment
|
Chris@109
|
419 (this,
|
Chris@155
|
420 cf,
|
Chris@155
|
421 tr("<h3>%1</h3><p>%2").arg(cf)
|
Chris@155
|
422 .arg(tr("You are about to commit the following files:")),
|
Chris@155
|
423 tr("<h3>%1</h3><p>%2").arg(cf)
|
Chris@168
|
424 .arg(tr("You are about to commit %n file(s).", "", reportFiles.size())),
|
Chris@127
|
425 reportFiles,
|
Chris@193
|
426 comment,
|
Chris@193
|
427 tr("Commit"))) {
|
Chris@103
|
428
|
Chris@157
|
429 if (!justMerged && !files.empty()) {
|
Chris@157
|
430 // User wants to commit selected file(s) (and this is not
|
Chris@157
|
431 // merge commit, which would fail if we selected files)
|
Chris@157
|
432 params << "commit" << "--message" << comment
|
Chris@157
|
433 << "--user" << getUserInfo() << "--" << files;
|
Chris@109
|
434 } else {
|
Chris@109
|
435 // Commit all changes
|
Chris@157
|
436 params << "commit" << "--message" << comment
|
Chris@157
|
437 << "--user" << getUserInfo();
|
jtkorhonen@0
|
438 }
|
Chris@109
|
439
|
Chris@109
|
440 runner->requestAction(HgAction(ACT_COMMIT, workFolderPath, params));
|
Chris@173
|
441 mergeCommitComment = "";
|
jtkorhonen@0
|
442 }
|
jtkorhonen@0
|
443 }
|
jtkorhonen@0
|
444
|
jtkorhonen@34
|
445 QString MainWindow::filterTag(QString tag)
|
jtkorhonen@34
|
446 {
|
jtkorhonen@34
|
447 for(int i = 0; i < tag.size(); i++)
|
jtkorhonen@34
|
448 {
|
jtkorhonen@34
|
449 if (tag[i].isLower() || tag[i].isUpper() || tag[i].isDigit() || (tag[i] == QChar('.')))
|
jtkorhonen@34
|
450 {
|
jtkorhonen@34
|
451 //ok
|
jtkorhonen@34
|
452 }
|
jtkorhonen@34
|
453 else
|
jtkorhonen@34
|
454 {
|
jtkorhonen@34
|
455 tag[i] = QChar('_');
|
jtkorhonen@34
|
456 }
|
jtkorhonen@34
|
457 }
|
jtkorhonen@34
|
458 return tag;
|
jtkorhonen@34
|
459 }
|
jtkorhonen@34
|
460
|
jtkorhonen@34
|
461
|
Chris@164
|
462 void MainWindow::hgTag(QString id)
|
jtkorhonen@34
|
463 {
|
Chris@109
|
464 QStringList params;
|
Chris@109
|
465 QString tag;
|
jtkorhonen@34
|
466
|
Chris@109
|
467 if (ConfirmCommentDialog::confirmAndGetShortComment
|
Chris@109
|
468 (this,
|
Chris@109
|
469 tr("Tag"),
|
Chris@109
|
470 tr("Enter tag:"),
|
Chris@193
|
471 tag,
|
Chris@193
|
472 tr("Add Tag"))) {
|
Chris@164
|
473 if (!tag.isEmpty()) {//!!! do something better if it is empty
|
Chris@164
|
474
|
Chris@164
|
475 params << "tag" << "--user" << getUserInfo();
|
Chris@164
|
476 params << "--rev" << Changeset::hashOf(id) << filterTag(tag);
|
Chris@109
|
477
|
Chris@109
|
478 runner->requestAction(HgAction(ACT_TAG, workFolderPath, params));
|
jtkorhonen@34
|
479 }
|
jtkorhonen@34
|
480 }
|
jtkorhonen@34
|
481 }
|
jtkorhonen@34
|
482
|
jtkorhonen@34
|
483
|
jtkorhonen@34
|
484 void MainWindow::hgIgnore()
|
jtkorhonen@34
|
485 {
|
Chris@109
|
486 QString hgIgnorePath;
|
Chris@109
|
487 QStringList params;
|
Chris@178
|
488
|
Chris@109
|
489 hgIgnorePath = workFolderPath;
|
Chris@178
|
490 hgIgnorePath += "/.hgignore";
|
Chris@109
|
491
|
Chris@109
|
492 params << hgIgnorePath;
|
Chris@179
|
493
|
Chris@179
|
494 QString editor = findEditorBinaryName();
|
Chris@112
|
495
|
Chris@179
|
496 if (editor == "") {
|
Chris@179
|
497 DEBUG << "Failed to find a text editor" << endl;
|
Chris@179
|
498 //!!! visible error!
|
Chris@179
|
499 return;
|
Chris@179
|
500 }
|
Chris@179
|
501
|
Chris@179
|
502 HgAction action(ACT_HG_IGNORE, workFolderPath, params);
|
Chris@179
|
503 action.executable = editor;
|
Chris@179
|
504
|
Chris@179
|
505 runner->requestAction(action);
|
Chris@179
|
506 }
|
Chris@179
|
507
|
Chris@179
|
508 QString MainWindow::findDiffBinaryName()
|
Chris@179
|
509 {
|
Chris@179
|
510 QSettings settings;
|
Chris@179
|
511 settings.beginGroup("Locations");
|
Chris@179
|
512 QString diff = settings.value("extdiffbinary", "").toString();
|
Chris@179
|
513 if (diff == "") {
|
Chris@179
|
514 QStringList bases;
|
Chris@212
|
515 #ifdef Q_OS_MAC
|
Chris@212
|
516 bases << "easyhg-extdiff-osx.sh";
|
Chris@212
|
517 #endif
|
Chris@212
|
518 bases << "kompare" << "kdiff3" << "meld";
|
Chris@179
|
519 bool found = false;
|
Chris@179
|
520 foreach (QString base, bases) {
|
Chris@179
|
521 diff = findInPath(base, m_myDirPath, true);
|
Chris@213
|
522 if (diff != "") {
|
Chris@179
|
523 found = true;
|
Chris@179
|
524 break;
|
Chris@179
|
525 }
|
Chris@179
|
526 }
|
Chris@179
|
527 if (found) {
|
Chris@179
|
528 settings.setValue("extdiffbinary", diff);
|
Chris@179
|
529 } else {
|
Chris@179
|
530 diff = "";
|
Chris@179
|
531 }
|
Chris@179
|
532 }
|
Chris@179
|
533 return diff;
|
Chris@179
|
534 }
|
Chris@179
|
535
|
Chris@179
|
536 QString MainWindow::findMergeBinaryName()
|
Chris@179
|
537 {
|
Chris@179
|
538 QSettings settings;
|
Chris@179
|
539 settings.beginGroup("Locations");
|
Chris@195
|
540 QVariant v = settings.value("mergebinary");
|
Chris@195
|
541 if (v != QVariant()) {
|
Chris@195
|
542 return v.toString(); // even if empty: user may have specified no external tool
|
Chris@195
|
543 }
|
Chris@195
|
544 QString merge;
|
Chris@195
|
545 QStringList bases;
|
Chris@212
|
546 #ifdef Q_OS_MAC
|
Chris@212
|
547 bases << "easyhg-merge-osx.sh";
|
Chris@212
|
548 #endif
|
Chris@212
|
549 bases << "meld" << "diffuse" << "kdiff3";
|
Chris@195
|
550 bool found = false;
|
Chris@195
|
551 foreach (QString base, bases) {
|
Chris@195
|
552 merge = findInPath(base, m_myDirPath, true);
|
Chris@213
|
553 if (merge != "") {
|
Chris@195
|
554 found = true;
|
Chris@195
|
555 break;
|
Chris@179
|
556 }
|
Chris@195
|
557 }
|
Chris@195
|
558 if (found) {
|
Chris@195
|
559 settings.setValue("mergebinary", merge);
|
Chris@195
|
560 } else {
|
Chris@195
|
561 merge = "";
|
Chris@179
|
562 }
|
Chris@179
|
563 return merge;
|
Chris@179
|
564 }
|
Chris@179
|
565
|
Chris@179
|
566 QString MainWindow::findEditorBinaryName()
|
Chris@179
|
567 {
|
Chris@178
|
568 QSettings settings;
|
Chris@178
|
569 settings.beginGroup("Locations");
|
Chris@178
|
570 QString editor = settings.value("editorbinary", "").toString();
|
Chris@178
|
571 if (editor == "") {
|
Chris@178
|
572 QStringList bases;
|
Chris@178
|
573 bases
|
Chris@178
|
574 #if defined Q_OS_WIN32
|
Chris@178
|
575 << "wordpad.exe"
|
Chris@178
|
576 << "C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe"
|
Chris@178
|
577 << "notepad.exe"
|
Chris@178
|
578 #elif defined Q_OS_MAC
|
Chris@212
|
579 << "/Applications/TextEdit.app/Contents/MacOS/TextEdit"
|
Chris@178
|
580 #else
|
Chris@178
|
581 << "gedit" << "kate"
|
Chris@178
|
582 #endif
|
Chris@178
|
583 ;
|
Chris@178
|
584 bool found = false;
|
Chris@178
|
585 foreach (QString base, bases) {
|
Chris@178
|
586 editor = findInPath(base, m_myDirPath, true);
|
Chris@213
|
587 if (editor != "") {
|
Chris@178
|
588 found = true;
|
Chris@178
|
589 break;
|
Chris@178
|
590 }
|
Chris@178
|
591 }
|
Chris@178
|
592 if (found) {
|
Chris@178
|
593 settings.setValue("editorbinary", editor);
|
Chris@178
|
594 } else {
|
Chris@178
|
595 editor = "";
|
Chris@178
|
596 }
|
Chris@178
|
597 }
|
Chris@179
|
598 return editor;
|
Chris@163
|
599 }
|
Chris@163
|
600
|
Chris@168
|
601 void MainWindow::hgShowSummary()
|
Chris@168
|
602 {
|
Chris@168
|
603 QStringList params;
|
Chris@168
|
604
|
Chris@168
|
605 params << "diff" << "--stat";
|
Chris@168
|
606
|
Chris@168
|
607 runner->requestAction(HgAction(ACT_DIFF_SUMMARY, workFolderPath, params));
|
Chris@168
|
608 }
|
Chris@168
|
609
|
jtkorhonen@0
|
610 void MainWindow::hgFolderDiff()
|
jtkorhonen@0
|
611 {
|
Chris@179
|
612 QString diff = findDiffBinaryName();
|
Chris@179
|
613 if (diff == "") return;
|
Chris@112
|
614
|
Chris@109
|
615 QStringList params;
|
jtkorhonen@0
|
616
|
Chris@112
|
617 // Diff parent against working folder (folder diff)
|
Chris@112
|
618
|
Chris@148
|
619 params << "--config" << "extensions.extdiff=" << "extdiff";
|
Chris@179
|
620 params << "--program" << diff;
|
Chris@109
|
621
|
Chris@153
|
622 params << hgTabs->getSelectedCommittableFiles(); // may be none: whole dir
|
Chris@153
|
623
|
Chris@109
|
624 runner->requestAction(HgAction(ACT_FOLDERDIFF, workFolderPath, params));
|
jtkorhonen@0
|
625 }
|
jtkorhonen@0
|
626
|
jtkorhonen@0
|
627
|
Chris@148
|
628 void MainWindow::hgDiffToCurrent(QString id)
|
jtkorhonen@0
|
629 {
|
Chris@179
|
630 QString diff = findDiffBinaryName();
|
Chris@179
|
631 if (diff == "") return;
|
Chris@163
|
632
|
Chris@148
|
633 QStringList params;
|
jtkorhonen@0
|
634
|
Chris@148
|
635 // Diff given revision against working folder
|
jtkorhonen@0
|
636
|
Chris@148
|
637 params << "--config" << "extensions.extdiff=" << "extdiff";
|
Chris@179
|
638 params << "--program" << diff;
|
Chris@153
|
639 params << "--rev" << Changeset::hashOf(id);
|
Chris@148
|
640
|
Chris@148
|
641 runner->requestAction(HgAction(ACT_FOLDERDIFF, workFolderPath, params));
|
jtkorhonen@0
|
642 }
|
jtkorhonen@0
|
643
|
jtkorhonen@0
|
644
|
Chris@148
|
645 void MainWindow::hgDiffToParent(QString child, QString parent)
|
Chris@148
|
646 {
|
Chris@179
|
647 QString diff = findDiffBinaryName();
|
Chris@179
|
648 if (diff == "") return;
|
Chris@163
|
649
|
Chris@148
|
650 QStringList params;
|
Chris@148
|
651
|
Chris@148
|
652 // Diff given revision against working folder
|
Chris@148
|
653
|
Chris@148
|
654 params << "--config" << "extensions.extdiff=" << "extdiff";
|
Chris@179
|
655 params << "--program" << diff;
|
Chris@153
|
656 params << "--rev" << Changeset::hashOf(parent)
|
Chris@153
|
657 << "--rev" << Changeset::hashOf(child);
|
Chris@148
|
658
|
Chris@148
|
659 runner->requestAction(HgAction(ACT_CHGSETDIFF, workFolderPath, params));
|
Chris@148
|
660 }
|
Chris@148
|
661
|
jtkorhonen@0
|
662
|
jtkorhonen@0
|
663 void MainWindow::hgUpdate()
|
jtkorhonen@0
|
664 {
|
Chris@109
|
665 QStringList params;
|
jtkorhonen@0
|
666
|
Chris@109
|
667 params << "update";
|
Chris@109
|
668
|
Chris@109
|
669 runner->requestAction(HgAction(ACT_UPDATE, workFolderPath, params));
|
jtkorhonen@0
|
670 }
|
jtkorhonen@0
|
671
|
jtkorhonen@0
|
672
|
Chris@148
|
673 void MainWindow::hgUpdateToRev(QString id)
|
jtkorhonen@0
|
674 {
|
Chris@148
|
675 QStringList params;
|
jtkorhonen@0
|
676
|
Chris@153
|
677 params << "update" << "--rev" << Changeset::hashOf(id) << "--check";
|
jtkorhonen@0
|
678
|
Chris@148
|
679 runner->requestAction(HgAction(ACT_UPDATE, workFolderPath, params));
|
jtkorhonen@0
|
680 }
|
jtkorhonen@0
|
681
|
jtkorhonen@0
|
682
|
jtkorhonen@0
|
683 void MainWindow::hgRevert()
|
jtkorhonen@0
|
684 {
|
Chris@109
|
685 QStringList params;
|
Chris@109
|
686 QString comment;
|
Chris@98
|
687
|
Chris@109
|
688 QStringList files = hgTabs->getSelectedRevertableFiles();
|
Chris@109
|
689 if (files.empty()) files = hgTabs->getAllRevertableFiles();
|
Chris@155
|
690
|
Chris@155
|
691 QString rf(tr("Revert files"));
|
Chris@109
|
692
|
Chris@109
|
693 if (ConfirmCommentDialog::confirmDangerousFilesAction
|
Chris@109
|
694 (this,
|
Chris@155
|
695 rf,
|
Chris@155
|
696 tr("<h3>%1</h3><p>%2").arg(rf)
|
Chris@155
|
697 .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@155
|
698 tr("<h3>%1</h3><p>%2").arg(rf)
|
Chris@155
|
699 .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@193
|
700 files,
|
Chris@193
|
701 tr("Revert"))) {
|
Chris@163
|
702
|
Chris@163
|
703 lastRevertedFiles = files;
|
Chris@109
|
704
|
Chris@98
|
705 if (files.empty()) {
|
Chris@98
|
706 params << "revert" << "--no-backup";
|
Chris@98
|
707 } else {
|
Chris@164
|
708 params << "revert" << "--" << files;
|
Chris@98
|
709 }
|
Chris@163
|
710
|
Chris@163
|
711 //!!! This is problematic. If you've got an uncommitted
|
Chris@163
|
712 //!!! merge, you can't revert it without declaring which
|
Chris@163
|
713 //!!! parent of the merge you want to revert to (reasonably
|
Chris@163
|
714 //!!! enough). We're OK if we just did the merge in easyhg a
|
Chris@163
|
715 //!!! moment ago, because we have a record of which parent was
|
Chris@163
|
716 //!!! the target -- but if you exit and restart, we've lost
|
Chris@163
|
717 //!!! that record and it doesn't appear to be possible to get
|
Chris@163
|
718 //!!! it back from Hg. Even if you just switched from one
|
Chris@163
|
719 //!!! repo to another, the record is lost. What to do?
|
Chris@163
|
720
|
Chris@163
|
721 if (justMerged && mergeTargetRevision != "") {
|
Chris@163
|
722 params << "--rev" << mergeTargetRevision;
|
Chris@163
|
723 }
|
Chris@109
|
724
|
Chris@109
|
725 runner->requestAction(HgAction(ACT_REVERT, workFolderPath, params));
|
jtkorhonen@0
|
726 }
|
jtkorhonen@0
|
727 }
|
jtkorhonen@0
|
728
|
Chris@163
|
729
|
Chris@163
|
730 void MainWindow::hgMarkResolved(QStringList files)
|
Chris@163
|
731 {
|
Chris@163
|
732 QStringList params;
|
Chris@163
|
733
|
Chris@163
|
734 params << "resolve" << "--mark";
|
Chris@163
|
735
|
Chris@163
|
736 if (files.empty()) {
|
Chris@163
|
737 params << "--all";
|
Chris@163
|
738 } else {
|
Chris@164
|
739 params << "--" << files;
|
Chris@163
|
740 }
|
Chris@163
|
741
|
Chris@163
|
742 runner->requestAction(HgAction(ACT_RESOLVE_MARK, workFolderPath, params));
|
Chris@163
|
743 }
|
Chris@163
|
744
|
Chris@163
|
745
|
jtkorhonen@33
|
746 void MainWindow::hgRetryMerge()
|
jtkorhonen@33
|
747 {
|
Chris@109
|
748 QStringList params;
|
jtkorhonen@33
|
749
|
Chris@163
|
750 params << "resolve";
|
Chris@163
|
751
|
Chris@179
|
752 QString merge = findMergeBinaryName();
|
Chris@179
|
753 if (merge != "") {
|
Chris@179
|
754 params << "--tool" << merge;
|
Chris@163
|
755 }
|
Chris@163
|
756
|
Chris@163
|
757 QStringList files = hgTabs->getSelectedUnresolvedFiles();
|
Chris@163
|
758 if (files.empty()) {
|
Chris@163
|
759 params << "--all";
|
Chris@163
|
760 } else {
|
Chris@164
|
761 params << "--" << files;
|
Chris@163
|
762 }
|
Chris@163
|
763
|
Chris@109
|
764 runner->requestAction(HgAction(ACT_RETRY_MERGE, workFolderPath, params));
|
Chris@163
|
765
|
Chris@163
|
766 mergeCommitComment = tr("Merge");
|
jtkorhonen@33
|
767 }
|
jtkorhonen@33
|
768
|
jtkorhonen@33
|
769
|
jtkorhonen@0
|
770 void MainWindow::hgMerge()
|
jtkorhonen@0
|
771 {
|
Chris@163
|
772 if (hgTabs->canResolve()) {
|
Chris@163
|
773 hgRetryMerge();
|
Chris@163
|
774 return;
|
Chris@163
|
775 }
|
Chris@163
|
776
|
Chris@109
|
777 QStringList params;
|
jtkorhonen@0
|
778
|
Chris@109
|
779 params << "merge";
|
Chris@163
|
780
|
Chris@179
|
781 QString merge = findMergeBinaryName();
|
Chris@179
|
782 if (merge != "") {
|
Chris@179
|
783 params << "--tool" << merge;
|
Chris@163
|
784 }
|
Chris@163
|
785
|
Chris@163
|
786 if (currentParents.size() == 1) {
|
Chris@163
|
787 mergeTargetRevision = currentParents[0]->id();
|
Chris@163
|
788 }
|
Chris@163
|
789
|
Chris@109
|
790 runner->requestAction(HgAction(ACT_MERGE, workFolderPath, params));
|
Chris@157
|
791
|
Chris@157
|
792 mergeCommitComment = tr("Merge");
|
jtkorhonen@0
|
793 }
|
jtkorhonen@0
|
794
|
jtkorhonen@0
|
795
|
Chris@148
|
796 void MainWindow::hgMergeFrom(QString id)
|
Chris@148
|
797 {
|
Chris@148
|
798 QStringList params;
|
Chris@148
|
799
|
Chris@148
|
800 params << "merge";
|
Chris@153
|
801 params << "--rev" << Changeset::hashOf(id);
|
Chris@163
|
802
|
Chris@179
|
803 QString merge = findMergeBinaryName();
|
Chris@179
|
804 if (merge != "") {
|
Chris@179
|
805 params << "--tool" << merge;
|
Chris@163
|
806 }
|
Chris@148
|
807
|
Chris@148
|
808 runner->requestAction(HgAction(ACT_MERGE, workFolderPath, params));
|
Chris@157
|
809
|
Chris@157
|
810 mergeCommitComment = "";
|
Chris@157
|
811
|
Chris@157
|
812 foreach (Changeset *cs, currentHeads) {
|
Chris@157
|
813 if (cs->id() == id && !cs->isOnBranch(currentBranch)) {
|
Chris@157
|
814 if (cs->branch() == "" || cs->branch() == "default") {
|
Chris@157
|
815 mergeCommitComment = tr("Merge from the default branch");
|
Chris@157
|
816 } else {
|
Chris@157
|
817 mergeCommitComment = tr("Merge from branch \"%1\"").arg(cs->branch());
|
Chris@157
|
818 }
|
Chris@157
|
819 }
|
Chris@157
|
820 }
|
Chris@157
|
821
|
Chris@157
|
822 if (mergeCommitComment == "") {
|
Chris@157
|
823 mergeCommitComment = tr("Merge from %1").arg(id);
|
Chris@157
|
824 }
|
Chris@148
|
825 }
|
Chris@148
|
826
|
Chris@148
|
827
|
jtkorhonen@0
|
828 void MainWindow::hgCloneFromRemote()
|
jtkorhonen@0
|
829 {
|
Chris@109
|
830 QStringList params;
|
jtkorhonen@0
|
831
|
Chris@109
|
832 if (!QDir(workFolderPath).exists()) {
|
Chris@109
|
833 if (!QDir().mkpath(workFolderPath)) {
|
Chris@109
|
834 DEBUG << "hgCloneFromRemote: Failed to create target path "
|
Chris@109
|
835 << workFolderPath << endl;
|
Chris@109
|
836 //!!! report error
|
Chris@109
|
837 return;
|
Chris@104
|
838 }
|
Chris@109
|
839 }
|
Chris@104
|
840
|
Chris@109
|
841 params << "clone" << remoteRepoPath << workFolderPath;
|
Chris@109
|
842
|
Chris@109
|
843 hgTabs->setWorkFolderAndRepoNames(workFolderPath, remoteRepoPath);
|
Chris@113
|
844 hgTabs->updateWorkFolderFileList("");
|
jtkorhonen@0
|
845
|
Chris@109
|
846 runner->requestAction(HgAction(ACT_CLONEFROMREMOTE, workFolderPath, params));
|
jtkorhonen@0
|
847 }
|
jtkorhonen@0
|
848
|
jtkorhonen@0
|
849 void MainWindow::hgInit()
|
jtkorhonen@0
|
850 {
|
Chris@109
|
851 QStringList params;
|
jtkorhonen@0
|
852
|
Chris@109
|
853 params << "init";
|
Chris@109
|
854 params << workFolderPath;
|
jtkorhonen@0
|
855
|
Chris@109
|
856 runner->requestAction(HgAction(ACT_INIT, workFolderPath, params));
|
jtkorhonen@0
|
857 }
|
jtkorhonen@0
|
858
|
jtkorhonen@0
|
859 void MainWindow::hgIncoming()
|
jtkorhonen@0
|
860 {
|
Chris@109
|
861 QStringList params;
|
jtkorhonen@0
|
862
|
Chris@109
|
863 params << "incoming" << "--newest-first" << remoteRepoPath;
|
Chris@125
|
864 params << "--template" << Changeset::getLogTemplate();
|
jtkorhonen@0
|
865
|
Chris@109
|
866 runner->requestAction(HgAction(ACT_INCOMING, workFolderPath, params));
|
jtkorhonen@0
|
867 }
|
jtkorhonen@0
|
868
|
jtkorhonen@0
|
869 void MainWindow::hgPull()
|
jtkorhonen@0
|
870 {
|
Chris@193
|
871 if (ConfirmCommentDialog::confirm
|
Chris@126
|
872 (this, tr("Confirm pull"),
|
Chris@126
|
873 format3(tr("Confirm pull from remote repository"),
|
Chris@192
|
874 tr("You are about to pull changes from the following remote repository:"),
|
Chris@126
|
875 remoteRepoPath),
|
Chris@194
|
876 tr("Pull"))) {
|
jtkorhonen@0
|
877
|
Chris@126
|
878 QStringList params;
|
Chris@126
|
879 params << "pull" << remoteRepoPath;
|
Chris@126
|
880 runner->requestAction(HgAction(ACT_PULL, workFolderPath, params));
|
Chris@126
|
881 }
|
jtkorhonen@0
|
882 }
|
jtkorhonen@0
|
883
|
jtkorhonen@0
|
884 void MainWindow::hgPush()
|
jtkorhonen@0
|
885 {
|
Chris@193
|
886 if (ConfirmCommentDialog::confirm
|
Chris@126
|
887 (this, tr("Confirm push"),
|
Chris@126
|
888 format3(tr("Confirm push to remote repository"),
|
Chris@192
|
889 tr("You are about to push your changes to the following remote repository:"),
|
Chris@126
|
890 remoteRepoPath),
|
Chris@194
|
891 tr("Push"))) {
|
jtkorhonen@0
|
892
|
Chris@126
|
893 QStringList params;
|
Chris@154
|
894 params << "push" << "--new-branch" << remoteRepoPath;
|
Chris@126
|
895 runner->requestAction(HgAction(ACT_PUSH, workFolderPath, params));
|
Chris@126
|
896 }
|
jtkorhonen@0
|
897 }
|
jtkorhonen@0
|
898
|
Chris@182
|
899 QStringList MainWindow::listAllUpIpV4Addresses()
|
jtkorhonen@26
|
900 {
|
Chris@182
|
901 QStringList ret;
|
jtkorhonen@26
|
902 QList<QNetworkInterface> ifaces = QNetworkInterface::allInterfaces();
|
jtkorhonen@26
|
903
|
Chris@182
|
904 for (int i = 0; i < ifaces.count(); i++) {
|
jtkorhonen@26
|
905 QNetworkInterface iface = ifaces.at(i);
|
Chris@182
|
906 if (iface.flags().testFlag(QNetworkInterface::IsUp)
|
Chris@182
|
907 && !iface.flags().testFlag(QNetworkInterface::IsLoopBack)) {
|
Chris@182
|
908 for (int j=0; j<iface.addressEntries().count(); j++) {
|
jtkorhonen@28
|
909 QHostAddress tmp = iface.addressEntries().at(j).ip();
|
Chris@182
|
910 if (QAbstractSocket::IPv4Protocol == tmp.protocol()) {
|
Chris@182
|
911 ret.push_back(tmp.toString());
|
jtkorhonen@24
|
912 }
|
jtkorhonen@24
|
913 }
|
jtkorhonen@22
|
914 }
|
jtkorhonen@17
|
915 }
|
jtkorhonen@28
|
916 return ret;
|
jtkorhonen@28
|
917 }
|
jtkorhonen@17
|
918
|
Chris@120
|
919 void MainWindow::clearState()
|
Chris@120
|
920 {
|
Chris@120
|
921 foreach (Changeset *cs, currentParents) delete cs;
|
Chris@120
|
922 currentParents.clear();
|
Chris@120
|
923 foreach (Changeset *cs, currentHeads) delete cs;
|
Chris@120
|
924 currentHeads.clear();
|
Chris@120
|
925 currentBranch = "";
|
Chris@163
|
926 lastStatOutput = "";
|
Chris@163
|
927 lastRevertedFiles.clear();
|
Chris@163
|
928 mergeTargetRevision = "";
|
Chris@163
|
929 mergeCommitComment = "";
|
Chris@173
|
930 stateUnknown = true;
|
Chris@120
|
931 needNewLog = true;
|
Chris@199
|
932 if (fsWatcher) {
|
Chris@199
|
933 delete fsWatcher;
|
Chris@199
|
934 fsWatcher = 0;
|
Chris@199
|
935 }
|
Chris@120
|
936 }
|
jtkorhonen@17
|
937
|
jtkorhonen@11
|
938 void MainWindow::hgServe()
|
jtkorhonen@11
|
939 {
|
Chris@109
|
940 QStringList params;
|
Chris@109
|
941 QString msg;
|
jtkorhonen@11
|
942
|
Chris@182
|
943 QStringList addrs = listAllUpIpV4Addresses();
|
Chris@182
|
944
|
Chris@182
|
945 if (addrs.empty()) {
|
Chris@182
|
946 QMessageBox::critical
|
Chris@182
|
947 (this, tr("Serve"), tr("Failed to identify an active IPv4 address"));
|
Chris@182
|
948 return;
|
Chris@182
|
949 }
|
Chris@182
|
950
|
Chris@182
|
951 //!!! should find available port as well
|
Chris@182
|
952
|
Chris@182
|
953 QTextStream ts(&msg);
|
Chris@182
|
954 ts << QString("<qt><p>%1</p>")
|
Chris@182
|
955 .arg(tr("Running temporary server at %n address(es):", "", addrs.size()));
|
Chris@182
|
956 foreach (QString addr, addrs) {
|
Chris@182
|
957 ts << QString("<pre> http://%1:8000</pre>").arg(xmlEncode(addr));
|
Chris@182
|
958 }
|
Chris@182
|
959 ts << tr("<p>Press Close to stop the server and return.</p>");
|
Chris@182
|
960 ts.flush();
|
Chris@182
|
961
|
Chris@109
|
962 params << "serve";
|
jtkorhonen@11
|
963
|
Chris@109
|
964 runner->requestAction(HgAction(ACT_SERVE, workFolderPath, params));
|
Chris@109
|
965
|
Chris@182
|
966 QMessageBox::information(this, tr("Serve"), msg, QMessageBox::Close);
|
Chris@182
|
967
|
Chris@182
|
968 runner->killCurrentActions();
|
jtkorhonen@11
|
969 }
|
jtkorhonen@11
|
970
|
Chris@64
|
971 void MainWindow::startupDialog()
|
Chris@64
|
972 {
|
Chris@64
|
973 StartupDialog *dlg = new StartupDialog(this);
|
Chris@65
|
974 if (dlg->exec()) firstStart = false;
|
Chris@64
|
975 }
|
jtkorhonen@11
|
976
|
Chris@69
|
977 void MainWindow::open()
|
Chris@69
|
978 {
|
Chris@86
|
979 bool done = false;
|
Chris@69
|
980
|
Chris@86
|
981 while (!done) {
|
Chris@69
|
982
|
Chris@86
|
983 MultiChoiceDialog *d = new MultiChoiceDialog
|
Chris@86
|
984 (tr("Open Repository"),
|
Chris@86
|
985 tr("<qt><big>What would you like to open?</big></qt>"),
|
Chris@86
|
986 this);
|
Chris@69
|
987
|
Chris@86
|
988 d->addChoice("remote",
|
Chris@86
|
989 tr("<qt><center><img src=\":images/browser-64.png\"><br>Remote repository</center></qt>"),
|
Chris@86
|
990 tr("Open a remote Mercurial repository, by cloning from its URL into a local folder."),
|
Chris@86
|
991 MultiChoiceDialog::UrlToDirectoryArg);
|
Chris@69
|
992
|
Chris@86
|
993 d->addChoice("local",
|
Chris@86
|
994 tr("<qt><center><img src=\":images/hglogo-64.png\"><br>Local repository</center></qt>"),
|
Chris@86
|
995 tr("Open an existing local Mercurial repository."),
|
Chris@86
|
996 MultiChoiceDialog::DirectoryArg);
|
Chris@69
|
997
|
Chris@86
|
998 d->addChoice("init",
|
Chris@86
|
999 tr("<qt><center><img src=\":images/hdd_unmount-64.png\"><br>File folder</center></qt>"),
|
Chris@86
|
1000 tr("Open a local folder, by creating a Mercurial repository in it."),
|
Chris@86
|
1001 MultiChoiceDialog::DirectoryArg);
|
Chris@79
|
1002
|
Chris@86
|
1003 d->setCurrentChoice("local");
|
Chris@86
|
1004
|
Chris@86
|
1005 if (d->exec() == QDialog::Accepted) {
|
Chris@86
|
1006
|
Chris@86
|
1007 QString choice = d->getCurrentChoice();
|
Chris@86
|
1008 QString arg = d->getArgument().trimmed();
|
Chris@86
|
1009
|
Chris@86
|
1010 bool result = false;
|
Chris@86
|
1011
|
Chris@86
|
1012 if (choice == "local") {
|
Chris@86
|
1013 result = openLocal(arg);
|
Chris@86
|
1014 } else if (choice == "remote") {
|
Chris@86
|
1015 result = openRemote(arg, d->getAdditionalArgument().trimmed());
|
Chris@86
|
1016 } else if (choice == "init") {
|
Chris@86
|
1017 result = openInit(arg);
|
Chris@86
|
1018 }
|
Chris@86
|
1019
|
Chris@86
|
1020 if (result) {
|
Chris@86
|
1021 enableDisableActions();
|
Chris@120
|
1022 clearState();
|
Chris@109
|
1023 hgQueryPaths();
|
Chris@91
|
1024 done = true;
|
Chris@91
|
1025 }
|
Chris@86
|
1026
|
Chris@86
|
1027 } else {
|
Chris@86
|
1028
|
Chris@86
|
1029 // cancelled
|
Chris@86
|
1030 done = true;
|
Chris@69
|
1031 }
|
Chris@79
|
1032
|
Chris@86
|
1033 delete d;
|
Chris@69
|
1034 }
|
Chris@69
|
1035 }
|
Chris@69
|
1036
|
Chris@182
|
1037 void MainWindow::changeRemoteRepo()
|
Chris@182
|
1038 {
|
Chris@183
|
1039 // This will involve rewriting the local .hgrc
|
Chris@183
|
1040
|
Chris@184
|
1041 QDir hgDir(workFolderPath + "/.hg");
|
Chris@184
|
1042 if (!hgDir.exists()) {
|
Chris@184
|
1043 //!!! visible error!
|
Chris@184
|
1044 return;
|
Chris@184
|
1045 }
|
Chris@184
|
1046
|
Chris@183
|
1047 QFileInfo hgrc(workFolderPath + "/.hg/hgrc");
|
Chris@184
|
1048 if (hgrc.exists() && !hgrc.isWritable()) {
|
Chris@183
|
1049 //!!! visible error!
|
Chris@183
|
1050 return;
|
Chris@183
|
1051 }
|
Chris@183
|
1052
|
Chris@183
|
1053 MultiChoiceDialog *d = new MultiChoiceDialog
|
Chris@183
|
1054 (tr("Change Remote Location"),
|
Chris@183
|
1055 tr("<qt><big>Change the remote location</big></qt>"),
|
Chris@183
|
1056 this);
|
Chris@183
|
1057
|
Chris@183
|
1058 d->addChoice("remote",
|
Chris@183
|
1059 tr("<qt><center><img src=\":images/browser-64.png\"><br>Remote repository</center></qt>"),
|
Chris@183
|
1060 tr("Provide a new URL to use for push and pull actions from the current local repository."),
|
Chris@183
|
1061 MultiChoiceDialog::UrlArg);
|
Chris@183
|
1062
|
Chris@183
|
1063 if (d->exec() == QDialog::Accepted) {
|
Chris@210
|
1064
|
Chris@210
|
1065 // New block to ensure QSettings is deleted before
|
Chris@210
|
1066 // hgQueryPaths called. NB use of absoluteFilePath instead of
|
Chris@210
|
1067 // canonicalFilePath, which would fail if the file did not yet
|
Chris@210
|
1068 // exist
|
Chris@210
|
1069
|
Chris@210
|
1070 {
|
Chris@210
|
1071 QSettings s(hgrc.absoluteFilePath(), QSettings::IniFormat);
|
Chris@210
|
1072 s.beginGroup("paths");
|
Chris@210
|
1073 s.setValue("default", d->getArgument());
|
Chris@210
|
1074 }
|
Chris@210
|
1075
|
Chris@186
|
1076 stateUnknown = true;
|
Chris@183
|
1077 hgQueryPaths();
|
Chris@183
|
1078 }
|
Chris@183
|
1079
|
Chris@183
|
1080 delete d;
|
Chris@182
|
1081 }
|
Chris@182
|
1082
|
Chris@145
|
1083 void MainWindow::open(QString local)
|
Chris@145
|
1084 {
|
Chris@145
|
1085 if (openLocal(local)) {
|
Chris@145
|
1086 enableDisableActions();
|
Chris@145
|
1087 clearState();
|
Chris@145
|
1088 hgQueryPaths();
|
Chris@145
|
1089 }
|
Chris@145
|
1090 }
|
Chris@145
|
1091
|
Chris@79
|
1092 bool MainWindow::complainAboutFilePath(QString arg)
|
Chris@79
|
1093 {
|
Chris@79
|
1094 QMessageBox::critical
|
Chris@79
|
1095 (this, tr("File chosen"),
|
Chris@84
|
1096 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
|
1097 return false;
|
Chris@79
|
1098 }
|
Chris@79
|
1099
|
Chris@79
|
1100 bool MainWindow::complainAboutUnknownFolder(QString arg)
|
Chris@79
|
1101 {
|
Chris@79
|
1102 QMessageBox::critical
|
Chris@79
|
1103 (this, tr("Folder does not exist"),
|
Chris@84
|
1104 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
|
1105 return false;
|
Chris@84
|
1106 }
|
Chris@84
|
1107
|
Chris@84
|
1108 bool MainWindow::complainAboutInitInRepo(QString arg)
|
Chris@84
|
1109 {
|
Chris@84
|
1110 QMessageBox::critical
|
Chris@84
|
1111 (this, tr("Path is in existing repository"),
|
Chris@84
|
1112 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
|
1113 return false;
|
Chris@84
|
1114 }
|
Chris@84
|
1115
|
Chris@84
|
1116 bool MainWindow::complainAboutInitFile(QString arg)
|
Chris@84
|
1117 {
|
Chris@84
|
1118 QMessageBox::critical
|
Chris@84
|
1119 (this, tr("Path is a file"),
|
Chris@84
|
1120 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
|
1121 return false;
|
Chris@84
|
1122 }
|
Chris@84
|
1123
|
Chris@84
|
1124 bool MainWindow::complainAboutCloneToExisting(QString arg)
|
Chris@84
|
1125 {
|
Chris@84
|
1126 QMessageBox::critical
|
Chris@84
|
1127 (this, tr("Path is in existing repository"),
|
Chris@84
|
1128 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 new folder name for the local repository.</qt>").arg(xmlEncode(arg)));
|
Chris@84
|
1129 return false;
|
Chris@84
|
1130 }
|
Chris@84
|
1131
|
Chris@84
|
1132 bool MainWindow::complainAboutCloneToFile(QString arg)
|
Chris@84
|
1133 {
|
Chris@84
|
1134 QMessageBox::critical
|
Chris@84
|
1135 (this, tr("Path is a file"),
|
Chris@84
|
1136 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
|
1137 return false;
|
Chris@84
|
1138 }
|
Chris@84
|
1139
|
Chris@84
|
1140 bool MainWindow::complainAboutCloneToExistingFolder(QString arg)
|
Chris@84
|
1141 {
|
Chris@84
|
1142 QMessageBox::critical
|
Chris@84
|
1143 (this, tr("Folder exists"),
|
Chris@84
|
1144 tr("<qt><b>Local folder already exists</b><br><br>You asked to open a remote repository by cloning it to the local path \"%1\".<br>This is the path of an existing folder.<br>Please provide a new folder name for the local repository.</qt>").arg(xmlEncode(arg)));
|
Chris@79
|
1145 return false;
|
Chris@79
|
1146 }
|
Chris@79
|
1147
|
Chris@79
|
1148 bool MainWindow::askToOpenParentRepo(QString arg, QString parent)
|
Chris@79
|
1149 {
|
Chris@79
|
1150 return (QMessageBox::question
|
Chris@84
|
1151 (this, tr("Path is inside a repository"),
|
Chris@86
|
1152 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
|
1153 .arg(xmlEncode(arg)).arg(xmlEncode(parent)),
|
Chris@79
|
1154 QMessageBox::Ok | QMessageBox::Cancel,
|
Chris@79
|
1155 QMessageBox::Ok)
|
Chris@79
|
1156 == QMessageBox::Ok);
|
Chris@79
|
1157 }
|
Chris@79
|
1158
|
Chris@79
|
1159 bool MainWindow::askToInitExisting(QString arg)
|
Chris@79
|
1160 {
|
Chris@79
|
1161 return (QMessageBox::question
|
Chris@84
|
1162 (this, tr("Folder has no repository"),
|
Chris@84
|
1163 tr("<qt><b>Initialise a repository here?</b><br><br>You asked to open \"%1\".<br>This folder does not contain a Mercurial repository.<br><br>Would you like to initialise a repository here?</qt>")
|
Chris@79
|
1164 .arg(xmlEncode(arg)),
|
Chris@79
|
1165 QMessageBox::Ok | QMessageBox::Cancel,
|
Chris@79
|
1166 QMessageBox::Ok)
|
Chris@79
|
1167 == QMessageBox::Ok);
|
Chris@79
|
1168 }
|
Chris@79
|
1169
|
Chris@79
|
1170 bool MainWindow::askToInitNew(QString arg)
|
Chris@79
|
1171 {
|
Chris@79
|
1172 return (QMessageBox::question
|
Chris@84
|
1173 (this, tr("Folder does not exist"),
|
Chris@84
|
1174 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
|
1175 .arg(xmlEncode(arg)),
|
Chris@84
|
1176 QMessageBox::Ok | QMessageBox::Cancel,
|
Chris@84
|
1177 QMessageBox::Ok)
|
Chris@84
|
1178 == QMessageBox::Ok);
|
Chris@84
|
1179 }
|
Chris@84
|
1180
|
Chris@84
|
1181 bool MainWindow::askToOpenInsteadOfInit(QString arg)
|
Chris@84
|
1182 {
|
Chris@84
|
1183 return (QMessageBox::question
|
Chris@84
|
1184 (this, tr("Repository exists"),
|
Chris@84
|
1185 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
|
1186 .arg(xmlEncode(arg)),
|
Chris@79
|
1187 QMessageBox::Ok | QMessageBox::Cancel,
|
Chris@79
|
1188 QMessageBox::Ok)
|
Chris@79
|
1189 == QMessageBox::Ok);
|
Chris@79
|
1190 }
|
Chris@79
|
1191
|
Chris@79
|
1192 bool MainWindow::openLocal(QString local)
|
Chris@79
|
1193 {
|
Chris@79
|
1194 DEBUG << "open " << local << endl;
|
Chris@79
|
1195
|
Chris@79
|
1196 FolderStatus status = getFolderStatus(local);
|
Chris@79
|
1197 QString containing = getContainingRepoFolder(local);
|
Chris@79
|
1198
|
Chris@79
|
1199 switch (status) {
|
Chris@79
|
1200
|
Chris@79
|
1201 case FolderHasRepo:
|
Chris@79
|
1202 // fine
|
Chris@79
|
1203 break;
|
Chris@79
|
1204
|
Chris@79
|
1205 case FolderExists:
|
Chris@79
|
1206 if (containing != "") {
|
Chris@79
|
1207 if (!askToOpenParentRepo(local, containing)) return false;
|
Chris@84
|
1208 local = containing;
|
Chris@79
|
1209 } else {
|
Chris@86
|
1210 //!!! No -- this is likely to happen far more by accident
|
Chris@86
|
1211 // than because the user actually wanted to init something.
|
Chris@86
|
1212 // Don't ask, just politely reject.
|
Chris@79
|
1213 if (!askToInitExisting(local)) return false;
|
Chris@79
|
1214 return openInit(local);
|
Chris@79
|
1215 }
|
Chris@79
|
1216 break;
|
Chris@79
|
1217
|
Chris@79
|
1218 case FolderParentExists:
|
Chris@79
|
1219 if (containing != "") {
|
Chris@79
|
1220 if (!askToOpenParentRepo(local, containing)) return false;
|
Chris@84
|
1221 local = containing;
|
Chris@79
|
1222 } else {
|
Chris@79
|
1223 if (!askToInitNew(local)) return false;
|
Chris@79
|
1224 return openInit(local);
|
Chris@79
|
1225 }
|
Chris@79
|
1226 break;
|
Chris@79
|
1227
|
Chris@79
|
1228 case FolderUnknown:
|
Chris@84
|
1229 if (containing != "") {
|
Chris@84
|
1230 if (!askToOpenParentRepo(local, containing)) return false;
|
Chris@84
|
1231 local = containing;
|
Chris@84
|
1232 } else {
|
Chris@84
|
1233 return complainAboutUnknownFolder(local);
|
Chris@84
|
1234 }
|
Chris@84
|
1235 break;
|
Chris@79
|
1236
|
Chris@79
|
1237 case FolderIsFile:
|
Chris@79
|
1238 return complainAboutFilePath(local);
|
Chris@79
|
1239 }
|
Chris@79
|
1240
|
Chris@79
|
1241 workFolderPath = local;
|
Chris@79
|
1242 remoteRepoPath = "";
|
Chris@79
|
1243 return true;
|
Chris@79
|
1244 }
|
Chris@79
|
1245
|
Chris@79
|
1246 bool MainWindow::openRemote(QString remote, QString local)
|
Chris@79
|
1247 {
|
Chris@79
|
1248 DEBUG << "clone " << remote << " to " << local << endl;
|
Chris@84
|
1249
|
Chris@84
|
1250 FolderStatus status = getFolderStatus(local);
|
Chris@84
|
1251 QString containing = getContainingRepoFolder(local);
|
Chris@84
|
1252
|
Chris@84
|
1253 DEBUG << "status = " << status << ", containing = " << containing << endl;
|
Chris@84
|
1254
|
Chris@84
|
1255 if (status == FolderHasRepo || containing != "") {
|
Chris@84
|
1256 return complainAboutCloneToExisting(local);
|
Chris@84
|
1257 }
|
Chris@84
|
1258
|
Chris@84
|
1259 if (status == FolderIsFile) {
|
Chris@84
|
1260 return complainAboutCloneToFile(local);
|
Chris@84
|
1261 }
|
Chris@84
|
1262
|
Chris@84
|
1263 if (status == FolderUnknown) {
|
Chris@84
|
1264 return complainAboutUnknownFolder(local);
|
Chris@84
|
1265 }
|
Chris@84
|
1266
|
Chris@84
|
1267 if (status == FolderExists) {
|
Chris@84
|
1268 //!!! we can do better than this surely?
|
Chris@84
|
1269 return complainAboutCloneToExistingFolder(local);
|
Chris@84
|
1270 }
|
Chris@84
|
1271
|
Chris@84
|
1272 workFolderPath = local;
|
Chris@84
|
1273 remoteRepoPath = remote;
|
Chris@84
|
1274 hgCloneFromRemote();
|
Chris@84
|
1275
|
Chris@79
|
1276 return true;
|
Chris@79
|
1277 }
|
Chris@79
|
1278
|
Chris@84
|
1279 bool MainWindow::openInit(QString local)
|
Chris@79
|
1280 {
|
Chris@84
|
1281 DEBUG << "openInit " << local << endl;
|
Chris@84
|
1282
|
Chris@84
|
1283 FolderStatus status = getFolderStatus(local);
|
Chris@84
|
1284 QString containing = getContainingRepoFolder(local);
|
Chris@84
|
1285
|
Chris@84
|
1286 DEBUG << "status = " << status << ", containing = " << containing << endl;
|
Chris@84
|
1287
|
Chris@84
|
1288 if (status == FolderHasRepo) {
|
Chris@84
|
1289 if (!askToOpenInsteadOfInit(local)) return false;
|
Chris@84
|
1290 }
|
Chris@84
|
1291
|
Chris@84
|
1292 if (containing != "") {
|
Chris@84
|
1293 return complainAboutInitInRepo(local);
|
Chris@84
|
1294 }
|
Chris@84
|
1295
|
Chris@84
|
1296 if (status == FolderIsFile) {
|
Chris@84
|
1297 return complainAboutInitFile(local);
|
Chris@84
|
1298 }
|
Chris@84
|
1299
|
Chris@84
|
1300 if (status == FolderUnknown) {
|
Chris@84
|
1301 return complainAboutUnknownFolder(local);
|
Chris@84
|
1302 }
|
Chris@84
|
1303
|
Chris@84
|
1304 workFolderPath = local;
|
Chris@84
|
1305 remoteRepoPath = "";
|
Chris@84
|
1306 hgInit();
|
Chris@79
|
1307 return true;
|
Chris@79
|
1308 }
|
Chris@79
|
1309
|
jtkorhonen@0
|
1310 void MainWindow::settings()
|
jtkorhonen@0
|
1311 {
|
jtkorhonen@0
|
1312 SettingsDialog *settingsDlg = new SettingsDialog(this);
|
jtkorhonen@0
|
1313 settingsDlg->exec();
|
jtkorhonen@0
|
1314 }
|
jtkorhonen@0
|
1315
|
jtkorhonen@2
|
1316 #define STDOUT_NEEDS_BIG_WINDOW 512
|
jtkorhonen@2
|
1317 #define SMALL_WND_W 500
|
jtkorhonen@2
|
1318 #define SMALL_WND_H 300
|
jtkorhonen@2
|
1319
|
jtkorhonen@2
|
1320 #define BIG_WND_W 1024
|
jtkorhonen@2
|
1321 #define BIG_WND_H 768
|
jtkorhonen@2
|
1322
|
jtkorhonen@2
|
1323
|
jtkorhonen@2
|
1324 void MainWindow::presentLongStdoutToUser(QString stdo)
|
jtkorhonen@0
|
1325 {
|
jtkorhonen@2
|
1326 if (!stdo.isEmpty())
|
jtkorhonen@2
|
1327 {
|
jtkorhonen@2
|
1328 QDialog dlg;
|
jtkorhonen@0
|
1329
|
jtkorhonen@2
|
1330 if (stdo.length() > STDOUT_NEEDS_BIG_WINDOW)
|
jtkorhonen@2
|
1331 {
|
jtkorhonen@2
|
1332 dlg.setMinimumWidth(BIG_WND_W);
|
jtkorhonen@2
|
1333 dlg.setMinimumHeight(BIG_WND_H);
|
jtkorhonen@2
|
1334 }
|
jtkorhonen@2
|
1335 else
|
jtkorhonen@2
|
1336 {
|
jtkorhonen@2
|
1337 dlg.setMinimumWidth(SMALL_WND_W);
|
jtkorhonen@2
|
1338 dlg.setMinimumHeight(SMALL_WND_H);
|
jtkorhonen@2
|
1339 }
|
jtkorhonen@0
|
1340
|
jtkorhonen@2
|
1341 QVBoxLayout *box = new QVBoxLayout;
|
jtkorhonen@2
|
1342 QListWidget *list = new QListWidget;
|
jtkorhonen@2
|
1343 list-> addItems(stdo.split("\n"));
|
jtkorhonen@2
|
1344 QPushButton *btn = new QPushButton(tr("Ok"));
|
jtkorhonen@2
|
1345 connect(btn, SIGNAL(clicked()), &dlg, SLOT(accept()));
|
jtkorhonen@0
|
1346
|
jtkorhonen@2
|
1347 box -> addWidget(list);
|
jtkorhonen@2
|
1348 box -> addWidget(btn);
|
jtkorhonen@2
|
1349 dlg.setLayout(box);
|
jtkorhonen@2
|
1350
|
jtkorhonen@2
|
1351 dlg.exec();
|
jtkorhonen@2
|
1352 }
|
jtkorhonen@2
|
1353 else
|
jtkorhonen@2
|
1354 {
|
Chris@98
|
1355 QMessageBox::information(this, tr("EasyMercurial"), tr("Mercurial command did not return any output."));
|
jtkorhonen@2
|
1356 }
|
jtkorhonen@0
|
1357 }
|
jtkorhonen@0
|
1358
|
Chris@90
|
1359 void MainWindow::updateFileSystemWatcher()
|
Chris@90
|
1360 {
|
Chris@199
|
1361 bool justCreated = false;
|
Chris@199
|
1362 if (!fsWatcher) {
|
Chris@199
|
1363 fsWatcher = new QFileSystemWatcher();
|
Chris@199
|
1364 justCreated = true;
|
Chris@199
|
1365 }
|
Chris@199
|
1366
|
Chris@199
|
1367 // QFileSystemWatcher will refuse to add a file or directory to
|
Chris@199
|
1368 // its watch list that it is already watching -- fine, that's what
|
Chris@199
|
1369 // we want -- but it prints a warning when this happens, which is
|
Chris@199
|
1370 // annoying because it would be the normal case for us. So we'll
|
Chris@199
|
1371 // check for duplicates ourselves.
|
Chris@199
|
1372 QSet<QString> alreadyWatched;
|
Chris@199
|
1373 QStringList dl(fsWatcher->directories());
|
Chris@199
|
1374 foreach (QString d, dl) alreadyWatched.insert(d);
|
Chris@199
|
1375
|
Chris@90
|
1376 std::deque<QString> pending;
|
Chris@90
|
1377 pending.push_back(workFolderPath);
|
Chris@199
|
1378
|
Chris@90
|
1379 while (!pending.empty()) {
|
Chris@199
|
1380
|
Chris@90
|
1381 QString path = pending.front();
|
Chris@90
|
1382 pending.pop_front();
|
Chris@199
|
1383 if (!alreadyWatched.contains(path)) {
|
Chris@199
|
1384 fsWatcher->addPath(path);
|
Chris@199
|
1385 DEBUG << "Added to file system watcher: " << path << endl;
|
Chris@199
|
1386 }
|
Chris@199
|
1387
|
Chris@90
|
1388 QDir d(path);
|
Chris@90
|
1389 if (d.exists()) {
|
Chris@199
|
1390 d.setFilter(QDir::Dirs | QDir::NoDotAndDotDot |
|
Chris@199
|
1391 QDir::Readable | QDir::NoSymLinks);
|
Chris@90
|
1392 foreach (QString entry, d.entryList()) {
|
Chris@199
|
1393 if (entry.startsWith('.')) continue;
|
Chris@90
|
1394 QString entryPath = d.absoluteFilePath(entry);
|
Chris@90
|
1395 pending.push_back(entryPath);
|
Chris@90
|
1396 }
|
Chris@90
|
1397 }
|
Chris@90
|
1398 }
|
Chris@199
|
1399
|
Chris@199
|
1400 if (justCreated) {
|
Chris@199
|
1401 connect(fsWatcher, SIGNAL(directoryChanged(QString)),
|
Chris@199
|
1402 this, SLOT(fsDirectoryChanged(QString)));
|
Chris@199
|
1403 connect(fsWatcher, SIGNAL(fileChanged(QString)),
|
Chris@199
|
1404 this, SLOT(fsFileChanged(QString)));
|
Chris@199
|
1405 }
|
Chris@90
|
1406 }
|
Chris@90
|
1407
|
Chris@122
|
1408 void MainWindow::fsDirectoryChanged(QString d)
|
Chris@90
|
1409 {
|
Chris@122
|
1410 DEBUG << "MainWindow::fsDirectoryChanged " << d << endl;
|
Chris@90
|
1411 hgStat();
|
Chris@90
|
1412 }
|
Chris@90
|
1413
|
Chris@122
|
1414 void MainWindow::fsFileChanged(QString f)
|
Chris@90
|
1415 {
|
Chris@122
|
1416 DEBUG << "MainWindow::fsFileChanged " << f << endl;
|
Chris@90
|
1417 hgStat();
|
Chris@90
|
1418 }
|
Chris@90
|
1419
|
Chris@125
|
1420 QString MainWindow::format3(QString head, QString intro, QString code)
|
Chris@125
|
1421 {
|
Chris@196
|
1422 code = xmlEncode(code).replace("\n", "<br>")
|
Chris@196
|
1423 #ifndef Q_OS_WIN32
|
Chris@196
|
1424 // The hard hyphen comes out funny on Windows
|
Chris@196
|
1425 .replace("-", "‑")
|
Chris@196
|
1426 #endif
|
Chris@196
|
1427 .replace(" ", " ");
|
Chris@125
|
1428 if (intro == "") {
|
Chris@168
|
1429 return QString("<qt><h3>%1</h3><p><code>%2</code></p>")
|
Chris@168
|
1430 .arg(head).arg(code);
|
Chris@126
|
1431 } else if (code == "") {
|
Chris@126
|
1432 return QString("<qt><h3>%1</h3><p>%2</p>")
|
Chris@126
|
1433 .arg(head).arg(intro);
|
Chris@125
|
1434 } else {
|
Chris@168
|
1435 return QString("<qt><h3>%1</h3><p>%2</p><p><code>%3</code></p>")
|
Chris@168
|
1436 .arg(head).arg(intro).arg(code);
|
Chris@125
|
1437 }
|
Chris@125
|
1438 }
|
Chris@125
|
1439
|
Chris@120
|
1440 void MainWindow::showIncoming(QString output)
|
Chris@120
|
1441 {
|
Chris@120
|
1442 runner->hide();
|
Chris@125
|
1443 IncomingDialog *d = new IncomingDialog(this, output);
|
Chris@125
|
1444 d->exec();
|
Chris@125
|
1445 delete d;
|
Chris@125
|
1446 }
|
Chris@125
|
1447
|
Chris@125
|
1448 int MainWindow::extractChangeCount(QString text)
|
Chris@125
|
1449 {
|
Chris@125
|
1450 QRegExp re("added (\\d+) ch\\w+ with (\\d+) ch\\w+ to (\\d+) f\\w+");
|
Chris@125
|
1451 if (re.indexIn(text) >= 0) {
|
Chris@125
|
1452 return re.cap(1).toInt();
|
Chris@125
|
1453 } else if (text.contains("no changes")) {
|
Chris@125
|
1454 return 0;
|
Chris@125
|
1455 } else {
|
Chris@125
|
1456 return -1; // unknown
|
Chris@125
|
1457 }
|
Chris@120
|
1458 }
|
Chris@120
|
1459
|
Chris@120
|
1460 void MainWindow::showPushResult(QString output)
|
Chris@120
|
1461 {
|
Chris@125
|
1462 QString report;
|
Chris@125
|
1463 int n = extractChangeCount(output);
|
Chris@125
|
1464 if (n > 0) {
|
Chris@125
|
1465 report = tr("Pushed %n changeset(s)", "", n);
|
Chris@125
|
1466 } else if (n == 0) {
|
Chris@125
|
1467 report = tr("No changes to push");
|
Chris@125
|
1468 } else {
|
Chris@125
|
1469 report = tr("Push complete");
|
Chris@125
|
1470 }
|
Chris@125
|
1471 report = format3(report, tr("The push command output was:"), output);
|
Chris@120
|
1472 runner->hide();
|
Chris@125
|
1473 QMessageBox::information(this, "Push complete", report);
|
Chris@120
|
1474 }
|
Chris@120
|
1475
|
Chris@120
|
1476 void MainWindow::showPullResult(QString output)
|
Chris@120
|
1477 {
|
Chris@125
|
1478 QString report;
|
Chris@125
|
1479 int n = extractChangeCount(output);
|
Chris@125
|
1480 if (n > 0) {
|
Chris@125
|
1481 report = tr("Pulled %n changeset(s)", "", n);
|
Chris@125
|
1482 } else if (n == 0) {
|
Chris@125
|
1483 report = tr("No changes to pull");
|
Chris@125
|
1484 } else {
|
Chris@125
|
1485 report = tr("Pull complete");
|
Chris@125
|
1486 }
|
Chris@125
|
1487 report = format3(report, tr("The pull command output was:"), output);
|
Chris@120
|
1488 runner->hide();
|
Chris@125
|
1489
|
Chris@125
|
1490 //!!! and something about updating
|
Chris@125
|
1491
|
Chris@125
|
1492 QMessageBox::information(this, "Pull complete", report);
|
Chris@120
|
1493 }
|
Chris@120
|
1494
|
Chris@174
|
1495 void MainWindow::reportNewRemoteHeads(QString output)
|
Chris@174
|
1496 {
|
Chris@174
|
1497 bool headsAreLocal = false;
|
Chris@174
|
1498
|
Chris@174
|
1499 if (currentParents.size() == 1) {
|
Chris@174
|
1500 int currentBranchHeads = 0;
|
Chris@174
|
1501 bool parentIsHead = false;
|
Chris@174
|
1502 Changeset *parent = currentParents[0];
|
Chris@174
|
1503 foreach (Changeset *head, currentHeads) {
|
Chris@174
|
1504 if (head->isOnBranch(currentBranch)) {
|
Chris@174
|
1505 ++currentBranchHeads;
|
Chris@174
|
1506 }
|
Chris@174
|
1507 if (parent->id() == head->id()) {
|
Chris@174
|
1508 parentIsHead = true;
|
Chris@174
|
1509 }
|
Chris@174
|
1510 }
|
Chris@174
|
1511 if (currentBranchHeads == 2 && parentIsHead) {
|
Chris@174
|
1512 headsAreLocal = true;
|
Chris@174
|
1513 }
|
Chris@174
|
1514 }
|
Chris@174
|
1515
|
Chris@174
|
1516 if (headsAreLocal) {
|
Chris@174
|
1517 QMessageBox::warning
|
Chris@174
|
1518 (this, tr("Push failed"),
|
Chris@174
|
1519 format3(tr("Push failed"),
|
Chris@174
|
1520 tr("Your local repository could not be pushed to the remote repository.<br><br>You may need to merge the changes locally first.<br><br>The output of the push command was:"),
|
Chris@174
|
1521 output));
|
Chris@174
|
1522 } else {
|
Chris@174
|
1523 QMessageBox::warning
|
Chris@174
|
1524 (this, tr("Push failed"),
|
Chris@174
|
1525 format3(tr("Push failed"),
|
Chris@174
|
1526 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.<br><br>The output of the push command was:"),
|
Chris@174
|
1527 output));
|
Chris@174
|
1528 }
|
Chris@174
|
1529 }
|
Chris@174
|
1530
|
Chris@143
|
1531 void MainWindow::commandFailed(HgAction action, QString output)
|
Chris@62
|
1532 {
|
Chris@62
|
1533 DEBUG << "MainWindow::commandFailed" << endl;
|
Chris@74
|
1534
|
Chris@210
|
1535 QString setstr;
|
Chris@210
|
1536 #ifdef Q_OS_MAC
|
Chris@210
|
1537 setstr = tr("Preferences");
|
Chris@210
|
1538 #else
|
Chris@210
|
1539 setstr = tr("Settings");
|
Chris@210
|
1540 #endif
|
Chris@210
|
1541
|
Chris@113
|
1542 // Some commands we just have to ignore bad return values from:
|
Chris@113
|
1543
|
Chris@113
|
1544 switch(action.action) {
|
Chris@113
|
1545 case ACT_NONE:
|
Chris@113
|
1546 // uh huh
|
Chris@113
|
1547 return;
|
Chris@175
|
1548 case ACT_TEST_HG:
|
Chris@175
|
1549 QMessageBox::warning
|
Chris@175
|
1550 (this, tr("Failed to run Mercurial"),
|
Chris@175
|
1551 format3(tr("Failed to run Mercurial"),
|
Chris@210
|
1552 tr("The Mercurial program either could not be found or failed to run.<br>Check that the Mercurial program path is correct in %1.<br><br>%2").arg(setstr).arg(output == "" ? QString("") : tr("The test command said:")),
|
Chris@200
|
1553 output));
|
Chris@200
|
1554 settings();
|
Chris@200
|
1555 return;
|
Chris@200
|
1556 case ACT_TEST_HG_EXT:
|
Chris@200
|
1557 QMessageBox::warning
|
Chris@200
|
1558 (this, tr("Failed to run Mercurial"),
|
Chris@200
|
1559 format3(tr("Failed to run Mercurial with extension enabled"),
|
Chris@210
|
1560 tr("The Mercurial program failed to run with the EasyMercurial interaction extension enabled.<br>This may indicate an installation problem with EasyMercurial.<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 may not work if you do this.<br><br>%2").arg(setstr).arg(output == "" ? QString("") : tr("The test command said:")),
|
Chris@175
|
1561 output));
|
Chris@175
|
1562 settings();
|
Chris@175
|
1563 return;
|
Chris@113
|
1564 case ACT_INCOMING:
|
Chris@211
|
1565 // returns non-zero code and no output if the check was
|
Chris@211
|
1566 // successful but there are no changes pending
|
Chris@211
|
1567 if (output.trimmed() == "") {
|
Chris@211
|
1568 showIncoming("");
|
Chris@211
|
1569 return;
|
Chris@211
|
1570 }
|
Chris@211
|
1571 break;
|
Chris@162
|
1572 case ACT_QUERY_HEADS:
|
Chris@162
|
1573 // fails if repo is empty; we don't care (if there's a genuine
|
Chris@202
|
1574 // problem, something else will fail too). Pretend it
|
Chris@202
|
1575 // succeeded, so that any further actions that are contingent
|
Chris@202
|
1576 // on the success of the heads query get carried out properly.
|
Chris@202
|
1577 commandCompleted(action, "");
|
Chris@162
|
1578 return;
|
Chris@113
|
1579 case ACT_FOLDERDIFF:
|
Chris@113
|
1580 case ACT_CHGSETDIFF:
|
Chris@113
|
1581 // external program, unlikely to be anything useful in stderr
|
Chris@113
|
1582 // and some return with failure codes when something as basic
|
Chris@113
|
1583 // as the user closing the window via the wm happens
|
Chris@113
|
1584 return;
|
Chris@174
|
1585 case ACT_PUSH:
|
Chris@174
|
1586 if (output.contains("creates new remote heads")) {
|
Chris@174
|
1587 reportNewRemoteHeads(output);
|
Chris@174
|
1588 return;
|
Chris@174
|
1589 }
|
Chris@199
|
1590 case ACT_STAT:
|
Chris@199
|
1591 if (fsWatcher) fsWatcher->blockSignals(false);
|
Chris@199
|
1592 break; // go on and report
|
Chris@113
|
1593 default:
|
Chris@114
|
1594 break;
|
Chris@113
|
1595 }
|
Chris@113
|
1596
|
Chris@113
|
1597 QString command = action.executable;
|
Chris@113
|
1598 if (command == "") command = "hg";
|
Chris@113
|
1599 foreach (QString arg, action.params) {
|
Chris@113
|
1600 command += " " + arg;
|
Chris@113
|
1601 }
|
Chris@113
|
1602
|
Chris@113
|
1603 QString message = tr("<qt><h3>Command failed</h3>"
|
Chris@113
|
1604 "<p>The following command failed:</p>"
|
Chris@113
|
1605 "<code>%1</code>"
|
Chris@113
|
1606 "%2</qt>")
|
Chris@113
|
1607 .arg(command)
|
Chris@143
|
1608 .arg((output.trimmed() != "") ?
|
Chris@113
|
1609 tr("<p>Its output said:</p><code>%1</code>")
|
Chris@143
|
1610 .arg(xmlEncode(output.left(800))
|
Chris@113
|
1611 .replace("\n", "<br>"))
|
Chris@113
|
1612 : "");
|
Chris@113
|
1613
|
Chris@113
|
1614 QMessageBox::warning(this, tr("Command failed"), message);
|
Chris@62
|
1615 }
|
Chris@62
|
1616
|
Chris@109
|
1617 void MainWindow::commandCompleted(HgAction completedAction, QString output)
|
jtkorhonen@0
|
1618 {
|
Chris@109
|
1619 HGACTIONS action = completedAction.action;
|
Chris@109
|
1620
|
Chris@109
|
1621 if (action == ACT_NONE) return;
|
Chris@109
|
1622
|
Chris@150
|
1623 bool headsChanged = false;
|
Chris@150
|
1624 QStringList oldHeadIds;
|
Chris@150
|
1625
|
Chris@150
|
1626 switch (action) {
|
Chris@109
|
1627
|
Chris@175
|
1628 case ACT_TEST_HG:
|
Chris@175
|
1629 break;
|
Chris@175
|
1630
|
Chris@200
|
1631 case ACT_TEST_HG_EXT:
|
Chris@200
|
1632 break;
|
Chris@200
|
1633
|
Chris@109
|
1634 case ACT_QUERY_PATHS:
|
jtkorhonen@0
|
1635 {
|
Chris@109
|
1636 DEBUG << "stdout is " << output << endl;
|
Chris@109
|
1637 LogParser lp(output, "=");
|
Chris@109
|
1638 LogList ll = lp.parse();
|
Chris@109
|
1639 DEBUG << ll.size() << " results" << endl;
|
Chris@109
|
1640 if (!ll.empty()) {
|
Chris@109
|
1641 remoteRepoPath = lp.parse()[0]["default"].trimmed();
|
Chris@109
|
1642 DEBUG << "Set remote path to " << remoteRepoPath << endl;
|
Chris@210
|
1643 } else {
|
Chris@210
|
1644 remoteRepoPath = "";
|
Chris@109
|
1645 }
|
Chris@109
|
1646 MultiChoiceDialog::addRecentArgument("local", workFolderPath);
|
Chris@109
|
1647 MultiChoiceDialog::addRecentArgument("remote", remoteRepoPath);
|
Chris@109
|
1648 hgTabs->setWorkFolderAndRepoNames(workFolderPath, remoteRepoPath);
|
Chris@109
|
1649 break;
|
Chris@109
|
1650 }
|
jtkorhonen@0
|
1651
|
Chris@109
|
1652 case ACT_QUERY_BRANCH:
|
Chris@109
|
1653 currentBranch = output.trimmed();
|
Chris@109
|
1654 break;
|
jtkorhonen@0
|
1655
|
Chris@109
|
1656 case ACT_STAT:
|
Chris@163
|
1657 lastStatOutput = output;
|
Chris@109
|
1658 updateFileSystemWatcher();
|
Chris@199
|
1659 if (fsWatcher) fsWatcher->blockSignals(false);
|
Chris@109
|
1660 break;
|
Chris@163
|
1661
|
Chris@163
|
1662 case ACT_RESOLVE_LIST:
|
Chris@163
|
1663 if (output != "") {
|
Chris@163
|
1664 // Remove lines beginning with R (they are resolved,
|
Chris@163
|
1665 // and the file stat parser treats R as removed)
|
Chris@163
|
1666 QStringList outList = output.split('\n');
|
Chris@163
|
1667 QStringList winnowed;
|
Chris@163
|
1668 foreach (QString line, outList) {
|
Chris@163
|
1669 if (!line.startsWith("R ")) winnowed.push_back(line);
|
Chris@163
|
1670 }
|
Chris@163
|
1671 output = winnowed.join("\n");
|
Chris@163
|
1672 }
|
Chris@163
|
1673 DEBUG << "lastStatOutput = " << lastStatOutput << endl;
|
Chris@199
|
1674 DEBUG << "resolve output = " << output << endl;
|
Chris@163
|
1675 hgTabs->updateWorkFolderFileList(lastStatOutput + output);
|
Chris@163
|
1676 break;
|
Chris@163
|
1677
|
Chris@163
|
1678 case ACT_RESOLVE_MARK:
|
Chris@163
|
1679 shouldHgStat = true;
|
Chris@163
|
1680 break;
|
Chris@109
|
1681
|
Chris@109
|
1682 case ACT_INCOMING:
|
Chris@120
|
1683 showIncoming(output);
|
Chris@120
|
1684 break;
|
Chris@120
|
1685
|
Chris@109
|
1686 case ACT_ANNOTATE:
|
Chris@109
|
1687 presentLongStdoutToUser(output);
|
Chris@109
|
1688 shouldHgStat = true;
|
Chris@109
|
1689 break;
|
Chris@109
|
1690
|
Chris@109
|
1691 case ACT_PULL:
|
Chris@120
|
1692 showPullResult(output);
|
Chris@109
|
1693 shouldHgStat = true;
|
Chris@109
|
1694 break;
|
Chris@109
|
1695
|
Chris@109
|
1696 case ACT_PUSH:
|
Chris@120
|
1697 showPushResult(output);
|
Chris@109
|
1698 break;
|
Chris@109
|
1699
|
Chris@109
|
1700 case ACT_INIT:
|
Chris@109
|
1701 MultiChoiceDialog::addRecentArgument("init", workFolderPath);
|
Chris@109
|
1702 MultiChoiceDialog::addRecentArgument("local", workFolderPath);
|
Chris@109
|
1703 enableDisableActions();
|
Chris@109
|
1704 shouldHgStat = true;
|
Chris@109
|
1705 break;
|
Chris@109
|
1706
|
Chris@109
|
1707 case ACT_CLONEFROMREMOTE:
|
Chris@109
|
1708 MultiChoiceDialog::addRecentArgument("local", workFolderPath);
|
Chris@109
|
1709 MultiChoiceDialog::addRecentArgument("remote", remoteRepoPath);
|
Chris@109
|
1710 MultiChoiceDialog::addRecentArgument("remote", workFolderPath, true);
|
Chris@109
|
1711 QMessageBox::information(this, "Clone", output);
|
Chris@109
|
1712 enableDisableActions();
|
Chris@109
|
1713 shouldHgStat = true;
|
Chris@109
|
1714 break;
|
Chris@109
|
1715
|
Chris@109
|
1716 case ACT_LOG:
|
Chris@120
|
1717 hgTabs->setNewLog(output);
|
Chris@120
|
1718 needNewLog = false;
|
Chris@120
|
1719 break;
|
Chris@120
|
1720
|
Chris@120
|
1721 case ACT_LOG_INCREMENTAL:
|
Chris@120
|
1722 hgTabs->addIncrementalLog(output);
|
Chris@109
|
1723 break;
|
Chris@109
|
1724
|
Chris@109
|
1725 case ACT_QUERY_PARENTS:
|
Chris@152
|
1726 {
|
Chris@109
|
1727 foreach (Changeset *cs, currentParents) delete cs;
|
Chris@109
|
1728 currentParents = Changeset::parseChangesets(output);
|
Chris@152
|
1729 QStringList parentIds = Changeset::getIds(currentParents);
|
Chris@153
|
1730 hgTabs->setCurrent(parentIds, currentBranch);
|
Chris@152
|
1731 }
|
Chris@109
|
1732 break;
|
Chris@109
|
1733
|
Chris@109
|
1734 case ACT_QUERY_HEADS:
|
Chris@150
|
1735 {
|
Chris@150
|
1736 oldHeadIds = Changeset::getIds(currentHeads);
|
Chris@150
|
1737 Changesets newHeads = Changeset::parseChangesets(output);
|
Chris@150
|
1738 QStringList newHeadIds = Changeset::getIds(newHeads);
|
Chris@150
|
1739 if (oldHeadIds != newHeadIds) {
|
Chris@150
|
1740 DEBUG << "Heads changed, will prompt an incremental log if appropriate" << endl;
|
Chris@150
|
1741 headsChanged = true;
|
Chris@150
|
1742 foreach (Changeset *cs, currentHeads) delete cs;
|
Chris@150
|
1743 currentHeads = newHeads;
|
Chris@150
|
1744 }
|
Chris@150
|
1745 }
|
Chris@109
|
1746 break;
|
Chris@130
|
1747
|
Chris@130
|
1748 case ACT_COMMIT:
|
Chris@130
|
1749 hgTabs->clearSelections();
|
Chris@163
|
1750 justMerged = false;
|
Chris@130
|
1751 shouldHgStat = true;
|
Chris@130
|
1752 break;
|
Chris@163
|
1753
|
Chris@163
|
1754 case ACT_REVERT:
|
Chris@163
|
1755 hgMarkResolved(lastRevertedFiles);
|
Chris@163
|
1756 justMerged = false;
|
Chris@163
|
1757 break;
|
Chris@109
|
1758
|
Chris@109
|
1759 case ACT_REMOVE:
|
Chris@109
|
1760 case ACT_ADD:
|
Chris@116
|
1761 hgTabs->clearSelections();
|
Chris@116
|
1762 shouldHgStat = true;
|
Chris@116
|
1763 break;
|
Chris@116
|
1764
|
Chris@164
|
1765 case ACT_TAG:
|
Chris@164
|
1766 needNewLog = true;
|
Chris@164
|
1767 shouldHgStat = true;
|
Chris@164
|
1768 break;
|
Chris@164
|
1769
|
Chris@168
|
1770 case ACT_DIFF_SUMMARY:
|
Chris@168
|
1771 QMessageBox::information(this, tr("Change summary"),
|
Chris@168
|
1772 format3(tr("Summary of uncommitted changes"),
|
Chris@168
|
1773 "",
|
Chris@168
|
1774 output));
|
Chris@168
|
1775 break;
|
Chris@168
|
1776
|
Chris@109
|
1777 case ACT_FOLDERDIFF:
|
Chris@109
|
1778 case ACT_CHGSETDIFF:
|
Chris@109
|
1779 case ACT_SERVE:
|
Chris@109
|
1780 case ACT_HG_IGNORE:
|
Chris@109
|
1781 shouldHgStat = true;
|
Chris@109
|
1782 break;
|
Chris@109
|
1783
|
Chris@109
|
1784 case ACT_UPDATE:
|
Chris@162
|
1785 QMessageBox::information(this, tr("Update"), tr("<qt><h3>Update successful</h3><p>%1</p>").arg(xmlEncode(output)));
|
Chris@109
|
1786 shouldHgStat = true;
|
Chris@109
|
1787 break;
|
Chris@109
|
1788
|
Chris@109
|
1789 case ACT_MERGE:
|
Chris@196
|
1790 //!!! use format3?
|
Chris@196
|
1791 QMessageBox::information(this, tr("Merge"), tr("<qt><h3>Merge successful</h3><pre>%1</pre>").arg(xmlEncode(output)));
|
Chris@109
|
1792 shouldHgStat = true;
|
Chris@109
|
1793 justMerged = true;
|
Chris@109
|
1794 break;
|
Chris@109
|
1795
|
Chris@109
|
1796 case ACT_RETRY_MERGE:
|
Chris@163
|
1797 QMessageBox::information(this, tr("Resolved"),
|
Chris@163
|
1798 tr("<qt><h3>Merge resolved</h3><p>Merge resolved successfully.</p>"));
|
Chris@109
|
1799 shouldHgStat = true;
|
Chris@109
|
1800 justMerged = true;
|
Chris@109
|
1801 break;
|
Chris@109
|
1802
|
Chris@109
|
1803 default:
|
Chris@109
|
1804 break;
|
Chris@109
|
1805 }
|
Chris@108
|
1806
|
Chris@121
|
1807 // Sequence when no full log required:
|
Chris@163
|
1808 // paths -> branch -> stat -> resolve-list -> heads ->
|
Chris@150
|
1809 // incremental-log (only if heads changed) -> parents
|
Chris@150
|
1810 //
|
Chris@121
|
1811 // Sequence when full log required:
|
Chris@163
|
1812 // paths -> branch -> stat -> resolve-list -> heads -> parents -> log
|
Chris@150
|
1813 //
|
Chris@150
|
1814 // Note we want to call enableDisableActions only once, at the end
|
Chris@150
|
1815 // of whichever sequence is in use.
|
Chris@150
|
1816
|
Chris@156
|
1817 bool noMore = false;
|
Chris@156
|
1818
|
Chris@150
|
1819 switch (action) {
|
Chris@175
|
1820
|
Chris@175
|
1821 case ACT_TEST_HG:
|
Chris@200
|
1822 hgTestExtension();
|
Chris@200
|
1823 break;
|
Chris@200
|
1824
|
Chris@200
|
1825 case ACT_TEST_HG_EXT:
|
Chris@175
|
1826 hgQueryPaths();
|
Chris@175
|
1827 break;
|
Chris@150
|
1828
|
Chris@150
|
1829 case ACT_QUERY_PATHS:
|
Chris@109
|
1830 hgQueryBranch();
|
Chris@150
|
1831 break;
|
Chris@150
|
1832
|
Chris@150
|
1833 case ACT_QUERY_BRANCH:
|
Chris@109
|
1834 hgStat();
|
Chris@150
|
1835 break;
|
Chris@150
|
1836
|
Chris@150
|
1837 case ACT_STAT:
|
Chris@163
|
1838 hgResolveList();
|
Chris@163
|
1839 break;
|
Chris@163
|
1840
|
Chris@163
|
1841 case ACT_RESOLVE_LIST:
|
Chris@150
|
1842 hgQueryHeads();
|
Chris@150
|
1843 break;
|
Chris@150
|
1844
|
Chris@150
|
1845 case ACT_QUERY_HEADS:
|
Chris@150
|
1846 if (headsChanged && !needNewLog) {
|
Chris@150
|
1847 hgLogIncremental(oldHeadIds);
|
Chris@121
|
1848 } else {
|
Chris@150
|
1849 hgQueryParents();
|
Chris@121
|
1850 }
|
Chris@150
|
1851 break;
|
Chris@150
|
1852
|
Chris@150
|
1853 case ACT_LOG_INCREMENTAL:
|
Chris@109
|
1854 hgQueryParents();
|
Chris@150
|
1855 break;
|
Chris@150
|
1856
|
Chris@150
|
1857 case ACT_QUERY_PARENTS:
|
Chris@120
|
1858 if (needNewLog) {
|
Chris@120
|
1859 hgLog();
|
Chris@150
|
1860 } else {
|
Chris@150
|
1861 // we're done
|
Chris@156
|
1862 noMore = true;
|
Chris@120
|
1863 }
|
Chris@150
|
1864 break;
|
Chris@150
|
1865
|
Chris@150
|
1866 case ACT_LOG:
|
Chris@150
|
1867 // we're done
|
Chris@156
|
1868 noMore = true;
|
Chris@198
|
1869 break;
|
Chris@150
|
1870
|
Chris@150
|
1871 default:
|
Chris@109
|
1872 if (shouldHgStat) {
|
Chris@163
|
1873 shouldHgStat = false;
|
Chris@109
|
1874 hgQueryPaths();
|
Chris@150
|
1875 } else {
|
Chris@156
|
1876 noMore = true;
|
jtkorhonen@0
|
1877 }
|
Chris@150
|
1878 break;
|
Chris@150
|
1879 }
|
Chris@156
|
1880
|
Chris@156
|
1881 if (noMore) {
|
Chris@173
|
1882 stateUnknown = false;
|
Chris@156
|
1883 enableDisableActions();
|
Chris@156
|
1884 hgTabs->updateHistory();
|
Chris@156
|
1885 }
|
jtkorhonen@0
|
1886 }
|
jtkorhonen@0
|
1887
|
jtkorhonen@0
|
1888 void MainWindow::connectActions()
|
jtkorhonen@0
|
1889 {
|
jtkorhonen@0
|
1890 connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
|
jtkorhonen@0
|
1891 connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
|
jtkorhonen@0
|
1892
|
Chris@120
|
1893 connect(hgRefreshAct, SIGNAL(triggered()), this, SLOT(hgRefresh()));
|
jtkorhonen@0
|
1894 connect(hgRemoveAct, SIGNAL(triggered()), this, SLOT(hgRemove()));
|
jtkorhonen@0
|
1895 connect(hgAddAct, SIGNAL(triggered()), this, SLOT(hgAdd()));
|
jtkorhonen@0
|
1896 connect(hgCommitAct, SIGNAL(triggered()), this, SLOT(hgCommit()));
|
jtkorhonen@0
|
1897 connect(hgFolderDiffAct, SIGNAL(triggered()), this, SLOT(hgFolderDiff()));
|
jtkorhonen@0
|
1898 connect(hgUpdateAct, SIGNAL(triggered()), this, SLOT(hgUpdate()));
|
jtkorhonen@0
|
1899 connect(hgRevertAct, SIGNAL(triggered()), this, SLOT(hgRevert()));
|
jtkorhonen@0
|
1900 connect(hgMergeAct, SIGNAL(triggered()), this, SLOT(hgMerge()));
|
jtkorhonen@34
|
1901 connect(hgIgnoreAct, SIGNAL(triggered()), this, SLOT(hgIgnore()));
|
jtkorhonen@0
|
1902
|
jtkorhonen@0
|
1903 connect(settingsAct, SIGNAL(triggered()), this, SLOT(settings()));
|
Chris@69
|
1904 connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
|
Chris@182
|
1905 connect(changeRemoteRepoAct, SIGNAL(triggered()), this, SLOT(changeRemoteRepo()));
|
jtkorhonen@0
|
1906
|
jtkorhonen@0
|
1907 connect(hgIncomingAct, SIGNAL(triggered()), this, SLOT(hgIncoming()));
|
jtkorhonen@0
|
1908 connect(hgPullAct, SIGNAL(triggered()), this, SLOT(hgPull()));
|
jtkorhonen@0
|
1909 connect(hgPushAct, SIGNAL(triggered()), this, SLOT(hgPush()));
|
jtkorhonen@0
|
1910
|
jtkorhonen@0
|
1911 connect(hgAnnotateAct, SIGNAL(triggered()), this, SLOT(hgAnnotate()));
|
jtkorhonen@11
|
1912 connect(hgServeAct, SIGNAL(triggered()), this, SLOT(hgServe()));
|
jtkorhonen@0
|
1913 }
|
Chris@141
|
1914
|
Chris@141
|
1915 void MainWindow::connectTabsSignals()
|
Chris@141
|
1916 {
|
Chris@141
|
1917 connect(hgTabs, SIGNAL(commit()),
|
Chris@141
|
1918 this, SLOT(hgCommit()));
|
Chris@141
|
1919
|
Chris@141
|
1920 connect(hgTabs, SIGNAL(revert()),
|
Chris@141
|
1921 this, SLOT(hgRevert()));
|
Chris@141
|
1922
|
Chris@141
|
1923 connect(hgTabs, SIGNAL(diffWorkingFolder()),
|
Chris@141
|
1924 this, SLOT(hgFolderDiff()));
|
Chris@168
|
1925
|
Chris@168
|
1926 connect(hgTabs, SIGNAL(showSummary()),
|
Chris@168
|
1927 this, SLOT(hgShowSummary()));
|
Chris@148
|
1928
|
Chris@141
|
1929 connect(hgTabs, SIGNAL(updateTo(QString)),
|
Chris@148
|
1930 this, SLOT(hgUpdateToRev(QString)));
|
Chris@141
|
1931
|
Chris@141
|
1932 connect(hgTabs, SIGNAL(diffToCurrent(QString)),
|
Chris@148
|
1933 this, SLOT(hgDiffToCurrent(QString)));
|
Chris@141
|
1934
|
Chris@148
|
1935 connect(hgTabs, SIGNAL(diffToParent(QString, QString)),
|
Chris@148
|
1936 this, SLOT(hgDiffToParent(QString, QString)));
|
Chris@141
|
1937
|
Chris@141
|
1938 connect(hgTabs, SIGNAL(mergeFrom(QString)),
|
Chris@148
|
1939 this, SLOT(hgMergeFrom(QString)));
|
Chris@164
|
1940
|
Chris@141
|
1941 connect(hgTabs, SIGNAL(tag(QString)),
|
Chris@148
|
1942 this, SLOT(hgTag(QString)));
|
Chris@141
|
1943 }
|
Chris@141
|
1944
|
jtkorhonen@0
|
1945 void MainWindow::enableDisableActions()
|
jtkorhonen@0
|
1946 {
|
Chris@90
|
1947 DEBUG << "MainWindow::enableDisableActions" << endl;
|
Chris@90
|
1948
|
Chris@202
|
1949 QString dirname = QDir(workFolderPath).dirName();
|
Chris@202
|
1950 if (dirname != "") {
|
Chris@202
|
1951 setWindowTitle(tr("EasyMercurial: %1").arg(dirname));
|
Chris@202
|
1952 } else {
|
Chris@202
|
1953 setWindowTitle(tr("EasyMercurial"));
|
Chris@202
|
1954 }
|
Chris@202
|
1955
|
Chris@115
|
1956 //!!! should also do things like set the status texts for the
|
Chris@115
|
1957 //!!! actions appropriately by context
|
Chris@115
|
1958
|
jtkorhonen@0
|
1959 QDir localRepoDir;
|
jtkorhonen@0
|
1960 QDir workFolderDir;
|
Chris@145
|
1961 bool workFolderExist = true;
|
Chris@145
|
1962 bool localRepoExist = true;
|
jtkorhonen@0
|
1963
|
jtkorhonen@0
|
1964 remoteRepoActionsEnabled = true;
|
Chris@90
|
1965 if (remoteRepoPath.isEmpty()) {
|
jtkorhonen@0
|
1966 remoteRepoActionsEnabled = false;
|
jtkorhonen@0
|
1967 }
|
jtkorhonen@0
|
1968
|
jtkorhonen@0
|
1969 localRepoActionsEnabled = true;
|
Chris@90
|
1970 if (workFolderPath.isEmpty()) {
|
jtkorhonen@0
|
1971 localRepoActionsEnabled = false;
|
jtkorhonen@0
|
1972 workFolderExist = false;
|
jtkorhonen@0
|
1973 }
|
jtkorhonen@0
|
1974
|
Chris@90
|
1975 if (!workFolderDir.exists(workFolderPath)) {
|
jtkorhonen@0
|
1976 localRepoActionsEnabled = false;
|
jtkorhonen@0
|
1977 workFolderExist = false;
|
Chris@90
|
1978 } else {
|
jtkorhonen@0
|
1979 workFolderExist = true;
|
jtkorhonen@0
|
1980 }
|
jtkorhonen@0
|
1981
|
Chris@112
|
1982 if (!localRepoDir.exists(workFolderPath + "/.hg")) {
|
jtkorhonen@0
|
1983 localRepoActionsEnabled = false;
|
jtkorhonen@0
|
1984 localRepoExist = false;
|
jtkorhonen@0
|
1985 }
|
jtkorhonen@0
|
1986
|
jtkorhonen@0
|
1987 hgIncomingAct -> setEnabled(remoteRepoActionsEnabled && remoteRepoActionsEnabled);
|
jtkorhonen@0
|
1988 hgPullAct -> setEnabled(remoteRepoActionsEnabled && remoteRepoActionsEnabled);
|
jtkorhonen@0
|
1989 hgPushAct -> setEnabled(remoteRepoActionsEnabled && remoteRepoActionsEnabled);
|
Chris@169
|
1990
|
Chris@179
|
1991 bool haveDiff = false;
|
Chris@179
|
1992 QSettings settings;
|
Chris@179
|
1993 settings.beginGroup("Locations");
|
Chris@179
|
1994 if (settings.value("extdiffbinary", "").toString() != "") {
|
Chris@179
|
1995 haveDiff = true;
|
Chris@179
|
1996 }
|
Chris@179
|
1997 settings.endGroup();
|
Chris@112
|
1998
|
Chris@120
|
1999 hgRefreshAct -> setEnabled(localRepoActionsEnabled);
|
Chris@112
|
2000 hgFolderDiffAct -> setEnabled(localRepoActionsEnabled && haveDiff);
|
jtkorhonen@0
|
2001 hgRevertAct -> setEnabled(localRepoActionsEnabled);
|
jtkorhonen@0
|
2002 hgAddAct -> setEnabled(localRepoActionsEnabled);
|
jtkorhonen@0
|
2003 hgRemoveAct -> setEnabled(localRepoActionsEnabled);
|
jtkorhonen@0
|
2004 hgUpdateAct -> setEnabled(localRepoActionsEnabled);
|
jtkorhonen@0
|
2005 hgCommitAct -> setEnabled(localRepoActionsEnabled);
|
jtkorhonen@0
|
2006 hgMergeAct -> setEnabled(localRepoActionsEnabled);
|
jtkorhonen@2
|
2007 hgAnnotateAct -> setEnabled(localRepoActionsEnabled);
|
jtkorhonen@11
|
2008 hgServeAct -> setEnabled(localRepoActionsEnabled);
|
jtkorhonen@34
|
2009 hgIgnoreAct -> setEnabled(localRepoActionsEnabled);
|
jtkorhonen@0
|
2010
|
Chris@90
|
2011 DEBUG << "localRepoActionsEnabled = " << localRepoActionsEnabled << endl;
|
Chris@98
|
2012 DEBUG << "canCommit = " << hgTabs->canCommit() << endl;
|
Chris@90
|
2013
|
Chris@98
|
2014 hgAddAct->setEnabled(localRepoActionsEnabled && hgTabs->canAdd());
|
Chris@98
|
2015 hgRemoveAct->setEnabled(localRepoActionsEnabled && hgTabs->canRemove());
|
Chris@98
|
2016 hgCommitAct->setEnabled(localRepoActionsEnabled && hgTabs->canCommit());
|
Chris@163
|
2017 hgRevertAct->setEnabled(localRepoActionsEnabled && hgTabs->canRevert());
|
Chris@163
|
2018 hgFolderDiffAct->setEnabled(localRepoActionsEnabled && hgTabs->canDiff());
|
Chris@90
|
2019
|
Chris@108
|
2020 // A default merge makes sense if:
|
Chris@108
|
2021 // * there is only one parent (if there are two, we have an uncommitted merge) and
|
Chris@108
|
2022 // * there are exactly two heads that have the same branch as the current branch and
|
Chris@108
|
2023 // * our parent is one of those heads
|
Chris@108
|
2024 //
|
Chris@108
|
2025 // A default update makes sense if:
|
Chris@108
|
2026 // * there is only one parent and
|
Chris@108
|
2027 // * the parent is not one of the current heads
|
Chris@156
|
2028
|
Chris@108
|
2029 bool canMerge = false;
|
Chris@108
|
2030 bool canUpdate = false;
|
Chris@156
|
2031 bool haveMerge = false;
|
Chris@162
|
2032 bool emptyRepo = false;
|
Chris@156
|
2033 int currentBranchHeads = 0;
|
Chris@156
|
2034
|
Chris@108
|
2035 if (currentParents.size() == 1) {
|
Chris@156
|
2036 bool parentIsHead = false;
|
Chris@108
|
2037 Changeset *parent = currentParents[0];
|
Chris@108
|
2038 foreach (Changeset *head, currentHeads) {
|
Chris@108
|
2039 DEBUG << "head branch " << head->branch() << ", current branch " << currentBranch << endl;
|
Chris@108
|
2040 if (head->isOnBranch(currentBranch)) {
|
Chris@108
|
2041 ++currentBranchHeads;
|
Chris@108
|
2042 if (parent->id() == head->id()) {
|
Chris@108
|
2043 parentIsHead = true;
|
Chris@108
|
2044 }
|
Chris@108
|
2045 }
|
Chris@108
|
2046 }
|
Chris@108
|
2047 if (currentBranchHeads == 2 && parentIsHead) {
|
Chris@108
|
2048 canMerge = true;
|
Chris@108
|
2049 }
|
Chris@108
|
2050 if (!parentIsHead) {
|
Chris@108
|
2051 canUpdate = true;
|
Chris@108
|
2052 DEBUG << "parent id = " << parent->id() << endl;
|
Chris@108
|
2053 DEBUG << " head ids "<<endl;
|
Chris@108
|
2054 foreach (Changeset *h, currentHeads) {
|
Chris@108
|
2055 DEBUG << "head id = " << h->id() << endl;
|
Chris@108
|
2056 }
|
Chris@108
|
2057 }
|
Chris@162
|
2058 } else if (currentParents.size() == 0) {
|
Chris@162
|
2059 emptyRepo = true;
|
Chris@156
|
2060 } else {
|
Chris@156
|
2061 haveMerge = true;
|
Chris@163
|
2062 justMerged = true;
|
Chris@108
|
2063 }
|
Chris@156
|
2064
|
Chris@163
|
2065 hgMergeAct->setEnabled(localRepoActionsEnabled &&
|
Chris@163
|
2066 (canMerge || hgTabs->canResolve()));
|
Chris@163
|
2067 hgUpdateAct->setEnabled(localRepoActionsEnabled &&
|
Chris@172
|
2068 (canUpdate && !hgTabs->haveChangesToCommit()));
|
Chris@115
|
2069
|
Chris@115
|
2070 // Set the state field on the file status widget
|
Chris@115
|
2071
|
Chris@115
|
2072 QString branchText;
|
Chris@115
|
2073 if (currentBranch == "" || currentBranch == "default") {
|
Chris@115
|
2074 branchText = tr("the default branch");
|
Chris@115
|
2075 } else {
|
Chris@115
|
2076 branchText = tr("branch \"%1\"").arg(currentBranch);
|
Chris@115
|
2077 }
|
Chris@156
|
2078
|
Chris@173
|
2079 if (stateUnknown) {
|
Chris@173
|
2080 hgTabs->setState(tr("(Examining repository)"));
|
Chris@173
|
2081 } else if (emptyRepo) {
|
Chris@162
|
2082 hgTabs->setState(tr("Nothing committed to this repository yet"));
|
Chris@162
|
2083 } else if (canMerge) {
|
Chris@156
|
2084 hgTabs->setState(tr("<b>Awaiting merge</b> on %1").arg(branchText));
|
Chris@163
|
2085 } else if (!hgTabs->getAllUnresolvedFiles().empty()) {
|
Chris@163
|
2086 hgTabs->setState(tr("Have unresolved files following merge on %1").arg(branchText));
|
Chris@156
|
2087 } else if (haveMerge) {
|
Chris@157
|
2088 hgTabs->setState(tr("Have merged but not yet committed on %1").arg(branchText));
|
Chris@156
|
2089 } else if (canUpdate) {
|
Chris@172
|
2090 if (hgTabs->haveChangesToCommit()) {
|
Chris@163
|
2091 // have uncommitted changes
|
Chris@163
|
2092 hgTabs->setState(tr("On %1. Not at the head of the branch").arg(branchText));
|
Chris@163
|
2093 } else {
|
Chris@163
|
2094 // no uncommitted changes
|
Chris@163
|
2095 hgTabs->setState(tr("On %1. Not at the head of the branch: consider updating").arg(branchText));
|
Chris@163
|
2096 }
|
Chris@156
|
2097 } else if (currentBranchHeads > 1) {
|
Chris@156
|
2098 hgTabs->setState(tr("At one of %n heads of %1", "", currentBranchHeads).arg(branchText));
|
Chris@115
|
2099 } else {
|
Chris@115
|
2100 hgTabs->setState(tr("At the head of %1").arg(branchText));
|
Chris@115
|
2101 }
|
jtkorhonen@0
|
2102 }
|
jtkorhonen@0
|
2103
|
jtkorhonen@0
|
2104 void MainWindow::createActions()
|
jtkorhonen@0
|
2105 {
|
jtkorhonen@0
|
2106 //File actions
|
Chris@69
|
2107 openAct = new QAction(QIcon(":/images/fileopen.png"), tr("Open..."), this);
|
Chris@199
|
2108 openAct -> setStatusTip(tr("Open an existing repository or working folder"));
|
Chris@69
|
2109
|
Chris@182
|
2110 changeRemoteRepoAct = new QAction(tr("Change Remote Location..."), this);
|
Chris@182
|
2111 changeRemoteRepoAct->setStatusTip(tr("Change the default remote repository for pull and push actions"));
|
Chris@182
|
2112
|
jtkorhonen@0
|
2113 settingsAct = new QAction(QIcon(":/images/settings.png"), tr("Settings..."), this);
|
jtkorhonen@0
|
2114 settingsAct -> setStatusTip(tr("View and change application settings"));
|
jtkorhonen@0
|
2115
|
Chris@169
|
2116 exitAct = new QAction(QIcon(":/images/exit.png"), tr("Quit"), this);
|
jtkorhonen@0
|
2117 exitAct->setShortcuts(QKeySequence::Quit);
|
Chris@169
|
2118 exitAct->setStatusTip(tr("Quit EasyMercurial"));
|
jtkorhonen@0
|
2119
|
jtkorhonen@0
|
2120 //Repository actions
|
Chris@120
|
2121 hgRefreshAct = new QAction(QIcon(":/images/status.png"), tr("Refresh"), this);
|
Chris@178
|
2122 hgRefreshAct->setStatusTip(tr("Refresh the window to show the current state of the working folder"));
|
Chris@61
|
2123
|
Chris@61
|
2124 hgIncomingAct = new QAction(QIcon(":/images/incoming.png"), tr("Preview"), this);
|
Chris@169
|
2125 hgIncomingAct -> setStatusTip(tr("See what changes are available in the remote repository waiting to be pulled"));
|
jtkorhonen@0
|
2126
|
Chris@61
|
2127 hgPullAct = new QAction(QIcon(":/images/pull.png"), tr("Pull"), this);
|
Chris@169
|
2128 hgPullAct -> setStatusTip(tr("Pull changes from the remote repository to the local repository"));
|
jtkorhonen@0
|
2129
|
Chris@61
|
2130 hgPushAct = new QAction(QIcon(":/images/push.png"), tr("Push"), this);
|
Chris@169
|
2131 hgPushAct->setStatusTip(tr("Push changes from the local repository to the remote repository"));
|
jtkorhonen@0
|
2132
|
jtkorhonen@0
|
2133 //Workfolder actions
|
Chris@99
|
2134 hgFolderDiffAct = new QAction(QIcon(":/images/folderdiff.png"), tr("Diff"), this);
|
Chris@169
|
2135 hgFolderDiffAct->setStatusTip(tr("See what has changed in the working folder compared with the last committed state"));
|
jtkorhonen@0
|
2136
|
Chris@61
|
2137 hgRevertAct = new QAction(QIcon(":/images/undo.png"), tr("Revert"), this);
|
Chris@169
|
2138 hgRevertAct->setStatusTip(tr("Throw away your changes and return to the last committed state"));
|
jtkorhonen@0
|
2139
|
Chris@61
|
2140 hgAddAct = new QAction(QIcon(":/images/add.png"), tr("Add"), this);
|
Chris@169
|
2141 hgAddAct -> setStatusTip(tr("Mark the selected file(s) to be added on the next commit"));
|
jtkorhonen@0
|
2142
|
Chris@169
|
2143 //!!! needs to be modified for number
|
Chris@61
|
2144 hgRemoveAct = new QAction(QIcon(":/images/remove.png"), tr("Remove"), this);
|
Chris@169
|
2145 hgRemoveAct -> setStatusTip(tr("Mark the selected file(s) to be removed from version control on the next commit"));
|
jtkorhonen@0
|
2146
|
Chris@61
|
2147 hgUpdateAct = new QAction(QIcon(":/images/update.png"), tr("Update"), this);
|
Chris@169
|
2148 hgUpdateAct->setStatusTip(tr("Update the working folder to the head of the current repository branch"));
|
jtkorhonen@0
|
2149
|
Chris@169
|
2150 //!!! needs to be modified when files selected
|
Chris@61
|
2151 hgCommitAct = new QAction(QIcon(":/images/commit.png"), tr("Commit"), this);
|
Chris@169
|
2152 hgCommitAct->setStatusTip(tr("Commit your changes to the local repository"));
|
jtkorhonen@0
|
2153
|
jtkorhonen@0
|
2154 hgMergeAct = new QAction(QIcon(":/images/merge.png"), tr("Merge"), this);
|
Chris@169
|
2155 hgMergeAct->setStatusTip(tr("Merge the two independent sets of changes in the local repository into the working folder"));
|
jtkorhonen@0
|
2156
|
jtkorhonen@0
|
2157 //Advanced actions
|
Chris@169
|
2158 //!!! needs to be modified for number
|
jtkorhonen@0
|
2159 hgAnnotateAct = new QAction(tr("Annotate"), this);
|
jtkorhonen@0
|
2160 hgAnnotateAct -> setStatusTip(tr("Show line-by-line version information for selected file"));
|
jtkorhonen@0
|
2161
|
Chris@182
|
2162 hgIgnoreAct = new QAction(tr("Edit .hgignore File"), this);
|
Chris@169
|
2163 hgIgnoreAct -> setStatusTip(tr("Edit the .hgignore file, containing the names of files that should be ignored by Mercurial"));
|
jtkorhonen@34
|
2164
|
Chris@182
|
2165 hgServeAct = new QAction(tr("Serve via HTTP"), this);
|
jtkorhonen@11
|
2166 hgServeAct -> setStatusTip(tr("Serve local repository via http for workgroup access"));
|
jtkorhonen@11
|
2167
|
jtkorhonen@0
|
2168 //Help actions
|
Chris@190
|
2169 aboutAct = new QAction(tr("About EasyMercurial"), this);
|
Chris@94
|
2170
|
Chris@94
|
2171 // Miscellaneous
|
Chris@199
|
2172 QShortcut *clearSelectionsShortcut = new QShortcut(Qt::Key_Escape, this);
|
Chris@199
|
2173 connect(clearSelectionsShortcut, SIGNAL(activated()),
|
Chris@199
|
2174 this, SLOT(clearSelections()));
|
jtkorhonen@0
|
2175 }
|
jtkorhonen@0
|
2176
|
jtkorhonen@0
|
2177 void MainWindow::createMenus()
|
jtkorhonen@0
|
2178 {
|
jtkorhonen@0
|
2179 fileMenu = menuBar()->addMenu(tr("File"));
|
Chris@169
|
2180
|
Chris@69
|
2181 fileMenu -> addAction(openAct);
|
Chris@182
|
2182 fileMenu -> addAction(changeRemoteRepoAct);
|
Chris@191
|
2183 fileMenu -> addSeparator();
|
Chris@191
|
2184
|
Chris@191
|
2185 advancedMenu = fileMenu->addMenu(tr("Advanced"));
|
Chris@191
|
2186
|
jtkorhonen@0
|
2187 fileMenu -> addAction(settingsAct);
|
Chris@191
|
2188
|
jtkorhonen@0
|
2189 fileMenu -> addSeparator();
|
jtkorhonen@0
|
2190 fileMenu -> addAction(exitAct);
|
jtkorhonen@0
|
2191
|
jtkorhonen@34
|
2192 advancedMenu -> addAction(hgIgnoreAct);
|
Chris@199
|
2193 advancedMenu -> addSeparator();
|
jtkorhonen@11
|
2194 advancedMenu -> addAction(hgServeAct);
|
jtkorhonen@0
|
2195
|
jtkorhonen@0
|
2196 helpMenu = menuBar()->addMenu(tr("Help"));
|
jtkorhonen@0
|
2197 helpMenu->addAction(aboutAct);
|
jtkorhonen@0
|
2198 }
|
jtkorhonen@0
|
2199
|
jtkorhonen@0
|
2200 void MainWindow::createToolBars()
|
jtkorhonen@0
|
2201 {
|
jtkorhonen@0
|
2202 fileToolBar = addToolBar(tr("File"));
|
jtkorhonen@0
|
2203 fileToolBar -> setIconSize(QSize(MY_ICON_SIZE, MY_ICON_SIZE));
|
Chris@69
|
2204 fileToolBar -> addAction(openAct);
|
Chris@120
|
2205 fileToolBar -> addAction(hgRefreshAct);
|
jtkorhonen@0
|
2206 fileToolBar -> addSeparator();
|
jtkorhonen@0
|
2207 fileToolBar -> setMovable(false);
|
jtkorhonen@0
|
2208
|
jtkorhonen@0
|
2209 repoToolBar = addToolBar(tr(REPOMENU_TITLE));
|
jtkorhonen@0
|
2210 repoToolBar -> setIconSize(QSize(MY_ICON_SIZE, MY_ICON_SIZE));
|
jtkorhonen@0
|
2211 repoToolBar->addAction(hgIncomingAct);
|
jtkorhonen@0
|
2212 repoToolBar->addAction(hgPullAct);
|
jtkorhonen@0
|
2213 repoToolBar->addAction(hgPushAct);
|
jtkorhonen@0
|
2214 repoToolBar -> setMovable(false);
|
jtkorhonen@0
|
2215
|
jtkorhonen@0
|
2216 workFolderToolBar = addToolBar(tr(WORKFOLDERMENU_TITLE));
|
jtkorhonen@0
|
2217 addToolBar(Qt::LeftToolBarArea, workFolderToolBar);
|
jtkorhonen@0
|
2218 workFolderToolBar -> setIconSize(QSize(MY_ICON_SIZE, MY_ICON_SIZE));
|
Chris@95
|
2219 workFolderToolBar->addAction(hgFolderDiffAct);
|
jtkorhonen@0
|
2220 workFolderToolBar->addSeparator();
|
jtkorhonen@0
|
2221 workFolderToolBar->addAction(hgRevertAct);
|
jtkorhonen@0
|
2222 workFolderToolBar->addAction(hgUpdateAct);
|
jtkorhonen@0
|
2223 workFolderToolBar->addAction(hgCommitAct);
|
jtkorhonen@0
|
2224 workFolderToolBar->addAction(hgMergeAct);
|
jtkorhonen@0
|
2225 workFolderToolBar->addSeparator();
|
jtkorhonen@0
|
2226 workFolderToolBar->addAction(hgAddAct);
|
jtkorhonen@0
|
2227 workFolderToolBar->addAction(hgRemoveAct);
|
jtkorhonen@0
|
2228 workFolderToolBar -> setMovable(false);
|
Chris@61
|
2229
|
Chris@61
|
2230 foreach (QToolButton *tb, findChildren<QToolButton *>()) {
|
Chris@61
|
2231 tb->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
|
Chris@61
|
2232 }
|
jtkorhonen@0
|
2233 }
|
jtkorhonen@0
|
2234
|
jtkorhonen@0
|
2235
|
jtkorhonen@0
|
2236 void MainWindow::createStatusBar()
|
jtkorhonen@0
|
2237 {
|
jtkorhonen@0
|
2238 statusBar()->showMessage(tr("Ready"));
|
jtkorhonen@0
|
2239 }
|
jtkorhonen@0
|
2240
|
Chris@69
|
2241
|
Chris@69
|
2242 //!!! review these:
|
Chris@69
|
2243
|
jtkorhonen@0
|
2244 void MainWindow::readSettings()
|
jtkorhonen@0
|
2245 {
|
jtkorhonen@0
|
2246 QDir workFolder;
|
jtkorhonen@0
|
2247
|
Chris@61
|
2248 QSettings settings;
|
jtkorhonen@0
|
2249
|
jtkorhonen@30
|
2250 remoteRepoPath = settings.value("remoterepopath", "").toString();
|
jtkorhonen@0
|
2251 workFolderPath = settings.value("workfolderpath", "").toString();
|
jtkorhonen@0
|
2252 if (!workFolder.exists(workFolderPath))
|
jtkorhonen@0
|
2253 {
|
jtkorhonen@0
|
2254 workFolderPath = "";
|
jtkorhonen@0
|
2255 }
|
jtkorhonen@0
|
2256
|
jtkorhonen@0
|
2257 QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
|
jtkorhonen@0
|
2258 QSize size = settings.value("size", QSize(400, 400)).toSize();
|
jtkorhonen@0
|
2259 firstStart = settings.value("firststart", QVariant(true)).toBool();
|
jtkorhonen@0
|
2260
|
Chris@109
|
2261 //!!! initialFileTypesBits = (unsigned char) settings.value("viewFileTypes", QVariant(DEFAULT_HG_STAT_BITS)).toInt();
|
jtkorhonen@0
|
2262 resize(size);
|
jtkorhonen@0
|
2263 move(pos);
|
jtkorhonen@0
|
2264 }
|
jtkorhonen@0
|
2265
|
jtkorhonen@17
|
2266
|
jtkorhonen@0
|
2267 void MainWindow::writeSettings()
|
jtkorhonen@0
|
2268 {
|
Chris@61
|
2269 QSettings settings;
|
jtkorhonen@0
|
2270 settings.setValue("pos", pos());
|
jtkorhonen@0
|
2271 settings.setValue("size", size());
|
jtkorhonen@0
|
2272 settings.setValue("remoterepopath", remoteRepoPath);
|
jtkorhonen@0
|
2273 settings.setValue("workfolderpath", workFolderPath);
|
jtkorhonen@0
|
2274 settings.setValue("firststart", firstStart);
|
Chris@98
|
2275 //!!!settings.setValue("viewFileTypes", hgTabs -> getFileTypesBits());
|
jtkorhonen@0
|
2276 }
|
jtkorhonen@0
|
2277
|
jtkorhonen@0
|
2278
|
jtkorhonen@0
|
2279
|
jtkorhonen@0
|
2280
|