Implement proper Dialog factory instead of implicit link-time dependencies

This commit is contained in:
Yuriy Skalko 2020-12-03 19:41:52 +02:00
parent 22193601bf
commit 78f457796c
42 changed files with 262 additions and 335 deletions

View File

@ -0,0 +1,227 @@
/**
* \file DialogFactory.cpp
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Yuriy Skalko
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "DialogFactory.h"
#include "FindAndReplace.h"
#include "GuiAbout.h"
#include "GuiBibitem.h"
#include "GuiBibtex.h"
#include "GuiBox.h"
#include "GuiBranch.h"
#include "GuiChanges.h"
#include "GuiCharacter.h"
#include "GuiCitation.h"
#include "GuiCompare.h"
#include "GuiCompareHistory.h"
#include "GuiCounter.h"
#include "GuiDelimiter.h"
#include "GuiDocument.h"
#include "GuiErrorList.h"
#include "GuiERT.h"
#include "GuiExternal.h"
#include "FloatPlacement.h"
#include "GuiGraphics.h"
#include "GuiHSpace.h"
#include "GuiHyperlink.h"
#include "GuiInclude.h"
#include "GuiIndex.h"
#include "GuiInfo.h"
#include "GuiLabel.h"
#include "GuiLine.h"
#include "GuiListings.h"
#include "GuiLog.h"
#include "GuiLyXFiles.h"
#include "GuiMathMatrix.h"
#include "GuiNomenclature.h"
#include "GuiNote.h"
#include "GuiParagraph.h"
#include "GuiPhantom.h"
#include "GuiPrefs.h"
#include "GuiPrintindex.h"
#include "GuiPrintNomencl.h"
#include "GuiProgressView.h"
#include "GuiRef.h"
#include "GuiSearch.h"
#include "GuiSendto.h"
#include "GuiShowFile.h"
#include "GuiSpellchecker.h"
#include "GuiSymbols.h"
#include "GuiTabular.h"
#include "GuiTabularCreate.h"
#include "GuiTexinfo.h"
#include "GuiThesaurus.h"
#include "GuiToc.h"
#include "GuiViewSource.h"
#include "GuiVSpace.h"
#include "GuiWrap.h"
#include "insets/Inset.h"
#include "InsetParamsDialog.h"
#include "InsetParamsWidget.h"
using namespace std;
namespace lyx {
namespace frontend {
Dialog * createDialog(GuiView & gv, string const & name)
{
InsetParamsWidget * widget;
switch (insetCode(name)) {
case ERT_CODE:
widget = new GuiERT;
break;
case FLOAT_CODE:
widget = new FloatPlacement(true);
break;
case BIBITEM_CODE:
widget = new GuiBibitem;
break;
case BRANCH_CODE:
widget = new GuiBranch;
break;
case BOX_CODE:
widget = new GuiBox;
break;
case HYPERLINK_CODE:
widget = new GuiHyperlink;
break;
case COUNTER_CODE:
widget = new GuiCounter(gv, nullptr);
break;
case INFO_CODE:
widget = new GuiInfo;
break;
case LABEL_CODE:
widget = new GuiLabel;
break;
case LINE_CODE:
widget = new GuiLine;
break;
case MATH_SPACE_CODE:
widget = new GuiHSpace(true);
break;
case NOMENCL_CODE:
widget = new GuiNomenclature;
break;
case NOMENCL_PRINT_CODE:
widget = new GuiPrintNomencl;
break;
case SPACE_CODE:
widget = new GuiHSpace(false);
break;
case TABULAR_CODE:
widget = new GuiTabular;
break;
case VSPACE_CODE:
widget = new GuiVSpace;
break;
default:
widget = nullptr;
}
if (widget)
return new InsetParamsDialog(gv, widget);
if (name == "aboutlyx")
return new GuiAbout(gv);
if (name == "bibtex")
return new GuiBibtex(gv);
if (name == "changes")
return new GuiChanges(gv);
if (name == "character")
return new GuiCharacter(gv);
if (name == "citation")
return new GuiCitation(gv);
if (name == "compare")
return new GuiCompare(gv);
if (name == "comparehistory")
return new GuiCompareHistory(gv);
if (name == "document")
return new GuiDocument(gv);
if (name == "errorlist")
return new GuiErrorList(gv);
if (name == "external")
return new GuiExternal(gv);
if (name == "file")
return new GuiShowFile(gv);
if (name == "findreplace")
return new GuiSearch(gv);
if (name == "findreplaceadv") {
FindAndReplace * gui = new FindAndReplace(gv, Qt::RightDockWidgetArea);
#ifdef Q_OS_MAC
// On Mac show and floating
gui->setFloating(true);
#endif
return gui;
}
if (name == "graphics")
return new GuiGraphics(gv);
if (name == "include")
return new GuiInclude(gv);
if (name == "index")
return new GuiIndex(gv);
if (name == "index_print")
return new GuiPrintindex(gv);
if (name == "listings")
return new GuiListings(gv);
if (name == "log")
return new GuiLog(gv);
if (name == "lyxfiles")
return new GuiLyXFiles(gv);
if (name == "mathdelimiter")
return new GuiDelimiter(gv);
if (name == "mathmatrix")
return new GuiMathMatrix(gv);
if (name == "note")
return new GuiNote(gv);
if (name == "paragraph")
return new GuiParagraph(gv);
if (name == "phantom")
return new GuiPhantom(gv);
if (name == "prefs")
return new GuiPreferences(gv);
if (name == "ref")
return new GuiRef(gv);
if (name == "sendto")
return new GuiSendTo(gv);
if (name == "spellchecker") {
GuiSpellchecker * gui = new GuiSpellchecker(gv, Qt::RightDockWidgetArea);
#ifdef Q_OS_MAC
// On Mac show and floating
gui->setFloating(true);
#endif
return gui;
}
if (name == "symbols")
return new GuiSymbols(gv);
if (name == "tabularcreate")
return new GuiTabularCreate(gv);
if (name == "texinfo")
return new GuiTexInfo(gv);
if (name == "thesaurus")
return new GuiThesaurus(gv);
if (name == "toc")
return new GuiToc(gv);
if (name == "view-source")
return new GuiViewSource(gv);
if (name == "wrap")
return new GuiWrap(gv);
if (name == "progress")
return new GuiProgressView(gv, Qt::BottomDockWidgetArea);
return nullptr;
}
} // namespace frontend
} // namespace lyx

View File

@ -0,0 +1,30 @@
// -*- C++ -*-
/**
* \file DialogFactory.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Yuriy Skalko
*
* Full author contact details are available in file CREDITS.
*/
#ifndef DIALOG_FACTORY_H
#define DIALOG_FACTORY_H
#include <string>
namespace lyx {
namespace frontend {
class Dialog;
class GuiView;
Dialog * createDialog(GuiView & gv, std::string const & name);
} // namespace frontend
} // namespace lyx
#endif // DIALOG_FACTORY_H

View File

@ -633,17 +633,6 @@ void FindAndReplaceWidget::updateGUI()
}
Dialog * createGuiSearchAdv(GuiView & lv)
{
FindAndReplace * gui = new FindAndReplace(lv, Qt::RightDockWidgetArea);
#ifdef Q_OS_MAC
// On Mac show and floating
gui->setFloating(true);
#endif
return gui;
}
} // namespace frontend
} // namespace lyx

View File

@ -355,9 +355,6 @@ void GuiAbout::on_buttonBox_rejected()
}
Dialog * createGuiAbout(GuiView & lv) { return new GuiAbout(lv); }
} // namespace frontend
} // namespace lyx

View File

@ -642,9 +642,6 @@ void GuiBibtex::dispatchParams()
}
Dialog * createGuiBibtex(GuiView & lv) { return new GuiBibtex(lv); }
} // namespace frontend
} // namespace lyx

View File

@ -123,9 +123,6 @@ void GuiChanges::rejectChange()
}
Dialog * createGuiChanges(GuiView & lv) { return new GuiChanges(lv); }
} // namespace frontend
} // namespace lyx

View File

@ -696,9 +696,6 @@ void GuiCharacter::restoreSession()
}
Dialog * createGuiCharacter(GuiView & lv) { return new GuiCharacter(lv); }
} // namespace frontend
} // namespace lyx

View File

@ -1101,9 +1101,6 @@ void GuiCitation::restoreSession()
}
Dialog * createGuiCitation(GuiView & lv) { return new GuiCitation(lv); }
} // namespace frontend
} // namespace lyx

View File

@ -378,8 +378,6 @@ bool GuiCompare::initialiseParams(std::string const &par)
return true;
}
Dialog * createGuiCompare(GuiView & lv) { return new GuiCompare(lv); }
} // namespace frontend
} // namespace lyx

View File

@ -154,9 +154,6 @@ void GuiCompareHistory::slotButtonBox(QAbstractButton * button)
}
Dialog * createGuiCompareHistory(GuiView & lv) { return new GuiCompareHistory(lv); }
} // namespace frontend
} // namespace lyx

View File

@ -468,9 +468,6 @@ void GuiDelimiter::on_swapPB_clicked()
}
Dialog * createGuiDelimiter(GuiView & lv) { return new GuiDelimiter(lv); }
} // namespace frontend
} // namespace lyx

View File

@ -5207,10 +5207,6 @@ void GuiDocument::setOutputSync(bool on)
}
Dialog * createGuiDocument(GuiView & lv) { return new GuiDocument(lv); }
} // namespace frontend
} // namespace lyx

View File

@ -178,8 +178,6 @@ bool GuiErrorList::goTo(int item)
}
Dialog * createGuiErrorList(GuiView & lv) { return new GuiErrorList(lv); }
} // namespace frontend
} // namespace lyx

View File

@ -680,9 +680,6 @@ QString GuiExternal::browse(QString const & input,
}
Dialog * createGuiExternal(GuiView & lv) { return new GuiExternal(lv); }
} // namespace frontend
} // namespace lyx

View File

@ -827,9 +827,6 @@ bool GuiGraphics::isFileNameValid(string const & fname) const
}
Dialog * createGuiGraphics(GuiView & lv) { return new GuiGraphics(lv); }
} // namespace frontend
} // namespace lyx

View File

@ -393,9 +393,6 @@ void GuiInclude::dispatchParams()
}
Dialog * createGuiInclude(GuiView & lv) { return new GuiInclude(lv); }
} // namespace frontend
} // namespace lyx

View File

@ -96,9 +96,6 @@ void GuiIndex::dispatchParams()
}
Dialog * createGuiIndex(GuiView & lv) { return new GuiIndex(lv); }
} // namespace frontend
} // namespace lyx

View File

@ -702,9 +702,6 @@ void GuiListings::setParams(InsetListingsParams const & params)
}
Dialog * createGuiListings(GuiView & lv) { return new GuiListings(lv); }
} // namespace frontend
} // namespace lyx

View File

@ -324,9 +324,6 @@ void GuiLog::getContents(ostream & ss) const
}
Dialog * createGuiLog(GuiView & lv) { return new GuiLog(lv); }
} // namespace frontend
} // namespace lyx

View File

@ -620,8 +620,6 @@ FuncCode GuiLyXFiles::getLfun() const
return LFUN_NOACTION;
}
Dialog * createGuiLyXFiles(GuiView & lv) { return new GuiLyXFiles(lv); }
} // namespace frontend
} // namespace lyx

View File

@ -181,9 +181,6 @@ void GuiMathMatrix::slotClose()
}
Dialog * createGuiMathMatrix(GuiView & lv) { return new GuiMathMatrix(lv); }
} // namespace frontend
} // namespace lyx

View File

@ -90,9 +90,6 @@ void GuiNote::dispatchParams()
}
Dialog * createGuiNote(GuiView & lv) { return new GuiNote(lv); }
} // namespace frontend
} // namespace lyx

View File

@ -396,12 +396,6 @@ void GuiParagraph::restoreSession()
}
Dialog * createGuiParagraph(GuiView & lv)
{
return new GuiParagraph(lv);
}
} // namespace frontend
} // namespace lyx

View File

@ -89,9 +89,6 @@ void GuiPhantom::dispatchParams()
}
Dialog * createGuiPhantom(GuiView & lv) { return new GuiPhantom(lv); }
} // namespace frontend
} // namespace lyx

View File

@ -3686,9 +3686,6 @@ QString GuiPreferences::browse(QString const & file,
}
Dialog * createGuiPreferences(GuiView & lv) { return new GuiPreferences(lv); }
} // namespace frontend
} // namespace lyx

View File

@ -131,9 +131,6 @@ void GuiPrintindex::dispatchParams()
}
Dialog * createGuiPrintindex(GuiView & lv) { return new GuiPrintindex(lv); }
} // namespace frontend
} // namespace lyx

View File

@ -265,13 +265,6 @@ void GuiProgressView::hideEvent(QHideEvent*)
}
Dialog * createGuiProgressView(GuiView & guiview)
{
return new GuiProgressView(guiview, Qt::BottomDockWidgetArea);
}
} // namespace frontend
} // namespace lyx

View File

@ -618,10 +618,6 @@ void GuiRef::dispatchParams()
}
Dialog * createGuiRef(GuiView & lv) { return new GuiRef(lv); }
} // namespace frontend
} // namespace lyx

View File

@ -146,9 +146,6 @@ void GuiSearch::replace(docstring const & search, docstring const & replace,
}
Dialog * createGuiSearch(GuiView & lv) { return new GuiSearch(lv); }
} // namespace frontend
} // namespace lyx

View File

@ -152,8 +152,6 @@ void GuiSendTo::dispatchParams()
dispatch(FuncRequest(lfun, sdata));
}
Dialog * createGuiSendTo(GuiView & lv) { return new GuiSendTo(lv); }
} // namespace frontend
} // namespace lyx

View File

@ -64,9 +64,6 @@ void GuiShowFile::clearParams()
}
Dialog * createGuiShowFile(GuiView & lv) { return new GuiShowFile(lv); }
} // namespace frontend
} // namespace lyx

View File

@ -614,16 +614,6 @@ void GuiSpellchecker::updateView()
}
Dialog * createGuiSpellchecker(GuiView & lv)
{
GuiSpellchecker * gui = new GuiSpellchecker(lv, Qt::RightDockWidgetArea);
#ifdef Q_OS_MAC
gui->setFloating(true);
#endif
return gui;
}
} // namespace frontend
} // namespace lyx

View File

@ -504,12 +504,6 @@ void GuiSymbols::dispatchParams()
}
Dialog * createGuiSymbols(GuiView & lv)
{
return new GuiSymbols(lv);
}
} // namespace frontend
} // namespace lyx

View File

@ -171,12 +171,6 @@ FuncCode GuiTabularCreate::getLfun() const
}
Dialog * createGuiTabularCreate(GuiView & lv)
{
return new GuiTabularCreate(lv);
}
} // namespace frontend
} // namespace lyx

View File

@ -186,9 +186,6 @@ string GuiTexInfo::classOptions(string const & classname) const
*/
Dialog * createGuiTexInfo(GuiView & lv) { return new GuiTexInfo(lv); }
} // namespace frontend
} // namespace lyx

View File

@ -279,9 +279,6 @@ Thesaurus::Meanings const & GuiThesaurus::getMeanings(WordLangTuple const & wl)
}
Dialog * createGuiThesaurus(GuiView & lv) { return new GuiThesaurus(lv); }
} // namespace frontend
} // namespace lyx

View File

@ -89,12 +89,6 @@ bool GuiToc::getStatus(Cursor & cur, FuncRequest const & cmd,
}
Dialog * createGuiToc(GuiView & lv)
{
return new GuiToc(lv);
}
} // namespace frontend
} // namespace lyx

View File

@ -15,6 +15,7 @@
#include "GuiView.h"
#include "DialogFactory.h"
#include "DispatchResult.h"
#include "FileDialog.h"
#include "FontLoader.h"
@ -4924,134 +4925,10 @@ void GuiView::updateDialogs()
updateLayoutList();
}
Dialog * createDialog(GuiView & lv, string const & name);
// will be replaced by a proper factory...
Dialog * createGuiAbout(GuiView & lv);
Dialog * createGuiBibtex(GuiView & lv);
Dialog * createGuiChanges(GuiView & lv);
Dialog * createGuiCharacter(GuiView & lv);
Dialog * createGuiCitation(GuiView & lv);
Dialog * createGuiCompare(GuiView & lv);
Dialog * createGuiCompareHistory(GuiView & lv);
Dialog * createGuiDelimiter(GuiView & lv);
Dialog * createGuiDocument(GuiView & lv);
Dialog * createGuiErrorList(GuiView & lv);
Dialog * createGuiExternal(GuiView & lv);
Dialog * createGuiGraphics(GuiView & lv);
Dialog * createGuiInclude(GuiView & lv);
Dialog * createGuiIndex(GuiView & lv);
Dialog * createGuiListings(GuiView & lv);
Dialog * createGuiLog(GuiView & lv);
Dialog * createGuiLyXFiles(GuiView & lv);
Dialog * createGuiMathMatrix(GuiView & lv);
Dialog * createGuiNote(GuiView & lv);
Dialog * createGuiParagraph(GuiView & lv);
Dialog * createGuiPhantom(GuiView & lv);
Dialog * createGuiPreferences(GuiView & lv);
Dialog * createGuiPrint(GuiView & lv);
Dialog * createGuiPrintindex(GuiView & lv);
Dialog * createGuiRef(GuiView & lv);
Dialog * createGuiSearch(GuiView & lv);
Dialog * createGuiSearchAdv(GuiView & lv);
Dialog * createGuiSendTo(GuiView & lv);
Dialog * createGuiShowFile(GuiView & lv);
Dialog * createGuiSpellchecker(GuiView & lv);
Dialog * createGuiSymbols(GuiView & lv);
Dialog * createGuiTabularCreate(GuiView & lv);
Dialog * createGuiTexInfo(GuiView & lv);
Dialog * createGuiToc(GuiView & lv);
Dialog * createGuiThesaurus(GuiView & lv);
Dialog * createGuiViewSource(GuiView & lv);
Dialog * createGuiWrap(GuiView & lv);
Dialog * createGuiProgressView(GuiView & lv);
Dialog * GuiView::build(string const & name)
{
LASSERT(isValidName(name), return nullptr);
Dialog * dialog = createDialog(*this, name);
if (dialog)
return dialog;
if (name == "aboutlyx")
return createGuiAbout(*this);
if (name == "bibtex")
return createGuiBibtex(*this);
if (name == "changes")
return createGuiChanges(*this);
if (name == "character")
return createGuiCharacter(*this);
if (name == "citation")
return createGuiCitation(*this);
if (name == "compare")
return createGuiCompare(*this);
if (name == "comparehistory")
return createGuiCompareHistory(*this);
if (name == "document")
return createGuiDocument(*this);
if (name == "errorlist")
return createGuiErrorList(*this);
if (name == "external")
return createGuiExternal(*this);
if (name == "file")
return createGuiShowFile(*this);
if (name == "findreplace")
return createGuiSearch(*this);
if (name == "findreplaceadv")
return createGuiSearchAdv(*this);
if (name == "graphics")
return createGuiGraphics(*this);
if (name == "include")
return createGuiInclude(*this);
if (name == "index")
return createGuiIndex(*this);
if (name == "index_print")
return createGuiPrintindex(*this);
if (name == "listings")
return createGuiListings(*this);
if (name == "log")
return createGuiLog(*this);
if (name == "lyxfiles")
return createGuiLyXFiles(*this);
if (name == "mathdelimiter")
return createGuiDelimiter(*this);
if (name == "mathmatrix")
return createGuiMathMatrix(*this);
if (name == "note")
return createGuiNote(*this);
if (name == "paragraph")
return createGuiParagraph(*this);
if (name == "phantom")
return createGuiPhantom(*this);
if (name == "prefs")
return createGuiPreferences(*this);
if (name == "ref")
return createGuiRef(*this);
if (name == "sendto")
return createGuiSendTo(*this);
if (name == "spellchecker")
return createGuiSpellchecker(*this);
if (name == "symbols")
return createGuiSymbols(*this);
if (name == "tabularcreate")
return createGuiTabularCreate(*this);
if (name == "texinfo")
return createGuiTexInfo(*this);
if (name == "thesaurus")
return createGuiThesaurus(*this);
if (name == "toc")
return createGuiToc(*this);
if (name == "view-source")
return createGuiViewSource(*this);
if (name == "wrap")
return createGuiWrap(*this);
if (name == "progress")
return createGuiProgressView(*this);
return nullptr;
return createDialog(*this, name);
}

View File

@ -474,12 +474,6 @@ void GuiViewSource::restoreSession()
}
Dialog * createGuiViewSource(GuiView & lv)
{
return new GuiViewSource(lv);
}
} // namespace frontend
} // namespace lyx

View File

@ -206,9 +206,6 @@ void GuiWrap::dispatchParams()
}
Dialog * createGuiWrap(GuiView & lv) { return new GuiWrap(lv); }
} // namespace frontend
} // namespace lyx

View File

@ -259,72 +259,6 @@ void InsetParamsDialog::updateView()
buttonBox->button(QDialogButtonBox::Ok)->setDefault(true);
}
Dialog * createDialog(GuiView & lv, InsetCode code)
{
InsetParamsWidget * widget;
switch (code) {
case ERT_CODE:
widget = new GuiERT;
break;
case FLOAT_CODE:
widget = new FloatPlacement(true);
break;
case BIBITEM_CODE:
widget = new GuiBibitem;
break;
case BRANCH_CODE:
widget = new GuiBranch;
break;
case BOX_CODE:
widget = new GuiBox;
break;
case HYPERLINK_CODE:
widget = new GuiHyperlink;
break;
case COUNTER_CODE:
widget = new GuiCounter(lv, nullptr);
break;
case INFO_CODE:
widget = new GuiInfo;
break;
case LABEL_CODE:
widget = new GuiLabel;
break;
case LINE_CODE:
widget = new GuiLine;
break;
case MATH_SPACE_CODE:
widget = new GuiHSpace(true);
break;
case NOMENCL_CODE:
widget = new GuiNomenclature;
break;
case NOMENCL_PRINT_CODE:
widget = new GuiPrintNomencl;
break;
case SPACE_CODE:
widget = new GuiHSpace(false);
break;
case TABULAR_CODE:
widget = new GuiTabular;
break;
case VSPACE_CODE:
widget = new GuiVSpace;
break;
default:
return nullptr;
}
InsetParamsDialog * dialog = new InsetParamsDialog(lv, widget);
return dialog;
}
Dialog * createDialog(GuiView & lv, string const & name)
{
return createDialog(lv, insetCode(name));
}
} // namespace frontend
} // namespace lyx

View File

@ -43,7 +43,7 @@ SOURCEFILES = \
ButtonPolicy.cpp \
ButtonPolicy.h \
Dialog.cpp \
Dialog.h \
DialogFactory.cpp \
Action.cpp \
BulletsModule.cpp \
ButtonController.cpp \
@ -171,6 +171,8 @@ MOCHEADER = \
BulletsModule.h \
CategorizedCombo.h \
CustomizedWidgets.h \
Dialog.h \
DialogFactory.h \
DialogView.h \
DockView.h \
EmptyTable.h \