From 127a0419fdc41368d129393703b4dd71d2e0cc2c Mon Sep 17 00:00:00 2001 From: John Levon Date: Fri, 15 Nov 2002 02:41:54 +0000 Subject: [PATCH] prefs/tabular MVC work git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5634 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/controllers/ChangeLog | 11 ++ src/frontends/controllers/ControlButtons.h | 4 +- src/frontends/controllers/ControlPrefs.C | 122 +++++++++++++++- src/frontends/controllers/ControlPrefs.h | 36 ++++- src/frontends/controllers/ControlTabular.C | 156 +++++++++++++++++++++ src/frontends/controllers/ControlTabular.h | 77 ++++++++++ src/frontends/controllers/Makefile.am | 2 + 7 files changed, 400 insertions(+), 8 deletions(-) create mode 100644 src/frontends/controllers/ControlTabular.C create mode 100644 src/frontends/controllers/ControlTabular.h diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index aed2a31ef0..920915e3f5 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,14 @@ +2002-11-15 John Levon + + * ControlButtons.h: make OKButton() virtual for prefs + + * ControlPrefs.h: + * ControlPrefs.C: updates for xforms port to MVC + + * Makefile.am: + * ControlTabular.h: + * ControlTabular.C: add simple MVC port + 2002-11-14 Juergen Spitzmueller * ControlInclude.C: fix file format masks for qt's use diff --git a/src/frontends/controllers/ControlButtons.h b/src/frontends/controllers/ControlButtons.h index f98ced9e7e..e1600a2d79 100644 --- a/src/frontends/controllers/ControlButtons.h +++ b/src/frontends/controllers/ControlButtons.h @@ -49,8 +49,8 @@ public: */ /// void ApplyButton(); - /// - void OKButton(); + /// virtual for ControlPrefs + virtual void OKButton(); /// void CancelButton(); /// diff --git a/src/frontends/controllers/ControlPrefs.C b/src/frontends/controllers/ControlPrefs.C index 91454a7837..63c6158616 100644 --- a/src/frontends/controllers/ControlPrefs.C +++ b/src/frontends/controllers/ControlPrefs.C @@ -14,25 +14,139 @@ #pragma implementation #endif +#include + #include "ControlPrefs.h" +#include "ViewBase.h" -//#include "frontends/Dialogs.h" -#include "commandtags.h" #include "frontends/LyXView.h" +#include "helper_funcs.h" +#include "gettext.h" +#include "support/filetools.h" +#include "frontends/Dialogs.h" +#include "converter.h" +#include "debug.h" +extern string system_lyxdir; +extern string user_lyxdir; + +using std::endl; +using std::pair; + ControlPrefs::ControlPrefs(LyXView & lv, Dialogs & d) : ControlDialogBI(lv, d) {} +void ControlPrefs::update() +{ + rc_ = lyxrc; + view().update(); +} + + void ControlPrefs::apply() { + view().apply(); lyxrc = rc_; } -void ControlPrefs::save() +void ControlPrefs::OKButton() { - lyxrc = rc_; + ControlDialogBI::OKButton(); lv_.dispatch(FuncRequest(LFUN_SAVEPREFERENCES)); } + + +string const ControlPrefs::browsebind(string const & file) +{ + string dir = AddName(system_lyxdir, "bind"); + // FIXME: stupid name + string name = _("System Bind|#S#s"); + pair dir1(name, dir); + + dir = AddName(user_lyxdir, "bind"); + // FIXME: stupid name + name = _("User Bind|#U#u"); + pair dir2(name, dir); + + return browseFile(&lv_, file, _("Choose bind file"), "*.bind", dir1, dir2); +} + + +string const ControlPrefs::browseUI(string const & file) +{ + string dir = AddName(system_lyxdir, "ui"); + // FIXME: stupid name + string name = _("Sys UI|#S#s"); + pair dir1(name, dir); + + dir = AddName(user_lyxdir, "ui"); + // FIXME: stupid name + name = _("User UI|#U#u"); + pair dir2(name, dir); + + return browseFile(&lv_, file, _("Choose UI file"), "*.ui", dir1, dir2); +} + + +string const ControlPrefs::browsekbmap(string const & file) +{ + string const dir = AddName(system_lyxdir, "kbd"); + string const name = _("Key maps|#K#k"); + pair dir1(name, dir); + + return browseFile(&lv_, file, _("Choose keyboard map"), "*.kmap", dir1); +} + + +string const ControlPrefs::browsedict(string const & file) +{ + return browseFile(&lv_, file, _("Choose personal dictionary"), "*.ispell"); +} + + +string const ControlPrefs::browse(string const & file, string const & title) +{ + return browseFile(&lv_, file, title, "*"); +} + + +void ControlPrefs::redrawGUI() +{ + // we must be sure to get the new values first + lyxrc = rc_; + + lv_.getDialogs().redrawGUI(); +} + + +void ControlPrefs::setColor(LColor::color col, string const & hex) +{ + string const s = lcolor.getLyXName(col) + string(" ") + hex; + lv_.dispatch(FuncRequest(LFUN_SET_COLOR, s)); +} + + +void ControlPrefs::updateScreenFonts() +{ + // we must be sure to get the new values first + lyxrc = rc_; + + lv_.dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE)); +} + + +void ControlPrefs::setConverters(Converters const & conv) +{ + converters = conv; + converters.update(formats); + converters.buildGraph(); +} + + +void ControlPrefs::setFormats(Formats const & form) +{ + formats = form; +} diff --git a/src/frontends/controllers/ControlPrefs.h b/src/frontends/controllers/ControlPrefs.h index 329f674529..083f04191b 100644 --- a/src/frontends/controllers/ControlPrefs.h +++ b/src/frontends/controllers/ControlPrefs.h @@ -20,7 +20,12 @@ #include "LString.h" #include "funcrequest.h" #include "lyxrc.h" +#include "LColor.h" +#include + +class Converters; +class Formats; class ControlPrefs : public ControlDialogBI { public: @@ -34,10 +39,37 @@ public: LyXRC const & rc() const { return rc_; } - /// save the rc - void save(); + /// make OK do the save + virtual void OKButton(); + + /// various file pickers + string const browsebind(string const & file); + string const browseUI(string const & file); + string const browsekbmap(string const & file); + string const browsedict(string const & file); + + /// general browse + string const browse(string const & file, string const & title); + + /// redraw widgets (for xforms color change) + void redrawGUI(); + + /// set a color + void setColor(LColor::color col, string const & hex); + /// update the screen fonts after change + void updateScreenFonts(); + + /// set global converters + void setConverters(Converters const & conv); + + /// set global formats + void setFormats(Formats const & form); + private: + /// get current lyxrc + virtual void update(); + /// apply current lyxrc virtual void apply(); diff --git a/src/frontends/controllers/ControlTabular.C b/src/frontends/controllers/ControlTabular.C new file mode 100644 index 0000000000..4509290009 --- /dev/null +++ b/src/frontends/controllers/ControlTabular.C @@ -0,0 +1,156 @@ +// -*- C++ -*- +/** + * \file ControlTabular.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author John Levon + * + * Full author contact details are available in file CREDITS + */ + +#include "ControlTabular.h" + +#include "ButtonControllerBase.h" +#include "ViewBase.h" +#include "support/LAssert.h" + +#include "frontends/LyXView.h" +#include "BufferView.h" +#include "buffer.h" +#include "lyxrc.h" +#include "insets/insettabular.h" + +#include + +ControlTabular::ControlTabular(LyXView & lv, Dialogs & d) + : ControlConnectBD(lv, d), + inset_(0), dialog_built_(false) +{} + + +void ControlTabular::showInset(InsetTabular * inset) +{ + lyx::Assert(inset); + + connectInset(inset); + show(inset); + + // The widgets may not be valid, so refresh the button controller + // FIXME: needed ? + bc().refresh(); +} + + +void ControlTabular::updateInset(InsetTabular * inset) +{ + lyx::Assert(inset); + + connectInset(inset); + + if (!dialog_built_) { + view().build(); + dialog_built_ = true; + } + + update(); +} + + +void ControlTabular::show(InsetTabular * inset) +{ + inset_ = inset; + + if (emergency_exit_) { + hide(); + return; + } + + if (!dialog_built_) { + view().build(); + dialog_built_ = true; + } + + bc().readOnly(bufferIsReadonly()); + view().show(); +} + + +void ControlTabular::update() +{ + if (emergency_exit_) { + hide(); + return; + } + + bc().readOnly(bufferIsReadonly()); + view().update(); + + // The widgets may not be valid, so refresh the button controller + // FIXME: needed ? + bc().refresh(); +} + + +void ControlTabular::hide() +{ + emergency_exit_ = false; + inset_ = 0; + + ih_.disconnect(); + disconnect(); + view().hide(); +} + + +void ControlTabular::updateSlot(bool switched) +{ + if (switched) + hide(); + else + update(); +} + + +void ControlTabular::connectInset(InsetTabular * inset) +{ + // If connected to another inset, disconnect from it. + if (inset_) { + ih_.disconnect(); + inset_ = 0; + } + + if (inset) { + inset_ = inset; + ih_ = inset->hideDialog.connect( + boost::bind(&ControlTabular::hide, this)); + } + connect(); +} + + +InsetTabular * ControlTabular::inset() const +{ + lyx::Assert(inset_); + return inset_; +} + + +LyXTabular * ControlTabular::tabular() const +{ + lyx::Assert(inset_); + return inset_->tabular.get(); +} + + +void ControlTabular::set(LyXTabular::Feature f, string const & arg) +{ + lyx::Assert(inset_); + inset_->tabularFeatures(lv_.view().get(), f, arg); +} + + +bool ControlTabular::metric() const +{ + return lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER; +} diff --git a/src/frontends/controllers/ControlTabular.h b/src/frontends/controllers/ControlTabular.h new file mode 100644 index 0000000000..86499c516e --- /dev/null +++ b/src/frontends/controllers/ControlTabular.h @@ -0,0 +1,77 @@ +// -*- C++ -*- +/** + * \file ControlTabular.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author John Levon + * + * Full author contact details are available in file CREDITS + * + * This is pretty icky, we should really be able to use + * ControlInset. We can't because there are no params for + * tabular inset. + */ + +#ifndef CONTROLTABULAR_H +#define CONTROLTABULAR_H + +#include "ControlConnections.h" +#include "LString.h" +#include "tabular.h" + +#include + +class InsetTabular; + +class ControlTabular : public ControlConnectBD { +public: + + ControlTabular(LyXView &, Dialogs &); + + /// get the inset + InsetTabular * inset() const; + + /// get the contained tabular + LyXTabular * tabular() const; + + /// set a parameter + void set(LyXTabular::Feature, string const & arg = string()); + + /// slot launching dialog to an existing inset. + void showInset(InsetTabular *); + + /// update inset + void updateInset(InsetTabular *); + + /// return true if units should default to metric + bool metric() const; + +private: + + /// we can't do this ... + virtual void apply() {}; + /// disconnect signals and hide View. + virtual void hide(); + /// update the dialog. + virtual void update(); + + /** Instantiation of ControlConnectBD private virtual method. + Slot connected to update signal. */ + virtual void updateSlot(bool); + + /// show the dialog. + void show(InsetTabular *); + /// connect signals + void connectInset(InsetTabular *); + + /// pointer to the inset passed through connectInset + InsetTabular * inset_; + /// inset::hide connection. + boost::signals::connection ih_; + + /// is the dialog built ? + bool dialog_built_; +}; + +#endif // CONTROLTABULAR_H diff --git a/src/frontends/controllers/Makefile.am b/src/frontends/controllers/Makefile.am index 72617fd46f..4f53db5df2 100644 --- a/src/frontends/controllers/Makefile.am +++ b/src/frontends/controllers/Makefile.am @@ -85,6 +85,8 @@ libcontrollers_la_SOURCES= \ ControlShowFile.h \ ControlSpellchecker.C \ ControlSpellchecker.h \ + ControlTabular.C \ + ControlTabular.h \ ControlTabularCreate.C \ ControlTabularCreate.h \ ControlTexinfo.C \ -- 2.39.2