]> git.lyx.org Git - features.git/commitdiff
* src/insets/InsetLabel.[cpp,h}:
authorJürgen Spitzmüller <spitz@lyx.org>
Tue, 4 Mar 2008 06:41:47 +0000 (06:41 +0000)
committerJürgen Spitzmüller <spitz@lyx.org>
Tue, 4 Mar 2008 06:41:47 +0000 (06:41 +0000)
* src/insets/InsetCommand{.cpp,h}:
- rename update to updateCommand

* src/CutAndPaste.cpp:
* src/insets/InsetBibitem{cpp,h}:
- add duplicate check. There's a remaining glitch: the warning message after setting a bibitem
  key in the dialog to a duplicate pops up twice.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23420 a592a061-630c-0410-9148-cb99ea01b6c8

src/CutAndPaste.cpp
src/insets/InsetBibitem.cpp
src/insets/InsetBibitem.h
src/insets/InsetCommand.h
src/insets/InsetLabel.cpp
src/insets/InsetLabel.h

index 7e980ddd6ab62aeb4f824e332263807e9b09b699..f661b3462bf43a92d086c31ad2fbe8da91a56d41 100644 (file)
@@ -225,7 +225,7 @@ pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist,
                        // check for duplicates
                        InsetCommand & lab = static_cast<InsetCommand &>(*it);
                        docstring const oldname = lab.getParam("name");
-                       lab.update(oldname, false);
+                       lab.updateCommand(oldname, false);
                        docstring const newname = lab.getParam("name");
                        if (oldname != newname) {
                                // adapt the references
@@ -240,6 +240,25 @@ pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist,
                        break;
                }
 
+               case BIBITEM_CODE: {
+                       // check for duplicates
+                       InsetCommand & bib = static_cast<InsetCommand &>(*it);
+                       docstring const oldkey = bib.getParam("key");
+                       bib.updateCommand(oldkey, false);
+                       docstring const newkey = bib.getParam("key");
+                       if (oldkey != newkey) {
+                               // adapt the references
+                               for (InsetIterator itt = inset_iterator_begin(in); itt != i_end; ++itt) {
+                                       if (itt->lyxCode() == CITE_CODE) {
+                                               InsetCommand & ref = dynamic_cast<InsetCommand &>(*itt);
+                                               if (ref.getParam("key") == oldkey)
+                                                       ref.setParam("key", newkey);
+                                       }
+                               }
+                       }
+                       break;
+               }
+
                default:
                        break; // nothing
                }
index 95a138dbe82d8cf0a07c02a87817c0080c2554a7..a05cbd45b0144dc7d4a33e84d53a36e35307cc40 100644 (file)
@@ -12,7 +12,9 @@
 
 #include "InsetBibitem.h"
 
+#include "BiblioInfo.h"
 #include "Buffer.h"
+#include "buffer_funcs.h"
 #include "BufferParams.h"
 #include "BufferView.h"
 #include "Counters.h"
 #include "ParagraphList.h"
 #include "TextClass.h"
 
+#include "frontends/alert.h"
+
 #include "support/lstrings.h"
 #include "support/docstream.h"
+#include "support/gettext.h"
 #include "support/convert.h"
 
 #include <ostream>
@@ -49,6 +54,40 @@ InsetBibitem::InsetBibitem(InsetCommandParams const & p)
 }
 
 
+void InsetBibitem::initView()
+{
+       updateCommand(getParam("key"));
+}
+
+
+void InsetBibitem::updateCommand(docstring const & new_key, bool)
+{
+       docstring const old_key = getParam("key");
+       docstring key = new_key;
+
+       BiblioInfo keys;
+       keys.fillWithBibKeys(&buffer());
+       vector<docstring> bibkeys = keys.getKeys();
+
+       int i = 1;
+
+       if (find(bibkeys.begin(), bibkeys.end(), key) != bibkeys.end()) {
+               // generate unique label
+               key = new_key + '-' + convert<docstring>(i);
+               while (find(bibkeys.begin(), bibkeys.end(), key) != bibkeys.end()) {
+                       ++i;
+                       key = new_key + '-' + convert<docstring>(i);
+               }
+               frontend::Alert::warning(_("Keys must be unique!"),
+                       bformat(_("The key %1$s already exists,\n"
+                       "it will be changed to %2$s."), new_key, key));
+       }
+       setParam("key", key);
+
+       lyx::updateLabels(buffer());
+}
+
+
 ParamInfo const & InsetBibitem::findInfo(string const & /* cmdName */)
 {
        static ParamInfo param_info_;
@@ -71,10 +110,12 @@ void InsetBibitem::doDispatch(Cursor & cur, FuncRequest & cmd)
                        cur.noUpdate();
                        break;
                }
-               if (p["key"] != params()["key"])
-                       cur.bv().buffer().changeRefsIfUnique(params()["key"],
-                                                      p["key"], CITE_CODE);
-               setParams(p);
+               docstring old_key = params()["key"];
+               setParam("label", p["label"]);
+               updateCommand(p["key"]);
+               if (params()["key"] != old_key)
+                       cur.bv().buffer().changeRefsIfUnique(old_key,
+                               params()["key"], CITE_CODE);
        }
 
        default:
index c6e6d70841313efd10624ddf51de1c79d048394c..c48bc17b688c950ed1d88a750e2f0243db5826c9 100644 (file)
@@ -28,6 +28,11 @@ class InsetBibitem : public InsetCommand {
 public:
        ///
        InsetBibitem(InsetCommandParams const &);
+       /// verify label and update references.
+       /**
+         * Overloaded from Inset::initView.
+         **/
+       void initView();
        ///
        void read(Lexer & lex);
        ///
@@ -51,6 +56,8 @@ public:
        ///
        static bool isCompatibleCommand(std::string const & s) 
                { return s == "bibitem"; }
+       ///
+       void updateCommand(docstring const & new_key, bool dummy = false);
 protected:
        ///
        virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
index 0228a0160cce3c70e8ff3f8230824441e444c3d5..beada3091a892d786f60a8052fd9e5cbd2b3a619 100644 (file)
@@ -82,8 +82,8 @@ public:
        /// Whether this is a command this inset can represent.
        /// Not implemented here. Must be implemented in derived class.
        static bool isCompatibleCommand(std::string const & cmd);
-       /// update label and references. Currently used by InsetLabel.
-       virtual void update(docstring const &, bool) {};
+       /// update label and references.
+       virtual void updateCommand(docstring const &, bool) {};
 
 protected:
        ///
index 0158361ab8b1774fc25fa5d5165456b91b601b7b..96212d4b9f3f46ba299cabcba28b7527d243184b 100644 (file)
@@ -45,11 +45,11 @@ InsetLabel::InsetLabel(InsetCommandParams const & p)
 
 void InsetLabel::initView()
 {
-       update(getParam("name"));
+       updateCommand(getParam("name"));
 }
 
 
-void InsetLabel::update(docstring const & new_label, bool updaterefs)
+void InsetLabel::updateCommand(docstring const & new_label, bool updaterefs)
 {
        docstring const old_label = getParam("name");
        docstring label = new_label;
@@ -148,7 +148,7 @@ void InsetLabel::doDispatch(Cursor & cur, FuncRequest & cmd)
                        cur.noUpdate();
                        break;
                }
-               update(p["name"]);
+               updateCommand(p["name"]);
                break;
        }
 
index a96344890916bd7613c143d25777813f267f654f..4b2d64a751d3ceb00eb8ee9dda7563b6203baa09 100644 (file)
@@ -54,7 +54,7 @@ public:
        ///
        void addToToc(ParConstIterator const &) const;
        ///
-       void update(docstring const & new_label, bool updaterefs = true);
+       void updateCommand(docstring const & new_label, bool updaterefs = true);
 protected:
        ///
        void doDispatch(Cursor & cur, FuncRequest & cmd);