#include "graphics/Previews.h"
+#include "support/lyxalgo.h"
#include "support/filetools.h"
#include "support/fs_extras.h"
#ifdef USE_COMPRESSION
}
}
+
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;
+ }
+ }
+ }
+ }
+}
+
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
/////////////////////////////////////////////////
-FontInfo::FontInfo(LyXFont const & f)
+QLFontInfo::QLFontInfo(LyXFont const & f)
: metrics(font)
{
}
-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;
* 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;
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;
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]));
}
-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) {
break;
}
if (p.getContents() != params().getContents())
- changeRefsIfUnique(cur.bv(), params().getContents(),
+ cur.bv().buffer()->changeRefsIfUnique(params().getContents(),
p.getContents());
setParams(p);
break;
//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;
}
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();