git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20809 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2007-10-07 09:47:12 +00:00
parent 3f554746dc
commit 30725acc58
6 changed files with 293 additions and 402 deletions

View File

@ -1,210 +0,0 @@
/**
* \file ControlPrefs.cpp
* 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 <config.h>
#include "ControlPrefs.h"
#include "frontend_helpers.h"
#include "BufferList.h"
#include "gettext.h"
#include "FuncRequest.h"
#include "paper.h"
#include "Color.h"
#include "support/FileFilterList.h"
#include <sstream>
using std::ostringstream;
using std::pair;
using std::string;
using std::vector;
using lyx::support::FileFilterList;
namespace lyx {
namespace frontend {
ControlPrefs::ControlPrefs(Dialog & parent)
: Controller(parent),
update_screen_font_(false)
{}
bool ControlPrefs::initialiseParams(std::string const &)
{
rc_ = lyxrc;
formats_ = lyx::formats;
converters_ = theConverters();
converters_.update(formats_);
movers_ = theMovers();
colors_.clear();
update_screen_font_ = false;
return true;
}
void ControlPrefs::dispatchParams()
{
ostringstream ss;
rc_.write(ss, true);
dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str()));
// FIXME: these need lfuns
// FIXME UNICODE
theBufferList().setCurrentAuthor(from_utf8(rc_.user_name), from_utf8(rc_.user_email));
lyx::formats = formats_;
theConverters() = converters_;
theConverters().update(lyx::formats);
theConverters().buildGraph();
theMovers() = movers_;
vector<string>::const_iterator it = colors_.begin();
vector<string>::const_iterator const end = colors_.end();
for (; it != end; ++it)
dispatch(FuncRequest(LFUN_SET_COLOR, *it));
colors_.clear();
if (update_screen_font_) {
dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
update_screen_font_ = false;
}
// The Save button has been pressed
if (dialog().isClosing()) {
dispatch(FuncRequest(LFUN_PREFERENCES_SAVE));
}
}
void ControlPrefs::setColor(Color_color col, string const & hex)
{
colors_.push_back(lcolor.getLyXName(col) + ' ' + hex);
}
void ControlPrefs::updateScreenFonts()
{
update_screen_font_ = true;
}
docstring const ControlPrefs::browsebind(docstring const & file) const
{
return browseLibFile(from_ascii("bind"), file, from_ascii("bind"),
_("Choose bind file"),
FileFilterList(_("LyX bind files (*.bind)")));
}
docstring const ControlPrefs::browseUI(docstring const & file) const
{
return browseLibFile(from_ascii("ui"), file, from_ascii("ui"),
_("Choose UI file"),
FileFilterList(_("LyX UI files (*.ui)")));
}
docstring const ControlPrefs::browsekbmap(docstring const & file) const
{
return browseLibFile(from_ascii("kbd"), file, from_ascii("kmap"),
_("Choose keyboard map"),
FileFilterList(_("LyX keyboard maps (*.kmap)")));
}
docstring const ControlPrefs::browsedict(docstring const & file) const
{
if (lyxrc.use_spell_lib)
return browseFile(file,
_("Choose personal dictionary"),
FileFilterList(_("*.pws")));
else
return browseFile(file,
_("Choose personal dictionary"),
FileFilterList(_("*.ispell")));
}
docstring const ControlPrefs::browse(docstring const & file,
docstring const & title) const
{
return browseFile(file, title, FileFilterList(), true);
}
docstring const ControlPrefs::browsedir(docstring const & path,
docstring const & title) const
{
return browseDir(path, title);
}
// We support less paper sizes than the document dialog
// Therefore this adjustment is needed.
PAPER_SIZE ControlPrefs::toPaperSize(int i) const
{
switch (i) {
case 0:
return PAPER_DEFAULT;
case 1:
return PAPER_USLETTER;
case 2:
return PAPER_USLEGAL;
case 3:
return PAPER_USEXECUTIVE;
case 4:
return PAPER_A3;
case 5:
return PAPER_A4;
case 6:
return PAPER_A5;
case 7:
return PAPER_B5;
default:
// should not happen
return PAPER_DEFAULT;
}
}
int ControlPrefs::fromPaperSize(PAPER_SIZE papersize) const
{
switch (papersize) {
case PAPER_DEFAULT:
return 0;
case PAPER_USLETTER:
return 1;
case PAPER_USLEGAL:
return 2;
case PAPER_USEXECUTIVE:
return 3;
case PAPER_A3:
return 4;
case PAPER_A4:
return 5;
case PAPER_A5:
return 6;
case PAPER_B5:
return 7;
default:
// should not happen
return 0;
}
}
} // namespace frontend
} // namespace lyx

View File

@ -1,102 +0,0 @@
// -*- C++ -*-
/**
* \file ControlPrefs.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.
*/
#ifndef CONTROLPREFS_H
#define CONTROLPREFS_H
#include "Dialog.h"
#include "Converter.h"
#include "Format.h"
#include "LyXRC.h"
#include "Mover.h"
#include <string>
#include <vector>
namespace lyx {
class Color_color;
namespace frontend {
class ControlPrefs : public Controller {
public:
ControlPrefs(Dialog &);
///
virtual bool initialiseParams(std::string const &);
///
virtual void clearParams() {}
///
virtual void dispatchParams();
///
virtual bool isBufferDependent() const { return false; }
LyXRC & rc() { 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_; }
Movers & movers() { return movers_; }
Movers const & movers() const { return movers_; }
/// various file pickers
docstring const browsebind(docstring const & file) const;
docstring const browseUI(docstring const & file) const;
docstring const browsekbmap(docstring const & file) const;
docstring const browsedict(docstring const & file) const;
/// general browse
docstring const browse(docstring const & file,
docstring const & title) const;
/// browse directory
docstring const browsedir(docstring const & path,
docstring const & title) const;
/// set a color
void setColor(Color_color col, std::string const & hex);
/// update the screen fonts after change
void updateScreenFonts();
/// adjust the prefs paper sizes
PAPER_SIZE toPaperSize(int i) const;
/// adjust the prefs paper sizes
int fromPaperSize(PAPER_SIZE papersize) const;
private:
/// temporary lyxrc
LyXRC rc_;
/// temporary converters
Converters converters_;
/// temporary formats
Formats formats_;
/// temporary movers
Movers movers_;
/// A list of colors to be dispatched
std::vector<std::string> colors_;
bool redraw_gui_;
bool update_screen_font_;
};
} // namespace frontend
} // namespace lyx
#endif // CONTROLPREFS_H

View File

@ -13,7 +13,6 @@ SOURCEFILES = \
ControlCommandBuffer.cpp \ ControlCommandBuffer.cpp \
ControlMath.cpp \ ControlMath.cpp \
ControlParagraph.cpp \ ControlParagraph.cpp \
ControlPrefs.cpp \
frontend_helpers.cpp frontend_helpers.cpp
HEADERFILES = \ HEADERFILES = \
@ -23,7 +22,6 @@ HEADERFILES = \
ControlCommandBuffer.h \ ControlCommandBuffer.h \
ControlMath.h \ ControlMath.h \
ControlParagraph.h \ ControlParagraph.h \
ControlPrefs.h \
frontend_helpers.h frontend_helpers.h
if MONOLITHIC_CONTROLLERS if MONOLITHIC_CONTROLLERS

View File

@ -22,7 +22,6 @@
#include "GuiMathMatrix.h" #include "GuiMathMatrix.h"
#include "GuiNomencl.h" #include "GuiNomencl.h"
#include "GuiParagraph.h" #include "GuiParagraph.h"
#include "GuiPrefs.h"
#include "GuiView.h" #include "GuiView.h"
#include "GuiURL.h" #include "GuiURL.h"
@ -98,7 +97,7 @@ Dialog * createGuiLog(LyXView & lv);
Dialog * createGuiMath(LyXView & lv); Dialog * createGuiMath(LyXView & lv);
Dialog * createGuiNomencl(LyXView & lv); Dialog * createGuiNomencl(LyXView & lv);
Dialog * createGuiNote(LyXView & lv); Dialog * createGuiNote(LyXView & lv);
Dialog * createGuiPrefs(LyXView & lv); Dialog * createGuiPreferences(LyXView & lv);
Dialog * createGuiPrint(LyXView & lv); Dialog * createGuiPrint(LyXView & lv);
Dialog * createGuiRef(LyXView & lv); Dialog * createGuiRef(LyXView & lv);
Dialog * createGuiSearch(LyXView & lv); Dialog * createGuiSearch(LyXView & lv);
@ -190,7 +189,7 @@ Dialog * Dialogs::build(string const & name)
#endif #endif
} }
if (name == "prefs") if (name == "prefs")
return new GuiPrefsDialog(lyxview_); return createGuiPreferences(lyxview_);
if (name == "print") if (name == "print")
return createGuiPrint(lyxview_); return createGuiPrint(lyxview_);
if (name == "ref") if (name == "ref")

View File

@ -11,22 +11,25 @@
#include <config.h> #include <config.h>
#include "GuiPrefs.h" #include "GuiPrefs.h"
#include "ControlPrefs.h"
#include "qt_helpers.h" #include "qt_helpers.h"
#include "GuiApplication.h" #include "GuiApplication.h"
#include "ConverterCache.h" #include "BufferList.h"
#include "Session.h"
#include "debug.h"
#include "Color.h" #include "Color.h"
#include "ConverterCache.h"
#include "debug.h"
#include "Font.h" #include "Font.h"
#include "PanelStack.h" #include "FuncRequest.h"
#include "GuiFontExample.h"
#include "gettext.h" #include "gettext.h"
#include "GuiFontExample.h"
#include "PanelStack.h"
#include "paper.h"
#include "Session.h"
#include "support/lstrings.h" #include "support/lstrings.h"
#include "support/os.h" #include "support/os.h"
#include "support/FileFilterList.h"
#include "frontend_helpers.h" #include "frontend_helpers.h"
@ -50,21 +53,23 @@
using namespace Ui; using namespace Ui;
using lyx::support::compare_ascii_no_case;
using lyx::support::os::external_path;
using lyx::support::os::external_path_list;
using lyx::support::os::internal_path;
using lyx::support::os::internal_path_list;
using std::endl; using std::endl;
using std::string; using std::ostringstream;
using std::pair; using std::pair;
using std::string;
using std::vector; using std::vector;
namespace lyx { namespace lyx {
namespace frontend { namespace frontend {
using support::compare_ascii_no_case;
using support::os::external_path;
using support::os::external_path_list;
using support::os::internal_path;
using support::os::internal_path_list;
using support::FileFilterList;
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
// //
// Helpers // Helpers
@ -234,7 +239,7 @@ void PrefDate::update(LyXRC const & rc)
// //
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
PrefKeyboard::PrefKeyboard(GuiPrefsDialog * form, QWidget * parent) PrefKeyboard::PrefKeyboard(GuiPreferences * form, QWidget * parent)
: PrefModule(_("Keyboard"), form, parent) : PrefModule(_("Keyboard"), form, parent)
{ {
setupUi(this); setupUi(this);
@ -268,7 +273,7 @@ void PrefKeyboard::update(LyXRC const & rc)
QString PrefKeyboard::testKeymap(QString keymap) QString PrefKeyboard::testKeymap(QString keymap)
{ {
return toqstr(form_->controller().browsekbmap(from_utf8(internal_path(fromqstr(keymap))))); return toqstr(form_->browsekbmap(from_utf8(internal_path(fromqstr(keymap)))));
} }
@ -305,7 +310,7 @@ void PrefKeyboard::on_keymapCB_toggled(bool keymap)
// //
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
PrefLatex::PrefLatex(GuiPrefsDialog * form, QWidget * parent) PrefLatex::PrefLatex(GuiPreferences * form, QWidget * parent)
: PrefModule(_("LaTeX"), form, parent) : PrefModule(_("LaTeX"), form, parent)
{ {
setupUi(this); setupUi(this);
@ -343,7 +348,7 @@ void PrefLatex::apply(LyXRC & rc) const
rc.auto_reset_options = latexAutoresetCB->isChecked(); rc.auto_reset_options = latexAutoresetCB->isChecked();
rc.view_dvi_paper_option = fromqstr(latexDviPaperED->text()); rc.view_dvi_paper_option = fromqstr(latexDviPaperED->text());
rc.default_papersize = rc.default_papersize =
form_->controller().toPaperSize(latexPaperSizeCO->currentIndex()); form_->toPaperSize(latexPaperSizeCO->currentIndex());
#if defined(__CYGWIN__) || defined(_WIN32) #if defined(__CYGWIN__) || defined(_WIN32)
rc.windows_style_tex_paths = pathCB->isChecked(); rc.windows_style_tex_paths = pathCB->isChecked();
#endif #endif
@ -359,7 +364,7 @@ void PrefLatex::update(LyXRC const & rc)
latexAutoresetCB->setChecked(rc.auto_reset_options); latexAutoresetCB->setChecked(rc.auto_reset_options);
latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option)); latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option));
latexPaperSizeCO->setCurrentIndex( latexPaperSizeCO->setCurrentIndex(
form_->controller().fromPaperSize(rc.default_papersize)); form_->fromPaperSize(rc.default_papersize));
#if defined(__CYGWIN__) || defined(_WIN32) #if defined(__CYGWIN__) || defined(_WIN32)
pathCB->setChecked(rc.windows_style_tex_paths); pathCB->setChecked(rc.windows_style_tex_paths);
#endif #endif
@ -372,7 +377,7 @@ void PrefLatex::update(LyXRC const & rc)
// //
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
PrefScreenFonts::PrefScreenFonts(GuiPrefsDialog * form, QWidget * parent) PrefScreenFonts::PrefScreenFonts(GuiPreferences * form, QWidget * parent)
: PrefModule(_("Screen fonts"), form, parent) : PrefModule(_("Screen fonts"), form, parent)
{ {
setupUi(this); setupUi(this);
@ -464,7 +469,7 @@ void PrefScreenFonts::apply(LyXRC & rc) const
|| rc.sans_font_name != oldrc.sans_font_name || rc.sans_font_name != oldrc.sans_font_name
|| rc.typewriter_font_name != oldrc.typewriter_font_name || rc.typewriter_font_name != oldrc.typewriter_font_name
|| rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) { || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
form_->controller().updateScreenFonts(); form_->updateScreenFonts();
} }
} }
@ -531,7 +536,7 @@ struct ColorSorter
} // namespace anon } // namespace anon
PrefColors::PrefColors(GuiPrefsDialog * form, QWidget * parent) PrefColors::PrefColors(GuiPreferences * form, QWidget * parent)
: PrefModule( _("Colors"), form, parent) : PrefModule( _("Colors"), form, parent)
{ {
setupUi(this); setupUi(this);
@ -580,7 +585,7 @@ void PrefColors::apply(LyXRC & /*rc*/) const
{ {
for (unsigned int i = 0; i < lcolors_.size(); ++i) for (unsigned int i = 0; i < lcolors_.size(); ++i)
if (curcolors_[i] != newcolors_[i]) if (curcolors_[i] != newcolors_[i])
form_->controller().setColor(lcolors_[i], fromqstr(newcolors_[i])); form_->setColor(lcolors_[i], fromqstr(newcolors_[i]));
} }
@ -700,7 +705,7 @@ void PrefDisplay::update(LyXRC const & rc)
// //
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
PrefPaths::PrefPaths(GuiPrefsDialog * form, QWidget * parent) PrefPaths::PrefPaths(GuiPreferences * form, QWidget * parent)
: PrefModule(_("Paths"), form, parent) : PrefModule(_("Paths"), form, parent)
{ {
setupUi(this); setupUi(this);
@ -750,7 +755,7 @@ void PrefPaths::update(LyXRC const & rc)
void PrefPaths::select_templatedir() void PrefPaths::select_templatedir()
{ {
docstring file(form_->controller().browsedir( docstring file(form_->browsedir(
from_utf8(internal_path(fromqstr(templateDirED->text()))), from_utf8(internal_path(fromqstr(templateDirED->text()))),
_("Select a document templates directory"))); _("Select a document templates directory")));
if (!file.empty()) if (!file.empty())
@ -760,7 +765,7 @@ void PrefPaths::select_templatedir()
void PrefPaths::select_tempdir() void PrefPaths::select_tempdir()
{ {
docstring file(form_->controller().browsedir( docstring file(form_->browsedir(
from_utf8(internal_path(fromqstr(tempDirED->text()))), from_utf8(internal_path(fromqstr(tempDirED->text()))),
_("Select a temporary directory"))); _("Select a temporary directory")));
if (!file.empty()) if (!file.empty())
@ -770,7 +775,7 @@ void PrefPaths::select_tempdir()
void PrefPaths::select_backupdir() void PrefPaths::select_backupdir()
{ {
docstring file(form_->controller().browsedir( docstring file(form_->browsedir(
from_utf8(internal_path(fromqstr(backupDirED->text()))), from_utf8(internal_path(fromqstr(backupDirED->text()))),
_("Select a backups directory"))); _("Select a backups directory")));
if (!file.empty()) if (!file.empty())
@ -780,7 +785,7 @@ void PrefPaths::select_backupdir()
void PrefPaths::select_workingdir() void PrefPaths::select_workingdir()
{ {
docstring file(form_->controller().browsedir( docstring file(form_->browsedir(
from_utf8(internal_path(fromqstr(workingDirED->text()))), from_utf8(internal_path(fromqstr(workingDirED->text()))),
_("Select a document directory"))); _("Select a document directory")));
if (!file.empty()) if (!file.empty())
@ -790,7 +795,7 @@ void PrefPaths::select_workingdir()
void PrefPaths::select_lyxpipe() void PrefPaths::select_lyxpipe()
{ {
docstring file(form_->controller().browse( docstring file(form_->browse(
from_utf8(internal_path(fromqstr(lyxserverDirED->text()))), from_utf8(internal_path(fromqstr(lyxserverDirED->text()))),
_("Give a filename for the LyX server pipe"))); _("Give a filename for the LyX server pipe")));
if (!file.empty()) if (!file.empty())
@ -804,7 +809,7 @@ void PrefPaths::select_lyxpipe()
// //
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
PrefSpellchecker::PrefSpellchecker(GuiPrefsDialog * form, QWidget * parent) PrefSpellchecker::PrefSpellchecker(GuiPreferences * form, QWidget * parent)
: PrefModule(_("Spellchecker"), form, parent) : PrefModule(_("Spellchecker"), form, parent)
{ {
setupUi(this); setupUi(this);
@ -899,7 +904,7 @@ void PrefSpellchecker::update(LyXRC const & rc)
void PrefSpellchecker::select_dict() void PrefSpellchecker::select_dict()
{ {
docstring file(form_->controller().browsedict( docstring file(form_->browsedict(
from_utf8(internal_path(fromqstr(persDictionaryED->text()))))); from_utf8(internal_path(fromqstr(persDictionaryED->text())))));
if (!file.empty()) if (!file.empty())
persDictionaryED->setText(toqstr(file)); persDictionaryED->setText(toqstr(file));
@ -914,7 +919,7 @@ void PrefSpellchecker::select_dict()
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
PrefConverters::PrefConverters(GuiPrefsDialog * form, QWidget * parent) PrefConverters::PrefConverters(GuiPreferences * form, QWidget * parent)
: PrefModule(_("Converters"), form, parent) : PrefModule(_("Converters"), form, parent)
{ {
setupUi(this); setupUi(this);
@ -1183,7 +1188,7 @@ std::string FormatPrettynameValidator::str(Formats::const_iterator it) const
} }
PrefFileformats::PrefFileformats(GuiPrefsDialog * form, QWidget * parent) PrefFileformats::PrefFileformats(GuiPreferences * form, QWidget * parent)
: PrefModule(_("File formats"), form, parent) : PrefModule(_("File formats"), form, parent)
{ {
setupUi(this); setupUi(this);
@ -1560,7 +1565,7 @@ void PrefPrinter::update(LyXRC const & rc)
// //
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
PrefUserInterface::PrefUserInterface(GuiPrefsDialog * form, QWidget * parent) PrefUserInterface::PrefUserInterface(GuiPreferences * form, QWidget * parent)
: PrefModule(_("User interface"), form, parent) : PrefModule(_("User interface"), form, parent)
{ {
setupUi(this); setupUi(this);
@ -1650,7 +1655,7 @@ void PrefUserInterface::select_ui()
{ {
docstring const name = docstring const name =
from_utf8(internal_path(fromqstr(uiFileED->text()))); from_utf8(internal_path(fromqstr(uiFileED->text())));
docstring file = form_->controller().browseUI(name); docstring file = form_->browseUI(name);
if (!file.empty()) if (!file.empty())
uiFileED->setText(toqstr(file)); uiFileED->setText(toqstr(file));
} }
@ -1660,7 +1665,7 @@ void PrefUserInterface::select_bind()
{ {
docstring const name = docstring const name =
from_utf8(internal_path(fromqstr(bindFileED->text()))); from_utf8(internal_path(fromqstr(bindFileED->text())));
docstring file = form_->controller().browsebind(name); docstring file = form_->browsebind(name);
if (!file.empty()) if (!file.empty())
bindFileED->setText(toqstr(file)); bindFileED->setText(toqstr(file));
} }
@ -1704,16 +1709,16 @@ void PrefIdentity::update(LyXRC const & rc)
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
// //
// GuiPrefsDialog // GuiPreferences
// //
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
GuiPrefsDialog::GuiPrefsDialog(LyXView & lv) GuiPreferences::GuiPreferences(LyXView & lv)
: GuiDialog(lv, "prefs") : GuiDialog(lv, "prefs"), Controller(this), update_screen_font_(false)
{ {
setupUi(this); setupUi(this);
setViewTitle(_("Preferences")); setViewTitle(_("Preferences"));
setController(new ControlPrefs(*this)); setController(this, false);
QDialog::setModal(false); QDialog::setModal(false);
@ -1762,13 +1767,7 @@ GuiPrefsDialog::GuiPrefsDialog(LyXView & lv)
} }
ControlPrefs & GuiPrefsDialog::controller() void GuiPreferences::add(PrefModule * module)
{
return static_cast<ControlPrefs &>(GuiDialog::controller());
}
void GuiPrefsDialog::add(PrefModule * module)
{ {
BOOST_ASSERT(module); BOOST_ASSERT(module);
prefsPS->addPanel(module, module->title()); prefsPS->addPanel(module, module->title());
@ -1777,20 +1776,20 @@ void GuiPrefsDialog::add(PrefModule * module)
} }
void GuiPrefsDialog::closeEvent(QCloseEvent * e) void GuiPreferences::closeEvent(QCloseEvent * e)
{ {
slotClose(); slotClose();
e->accept(); e->accept();
} }
void GuiPrefsDialog::change_adaptor() void GuiPreferences::change_adaptor()
{ {
changed(); changed();
} }
void GuiPrefsDialog::apply(LyXRC & rc) const void GuiPreferences::apply(LyXRC & rc) const
{ {
size_t end = modules_.size(); size_t end = modules_.size();
for (size_t i = 0; i != end; ++i) for (size_t i = 0; i != end; ++i)
@ -1798,7 +1797,7 @@ void GuiPrefsDialog::apply(LyXRC & rc) const
} }
void GuiPrefsDialog::updateRc(LyXRC const & rc) void GuiPreferences::updateRc(LyXRC const & rc)
{ {
size_t const end = modules_.size(); size_t const end = modules_.size();
for (size_t i = 0; i != end; ++i) for (size_t i = 0; i != end; ++i)
@ -1806,33 +1805,186 @@ void GuiPrefsDialog::updateRc(LyXRC const & rc)
} }
Converters & GuiPrefsDialog::converters() void GuiPreferences::applyView()
{ {
return controller().converters(); apply(rc());
} }
Formats & GuiPrefsDialog::formats() void GuiPreferences::updateContents()
{ {
return controller().formats(); updateRc(rc());
} }
Movers & GuiPrefsDialog::movers() bool GuiPreferences::initialiseParams(std::string const &)
{ {
return controller().movers(); rc_ = lyxrc;
formats_ = lyx::formats;
converters_ = theConverters();
converters_.update(formats_);
movers_ = theMovers();
colors_.clear();
update_screen_font_ = false;
return true;
} }
void GuiPrefsDialog::applyView() void GuiPreferences::dispatchParams()
{ {
apply(controller().rc()); ostringstream ss;
rc_.write(ss, true);
dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str()));
// FIXME: these need lfuns
// FIXME UNICODE
theBufferList().setCurrentAuthor(from_utf8(rc_.user_name), from_utf8(rc_.user_email));
lyx::formats = formats_;
theConverters() = converters_;
theConverters().update(lyx::formats);
theConverters().buildGraph();
theMovers() = movers_;
vector<string>::const_iterator it = colors_.begin();
vector<string>::const_iterator const end = colors_.end();
for (; it != end; ++it)
dispatch(FuncRequest(LFUN_SET_COLOR, *it));
colors_.clear();
if (update_screen_font_) {
dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
update_screen_font_ = false;
} }
void GuiPrefsDialog::updateContents() // The Save button has been pressed
{ if (dialog().isClosing()) {
updateRc(controller().rc()); dispatch(FuncRequest(LFUN_PREFERENCES_SAVE));
} }
}
void GuiPreferences::setColor(Color_color col, string const & hex)
{
colors_.push_back(lcolor.getLyXName(col) + ' ' + hex);
}
void GuiPreferences::updateScreenFonts()
{
update_screen_font_ = true;
}
docstring const GuiPreferences::browsebind(docstring const & file) const
{
return browseLibFile(from_ascii("bind"), file, from_ascii("bind"),
_("Choose bind file"),
FileFilterList(_("LyX bind files (*.bind)")));
}
docstring const GuiPreferences::browseUI(docstring const & file) const
{
return browseLibFile(from_ascii("ui"), file, from_ascii("ui"),
_("Choose UI file"),
FileFilterList(_("LyX UI files (*.ui)")));
}
docstring const GuiPreferences::browsekbmap(docstring const & file) const
{
return browseLibFile(from_ascii("kbd"), file, from_ascii("kmap"),
_("Choose keyboard map"),
FileFilterList(_("LyX keyboard maps (*.kmap)")));
}
docstring const GuiPreferences::browsedict(docstring const & file) const
{
if (lyxrc.use_spell_lib)
return browseFile(file,
_("Choose personal dictionary"),
FileFilterList(_("*.pws")));
else
return browseFile(file,
_("Choose personal dictionary"),
FileFilterList(_("*.ispell")));
}
docstring const GuiPreferences::browse(docstring const & file,
docstring const & title) const
{
return browseFile(file, title, FileFilterList(), true);
}
docstring const GuiPreferences::browsedir(docstring const & path,
docstring const & title) const
{
return browseDir(path, title);
}
// We support less paper sizes than the document dialog
// Therefore this adjustment is needed.
PAPER_SIZE GuiPreferences::toPaperSize(int i) const
{
switch (i) {
case 0:
return PAPER_DEFAULT;
case 1:
return PAPER_USLETTER;
case 2:
return PAPER_USLEGAL;
case 3:
return PAPER_USEXECUTIVE;
case 4:
return PAPER_A3;
case 5:
return PAPER_A4;
case 6:
return PAPER_A5;
case 7:
return PAPER_B5;
default:
// should not happen
return PAPER_DEFAULT;
}
}
int GuiPreferences::fromPaperSize(PAPER_SIZE papersize) const
{
switch (papersize) {
case PAPER_DEFAULT:
return 0;
case PAPER_USLETTER:
return 1;
case PAPER_USLEGAL:
return 2;
case PAPER_USEXECUTIVE:
return 3;
case PAPER_A3:
return 4;
case PAPER_A4:
return 5;
case PAPER_A5:
return 6;
case PAPER_B5:
return 7;
default:
// should not happen
return 0;
}
}
Dialog * createGuiPreferences(LyXView & lv) { return new GuiPreferences(lv); }
} // namespace frontend } // namespace frontend
} // namespace lyx } // namespace lyx

View File

@ -13,10 +13,12 @@
#define GUIPREFS_H #define GUIPREFS_H
#include "GuiDialog.h" #include "GuiDialog.h"
#include "ControlPrefs.h"
#include "Color.h" #include "Color.h"
#include "LyXRC.h" #include "Converter.h"
#include "Format.h" #include "Format.h"
#include "LyXRC.h"
#include "Mover.h"
#include "ui_PrefsUi.h" #include "ui_PrefsUi.h"
@ -39,24 +41,27 @@
#include <QDialog> #include <QDialog>
#include <QValidator> #include <QValidator>
#include <string>
#include <vector> #include <vector>
namespace lyx { namespace lyx {
class Color_color;
class Converters; class Converters;
class Formats; class Formats;
class Movers; class Movers;
namespace frontend { namespace frontend {
class GuiPrefsDialog; class GuiPreferences;
class PrefModule : public QWidget class PrefModule : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
PrefModule(docstring const & t, PrefModule(docstring const & t,
GuiPrefsDialog * form = 0, QWidget * parent = 0) GuiPreferences * form = 0, QWidget * parent = 0)
: QWidget(parent), title_(t), form_(form) : QWidget(parent), title_(t), form_(form)
{} {}
@ -67,7 +72,7 @@ public:
protected: protected:
docstring title_; docstring title_;
GuiPrefsDialog * form_; GuiPreferences * form_;
Q_SIGNALS: Q_SIGNALS:
void changed(); void changed();
@ -100,7 +105,7 @@ class PrefKeyboard : public PrefModule, public Ui::PrefKeyboardUi
{ {
Q_OBJECT Q_OBJECT
public: public:
PrefKeyboard(GuiPrefsDialog * form, QWidget * parent = 0); PrefKeyboard(GuiPreferences * form, QWidget * parent = 0);
virtual void apply(LyXRC & rc) const; virtual void apply(LyXRC & rc) const;
virtual void update(LyXRC const & rc); virtual void update(LyXRC const & rc);
@ -119,7 +124,7 @@ class PrefLatex : public PrefModule, public Ui::PrefLatexUi
{ {
Q_OBJECT Q_OBJECT
public: public:
PrefLatex(GuiPrefsDialog * form, QWidget * parent = 0); PrefLatex(GuiPreferences * form, QWidget * parent = 0);
virtual void apply(LyXRC & rc) const; virtual void apply(LyXRC & rc) const;
virtual void update(LyXRC const & rc); virtual void update(LyXRC const & rc);
@ -130,7 +135,7 @@ class PrefScreenFonts : public PrefModule, public Ui::PrefScreenFontsUi
{ {
Q_OBJECT Q_OBJECT
public: public:
PrefScreenFonts(GuiPrefsDialog * form, QWidget * parent = 0); PrefScreenFonts(GuiPreferences * form, QWidget * parent = 0);
virtual void apply(LyXRC & rc) const; virtual void apply(LyXRC & rc) const;
virtual void update(LyXRC const & rc); virtual void update(LyXRC const & rc);
@ -146,7 +151,7 @@ class PrefColors : public PrefModule, public Ui::PrefColorsUi
{ {
Q_OBJECT Q_OBJECT
public: public:
PrefColors(GuiPrefsDialog * form, QWidget * parent = 0); PrefColors(GuiPreferences * form, QWidget * parent = 0);
void apply(LyXRC & rc) const; void apply(LyXRC & rc) const;
void update(LyXRC const & rc); void update(LyXRC const & rc);
@ -181,7 +186,7 @@ class PrefPaths : public PrefModule, public Ui::PrefPathsUi
{ {
Q_OBJECT Q_OBJECT
public: public:
PrefPaths(GuiPrefsDialog * form, QWidget * parent = 0); PrefPaths(GuiPreferences * form, QWidget * parent = 0);
void apply(LyXRC & rc) const; void apply(LyXRC & rc) const;
void update(LyXRC const & rc); void update(LyXRC const & rc);
@ -200,7 +205,7 @@ class PrefSpellchecker : public PrefModule, public Ui::PrefSpellcheckerUi
{ {
Q_OBJECT Q_OBJECT
public: public:
PrefSpellchecker(GuiPrefsDialog * form, QWidget * parent = 0); PrefSpellchecker(GuiPreferences * form, QWidget * parent = 0);
void apply(LyXRC & rc) const; void apply(LyXRC & rc) const;
void update(LyXRC const & rc); void update(LyXRC const & rc);
@ -214,7 +219,7 @@ class PrefConverters : public PrefModule, public Ui::PrefConvertersUi
{ {
Q_OBJECT Q_OBJECT
public: public:
PrefConverters(GuiPrefsDialog * form, QWidget * parent = 0); PrefConverters(GuiPreferences * form, QWidget * parent = 0);
void apply(LyXRC & rc) const; void apply(LyXRC & rc) const;
void update(LyXRC const & rc); void update(LyXRC const & rc);
@ -268,7 +273,7 @@ class PrefFileformats : public PrefModule, public Ui::PrefFileformatsUi
{ {
Q_OBJECT Q_OBJECT
public: public:
PrefFileformats(GuiPrefsDialog * form, QWidget * parent = 0); PrefFileformats(GuiPreferences * form, QWidget * parent = 0);
void apply(LyXRC & rc) const; void apply(LyXRC & rc) const;
void update(LyXRC const & rc); void update(LyXRC const & rc);
@ -326,7 +331,7 @@ class PrefUserInterface : public PrefModule, public Ui::PrefUi
{ {
Q_OBJECT Q_OBJECT
public: public:
PrefUserInterface(GuiPrefsDialog * form, QWidget * parent = 0); PrefUserInterface(GuiPreferences * form, QWidget * parent = 0);
void apply(LyXRC & rc) const; void apply(LyXRC & rc) const;
void update(LyXRC const & rc); void update(LyXRC const & rc);
@ -349,12 +354,12 @@ public:
void update(LyXRC const & rc); void update(LyXRC const & rc);
}; };
///
class GuiPrefsDialog : public GuiDialog, public Ui::PrefsUi class GuiPreferences : public GuiDialog, public Ui::PrefsUi, public Controller
{ {
Q_OBJECT Q_OBJECT
public: public:
GuiPrefsDialog(LyXView & lv); GuiPreferences(LyXView & lv);
void apply(LyXRC & rc) const; void apply(LyXRC & rc) const;
void updateRc(LyXRC const & rc); void updateRc(LyXRC const & rc);
@ -367,20 +372,69 @@ public:
void closeEvent(QCloseEvent * e); void closeEvent(QCloseEvent * e);
/// ///
void add(PrefModule * module); void add(PrefModule * module);
///
Converters & converters();
///
Formats & formats();
///
Movers & movers();
/// parent controller /// parent controller
ControlPrefs & controller(); Controller & controller() { return *this; }
/// Apply changes /// Apply changes
void applyView(); void applyView();
/// update (do we need this?) /// update (do we need this?)
void updateContents(); void updateContents();
std::vector<PrefModule *> modules_; std::vector<PrefModule *> modules_;
///
bool initialiseParams(std::string const &);
///
void clearParams() {}
///
void dispatchParams();
///
bool isBufferDependent() const { return false; }
/// various file pickers
docstring const browsebind(docstring const & file) const;
docstring const browseUI(docstring const & file) const;
docstring const browsekbmap(docstring const & file) const;
docstring const browsedict(docstring const & file) const;
/// general browse
docstring const browse(docstring const & file,
docstring const & title) const;
/// browse directory
docstring const browsedir(docstring const & path,
docstring const & title) const;
/// set a color
void setColor(Color_color col, std::string const & hex);
/// update the screen fonts after change
void updateScreenFonts();
/// adjust the prefs paper sizes
PAPER_SIZE toPaperSize(int i) const;
/// adjust the prefs paper sizes
int fromPaperSize(PAPER_SIZE papersize) const;
LyXRC & rc() { return rc_; }
Converters & converters() { return converters_; }
Formats & formats() { return formats_; }
Movers & movers() { return movers_; }
private:
/// temporary lyxrc
LyXRC rc_;
/// temporary converters
Converters converters_;
/// temporary formats
Formats formats_;
/// temporary movers
Movers movers_;
/// A list of colors to be dispatched
std::vector<std::string> colors_;
bool redraw_gui_;
bool update_screen_font_;
}; };