From 00d6906d04a9f5738adbf21e1a1ae6d747b7ddb7 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Sun, 2 Mar 2008 18:14:12 +0000 Subject: [PATCH] Introduce Inset::validate() for Inset validation purpose upon interactive creation. In this commit this is used to validate a newly inserted label. As an added bonus, broken cross-references will be automatically fixed if the corresponding label is created. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23399 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Cursor.cpp | 1 + src/insets/Inset.h | 9 +++++++++ src/insets/InsetLabel.cpp | 9 ++++++--- src/insets/InsetLabel.h | 7 +++++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/Cursor.cpp b/src/Cursor.cpp index 0854e242ae..05dfc5b9d3 100644 --- a/src/Cursor.cpp +++ b/src/Cursor.cpp @@ -1027,6 +1027,7 @@ void Cursor::insert(Inset * inset0) else text()->insertInset(*this, inset0); inset().setBuffer(bv_->buffer()); + inset().validate(); } diff --git a/src/insets/Inset.h b/src/insets/Inset.h index c2d1a21b90..949ede774e 100644 --- a/src/insets/Inset.h +++ b/src/insets/Inset.h @@ -91,11 +91,20 @@ public: virtual ~Inset() {} /// change associated Buffer + /// FIXME this should go. virtual void setBuffer(Buffer & buffer); /// retrieve associated Buffer virtual Buffer & buffer(); virtual Buffer const & buffer() const; + /// validate inset. + /** + * This is typically used after this inset is created interactively. + * Intented purpose is to sanitize internal state with regard to current + * Buffer. + **/ + virtual void validate() {} + /// identification as math inset virtual InsetMath * asInsetMath() { return 0; } /// true for 'math' math inset, but not for e.g. mbox diff --git a/src/insets/InsetLabel.cpp b/src/insets/InsetLabel.cpp index 9a9cb31ddd..5f4753b66f 100644 --- a/src/insets/InsetLabel.cpp +++ b/src/insets/InsetLabel.cpp @@ -43,12 +43,15 @@ InsetLabel::InsetLabel(InsetCommandParams const & p) {} +void InsetLabel::validate() +{ + update(getParam("name")); +} + + void InsetLabel::update(docstring const & new_label) { docstring const old_label = getParam("name"); - if (old_label == new_label) - return; - docstring label = new_label; int i = 0; while (buffer().insetLabel(label)) { diff --git a/src/insets/InsetLabel.h b/src/insets/InsetLabel.h index e9e2669c10..f051a38add 100644 --- a/src/insets/InsetLabel.h +++ b/src/insets/InsetLabel.h @@ -21,6 +21,13 @@ class InsetLabel : public InsetCommand { public: /// InsetLabel(InsetCommandParams const &); + + /// verify label and update references. + /** + * Overloaded from Inset::validate. + **/ + void validate(); + /// docstring screenLabel() const; /// -- 2.39.5