From 35b6b4c8d0f76e5f8b57da0ef0d10249b4408c81 Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Sat, 6 Sep 2003 19:16:30 +0000 Subject: [PATCH] Move BufferView::ChangeInsets to the Pimpl. As a result, can remove the #include "insets/inset.h" from BufferView.h. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7696 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.C | 43 +---------------------------------- src/BufferView.h | 29 ++++++++--------------- src/BufferView_pimpl.C | 41 +++++++++++++++++++++++++++++++++ src/BufferView_pimpl.h | 14 +++++++++++- src/ChangeLog | 5 ++++ src/graphics/ChangeLog | 4 ++++ src/graphics/PreviewedInset.C | 2 ++ src/insets/ChangeLog | 4 ++++ src/insets/renderers.C | 2 ++ 9 files changed, 82 insertions(+), 62 deletions(-) diff --git a/src/BufferView.C b/src/BufferView.C index 3c0e80f109..69c73907d4 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -517,47 +517,6 @@ void BufferView::updateInset(InsetOld const * inset) } -bool BufferView::ChangeInsets(InsetOld::Code code, - string const & from, string const & to) -{ - bool need_update = false; - LyXCursor cursor = text->cursor; - LyXCursor tmpcursor = cursor; - cursor.par(tmpcursor.par()); - cursor.pos(tmpcursor.pos()); - - ParIterator end = buffer()->par_iterator_end(); - for (ParIterator it = buffer()->par_iterator_begin(); - it != end; ++it) { - bool changed_inset = false; - for (InsetList::iterator it2 = it->insetlist.begin(); - it2 != it->insetlist.end(); ++it2) { - if (it2->inset->lyxCode() == code) { - InsetCommand * inset = static_cast(it2->inset); - if (inset->getContents() == from) { - inset->setContents(to); - changed_inset = true; - } - } - } - if (changed_inset) { - need_update = true; - - // FIXME - - // The test it.size()==1 was needed to prevent crashes. - // How to set the cursor corretly when it.size()>1 ?? - if (it.size() == 1) { - text->setCursorIntern(it.pit(), 0); - text->redoParagraph(text->cursor.par()); - } - } - } - text->setCursorIntern(cursor.par(), cursor.pos()); - return need_update; -} - - bool BufferView::ChangeRefsIfUnique(string const & from, string const & to) { // Check if the label 'from' appears more than once @@ -567,7 +526,7 @@ bool BufferView::ChangeRefsIfUnique(string const & from, string const & to) if (lyx::count(labels.begin(), labels.end(), from) > 1) return false; - return ChangeInsets(InsetOld::REF_CODE, from, to); + return pimpl_->ChangeInsets(InsetOld::REF_CODE, from, to); } diff --git a/src/BufferView.h b/src/BufferView.h index 2172c101ca..df086a8f7e 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -15,24 +15,24 @@ #ifndef BUFFER_VIEW_H #define BUFFER_VIEW_H -#include "support/std_string.h" - -#include "insets/inset.h" - #include +#include "support/std_string.h" + +class Buffer; class Change; -class LyXView; +class Encoding; +class ErrorList; +class FuncRequest; +class InsetOld; +class Language; class LyXText; -class TeXErrors; -class Buffer; class LyXScreen; -class Language; +class LyXView; class Painter; +class TeXErrors; class UpdatableInset; class WordLangTuple; -class Encoding; -class ErrorList; /** * A buffer view encapsulates a view onto a particular @@ -205,15 +205,6 @@ private: /// Set the current locking inset void theLockingInset(UpdatableInset * inset); - /** - * Change all insets with the given code's contents to a new - * string. May only be used with InsetCommand-derived insets - * Returns true if a screen update is needed. - */ - bool ChangeInsets(InsetOld::Code code, string const & from, - string const & to); - - struct Pimpl; friend struct BufferView::Pimpl; diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 5d43f7d13c..abcc8144da 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -1384,3 +1384,44 @@ void BufferView::Pimpl::updateInset(InsetOld const * inset) update(); updateScrollbar(); } + + +bool BufferView::Pimpl::ChangeInsets(InsetOld::Code code, + string const & from, string const & to) +{ + bool need_update = false; + LyXCursor cursor = bv_->text->cursor; + LyXCursor tmpcursor = cursor; + cursor.par(tmpcursor.par()); + cursor.pos(tmpcursor.pos()); + + ParIterator end = bv_->buffer()->par_iterator_end(); + for (ParIterator it = bv_->buffer()->par_iterator_begin(); + it != end; ++it) { + bool changed_inset = false; + for (InsetList::iterator it2 = it->insetlist.begin(); + it2 != it->insetlist.end(); ++it2) { + if (it2->inset->lyxCode() == code) { + InsetCommand * inset = static_cast(it2->inset); + if (inset->getContents() == from) { + inset->setContents(to); + changed_inset = true; + } + } + } + if (changed_inset) { + need_update = true; + + // FIXME + + // The test it.size()==1 was needed to prevent crashes. + // How to set the cursor corretly when it.size()>1 ?? + if (it.size() == 1) { + bv_->text->setCursorIntern(it.pit(), 0); + bv_->text->redoParagraph(bv_->text->cursor.par()); + } + } + } + bv_->text->setCursorIntern(cursor.par(), cursor.pos()); + return need_update; +} diff --git a/src/BufferView_pimpl.h b/src/BufferView_pimpl.h index 2032a09ec3..6599d6c6e7 100644 --- a/src/BufferView_pimpl.h +++ b/src/BufferView_pimpl.h @@ -20,9 +20,13 @@ #include "errorlist.h" #include "BufferView.h" -#include "frontends/Timeout.h" + +#include "insets/inset.h" + #include "frontends/key_state.h" #include "frontends/LyXKeySym.h" +#include "frontends/Timeout.h" + #include "support/types.h" #include @@ -140,6 +144,14 @@ private: /// notify readonly status void showReadonly(bool); + /** + * Change all insets with the given code's contents to a new + * string. May only be used with InsetCommand-derived insets + * Returns true if a screen update is needed. + */ + bool ChangeInsets(InsetOld::Code code, string const & from, + string const & to); + /// friend class BufferView; diff --git a/src/ChangeLog b/src/ChangeLog index 2066d2dea9..ca6a06b4b3 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2003-09-06 Angus Leeming + + * BufferView.[Ch] (ChangeInsets): moved to BufferView_pimpl.[Ch]. + As a result, can remove the #include "insets/inset.h" from BufferView.h + 2003-09-06 Angus Leeming * buffer_funcs.C: diff --git a/src/graphics/ChangeLog b/src/graphics/ChangeLog index fd8637ea9f..cf374b45f5 100644 --- a/src/graphics/ChangeLog +++ b/src/graphics/ChangeLog @@ -1,3 +1,7 @@ +2003-09-06 Angus Leeming + + * PreviewedInset.C: add #include "insets/inset.h" + 2003-09-05 Angus Leeming * *.C: strip out redundant #includes. (26 in total.) diff --git a/src/graphics/PreviewedInset.C b/src/graphics/PreviewedInset.C index c6ebaf76b1..a644760247 100644 --- a/src/graphics/PreviewedInset.C +++ b/src/graphics/PreviewedInset.C @@ -17,6 +17,8 @@ #include "BufferView.h" +#include "insets/inset.h" + #include "support/lstrings.h" #include diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 60b7201ce7..2e0bdb85b1 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,7 @@ +2003-09-06 Angus Leeming + + * renderers.C: add #include "insets/inset.h" + 2003-09-05 Angus Leeming * *.C: strip out redundant #includes. (193 in total.) diff --git a/src/insets/renderers.C b/src/insets/renderers.C index c33cab867c..9018865f32 100644 --- a/src/insets/renderers.C +++ b/src/insets/renderers.C @@ -12,6 +12,8 @@ #include "insets/renderers.h" +#include "insets/inset.h" + #include "BufferView.h" #include "gettext.h" #include "metricsinfo.h" -- 2.39.2