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