A new LFUN_LYXRC_APPLY lfun, together with a bit of a clean-up of the

preferences dialog code.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8570 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2004-03-31 16:50:59 +00:00
parent 2baeac64ff
commit 931a49cc87
16 changed files with 281 additions and 186 deletions

View File

@ -1,3 +1,13 @@
2004-03-31 Angus Leeming <leeming@lyx.org>
* lfuns.h:
* LyXAction.C: new lfun LFUN_LYXRC_APPLY.
* lyxrc.[Ch] (read, write): overloaded member functions taking
a std::[io]stream arguments.
* lyxfunc.C (getStatus, dispatch): handle LFUN_LYXRC_APPLY.
2004-03-31 Angus Leeming <leeming@lyx.org> 2004-03-31 Angus Leeming <leeming@lyx.org>
* lyxfunc.C (loadTextclass): new helper function, invoked by two of * lyxfunc.C (loadTextclass): new helper function, invoked by two of

View File

@ -334,6 +334,7 @@ void LyXAction::init()
{ LFUN_TEXTCLASS_LOAD, "textclass-load", Noop }, { LFUN_TEXTCLASS_LOAD, "textclass-load", Noop },
{ LFUN_SAVE_AS_DEFAULT, "buffer-save-as-default", Noop }, { LFUN_SAVE_AS_DEFAULT, "buffer-save-as-default", Noop },
{ LFUN_BUFFERPARAMS_APPLY, "buffer-params-apply", Noop }, { LFUN_BUFFERPARAMS_APPLY, "buffer-params-apply", Noop },
{ LFUN_LYXRC_APPLY, "lyxrc-apply", NoBuffer },
{ LFUN_NOACTION, "", Noop } { LFUN_NOACTION, "", Noop }
}; };

View File

@ -1,3 +1,11 @@
2004-03-31 Angus Leeming <leeming@lyx.org>
* ControlPrefs.C: a bit of an overhaul, moving the local Converters
and Formats variables out of the various frontends to here,
and ensuring that nothing is actually dispatched to the core except
from apply().
Also use the new LFUN_LYXRC_APPLY lfun.
2004-03-30 Angus Leeming <leeming@lyx.org> 2004-03-30 Angus Leeming <leeming@lyx.org>
* ControlDocument.[Ch]: converted to the dialog-based scheme. * ControlDocument.[Ch]: converted to the dialog-based scheme.

View File

@ -16,12 +16,9 @@
#include "ViewBase.h" #include "ViewBase.h"
#include "bufferlist.h" #include "bufferlist.h"
#include "converter.h"
#include "format.h"
#include "gettext.h" #include "gettext.h"
#include "funcrequest.h" #include "funcrequest.h"
#include "LColor.h" #include "LColor.h"
#include "lfuns.h"
#include "frontends/Dialogs.h" #include "frontends/Dialogs.h"
#include "frontends/LyXView.h" #include "frontends/LyXView.h"
@ -30,6 +27,8 @@
#include "support/globbing.h" #include "support/globbing.h"
#include "support/path_defines.h" #include "support/path_defines.h"
#include "support/std_sstream.h"
#include <utility> #include <utility>
using lyx::support::AddName; using lyx::support::AddName;
@ -37,30 +36,66 @@ using lyx::support::FileFilterList;
using lyx::support::system_lyxdir; using lyx::support::system_lyxdir;
using lyx::support::user_lyxdir; using lyx::support::user_lyxdir;
using std::ostringstream;
using std::pair; using std::pair;
using std::string; using std::string;
using std::vector;
extern BufferList bufferlist; extern BufferList bufferlist;
ControlPrefs::ControlPrefs(LyXView & lv, Dialogs & d) ControlPrefs::ControlPrefs(LyXView & lv, Dialogs & d)
: ControlDialogBI(lv, d) : ControlDialogBI(lv, d),
redraw_gui_(false),
update_screen_font_(false)
{} {}
void ControlPrefs::setParams() void ControlPrefs::setParams()
{ {
rc_ = lyxrc; rc_ = lyxrc;
formats_ = ::formats;
converters_ = ::converters;
converters_.update(formats_);
colors_.clear();
redraw_gui_ = false;
update_screen_font_ = false;
} }
void ControlPrefs::apply() void ControlPrefs::apply()
{ {
view().apply(); view().apply();
lyxrc = rc_;
ostringstream ss;
rc_.write(ss);
lv_.dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str()));
// FIXME: these need lfuns
bufferlist.setCurrentAuthor(rc_.user_name, rc_.user_email); bufferlist.setCurrentAuthor(rc_.user_name, rc_.user_email);
::formats = formats_;
::converters = converters_;
::converters.update(::formats);
::converters.buildGraph();
vector<string>::const_iterator it = colors_.begin();
vector<string>::const_iterator const end = colors_.end();
for (; it != end; ++it)
lv_.dispatch(FuncRequest(LFUN_SET_COLOR, *it));
colors_.clear();
if (redraw_gui_) {
lv_.getDialogs().redrawGUI();
redraw_gui_ = false;
}
if (update_screen_font_) {
lv_.dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
update_screen_font_ = false;
}
// The Save button has been pressed // The Save button has been pressed
if (isClosing()) { if (isClosing()) {
lv_.dispatch(FuncRequest(LFUN_SAVEPREFERENCES)); lv_.dispatch(FuncRequest(LFUN_SAVEPREFERENCES));
@ -68,17 +103,31 @@ void ControlPrefs::apply()
} }
void ControlPrefs::redrawGUI()
{
redraw_gui_ = true;
}
void ControlPrefs::setColor(LColor_color col, string const & hex)
{
colors_.push_back(lcolor.getLyXName(col) + ' ' + hex);
}
void ControlPrefs::updateScreenFonts()
{
update_screen_font_ = true;
}
string const ControlPrefs::browsebind(string const & file) const string const ControlPrefs::browsebind(string const & file) const
{ {
string dir = AddName(system_lyxdir(), "bind"); pair<string,string> dir1(_("System Bind|#S#s"),
// FIXME: stupid name AddName(system_lyxdir(), "bind"));
string name = _("System Bind|#S#s");
pair<string,string> dir1(name, dir);
dir = AddName(user_lyxdir(), "bind"); pair<string,string> dir2(_("User Bind|#U#u"),
// FIXME: stupid name AddName(user_lyxdir(), "bind"));
name = _("User Bind|#U#u");
pair<string,string> dir2(name, dir);
return browseFile(file, _("Choose bind file"), return browseFile(file, _("Choose bind file"),
FileFilterList("*.bind"), false, dir1, dir2); FileFilterList("*.bind"), false, dir1, dir2);
@ -87,15 +136,11 @@ string const ControlPrefs::browsebind(string const & file) const
string const ControlPrefs::browseUI(string const & file) const string const ControlPrefs::browseUI(string const & file) const
{ {
string dir = AddName(system_lyxdir(), "ui"); pair<string,string> const dir1(_("Sys UI|#S#s"),
// FIXME: stupid name AddName(system_lyxdir(), "ui"));
string name = _("Sys UI|#S#s");
pair<string,string> dir1(name, dir);
dir = AddName(user_lyxdir(), "ui"); pair<string,string> const dir2(_("User UI|#U#u"),
// FIXME: stupid name AddName(user_lyxdir(), "ui"));
name = _("User UI|#U#u");
pair<string,string> dir2(name, dir);
return browseFile(file, _("Choose UI file"), return browseFile(file, _("Choose UI file"),
FileFilterList("*.ui"), false, dir1, dir2); FileFilterList("*.ui"), false, dir1, dir2);
@ -104,12 +149,11 @@ string const ControlPrefs::browseUI(string const & file) const
string const ControlPrefs::browsekbmap(string const & file) const string const ControlPrefs::browsekbmap(string const & file) const
{ {
string const dir = AddName(system_lyxdir(), "kbd"); pair<string, string> dir(_("Key maps|#K#k"),
string const name = _("Key maps|#K#k"); AddName(system_lyxdir(), "kbd"));
pair<string, string> dir1(name, dir);
return browseFile(file, _("Choose keyboard map"), return browseFile(file, _("Choose keyboard map"),
FileFilterList("*.kmap"), false, dir1); FileFilterList("*.kmap"), false, dir);
} }
@ -132,42 +176,3 @@ string const ControlPrefs::browsedir(string const & path,
{ {
return browseDir(path, title); return browseDir(path, 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) + ' ' + 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

@ -12,27 +12,30 @@
#ifndef CONTROLPREFS_H #ifndef CONTROLPREFS_H
#define CONTROLPREFS_H #define CONTROLPREFS_H
#include "ControlDialog_impl.h" #include "ControlDialog_impl.h"
#include "converter.h"
#include "format.h"
#include "lyxrc.h" #include "lyxrc.h"
#include <string>
#include <vector>
class Converters;
class LColor_color; class LColor_color;
class Formats;
class ControlPrefs : public ControlDialogBI { class ControlPrefs : public ControlDialogBI {
public: public:
ControlPrefs(LyXView &, Dialogs &); ControlPrefs(LyXView &, Dialogs &);
// FIXME: we should probably devolve the individual
// settings to methods here. But for now, this will
// do
LyXRC & rc() { return rc_; } LyXRC & rc() { return rc_; }
LyXRC const & rc() const { return rc_; } LyXRC const & rc() const { return rc_; }
Converters & converters() { return converters_; }
Converters const & converters() const { return converters_; }
Formats & formats() { return formats_; }
Formats const & formats() const { return formats_; }
/// various file pickers /// various file pickers
std::string const browsebind(std::string const & file) const; std::string const browsebind(std::string const & file) const;
std::string const browseUI(std::string const & file) const; std::string const browseUI(std::string const & file) const;
@ -56,12 +59,6 @@ public:
/// update the screen fonts after change /// update the screen fonts after change
void updateScreenFonts(); void updateScreenFonts();
/// set global converters
void setConverters(Converters const & conv);
/// set global formats
void setFormats(Formats const & form);
private: private:
/// get current lyxrc /// get current lyxrc
virtual void setParams(); virtual void setParams();
@ -71,6 +68,18 @@ private:
/// temporary lyxrc /// temporary lyxrc
LyXRC rc_; LyXRC rc_;
/// temporary converters
Converters converters_;
/// temporary formats
Formats formats_;
/// A list of colors to be dispatched
std::vector<std::string> colors_;
bool redraw_gui_;
bool update_screen_font_;
}; };
#endif // CONTROLPREFS_H #endif // CONTROLPREFS_H

View File

@ -1,3 +1,8 @@
2004-03-31 Angus Leeming <leeming@lyx.org>
* QPrefs.[Ch]:
* QPrefsDialog.C: changes due to the changed ControlPrefs interface.
2004-03-30 Angus Leeming <leeming@lyx.org> 2004-03-30 Angus Leeming <leeming@lyx.org>
* Dialogs.C (build): added document dialog. * Dialogs.C (build): added document dialog.

View File

@ -73,6 +73,18 @@ QPrefs::QPrefs()
} }
Converters & QPrefs::converters()
{
return controller().converters();
}
Formats & QPrefs::formats()
{
return controller().formats();
}
void QPrefs::build_dialog() void QPrefs::build_dialog()
{ {
dialog_.reset(new QPrefsDialog(this)); dialog_.reset(new QPrefsDialog(this));
@ -287,9 +299,6 @@ void QPrefs::apply()
controller().updateScreenFonts(); controller().updateScreenFonts();
} }
controller().setFormats(formats_);
controller().setConverters(converters_);
QPrefColorsModule * colmod(dialog_->colorsModule); QPrefColorsModule * colmod(dialog_->colorsModule);
unsigned int i; unsigned int i;
@ -582,11 +591,7 @@ void QPrefs::update_contents()
fontmod->screenHugeED->setText(toqstr(tostr(rc.font_sizes[LyXFont::SIZE_HUGE]))); fontmod->screenHugeED->setText(toqstr(tostr(rc.font_sizes[LyXFont::SIZE_HUGE])));
fontmod->screenHugerED->setText(toqstr(tostr(rc.font_sizes[LyXFont::SIZE_HUGER]))); fontmod->screenHugerED->setText(toqstr(tostr(rc.font_sizes[LyXFont::SIZE_HUGER])));
formats_ = formats;
dialog_->updateFormats(); dialog_->updateFormats();
converters_ = converters;
dialog_->updateConverters(); dialog_->updateConverters();
} }

View File

@ -13,8 +13,6 @@
#define QPREFS_H #define QPREFS_H
#include "converter.h"
#include "format.h"
#include "ControlPrefs.h" #include "ControlPrefs.h"
#include "Qt2Base.h" #include "Qt2Base.h"
@ -22,6 +20,8 @@
#include <vector> #include <vector>
class QPrefsDialog; class QPrefsDialog;
class Controllers;
class Formats;
class QPrefs class QPrefs
: public Qt2CB<ControlPrefs, Qt2DB<QPrefsDialog> > : public Qt2CB<ControlPrefs, Qt2DB<QPrefsDialog> >
@ -42,14 +42,11 @@ private:
/// build the dialog /// build the dialog
virtual void build_dialog(); virtual void build_dialog();
Converters & converters();
Formats & formats();
/// languages /// languages
std::vector<std::string> lang_; std::vector<std::string> lang_;
/// converters
Converters converters_;
/// formats
Formats formats_;
}; };
#endif // QPREFS_H #endif // QPREFS_H

View File

@ -282,8 +282,8 @@ void QPrefsDialog::updateConverters()
convertmod->converterFromCO->clear(); convertmod->converterFromCO->clear();
convertmod->converterToCO->clear(); convertmod->converterToCO->clear();
Formats::const_iterator cit = form_->formats_.begin(); Formats::const_iterator cit = form_->formats().begin();
Formats::const_iterator end = form_->formats_.end(); Formats::const_iterator end = form_->formats().end();
for (; cit != end; ++cit) { for (; cit != end; ++cit) {
convertmod->converterFromCO->insertItem(toqstr(cit->prettyname())); convertmod->converterFromCO->insertItem(toqstr(cit->prettyname()));
convertmod->converterToCO->insertItem(toqstr(cit->prettyname())); convertmod->converterToCO->insertItem(toqstr(cit->prettyname()));
@ -291,8 +291,8 @@ void QPrefsDialog::updateConverters()
convertmod->convertersLB->clear(); convertmod->convertersLB->clear();
Converters::const_iterator ccit = form_->converters_.begin(); Converters::const_iterator ccit = form_->converters().begin();
Converters::const_iterator cend = form_->converters_.end(); Converters::const_iterator cend = form_->converters().end();
for (; ccit != cend; ++ccit) { for (; ccit != cend; ++ccit) {
string const name(ccit->From->prettyname() + " -> " + string const name(ccit->From->prettyname() + " -> " +
ccit->To->prettyname()); ccit->To->prettyname());
@ -306,9 +306,9 @@ void QPrefsDialog::updateConverters()
void QPrefsDialog::switch_converter(int nr) void QPrefsDialog::switch_converter(int nr)
{ {
Converter const & c(form_->converters_.get(nr)); Converter const & c(form_->converters().get(nr));
convertersModule->converterFromCO->setCurrentItem(form_->formats_.getNumber(c.from)); convertersModule->converterFromCO->setCurrentItem(form_->formats().getNumber(c.from));
convertersModule->converterToCO->setCurrentItem(form_->formats_.getNumber(c.to)); convertersModule->converterToCO->setCurrentItem(form_->formats().getNumber(c.to));
convertersModule->converterED->setText(toqstr(c.command)); convertersModule->converterED->setText(toqstr(c.command));
convertersModule->converterFlagED->setText(toqstr(c.flags)); convertersModule->converterFlagED->setText(toqstr(c.flags));
} }
@ -318,13 +318,13 @@ void QPrefsDialog::switch_converter(int nr)
// specify unique from/to or it doesn't appear. This is really bad UI // specify unique from/to or it doesn't appear. This is really bad UI
void QPrefsDialog::new_converter() void QPrefsDialog::new_converter()
{ {
Format const & from(form_->formats_.get(convertersModule->converterFromCO->currentItem())); Format const & from(form_->formats().get(convertersModule->converterFromCO->currentItem()));
Format const & to(form_->formats_.get(convertersModule->converterToCO->currentItem())); Format const & to(form_->formats().get(convertersModule->converterToCO->currentItem()));
Converter const * old = form_->converters_.getConverter(from.name(), to.name()); Converter const * old = form_->converters().getConverter(from.name(), to.name());
form_->converters_.add(from.name(), to.name(), "", ""); form_->converters().add(from.name(), to.name(), "", "");
if (!old) { if (!old) {
form_->converters_.updateLast(form_->formats_); form_->converters().updateLast(form_->formats());
} }
updateConverters(); updateConverters();
convertersModule->convertersLB->setCurrentItem(convertersModule->convertersLB->count() - 1); convertersModule->convertersLB->setCurrentItem(convertersModule->convertersLB->count() - 1);
@ -333,15 +333,15 @@ void QPrefsDialog::new_converter()
void QPrefsDialog::modify_converter() void QPrefsDialog::modify_converter()
{ {
Format const & from(form_->formats_.get(convertersModule->converterFromCO->currentItem())); Format const & from(form_->formats().get(convertersModule->converterFromCO->currentItem()));
Format const & to(form_->formats_.get(convertersModule->converterToCO->currentItem())); Format const & to(form_->formats().get(convertersModule->converterToCO->currentItem()));
string flags(fromqstr(convertersModule->converterFlagED->text())); string flags(fromqstr(convertersModule->converterFlagED->text()));
string name(fromqstr(convertersModule->converterED->text())); string name(fromqstr(convertersModule->converterED->text()));
Converter const * old = form_->converters_.getConverter(from.name(), to.name()); Converter const * old = form_->converters().getConverter(from.name(), to.name());
form_->converters_.add(from.name(), to.name(), name, flags); form_->converters().add(from.name(), to.name(), name, flags);
if (!old) { if (!old) {
form_->converters_.updateLast(form_->formats_); form_->converters().updateLast(form_->formats());
} }
updateConverters(); updateConverters();
} }
@ -349,9 +349,9 @@ void QPrefsDialog::modify_converter()
void QPrefsDialog::remove_converter() void QPrefsDialog::remove_converter()
{ {
Format const & from(form_->formats_.get(convertersModule->converterFromCO->currentItem())); Format const & from(form_->formats().get(convertersModule->converterFromCO->currentItem()));
Format const & to(form_->formats_.get(convertersModule->converterToCO->currentItem())); Format const & to(form_->formats().get(convertersModule->converterToCO->currentItem()));
form_->converters_.erase(from.name(), to.name()); form_->converters().erase(from.name(), to.name());
updateConverters(); updateConverters();
} }
@ -362,8 +362,8 @@ void QPrefsDialog::updateFormats()
formatmod->formatsLB->clear(); formatmod->formatsLB->clear();
Formats::const_iterator cit = form_->formats_.begin(); Formats::const_iterator cit = form_->formats().begin();
Formats::const_iterator end = form_->formats_.end(); Formats::const_iterator end = form_->formats().end();
for (; cit != end; ++cit) { for (; cit != end; ++cit) {
formatmod->formatsLB->insertItem(toqstr(cit->prettyname())); formatmod->formatsLB->insertItem(toqstr(cit->prettyname()));
} }
@ -375,42 +375,42 @@ void QPrefsDialog::updateFormats()
void QPrefsDialog::switch_format(int nr) void QPrefsDialog::switch_format(int nr)
{ {
Format const & f(form_->formats_.get(nr)); Format const & f(form_->formats().get(nr));
fileformatsModule->formatED->setText(toqstr(f.name())); fileformatsModule->formatED->setText(toqstr(f.name()));
fileformatsModule->guiNameED->setText(toqstr(f.prettyname())); fileformatsModule->guiNameED->setText(toqstr(f.prettyname()));
fileformatsModule->extensionED->setText(toqstr(f.extension())); fileformatsModule->extensionED->setText(toqstr(f.extension()));
fileformatsModule->shortcutED->setText(toqstr(f.shortcut())); fileformatsModule->shortcutED->setText(toqstr(f.shortcut()));
fileformatsModule->viewerED->setText(toqstr(f.viewer())); fileformatsModule->viewerED->setText(toqstr(f.viewer()));
fileformatsModule->formatRemovePB->setEnabled( fileformatsModule->formatRemovePB->setEnabled(
!form_->converters_.formatIsUsed(f.name())); !form_->converters().formatIsUsed(f.name()));
} }
void QPrefsDialog::new_format() void QPrefsDialog::new_format()
{ {
form_->formats_.add(_("New")); form_->formats().add(_("New"));
form_->formats_.sort(); form_->formats().sort();
updateFormats(); updateFormats();
fileformatsModule->formatsLB->setCurrentItem(form_->formats_.getNumber(_("New"))); fileformatsModule->formatsLB->setCurrentItem(form_->formats().getNumber(_("New")));
updateConverters(); updateConverters();
} }
void QPrefsDialog::modify_format() void QPrefsDialog::modify_format()
{ {
Format const & oldformat(form_->formats_.get(fileformatsModule->formatsLB->currentItem())); Format const & oldformat(form_->formats().get(fileformatsModule->formatsLB->currentItem()));
string const oldpretty(oldformat.prettyname()); string const oldpretty(oldformat.prettyname());
string const name(fromqstr(fileformatsModule->formatED->text())); string const name(fromqstr(fileformatsModule->formatED->text()));
form_->formats_.erase(oldformat.name()); form_->formats().erase(oldformat.name());
string const prettyname = fromqstr(fileformatsModule->guiNameED->text()); string const prettyname = fromqstr(fileformatsModule->guiNameED->text());
string const extension = fromqstr(fileformatsModule->extensionED->text()); string const extension = fromqstr(fileformatsModule->extensionED->text());
string const shortcut = fromqstr(fileformatsModule->shortcutED->text()); string const shortcut = fromqstr(fileformatsModule->shortcutED->text());
string const viewer = fromqstr(fileformatsModule->viewerED->text()); string const viewer = fromqstr(fileformatsModule->viewerED->text());
form_->formats_.add(name, extension, prettyname, shortcut); form_->formats().add(name, extension, prettyname, shortcut);
form_->formats_.sort(); form_->formats().sort();
form_->formats_.setViewer(name, viewer); form_->formats().setViewer(name, viewer);
fileformatsModule->formatsLB->setUpdatesEnabled(false); fileformatsModule->formatsLB->setUpdatesEnabled(false);
updateFormats(); updateFormats();
@ -426,7 +426,7 @@ void QPrefsDialog::remove_format()
int const nr(fileformatsModule->formatsLB->currentItem()); int const nr(fileformatsModule->formatsLB->currentItem());
if (nr < 0) if (nr < 0)
return; return;
form_->formats_.erase(form_->formats_.get(nr).name()); form_->formats().erase(form_->formats().get(nr).name());
updateFormats(); updateFormats();
updateConverters(); updateConverters();
} }

View File

@ -1,3 +1,8 @@
2004-03-31 Angus Leeming <leeming@lyx.org>
* FormPreferences.[Ch]: changes due to the changed ControlPrefs
interface.
2004-03-30 Angus Leeming <leeming@lyx.org> 2004-03-30 Angus Leeming <leeming@lyx.org>
* Dialogs.C (build): added document dialog. * Dialogs.C (build): added document dialog.

View File

@ -24,8 +24,6 @@
#include "controllers/helper_funcs.h" // getSecond #include "controllers/helper_funcs.h" // getSecond
#include "buffer.h" #include "buffer.h"
#include "converter.h"
#include "format.h"
#include "LColor.h" #include "LColor.h"
#include "lyxfont.h" #include "lyxfont.h"
@ -58,10 +56,6 @@ using std::string;
namespace { namespace {
// These should probably go inside the class definition...
Formats local_formats;
Converters local_converters;
string makeFontName(string const & family, string const & foundry) string makeFontName(string const & family, string const & foundry)
{ {
if (foundry.empty()) if (foundry.empty())
@ -291,8 +285,6 @@ void FormPreferences::apply()
LyXRC & rc(controller().rc()); LyXRC & rc(controller().rc());
colors_.apply(); colors_.apply();
formats_.apply(); // Must be before converters_.apply()
converters_.apply();
inputs_misc_.apply(rc); inputs_misc_.apply(rc);
interface_.apply(rc); interface_.apply(rc);
language_.apply(rc); language_.apply(rc);
@ -716,9 +708,15 @@ FD_preferences_converters const * FormPreferences::Converters::dialog()
} }
void FormPreferences::Converters::apply() const ::Converters & FormPreferences::Converters::converters()
{ {
parent_.controller().setConverters(local_converters); return parent_.controller().converters();
}
::Formats & FormPreferences::Converters::formats()
{
return parent_.controller().formats();
} }
@ -802,20 +800,18 @@ bool FormPreferences::Converters::input(FL_OBJECT const * const ob)
void FormPreferences::Converters::update() void FormPreferences::Converters::update()
{ {
local_converters = converters;
local_converters.update(local_formats);
UpdateBrowser(); UpdateBrowser();
} }
void FormPreferences::Converters::UpdateBrowser() void FormPreferences::Converters::UpdateBrowser()
{ {
local_converters.sort(); converters().sort();
fl_freeze_form(dialog_->form); fl_freeze_form(dialog_->form);
fl_clear_browser(dialog_->browser_all); fl_clear_browser(dialog_->browser_all);
for (::Converters::const_iterator cit = local_converters.begin(); for (::Converters::const_iterator cit = converters().begin();
cit != local_converters.end(); ++cit) { cit != converters().end(); ++cit) {
string const name = cit->From->prettyname() + " -> " string const name = cit->From->prettyname() + " -> "
+ cit->To->prettyname(); + cit->To->prettyname();
fl_addto_browser(dialog_->browser_all, name.c_str()); fl_addto_browser(dialog_->browser_all, name.c_str());
@ -832,10 +828,10 @@ bool FormPreferences::Converters::Add()
string const command = fl_get_input(dialog_->input_converter); string const command = fl_get_input(dialog_->input_converter);
string const flags = fl_get_input(dialog_->input_flags); string const flags = fl_get_input(dialog_->input_flags);
Converter const * old = local_converters.getConverter(from, to); Converter const * old = converters().getConverter(from, to);
local_converters.add(from, to, command, flags); converters().add(from, to, command, flags);
if (!old) { if (!old) {
local_converters.updateLast(local_formats); converters().updateLast(formats());
UpdateBrowser(); UpdateBrowser();
} }
setEnabled(dialog_->button_add, false); setEnabled(dialog_->button_add, false);
@ -851,12 +847,12 @@ bool FormPreferences::Converters::Browser()
fl_freeze_form(dialog_->form); fl_freeze_form(dialog_->form);
Converter const & c = local_converters.get(i - 1); Converter const & c = converters().get(i - 1);
int j = local_formats.getNumber(c.from); int j = formats().getNumber(c.from);
if (j >= 0) if (j >= 0)
fl_set_choice(dialog_->choice_from, j + 1); fl_set_choice(dialog_->choice_from, j + 1);
j = local_formats.getNumber(c.to); j = formats().getNumber(c.to);
if (j >= 0) if (j >= 0)
fl_set_choice(dialog_->choice_to, j + 1); fl_set_choice(dialog_->choice_to, j + 1);
@ -880,7 +876,7 @@ bool FormPreferences::Converters::erase()
string const from = GetFrom(); string const from = GetFrom();
string const to = GetTo(); string const to = GetTo();
local_converters.erase(from, to); converters().erase(from, to);
UpdateBrowser(); UpdateBrowser();
return true; return true;
} }
@ -890,7 +886,7 @@ bool FormPreferences::Converters::Input()
{ {
string const from = GetFrom(); string const from = GetFrom();
string const to = GetTo(); string const to = GetTo();
int const sel = local_converters.getNumber(from, to); int const sel = converters().getNumber(from, to);
fl_freeze_form(dialog_->form); fl_freeze_form(dialog_->form);
@ -924,37 +920,37 @@ bool FormPreferences::Converters::Input()
} }
string const FormPreferences::Converters::GetFrom() const string const FormPreferences::Converters::GetFrom()
{ {
::Formats::FormatList::size_type const i = ::Formats::FormatList::size_type const i =
fl_get_choice(dialog_->choice_from); fl_get_choice(dialog_->choice_from);
if (i > 0 && i <= local_formats.size()) if (i > 0 && i <= formats().size())
return local_formats.get(i - 1).name(); return formats().get(i - 1).name();
lyxerr << "FormPreferences::Converters::GetFrom: No choice!" << endl; lyxerr << "FormPreferences::Converters::GetFrom: No choice!" << endl;
return "???"; return "???";
} }
string const FormPreferences::Converters::GetTo() const string const FormPreferences::Converters::GetTo()
{ {
::Formats::FormatList::size_type const i = ::Formats::FormatList::size_type const i =
fl_get_choice(dialog_->choice_to); fl_get_choice(dialog_->choice_to);
if (i > 0 && i <= local_formats.size()) if (i > 0 && i <= formats().size())
return local_formats.get(i - 1).name(); return formats().get(i - 1).name();
lyxerr << "FormPreferences::Converters::GetTo: No choice!" << endl; lyxerr << "FormPreferences::Converters::GetTo: No choice!" << endl;
return "???"; return "???";
} }
void FormPreferences::Converters::UpdateChoices() const void FormPreferences::Converters::UpdateChoices()
{ {
string choice; string choice;
for (::Formats::const_iterator cit = local_formats.begin(); for (::Formats::const_iterator cit = formats().begin();
cit != local_formats.end(); ++cit) { cit != formats().end(); ++cit) {
if (!choice.empty()) if (!choice.empty())
choice += " | "; choice += " | ";
else else
@ -982,9 +978,15 @@ FD_preferences_formats const * FormPreferences::Formats::dialog()
} }
void FormPreferences::Formats::apply() const ::Converters & FormPreferences::Formats::converters()
{ {
parent_.controller().setFormats(local_formats); return parent_.controller().converters();
}
::Formats & FormPreferences::Formats::formats()
{
return parent_.controller().formats();
} }
@ -1075,20 +1077,19 @@ bool FormPreferences::Formats::input(FL_OBJECT const * const ob)
void FormPreferences::Formats::update() void FormPreferences::Formats::update()
{ {
local_formats = formats;
UpdateBrowser(); UpdateBrowser();
} }
void FormPreferences::Formats::UpdateBrowser() void FormPreferences::Formats::UpdateBrowser()
{ {
local_formats.sort(); formats().sort();
fl_freeze_form(dialog_->form); fl_freeze_form(dialog_->form);
fl_deselect_browser(dialog_->browser_all); fl_deselect_browser(dialog_->browser_all);
fl_clear_browser(dialog_->browser_all); fl_clear_browser(dialog_->browser_all);
for (::Formats::const_iterator cit = local_formats.begin(); for (::Formats::const_iterator cit = formats().begin();
cit != local_formats.end(); ++cit) cit != formats().end(); ++cit)
fl_addto_browser(dialog_->browser_all, fl_addto_browser(dialog_->browser_all,
cit->prettyname().c_str()); cit->prettyname().c_str());
@ -1097,7 +1098,7 @@ void FormPreferences::Formats::UpdateBrowser()
// Mustn't forget to update the Formats available to the converters_ // Mustn't forget to update the Formats available to the converters_
parent_.converters_.UpdateChoices(); parent_.converters_.UpdateChoices();
local_converters.update(local_formats); converters().update(formats());
} }
@ -1109,10 +1110,10 @@ bool FormPreferences::Formats::Add()
string const shortcut = fl_get_input(dialog_->input_shrtcut); string const shortcut = fl_get_input(dialog_->input_shrtcut);
string const viewer = fl_get_input(dialog_->input_viewer); string const viewer = fl_get_input(dialog_->input_viewer);
Format const * old = local_formats.getFormat(name); Format const * old = formats().getFormat(name);
string const old_prettyname = old ? old->prettyname() : string(); string const old_prettyname = old ? old->prettyname() : string();
local_formats.add(name, extension, prettyname, shortcut); formats().add(name, extension, prettyname, shortcut);
local_formats.setViewer(name, viewer); formats().setViewer(name, viewer);
if (!old || prettyname != old_prettyname) { if (!old || prettyname != old_prettyname) {
UpdateBrowser(); UpdateBrowser();
if (old) if (old)
@ -1132,7 +1133,7 @@ bool FormPreferences::Formats::Browser()
fl_freeze_form(dialog_->form); fl_freeze_form(dialog_->form);
Format const & f = local_formats.get(i - 1); Format const & f = formats().get(i - 1);
fl_set_input(dialog_->input_format, f.name().c_str()); fl_set_input(dialog_->input_format, f.name().c_str());
fl_set_input(dialog_->input_gui_name, f.prettyname().c_str()); fl_set_input(dialog_->input_gui_name, f.prettyname().c_str());
@ -1157,14 +1158,14 @@ bool FormPreferences::Formats::erase()
{ {
string const name = fl_get_input(dialog_->input_format); string const name = fl_get_input(dialog_->input_format);
if (local_converters.formatIsUsed(name)) { if (converters().formatIsUsed(name)) {
parent_.postWarning(_("Cannot remove a Format used by a Converter. " parent_.postWarning(_("Cannot remove a Format used by a Converter. "
"Remove the converter first.")); "Remove the converter first."));
setEnabled(dialog_->button_delete, false); setEnabled(dialog_->button_delete, false);
return false; return false;
} }
local_formats.erase(name); formats().erase(name);
UpdateBrowser(); UpdateBrowser();
return true; return true;
} }
@ -1173,7 +1174,7 @@ bool FormPreferences::Formats::erase()
bool FormPreferences::Formats::Input() bool FormPreferences::Formats::Input()
{ {
string const name = fl_get_input(dialog_->input_format); string const name = fl_get_input(dialog_->input_format);
int const sel = local_formats.getNumber(name); int const sel = formats().getNumber(name);
fl_freeze_form(dialog_->form); fl_freeze_form(dialog_->form);
if (sel < 0) { if (sel < 0) {

View File

@ -20,6 +20,8 @@
#include <boost/scoped_ptr.hpp> #include <boost/scoped_ptr.hpp>
class ControlPrefs; class ControlPrefs;
class Converters;
class Formats;
class Dialogs; class Dialogs;
class FormColorpicker; class FormColorpicker;
@ -142,8 +144,6 @@ private:
/// ///
FD_preferences_converters const * dialog(); FD_preferences_converters const * dialog();
/// ///
void apply() const;
///
void build(); void build();
/// ///
std::string const feedback(FL_OBJECT const * const) const; std::string const feedback(FL_OBJECT const * const) const;
@ -154,7 +154,7 @@ private:
/// ///
void UpdateBrowser(); void UpdateBrowser();
/// ///
void UpdateChoices() const; void UpdateChoices();
private: private:
/// ///
@ -166,9 +166,12 @@ private:
/// ///
bool Input(); bool Input();
/// ///
std::string const GetFrom() const; std::string const GetFrom();
/// ///
std::string const GetTo() const; std::string const GetTo();
///
::Converters & converters();
::Formats & formats();
/// ///
FormPreferences & parent_; FormPreferences & parent_;
@ -186,8 +189,6 @@ private:
/// ///
FD_preferences_formats const * dialog(); FD_preferences_formats const * dialog();
/// ///
void apply() const;
///
void build(); void build();
/// ///
std::string const feedback(FL_OBJECT const * const) const; std::string const feedback(FL_OBJECT const * const) const;
@ -207,6 +208,9 @@ private:
bool erase(); bool erase();
/// ///
bool Input(); bool Input();
//
::Converters & converters();
::Formats & formats();
/// ///
FormPreferences & parent_; FormPreferences & parent_;

View File

@ -347,6 +347,7 @@ enum kb_action {
LFUN_SAVE_AS_DEFAULT, LFUN_SAVE_AS_DEFAULT,
LFUN_BUFFERPARAMS_APPLY, LFUN_BUFFERPARAMS_APPLY,
// 265 // 265
LFUN_LYXRC_APPLY,
LFUN_LASTACTION // end of the table LFUN_LASTACTION // end of the table
}; };

View File

@ -506,6 +506,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
case LFUN_TEXTCLASS_LOAD: case LFUN_TEXTCLASS_LOAD:
case LFUN_SAVE_AS_DEFAULT: case LFUN_SAVE_AS_DEFAULT:
case LFUN_BUFFERPARAMS_APPLY: case LFUN_BUFFERPARAMS_APPLY:
case LFUN_LYXRC_APPLY:
// these are handled in our dispatch() // these are handled in our dispatch()
break; break;
@ -1367,6 +1368,18 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
loadTextclass(argument); loadTextclass(argument);
break; break;
case LFUN_LYXRC_APPLY: {
istringstream ss(argument);
bool const success = lyxrc.read(ss) == 0;
if (!success) {
lyxerr << "Warning in LFUN_LYXRC_APPLY!\n"
<< "Unable to read lyxrc data"
<< endl;
}
break;
}
default: { default: {
DispatchResult res = view()->cursor().dispatch(cmd); DispatchResult res = view()->cursor().dispatch(cmd);
if (!res.dispatched()); if (!res.dispatched());

View File

@ -303,6 +303,29 @@ int LyXRC::read(string const & filename)
lyxerr[Debug::LYXRC] << "Reading '" << filename << "'..." << endl; lyxerr[Debug::LYXRC] << "Reading '" << filename << "'..." << endl;
return read(lexrc);
}
int LyXRC::read(std::istream & is)
{
LyXLex lexrc(lyxrcTags, lyxrcCount);
if (lyxerr.debugging(Debug::PARSER))
lexrc.printTable(lyxerr);
lexrc.setStream(is);
if (!lexrc.isOK()) return -2;
lyxerr[Debug::LYXRC] << "Reading istream..." << endl;
return read(lexrc);
}
int LyXRC::read(LyXLex & lexrc)
{
if (!lexrc.isOK()) return -2;
while (lexrc.isOK()) { while (lexrc.isOK()) {
// By using two switches we take advantage of the compiler // By using two switches we take advantage of the compiler
// telling us if we have missed a LyXRCTags element in // telling us if we have missed a LyXRCTags element in
@ -569,7 +592,7 @@ int LyXRC::read(string const & filename)
dpi = lexrc.getInteger(); dpi = lexrc.getInteger();
} }
break; break;
1G
case RC_SCREEN_ZOOM: case RC_SCREEN_ZOOM:
if (lexrc.next()) { if (lexrc.next()) {
zoom = lexrc.getInteger(); zoom = lexrc.getInteger();
@ -1052,20 +1075,20 @@ void LyXRC::write(string const & filename) const
{ {
ofstream ofs(filename.c_str()); ofstream ofs(filename.c_str());
if (ofs) if (ofs)
output(ofs); write(ofs);
} }
void LyXRC::print() const void LyXRC::print() const
{ {
if (lyxerr.debugging()) if (lyxerr.debugging())
output(lyxerr); write(lyxerr);
else else
output(cout); write(cout);
} }
void LyXRC::output(ostream & os) const void LyXRC::write(ostream & os) const
{ {
os << "### This file is part of\n" os << "### This file is part of\n"
<< "### ========================================================\n" << "### ========================================================\n"

View File

@ -21,8 +21,10 @@
#include "paper.h" #include "paper.h"
#include "graphics/GraphicsTypes.h" #include "graphics/GraphicsTypes.h"
#include <iosfwd>
#include <string> #include <string>
class LyXLex;
/// This contains the runtime configuration of LyX /// This contains the runtime configuration of LyX
class LyXRC //: public noncopyable { class LyXRC //: public noncopyable {
@ -139,12 +141,18 @@ enum LyXRCTags {
void setDefaults(); void setDefaults();
/// ///
int read(std::string const & filename); int read(std::string const & filename);
///
int read(std::istream &);
private:
///
int read(LyXLex &);
public:
/// ///
void write(std::string const & filename) const; void write(std::string const & filename) const;
/// ///
void print() const; void write(std::ostream & os) const;
/// ///
void output(std::ostream & os) const; void print() const;
/// ///
static std::string const getDescription(LyXRCTags); static std::string const getDescription(LyXRCTags);
/// ///