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