From f8e05c680003b28c13d22deebd3763bdfb38f331 Mon Sep 17 00:00:00 2001 From: Dekel Tsur Date: Wed, 31 Jan 2001 11:46:13 +0000 Subject: [PATCH] Several InsetBibKey fixes. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1428 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 4 ++++ src/buffer.C | 2 +- src/insets/ChangeLog | 7 +++++++ src/insets/insetbib.C | 32 +++++++++++++++++++++++--------- src/insets/insetbib.h | 4 ++++ src/paragraph.C | 3 +++ 6 files changed, 42 insertions(+), 10 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 7210b126e8..554311276a 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2001-01-31 Dekel Tsur + + * paragraph.C (GetPositionOfInset): Handle bibkey. + 2001-01-29 Jean-Marc Lasgouttes * BufferView_pimpl.h: change type of Position::par_pos to diff --git a/src/buffer.C b/src/buffer.C index 6c70ca69f1..26cdc9c873 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -933,7 +933,7 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par, ++pos; } else if (token == "\\bibitem") { // ale970302 if (!par->bibkey) { - InsetCommandParams p( "bibitem" ); + InsetCommandParams p("bibitem", "dummy"); par->bibkey = new InsetBibKey(p); } par->bibkey->Read(this, lex); diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 40e2ad8bc4..03ae50b178 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,10 @@ +2001-01-31 Dekel Tsur + + * insetbib.C (InsetBibKey): Better computation of default key. + (getScreenLabel) Show both the key and the label. + (getBibLabel): New method. + (callback): Force a redraw if the inset have been changed. + 2001-01-26 Dekel Tsur * insetref.C (getType, getName): Move methods from diff --git a/src/insets/insetbib.C b/src/insets/insetbib.C index 25e2dd6f60..4f54ecd0bf 100644 --- a/src/insets/insetbib.C +++ b/src/insets/insetbib.C @@ -27,6 +27,7 @@ using std::getline; using std::endl; using std::vector; using std::pair; +using std::max; FD_bibitem_form * bibitem_form = 0; @@ -76,10 +77,15 @@ FD_bibitem_form * create_form_bibitem_form(void) } +int InsetBibKey::key_counter = 0; +const string key_prefix = "key-"; + InsetBibKey::InsetBibKey(InsetCommandParams const & p) : InsetCommand(p) { counter = 1; + if (getContents().empty()) + setContents(key_prefix + tostr(++key_counter)); } @@ -113,6 +119,9 @@ void InsetBibKey::callback( FD_bibitem_form * form, long data ) // shouldn't mark the buffer dirty unless // something was actually altered current_view->updateInset( this, true ); + // We need to do a redraw becuase the maximum + // InsetBibKey width could have changed. + current_view->redraw(); } // fall through to Cancel case 0: fl_hide_form(form->bibitem_form); @@ -124,9 +133,6 @@ void InsetBibKey::callback( FD_bibitem_form * form, long data ) void InsetBibKey::setCounter(int c) { counter = c; - - if (getCmdName().empty()) - setCmdName( tostr(counter) ); } @@ -157,17 +163,25 @@ void InsetBibKey::Read(Buffer const *, LyXLex & lex) scanCommand(token); } else lex.printError("InsetCommand: Parse error: `$$Token'"); -} + if (prefixIs(getContents(), key_prefix)) { + int key = strToInt(getContents().substr(key_prefix.length())); + key_counter = max(key_counter, key); + } +} -string const InsetBibKey::getScreenLabel() const +string const InsetBibKey::getBibLabel() const { if (! getOptions().empty()) return getOptions(); - return tostr(counter); } +string const InsetBibKey::getScreenLabel() const +{ + return getContents() + " [" + getBibLabel() + "]"; +} + /** The value in "Key:" isn't allways set right after a few bibkey insets have @@ -398,7 +412,7 @@ string const bibitemWidest(Buffer const * buffer) while (par) { if (par->bibkey) { int const wx = - lyxfont::width(par->bibkey->getScreenLabel(), + lyxfont::width(par->bibkey->getBibLabel(), font); if (wx > w) { w = wx; @@ -408,8 +422,8 @@ string const bibitemWidest(Buffer const * buffer) par = par->next; } - if (bkey && !bkey->getScreenLabel().empty()) - return bkey->getScreenLabel(); + if (bkey && !bkey->getBibLabel().empty()) + return bkey->getBibLabel(); return "99"; } diff --git a/src/insets/insetbib.h b/src/insets/insetbib.h index 3c02c7618d..fa58d77894 100644 --- a/src/insets/insetbib.h +++ b/src/insets/insetbib.h @@ -58,6 +58,8 @@ public: /// int getCounter() const { return counter; } /// + string const getBibLabel() const; + /// void callback( FD_bibitem_form *, long ); /// struct Holder { @@ -70,6 +72,8 @@ private: int counter; /// Holder holder; + /// + static int key_counter; }; diff --git a/src/paragraph.C b/src/paragraph.C index 4178582b70..e6ab4c8774 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -2205,6 +2205,9 @@ int LyXParagraph::GetPositionOfInset(Inset * inset) const return (*cit).pos; } } + if (inset == bibkey) + return 0; + #ifndef NEW_INSETS // Think about footnotes. if (footnoteflag == LyXParagraph::NO_FOOTNOTE -- 2.39.2