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