]> git.lyx.org Git - features.git/blob - src/frontends/qt/GuiChanges.cpp
Improve info in changes dialog
[features.git] / src / frontends / qt / GuiChanges.cpp
1 /**
2  * \file GuiChanges.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  * \author Michael Gerz
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "GuiChanges.h"
15
16 #include "qt_helpers.h"
17
18 #include "support/gettext.h"
19 #include "support/lstrings.h"
20 #include "support/lyxtime.h"
21
22 #include "Author.h"
23 #include "Buffer.h"
24 #include "BufferParams.h"
25 #include "BufferView.h"
26 #include "Changes.h"
27 #include "FuncRequest.h"
28 #include "LyXRC.h"
29
30 #include <QDateTime>
31 #include <QTextBrowser>
32
33
34 namespace lyx {
35 namespace frontend {
36
37
38 GuiChanges::GuiChanges(GuiView & lv)
39         : GuiDialog(lv, "changes", qt_("Merge Changes"))
40 {
41         setupUi(this);
42
43         connect(buttonBox, SIGNAL(clicked(QAbstractButton *)),
44                 this, SLOT(slotButtonBox(QAbstractButton *)));
45         connect(nextPB, SIGNAL(clicked()), this, SLOT(nextChange()));
46         connect(previousPB, SIGNAL(clicked()), this, SLOT(previousChange()));
47         connect(rejectPB, SIGNAL(clicked()), this, SLOT(rejectChange()));
48         connect(acceptPB, SIGNAL(clicked()), this, SLOT(acceptChange()));
49
50         bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
51         bc().setCancel(buttonBox->button(QDialogButtonBox::Cancel));
52         bc().addReadOnly(acceptPB);
53         bc().addReadOnly(rejectPB);
54 }
55
56
57 void GuiChanges::updateContents()
58 {
59         bool const changesPresent = buffer().areChangesPresent();
60         nextPB->setEnabled(changesPresent);
61         previousPB->setEnabled(changesPresent);
62         changeTB->setEnabled(changesPresent);
63
64         Change const & c = bufferview()->getCurrentChange();
65         bool const changePresent = c.type != Change::UNCHANGED;
66         rejectPB->setEnabled(changePresent);
67         acceptPB->setEnabled(changePresent);
68
69         QString text;
70         if (changePresent) {
71                 QString const author =
72                         toqstr(buffer().params().authors().get(c.author).nameAndEmail());
73                 if (!author.isEmpty())
74                         text += (c.type == Change::INSERTED) ? qt_("Inserted by %1").arg(author)
75                                                              : qt_("Deleted by %1").arg(author);
76
77                 QString const date = QDateTime::fromTime_t(c.changetime)
78                                          .toString(Qt::DefaultLocaleLongDate);
79                 if (!date.isEmpty()) {
80                         if (!author.isEmpty())
81                                 text += qt_(" on[[date]] %1\n").arg(date);
82                         else
83                                 text += (c.type == Change::INSERTED) ? qt_("Inserted on %1\n").arg(date)
84                                                                      : qt_("Deleted on %1\n").arg(date);
85                 }
86         }
87         changeTB->setPlainText(text);
88 }
89
90
91 void GuiChanges::nextChange()
92 {
93         dispatch(FuncRequest(LFUN_CHANGE_NEXT));
94 }
95
96
97 void GuiChanges::previousChange()
98 {
99         dispatch(FuncRequest(LFUN_CHANGE_PREVIOUS));
100 }
101
102
103 void GuiChanges::acceptChange()
104 {
105         dispatch(FuncRequest(LFUN_CHANGE_ACCEPT));
106         nextChange();
107 }
108
109
110 void GuiChanges::rejectChange()
111 {
112         dispatch(FuncRequest(LFUN_CHANGE_REJECT));
113         nextChange();
114 }
115
116
117 Dialog * createGuiChanges(GuiView & lv) { return new GuiChanges(lv); }
118
119
120 } // namespace frontend
121 } // namespace lyx
122
123 #include "moc_GuiChanges.cpp"