]> git.lyx.org Git - lyx.git/commitdiff
Rewrite the MailInset as suggested to Andr��.
authorAngus Leeming <leeming@lyx.org>
Mon, 10 Mar 2003 22:12:07 +0000 (22:12 +0000)
committerAngus Leeming <leeming@lyx.org>
Mon, 10 Mar 2003 22:12:07 +0000 (22:12 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6438 a592a061-630c-0410-9148-cb99ea01b6c8

27 files changed:
src/frontends/ChangeLog
src/frontends/Dialogs.C
src/frontends/Dialogs.h
src/frontends/controllers/ControlChanges.C
src/insets/ChangeLog
src/insets/insetbibitem.C
src/insets/insetbibtex.C
src/insets/insetcite.C
src/insets/insetcommand.C
src/insets/inseterror.C
src/insets/insetert.C
src/insets/insetexternal.C
src/insets/insetfloat.C
src/insets/insetfloatlist.C
src/insets/insetgraphics.C
src/insets/insetinclude.C
src/insets/insetindex.C
src/insets/insetlabel.C
src/insets/insetminipage.C
src/insets/insetref.C
src/insets/insettabular.C
src/insets/insettoc.C
src/insets/inseturl.C
src/insets/insetwrap.C
src/insets/mailinset.C
src/insets/mailinset.h
src/lyxfunc.C

index db99b80f6b0eb5c47e496c7a1830aff43d808f74..bb832714c37e88d81a2de1ee90ce6b43a493e2f4 100644 (file)
@@ -1,3 +1,8 @@
+2003-03-10  Angus Leeming  <leeming@lyx.org>
+
+       * Dialogs.h (hide): make it a static method that returns a
+       boost::signal2<> & (takes 'name' and 'inset' args).
+
 2003-03-09  Angus Leeming  <leeming@lyx.org>
 
        * Dialogs.h: remove showMergeChanges.
index 23907a8709127028fd48fc09dc0610f5af4c5357..bfbfd10e207048d8f08a3f3a061adad18e84dc36 100644 (file)
@@ -43,11 +43,20 @@ boost::signal0<void> & Dialogs::redrawGUI()
 }
 
 
+boost::signal2<void, string const &, InsetBase*> & Dialogs::hide()
+{
+       static BugfixSignal<boost::signal2<void, string const &, InsetBase*> >
+               thesignal;
+       return thesignal();
+}
+
+
 Dialogs::Dialogs(LyXView & lyxview)
        : lyxview_(lyxview)
 {
        // Connect signals
        redrawGUI().connect(boost::bind(&Dialogs::redraw, this));
+       hide().connect(boost::bind(&Dialogs::hideSlot, this, _1, _2));
 
        // All this is slated to go
        init_pimpl();
@@ -106,12 +115,15 @@ void Dialogs::update(string const & name, string const & data)
 }
 
 
-void Dialogs::hide(string const & name)
+void Dialogs::hideSlot(string const & name, InsetBase * inset)
 {
        Dialog * dialog = find(name);
        if (!dialog)
                return;
 
+       if (inset && inset != getOpenInset(name))
+               return;
+
        if (dialog->isVisible())
                dialog->hide();
        open_insets_[name] = 0;
index b6f9f4b8daff374d8f797a1a806d1d415b186dd8..c528fc3c1cd34f24b4bc0ca35b0d0548cc699271 100644 (file)
@@ -18,6 +18,7 @@
 #include <boost/scoped_ptr.hpp>
 #include <boost/signals/signal0.hpp>
 #include <boost/signals/signal1.hpp>
+#include <boost/signals/signal2.hpp>
 
 class Dialog;
 class InsetBase;
@@ -123,13 +124,17 @@ public:
            Update the contents of the dialog.
         */
        void update(string const & name, string const & data);
-       ///
-       void hide(string const & name);
+       /** All Dialogs of the given 'name' will be closed if they are
+           connected to the given 'inset'.
+        */
+       static boost::signal2<void, string const &, InsetBase*> & hide();
        ///
        void disconnect(string const & name);
        ///
        InsetBase * getOpenInset(string const & name) const;
 private:
+       ///
+       void hideSlot(string const & name, InsetBase * inset);
        ///
        void redraw() const;
        ///
index 96f744c9ad67b174a175101404ae639966c82977..b3b6f8feb61161efefecb01f416412d3e3d502fb 100644 (file)
@@ -11,8 +11,6 @@
 #include <config.h>
 
 #include "ControlChanges.h"
-#include "frontends/Dialogs.h"
-#include "frontends/LyXView.h"
 #include "buffer.h"
 #include "BufferView.h"
 #include "funcrequest.h"
index 36c5f9092e304716c13f76d17e4642c3e7e94613..594ca54c96b7841a0c53c7e4a8211a2aa8775e1f 100644 (file)
@@ -1,3 +1,31 @@
+2003-03-10  Angus Leeming  <leeming@lyx.org>
+
+       * mailinset.[Ch] (showDialog, updateDialog): now take a mandatory
+       BufferView * arg.
+       (hideDialog): calls the new static Dialogs::hide() method.
+
+       * insetbibitem.C (edit):
+       * insetbibtex.C (edit):
+       * insetcite.C (edit):
+       * insetcommand.C (localDispatch):
+       * inseterror.C (d-tor):
+       * insetert.C (showInsetDialog):
+       * insetexternal.C (localDispatch, edit):
+       * insetfloat.C (localDispatch, showInsetDialog):
+       * insetfloatlist.C (edit):
+       * insetgraphics.C (localDispatch, edit):
+       * insetinclude.C (localDispatch, edit):
+       * insetindex.C (edit):
+       * insetlabel.C (edit):
+       * insetminipage.C (localDispatch, showInsetDialog):
+       * insetref.C (edit):
+       * insettabular.C (unlockInsetInInset, lfunMouseRelease, localDispatch,
+       resetPos, showInsetDialog, openLayoutDialog):
+       * insettoc.C (edit):
+       * inseturl.C (edit):
+       * insetwrap.C (localDispatch, showInsetDialog):
+       changes due to the changed MailInset interface.
+
 2003-03-10  Dekel Tsur  <dekelts@tau.ac.il>
 
        * insetfloat.h: Set default placement to an empty string.
index 50abe3fe5b44dd856e284c744fd7a87c24a812b1..670c4d200e79ef73ebf5a306a673e20fcee07660 100644 (file)
@@ -126,10 +126,10 @@ string const InsetBibitem::getScreenLabel(Buffer const *) const
 }
 
 
-void InsetBibitem::edit(BufferView *, int, int, mouse_button::state)
+void InsetBibitem::edit(BufferView * bv, int, int, mouse_button::state)
 {
        InsetCommandMailer mailer("bibitem", *this);
-       mailer.showDialog();
+       mailer.showDialog(bv);
 }
 
 
index 370faeaf2b66ebdf30630b50d0d94c51aca61f16..6796f5db485be9ca99c435d65f6c3c51f632b3a2 100644 (file)
@@ -218,10 +218,10 @@ void InsetBibtex::fillWithBibKeys
 }
 
 
-void InsetBibtex::edit(BufferView *, int, int, mouse_button::state)
+void InsetBibtex::edit(BufferView * bv, int, int, mouse_button::state)
 {
        InsetCommandMailer mailer("bibtex", *this);
-       mailer.showDialog();
+       mailer.showDialog(bv);
 }
 
 
index 9d9db5b0df2634157de765fb6f71a749d039e3ee..8bd95bfdbea5f73c6cad53c8bd0767386521126c 100644 (file)
@@ -324,7 +324,7 @@ void InsetCitation::edit(BufferView * bv, int, int, mouse_button::state)
        setLoadingBuffer(bv->buffer(), false);
 
        InsetCommandMailer mailer("citation", *this);
-       mailer.showDialog();
+       mailer.showDialog(bv);
 }
 
 
index 70676127b95159e4e788518b74b33b1756bab05f..95ecbce1a634edc0945885c6612d53eba8b870ff 100644 (file)
@@ -84,7 +84,7 @@ dispatch_result InsetCommand::localDispatch(FuncRequest const & cmd)
 
        case LFUN_INSET_DIALOG_UPDATE: {
                InsetCommandMailer mailer(cmd.argument, *this);
-               mailer.updateDialog();
+               mailer.updateDialog(cmd.view());
        }
        break;
 
index 084a777bb524771fbab55709a4f05fbcac9bdb1b..858fcf6f15d802d36aed6012808f56f10affae19 100644 (file)
@@ -35,8 +35,7 @@ InsetError::InsetError(string const & str, bool)
 
 InsetError::~InsetError()
 {
-       if (view())
-               view()->owner()->getDialogs().hide("error");
+       Dialogs::hide()("error", this);
 }
 
 
index a4807b046fa063e5eedb942acceb92f91e86930f..78783ecde0b69d331963d515bb3fc7e8f81efa38 100644 (file)
@@ -670,10 +670,10 @@ void InsetERT::status(BufferView * bv, ERTStatus const st) const
 }
 
 
-bool InsetERT::showInsetDialog(BufferView *) const
+bool InsetERT::showInsetDialog(BufferView * bv) const
 {
        InsetERTMailer mailer(const_cast<InsetERT &>(*this));
-       mailer.showDialog();
+       mailer.showDialog(bv);
        return true;
 }
 
index 9b8ffe451c0b9984236e4608c7bad675bbdc99f7..81980a98600b1e960ff6f100e157050ba5adc53e 100644 (file)
@@ -81,7 +81,7 @@ dispatch_result InsetExternal::localDispatch(FuncRequest const & cmd)
 
        case LFUN_INSET_DIALOG_UPDATE: {
                InsetExternalMailer mailer(*this);
-               mailer.updateDialog();
+               mailer.updateDialog(cmd.view());
        }
        break;
 
@@ -111,10 +111,10 @@ string const InsetExternal::editMessage() const
 }
 
 
-void InsetExternal::edit(BufferView *, int, int, mouse_button::state)
+void InsetExternal::edit(BufferView * bv, int, int, mouse_button::state)
 {
        InsetExternalMailer mailer(*this);
-       mailer.showDialog();
+       mailer.showDialog(bv);
 }
 
 
index 27ae97c90ceccf00aaf4cd3370df3f009342da80..4a261a507a955ce57847fd1704e191249dc50186 100644 (file)
@@ -172,7 +172,7 @@ dispatch_result InsetFloat::localDispatch(FuncRequest const & cmd)
 
        case LFUN_INSET_DIALOG_UPDATE: {
                InsetFloatMailer mailer(*this);
-               mailer.updateDialog();
+               mailer.updateDialog(cmd.view());
        }
        break;
 
@@ -335,7 +335,7 @@ bool InsetFloat::showInsetDialog(BufferView * bv) const
        if (!inset.showInsetDialog(bv)) {
                InsetFloat * tmp = const_cast<InsetFloat *>(this);
                InsetFloatMailer mailer(*tmp);
-               mailer.showDialog();
+               mailer.showDialog(bv);
        }
        return true;
 }
index f6b49cef57c8e98ce37dda7373b8b380378d1a08..eea56091cc6e0819b53fb7c11546f263f9f68886 100644 (file)
@@ -96,10 +96,10 @@ void InsetFloatList::read(Buffer const * buf, LyXLex & lex)
 }
 
 
-void InsetFloatList::edit(BufferView *, int, int, mouse_button::state)
+void InsetFloatList::edit(BufferView * bv, int, int, mouse_button::state)
 {
        InsetCommandMailer mailer("toc", *this);
-       mailer.showDialog();
+       mailer.showDialog(bv);
 }
 
 
index c03c06a6ac620c87d3d6d46a3569cbb81851c101..ec49afb8c06eeb6c73f62ccc1f9cf82b3daea4c0 100644 (file)
@@ -237,7 +237,7 @@ dispatch_result InsetGraphics::localDispatch(FuncRequest const & cmd)
 
        case LFUN_INSET_DIALOG_UPDATE: {
                InsetGraphicsMailer mailer(*this);
-               mailer.updateDialog();
+               mailer.updateDialog(cmd.view());
        }
        break;
 
@@ -436,10 +436,10 @@ void InsetGraphics::draw(BufferView * bv, LyXFont const & font,
 }
 
 
-void InsetGraphics::edit(BufferView *, int, int, mouse_button::state)
+void InsetGraphics::edit(BufferView * bv, int, int, mouse_button::state)
 {
        InsetGraphicsMailer mailer(*this);
-       mailer.showDialog();
+       mailer.showDialog(bv);
 }
 
 
index b03f9392024079541ae95a29d4bac07f0b46efdb..ec0fb8f22658cf32768da9b7b055847f25906ca2 100644 (file)
@@ -134,7 +134,7 @@ dispatch_result InsetInclude::localDispatch(FuncRequest const & cmd)
 
        case LFUN_INSET_DIALOG_UPDATE: {
                InsetIncludeMailer mailer(*this);
-               mailer.updateDialog();
+               mailer.updateDialog(cmd.view());
        }
        break;
 
@@ -212,10 +212,10 @@ Inset * InsetInclude::clone(Buffer const & buffer, bool) const
 }
 
 
-void InsetInclude::edit(BufferView *, int, int, mouse_button::state)
+void InsetInclude::edit(BufferView * bv, int, int, mouse_button::state)
 {
        InsetIncludeMailer mailer(*this);
-       mailer.showDialog();
+       mailer.showDialog(bv);
 }
 
 
index 29d2aa4b80da2073afde0609909a099ea8051fcc..c7f4b935eb046a8007d58add7bfcbaf507b21fea 100644 (file)
@@ -38,10 +38,10 @@ string const InsetIndex::getScreenLabel(Buffer const *) const
 }
 
 
-void InsetIndex::edit(BufferView *, int, int, mouse_button::state)
+void InsetIndex::edit(BufferView * bv, int, int, mouse_button::state)
 {
        InsetCommandMailer mailer("index", *this);
-       mailer.showDialog();
+       mailer.showDialog(bv);
 }
 
 
index efb874673df1536a16f517d44b458da77a3befe6..30010afad893a946a04940961cffb2aaa79fe7a6 100644 (file)
@@ -45,10 +45,10 @@ vector<string> const InsetLabel::getLabelList() const
 }
 
 
-void InsetLabel::edit(BufferView *, int, int, mouse_button::state)
+void InsetLabel::edit(BufferView * bv, int, int, mouse_button::state)
 {
        InsetCommandMailer mailer("label", *this);
-       mailer.showDialog();
+       mailer.showDialog(bv);
 }
 
 
index 7586407a7d5c0618ac9354ed1bb4fd010a90d40c..02d8a8f8ac221b3fb330079624417105e7285303 100644 (file)
@@ -124,7 +124,7 @@ dispatch_result InsetMinipage::localDispatch(FuncRequest const & cmd)
 
        case LFUN_INSET_DIALOG_UPDATE: {
                InsetMinipageMailer mailer(*this);
-               mailer.updateDialog();
+               mailer.updateDialog(cmd.view());
        }
        break;
 
@@ -367,7 +367,7 @@ bool InsetMinipage::showInsetDialog(BufferView * bv) const
        if (!inset.showInsetDialog(bv)) {
                InsetMinipage * tmp = const_cast<InsetMinipage *>(this);
                InsetMinipageMailer mailer(*tmp);
-               mailer.showDialog();
+               mailer.showDialog(bv);
        }
 
        return true;
index 7f0e3f1b8f1b765b245dbccf425c3ae03193bc58..022bebd23e4ae4cbdb4aa71714c430dd4866f6b2 100644 (file)
@@ -42,7 +42,7 @@ void InsetRef::edit(BufferView * bv, int, int, mouse_button::state button)
                bv->owner()->dispatch(FuncRequest(LFUN_REF_GOTO, getContents()));
        else if (button == mouse_button::button1) {
                InsetCommandMailer mailer("ref", *this);
-               mailer.showDialog();
+               mailer.showDialog(bv);
        }
 }
 
index e43c89c79bcbb1e7e19596c20a7b84460faf56ae..72037697f93a60cb73f063f54bbaaaed498c27b5 100644 (file)
@@ -736,7 +736,7 @@ bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
                if (inset->lyxCode() == TABULAR_CODE &&
                    !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
                        InsetTabularMailer mailer(*this);
-                       mailer.updateDialog();
+                       mailer.updateDialog(bv);
                        oldcell = actcell;
                }
                return true;
@@ -884,7 +884,7 @@ bool InsetTabular::lfunMouseRelease(FuncRequest const & cmd)
        }
        if (cmd.button() == mouse_button::button3 && !ret) {
                InsetTabularMailer mailer(*this);
-               mailer.showDialog();
+               mailer.showDialog(cmd.view());
                return true;
        }
        return ret;
@@ -1170,12 +1170,12 @@ Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
                break;
        case LFUN_LAYOUT_TABULAR: {
                InsetTabularMailer mailer(*this);
-               mailer.showDialog();
+               mailer.showDialog(bv);
                break;
        }
        case LFUN_INSET_DIALOG_UPDATE: {
                InsetTabularMailer mailer(*this);
-               mailer.updateDialog();
+               mailer.updateDialog(bv);
                break;
        }
        case LFUN_TABULAR_FEATURE:
@@ -1667,7 +1667,7 @@ void InsetTabular::resetPos(BufferView * bv) const
            actcell != oldcell) {
                InsetTabular * inset = const_cast<InsetTabular *>(this);
                InsetTabularMailer mailer(*inset);
-               mailer.updateDialog();
+               mailer.updateDialog(bv);
                oldcell = actcell;
        }
        in_reset_pos = 0;
@@ -2354,7 +2354,7 @@ bool InsetTabular::showInsetDialog(BufferView * bv) const
        if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv)) {
                InsetTabular * tmp = const_cast<InsetTabular *>(this);
                InsetTabularMailer mailer(*tmp);
-               mailer.showDialog();
+               mailer.showDialog(bv);
        }
        return true;
 }
@@ -2372,7 +2372,7 @@ void InsetTabular::openLayoutDialog(BufferView * bv) const
        }
        InsetTabular * tmp = const_cast<InsetTabular *>(this);
        InsetTabularMailer mailer(*tmp);
-       mailer.showDialog();
+       mailer.showDialog(bv);
 }
 
 
index 0c64eb5013d091bd6a9e1241c35edec5648f1ac4..8b7816766f6ed10a2efd5209fd4aea00b9f1cf0c 100644 (file)
@@ -53,10 +53,10 @@ Inset::Code InsetTOC::lyxCode() const
 }
 
 
-void InsetTOC::edit(BufferView *, int, int, mouse_button::state)
+void InsetTOC::edit(BufferView * bv, int, int, mouse_button::state)
 {
        InsetCommandMailer mailer("toc", *this);
-       mailer.showDialog();
+       mailer.showDialog(bv);
 }
 
 
index 60c2ab2a12e7610801a38cdb5c7692834a6d1d40..0c1c1f17aac7bc9d86c6b4ea156d1c219054ad3b 100644 (file)
@@ -34,10 +34,10 @@ InsetUrl::~InsetUrl()
 }
 
 
-void InsetUrl::edit(BufferView *, int, int, mouse_button::state)
+void InsetUrl::edit(BufferView * bv, int, int, mouse_button::state)
 {
        InsetCommandMailer mailer("url", *this);
-       mailer.showDialog();
+       mailer.showDialog(bv);
 }
 
 
index 3851bfcc3211db5c28728b0328b66916fd9cc553..92cdeaa4aa500560e3debdb570b0f3f060ffb4ff 100644 (file)
@@ -102,7 +102,7 @@ dispatch_result InsetWrap::localDispatch(FuncRequest const & cmd)
 
        case LFUN_INSET_DIALOG_UPDATE: {
                InsetWrapMailer mailer(*this);
-               mailer.updateDialog();
+               mailer.updateDialog(cmd.view());
        }
        break;
 
@@ -291,7 +291,7 @@ bool InsetWrap::showInsetDialog(BufferView * bv) const
        if (!inset.showInsetDialog(bv)) {
                InsetWrap * tmp = const_cast<InsetWrap *>(this);
                InsetWrapMailer mailer(*tmp);
-               mailer.showDialog();
+               mailer.showDialog(bv);
        }
        return true;
 }
index 69e8e8682dd629e2da4f40bad5160d40a6b50c12..8cf6e8606f7fe19ebc901b2784a0892522888fb9 100644 (file)
 #include "mailinset.h"
 #include "inset.h"
 #include "BufferView.h"
-#include "debug.h"
 #include "frontends/LyXView.h"
 #include "frontends/Dialogs.h"
+#include "support/LAssert.h"
 #include "Lsstream.h"
 
 
-namespace {
-
-BufferView * cachedBufferView(InsetBase & inset, string const & title)
+void MailInset::showDialog(BufferView * bv) const
 {
-       BufferView * const bv = inset.view();
-       if (!bv) {
-               lyxerr << "MailInset::" << title << ":\n"
-                      << "The BufferView has not been cached!"
-                      << std::endl;
-       }
-       return bv;
-}
-
-} // namespace anon
-
-
-void MailInset::showDialog() const
-{
-       BufferView * bv = cachedBufferView(inset(), "showDialog");
-       if (!bv)
-               return;
-
+       lyx::Assert(bv);
        bv->owner()->getDialogs().show(name(), inset2string(), &inset());
 }
 
 
-void MailInset::updateDialog() const
+void MailInset::updateDialog(BufferView * bv) const
 {
-       BufferView * bv = cachedBufferView(inset(), "updateDDialog");
-       if (!bv)
-               return;
-
+       lyx::Assert(bv);
        bv->owner()->getDialogs().update(name(), inset2string());
 }
 
 
 void MailInset::hideDialog() const
 {
-       BufferView * bv = cachedBufferView(inset(), "hideDialog");
-       if (!bv)
-               return;
-
-       InsetBase * cmp = bv->owner()->getDialogs().getOpenInset(name());
-       if (cmp == &inset())
-               bv->owner()->getDialogs().hide(name());
+       Dialogs::hide()(name(), &inset());
 }
index e4d1fe3048b092303ad2cd476d90c8663ec9190a..b5a365e4cbf5cbc99c54b5a83b6cb18cac2bc5b8 100644 (file)
@@ -17,6 +17,7 @@
 
 
 class InsetBase;
+class BufferView;
 
 
 class MailInset {
@@ -24,9 +25,9 @@ public:
        ///
        virtual ~MailInset() {};
        ///
-       void showDialog() const;
+       void showDialog(BufferView *) const;
        ///
-       void updateDialog() const;
+       void updateDialog(BufferView *) const;
        ///
        void hideDialog() const;
        ///
index f762f743ce08dcae29edc53b7c3137ac33cfe4f2..7638abb4b4aa672a09e1ea180443198868df761d 100644 (file)
@@ -1409,7 +1409,7 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
        break;
 
        case LFUN_DIALOG_HIDE:
-               owner ->getDialogs().hide(argument);
+               Dialogs::hide()(argument, 0);
                break;
 
        case LFUN_DIALOG_DISCONNECT_INSET: