From 3e1919e067d499ae472af9ecf6f352f193ca3f3d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Sun, 17 Jul 2005 23:03:01 +0000 Subject: [PATCH] probably fixed bug 1561 git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10298 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/buffer.C | 33 +++++++++++++++++++++++++++++++ src/buffer.h | 2 ++ src/frontends/qt2/qfont_loader.C | 6 +++--- src/frontends/qt2/qfont_loader.h | 12 +++++------ src/frontends/qt2/qfont_metrics.C | 2 +- src/insets/insetlabel.C | 33 +------------------------------ src/mathed/math_hullinset.C | 12 +++++++---- src/text.C | 3 +-- 8 files changed, 55 insertions(+), 48 deletions(-) diff --git a/src/buffer.C b/src/buffer.C index 0c379584fa..5d60e577ac 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -64,6 +64,7 @@ #include "graphics/Previews.h" +#include "support/lyxalgo.h" #include "support/filetools.h" #include "support/fs_extras.h" #ifdef USE_COMPRESSION @@ -1543,8 +1544,40 @@ void Buffer::buildMacros() } } + void Buffer::saveCursor(StableDocIterator cur, StableDocIterator anc) { cursor_ = cur; anchor_ = anc; } + + +void Buffer::changeRefsIfUnique(string const & from, string const & to) +{ + // Check if the label 'from' appears more than once + vector labels; + getLabelList(labels); + + if (lyx::count(labels.begin(), labels.end(), from) > 1) + return; + + InsetBase::Code code = InsetBase::REF_CODE; + + ParIterator it = par_iterator_begin(); + ParIterator end = par_iterator_end(); + for ( ; 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); + //inset->setButtonLabel(); + changed_inset = true; + } + } + } + } +} + diff --git a/src/buffer.h b/src/buffer.h index f181ded04b..bf2c690f42 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -333,6 +333,8 @@ public: StableDocIterator getCursor() const { return cursor_; } /// StableDocIterator getAnchor() const { return anchor_; } + /// + void changeRefsIfUnique(std::string const & from, std::string const & to); private: /** Inserts a file into a document diff --git a/src/frontends/qt2/qfont_loader.C b/src/frontends/qt2/qfont_loader.C index f15ee0de40..73b9362512 100644 --- a/src/frontends/qt2/qfont_loader.C +++ b/src/frontends/qt2/qfont_loader.C @@ -251,7 +251,7 @@ void FontLoader::update() ///////////////////////////////////////////////// -FontInfo::FontInfo(LyXFont const & f) +QLFontInfo::QLFontInfo(LyXFont const & f) : metrics(font) { @@ -322,12 +322,12 @@ FontInfo::FontInfo(LyXFont const & f) } -int FontInfo::width(Uchar val) const +int QLFontInfo::width(Uchar val) const { // Starting with version 3.1.0, Qt/X11 does its own caching of // character width, so it is not necessary to provide ours. #if defined (USE_LYX_FONTCACHE) - FontInfo::WidthCache::const_iterator cit = widthcache.find(val); + QLFontInfo::WidthCache::const_iterator cit = widthcache.find(val); if (cit != widthcache.end()) return cit->second; diff --git a/src/frontends/qt2/qfont_loader.h b/src/frontends/qt2/qfont_loader.h index 7447e0189f..cbdaca3310 100644 --- a/src/frontends/qt2/qfont_loader.h +++ b/src/frontends/qt2/qfont_loader.h @@ -30,9 +30,9 @@ * Qt font loader for LyX. Matches LyXFonts against * actual QFont instances, and also caches metrics. */ -class FontInfo { +class QLFontInfo { public: - FontInfo(LyXFont const & f); + QLFontInfo(LyXFont const & f); /// Return pixel width for the given unicode char int width(Uchar val) const; @@ -79,17 +79,17 @@ public: static void addToFontPath(); /// Get font info (font + metrics) for the given LyX font. - FontInfo & fontinfo(LyXFont const & f) { - FontInfo * & fi = + QLFontInfo & fontinfo(LyXFont const & f) { + QLFontInfo * & fi = fontinfo_[f.family()][f.series()][f.realShape()][f.size()]; if (!fi) - fi = new FontInfo(f); + fi = new QLFontInfo(f); return *fi; } private: /// BUTT ugly ! - FontInfo * fontinfo_[LyXFont::NUM_FAMILIES][2][4][10]; + QLFontInfo * fontinfo_[LyXFont::NUM_FAMILIES][2][4][10]; }; extern FontLoader fontloader; diff --git a/src/frontends/qt2/qfont_metrics.C b/src/frontends/qt2/qfont_metrics.C index 8bdb81e564..1c6fb24182 100644 --- a/src/frontends/qt2/qfont_metrics.C +++ b/src/frontends/qt2/qfont_metrics.C @@ -139,7 +139,7 @@ int width(char const * s, size_t ls, LyXFont const & f) return smallcapswidth(s, ls, f); Encoding const * encoding = fontencoding(f); - FontInfo & fi = fontloader.fontinfo(f); + QLFontInfo & fi = fontloader.fontinfo(f); if (ls == 1) return fi.width(encoding->ucs(s[0])); diff --git a/src/insets/insetlabel.C b/src/insets/insetlabel.C index 9c2ba9e994..9d1264dbe0 100644 --- a/src/insets/insetlabel.C +++ b/src/insets/insetlabel.C @@ -58,37 +58,6 @@ string const InsetLabel::getScreenLabel(Buffer const &) const } -namespace { - -void changeRefsIfUnique(BufferView & bv, string const & from, string const & to) -{ - // Check if the label 'from' appears more than once - vector labels; - bv.buffer()->getLabelList(labels); - - if (lyx::count(labels.begin(), labels.end(), from) > 1) - return; - - InsetBase::Code code = InsetBase::REF_CODE; - - ParIterator it = bv.buffer()->par_iterator_begin(); - ParIterator end = bv.buffer()->par_iterator_end(); - for ( ; it != end; ++it) { - 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); - } - } - } - } -} - -} // namespace anon - - void InsetLabel::doDispatch(LCursor & cur, FuncRequest & cmd) { switch (cmd.action) { @@ -101,7 +70,7 @@ void InsetLabel::doDispatch(LCursor & cur, FuncRequest & cmd) break; } if (p.getContents() != params().getContents()) - changeRefsIfUnique(cur.bv(), params().getContents(), + cur.bv().buffer()->changeRefsIfUnique(params().getContents(), p.getContents()); setParams(p); break; diff --git a/src/mathed/math_hullinset.C b/src/mathed/math_hullinset.C index 6f82efd91d..dcec2d249c 100644 --- a/src/mathed/math_hullinset.C +++ b/src/mathed/math_hullinset.C @@ -1064,15 +1064,19 @@ void MathHullInset::doDispatch(LCursor & cur, FuncRequest & cmd) //lyxerr << "arg: " << cmd.argument << endl; string const name = cmd.getArg(0); if (name == "label") { - InsetCommandParams icp; - InsetCommandMailer::string2params(name, cmd.argument, icp); - string str = icp.getContents(); + InsetCommandParams p; + InsetCommandMailer::string2params(name, cmd.argument, p); + string str = p.getContents(); recordUndoInset(cur); row_type const r = (type_ == "multline") ? nrows() - 1 : cur.row(); str = lyx::support::trim(str); if (!str.empty()) numbered(r, true); - label(r, str); + string old = label(r); + if (str != old) { + cur.bv().buffer()->changeRefsIfUnique(old, str); + label(r, str); + } } break; } diff --git a/src/text.C b/src/text.C index 63b5d4a91d..e4f85e7532 100644 --- a/src/text.C +++ b/src/text.C @@ -160,9 +160,8 @@ void readParToken(Buffer const & buf, Paragraph & par, LyXLex & lex, if (token[0] != '\\') { string::const_iterator cit = token.begin(); - for (; cit != token.end(); ++cit) { + for (; cit != token.end(); ++cit) par.insertChar(par.size(), (*cit), font, change); - } } else if (token == "\\begin_layout") { lex.eatLine(); string layoutname = lex.getString(); -- 2.39.5