]> git.lyx.org Git - lyx.git/blobdiff - src/support/Package.cpp
Fix layout bug. Pasting text into a cell tried to set Standard layout, because
[lyx.git] / src / support / Package.cpp
index 9ffc8dc3f8ed24279bfc0d445ad556080f8599dd..7cd1fe099e96627be5e713a6ebb819fedf516197 100644 (file)
@@ -73,7 +73,7 @@ Package const & package()
        // Commented out because package().locale_dir() can be called
        // from the message translation code in Messages.cpp before
        // init_package() is called. Lars is on the case...
-       // BOOST_ASSERT(initialised_);
+       // LASSERT(initialised_, /**/);
        return package_;
 }
 
@@ -95,8 +95,6 @@ FileName const get_locale_dir(FileName const & system_support_dir);
 FileName const get_system_support_dir(FileName const & abs_binary,
                                    string const & command_line_system_support_dir);
 
-FileName const get_temp_dir();
-
 FileName const get_default_user_support_dir(FileName const & home_dir);
 
 bool userSupportDir(FileName const & default_user_support_dir,
@@ -115,7 +113,9 @@ Package::Package(string const & command_line_arg0,
        : explicit_user_support_dir_(false)
 {
        home_dir_ = get_home_dir();
-       system_temp_dir_ = get_temp_dir();
+       // Specification of temp_dir_ may be reset by LyXRC,
+       // but the default is fixed for a given OS.
+       system_temp_dir_ = FileName::tempPath();
        temp_dir_ = system_temp_dir_;
        document_dir_ = get_document_dir(home_dir_);
 
@@ -162,6 +162,15 @@ Package::Package(string const & command_line_arg0,
 }
 
 
+void Package::set_temp_dir(FileName const & temp_dir) const
+{
+       if (temp_dir.empty())
+               temp_dir_ = system_temp_dir_;
+       else
+               temp_dir_ = temp_dir;
+}
+
+
 namespace {
 
 // These next functions contain the stuff that is substituted at
@@ -358,29 +367,15 @@ FileName const get_locale_dir(FileName const & system_support_dir)
 }
 
 
-// Specification of temp_dir_ may be reset by LyXRC,
-// but the default is fixed for a given OS.
-FileName const get_temp_dir()
-{
-#if defined (USE_WINDOWS_PACKAGING)
-       // Typical example: C:/TEMP/.
-       char path[MAX_PATH];
-       GetTempPath(MAX_PATH, path);
-       return FileName(to_utf8(from_local8bit(path)));
-#else // Posix-like.
-       return FileName("/tmp");
-#endif
-}
-
-
 // Extracts the absolute path from the foo of "-sysdir foo" or "-userdir foo"
 FileName const abs_path_from_command_line(string const & command_line)
 {
        if (command_line.empty())
                return FileName();
 
-       string const path = fix_dir_name(command_line);
-       return os::is_absolute_path(path) ? FileName(path) : makeAbsPath(path);
+       string const str_path = fix_dir_name(command_line);
+       FileName path(str_path);
+       return path.isAbsolute() ? path : makeAbsPath(str_path);
 }
 
 
@@ -397,8 +392,9 @@ FileName const get_binary_path(string const & exe)
 #else
        string const exe_path = os::internal_path(exe);
 #endif
-       if (os::is_absolute_path(exe_path))
-               return FileName(exe_path);
+       FileName exepath(exe_path);
+       if (exepath.isAbsolute())
+               return exepath;
 
        // Two possibilities present themselves.
        // 1. The binary is relative to the CWD.
@@ -412,9 +408,9 @@ FileName const get_binary_path(string const & exe)
        if (exe_name != exe_path)
                return FileName();
 
-       std::vector<string> const path = getEnvPath("PATH");
-       std::vector<string>::const_iterator it = path.begin();
-       std::vector<string>::const_iterator const end = path.end();
+       vector<string> const path = getEnvPath("PATH");
+       vector<string>::const_iterator it = path.begin();
+       vector<string>::const_iterator const end = path.end();
        for (; it != end; ++it) {
                // This will do nothing if *it is already absolute.
                string const exe_dir = makeAbsPath(*it).absFilename();
@@ -455,7 +451,7 @@ get_system_support_dir(FileName const & abs_binary,
 
        // searched_dirs is used for diagnostic purposes only in the case
        // that "chkconfig.ltx" is not found.
-       std::list<FileName> searched_dirs;
+       list<FileName> searched_dirs;
 
        // 1. Use the -sysdir command line parameter.
        FileName path = abs_path_from_command_line(command_line_system_support_dir);
@@ -465,11 +461,11 @@ get_system_support_dir(FileName const & abs_binary,
                        return path;
        }
 
-       // 2. Use the "LYX_DIR_15x" environment variable.
-       path = extract_env_var_dir("LYX_DIR_15x");
+       // 2. Use the "LYX_DIR_${major}${minor}x" environment variable.
+       path = extract_env_var_dir(LYX_DIR_VER);
        if (!path.empty()) {
                searched_dirs.push_back(path);
-               if (check_env_var_dir(path, chkconfig_ltx, "LYX_DIR_15x"))
+               if (check_env_var_dir(path, chkconfig_ltx, LYX_DIR_VER))
                        return path;
        }
 
@@ -545,7 +541,7 @@ get_system_support_dir(FileName const & abs_binary,
        // Everything has failed :-(
        // So inform the user and exit.
        string searched_dirs_str;
-       typedef std::list<FileName>::const_iterator iterator;
+       typedef list<FileName>::const_iterator iterator;
        iterator const begin = searched_dirs.begin();
        iterator const end = searched_dirs.end();
        for (iterator it = begin; it != end; ++it) {
@@ -557,13 +553,13 @@ get_system_support_dir(FileName const & abs_binary,
        // FIXME UNICODE
        throw ExceptionMessage(ErrorException, _("No system directory"),
                bformat(_("Unable to determine the system directory "
-                                        "having searched\n"
-                                        "\t%1$s\n"
-                                        "Use the '-sysdir' command line parameter or "
-                                        "set the environment variable LYX_DIR_15x to "
-                                        "the LyX system directory containing the file "
-                                        "`chkconfig.ltx'."),
-                         from_utf8(searched_dirs_str)));
+                               "having searched\n"
+                               "\t%1$s\n"
+                               "Use the '-sysdir' command line parameter or "
+                               "set the environment variable\n%2$s "
+                               "to the LyX system directory containing the "
+                               "file `chkconfig.ltx'."),
+                         from_utf8(searched_dirs_str), from_ascii(LYX_DIR_VER)));
 
        // Keep the compiler happy.
        return FileName();
@@ -581,8 +577,8 @@ bool userSupportDir(FileName const & default_user_support_dir,
        if (!result.empty())
                return true;
 
-       // 2. Use the LYX_USERDIR_15x environment variable.
-       result = extract_env_var_dir("LYX_USERDIR_15x");
+       // 2. Use the LYX_USERDIR_${major}${minor}x environment variable.
+       result = extract_env_var_dir(LYX_USERDIR_VER);
        if (!result.empty())
                return true;
 
@@ -629,7 +625,7 @@ FileName const get_default_user_support_dir(FileName const & home_dir)
 
 
 // Check that directory @c dir contains @c file.
-// Else emit a warning about an invalid @c command_line_switch.
+// Else emit an error message about an invalid @c command_line_switch.
 bool check_command_line_dir(string const & dir,
                            string const & file,
                            string const & command_line_switch)
@@ -637,7 +633,7 @@ bool check_command_line_dir(string const & dir,
        FileName const abs_path = fileSearch(dir, file);
        if (abs_path.empty()) {
                // FIXME UNICODE
-               throw ExceptionMessage(WarningException, _("File not found"), bformat(
+               throw ExceptionMessage(ErrorException, _("File not found"), bformat(
                        _("Invalid %1$s switch.\nDirectory %2$s does not contain %3$s."),
                        from_utf8(command_line_switch), from_utf8(dir),
                        from_utf8(file)));