From 4c724a6072013247ac178f0acec06825585c6c55 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Wed, 19 Oct 2016 11:55:08 +0200 Subject: [PATCH] Do some caching of window title and related UI This should avoid performance problems related to the window update machinery. Moreover this fixes a crash introduced by e4998f21 when closing a file. Note that GuiWorkArea::Private already had a read_only_ member, but it was unused. Also rename LyXVC::vcname() to LyXVC::vcstatus() since it now contains directly the UI string to be shown. (cherry picked from commit 6cb05ce8bb58720dfef6e5707c1f3fad3949881f) (cherry picked from commit 85bcf0d93f7b0137c1d3b4d030a1840cbfe5892e) --- src/LyXVC.cpp | 9 +++++++-- src/LyXVC.h | 6 ++++-- src/frontends/qt4/GuiView.cpp | 7 +------ src/frontends/qt4/GuiWorkArea.cpp | 23 +++++++++++++++-------- src/frontends/qt4/GuiWorkArea_Private.h | 14 ++++++++++++-- 5 files changed, 39 insertions(+), 20 deletions(-) diff --git a/src/LyXVC.cpp b/src/LyXVC.cpp index 323965858c..fcea6491da 100644 --- a/src/LyXVC.cpp +++ b/src/LyXVC.cpp @@ -46,9 +46,14 @@ LyXVC::~LyXVC() {} -string LyXVC::vcname() const +docstring LyXVC::vcstatus() const { - return vcs->vcname(); + if (!vcs) + return docstring(); + if (locking()) + return bformat(_("%1$s lock"), from_ascii(vcs->vcname())); + else + return from_ascii(vcs->vcname()); } diff --git a/src/LyXVC.h b/src/LyXVC.h index 197c4d98b9..3d18a45def 100644 --- a/src/LyXVC.h +++ b/src/LyXVC.h @@ -14,6 +14,8 @@ #include +#include "support/docstring.h" + #include @@ -50,8 +52,8 @@ public: LyXVC(); /// ~LyXVC(); - /// Name of the underlying VCS - std::string vcname() const; + /// Status of the underlying VCS + docstring vcstatus() const; /// Is \p fn under version control? static bool fileInVC(support::FileName const & fn); /** Not a good name perhaps. This function should be called whenever diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index a7d4f4d19f..9166f72ed3 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -1180,12 +1180,7 @@ void GuiView::updateWindowTitle(GuiWorkArea * wa) if (buf.lyxvc().inUse()) { version_control_->show(); - if (buf.lyxvc().locking()) - version_control_->setText( - toqstr(bformat(_("%1$s lock"), - from_ascii(buf.lyxvc().vcname())))); - else - version_control_->setText(toqstr(buf.lyxvc().vcname())); + version_control_->setText(toqstr(buf.lyxvc().vcstatus())); } else version_control_->hide(); } diff --git a/src/frontends/qt4/GuiWorkArea.cpp b/src/frontends/qt4/GuiWorkArea.cpp index 4fb5ef0a53..5557c99696 100644 --- a/src/frontends/qt4/GuiWorkArea.cpp +++ b/src/frontends/qt4/GuiWorkArea.cpp @@ -47,7 +47,6 @@ #include "support/convert.h" #include "support/debug.h" #include "support/gettext.h" -#include "support/FileName.h" #include "support/lassert.h" #include "support/TempFile.h" @@ -246,11 +245,12 @@ SyntheticMouseEvent::SyntheticMouseEvent() GuiWorkArea::Private::Private(GuiWorkArea * parent) -: p(parent), screen_(0), buffer_view_(0), read_only_(false), lyx_view_(0), -cursor_visible_(false), cursor_(0), -need_resize_(false), schedule_redraw_(false), preedit_lines_(1), -pixel_ratio_(1.0), -completer_(new GuiCompleter(p, p)), dialog_mode_(false) +: p(parent), screen_(0), buffer_view_(0), lyx_view_(0), + cursor_visible_(false), cursor_(0), + need_resize_(false), schedule_redraw_(false), preedit_lines_(1), + pixel_ratio_(1.0), + completer_(new GuiCompleter(p, p)), dialog_mode_(false), + read_only_(false), clean_(true) { } @@ -1373,8 +1373,15 @@ QVariant GuiWorkArea::inputMethodQuery(Qt::InputMethodQuery query) const void GuiWorkArea::updateWindowTitle() { - d->lyx_view_->updateWindowTitle(this); - titleChanged(this); + Buffer const & buf = bufferView().buffer(); + if (buf.fileName() != d->file_name_ || buf.isReadonly() != d->read_only_ + || buf.lyxvc().vcstatus() != d->vc_status_ || buf.isClean() != d->clean_) { + d->file_name_ = buf.fileName(); + d->read_only_ = buf.isReadonly(); + d->vc_status_ = buf.lyxvc().vcstatus(); + d->clean_ = buf.isClean(); + titleChanged(this); + } } diff --git a/src/frontends/qt4/GuiWorkArea_Private.h b/src/frontends/qt4/GuiWorkArea_Private.h index 5320c5c713..0e03dd61fe 100644 --- a/src/frontends/qt4/GuiWorkArea_Private.h +++ b/src/frontends/qt4/GuiWorkArea_Private.h @@ -15,6 +15,7 @@ #include "FuncRequest.h" #include "LyXRC.h" +#include "support/FileName.h" #include "support/Timeout.h" #include @@ -150,8 +151,6 @@ struct GuiWorkArea::Private QPaintDevice * screen_; /// BufferView * buffer_view_; - /// Read only Buffer status cache. - bool read_only_; /// GuiView * lyx_view_; /// is the cursor currently displayed @@ -187,6 +186,17 @@ struct GuiWorkArea::Private /// when the menu is actually shown (after releasing on Windows) /// and after the DEPM has done its job. std::string context_menu_name_; + + /// stuff related to window title + /// + support::FileName file_name_; + /// + bool read_only_; + /// + docstring vc_status_; + /// + bool clean_; + }; // GuiWorkArea } // namespace frontend