It seems to me that it would be apropriate to use multiple 
inheritance for insets that have a dialog. Attached is a sample piece 
of code that compiles but is otherwise untested. 

* Does anyone have any experience with such a beast?
* Are there any problems I should watch out for?
* Is this a good thing to do?

What do you think?
Angus


#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
#include <sstream>
#include <string>

using std::ostream;
using std::ostringstream;
using std::string;

class InsetBase;

class Dialogs {
public:
        void show(string const &, string const &, InsetBase *);
        void hide(string const &);
};

class BufferView;

class LyXView {
public:
        Dialogs * getDialogs();
        boost::shared_ptr<BufferView> const & view();
};


class BufferView {
public:
        LyXView * owner();
};


class InsetBase {
public:
        virtual ~InsetBase() {}
        virtual BufferView * view() const { return 0; }
        virtual void write(ostream &) const {}
};

class DialogedInset {
public:
        virtual ~DialogedInset() { hideDialog(); }

        virtual string const & name() const = 0;
        virtual BufferView * view() const = 0;
        virtual string const writeSnippet() const = 0;

        void showDialog(InsetBase * inset) const {
                if (!view()) return;
                view()->owner()->getDialogs()
                        ->show(name(), writeSnippet(), inset);
        }

        void hideDialog() const {
                if (!view()) return;
                        view()->owner()->getDialogs()->hide(name());
        }
};

class InsetCitation 
        : virtual public InsetBase, virtual public DialogedInset {
public:
        InsetCitation() : name_("citation") {}
        virtual string const & name() const { return name_; }
        virtual BufferView * view() const { return view_.get(); }

        virtual string const writeSnippet() const {
                ostringstream data;
                write(data);
                data << "\\end_inset\n";
                return data.str();
        }

        virtual void write(ostream &) const;

        void edit(BufferView * bv, ...) {
                view_ = bv->owner()->view();
                showDialog(this);
        }
private:
        string const name_;
        boost::weak_ptr<BufferView> view_;
};


Reply via email to