]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt/GuiChanges.cpp
Fix completion in math when inline completion was not yet shown
[lyx.git] / src / frontends / qt / GuiChanges.cpp
index 150d8a1c3b1a4b5f9ffe67e60704eab2078bdae8..b2f809b026a5bd9c620f339dd060552d09e551d7 100644 (file)
 
 #include "qt_helpers.h"
 
-#include "support/gettext.h"
-#include "support/lstrings.h"
-#include "support/lyxtime.h"
-
 #include "Author.h"
 #include "Buffer.h"
 #include "BufferParams.h"
 #include "BufferView.h"
 #include "Changes.h"
+#include "Cursor.h"
 #include "FuncRequest.h"
 #include "LyXRC.h"
 
@@ -49,8 +46,6 @@ GuiChanges::GuiChanges(GuiView & lv)
 
        bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
        bc().setCancel(buttonBox->button(QDialogButtonBox::Cancel));
-       bc().addReadOnly(acceptPB);
-       bc().addReadOnly(rejectPB);
 }
 
 
@@ -63,28 +58,49 @@ void GuiChanges::updateContents()
 
        Change const & c = bufferview()->getCurrentChange();
        bool const changePresent = c.type != Change::UNCHANGED;
-       rejectPB->setEnabled(changePresent);
-       acceptPB->setEnabled(changePresent);
+       rejectPB->setEnabled(changePresent && !isBufferReadonly());
+       acceptPB->setEnabled(changePresent && !isBufferReadonly());
+       bool const inserted = c.type == Change::INSERTED;
 
        QString text;
        if (changePresent) {
                QString const author =
                        toqstr(buffer().params().authors().get(c.author).nameAndEmail());
                if (!author.isEmpty())
-                       text += (c.type == Change::INSERTED) ? qt_("Inserted by %1").arg(author)
-                                                            : qt_("Deleted by %1").arg(author);
-
-               QString const date = QDateTime::fromTime_t(c.changetime)
-                                        .toString(Qt::DefaultLocaleLongDate);
+                       text += inserted ? qt_("Inserted by %1").arg(author)
+                                        : qt_("Deleted by %1").arg(author);
+
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 8, 0))
+               QString const date =
+                       QLocale().toString(QDateTime::fromSecsSinceEpoch(c.changetime),
+                                       QLocale::LongFormat);
+#else
+               QString const date =
+                       QLocale().toString(QDateTime::fromTime_t(c.changetime),
+                                       QLocale::LongFormat);
+#endif
                if (!date.isEmpty()) {
                        if (!author.isEmpty())
-                               text += qt_(" on[[date]] %1\n").arg(date);
+                               text += qt_(" on[[date]] %1").arg(date);
                        else
-                               text += (c.type == Change::INSERTED) ? qt_("Inserted on %1\n").arg(date)
-                                                                    : qt_("Deleted on %1\n").arg(date);
+                               text += inserted ? qt_("Inserted on %1").arg(date)
+                                                : qt_("Deleted on %1").arg(date);
+               }
+               QString changedcontent = toqstr(bufferview()->cursor().selectionAsString(false));
+               if (!changedcontent.isEmpty()) {
+                       text += ":<br><br><b>";
+                       if (inserted)
+                               text += "<u><span style=\"color:blue\">";
+                       else
+                               text += "<s><span style=\"color:red\">";
+                       text += changedcontent;
+                       if (inserted)
+                               text += "</u></span></b>";
+                       else
+                               text += "</s></span></b>";
                }
        }
-       changeTB->setPlainText(text);
+       changeTB->setHtml(text);
 }
 
 
@@ -114,9 +130,6 @@ void GuiChanges::rejectChange()
 }
 
 
-Dialog * createGuiChanges(GuiView & lv) { return new GuiChanges(lv); }
-
-
 } // namespace frontend
 } // namespace lyx