From: Angus Leeming Date: Sun, 27 Jul 2003 22:13:29 +0000 (+0000) Subject: Flying high and free... X-Git-Tag: 1.6.10~16432 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=cd16abc0fd6a071bcb97869a408b84904d7b95cf;p=features.git Flying high and free... The user_lyxdir is also now a function. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7399 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/frontends/controllers/ControlAboutlyx.C b/src/frontends/controllers/ControlAboutlyx.C index 8506fcbcdd..8f1c943826 100644 --- a/src/frontends/controllers/ControlAboutlyx.C +++ b/src/frontends/controllers/ControlAboutlyx.C @@ -27,9 +27,6 @@ using namespace lyx::support; using std::ostream; -// needed for the browser -extern string user_lyxdir; - ControlAboutlyx::ControlAboutlyx(Dialog & parent) : Dialog::Controller(parent) @@ -88,7 +85,7 @@ string const ControlAboutlyx::getVersion() const << MakeDisplayPath(system_lyxdir()) << "\n" << _("User directory: ") - << MakeDisplayPath(user_lyxdir); + << MakeDisplayPath(user_lyxdir()); return STRCONV(ss.str()); } diff --git a/src/frontends/controllers/ControlDocument.C b/src/frontends/controllers/ControlDocument.C index 43d81897e7..8e5ae244e1 100644 --- a/src/frontends/controllers/ControlDocument.C +++ b/src/frontends/controllers/ControlDocument.C @@ -33,6 +33,7 @@ #include "support/LAssert.h" #include "support/lstrings.h" #include "support/filetools.h" +#include "support/path_defines.h" using namespace lyx::support; @@ -161,7 +162,7 @@ void ControlDocument::saveAsDefault() lv_.buffer()->params.preamble = bp_->preamble; - string const fname = AddName(AddPath(user_lyxdir, "templates/"), + string const fname = AddName(AddPath(user_lyxdir(), "templates/"), "defaults.lyx"); Buffer defaults(fname); defaults.params = params(); diff --git a/src/frontends/controllers/ControlGraphics.C b/src/frontends/controllers/ControlGraphics.C index 8d3e8e5213..ef667050d3 100644 --- a/src/frontends/controllers/ControlGraphics.C +++ b/src/frontends/controllers/ControlGraphics.C @@ -38,9 +38,6 @@ using std::pair; using std::make_pair; using std::vector; -// We need these in the file browser. -extern string user_lyxdir; - ControlGraphics::ControlGraphics(Dialog & parent) : Dialog::Controller(parent) @@ -76,7 +73,7 @@ string const ControlGraphics::Browse(string const & in_name) string const title = _("Select graphics file"); // Does user clipart directory exist? - string clipdir = AddName (user_lyxdir, "clipart"); + string clipdir = AddName (user_lyxdir(), "clipart"); FileInfo fileInfo(clipdir); if (!(fileInfo.isOK() && fileInfo.isDir())) // No - bail out to system clipart directory diff --git a/src/frontends/controllers/ControlPrefs.C b/src/frontends/controllers/ControlPrefs.C index 32c0626cb4..b7ecec1592 100644 --- a/src/frontends/controllers/ControlPrefs.C +++ b/src/frontends/controllers/ControlPrefs.C @@ -27,7 +27,6 @@ #include "format.h" #include "debug.h" -extern string user_lyxdir; extern BufferList bufferlist; using namespace lyx::support; @@ -67,7 +66,7 @@ string const ControlPrefs::browsebind(string const & file) string name = _("System Bind|#S#s"); pair dir1(name, dir); - dir = AddName(user_lyxdir, "bind"); + dir = AddName(user_lyxdir(), "bind"); // FIXME: stupid name name = _("User Bind|#U#u"); pair dir2(name, dir); @@ -83,7 +82,7 @@ string const ControlPrefs::browseUI(string const & file) string name = _("Sys UI|#S#s"); pair dir1(name, dir); - dir = AddName(user_lyxdir, "ui"); + dir = AddName(user_lyxdir(), "ui"); // FIXME: stupid name name = _("User UI|#U#u"); pair dir2(name, dir); diff --git a/src/frontends/controllers/tex_helpers.C b/src/frontends/controllers/tex_helpers.C index ad72098e15..500f20bd0c 100644 --- a/src/frontends/controllers/tex_helpers.C +++ b/src/frontends/controllers/tex_helpers.C @@ -20,6 +20,7 @@ #include "support/systemcall.h" #include "support/path.h" #include "support/lyxalgo.h" +#include "support/path_defines.h" #include #include @@ -33,15 +34,13 @@ using std::endl; using std::sort; using std::unique; -extern string user_lyxdir; // home of *Files.lst - // build filelists of all availabe bst/cls/sty-files. done through // kpsewhich and an external script, saved in *Files.lst void rescanTexStyles() { // Run rescan in user lyx directory - Path p(user_lyxdir); + Path p(user_lyxdir()); Systemcall one; one.startscript(Systemcall::Wait, LibFileSearch("scripts", "TeXFiles.sh")); @@ -51,7 +50,7 @@ void rescanTexStyles() void texhash() { // Run texhash in user lyx directory - Path p(user_lyxdir); + Path p(user_lyxdir()); //path to texhash through system Systemcall one; diff --git a/src/frontends/gnome/lyx_gui.C b/src/frontends/gnome/lyx_gui.C index ca1b6f82bc..4a1d3963d0 100644 --- a/src/frontends/gnome/lyx_gui.C +++ b/src/frontends/gnome/lyx_gui.C @@ -16,6 +16,7 @@ #include "support/lyxlib.h" #include "support/os.h" #include "support/filetools.h" +#include "support/path_defines.h" #include "debug.h" #include "gettext.h" @@ -182,7 +183,7 @@ void lyx_gui::parse_init(int & argc, char * argv[]) void lyx_gui::parse_lyxrc() { - XformsColor::read(AddName(user_lyxdir, "preferences.xform")); + XformsColor::read(AddName(user_lyxdir(), "preferences.xform")); if (lyxrc.popup_font_encoding.empty()) lyxrc.popup_font_encoding = lyxrc.font_norm; diff --git a/src/frontends/xforms/FormPreferences.C b/src/frontends/xforms/FormPreferences.C index 852ce0e4de..1859eadc7d 100644 --- a/src/frontends/xforms/FormPreferences.C +++ b/src/frontends/xforms/FormPreferences.C @@ -40,6 +40,7 @@ #include "support/lyxfunctional.h" #include "support/lyxmanip.h" #include "support/tostr.h" +#include "support/path_defines.h" #include "support/filetools.h" #include "support/LAssert.h" @@ -64,8 +65,6 @@ using std::vector; using std::setw; using std::setfill; -extern string user_lyxdir; - using namespace lyx::support; namespace { @@ -330,7 +329,7 @@ void FormPreferences::apply() // The "Save" button has been pressed. if (controller().isClosing() && colors_.modifiedXformsPrefs) { string const filename = - AddName(user_lyxdir, "preferences.xform"); + AddName(user_lyxdir(), "preferences.xform"); colors_.modifiedXformsPrefs = !XformsColor::write(filename); } } diff --git a/src/frontends/xforms/lyx_gui.C b/src/frontends/xforms/lyx_gui.C index 74733e0f60..c97b591b3d 100644 --- a/src/frontends/xforms/lyx_gui.C +++ b/src/frontends/xforms/lyx_gui.C @@ -16,6 +16,7 @@ #include "support/lyxlib.h" #include "support/os.h" #include "support/filetools.h" +#include "support/path_defines.h" #include "debug.h" #include "gettext.h" @@ -187,7 +188,7 @@ void parse_init(int & argc, char * argv[]) void parse_lyxrc() { - XformsColor::read(AddName(user_lyxdir, "preferences.xform")); + XformsColor::read(AddName(user_lyxdir(), "preferences.xform")); if (lyxrc.popup_font_encoding.empty()) lyxrc.popup_font_encoding = lyxrc.font_norm; diff --git a/src/insets/ExternalTemplate.C b/src/insets/ExternalTemplate.C index 45e2362ac7..8c7a3c65ae 100644 --- a/src/insets/ExternalTemplate.C +++ b/src/insets/ExternalTemplate.C @@ -20,6 +20,7 @@ #include "support/path.h" #include "support/LAssert.h" #include "support/filetools.h" +#include "support/path_defines.h" using namespace lyx::support; @@ -27,9 +28,6 @@ using std::endl; using std::ostream; using std::for_each; -extern string user_lyxdir; - - // We have to have dummy default commands for security reasons! ExternalTemplate::ExternalTemplate() @@ -44,7 +42,7 @@ ExternalTemplate::FormatTemplate::FormatTemplate() ExternalTemplateManager::ExternalTemplateManager() { // gimp gnuchess gnuplot ical netscape tetris xpaint - readTemplates(user_lyxdir); + readTemplates(user_lyxdir()); if (lyxerr.debugging()) dumpTemplates(); } diff --git a/src/lyx_cb.C b/src/lyx_cb.C index 933b050f64..1b49bafece 100644 --- a/src/lyx_cb.C +++ b/src/lyx_cb.C @@ -454,7 +454,7 @@ void Reconfigure(BufferView * bv) bv->owner()->message(_("Running configure...")); // Run configure in user lyx directory - Path p(user_lyxdir); + Path p(user_lyxdir()); Systemcall one; one.startscript(Systemcall::Wait, AddName(system_lyxdir(), "configure")); diff --git a/src/lyx_main.C b/src/lyx_main.C index 0a5ee65cee..f12367b635 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -64,8 +64,6 @@ extern void QuitLyX(); extern LyXServer * lyxserver; -extern string user_lyxdir; - DebugStream lyxerr; boost::scoped_ptr lastfiles; @@ -253,7 +251,7 @@ void LyX::init(bool gui) } if (lyxrc.lastfiles.empty()) { - lyxrc.lastfiles = AddName(user_lyxdir, "lastfiles"); + lyxrc.lastfiles = AddName(user_lyxdir(), "lastfiles"); } if (lyxrc.roman_font_name.empty()) @@ -415,16 +413,16 @@ void LyX::queryUserLyXDir(bool explicit_userdir) string const configure_script = AddName(system_lyxdir(), "configure"); // Does user directory exist? - FileInfo fileInfo(user_lyxdir); + FileInfo fileInfo(user_lyxdir()); if (fileInfo.isOK() && fileInfo.isDir()) { first_start = false; FileInfo script(configure_script); - FileInfo defaults(AddName(user_lyxdir, "lyxrc.defaults")); + FileInfo defaults(AddName(user_lyxdir(), "lyxrc.defaults")); if (defaults.isOK() && script.isOK() && defaults.getModificationTime() < script.getModificationTime()) { lyxerr << _("LyX: reconfiguring user directory") << endl; - Path p(user_lyxdir); + Path p(user_lyxdir()); ::system(configure_script.c_str()); lyxerr << "LyX: " << _("Done!") << endl; } @@ -434,18 +432,18 @@ void LyX::queryUserLyXDir(bool explicit_userdir) first_start = !explicit_userdir; lyxerr << bformat(_("LyX: Creating directory %1$s" - " and running configure..."), user_lyxdir) << endl; + " and running configure..."), user_lyxdir()) << endl; - if (!createDirectory(user_lyxdir, 0755)) { + if (!createDirectory(user_lyxdir(), 0755)) { // Failed, let's use $HOME instead. - user_lyxdir = GetEnvPath("HOME"); + user_lyxdir(GetEnvPath("HOME")); lyxerr << bformat(_("Failed. Will use %1$s instead."), - user_lyxdir) << endl; + user_lyxdir()) << endl; return; } // Run configure in user lyx directory - Path p(user_lyxdir); + Path p(user_lyxdir()); ::system(configure_script.c_str()); lyxerr << "LyX: " << _("Done!") << endl; } @@ -656,7 +654,7 @@ int parse_userdir(string const & arg, string const &) lyxerr << _("Missing directory for -userdir switch") << endl; exit(1); } - user_lyxdir = arg; + user_lyxdir(arg); return 1; } diff --git a/src/lyx_main.h b/src/lyx_main.h index 2451f400d0..21e7b7d6f6 100644 --- a/src/lyx_main.h +++ b/src/lyx_main.h @@ -25,8 +25,6 @@ class Buffer; class kb_keymap; -/// e.g. $HOME/.lyx/ -extern string user_lyxdir; /// last files loaded extern boost::scoped_ptr lastfiles; diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 3f4edb35af..7510fec113 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -1538,7 +1538,7 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose) case LFUN_SAVEPREFERENCES: { - Path p(user_lyxdir); + Path p(user_lyxdir()); lyxrc.write("preferences"); } break; diff --git a/src/support/ChangeLog b/src/support/ChangeLog index 4fc0ff4172..f2e7616735 100644 --- a/src/support/ChangeLog +++ b/src/support/ChangeLog @@ -1,7 +1,7 @@ 2003-07-27 Angus Leeming - * path_defines.{h,C.in} (build_lyxdir, system_lyxdir): are now - functions, not global vars. + * path_defines.{h,C.in} (build_lyxdir, system_lyxdir, + user_lyxdir): are now functions, not global vars. * Makefile.am: set build_lyxdir at make time. diff --git a/src/support/filetools.C b/src/support/filetools.C index 501ef61f7a..b7f4eea293 100644 --- a/src/support/filetools.C +++ b/src/support/filetools.C @@ -80,7 +80,6 @@ using std::ifstream; using std::vector; using std::getline; -extern string user_lyxdir; namespace lyx { namespace support { @@ -187,7 +186,7 @@ string const FileOpenSearch(string const & path, string const & name, if (!suffixIs(path_element, '/')) path_element+= '/'; path_element = subst(path_element, "$$LyX", system_lyxdir()); - path_element = subst(path_element, "$$User", user_lyxdir); + path_element = subst(path_element, "$$User", user_lyxdir()); real_file = FileSearch(path_element, name, ext); @@ -292,7 +291,7 @@ string const FileSearch(string const & path, string const & name, string const LibFileSearch(string const & dir, string const & name, string const & ext) { - string fullname = FileSearch(AddPath(user_lyxdir, dir), name, ext); + string fullname = FileSearch(AddPath(user_lyxdir(), dir), name, ext); if (!fullname.empty()) return fullname; @@ -465,7 +464,7 @@ string const CreateTmpDir(string const & tempdir, string const & mask) int destroyDir(string const & tmpdir) { #ifdef __EMX__ - Path p(user_lyxdir); + Path p(user_lyxdir()); #endif if (DeleteAllFilesInDir(tmpdir)) return -1; @@ -497,14 +496,14 @@ string const CreateLyXTmpDir(string const & deflt) if ((!deflt.empty()) && (deflt != "/tmp")) { if (mkdir(deflt, 0777)) { #ifdef __EMX__ - Path p(user_lyxdir); + Path p(user_lyxdir()); #endif return CreateTmpDir(deflt, "lyx_tmpdir"); } else return deflt; } else { #ifdef __EMX__ - Path p(user_lyxdir); + Path p(user_lyxdir()); #endif return CreateTmpDir("/tmp", "lyx_tmpdir"); } diff --git a/src/support/path_defines.C.in b/src/support/path_defines.C.in index 478757a71a..ec5689b696 100644 --- a/src/support/path_defines.C.in +++ b/src/support/path_defines.C.in @@ -27,14 +27,15 @@ using std::endl; -string user_lyxdir; - - namespace { // Store for the path to the lyx support files we're actually going to use. string system_lyxdir_; +// Store for the path to the user-level support files. +string user_lyxdir_; + + /* The absolute path to the system-level lyx support files. * (Make-time value.) */ @@ -89,6 +90,18 @@ void system_lyxdir(string const & sld) } +string const & user_lyxdir() +{ + return user_lyxdir_; +} + + +void user_lyxdir(string const & uld) +{ + user_lyxdir_ = uld; +} + + bool setLyxPaths() { // @@ -241,22 +254,22 @@ bool setLyxPaths() // 2) LYX_USERDIR_14x environment variable // 3) $HOME/. - // If we had a command line switch, user_lyxdir is already set + // If we had a command line switch, user_lyxdir_ is already set bool explicit_userdir = true; - if (user_lyxdir.empty()) { + if (user_lyxdir_.empty()) { // LYX_USERDIR_14x environment variable - user_lyxdir = GetEnvPath("LYX_USERDIR_14x"); + user_lyxdir_ = GetEnvPath("LYX_USERDIR_14x"); // default behaviour - if (user_lyxdir.empty()) - user_lyxdir = AddPath(GetEnvPath("HOME"), - string(".") + PACKAGE); + if (user_lyxdir_.empty()) + user_lyxdir_ = AddPath(GetEnvPath("HOME"), + string(".") + PACKAGE); explicit_userdir = false; } lyxerr[Debug::INIT] << "User LyX directory: '" - << user_lyxdir << '\'' << endl; + << user_lyxdir_ << '\'' << endl; return explicit_userdir; } diff --git a/src/support/path_defines.h b/src/support/path_defines.h index 61d43a3f27..cfb5728bb1 100644 --- a/src/support/path_defines.h +++ b/src/support/path_defines.h @@ -28,6 +28,12 @@ string const & system_lyxdir(); /// Set the absolute path to the lyx support files (from the command line). void system_lyxdir(string const &); +/// The absolute path to the user-level lyx support files. +string const & user_lyxdir(); + +/// Set the absolute path to the user-level lyx support files. +void user_lyxdir(string const &); + /** \returns true if the user lyx dir existed already and did not need * to be created afresh. */