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@113
|
1552 // returns non-zero code if the check was successful but there
|
Chris@113
|
1553 // are no changes pending
|
Chris@143
|
1554 if (output.trimmed() == "") showIncoming("");
|
Chris@113
|
1555 return;
|
Chris@162
|
1556 case ACT_QUERY_HEADS:
|
Chris@162
|
1557 // fails if repo is empty; we don't care (if there's a genuine
|
Chris@202
|
1558 // problem, something else will fail too). Pretend it
|
Chris@202
|
1559 // succeeded, so that any further actions that are contingent
|
Chris@202
|
1560 // on the success of the heads query get carried out properly.
|
Chris@202
|
1561 commandCompleted(action, "");
|
Chris@162
|
1562 return;
|
Chris@113
|
1563 case ACT_FOLDERDIFF:
|
Chris@113
|
1564 case ACT_CHGSETDIFF:
|
Chris@113
|
1565 // external program, unlikely to be anything useful in stderr
|
Chris@113
|
1566 // and some return with failure codes when something as basic
|
Chris@113
|
1567 // as the user closing the window via the wm happens
|
Chris@113
|
1568 return;
|
Chris@174
|
1569 case ACT_PUSH:
|
Chris@174
|
1570 if (output.contains("creates new remote heads")) {
|
Chris@174
|
1571 reportNewRemoteHeads(output);
|
Chris@174
|
1572 return;
|
Chris@174
|
1573 }
|
Chris@199
|
1574 case ACT_STAT:
|
Chris@199
|
1575 if (fsWatcher) fsWatcher->blockSignals(false);
|
Chris@199
|
1576 break; // go on and report
|
Chris@113
|
1577 default:
|
Chris@114
|
1578 break;
|
Chris@113
|
1579 }
|
Chris@113
|
1580
|
Chris@113
|
1581 QString command = action.executable;
|
Chris@113
|
1582 if (command == "") command = "hg";
|
Chris@113
|
1583 foreach (QString arg, action.params) {
|
Chris@113
|
1584 command += " " + arg;
|
Chris@113
|
1585 }
|
Chris@113
|
1586
|
Chris@113
|
1587 QString message = tr("<qt><h3>Command failed</h3>"
|
Chris@113
|
1588 "<p>The following command failed:</p>"
|
Chris@113
|
1589 "<code>%1</code>"
|
Chris@113
|
1590 "%2</qt>")
|
Chris@113
|
1591 .arg(command)
|
Chris@143
|
1592 .arg((output.trimmed() != "") ?
|
Chris@113
|
1593 tr("<p>Its output said:</p><code>%1</code>")
|
Chris@143
|
1594 .arg(xmlEncode(output.left(800))
|
Chris@113
|
1595 .replace("\n", "<br>"))
|
Chris@113
|
1596 : "");
|
Chris@113
|
1597
|
Chris@113
|
1598 QMessageBox::warning(this, tr("Command failed"), message);
|
Chris@62
|
1599 }
|
Chris@62
|
1600
|
Chris@109
|
1601 void MainWindow::commandCompleted(HgAction completedAction, QString output)
|
jtkorhonen@0
|
1602 {
|
Chris@109
|
1603 HGACTIONS action = completedAction.action;
|
Chris@109
|
1604
|
Chris@109
|
1605 if (action == ACT_NONE) return;
|
Chris@109
|
1606
|
Chris@150
|
1607 bool headsChanged = false;
|
Chris@150
|
1608 QStringList oldHeadIds;
|
Chris@150
|
1609
|
Chris@150
|
1610 switch (action) {
|
Chris@109
|
1611
|
Chris@175
|
1612 case ACT_TEST_HG:
|
Chris@175
|
1613 break;
|
Chris@175
|
1614
|
Chris@200
|
1615 case ACT_TEST_HG_EXT:
|
Chris@200
|
1616 break;
|
Chris@200
|
1617
|
Chris@109
|
1618 case ACT_QUERY_PATHS:
|
jtkorhonen@0
|
1619 {
|
Chris@109
|
1620 DEBUG << "stdout is " << output << endl;
|
Chris@109
|
1621 LogParser lp(output, "=");
|
Chris@109
|
1622 LogList ll = lp.parse();
|
Chris@109
|
1623 DEBUG << ll.size() << " results" << endl;
|
Chris@109
|
1624 if (!ll.empty()) {
|
Chris@109
|
1625 remoteRepoPath = lp.parse()[0]["default"].trimmed();
|
Chris@109
|
1626 DEBUG << "Set remote path to " << remoteRepoPath << endl;
|
Chris@210
|
1627 } else {
|
Chris@210
|
1628 remoteRepoPath = "";
|
Chris@109
|
1629 }
|
Chris@109
|
1630 MultiChoiceDialog::addRecentArgument("local", workFolderPath);
|
Chris@109
|
1631 MultiChoiceDialog::addRecentArgument("remote", remoteRepoPath);
|
Chris@109
|
1632 hgTabs->setWorkFolderAndRepoNames(workFolderPath, remoteRepoPath);
|
Chris@109
|
1633 break;
|
Chris@109
|
1634 }
|
jtkorhonen@0
|
1635
|
Chris@109
|
1636 case ACT_QUERY_BRANCH:
|
Chris@109
|
1637 currentBranch = output.trimmed();
|
Chris@109
|
1638 break;
|
jtkorhonen@0
|
1639
|
Chris@109
|
1640 case ACT_STAT:
|
Chris@163
|
1641 lastStatOutput = output;
|
Chris@109
|
1642 updateFileSystemWatcher();
|
Chris@199
|
1643 if (fsWatcher) fsWatcher->blockSignals(false);
|
Chris@109
|
1644 break;
|
Chris@163
|
1645
|
Chris@163
|
1646 case ACT_RESOLVE_LIST:
|
Chris@163
|
1647 if (output != "") {
|
Chris@163
|
1648 // Remove lines beginning with R (they are resolved,
|
Chris@163
|
1649 // and the file stat parser treats R as removed)
|
Chris@163
|
1650 QStringList outList = output.split('\n');
|
Chris@163
|
1651 QStringList winnowed;
|
Chris@163
|
1652 foreach (QString line, outList) {
|
Chris@163
|
1653 if (!line.startsWith("R ")) winnowed.push_back(line);
|
Chris@163
|
1654 }
|
Chris@163
|
1655 output = winnowed.join("\n");
|
Chris@163
|
1656 }
|
Chris@163
|
1657 DEBUG << "lastStatOutput = " << lastStatOutput << endl;
|
Chris@199
|
1658 DEBUG << "resolve output = " << output << endl;
|
Chris@163
|
1659 hgTabs->updateWorkFolderFileList(lastStatOutput + output);
|
Chris@163
|
1660 break;
|
Chris@163
|
1661
|
Chris@163
|
1662 case ACT_RESOLVE_MARK:
|
Chris@163
|
1663 shouldHgStat = true;
|
Chris@163
|
1664 break;
|
Chris@109
|
1665
|
Chris@109
|
1666 case ACT_INCOMING:
|
Chris@120
|
1667 showIncoming(output);
|
Chris@120
|
1668 break;
|
Chris@120
|
1669
|
Chris@109
|
1670 case ACT_ANNOTATE:
|
Chris@109
|
1671 presentLongStdoutToUser(output);
|
Chris@109
|
1672 shouldHgStat = true;
|
Chris@109
|
1673 break;
|
Chris@109
|
1674
|
Chris@109
|
1675 case ACT_PULL:
|
Chris@120
|
1676 showPullResult(output);
|
Chris@109
|
1677 shouldHgStat = true;
|
Chris@109
|
1678 break;
|
Chris@109
|
1679
|
Chris@109
|
1680 case ACT_PUSH:
|
Chris@120
|
1681 showPushResult(output);
|
Chris@109
|
1682 break;
|
Chris@109
|
1683
|
Chris@109
|
1684 case ACT_INIT:
|
Chris@109
|
1685 MultiChoiceDialog::addRecentArgument("init", workFolderPath);
|
Chris@109
|
1686 MultiChoiceDialog::addRecentArgument("local", workFolderPath);
|
Chris@109
|
1687 enableDisableActions();
|
Chris@109
|
1688 shouldHgStat = true;
|
Chris@109
|
1689 break;
|
Chris@109
|
1690
|
Chris@109
|
1691 case ACT_CLONEFROMREMOTE:
|
Chris@109
|
1692 MultiChoiceDialog::addRecentArgument("local", workFolderPath);
|
Chris@109
|
1693 MultiChoiceDialog::addRecentArgument("remote", remoteRepoPath);
|
Chris@109
|
1694 MultiChoiceDialog::addRecentArgument("remote", workFolderPath, true);
|
Chris@109
|
1695 QMessageBox::information(this, "Clone", output);
|
Chris@109
|
1696 enableDisableActions();
|
Chris@109
|
1697 shouldHgStat = true;
|
Chris@109
|
1698 break;
|
Chris@109
|
1699
|
Chris@109
|
1700 case ACT_LOG:
|
Chris@120
|
1701 hgTabs->setNewLog(output);
|
Chris@120
|
1702 needNewLog = false;
|
Chris@120
|
1703 break;
|
Chris@120
|
1704
|
Chris@120
|
1705 case ACT_LOG_INCREMENTAL:
|
Chris@120
|
1706 hgTabs->addIncrementalLog(output);
|
Chris@109
|
1707 break;
|
Chris@109
|
1708
|
Chris@109
|
1709 case ACT_QUERY_PARENTS:
|
Chris@152
|
1710 {
|
Chris@109
|
1711 foreach (Changeset *cs, currentParents) delete cs;
|
Chris@109
|
1712 currentParents = Changeset::parseChangesets(output);
|
Chris@152
|
1713 QStringList parentIds = Changeset::getIds(currentParents);
|
Chris@153
|
1714 hgTabs->setCurrent(parentIds, currentBranch);
|
Chris@152
|
1715 }
|
Chris@109
|
1716 break;
|
Chris@109
|
1717
|
Chris@109
|
1718 case ACT_QUERY_HEADS:
|
Chris@150
|
1719 {
|
Chris@150
|
1720 oldHeadIds = Changeset::getIds(currentHeads);
|
Chris@150
|
1721 Changesets newHeads = Changeset::parseChangesets(output);
|
Chris@150
|
1722 QStringList newHeadIds = Changeset::getIds(newHeads);
|
Chris@150
|
1723 if (oldHeadIds != newHeadIds) {
|
Chris@150
|
1724 DEBUG << "Heads changed, will prompt an incremental log if appropriate" << endl;
|
Chris@150
|
1725 headsChanged = true;
|
Chris@150
|
1726 foreach (Changeset *cs, currentHeads) delete cs;
|
Chris@150
|
1727 currentHeads = newHeads;
|
Chris@150
|
1728 }
|
Chris@150
|
1729 }
|
Chris@109
|
1730 break;
|
Chris@130
|
1731
|
Chris@130
|
1732 case ACT_COMMIT:
|
Chris@130
|
1733 hgTabs->clearSelections();
|
Chris@163
|
1734 justMerged = false;
|
Chris@130
|
1735 shouldHgStat = true;
|
Chris@130
|
1736 break;
|
Chris@163
|
1737
|
Chris@163
|
1738 case ACT_REVERT:
|
Chris@163
|
1739 hgMarkResolved(lastRevertedFiles);
|
Chris@163
|
1740 justMerged = false;
|
Chris@163
|
1741 break;
|
Chris@109
|
1742
|
Chris@109
|
1743 case ACT_REMOVE:
|
Chris@109
|
1744 case ACT_ADD:
|
Chris@116
|
1745 hgTabs->clearSelections();
|
Chris@116
|
1746 shouldHgStat = true;
|
Chris@116
|
1747 break;
|
Chris@116
|
1748
|
Chris@164
|
1749 case ACT_TAG:
|
Chris@164
|
1750 needNewLog = true;
|
Chris@164
|
1751 shouldHgStat = true;
|
Chris@164
|
1752 break;
|
Chris@164
|
1753
|
Chris@168
|
1754 case ACT_DIFF_SUMMARY:
|
Chris@168
|
1755 QMessageBox::information(this, tr("Change summary"),
|
Chris@168
|
1756 format3(tr("Summary of uncommitted changes"),
|
Chris@168
|
1757 "",
|
Chris@168
|
1758 output));
|
Chris@168
|
1759 break;
|
Chris@168
|
1760
|
Chris@109
|
1761 case ACT_FOLDERDIFF:
|
Chris@109
|
1762 case ACT_CHGSETDIFF:
|
Chris@109
|
1763 case ACT_SERVE:
|
Chris@109
|
1764 case ACT_HG_IGNORE:
|
Chris@109
|
1765 shouldHgStat = true;
|
Chris@109
|
1766 break;
|
Chris@109
|
1767
|
Chris@109
|
1768 case ACT_UPDATE:
|
Chris@162
|
1769 QMessageBox::information(this, tr("Update"), tr("<qt><h3>Update successful</h3><p>%1</p>").arg(xmlEncode(output)));
|
Chris@109
|
1770 shouldHgStat = true;
|
Chris@109
|
1771 break;
|
Chris@109
|
1772
|
Chris@109
|
1773 case ACT_MERGE:
|
Chris@196
|
1774 //!!! use format3?
|
Chris@196
|
1775 QMessageBox::information(this, tr("Merge"), tr("<qt><h3>Merge successful</h3><pre>%1</pre>").arg(xmlEncode(output)));
|
Chris@109
|
1776 shouldHgStat = true;
|
Chris@109
|
1777 justMerged = true;
|
Chris@109
|
1778 break;
|
Chris@109
|
1779
|
Chris@109
|
1780 case ACT_RETRY_MERGE:
|
Chris@163
|
1781 QMessageBox::information(this, tr("Resolved"),
|
Chris@163
|
1782 tr("<qt><h3>Merge resolved</h3><p>Merge resolved successfully.</p>"));
|
Chris@109
|
1783 shouldHgStat = true;
|
Chris@109
|
1784 justMerged = true;
|
Chris@109
|
1785 break;
|
Chris@109
|
1786
|
Chris@109
|
1787 default:
|
Chris@109
|
1788 break;
|
Chris@109
|
1789 }
|
Chris@108
|
1790
|
Chris@121
|
1791 // Sequence when no full log required:
|
Chris@163
|
1792 // paths -> branch -> stat -> resolve-list -> heads ->
|
Chris@150
|
1793 // incremental-log (only if heads changed) -> parents
|
Chris@150
|
1794 //
|
Chris@121
|
1795 // Sequence when full log required:
|
Chris@163
|
1796 // paths -> branch -> stat -> resolve-list -> heads -> parents -> log
|
Chris@150
|
1797 //
|
Chris@150
|
1798 // Note we want to call enableDisableActions only once, at the end
|
Chris@150
|
1799 // of whichever sequence is in use.
|
Chris@150
|
1800
|
Chris@156
|
1801 bool noMore = false;
|
Chris@156
|
1802
|
Chris@150
|
1803 switch (action) {
|
Chris@175
|
1804
|
Chris@175
|
1805 case ACT_TEST_HG:
|
Chris@200
|
1806 hgTestExtension();
|
Chris@200
|
1807 break;
|
Chris@200
|
1808
|
Chris@200
|
1809 case ACT_TEST_HG_EXT:
|
Chris@175
|
1810 hgQueryPaths();
|
Chris@175
|
1811 break;
|
Chris@150
|
1812
|
Chris@150
|
1813 case ACT_QUERY_PATHS:
|
Chris@109
|
1814 hgQueryBranch();
|
Chris@150
|
1815 break;
|
Chris@150
|
1816
|
Chris@150
|
1817 case ACT_QUERY_BRANCH:
|
Chris@109
|
1818 hgStat();
|
Chris@150
|
1819 break;
|
Chris@150
|
1820
|
Chris@150
|
1821 case ACT_STAT:
|
Chris@163
|
1822 hgResolveList();
|
Chris@163
|
1823 break;
|
Chris@163
|
1824
|
Chris@163
|
1825 case ACT_RESOLVE_LIST:
|
Chris@150
|
1826 hgQueryHeads();
|
Chris@150
|
1827 break;
|
Chris@150
|
1828
|
Chris@150
|
1829 case ACT_QUERY_HEADS:
|
Chris@150
|
1830 if (headsChanged && !needNewLog) {
|
Chris@150
|
1831 hgLogIncremental(oldHeadIds);
|
Chris@121
|
1832 } else {
|
Chris@150
|
1833 hgQueryParents();
|
Chris@121
|
1834 }
|
Chris@150
|
1835 break;
|
Chris@150
|
1836
|
Chris@150
|
1837 case ACT_LOG_INCREMENTAL:
|
Chris@109
|
1838 hgQueryParents();
|
Chris@150
|
1839 break;
|
Chris@150
|
1840
|
Chris@150
|
1841 case ACT_QUERY_PARENTS:
|
Chris@120
|
1842 if (needNewLog) {
|
Chris@120
|
1843 hgLog();
|
Chris@150
|
1844 } else {
|
Chris@150
|
1845 // we're done
|
Chris@156
|
1846 noMore = true;
|
Chris@120
|
1847 }
|
Chris@150
|
1848 break;
|
Chris@150
|
1849
|
Chris@150
|
1850 case ACT_LOG:
|
Chris@150
|
1851 // we're done
|
Chris@156
|
1852 noMore = true;
|
Chris@198
|
1853 break;
|
Chris@150
|
1854
|
Chris@150
|
1855 default:
|
Chris@109
|
1856 if (shouldHgStat) {
|
Chris@163
|
1857 shouldHgStat = false;
|
Chris@109
|
1858 hgQueryPaths();
|
Chris@150
|
1859 } else {
|
Chris@156
|
1860 noMore = true;
|
jtkorhonen@0
|
1861 }
|
Chris@150
|
1862 break;
|
Chris@150
|
1863 }
|
Chris@156
|
1864
|
Chris@156
|
1865 if (noMore) {
|
Chris@173
|
1866 stateUnknown = false;
|
Chris@156
|
1867 enableDisableActions();
|
Chris@156
|
1868 hgTabs->updateHistory();
|
Chris@156
|
1869 }
|
jtkorhonen@0
|
1870 }
|
jtkorhonen@0
|
1871
|
jtkorhonen@0
|
1872 void MainWindow::connectActions()
|
jtkorhonen@0
|
1873 {
|
jtkorhonen@0
|
1874 connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
|
jtkorhonen@0
|
1875 connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
|
jtkorhonen@0
|
1876
|
Chris@120
|
1877 connect(hgRefreshAct, SIGNAL(triggered()), this, SLOT(hgRefresh()));
|
jtkorhonen@0
|
1878 connect(hgRemoveAct, SIGNAL(triggered()), this, SLOT(hgRemove()));
|
jtkorhonen@0
|
1879 connect(hgAddAct, SIGNAL(triggered()), this, SLOT(hgAdd()));
|
jtkorhonen@0
|
1880 connect(hgCommitAct, SIGNAL(triggered()), this, SLOT(hgCommit()));
|
jtkorhonen@0
|
1881 connect(hgFolderDiffAct, SIGNAL(triggered()), this, SLOT(hgFolderDiff()));
|
jtkorhonen@0
|
1882 connect(hgUpdateAct, SIGNAL(triggered()), this, SLOT(hgUpdate()));
|
jtkorhonen@0
|
1883 connect(hgRevertAct, SIGNAL(triggered()), this, SLOT(hgRevert()));
|
jtkorhonen@0
|
1884 connect(hgMergeAct, SIGNAL(triggered()), this, SLOT(hgMerge()));
|
jtkorhonen@34
|
1885 connect(hgIgnoreAct, SIGNAL(triggered()), this, SLOT(hgIgnore()));
|
jtkorhonen@0
|
1886
|
jtkorhonen@0
|
1887 connect(settingsAct, SIGNAL(triggered()), this, SLOT(settings()));
|
Chris@69
|
1888 connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
|
Chris@182
|
1889 connect(changeRemoteRepoAct, SIGNAL(triggered()), this, SLOT(changeRemoteRepo()));
|
jtkorhonen@0
|
1890
|
jtkorhonen@0
|
1891 connect(hgIncomingAct, SIGNAL(triggered()), this, SLOT(hgIncoming()));
|
jtkorhonen@0
|
1892 connect(hgPullAct, SIGNAL(triggered()), this, SLOT(hgPull()));
|
jtkorhonen@0
|
1893 connect(hgPushAct, SIGNAL(triggered()), this, SLOT(hgPush()));
|
jtkorhonen@0
|
1894
|
jtkorhonen@0
|
1895 connect(hgAnnotateAct, SIGNAL(triggered()), this, SLOT(hgAnnotate()));
|
jtkorhonen@11
|
1896 connect(hgServeAct, SIGNAL(triggered()), this, SLOT(hgServe()));
|
jtkorhonen@0
|
1897 }
|
Chris@141
|
1898
|
Chris@141
|
1899 void MainWindow::connectTabsSignals()
|
Chris@141
|
1900 {
|
Chris@141
|
1901 connect(hgTabs, SIGNAL(commit()),
|
Chris@141
|
1902 this, SLOT(hgCommit()));
|
Chris@141
|
1903
|
Chris@141
|
1904 connect(hgTabs, SIGNAL(revert()),
|
Chris@141
|
1905 this, SLOT(hgRevert()));
|
Chris@141
|
1906
|
Chris@141
|
1907 connect(hgTabs, SIGNAL(diffWorkingFolder()),
|
Chris@141
|
1908 this, SLOT(hgFolderDiff()));
|
Chris@168
|
1909
|
Chris@168
|
1910 connect(hgTabs, SIGNAL(showSummary()),
|
Chris@168
|
1911 this, SLOT(hgShowSummary()));
|
Chris@148
|
1912
|
Chris@141
|
1913 connect(hgTabs, SIGNAL(updateTo(QString)),
|
Chris@148
|
1914 this, SLOT(hgUpdateToRev(QString)));
|
Chris@141
|
1915
|
Chris@141
|
1916 connect(hgTabs, SIGNAL(diffToCurrent(QString)),
|
Chris@148
|
1917 this, SLOT(hgDiffToCurrent(QString)));
|
Chris@141
|
1918
|
Chris@148
|
1919 connect(hgTabs, SIGNAL(diffToParent(QString, QString)),
|
Chris@148
|
1920 this, SLOT(hgDiffToParent(QString, QString)));
|
Chris@141
|
1921
|
Chris@141
|
1922 connect(hgTabs, SIGNAL(mergeFrom(QString)),
|
Chris@148
|
1923 this, SLOT(hgMergeFrom(QString)));
|
Chris@164
|
1924
|
Chris@141
|
1925 connect(hgTabs, SIGNAL(tag(QString)),
|
Chris@148
|
1926 this, SLOT(hgTag(QString)));
|
Chris@141
|
1927 }
|
Chris@141
|
1928
|
jtkorhonen@0
|
1929 void MainWindow::enableDisableActions()
|
jtkorhonen@0
|
1930 {
|
Chris@90
|
1931 DEBUG << "MainWindow::enableDisableActions" << endl;
|
Chris@90
|
1932
|
Chris@202
|
1933 QString dirname = QDir(workFolderPath).dirName();
|
Chris@202
|
1934 if (dirname != "") {
|
Chris@202
|
1935 setWindowTitle(tr("EasyMercurial: %1").arg(dirname));
|
Chris@202
|
1936 } else {
|
Chris@202
|
1937 setWindowTitle(tr("EasyMercurial"));
|
Chris@202
|
1938 }
|
Chris@202
|
1939
|
Chris@115
|
1940 //!!! should also do things like set the status texts for the
|
Chris@115
|
1941 //!!! actions appropriately by context
|
Chris@115
|
1942
|
jtkorhonen@0
|
1943 QDir localRepoDir;
|
jtkorhonen@0
|
1944 QDir workFolderDir;
|
Chris@145
|
1945 bool workFolderExist = true;
|
Chris@145
|
1946 bool localRepoExist = true;
|
jtkorhonen@0
|
1947
|
jtkorhonen@0
|
1948 remoteRepoActionsEnabled = true;
|
Chris@90
|
1949 if (remoteRepoPath.isEmpty()) {
|
jtkorhonen@0
|
1950 remoteRepoActionsEnabled = false;
|
jtkorhonen@0
|
1951 }
|
jtkorhonen@0
|
1952
|
jtkorhonen@0
|
1953 localRepoActionsEnabled = true;
|
Chris@90
|
1954 if (workFolderPath.isEmpty()) {
|
jtkorhonen@0
|
1955 localRepoActionsEnabled = false;
|
jtkorhonen@0
|
1956 workFolderExist = false;
|
jtkorhonen@0
|
1957 }
|
jtkorhonen@0
|
1958
|
Chris@90
|
1959 if (!workFolderDir.exists(workFolderPath)) {
|
jtkorhonen@0
|
1960 localRepoActionsEnabled = false;
|
jtkorhonen@0
|
1961 workFolderExist = false;
|
Chris@90
|
1962 } else {
|
jtkorhonen@0
|
1963 workFolderExist = true;
|
jtkorhonen@0
|
1964 }
|
jtkorhonen@0
|
1965
|
Chris@112
|
1966 if (!localRepoDir.exists(workFolderPath + "/.hg")) {
|
jtkorhonen@0
|
1967 localRepoActionsEnabled = false;
|
jtkorhonen@0
|
1968 localRepoExist = false;
|
jtkorhonen@0
|
1969 }
|
jtkorhonen@0
|
1970
|
jtkorhonen@0
|
1971 hgIncomingAct -> setEnabled(remoteRepoActionsEnabled && remoteRepoActionsEnabled);
|
jtkorhonen@0
|
1972 hgPullAct -> setEnabled(remoteRepoActionsEnabled && remoteRepoActionsEnabled);
|
jtkorhonen@0
|
1973 hgPushAct -> setEnabled(remoteRepoActionsEnabled && remoteRepoActionsEnabled);
|
Chris@169
|
1974
|
Chris@179
|
1975 bool haveDiff = false;
|
Chris@179
|
1976 QSettings settings;
|
Chris@179
|
1977 settings.beginGroup("Locations");
|
Chris@179
|
1978 if (settings.value("extdiffbinary", "").toString() != "") {
|
Chris@179
|
1979 haveDiff = true;
|
Chris@179
|
1980 }
|
Chris@179
|
1981 settings.endGroup();
|
Chris@112
|
1982
|
Chris@120
|
1983 hgRefreshAct -> setEnabled(localRepoActionsEnabled);
|
Chris@112
|
1984 hgFolderDiffAct -> setEnabled(localRepoActionsEnabled && haveDiff);
|
jtkorhonen@0
|
1985 hgRevertAct -> setEnabled(localRepoActionsEnabled);
|
jtkorhonen@0
|
1986 hgAddAct -> setEnabled(localRepoActionsEnabled);
|
jtkorhonen@0
|
1987 hgRemoveAct -> setEnabled(localRepoActionsEnabled);
|
jtkorhonen@0
|
1988 hgUpdateAct -> setEnabled(localRepoActionsEnabled);
|
jtkorhonen@0
|
1989 hgCommitAct -> setEnabled(localRepoActionsEnabled);
|
jtkorhonen@0
|
1990 hgMergeAct -> setEnabled(localRepoActionsEnabled);
|
jtkorhonen@2
|
1991 hgAnnotateAct -> setEnabled(localRepoActionsEnabled);
|
jtkorhonen@11
|
1992 hgServeAct -> setEnabled(localRepoActionsEnabled);
|
jtkorhonen@34
|
1993 hgIgnoreAct -> setEnabled(localRepoActionsEnabled);
|
jtkorhonen@0
|
1994
|
Chris@90
|
1995 DEBUG << "localRepoActionsEnabled = " << localRepoActionsEnabled << endl;
|
Chris@98
|
1996 DEBUG << "canCommit = " << hgTabs->canCommit() << endl;
|
Chris@90
|
1997
|
Chris@98
|
1998 hgAddAct->setEnabled(localRepoActionsEnabled && hgTabs->canAdd());
|
Chris@98
|
1999 hgRemoveAct->setEnabled(localRepoActionsEnabled && hgTabs->canRemove());
|
Chris@98
|
2000 hgCommitAct->setEnabled(localRepoActionsEnabled && hgTabs->canCommit());
|
Chris@163
|
2001 hgRevertAct->setEnabled(localRepoActionsEnabled && hgTabs->canRevert());
|
Chris@163
|
2002 hgFolderDiffAct->setEnabled(localRepoActionsEnabled && hgTabs->canDiff());
|
Chris@90
|
2003
|
Chris@108
|
2004 // A default merge makes sense if:
|
Chris@108
|
2005 // * there is only one parent (if there are two, we have an uncommitted merge) and
|
Chris@108
|
2006 // * there are exactly two heads that have the same branch as the current branch and
|
Chris@108
|
2007 // * our parent is one of those heads
|
Chris@108
|
2008 //
|
Chris@108
|
2009 // A default update makes sense if:
|
Chris@108
|
2010 // * there is only one parent and
|
Chris@108
|
2011 // * the parent is not one of the current heads
|
Chris@156
|
2012
|
Chris@108
|
2013 bool canMerge = false;
|
Chris@108
|
2014 bool canUpdate = false;
|
Chris@156
|
2015 bool haveMerge = false;
|
Chris@162
|
2016 bool emptyRepo = false;
|
Chris@156
|
2017 int currentBranchHeads = 0;
|
Chris@156
|
2018
|
Chris@108
|
2019 if (currentParents.size() == 1) {
|
Chris@156
|
2020 bool parentIsHead = false;
|
Chris@108
|
2021 Changeset *parent = currentParents[0];
|
Chris@108
|
2022 foreach (Changeset *head, currentHeads) {
|
Chris@108
|
2023 DEBUG << "head branch " << head->branch() << ", current branch " << currentBranch << endl;
|
Chris@108
|
2024 if (head->isOnBranch(currentBranch)) {
|
Chris@108
|
2025 ++currentBranchHeads;
|
Chris@108
|
2026 if (parent->id() == head->id()) {
|
Chris@108
|
2027 parentIsHead = true;
|
Chris@108
|
2028 }
|
Chris@108
|
2029 }
|
Chris@108
|
2030 }
|
Chris@108
|
2031 if (currentBranchHeads == 2 && parentIsHead) {
|
Chris@108
|
2032 canMerge = true;
|
Chris@108
|
2033 }
|
Chris@108
|
2034 if (!parentIsHead) {
|
Chris@108
|
2035 canUpdate = true;
|
Chris@108
|
2036 DEBUG << "parent id = " << parent->id() << endl;
|
Chris@108
|
2037 DEBUG << " head ids "<<endl;
|
Chris@108
|
2038 foreach (Changeset *h, currentHeads) {
|
Chris@108
|
2039 DEBUG << "head id = " << h->id() << endl;
|
Chris@108
|
2040 }
|
Chris@108
|
2041 }
|
Chris@162
|
2042 } else if (currentParents.size() == 0) {
|
Chris@162
|
2043 emptyRepo = true;
|
Chris@156
|
2044 } else {
|
Chris@156
|
2045 haveMerge = true;
|
Chris@163
|
2046 justMerged = true;
|
Chris@108
|
2047 }
|
Chris@156
|
2048
|
Chris@163
|
2049 hgMergeAct->setEnabled(localRepoActionsEnabled &&
|
Chris@163
|
2050 (canMerge || hgTabs->canResolve()));
|
Chris@163
|
2051 hgUpdateAct->setEnabled(localRepoActionsEnabled &&
|
Chris@172
|
2052 (canUpdate && !hgTabs->haveChangesToCommit()));
|
Chris@115
|
2053
|
Chris@115
|
2054 // Set the state field on the file status widget
|
Chris@115
|
2055
|
Chris@115
|
2056 QString branchText;
|
Chris@115
|
2057 if (currentBranch == "" || currentBranch == "default") {
|
Chris@115
|
2058 branchText = tr("the default branch");
|
Chris@115
|
2059 } else {
|
Chris@115
|
2060 branchText = tr("branch \"%1\"").arg(currentBranch);
|
Chris@115
|
2061 }
|
Chris@156
|
2062
|
Chris@173
|
2063 if (stateUnknown) {
|
Chris@173
|
2064 hgTabs->setState(tr("(Examining repository)"));
|
Chris@173
|
2065 } else if (emptyRepo) {
|
Chris@162
|
2066 hgTabs->setState(tr("Nothing committed to this repository yet"));
|
Chris@162
|
2067 } else if (canMerge) {
|
Chris@156
|
2068 hgTabs->setState(tr("<b>Awaiting merge</b> on %1").arg(branchText));
|
Chris@163
|
2069 } else if (!hgTabs->getAllUnresolvedFiles().empty()) {
|
Chris@163
|
2070 hgTabs->setState(tr("Have unresolved files following merge on %1").arg(branchText));
|
Chris@156
|
2071 } else if (haveMerge) {
|
Chris@157
|
2072 hgTabs->setState(tr("Have merged but not yet committed on %1").arg(branchText));
|
Chris@156
|
2073 } else if (canUpdate) {
|
Chris@172
|
2074 if (hgTabs->haveChangesToCommit()) {
|
Chris@163
|
2075 // have uncommitted changes
|
Chris@163
|
2076 hgTabs->setState(tr("On %1. Not at the head of the branch").arg(branchText));
|
Chris@163
|
2077 } else {
|
Chris@163
|
2078 // no uncommitted changes
|
Chris@163
|
2079 hgTabs->setState(tr("On %1. Not at the head of the branch: consider updating").arg(branchText));
|
Chris@163
|
2080 }
|
Chris@156
|
2081 } else if (currentBranchHeads > 1) {
|
Chris@156
|
2082 hgTabs->setState(tr("At one of %n heads of %1", "", currentBranchHeads).arg(branchText));
|
Chris@115
|
2083 } else {
|
Chris@115
|
2084 hgTabs->setState(tr("At the head of %1").arg(branchText));
|
Chris@115
|
2085 }
|
jtkorhonen@0
|
2086 }
|
jtkorhonen@0
|
2087
|
jtkorhonen@0
|
2088 void MainWindow::createActions()
|
jtkorhonen@0
|
2089 {
|
jtkorhonen@0
|
2090 //File actions
|
Chris@69
|
2091 openAct = new QAction(QIcon(":/images/fileopen.png"), tr("Open..."), this);
|
Chris@199
|
2092 openAct -> setStatusTip(tr("Open an existing repository or working folder"));
|
Chris@69
|
2093
|
Chris@182
|
2094 changeRemoteRepoAct = new QAction(tr("Change Remote Location..."), this);
|
Chris@182
|
2095 changeRemoteRepoAct->setStatusTip(tr("Change the default remote repository for pull and push actions"));
|
Chris@182
|
2096
|
jtkorhonen@0
|
2097 settingsAct = new QAction(QIcon(":/images/settings.png"), tr("Settings..."), this);
|
jtkorhonen@0
|
2098 settingsAct -> setStatusTip(tr("View and change application settings"));
|
jtkorhonen@0
|
2099
|
Chris@169
|
2100 exitAct = new QAction(QIcon(":/images/exit.png"), tr("Quit"), this);
|
jtkorhonen@0
|
2101 exitAct->setShortcuts(QKeySequence::Quit);
|
Chris@169
|
2102 exitAct->setStatusTip(tr("Quit EasyMercurial"));
|
jtkorhonen@0
|
2103
|
jtkorhonen@0
|
2104 //Repository actions
|
Chris@120
|
2105 hgRefreshAct = new QAction(QIcon(":/images/status.png"), tr("Refresh"), this);
|
Chris@178
|
2106 hgRefreshAct->setStatusTip(tr("Refresh the window to show the current state of the working folder"));
|
Chris@61
|
2107
|
Chris@61
|
2108 hgIncomingAct = new QAction(QIcon(":/images/incoming.png"), tr("Preview"), this);
|
Chris@169
|
2109 hgIncomingAct -> setStatusTip(tr("See what changes are available in the remote repository waiting to be pulled"));
|
jtkorhonen@0
|
2110
|
Chris@61
|
2111 hgPullAct = new QAction(QIcon(":/images/pull.png"), tr("Pull"), this);
|
Chris@169
|
2112 hgPullAct -> setStatusTip(tr("Pull changes from the remote repository to the local repository"));
|
jtkorhonen@0
|
2113
|
Chris@61
|
2114 hgPushAct = new QAction(QIcon(":/images/push.png"), tr("Push"), this);
|
Chris@169
|
2115 hgPushAct->setStatusTip(tr("Push changes from the local repository to the remote repository"));
|
jtkorhonen@0
|
2116
|
jtkorhonen@0
|
2117 //Workfolder actions
|
Chris@99
|
2118 hgFolderDiffAct = new QAction(QIcon(":/images/folderdiff.png"), tr("Diff"), this);
|
Chris@169
|
2119 hgFolderDiffAct->setStatusTip(tr("See what has changed in the working folder compared with the last committed state"));
|
jtkorhonen@0
|
2120
|
Chris@61
|
2121 hgRevertAct = new QAction(QIcon(":/images/undo.png"), tr("Revert"), this);
|
Chris@169
|
2122 hgRevertAct->setStatusTip(tr("Throw away your changes and return to the last committed state"));
|
jtkorhonen@0
|
2123
|
Chris@61
|
2124 hgAddAct = new QAction(QIcon(":/images/add.png"), tr("Add"), this);
|
Chris@169
|
2125 hgAddAct -> setStatusTip(tr("Mark the selected file(s) to be added on the next commit"));
|
jtkorhonen@0
|
2126
|
Chris@169
|
2127 //!!! needs to be modified for number
|
Chris@61
|
2128 hgRemoveAct = new QAction(QIcon(":/images/remove.png"), tr("Remove"), this);
|
Chris@169
|
2129 hgRemoveAct -> setStatusTip(tr("Mark the selected file(s) to be removed from version control on the next commit"));
|
jtkorhonen@0
|
2130
|
Chris@61
|
2131 hgUpdateAct = new QAction(QIcon(":/images/update.png"), tr("Update"), this);
|
Chris@169
|
2132 hgUpdateAct->setStatusTip(tr("Update the working folder to the head of the current repository branch"));
|
jtkorhonen@0
|
2133
|
Chris@169
|
2134 //!!! needs to be modified when files selected
|
Chris@61
|
2135 hgCommitAct = new QAction(QIcon(":/images/commit.png"), tr("Commit"), this);
|
Chris@169
|
2136 hgCommitAct->setStatusTip(tr("Commit your changes to the local repository"));
|
jtkorhonen@0
|
2137
|
jtkorhonen@0
|
2138 hgMergeAct = new QAction(QIcon(":/images/merge.png"), tr("Merge"), this);
|
Chris@169
|
2139 hgMergeAct->setStatusTip(tr("Merge the two independent sets of changes in the local repository into the working folder"));
|
jtkorhonen@0
|
2140
|
jtkorhonen@0
|
2141 //Advanced actions
|
Chris@169
|
2142 //!!! needs to be modified for number
|
jtkorhonen@0
|
2143 hgAnnotateAct = new QAction(tr("Annotate"), this);
|
jtkorhonen@0
|
2144 hgAnnotateAct -> setStatusTip(tr("Show line-by-line version information for selected file"));
|
jtkorhonen@0
|
2145
|
Chris@182
|
2146 hgIgnoreAct = new QAction(tr("Edit .hgignore File"), this);
|
Chris@169
|
2147 hgIgnoreAct -> setStatusTip(tr("Edit the .hgignore file, containing the names of files that should be ignored by Mercurial"));
|
jtkorhonen@34
|
2148
|
Chris@182
|
2149 hgServeAct = new QAction(tr("Serve via HTTP"), this);
|
jtkorhonen@11
|
2150 hgServeAct -> setStatusTip(tr("Serve local repository via http for workgroup access"));
|
jtkorhonen@11
|
2151
|
jtkorhonen@0
|
2152 //Help actions
|
Chris@190
|
2153 aboutAct = new QAction(tr("About EasyMercurial"), this);
|
Chris@94
|
2154
|
Chris@94
|
2155 // Miscellaneous
|
Chris@199
|
2156 QShortcut *clearSelectionsShortcut = new QShortcut(Qt::Key_Escape, this);
|
Chris@199
|
2157 connect(clearSelectionsShortcut, SIGNAL(activated()),
|
Chris@199
|
2158 this, SLOT(clearSelections()));
|
jtkorhonen@0
|
2159 }
|
jtkorhonen@0
|
2160
|
jtkorhonen@0
|
2161 void MainWindow::createMenus()
|
jtkorhonen@0
|
2162 {
|
jtkorhonen@0
|
2163 fileMenu = menuBar()->addMenu(tr("File"));
|
Chris@169
|
2164
|
Chris@69
|
2165 fileMenu -> addAction(openAct);
|
Chris@182
|
2166 fileMenu -> addAction(changeRemoteRepoAct);
|
Chris@191
|
2167 fileMenu -> addSeparator();
|
Chris@191
|
2168
|
Chris@191
|
2169 advancedMenu = fileMenu->addMenu(tr("Advanced"));
|
Chris@191
|
2170
|
jtkorhonen@0
|
2171 fileMenu -> addAction(settingsAct);
|
Chris@191
|
2172
|
jtkorhonen@0
|
2173 fileMenu -> addSeparator();
|
jtkorhonen@0
|
2174 fileMenu -> addAction(exitAct);
|
jtkorhonen@0
|
2175
|
jtkorhonen@34
|
2176 advancedMenu -> addAction(hgIgnoreAct);
|
Chris@199
|
2177 advancedMenu -> addSeparator();
|
jtkorhonen@11
|
2178 advancedMenu -> addAction(hgServeAct);
|
jtkorhonen@0
|
2179
|
jtkorhonen@0
|
2180 helpMenu = menuBar()->addMenu(tr("Help"));
|
jtkorhonen@0
|
2181 helpMenu->addAction(aboutAct);
|
jtkorhonen@0
|
2182 }
|
jtkorhonen@0
|
2183
|
jtkorhonen@0
|
2184 void MainWindow::createToolBars()
|
jtkorhonen@0
|
2185 {
|
jtkorhonen@0
|
2186 fileToolBar = addToolBar(tr("File"));
|
jtkorhonen@0
|
2187 fileToolBar -> setIconSize(QSize(MY_ICON_SIZE, MY_ICON_SIZE));
|
Chris@69
|
2188 fileToolBar -> addAction(openAct);
|
Chris@120
|
2189 fileToolBar -> addAction(hgRefreshAct);
|
jtkorhonen@0
|
2190 fileToolBar -> addSeparator();
|
jtkorhonen@0
|
2191 fileToolBar -> setMovable(false);
|
jtkorhonen@0
|
2192
|
jtkorhonen@0
|
2193 repoToolBar = addToolBar(tr(REPOMENU_TITLE));
|
jtkorhonen@0
|
2194 repoToolBar -> setIconSize(QSize(MY_ICON_SIZE, MY_ICON_SIZE));
|
jtkorhonen@0
|
2195 repoToolBar->addAction(hgIncomingAct);
|
jtkorhonen@0
|
2196 repoToolBar->addAction(hgPullAct);
|
jtkorhonen@0
|
2197 repoToolBar->addAction(hgPushAct);
|
jtkorhonen@0
|
2198 repoToolBar -> setMovable(false);
|
jtkorhonen@0
|
2199
|
jtkorhonen@0
|
2200 workFolderToolBar = addToolBar(tr(WORKFOLDERMENU_TITLE));
|
jtkorhonen@0
|
2201 addToolBar(Qt::LeftToolBarArea, workFolderToolBar);
|
jtkorhonen@0
|
2202 workFolderToolBar -> setIconSize(QSize(MY_ICON_SIZE, MY_ICON_SIZE));
|
Chris@95
|
2203 workFolderToolBar->addAction(hgFolderDiffAct);
|
jtkorhonen@0
|
2204 workFolderToolBar->addSeparator();
|
jtkorhonen@0
|
2205 workFolderToolBar->addAction(hgRevertAct);
|
jtkorhonen@0
|
2206 workFolderToolBar->addAction(hgUpdateAct);
|
jtkorhonen@0
|
2207 workFolderToolBar->addAction(hgCommitAct);
|
jtkorhonen@0
|
2208 workFolderToolBar->addAction(hgMergeAct);
|
jtkorhonen@0
|
2209 workFolderToolBar->addSeparator();
|
jtkorhonen@0
|
2210 workFolderToolBar->addAction(hgAddAct);
|
jtkorhonen@0
|
2211 workFolderToolBar->addAction(hgRemoveAct);
|
jtkorhonen@0
|
2212 workFolderToolBar -> setMovable(false);
|
Chris@61
|
2213
|
Chris@61
|
2214 foreach (QToolButton *tb, findChildren<QToolButton *>()) {
|
Chris@61
|
2215 tb->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
|
Chris@61
|
2216 }
|
jtkorhonen@0
|
2217 }
|
jtkorhonen@0
|
2218
|
jtkorhonen@0
|
2219
|
jtkorhonen@0
|
2220 void MainWindow::createStatusBar()
|
jtkorhonen@0
|
2221 {
|
jtkorhonen@0
|
2222 statusBar()->showMessage(tr("Ready"));
|
jtkorhonen@0
|
2223 }
|
jtkorhonen@0
|
2224
|
Chris@69
|
2225
|
Chris@69
|
2226 //!!! review these:
|
Chris@69
|
2227
|
jtkorhonen@0
|
2228 void MainWindow::readSettings()
|
jtkorhonen@0
|
2229 {
|
jtkorhonen@0
|
2230 QDir workFolder;
|
jtkorhonen@0
|
2231
|
Chris@61
|
2232 QSettings settings;
|
jtkorhonen@0
|
2233
|
jtkorhonen@30
|
2234 remoteRepoPath = settings.value("remoterepopath", "").toString();
|
jtkorhonen@0
|
2235 workFolderPath = settings.value("workfolderpath", "").toString();
|
jtkorhonen@0
|
2236 if (!workFolder.exists(workFolderPath))
|
jtkorhonen@0
|
2237 {
|
jtkorhonen@0
|
2238 workFolderPath = "";
|
jtkorhonen@0
|
2239 }
|
jtkorhonen@0
|
2240
|
jtkorhonen@0
|
2241 QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
|
jtkorhonen@0
|
2242 QSize size = settings.value("size", QSize(400, 400)).toSize();
|
jtkorhonen@0
|
2243 firstStart = settings.value("firststart", QVariant(true)).toBool();
|
jtkorhonen@0
|
2244
|
Chris@109
|
2245 //!!! initialFileTypesBits = (unsigned char) settings.value("viewFileTypes", QVariant(DEFAULT_HG_STAT_BITS)).toInt();
|
jtkorhonen@0
|
2246 resize(size);
|
jtkorhonen@0
|
2247 move(pos);
|
jtkorhonen@0
|
2248 }
|
jtkorhonen@0
|
2249
|
jtkorhonen@17
|
2250
|
jtkorhonen@0
|
2251 void MainWindow::writeSettings()
|
jtkorhonen@0
|
2252 {
|
Chris@61
|
2253 QSettings settings;
|
jtkorhonen@0
|
2254 settings.setValue("pos", pos());
|
jtkorhonen@0
|
2255 settings.setValue("size", size());
|
jtkorhonen@0
|
2256 settings.setValue("remoterepopath", remoteRepoPath);
|
jtkorhonen@0
|
2257 settings.setValue("workfolderpath", workFolderPath);
|
jtkorhonen@0
|
2258 settings.setValue("firststart", firstStart);
|
Chris@98
|
2259 //!!!settings.setValue("viewFileTypes", hgTabs -> getFileTypesBits());
|
jtkorhonen@0
|
2260 }
|
jtkorhonen@0
|
2261
|
jtkorhonen@0
|
2262
|
jtkorhonen@0
|
2263
|
jtkorhonen@0
|
2264
|