]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/controllers/ControlPrefs.C
The Movers patch.
[lyx.git] / src / frontends / controllers / ControlPrefs.C
index b36d2ee2fc84187d5463c4b924be21d0bd7aecf1..67f0dc910e83ea29180a64e3b655afbb6feca98d 100644 (file)
  *
  * \author John Levon
  *
- * Full author contact details are available in file CREDITS
+ * Full author contact details are available in file CREDITS.
  */
 
 #include <config.h>
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
-#include <utility>
 #include "ControlPrefs.h"
-#include "ViewBase.h"
 
-#include "frontends/LyXView.h"
 #include "helper_funcs.h"
+#include "Kernel.h"
+
+#include "bufferlist.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;
+#include "funcrequest.h"
+#include "LColor.h"
+
+#include "support/globbing.h"
+
+#include <sstream>
+
+using std::ostringstream;
 using std::pair;
-ControlPrefs::ControlPrefs(LyXView & lv, Dialogs & d)
-       : ControlDialogBI(lv, d)
+using std::string;
+using std::vector;
+
+
+extern BufferList bufferlist;
+
+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);
 
-void ControlPrefs::OKButton()
-{
-       ControlDialogBI::OKButton();
-       lv_.dispatch(FuncRequest(LFUN_SAVEPREFERENCES));
+       ::formats = formats_;
+
+       ::converters = converters_;
+       ::converters.update(::formats);
+       ::converters.buildGraph();
+
+       ::movers = movers_;
+
+       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;
+       }
+
+       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_SAVEPREFERENCES));
+       }
 }
 
-string const ControlPrefs::browsebind(string const & file)
+
+void ControlPrefs::redrawGUI()
 {
-       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);
+       redraw_gui_ = true;
 }
 
 
-string const ControlPrefs::browseUI(string const & file)
+void ControlPrefs::setColor(LColor_color col, string const & hex)
 {
-       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);
+       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(&lv_, file, _("Choose keyboard map"), "*.kmap", dir1);
+       update_screen_font_ = true;
 }
 
-string const ControlPrefs::browsedict(string const & file)
+
+string const ControlPrefs::browsebind(string const & file) const
 {
-       return browseFile(&lv_, 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(&lv_, file, title, "*");
+       return browseLibFile("ui", file, "ui", _("Choose UI file"),
+                         FileFilterList("LyX UI files (*.ui)"));
 }
 
 
-void ControlPrefs::redrawGUI()
+string const ControlPrefs::browsekbmap(string const & file) const
 {
-       // we must be sure to get the new values first
-       lyxrc = rc_;
-       lv_.getDialogs().redrawGUI();
+       return browseLibFile("kbd", file, "kmap", _("Choose keyboard map"),
+                         FileFilterList("LyX keyboard maps (*.kmap)"));
 }
 
-void ControlPrefs::setColor(LColor::color col, string const & hex)
+
+string const ControlPrefs::browsedict(string const & file) const
 {
-       string const s = lcolor.getLyXName(col) + string(" ") + hex;
-       lv_.dispatch(FuncRequest(LFUN_SET_COLOR, s));
+       return browseFile(file, _("Choose personal dictionary"),
+                         FileFilterList("*.ispell"));
 }
 
 
-void ControlPrefs::updateScreenFonts()
+string const ControlPrefs::browse(string const & file,
+                                 string const & title) const
 {
-       // 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();
+       return browseFile(file, title, FileFilterList(), true);
 }
 
 
-void ControlPrefs::setFormats(Formats const & form)
+string const ControlPrefs::browsedir(string const & path,
+                                    string const & title) const
 {
-       formats = form;
+       return browseDir(path, title);
 }
+
+} // namespace frontend
+} // namespace lyx