]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/Dialogs.C
do not define boost::throw_exceptions if we are compiling with exceptions
[lyx.git] / src / frontends / Dialogs.C
index ad2d6c2689bf57a819d6cddfca46e8c906000939..5ea2ef5ad3347dea7fa529b244aa8345e074ac29 100644 (file)
-/* This file is part of
- * ======================================================
+/**
+ * \file frontends/Dialogs.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- *           LyX, The Document Processor
+ * \author Angus Leeming
  *
- *           Copyright 1995 Matthias Ettrich
- *           Copyright 1995-2001 The LyX Team.
+ * Full author contact details are available in file CREDITS.
  *
- * ======================================================
- *
- * \file Dialogs.C
- * \author Angus Leeming <a.leeming@ic.ac.uk>
- *
- * Methods common to all frontends' Dialogs that should not be inline
+ * Common to all frontends' Dialogs
  */
 
 #include <config.h>
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
 #include "Dialogs.h"
 
-#include "support/LAssert.h"
-
-#include "guiapi.h"
-
-// Signal enabling all visible dialogs to be redrawn if so desired.
-// E.g., when the GUI colours have been remapped.
-//boost::signal0<void> Dialogs::redrawGUI;
-
-extern LyXView * dialogs_lyxview;
+#include "controllers/Dialog.h"
 
+#include <boost/signal.hpp>
+#include <boost/bind.hpp>
 
-// toggle tooltips on/off in all dialogs.
-//boost::signal0<void> Dialogs::toggleTooltips;
 
-void Dialogs::showAboutlyx()
-{
-       gui_ShowAboutlyx(*dialogs_lyxview, *this);
-}
+using std::string;
+using lyx::frontend::Dialog;
 
 
-void Dialogs::showBibitem(InsetCommand * ic)
-{
-       gui_ShowBibitem(ic, *dialogs_lyxview, *this);
-}
+// Note that static boost signals break some compilers, so this wrapper
+// initialises the signal dynamically when it is first invoked.
+template<typename Signal>
+class BugfixSignal {
+public:
+       Signal & operator()() { return thesignal(); }
+       Signal const & operator()() const { return thesignal(); }
 
+private:
+       Signal & thesignal() const
+       {
+               if (!signal_.get())
+                       signal_.reset(new Signal);
+               return *signal_;
+       }
 
-void Dialogs::showBibtex(InsetCommand * ic)
-{
-       gui_ShowBibtex(ic, *dialogs_lyxview, *this);
-}
+       mutable boost::scoped_ptr<Signal> signal_;
+};
 
 
-void Dialogs::showCharacter()
+boost::signal<void()> & Dialogs::redrawGUI()
 {
-       gui_ShowCharacter(*dialogs_lyxview, *this);
+       static BugfixSignal<boost::signal<void()> > thesignal;
+       return thesignal();
 }
 
 
-void Dialogs::setUserFreeFont()
-{
-       gui_SetUserFreeFont(*dialogs_lyxview, *this);
-}
+namespace {
 
+BugfixSignal<boost::signal<void(string const &, InsetBase*)> > hideSignal;
 
-void Dialogs::showCitation(InsetCommand * ic)
-{
-       gui_ShowCitation(ic, *dialogs_lyxview, *this);
 }
 
 
-void Dialogs::createCitation(string const & s)
+void Dialogs::hide(string const & name, InsetBase* inset)
 {
-       gui_CreateCitation(s, *dialogs_lyxview, *this);
+       hideSignal()(name, inset);
 }
 
 
-void Dialogs::showDocument()
+Dialogs::Dialogs(LyXView & lyxview)
+       : lyxview_(lyxview), in_show_(false)
 {
-       gui_ShowDocument(*dialogs_lyxview, *this);
+       // Connect signals
+       redrawGUI().connect(boost::bind(&Dialogs::redraw, this));
+       hideSignal().connect(boost::bind(&Dialogs::hideSlot, this, _1, _2));
 }
 
 
-void Dialogs::showError(InsetError * ie)
+Dialog * Dialogs::find_or_build(string const & name)
 {
-       gui_ShowError(ie, *dialogs_lyxview, *this);
-}
-
+       if (!isValidName(name))
+               return 0;
 
-void Dialogs::showERT(InsetERT * ie)
-{
-       gui_ShowERT(ie, *dialogs_lyxview, *this);
-}
+       std::map<string, DialogPtr>::iterator it =
+               dialogs_.find(name);
 
+       if (it != dialogs_.end())
+               return it->second.get();
 
-void Dialogs::updateERT(InsetERT * ie)
-{
-       gui_UpdateERT(ie, *dialogs_lyxview, *this);
+       dialogs_[name] = build(name);
+       return dialogs_[name].get();
 }
 
 
-void Dialogs::showExternal(InsetExternal * ie)
+void Dialogs::show(string const & name, string const & data)
 {
-       gui_ShowExternal(ie, *dialogs_lyxview, *this);
+       if (in_show_) {
+               return;
+       }
+       in_show_ = true;
+       Dialog * dialog = find_or_build(name);
+       if (dialog) {
+               // FIXME! Should check that the dialog is NOT an inset dialog.
+               dialog->show(data);
+       }
+       in_show_ = false;
 }
 
 
-void Dialogs::showFile(string const & f)
+void Dialogs::show(string const & name, string const & data, InsetBase * inset)
 {
-       gui_ShowFile(f, *dialogs_lyxview, *this);
+       if (in_show_) {
+               return;
+       }
+       in_show_ = true;
+       Dialog * dialog = find_or_build(name);
+       if (dialog) {
+               // FIXME! Should check that the dialog IS an inset dialog.
+               dialog->show(data);
+               open_insets_[name] = inset;
+       }
+       in_show_ = false;
 }
 
 
-void Dialogs::showFloat(InsetFloat * ifl)
+bool Dialogs::visible(string const & name) const
 {
-       gui_ShowFloat(ifl, *dialogs_lyxview, *this);
+       std::map<string, DialogPtr>::const_iterator it =
+               dialogs_.find(name);
+       if (it == dialogs_.end())
+               return false;
+       return it->second.get()->isVisible();
 }
 
 
-void Dialogs::showForks()
+void Dialogs::update(string const & name, string const & data)
 {
-       gui_ShowForks(*dialogs_lyxview, *this);
-}
+       std::map<string, DialogPtr>::const_iterator it =
+               dialogs_.find(name);
+       if (it == dialogs_.end())
+               return;
 
-
-void Dialogs::showGraphics(InsetGraphics * ig)
-{
-       gui_ShowGraphics(ig, *dialogs_lyxview, *this);
+       Dialog * const dialog = it->second.get();
+       if (dialog->isVisible())
+               dialog->update(data);
 }
 
 
-void Dialogs::showInclude(InsetInclude * ii)
+void Dialogs::hideSlot(string const & name, InsetBase * inset)
 {
-       gui_ShowInclude(ii, *dialogs_lyxview, *this);
-}
+       std::map<string, DialogPtr>::const_iterator it =
+               dialogs_.find(name);
+       if (it == dialogs_.end())
+               return;
 
+       if (inset && inset != getOpenInset(name))
+               return;
 
-void Dialogs::showIndex(InsetCommand * ic)
-{
-       gui_ShowIndex(ic, *dialogs_lyxview, *this);
+       Dialog * const dialog = it->second.get();
+       if (dialog->isVisible())
+               dialog->hide();
+       open_insets_[name] = 0;
 }
 
 
-void Dialogs::createIndex()
+void Dialogs::disconnect(string const & name)
 {
-       gui_CreateIndex(*dialogs_lyxview, *this);
-}
-
+       if (!isValidName(name))
+               return;
 
-void Dialogs::showInfo(InsetInfo * /*ii*/)
-{
-#if 0
-       gui_ShowInfo(ii, *dialogs_lyxview, *this);
-#endif
+       open_insets_[name] = 0;
 }
 
 
-void Dialogs::showLogFile()
+InsetBase * Dialogs::getOpenInset(string const & name) const
 {
-       gui_ShowLogFile(*dialogs_lyxview, *this);
-}
-
+       if (!isValidName(name))
+               return 0;
 
-void Dialogs::showMathPanel()
-{
-       gui_ShowMathPanel(*dialogs_lyxview, *this);
+       std::map<string, InsetBase *>::const_iterator it =
+               open_insets_.find(name);
+       return it == open_insets_.end() ? 0 : it->second;
 }
 
 
-void Dialogs::showMinipage(InsetMinipage * im)
+void Dialogs::hideAll() const
 {
-       gui_ShowMinipage(im, *dialogs_lyxview, *this);
-}
-
+       std::map<string, DialogPtr>::const_iterator it  = dialogs_.begin();
+       std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
 
-void Dialogs::updateMinipage(InsetMinipage * im)
-{
-       gui_UpdateMinipage(im, *dialogs_lyxview, *this);
+       for(; it != end; ++it) {
+               it->second->hide();
+       }
 }
 
 
-void Dialogs::showParagraph()
+void Dialogs::hideBufferDependent() const
 {
-       gui_ShowParagraph(*dialogs_lyxview, *this);
-}
+       std::map<string, DialogPtr>::const_iterator it  = dialogs_.begin();
+       std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
 
-void Dialogs::updateParagraph()
-{
-#if 0
-       gui_UpdateParagraph(*dialogs_lyxview, *this);
-#endif
+       for(; it != end; ++it) {
+               Dialog * dialog =  it->second.get();
+               if (dialog->controller().isBufferDependent())
+                       dialog->hide();
+       }
 }
 
 
-void Dialogs::showPreamble()
+void Dialogs::updateBufferDependent(bool switched) const
 {
-       gui_ShowPreamble(*dialogs_lyxview, *this);
-}
-
+       std::map<string, DialogPtr>::const_iterator it  = dialogs_.begin();
+       std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
 
-void Dialogs::showPreferences()
-{
-       gui_ShowPreferences(*dialogs_lyxview, *this);
+       for(; it != end; ++it) {
+               Dialog * dialog =  it->second.get();
+               if (switched && dialog->controller().isBufferDependent()) {
+                       dialog->hide();
+               } else {
+                       // A bit clunky, but the dialog will request
+                       // that the kernel provides it with the necessary
+                       // data.
+                       dialog->RestoreButton();
+               }
+       }
 }
 
 
-void Dialogs::showPrint()
+void Dialogs::redraw() const
 {
-       gui_ShowPrint(*dialogs_lyxview, *this);
-}
-
+       std::map<string, DialogPtr>::const_iterator it  = dialogs_.begin();
+       std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
 
-void Dialogs::showRef(InsetCommand * ic)
-{
-       gui_ShowRef(ic, *dialogs_lyxview, *this);
+       for(; it != end; ++it) {
+               it->second->redraw();
+       }
 }
 
 
-void Dialogs::createRef(string const & s)
+void Dialogs::checkStatus()
 {
-       gui_CreateRef(s, *dialogs_lyxview, *this);
-}
-
+       std::map<string, DialogPtr>::const_iterator it  = dialogs_.begin();
+       std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
 
-void Dialogs::showSearch()
-{
-       gui_ShowSearch(*dialogs_lyxview, *this);
+       for(; it != end; ++it) {
+               Dialog * const dialog = it->second.get();
+               if (dialog->isVisible())
+                       dialog->checkStatus();
+       }
 }
-
-
-void Dialogs::showSendto()
-{
-       gui_ShowSendto(*dialogs_lyxview, *this);
-}
-
-
-void Dialogs::showSpellchecker()
-{
-       gui_ShowSpellchecker(*dialogs_lyxview, *this);
-}
-
-
-void Dialogs::showTabular(InsetTabular * it)
-{
-       gui_ShowTabular(it, *dialogs_lyxview, *this);
-}
-
-
-void Dialogs::updateTabular(InsetTabular * it)
-{
-       gui_UpdateTabular(it, *dialogs_lyxview, *this);
-}
-
-
-void Dialogs::showTabularCreate()
-{
-       gui_ShowTabularCreate(*dialogs_lyxview, *this);
-}
-
-
-void Dialogs::showThesaurus(string const & s)
-{
-       gui_ShowThesaurus(s, *dialogs_lyxview, *this);
-}
-
-
-void Dialogs::showTexinfo()
-{
-       gui_ShowTexinfo(*dialogs_lyxview, *this);
-}
-
-
-void Dialogs::showTOC(InsetCommand * ic)
-{
-       gui_ShowTOC(ic, *dialogs_lyxview, *this);
-}
-
-
-void Dialogs::createTOC(string const & s)
-{
-       gui_CreateTOC(s, *dialogs_lyxview, *this);
-}
-
-
-void Dialogs::showUrl(InsetCommand * ic)
-{
-       gui_ShowUrl(ic, *dialogs_lyxview, *this);
-}
-
-
-void Dialogs::createUrl(string const & s)
-{
-       gui_CreateUrl(s, *dialogs_lyxview, *this);
-}
-
-
-void Dialogs::showVCLogFile()
-{
-       gui_ShowVCLogFile(*dialogs_lyxview, *this);
-}
-
-
-//void Dialogs::add(DialogBase * ptr)
-//{
-//     lyx::Assert(ptr);
-//     dialogs_.push_back(db_ptr(ptr));
-//}