3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
14 #include "GuiChanges.h"
16 #include "qt_helpers.h"
18 #include "support/gettext.h"
19 #include "support/lstrings.h"
20 #include "support/lyxtime.h"
24 #include "BufferParams.h"
25 #include "BufferView.h"
28 #include "FuncRequest.h"
33 #include <QTextBrowser>
40 GuiChanges::GuiChanges(GuiView & lv)
41 : GuiDialog(lv, "changes", qt_("Merge Changes"))
45 connect(buttonBox, SIGNAL(clicked(QAbstractButton *)),
46 this, SLOT(slotButtonBox(QAbstractButton *)));
47 connect(nextPB, SIGNAL(clicked()), this, SLOT(nextChange()));
48 connect(previousPB, SIGNAL(clicked()), this, SLOT(previousChange()));
49 connect(rejectPB, SIGNAL(clicked()), this, SLOT(rejectChange()));
50 connect(acceptPB, SIGNAL(clicked()), this, SLOT(acceptChange()));
52 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
53 bc().setCancel(buttonBox->button(QDialogButtonBox::Cancel));
54 bc().addReadOnly(acceptPB);
55 bc().addReadOnly(rejectPB);
59 void GuiChanges::updateContents()
61 bool const changesPresent = buffer().areChangesPresent();
62 nextPB->setEnabled(changesPresent);
63 previousPB->setEnabled(changesPresent);
64 changeTB->setEnabled(changesPresent);
66 Change const & c = bufferview()->getCurrentChange();
67 bool const changePresent = c.type != Change::UNCHANGED;
68 rejectPB->setEnabled(changePresent);
69 acceptPB->setEnabled(changePresent);
70 bool const inserted = c.type == Change::INSERTED;
74 QString const author =
75 toqstr(buffer().params().authors().get(c.author).nameAndEmail());
76 if (!author.isEmpty())
77 text += inserted ? qt_("Inserted by %1").arg(author)
78 : qt_("Deleted by %1").arg(author);
80 QString const date = QDateTime::fromTime_t(c.changetime)
81 .toString(Qt::DefaultLocaleLongDate);
82 if (!date.isEmpty()) {
83 if (!author.isEmpty())
84 text += qt_(" on[[date]] %1").arg(date);
86 text += inserted ? qt_("Inserted on %1").arg(date)
87 : qt_("Deleted on %1").arg(date);
89 QString changedcontent = toqstr(bufferview()->cursor().selectionAsString(false));
90 if (!changedcontent.isEmpty()) {
91 text += ":<br><br><b>";
93 text += "<u><span style=\"color:blue\">";
95 text += "<s><span style=\"color:red\">";
96 text += changedcontent;
98 text += "</u></span></b>";
100 text += "</s></span></b>";
103 changeTB->setHtml(text);
107 void GuiChanges::nextChange()
109 dispatch(FuncRequest(LFUN_CHANGE_NEXT));
113 void GuiChanges::previousChange()
115 dispatch(FuncRequest(LFUN_CHANGE_PREVIOUS));
119 void GuiChanges::acceptChange()
121 dispatch(FuncRequest(LFUN_CHANGE_ACCEPT));
126 void GuiChanges::rejectChange()
128 dispatch(FuncRequest(LFUN_CHANGE_REJECT));
133 Dialog * createGuiChanges(GuiView & lv) { return new GuiChanges(lv); }
136 } // namespace frontend
139 #include "moc_GuiChanges.cpp"