X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2FDialogs.C;h=5ea2ef5ad3347dea7fa529b244aa8345e074ac29;hb=e7fc677261bd14fdf159e594fcf422e985c72664;hp=6b6abb0e830b39aff0068654b837e77c316efc39;hpb=5fd921e9e6caa0cd7eaa8ce8e378726407ab70c5;p=lyx.git diff --git a/src/frontends/Dialogs.C b/src/frontends/Dialogs.C index 6b6abb0e83..5ea2ef5ad3 100644 --- a/src/frontends/Dialogs.C +++ b/src/frontends/Dialogs.C @@ -1,316 +1,247 @@ -/* 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 - * - * Methods common to all frontends' Dialogs that should not be inline + * Common to all frontends' Dialogs */ #include -#ifdef __GNUG__ -#pragma implementation -#endif - #include "Dialogs.h" -#include "support/LAssert.h" +#include "controllers/Dialog.h" -#include "guiapi.h" +#include +#include -// Signal enabling all visible dialogs to be redrawn if so desired. -// E.g., when the GUI colours have been remapped. -//boost::signal0 Dialogs::redrawGUI; -extern LyXView * dialogs_lyxview; +using std::string; +using lyx::frontend::Dialog; -// toggle tooltips on/off in all dialogs. -//boost::signal0 Dialogs::toggleTooltips; +// Note that static boost signals break some compilers, so this wrapper +// initialises the signal dynamically when it is first invoked. +template +class BugfixSignal { +public: + Signal & operator()() { return thesignal(); } + Signal const & operator()() const { return thesignal(); } -void Dialogs::showAboutlyx() -{ - gui_ShowAboutlyx(*dialogs_lyxview, *this); -} +private: + Signal & thesignal() const + { + if (!signal_.get()) + signal_.reset(new Signal); + return *signal_; + } + mutable boost::scoped_ptr signal_; +}; -void Dialogs::showBibitem(InsetCommand * ic) -{ - gui_ShowBibitem(ic, *dialogs_lyxview, *this); -} - -void Dialogs::showBibtex(InsetCommand * ic) +boost::signal & Dialogs::redrawGUI() { - gui_ShowBibtex(ic, *dialogs_lyxview, *this); + static BugfixSignal > thesignal; + return thesignal(); } -void Dialogs::showCharacter() -{ - gui_ShowCharacter(*dialogs_lyxview, *this); -} +namespace { +BugfixSignal > hideSignal; -void Dialogs::setUserFreeFont() -{ - gui_SetUserFreeFont(*dialogs_lyxview, *this); } -void Dialogs::showCitation(InsetCommand * ic) +void Dialogs::hide(string const & name, InsetBase* inset) { - gui_ShowCitation(ic, *dialogs_lyxview, *this); + hideSignal()(name, inset); } -void Dialogs::createCitation(string const & s) +Dialogs::Dialogs(LyXView & lyxview) + : lyxview_(lyxview), in_show_(false) { - gui_CreateCitation(s, *dialogs_lyxview, *this); + // Connect signals + redrawGUI().connect(boost::bind(&Dialogs::redraw, this)); + hideSignal().connect(boost::bind(&Dialogs::hideSlot, this, _1, _2)); } -void Dialogs::showDocument() +Dialog * Dialogs::find_or_build(string const & name) { - gui_ShowDocument(*dialogs_lyxview, *this); -} + if (!isValidName(name)) + return 0; + std::map::iterator it = + dialogs_.find(name); -void Dialogs::showError(InsetError * ie) -{ - gui_ShowError(ie, *dialogs_lyxview, *this); -} - - -void Dialogs::showERT(InsetERT * ie) -{ - gui_ShowERT(ie, *dialogs_lyxview, *this); -} - + 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::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::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::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::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::const_iterator it = dialogs_.begin(); + std::map::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::const_iterator it = dialogs_.begin(); + std::map::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::const_iterator it = dialogs_.begin(); + std::map::const_iterator end = dialogs_.end(); -void Dialogs::showPreferences() -{ - gui_ShowPreferences(*dialogs_lyxview, *this); -} - - -void Dialogs::showPrint() -{ - gui_ShowPrint(*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::showRef(InsetCommand * ic) +void Dialogs::redraw() const { - gui_ShowRef(ic, *dialogs_lyxview, *this); -} + std::map::const_iterator it = dialogs_.begin(); + std::map::const_iterator end = dialogs_.end(); - -void Dialogs::createRef(string const & s) -{ - gui_CreateRef(s, *dialogs_lyxview, *this); + for(; it != end; ++it) { + it->second->redraw(); + } } -void Dialogs::showSearch() +void Dialogs::checkStatus() { - gui_ShowSearch(*dialogs_lyxview, *this); -} + std::map::const_iterator it = dialogs_.begin(); + std::map::const_iterator end = dialogs_.end(); - -void Dialogs::showSendto() -{ - gui_ShowSendto(*dialogs_lyxview, *this); + for(; it != end; ++it) { + Dialog * const dialog = it->second.get(); + if (dialog->isVisible()) + dialog->checkStatus(); + } } - - -void Dialogs::showSpellchecker() -{ - gui_ShowSpellchecker(*dialogs_lyxview, *this); -} - - -void Dialogs::showSpellcheckerPreferences() -{ - gui_ShowSpellcheckerPreferences(*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)); -//}