#include <config.h>
#include "GuiChanges.h"
-#include "Qt2BC.h"
+
#include "qt_helpers.h"
+#include "support/gettext.h"
#include "support/lstrings.h"
+#include "support/lyxtime.h"
-#include <QCloseEvent>
-#include <QTextBrowser>
+#include "Author.h"
+#include "Buffer.h"
+#include "BufferParams.h"
+#include "BufferView.h"
+#include "Changes.h"
+#include "FuncRequest.h"
+#include "LyXRC.h"
-using lyx::support::bformat;
+#include <QDateTime>
+#include <QTextBrowser>
namespace lyx {
namespace frontend {
-/////////////////////////////////////////////////////////////////////
-//
-// GuiChangesDialog
-//
-/////////////////////////////////////////////////////////////////////
-GuiChangesDialog::GuiChangesDialog(GuiChanges * form)
- : form_(form)
+GuiChanges::GuiChanges(GuiView & lv)
+ : GuiDialog(lv, "changes", qt_("Merge Changes"))
{
setupUi(this);
- connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
- connect(nextPB, SIGNAL(clicked()), this, SLOT(nextPressed()));
- connect(rejectPB, SIGNAL(clicked()), this, SLOT(rejectPressed()));
- connect(acceptPB, SIGNAL(clicked()), this, SLOT(acceptPressed()));
-}
-
-
-void GuiChangesDialog::nextPressed()
-{
- form_->next();
-}
-
-
-void GuiChangesDialog::acceptPressed()
-{
- form_->accept();
-}
+ connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
+ connect(nextPB, SIGNAL(clicked()), this, SLOT(nextChange()));
+ connect(previousPB, SIGNAL(clicked()), this, SLOT(previousChange()));
+ connect(rejectPB, SIGNAL(clicked()), this, SLOT(rejectChange()));
+ connect(acceptPB, SIGNAL(clicked()), this, SLOT(acceptChange()));
-void GuiChangesDialog::rejectPressed()
-{
- form_->reject();
+ bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
+ bc().setCancel(closePB);
+ bc().addReadOnly(acceptPB);
+ bc().addReadOnly(rejectPB);
}
-void GuiChangesDialog::closeEvent(QCloseEvent *e)
+void GuiChanges::updateContents()
{
- form_->slotWMHide();
- e->accept();
+ bool const changesPresent = buffer().areChangesPresent();
+ nextPB->setEnabled(changesPresent);
+ previousPB->setEnabled(changesPresent);
+ changeTB->setEnabled(changesPresent);
+
+ Change const & c = bufferview()->getCurrentChange();
+ bool const changePresent = c.type != Change::UNCHANGED;
+ rejectPB->setEnabled(changePresent);
+ acceptPB->setEnabled(changePresent);
+
+ QString text;
+ if (changePresent) {
+ QString const author =
+ toqstr(buffer().params().authors().get(c.author).nameAndEmail());
+ if (!author.isEmpty())
+ text += qt_("Changed by %1\n\n").arg(author);
+
+ QString const date = QDateTime::fromTime_t(c.changetime)
+ .toString(Qt::DefaultLocaleLongDate);
+ if (!date.isEmpty())
+ text += qt_("Change made on %1\n").arg(date);
+ }
+ changeTB->setPlainText(text);
}
-
-/////////////////////////////////////////////////////////////////////
-//
-// GuiChanges
-//
-/////////////////////////////////////////////////////////////////////
-
-
-GuiChanges::GuiChanges(Dialog & parent)
- : GuiView<GuiChangesDialog>(parent, _("Merge Changes"))
+void GuiChanges::nextChange()
{
+ dispatch(FuncRequest(LFUN_CHANGE_NEXT));
}
-void GuiChanges::build_dialog()
+void GuiChanges::previousChange()
{
- dialog_.reset(new GuiChangesDialog(this));
-
- bcview().setCancel(dialog_->closePB);
- bcview().addReadOnly(dialog_->acceptPB);
- bcview().addReadOnly(dialog_->rejectPB);
+ dispatch(FuncRequest(LFUN_CHANGE_PREVIOUS));
}
-void GuiChanges::update_contents()
+void GuiChanges::acceptChange()
{
- docstring text;
- docstring author = controller().getChangeAuthor();
- docstring date = controller().getChangeDate();
-
- if (!author.empty())
- text += bformat(_("Change by %1$s\n\n"), author);
- if (!date.empty())
- text += bformat(_("Change made at %1$s\n"), date);
-
- dialog_->changeTB->setPlainText(toqstr(text));
+ dispatch(FuncRequest(LFUN_CHANGE_ACCEPT));
+ nextChange();
}
-void GuiChanges::next()
+void GuiChanges::rejectChange()
{
- controller().next();
+ dispatch(FuncRequest(LFUN_CHANGE_REJECT));
+ nextChange();
}
-void GuiChanges::accept()
-{
- controller().accept();
-}
-
+Dialog * createGuiChanges(GuiView & lv) { return new GuiChanges(lv); }
-void GuiChanges::reject()
-{
- controller().reject();
-}
} // namespace frontend
} // namespace lyx
-#include "GuiChanges_moc.cpp"
+#include "moc_GuiChanges.cpp"