prefs/tabular MVC work

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5634 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
John Levon 2002-11-15 02:41:54 +00:00
parent 77bdf5aa27
commit 127a0419fd
7 changed files with 400 additions and 8 deletions

View File

@ -1,3 +1,14 @@
2002-11-15 John Levon <levon@movementarian.org>
* 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 <j.spitzmueller@gmx.de>
* ControlInclude.C: fix file format masks for qt's use

View File

@ -49,8 +49,8 @@ public:
*/
///
void ApplyButton();
///
void OKButton();
/// virtual for ControlPrefs
virtual void OKButton();
///
void CancelButton();
///

View File

@ -14,25 +14,139 @@
#pragma implementation
#endif
#include "ControlPrefs.h"
#include <utility>
#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<string,string> dir1(name, dir);
dir = AddName(user_lyxdir, "bind");
// FIXME: stupid name
name = _("User Bind|#U#u");
pair<string,string> 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<string,string> dir1(name, dir);
dir = AddName(user_lyxdir, "ui");
// FIXME: stupid name
name = _("User UI|#U#u");
pair<string,string> 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<string, string> 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;
}

View File

@ -20,7 +20,12 @@
#include "LString.h"
#include "funcrequest.h"
#include "lyxrc.h"
#include "LColor.h"
#include <utility>
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();

View File

@ -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 <boost/bind.hpp>
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;
}

View File

@ -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 <boost/signals/connection.hpp>
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

View File

@ -85,6 +85,8 @@ libcontrollers_la_SOURCES= \
ControlShowFile.h \
ControlSpellchecker.C \
ControlSpellchecker.h \
ControlTabular.C \
ControlTabular.h \
ControlTabularCreate.C \
ControlTabularCreate.h \
ControlTexinfo.C \