-/* 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;
-
-
-// toggle tooltips on/off in all dialogs.
-boost::signal0<void> Dialogs::toggleTooltips;
-
-void Dialogs::showAboutlyx()
-{
- gui_ShowAboutlyx(*dialogs_lyxview, *this);
-}
-
-
-void Dialogs::showBibitem(InsetCommand * ic)
-{
- gui_ShowBibitem(ic, *dialogs_lyxview, *this);
-}
-
-
-void Dialogs::showBibtex(InsetCommand * ic)
-{
- gui_ShowBibtex(ic, *dialogs_lyxview, *this);
-}
-
-
-void Dialogs::showCharacter()
-{
- gui_ShowCharacter(*dialogs_lyxview, *this);
-}
-
-
-void Dialogs::setUserFreeFont()
-{
- gui_SetUserFreeFont(*dialogs_lyxview, *this);
-}
-
-
-void Dialogs::showCitation(InsetCommand * ic)
-{
- gui_ShowCitation(ic, *dialogs_lyxview, *this);
-}
-
-
-void Dialogs::createCitation(string const & s)
-{
- gui_CreateCitation(s, *dialogs_lyxview, *this);
-}
-
-
-void Dialogs::showDocument()
-{
- gui_ShowDocument(*dialogs_lyxview, *this);
-}
-
-
-void Dialogs::showError(InsetError * ie)
-{
- gui_ShowError(ie, *dialogs_lyxview, *this);
-}
-
-
-void Dialogs::showERT(InsetERT * ie)
-{
- gui_ShowERT(ie, *dialogs_lyxview, *this);
-}
-
-
-void Dialogs::updateERT(InsetERT * ie)
-{
- gui_UpdateERT(ie, *dialogs_lyxview, *this);
-}
+#include "lyx_cb.h"
+#include "controllers/Dialog.h"
-void Dialogs::showExternal(InsetExternal * ie)
-{
- gui_ShowExternal(ie, *dialogs_lyxview, *this);
-}
+#include <boost/signal.hpp>
+#include <boost/bind.hpp>
-void Dialogs::showFile(string const & f)
-{
- gui_ShowFile(f, *dialogs_lyxview, *this);
-}
+namespace lyx {
-void Dialogs::showFloat(InsetFloat * ifl)
-{
- gui_ShowFloat(ifl, *dialogs_lyxview, *this);
-}
+using std::string;
+using lyx::frontend::Dialog;
-void Dialogs::showForks()
-{
- gui_ShowForks(*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::showGraphics(InsetGraphics * ig)
-{
- gui_ShowGraphics(ig, *dialogs_lyxview, *this);
-}
+ mutable boost::scoped_ptr<Signal> signal_;
+};
-void Dialogs::showInclude(InsetInclude * ii)
-{
- gui_ShowInclude(ii, *dialogs_lyxview, *this);
-}
+namespace {
+BugfixSignal<boost::signal<void(string const &, InsetBase*)> > hideSignal;
-void Dialogs::showIndex(InsetCommand * ic)
-{
- gui_ShowIndex(ic, *dialogs_lyxview, *this);
}
-void Dialogs::createIndex(string const & s)
+void Dialogs::hide(string const & name, InsetBase* inset)
{
- gui_CreateIndex(s, *dialogs_lyxview, *this);
+ // Don't send the signal if we are quitting, because on MSVC it is
+ // destructed before the cut stack in CutAndPaste.C, and this method
+ // is called from some inset destructor if the cut stack is not empty
+ // on exit.
+ if (!quitting)
+ hideSignal()(name, inset);
}
-void Dialogs::showInfo(InsetInfo * /*ii*/)
+Dialogs::Dialogs(LyXView & lyxview)
+ : lyxview_(lyxview), in_show_(false)
{
-#if 0
- gui_ShowInfo(ii, *dialogs_lyxview, *this);
-#endif
+ // Connect signals
+ hideSignal().connect(boost::bind(&Dialogs::hideSlot, this, _1, _2));
}
-void Dialogs::showLogFile()
+Dialog * Dialogs::find_or_build(string const & name)
{
- gui_ShowLogFile(*dialogs_lyxview, *this);
-}
+ if (!isValidName(name))
+ return 0;
+ std::map<string, DialogPtr>::iterator it =
+ dialogs_.find(name);
-void Dialogs::showMathPanel()
-{
- gui_ShowMathPanel(*dialogs_lyxview, *this);
-}
-
+ if (it != dialogs_.end())
+ return it->second.get();
-void Dialogs::showMinipage(InsetMinipage * im)
-{
- gui_ShowMinipage(im, *dialogs_lyxview, *this);
+ dialogs_[name] = build(name);
+ return dialogs_[name].get();
}
-void Dialogs::updateMinipage(InsetMinipage * im)
+void Dialogs::show(string const & name, string const & data)
{
- gui_UpdateMinipage(im, *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::showParagraph()
-{
- gui_ShowParagraph(*dialogs_lyxview, *this);
-}
-
-void Dialogs::updateParagraph()
+void Dialogs::show(string const & name, string const & data, InsetBase * inset)
{
-#if 0
- gui_UpdateParagraph(*dialogs_lyxview, *this);
-#endif
+ 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::showPreamble()
+bool Dialogs::visible(string const & name) const
{
- gui_ShowPreamble(*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::showPreferences()
+void Dialogs::update(string const & name, string const & data)
{
- gui_ShowPreferences(*dialogs_lyxview, *this);
-}
-
+ std::map<string, DialogPtr>::const_iterator it =
+ dialogs_.find(name);
+ if (it == dialogs_.end())
+ return;
-void Dialogs::showPrint()
-{
- gui_ShowPrint(*dialogs_lyxview, *this);
+ Dialog * const dialog = it->second.get();
+ if (dialog->isVisible())
+ dialog->update(data);
}
-void Dialogs::showRef(InsetCommand * ic)
+void Dialogs::hideSlot(string const & name, InsetBase * inset)
{
- gui_ShowRef(ic, *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::createRef(string const & s)
-{
- gui_CreateRef(s, *dialogs_lyxview, *this);
+ Dialog * const dialog = it->second.get();
+ if (dialog->isVisible())
+ dialog->hide();
+ open_insets_[name] = 0;
}
-void Dialogs::showSearch()
+void Dialogs::disconnect(string const & name)
{
- gui_ShowSearch(*dialogs_lyxview, *this);
-}
-
+ if (!isValidName(name))
+ return;
-void Dialogs::showSendto()
-{
- gui_ShowSendto(*dialogs_lyxview, *this);
+ if (open_insets_.find(name) != open_insets_.end())
+ open_insets_[name] = 0;
}
-void Dialogs::showSpellchecker()
+InsetBase * Dialogs::getOpenInset(string const & name) const
{
- gui_ShowSpellchecker(*dialogs_lyxview, *this);
-}
-
+ if (!isValidName(name))
+ return 0;
-void Dialogs::showSpellcheckerPreferences()
-{
- gui_ShowSpellcheckerPreferences(*dialogs_lyxview, *this);
+ std::map<string, InsetBase *>::const_iterator it =
+ open_insets_.find(name);
+ return it == open_insets_.end() ? 0 : it->second;
}
-void Dialogs::showTabular(InsetTabular * it)
+void Dialogs::hideAll() const
{
- gui_ShowTabular(it, *dialogs_lyxview, *this);
-}
-
+ std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
+ std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
-void Dialogs::updateTabular(InsetTabular * it)
-{
- gui_UpdateTabular(it, *dialogs_lyxview, *this);
+ for(; it != end; ++it) {
+ it->second->hide();
+ }
}
-void Dialogs::showTabularCreate()
+void Dialogs::hideBufferDependent() const
{
- gui_ShowTabularCreate(*dialogs_lyxview, *this);
-}
-
+ std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
+ std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
-void Dialogs::showThesaurus(string const & s)
-{
- gui_ShowThesaurus(s, *dialogs_lyxview, *this);
+ for(; it != end; ++it) {
+ Dialog * dialog = it->second.get();
+ if (dialog->controller().isBufferDependent())
+ dialog->hide();
+ }
}
-void Dialogs::showTexinfo()
+void Dialogs::updateBufferDependent(bool switched) const
{
- gui_ShowTexinfo(*dialogs_lyxview, *this);
-}
-
+ std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
+ std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
-void Dialogs::showTOC(InsetCommand * ic)
-{
- gui_ShowTOC(ic, *dialogs_lyxview, *this);
+ for(; it != end; ++it) {
+ Dialog * dialog = it->second.get();
+ if (switched && dialog->controller().isBufferDependent()) {
+ if (dialog->isVisible() && dialog->controller().initialiseParams(""))
+ dialog->view().update();
+ else
+ dialog->hide();
+ } else {
+ // A bit clunky, but the dialog will request
+ // that the kernel provides it with the necessary
+ // data.
+ dialog->RestoreButton();
+ }
+ }
}
-void Dialogs::createTOC(string const & s)
+void Dialogs::redraw() const
{
- gui_CreateTOC(s, *dialogs_lyxview, *this);
-}
-
+ std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
+ std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
-void Dialogs::showUrl(InsetCommand * ic)
-{
- gui_ShowUrl(ic, *dialogs_lyxview, *this);
+ for(; it != end; ++it) {
+ it->second->redraw();
+ }
}
-void Dialogs::createUrl(string const & s)
+void Dialogs::checkStatus()
{
- gui_CreateUrl(s, *dialogs_lyxview, *this);
-}
-
+ std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
+ std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
-void Dialogs::showVCLogFile()
-{
- gui_ShowVCLogFile(*dialogs_lyxview, *this);
+ for(; it != end; ++it) {
+ Dialog * const dialog = it->second.get();
+ if (dialog->isVisible())
+ dialog->checkStatus();
+ }
}
-//void Dialogs::add(DialogBase * ptr)
-//{
-// lyx::Assert(ptr);
-// dialogs_.push_back(db_ptr(ptr));
-//}
+} // namespace lyx