]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiChanges.cpp
* fix spelling in comments to please John.
[lyx.git] / src / frontends / qt4 / GuiChanges.cpp
index 7f4bb8b7b81ae2c47ae9a12551288f44e50cae0b..63268ae24e808d3dc3f89428c7649ffd3c5455b7 100644 (file)
 #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 <QTextBrowser>
 
 
 namespace lyx {
 namespace frontend {
 
-/////////////////////////////////////////////////////////////////////
-//
-// GuiChangesDialog
-//
-/////////////////////////////////////////////////////////////////////
+using support::bformat;
 
-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()));
-}
 
+       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::nextPressed()
-{
-       form_->next();
+       bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
+       bc().setCancel(closePB);
+       bc().addReadOnly(acceptPB);
+       bc().addReadOnly(rejectPB);
 }
 
 
-void GuiChangesDialog::acceptPressed()
+void GuiChanges::updateContents()
 {
-       form_->accept();
-}
+       docstring text;
+       docstring author = changeAuthor();
+       docstring date = changeDate();
 
+       if (!author.empty())
+               text += bformat(_("Change by %1$s\n\n"), author);
+       if (!date.empty())
+               text += bformat(_("Change made at %1$s\n"), date);
 
-void GuiChangesDialog::rejectPressed()
-{
-       form_->reject();
+       changeTB->setPlainText(toqstr(text));
 }
 
 
-void GuiChangesDialog::closeEvent(QCloseEvent *e)
+void GuiChanges::nextChange()
 {
-       form_->slotWMHide();
-       e->accept();
+       dispatch(FuncRequest(LFUN_CHANGE_NEXT));
 }
 
 
-
-/////////////////////////////////////////////////////////////////////
-//
-// GuiChanges
-//
-/////////////////////////////////////////////////////////////////////
-
-
-GuiChanges::GuiChanges(Dialog & parent)
-       : GuiView<GuiChangesDialog>(parent, _("Merge Changes"))
+void GuiChanges::previousChange()
 {
+       dispatch(FuncRequest(LFUN_CHANGE_PREVIOUS));
 }
 
 
-void GuiChanges::build_dialog()
+docstring GuiChanges::changeDate() const
 {
-       dialog_.reset(new GuiChangesDialog(this));
+       Change const & c = bufferview()->getCurrentChange();
+       if (c.type == Change::UNCHANGED)
+               return docstring();
 
-       bcview().setCancel(dialog_->closePB);
-       bcview().addReadOnly(dialog_->acceptPB);
-       bcview().addReadOnly(dialog_->rejectPB);
+       // FIXME UNICODE
+       return from_utf8(formatted_time(c.changetime, lyxrc.date_insert_format));
 }
 
 
-void GuiChanges::update_contents()
+docstring GuiChanges::changeAuthor() const
 {
-       docstring text;
-       docstring author = controller().getChangeAuthor();
-       docstring date = controller().getChangeDate();
+       Change const & c = bufferview()->getCurrentChange();
+       if (c.type == Change::UNCHANGED)
+               return docstring();
 
-       if (!author.empty())
-               text += bformat(_("Change by %1$s\n\n"), author);
-       if (!date.empty())
-               text += bformat(_("Change made at %1$s\n"), date);
+       Author const & a = buffer().params().authors().get(c.author);
 
-       dialog_->changeTB->setPlainText(toqstr(text));
-}
+       docstring author = a.name();
 
+       if (!a.email().empty())
+               author += " (" + a.email() + ")";
 
-void GuiChanges::next()
-{
-       controller().next();
+       return author;
 }
 
 
-void GuiChanges::accept()
+void GuiChanges::acceptChange()
 {
-       controller().accept();
+       dispatch(FuncRequest(LFUN_CHANGE_ACCEPT));
+       nextChange();
 }
 
 
-void GuiChanges::reject()
+void GuiChanges::rejectChange()
 {
-       controller().reject();
+       dispatch(FuncRequest(LFUN_CHANGE_REJECT));
+       nextChange();
 }
 
+
+Dialog * createGuiChanges(GuiView & lv) { return new GuiChanges(lv); }
+
+
 } // namespace frontend
 } // namespace lyx
 
-#include "GuiChanges_moc.cpp"
+#include "moc_GuiChanges.cpp"