]> git.lyx.org Git - features.git/commitdiff
probably fixed bug 1561
authorAndré Pönitz <poenitz@gmx.net>
Sun, 17 Jul 2005 23:03:01 +0000 (23:03 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Sun, 17 Jul 2005 23:03:01 +0000 (23:03 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10298 a592a061-630c-0410-9148-cb99ea01b6c8

src/buffer.C
src/buffer.h
src/frontends/qt2/qfont_loader.C
src/frontends/qt2/qfont_loader.h
src/frontends/qt2/qfont_metrics.C
src/insets/insetlabel.C
src/mathed/math_hullinset.C
src/text.C

index 0c379584fa5acd8acd086629b1659c8ebb9bae95..5d60e577acaf0c331556f291d1a5b902112d0ea2 100644 (file)
@@ -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<string> 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<InsetCommand *>(it2->inset);
+                               if (inset->getContents() == from) {
+                                       inset->setContents(to);
+                                       //inset->setButtonLabel();
+                                       changed_inset = true;
+                               }
+                       }
+               }
+       }
+}
+
index f181ded04bd897df4b3124d883ba326970083c2a..bf2c690f422f78ad704a2ac7fd71d54168098665 100644 (file)
@@ -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
index f15ee0de40213a2883a9c8f133b77391bde95f4a..73b9362512bb647587c1e840c3706bc25292e1d8 100644 (file)
@@ -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;
 
index 7447e0189f2e9bcd010f7a42782cd229fc20424f..cbdaca331035c29c6385b0d183e80981fd22281b 100644 (file)
@@ -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;
index 8bdb81e564ba0d6bfcf565565c2cb400a54bfede..1c6fb2418226df9130d2980b77825d8ab1796ee3 100644 (file)
@@ -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]));
index 9c2ba9e99480e3c78e022f77f16335e27fcc8466..9d1264dbe0b955da8f64f76fad7a334c9805317a 100644 (file)
@@ -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<string> 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<InsetCommand *>(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;
index 6f82efd91dc2f0ca353618891dc39162d6f38c04..dcec2d249c4117d15f4ef2ac8daea570ccecd04d 100644 (file)
@@ -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;
        }
index 63b5d4a91d39da501afee280a282d05d0ae4f595..e4f85e75329f419e7c68ad481017598125bd2e71 100644 (file)
@@ -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();