]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/controllers/ControlPrefs.C
rename LFUN enum values according to their command (as used in th minibuffer/bind...
[lyx.git] / src / frontends / controllers / ControlPrefs.C
index a784dcb93030142bf2741beebd6f2afb2c02d0f7..30efddbe089bdd971ee2f6e030410b14cd523018 100644 (file)
 #include "ControlPrefs.h"
 
 #include "helper_funcs.h"
-#include "ViewBase.h"
+#include "Kernel.h"
 
 #include "bufferlist.h"
-#include "converter.h"
-#include "format.h"
 #include "gettext.h"
+#include "funcrequest.h"
+#include "paper.h"
+#include "LColor.h"
 
-#include "frontends/Dialogs.h"
-#include "frontends/LyXView.h"
+#include "support/filefilterlist.h"
 
-#include "support/filetools.h"
-#include "support/path_defines.h"
+#include <sstream>
 
-#include <utility>
-
-using namespace lyx::support;
-
-using std::endl;
+using std::ostringstream;
 using std::pair;
+using std::string;
+using std::vector;
 
 
 extern BufferList bufferlist;
 
-ControlPrefs::ControlPrefs(LyXView & lv, Dialogs & d)
-       : ControlDialogBI(lv, d)
+namespace lyx {
+
+using support::FileFilterList;
+
+namespace frontend {
+
+
+ControlPrefs::ControlPrefs(Dialog & parent)
+       : Dialog::Controller(parent),
+         redraw_gui_(false),
+         update_screen_font_(false)
 {}
 
 
-void ControlPrefs::setParams()
+bool ControlPrefs::initialiseParams(std::string const &)
 {
        rc_ = lyxrc;
+       formats_ = ::formats;
+       converters_ = ::converters;
+       converters_.update(formats_);
+       movers_ = ::movers;
+       colors_.clear();
+       redraw_gui_ = false;
+       update_screen_font_ = false;
+
+       return true;
 }
 
 
-void ControlPrefs::apply()
+void ControlPrefs::dispatchParams()
 {
-       view().apply();
-       lyxrc = rc_;
+       ostringstream ss;
+       rc_.write(ss, true);
+       kernel().dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str()));
 
+       // FIXME: these need lfuns
        bufferlist.setCurrentAuthor(rc_.user_name, rc_.user_email);
 
-       // The Save button has been pressed
-       if (isClosing()) {
-               lv_.dispatch(FuncRequest(LFUN_SAVEPREFERENCES));
-       }
-}
+       ::formats = formats_;
 
+       ::converters = converters_;
+       ::converters.update(::formats);
+       ::converters.buildGraph();
 
-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);
+       ::movers = movers_;
 
-       dir = AddName(user_lyxdir(), "bind");
-       // FIXME: stupid name
-       name = _("User Bind|#U#u");
-       pair<string,string> dir2(name, dir);
+       vector<string>::const_iterator it = colors_.begin();
+       vector<string>::const_iterator const end = colors_.end();
+       for (; it != end; ++it)
+               kernel().dispatch(FuncRequest(LFUN_SET_COLOR, *it));
+       colors_.clear();
+
+       if (redraw_gui_) {
+               kernel().redrawGUI();
+               redraw_gui_ = false;
+       }
 
-       return browseFile(file, _("Choose bind file"), "*.bind", false, dir1, dir2);
+       if (update_screen_font_) {
+               kernel().dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
+               update_screen_font_ = false;
+       }
+
+       // The Save button has been pressed
+       if (dialog().isClosing()) {
+               kernel().dispatch(FuncRequest(LFUN_PREFERENCES_SAVE));
+       }
 }
 
 
-string const ControlPrefs::browseUI(string const & file)
+void ControlPrefs::redrawGUI()
 {
-       string dir  = AddName(system_lyxdir(), "ui");
-       // FIXME: stupid name
-       string name = _("Sys UI|#S#s");
-       pair<string,string> dir1(name, dir);
+       redraw_gui_ = true;
+}
 
-       dir = AddName(user_lyxdir(), "ui");
-       // FIXME: stupid name
-       name = _("User UI|#U#u");
-       pair<string,string> dir2(name, dir);
 
-       return browseFile(file, _("Choose UI file"), "*.ui", false, dir1, dir2);
+void ControlPrefs::setColor(LColor_color col, string const & hex)
+{
+       colors_.push_back(lcolor.getLyXName(col) + ' ' + hex);
 }
 
 
-string const ControlPrefs::browsekbmap(string const & file)
+void ControlPrefs::updateScreenFonts()
 {
-       string const dir = AddName(system_lyxdir(), "kbd");
-       string const name = _("Key maps|#K#k");
-       pair<string, string> dir1(name, dir);
-
-       return browseFile(file, _("Choose keyboard map"), "*.kmap", false, dir1);
+       update_screen_font_ = true;
 }
 
 
-string const ControlPrefs::browsedict(string const & file)
+string const ControlPrefs::browsebind(string const & file) const
 {
-       return browseFile(file, _("Choose personal dictionary"), "*.ispell");
+       return browseLibFile("bind", file, "bind", _("Choose bind file"),
+                         FileFilterList(_("LyX bind files (*.bind)")));
 }
 
 
-string const ControlPrefs::browse(string const & file, string const & title)
+string const ControlPrefs::browseUI(string const & file) const
 {
-       return browseFile(file, title, "*", true);
+       return browseLibFile("ui", file, "ui", _("Choose UI file"),
+                         FileFilterList(_("LyX UI files (*.ui)")));
 }
 
 
-string const ControlPrefs::browsedir(string const & path, string const & title)
+string const ControlPrefs::browsekbmap(string const & file) const
 {
-       return browseDir(path, title);
+       return browseLibFile("kbd", file, "kmap", _("Choose keyboard map"),
+                         FileFilterList(_("LyX keyboard maps (*.kmap)")));
 }
 
 
-void ControlPrefs::redrawGUI()
+string const ControlPrefs::browsedict(string const & file) const
 {
-       // we must be sure to get the new values first
-       lyxrc = rc_;
-
-       lv_.getDialogs().redrawGUI();
+       return browseFile(file, _("Choose personal dictionary"),
+                         FileFilterList(_("*.ispell")));
 }
 
 
-void ControlPrefs::setColor(LColor::color col, string const & hex)
+string const ControlPrefs::browse(string const & file,
+                                 string const & title) const
 {
-       string const s = lcolor.getLyXName(col) + ' ' + hex;
-       lv_.dispatch(FuncRequest(LFUN_SET_COLOR, s));
+       return browseFile(file, title, FileFilterList(), true);
 }
 
 
-void ControlPrefs::updateScreenFonts()
+string const ControlPrefs::browsedir(string const & path,
+                                    string const & title) const
 {
-       // we must be sure to get the new values first
-       lyxrc = rc_;
-
-       lv_.dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
+       return browseDir(path, title);
 }
 
 
-void ControlPrefs::setConverters(Converters const & conv)
+// We support less paper sizes than the document dialog
+// Therefore this adjustment is needed.
+PAPER_SIZE const ControlPrefs::toPaperSize(int i) const
 {
-       converters = conv;
-       converters.update(formats);
-       converters.buildGraph();
+       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;
+       }
 }
 
 
-void ControlPrefs::setFormats(Formats const & form)
+int const ControlPrefs::fromPaperSize(PAPER_SIZE papersize) const
 {
-       formats = form;
+       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