-/* 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 "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);
-}
+using std::string;
+using lyx::frontend::Dialog;
-void Dialogs::showFloat(InsetFloat * ifl)
-{
- gui_ShowFloat(ifl, *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::showForks()
-{
- gui_ShowForks(*dialogs_lyxview, *this);
-}
-
-
-void Dialogs::showGraphics(InsetGraphics * ig)
-{
- gui_ShowGraphics(ig, *dialogs_lyxview, *this);
-}
+ mutable boost::scoped_ptr<Signal> signal_;
+};
-void Dialogs::showInclude(InsetInclude * ii)
+boost::signal<void()> & Dialogs::redrawGUI()
{
- gui_ShowInclude(ii, *dialogs_lyxview, *this);
+ static BugfixSignal<boost::signal<void()> > thesignal;
+ return thesignal();
}
-void Dialogs::showIndex(InsetCommand * ic)
-{
- gui_ShowIndex(ic, *dialogs_lyxview, *this);
-}
+namespace {
+BugfixSignal<boost::signal<void(string const &, InsetBase*)> > hideSignal;
-void Dialogs::createIndex(string const & s)
-{
- gui_CreateIndex(s, *dialogs_lyxview, *this);
}
-void Dialogs::showInfo(InsetInfo * /*ii*/)
+void Dialogs::hide(string const & name, InsetBase* inset)
{
-#if 0
- gui_ShowInfo(ii, *dialogs_lyxview, *this);
-#endif
+ hideSignal()(name, inset);
}
-void Dialogs::showLogFile()
+Dialogs::Dialogs(LyXView & lyxview)
+ : lyxview_(lyxview)
{
- gui_ShowLogFile(*dialogs_lyxview, *this);
+ // Connect signals
+ redrawGUI().connect(boost::bind(&Dialogs::redraw, this));
}
-void Dialogs::showMathPanel()
+Dialog * Dialogs::find_or_build(string const & name)
{
- gui_ShowMathPanel(*dialogs_lyxview, *this);
-}
+ if (!isValidName(name))
+ return 0;
+ std::map<string, DialogPtr>::iterator it =
+ dialogs_.find(name);
-void Dialogs::showMinipage(InsetMinipage * im)
-{
- gui_ShowMinipage(im, *dialogs_lyxview, *this);
-}
-
+ if (it != dialogs_.end())
+ return it->second.get();
-void Dialogs::updateMinipage(InsetMinipage * im)
-{
- gui_UpdateMinipage(im, *dialogs_lyxview, *this);
+ dialogs_[name] = build(name);
+ return dialogs_[name].get();
}
-void Dialogs::showParagraph()
+void Dialogs::show(string const & name, string const & data)
{
- gui_ShowParagraph(*dialogs_lyxview, *this);
-}
+ Dialog * dialog = find_or_build(name);
+ if (!dialog)
+ return;
-void Dialogs::updateParagraph()
-{
-#if 0
- gui_UpdateParagraph(*dialogs_lyxview, *this);
-#endif
+ // FIXME! Should check that the dialog is NOT an inset dialog.
+ dialog->show(data);
}
-void Dialogs::showPreamble()
+void Dialogs::show(string const & name, string const & data, InsetBase * inset)
{
- gui_ShowPreamble(*dialogs_lyxview, *this);
-}
-
+ Dialog * dialog = find_or_build(name);
+ if (!dialog)
+ return;
-void Dialogs::showPreferences()
-{
- gui_ShowPreferences(*dialogs_lyxview, *this);
+ // FIXME! Should check that the dialog IS an inset dialog.
+ dialog->show(data);
+ open_insets_[name] = inset;
}
-void Dialogs::showPrint()
+bool Dialogs::visible(string const & name) const
{
- gui_ShowPrint(*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::showRef(InsetCommand * ic)
+void Dialogs::update(string const & name, string const & data)
{
- gui_ShowRef(ic, *dialogs_lyxview, *this);
-}
-
+ std::map<string, DialogPtr>::const_iterator it =
+ dialogs_.find(name);
+ if (it == dialogs_.end())
+ return;
-void Dialogs::createRef(string const & s)
-{
- gui_CreateRef(s, *dialogs_lyxview, *this);
+ Dialog * const dialog = it->second.get();
+ if (dialog->isVisible())
+ dialog->update(data);
}
-void Dialogs::showSearch()
+void Dialogs::hideSlot(string const & name, InsetBase * inset)
{
- gui_ShowSearch(*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::showSendto()
-{
- gui_ShowSendto(*dialogs_lyxview, *this);
+ Dialog * const dialog = it->second.get();
+ if (dialog->isVisible())
+ dialog->hide();
+ open_insets_[name] = 0;
}
-void Dialogs::showSpellchecker()
+void Dialogs::disconnect(string const & name)
{
- gui_ShowSpellchecker(*dialogs_lyxview, *this);
-}
-
+ if (!isValidName(name))
+ return;
-void Dialogs::showSpellcheckerPreferences()
-{
- gui_ShowSpellcheckerPreferences(*dialogs_lyxview, *this);
+ open_insets_[name] = 0;
}
-void Dialogs::showTabular(InsetTabular * it)
+InsetBase * Dialogs::getOpenInset(string const & name) const
{
- gui_ShowTabular(it, *dialogs_lyxview, *this);
-}
-
+ if (!isValidName(name))
+ return 0;
-void Dialogs::updateTabular(InsetTabular * it)
-{
- gui_UpdateTabular(it, *dialogs_lyxview, *this);
+ std::map<string, InsetBase *>::const_iterator it =
+ open_insets_.find(name);
+ return it == open_insets_.end() ? 0 : it->second;
}
-void Dialogs::showTabularCreate()
+void Dialogs::hideAll() 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) {
+ it->second->hide();
+ }
}
-void Dialogs::showTexinfo()
+void Dialogs::hideBufferDependent() 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 (dialog->controller().isBufferDependent())
+ dialog->hide();
+ }
}
-void Dialogs::createTOC(string const & s)
+void Dialogs::updateBufferDependent(bool switched) 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) {
+ 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::createUrl(string const & s)
+void Dialogs::redraw() const
{
- 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) {
+ it->second->redraw();
+ }
}
-
-
-//void Dialogs::add(DialogBase * ptr)
-//{
-// lyx::Assert(ptr);
-// dialogs_.push_back(db_ptr(ptr));
-//}