finally merge Dialog and Controller

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20875 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2007-10-09 21:21:01 +00:00
parent fee6fea248
commit 5342ee5aad
20 changed files with 69 additions and 160 deletions

View File

@ -30,53 +30,39 @@ Dialog::~Dialog()
{}
Controller::Controller(Dialog & parent)
: parent_(parent), lyxview_(0)
{}
Controller::Controller(Dialog * parent)
: parent_(*parent), lyxview_(0)
{}
Controller::~Controller()
{}
bool Controller::canApply() const
bool Dialog::canApply() const
{
FuncRequest const fr(getLfun(), dialog().name());
FuncRequest const fr(getLfun(), name());
FuncStatus const fs(getStatus(fr));
return fs.enabled();
}
void Controller::dispatch(FuncRequest const & fr) const
void Dialog::dispatch(FuncRequest const & fr) const
{
lyxview_->dispatch(fr);
}
void Controller::updateDialog(std::string const & name) const
void Dialog::updateDialog(std::string const & name) const
{
dispatch(FuncRequest(LFUN_DIALOG_UPDATE, name));
}
void Controller::disconnect(std::string const & name) const
void Dialog::disconnect(std::string const & name) const
{
lyxview_->getDialogs().disconnect(name);
}
bool Controller::isBufferAvailable() const
bool Dialog::isBufferAvailable() const
{
return lyxview_->buffer() != 0;
}
bool Controller::isBufferReadonly() const
bool Dialog::isBufferReadonly() const
{
if (!lyxview_->buffer())
return true;
@ -84,13 +70,13 @@ bool Controller::isBufferReadonly() const
}
std::string const Controller::bufferFilepath() const
std::string const Dialog::bufferFilepath() const
{
return buffer().filePath();
}
KernelDocType Controller::docType() const
KernelDocType Dialog::docType() const
{
if (buffer().isLatex())
return LATEX;
@ -101,26 +87,26 @@ KernelDocType Controller::docType() const
}
BufferView * Controller::bufferview()
BufferView * Dialog::bufferview()
{
return lyxview_->view();
}
BufferView const * Controller::bufferview() const
BufferView const * Dialog::bufferview() const
{
return lyxview_->view();
}
Buffer & Controller::buffer()
Buffer & Dialog::buffer()
{
BOOST_ASSERT(lyxview_->buffer());
return *lyxview_->buffer();
}
Buffer const & Controller::buffer() const
Buffer const & Dialog::buffer() const
{
BOOST_ASSERT(lyxview_->buffer());
return *lyxview_->buffer();

View File

@ -39,13 +39,6 @@ enum KernelDocType
};
/** Different dialogs will have different Controllers and Views.
* deriving from these base classes.
*/
//@{
class Controller;
//@}
/** \c Dialog collects the different parts of a Model-Controller-View
* split of a generic dialog together.
*/
@ -55,7 +48,7 @@ public:
/// \param lv is the access point for the dialog to the LyX kernel.
/// \param name is the identifier given to the dialog by its parent
/// container.
Dialog() {}
Dialog(LyXView & lv) : lyxview_(&lv) {}
virtual ~Dialog();
/** \name Container Access
@ -93,13 +86,6 @@ public:
*/
virtual bool isClosing() const { return false; }
/** \name Dialog Specialization
* Methods to set the Controller and View and so specialise
* to a particular dialog.
*/
//@{
virtual Controller & controller() = 0;
//@}
/** \c Button controller part
*/
@ -144,33 +130,6 @@ public:
///
virtual std::string name() const = 0;
protected:
virtual void apply() {}
private:
/// intentionally unimplemented, therefore uncopiable
Dialog(Dialog const &);
void operator=(Dialog const &);
};
/** \c Controller is an abstract base class for the Controller
* of a Model-Controller-View split of a generic dialog.
*/
class Controller
{
public:
/// \param parent Dialog owning this Controller.
Controller(Dialog & parent);
// the same. avoids ambiguity with the (non-existent) copy constructor
Controller(Dialog * parent);
virtual ~Controller();
void setLyXView(LyXView & lv) { lyxview_ = &lv; }
/** \name Generic Controller
* These few methods are all that a generic dialog needs of a
* controller.
*/
//@{
/** Enable the controller to initialise its data structures.
* \param data is a string encoding of the parameters to be displayed.
@ -229,14 +188,6 @@ public:
*/
virtual bool exitEarly() const { return false; }
//@}
public:
/** \name Controller Access
* Enable the derived classes to access the other parts of the whole.
*/
//@{
Dialog & dialog() { return parent_; }
Dialog const & dialog() const { return parent_; }
//@}
/** \c Kernel part: a wrapper making the LyX kernel available to the dialog.
* (Ie, it provides an interface to the Model part of the Model-Controller-
@ -295,14 +246,17 @@ public:
BufferView const * bufferview() const;
//@}
private:
/// intentionally unimplemented, therefore uncopiable
Controller(Controller const &);
void operator=(Controller const &);
protected:
virtual void apply() {}
private:
Dialog & parent_;
LyXView * lyxview_;
private:
/// intentionally unimplemented, therefore uncopiable
Dialog(Dialog const &);
void operator=(Dialog const &);
};

View File

@ -65,8 +65,7 @@ void Dialogs::show(string const & name, string const & data, Inset * inset)
bool Dialogs::visible(string const & name) const
{
std::map<string, DialogPtr>::const_iterator it =
dialogs_.find(name);
std::map<string, DialogPtr>::const_iterator it = dialogs_.find(name);
if (it == dialogs_.end())
return false;
return it->second.get()->isVisibleView();
@ -75,8 +74,7 @@ bool Dialogs::visible(string const & name) const
void Dialogs::update(string const & name, string const & data)
{
std::map<string, DialogPtr>::const_iterator it =
dialogs_.find(name);
std::map<string, DialogPtr>::const_iterator it = dialogs_.find(name);
if (it == dialogs_.end())
return;
@ -148,7 +146,7 @@ void Dialogs::hideBufferDependent() const
for(; it != end; ++it) {
Dialog * dialog = it->second.get();
if (dialog->controller().isBufferDependent())
if (dialog->isBufferDependent())
dialog->hide();
}
}
@ -161,8 +159,8 @@ void Dialogs::updateBufferDependent(bool switched) const
for(; it != end; ++it) {
Dialog * dialog = it->second.get();
if (switched && dialog->controller().isBufferDependent()) {
if (dialog->isVisibleView() && dialog->controller().initialiseParams(""))
if (switched && dialog->isBufferDependent()) {
if (dialog->isVisibleView() && dialog->initialiseParams(""))
dialog->updateView();
else
dialog->hide();

View File

@ -25,7 +25,7 @@ namespace frontend {
/// Dock Widget container for LyX dialogs.
/// This template class that encapsulates a given Widget inside a
/// QDockWidget and presents a Dialog interface
class DockView : public QDockWidget, public Dialog, public Controller
class DockView : public QDockWidget, public Dialog
{
public:
DockView(
@ -34,7 +34,7 @@ public:
Qt::DockWidgetArea area = Qt::LeftDockWidgetArea, ///< Position of the dock (and also drawer)
Qt::WindowFlags flags = 0
)
: QDockWidget(&parent, flags), Controller(this, parent), name_(name)
: QDockWidget(&parent, flags), Dialog(parent), name_(name)
{
if (flags & Qt::Drawer)
setFeatures(QDockWidget::NoDockWidgetFeatures);
@ -68,7 +68,6 @@ public:
}
bool isClosing() const { return false; }
void partialUpdateView(int /*id*/) {}
Controller & controller() { return *this; }
std::string name() const { return name_; }
//@}
private:

View File

@ -406,7 +406,7 @@ void GuiCharacter::updateContents()
colorCO->setCurrentIndex(findPos2nd(color, getColor()));
langCO->setCurrentIndex(findPos2nd(language, getLanguage()));
toggleallCB->setChecked(getToggleAll());
toggleallCB->setChecked(toggleall_);
}
@ -420,7 +420,7 @@ void GuiCharacter::applyView()
setColor(color[colorCO->currentIndex()].second);
setLanguage(language[langCO->currentIndex()].second);
setToggleAll(toggleallCB->isChecked());
toggleall_ = toggleallCB->isChecked();
}
@ -434,7 +434,7 @@ bool GuiCharacter::initialiseParams(string const &)
|| getBar() != IGNORE
|| getColor() != Color::ignore
|| font_.language() != ignore_language)
dialog().setButtonsValid(true);
setButtonsValid(true);
return true;
}
@ -596,18 +596,6 @@ void GuiCharacter::setLanguage(string const & val)
}
bool GuiCharacter::getToggleAll() const
{
return toggleall_;
}
void GuiCharacter::setToggleAll(bool t)
{
toggleall_ = t;
}
Dialog * createGuiCharacter(LyXView & lv) { return new GuiCharacter(lv); }

View File

@ -98,8 +98,6 @@ private:
void setColor(Color_color);
///
void setLanguage(std::string const &);
///
void setToggleAll(bool);
///
Font::FONT_FAMILY getFamily() const;
@ -115,8 +113,7 @@ private:
Color_color getColor() const;
///
std::string getLanguage() const;
///
bool getToggleAll() const;
private:
///
Font font_;

View File

@ -25,7 +25,7 @@ namespace lyx {
namespace frontend {
GuiDialog::GuiDialog(LyXView & lv, std::string const & name)
: Controller(this, lv), is_closing_(false), name_(name)
: Dialog(lv), is_closing_(false), name_(name)
{}
@ -206,7 +206,7 @@ void GuiDialog::hide()
clearParams();
hideView();
Controller::disconnect(name_);
Dialog::disconnect(name_);
}
@ -222,7 +222,7 @@ void GuiDialog::apply()
dispatchParams();
if (disconnectOnApply() && !is_closing_) {
Controller::disconnect(name_);
Dialog::disconnect(name_);
initialiseParams(string());
updateView();
}

View File

@ -29,7 +29,7 @@ namespace frontend {
/** \c Dialog collects the different parts of a Model-Controller-View
* split of a generic dialog together.
*/
class GuiDialog : public QDialog, public Dialog, public Controller
class GuiDialog : public QDialog, public Dialog
{
Q_OBJECT
@ -119,13 +119,6 @@ public:
*/
bool isClosing() const { return is_closing_; }
/** \name Dialog Components
* Methods to access the various components making up a dialog.
*/
//@{
virtual Controller & controller() { return *this; }
//@}
/** Defaults to nothing. Can be used by the Controller, however, to
* indicate to the View that something has changed and that the
* dialog therefore needs updating.
@ -139,10 +132,10 @@ public:
void apply();
void redrawView() {}
private:
/// Update the display of the dialog whilst it is still visible.
virtual void updateView();
private:
ButtonController bc_;
/// are we updating ?
bool updating_;

View File

@ -1681,14 +1681,14 @@ TextClass const & GuiDocument::textClass() const
}
static void dispatch_bufferparams(Controller const & controller,
static void dispatch_bufferparams(Dialog const & dialog,
BufferParams const & bp, kb_action lfun)
{
ostringstream ss;
ss << "\\begin_header\n";
bp.writeFile(ss);
ss << "\\end_header\n";
controller.dispatch(FuncRequest(lfun, ss.str()));
dialog.dispatch(FuncRequest(lfun, ss.str()));
}
@ -1711,8 +1711,7 @@ void GuiDocument::dispatchParams()
for (; it != end; ++it) {
docstring const & current_branch = it->getBranch();
Branch const * branch = branchlist.find(current_branch);
string const x11hexname =
lyx::X11hexname(branch->getColor());
string const x11hexname = X11hexname(branch->getColor());
// display the new color
docstring const str = current_branch + ' ' + from_ascii(x11hexname);
dispatch(FuncRequest(LFUN_SET_COLOR, str));

View File

@ -653,7 +653,7 @@ void GuiExternal::updateTemplate()
void GuiExternal::applyView()
{
params_.filename.set(internal_path(fromqstr(fileED->text())),
controller().bufferFilepath());
bufferFilepath());
params_.settemplate(getTemplate(externalCO->currentIndex()).lyxName);
@ -725,7 +725,7 @@ void GuiExternal::dispatchParams()
void GuiExternal::editExternal()
{
dialog().applyView();
applyView();
string const lfun = InsetExternalMailer::params2string(params_, buffer());
dispatch(FuncRequest(LFUN_EXTERNAL_EDIT, lfun));
}

View File

@ -808,14 +808,13 @@ string const GuiGraphics::readBB(string const & file)
bool GuiGraphics::isFilenameValid(string const & fname) const
{
// It may be that the filename is relative.
FileName const name(makeAbsPath(fname, bufferFilepath()));
return isFileReadable(name);
return isFileReadable(makeAbsPath(fname, bufferFilepath()));
}
void GuiGraphics::editGraphics()
{
dialog().applyView();
applyView();
string const lfun =
InsetGraphicsMailer::params2string(params_, buffer());
dispatch(FuncRequest(LFUN_GRAPHICS_EDIT, lfun));

View File

@ -20,8 +20,8 @@
#include "BufferView.h"
#include "Cursor.h"
#include "debug.h"
#include "DialogView.h"
#include "DockView.h"
//#include "DialogView.h"
//#include "DockView.h"
#include "frontend_helpers.h"
#include "FuncRequest.h"
#include "gettext.h"
@ -50,7 +50,7 @@ namespace lyx {
namespace frontend {
GuiParagraph::GuiParagraph(LyXView & lv)
: Controller(this, lv)
: Dialog(lv)
{
setupUi(this);
setWindowTitle(qt_("Paragraph Settings"));

View File

@ -38,7 +38,7 @@ namespace lyx {
namespace frontend {
class GuiParagraph
: public QDialog, public Ui::ParagraphUi, public Controller, public Dialog
: public QDialog, public Ui::ParagraphUi, public Dialog
{
Q_OBJECT
public:
@ -55,8 +55,6 @@ private:
///
LyXAlignment getAlignmentFromDialog();
///
Controller & controller() { return *this; }
///
typedef std::map<LyXAlignment, QRadioButton *> RadioMap;
RadioMap radioMap;
@ -112,7 +110,7 @@ private:
std::string key = name_ + "/geometry";
settings.setValue(key.c_str(), QDialog::saveGeometry());
#endif
QDialog::closeEvent(e);
QDialog::closeEvent(e);
}
private Q_SLOTS:

View File

@ -1866,9 +1866,8 @@ void GuiPreferences::dispatchParams()
}
// The Save button has been pressed
if (dialog().isClosing()) {
if (isClosing())
dispatch(FuncRequest(LFUN_PREFERENCES_SAVE));
}
}

View File

@ -191,7 +191,7 @@ bool GuiPrint::initialiseParams(std::string const &)
lyxrc.print_file_extension);
params_ = PrinterParams(PrinterParams::PRINTER, lyxrc.printer, name);
dialog().setButtonsValid(true); // so that the user can press Ok
setButtonsValid(true); // so that the user can press Ok
return true;
}

View File

@ -132,7 +132,7 @@ void GuiRef::selectionChanged()
void GuiRef::refHighlighted(QListWidgetItem * sel)
{
if (controller().isBufferReadonly())
if (isBufferReadonly())
return;
/* int const cur_item = refsLW->currentRow();

View File

@ -30,10 +30,9 @@ namespace frontend {
static void uniqueInsert(QComboBox * box, QString const & text)
{
for (int i = 0; i < box->count(); ++i) {
for (int i = box->count(); --i >= 0; )
if (box->itemText(i) == text)
return;
}
box->addItem(text);
}
@ -87,8 +86,8 @@ void GuiSearch::findChanged()
replaceallPB->setEnabled(false);
} else {
findPB->setEnabled(true);
replacePB->setEnabled(!controller().isBufferReadonly());
replaceallPB->setEnabled(!controller().isBufferReadonly());
replacePB->setEnabled(!isBufferReadonly());
replaceallPB->setEnabled(!isBufferReadonly());
}
}
@ -127,8 +126,8 @@ void GuiSearch::replaceallClicked()
void GuiSearch::find(docstring const & search, bool casesensitive,
bool matchword, bool forward)
{
docstring const data = find2string(search, casesensitive,
matchword, forward);
docstring const data =
find2string(search, casesensitive, matchword, forward);
dispatch(FuncRequest(LFUN_WORD_FIND, data));
}

View File

@ -357,7 +357,7 @@ void GuiSpellchecker::check()
LYXERR(Debug::GUI) << "Updating spell progress." << endl;
oldval_ = newvalue_;
// set progress bar
dialog().partialUpdateView(SPELL_PROGRESSED);
partialUpdateView(SPELL_PROGRESSED);
}
// speller might be dead ...
@ -385,7 +385,7 @@ void GuiSpellchecker::check()
// set suggestions
if (res != SpellBase::OK && res != SpellBase::IGNORED_WORD) {
LYXERR(Debug::GUI) << "Found a word needing checking." << endl;
dialog().partialUpdateView(SPELL_FOUND_WORD);
partialUpdateView(SPELL_FOUND_WORD);
}
}
@ -402,7 +402,7 @@ bool GuiSpellchecker::checkAlive()
else
message = _("The spellchecker has failed.\n") + speller_->error();
dialog().slotClose();
slotClose();
Alert::error(_("The spellchecker has failed"), message);
return false;
@ -412,7 +412,7 @@ bool GuiSpellchecker::checkAlive()
void GuiSpellchecker::showSummary()
{
if (!checkAlive() || count_ == 0) {
dialog().slotClose();
slotClose();
return;
}
@ -422,7 +422,7 @@ void GuiSpellchecker::showSummary()
else
message = _("One word checked.");
dialog().slotClose();
slotClose();
Alert::information(_("Spelling check completed"), message);
}

View File

@ -941,6 +941,7 @@ void GuiTabular::closeGUI()
*/
}
bool GuiTabular::initialiseParams(string const & data)
{
// try to get the current cell
@ -1049,14 +1050,14 @@ void GuiTabular::setWidth(string const & width)
else
set(Tabular::SET_PWIDTH, width);
dialog().updateView();
updateView();
}
void GuiTabular::toggleMultiColumn()
{
set(Tabular::MULTICOLUMN);
dialog().updateView();
updateView();
}

View File

@ -50,9 +50,9 @@ GuiVSpace::GuiVSpace(LyXView & lv)
connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
connect(spacingCO, SIGNAL(highlighted(const QString &)),
connect(spacingCO, SIGNAL(highlighted(QString)),
this, SLOT(change_adaptor()));
connect(valueLE, SIGNAL(textChanged(const QString &)),
connect(valueLE, SIGNAL(textChanged(QString)),
this, SLOT(change_adaptor()));
connect(spacingCO, SIGNAL(activated(int)),
this, SLOT(enableCustom(int)));
@ -166,7 +166,6 @@ void GuiVSpace::applyView()
params_ = setVSpaceFromWidgets(spacingCO->currentIndex(),
valueLE, unitCO, keepCB->isChecked());
}
@ -179,7 +178,7 @@ void GuiVSpace::updateContents()
bool GuiVSpace::initialiseParams(string const & data)
{
InsetVSpaceMailer::string2params(data, params_);
dialog().setButtonsValid(true);
setButtonsValid(true);
return true;
}