Some enhancement for specifying klayout paths

$KLAYOUT_HOME can now be empty which has the same effect
than setting it to /dev/null - no home folder is present and
no packages will be searched there.

$KLAYOUT_PATH can be empty which makes KLayout not choose
the installation folder as the default path location as before.
This commit is contained in:
Matthias Koefferlein 2022-11-10 22:01:07 +01:00
parent c220ed0cbc
commit 719cd28f76
4 changed files with 31 additions and 13 deletions

View File

@ -258,7 +258,10 @@ ApplicationBase::parse_cmd (int &argc, char **argv)
}
}
m_config_file_to_write = tl::to_string (QDir (tl::to_qstring (m_appdata_path)).absoluteFilePath (QString::fromUtf8 ("klayoutrc")));
m_config_file_to_write.clear ();
if (! m_appdata_path.empty ()) {
m_config_file_to_write = tl::to_string (QDir (tl::to_qstring (m_appdata_path)).absoluteFilePath (QString::fromUtf8 ("klayoutrc")));
}
// Hint: the order is reverse in the sense that the first one wins ...
for (std::vector <std::string>::const_iterator p = m_klayout_path.end (); p != m_klayout_path.begin (); ) {
@ -733,10 +736,12 @@ ApplicationBase::init_app ()
std::vector<std::string> global_modules = scan_global_modules ();
m_load_macros.insert (m_load_macros.begin (), global_modules.begin (), global_modules.end ());
size_t local_folders = (lay::get_appdata_path ().empty () ? 0 : 1);
for (std::vector <std::string>::const_iterator p = m_klayout_path.begin (); p != m_klayout_path.end (); ++p) {
if (p == m_klayout_path.begin ()) {
if (p - m_klayout_path.begin () < local_folders) {
mc->add_path (*p, tl::to_string (QObject::tr ("Local")), std::string (), false);
} else if (m_klayout_path.size () == 2) {
} else if (m_klayout_path.size () == 1 + local_folders) {
mc->add_path (*p, tl::to_string (QObject::tr ("Global")), std::string (), true);
} else {
mc->add_path (*p, tl::to_string (QObject::tr ("Global")) + " - " + *p, std::string (), true);

View File

@ -274,13 +274,18 @@ HelpSource::initialize_index ()
bool ok = false;
const QString help_index_cache_file = QString::fromUtf8 ("help-index.xml");
std::string per_user_cache_file = tl::to_string (QDir (tl::to_qstring (lay::ApplicationBase::instance ()->appdata_path ())).absoluteFilePath (help_index_cache_file));
std::string per_user_cache_file;
if (! lay::ApplicationBase::instance ()->appdata_path ().empty ()) {
per_user_cache_file = tl::to_string (QDir (tl::to_qstring (lay::ApplicationBase::instance ()->appdata_path ())).absoluteFilePath (help_index_cache_file));
}
// Try to obtain the help index from the installation or application path
std::vector<std::string> cache_files;
cache_files.push_back (tl::to_string (QDir (tl::to_qstring (lay::ApplicationBase::instance ()->inst_path ())).absoluteFilePath (help_index_cache_file)));
cache_files.push_back (per_user_cache_file);
if (! per_user_cache_file.empty ()) {
cache_files.push_back (per_user_cache_file);
}
for (std::vector<std::string>::const_iterator c = cache_files.begin (); ! ok && c != cache_files.end (); ++c) {
@ -307,7 +312,7 @@ HelpSource::initialize_index ()
}
if (! ok) {
if (! ok && ! per_user_cache_file.empty ()) {
// If no index is found, create one in "per_user_cache_file"
produce_index_file (per_user_cache_file);
}

View File

@ -262,7 +262,7 @@ MacroController::drop_url (const std::string &path_or_url)
macro->load_from (path);
macro->set_file_path (path);
if (macro->is_autorun () || macro->show_in_menu ()) {
if ((macro->is_autorun () || macro->show_in_menu ()) && ! lay::ApplicationBase::instance ()->appdata_path ().empty ()) {
// install macro permanently
if (QMessageBox::question (mp_mw,

View File

@ -40,8 +40,9 @@ namespace lay
std::string
get_appdata_path ()
{
if (tl::has_env ("KLAYOUT_HOME")) {
return tl::get_env ("KLAYOUT_HOME");
const char *klayout_home_env = "KLAYOUT_HOME";
if (tl::has_env (klayout_home_env)) {
return tl::get_env (klayout_home_env);
}
QDir appdata_dir = QDir::homePath ();
@ -105,11 +106,18 @@ get_klayout_path ()
std::vector<std::string> klayout_path;
// generate the klayout path: the first component is always the appdata path
klayout_path.push_back (get_appdata_path ());
std::string adp = get_appdata_path ();
if (! adp.empty ()) {
klayout_path.push_back (adp);
}
std::string env = tl::get_env ("KLAYOUT_PATH");
if (! env.empty ()) {
split_path (env, klayout_path);
const char *klayout_path_env = "KLAYOUT_PATH";
if (tl::has_env (klayout_path_env)) {
std::string env = tl::get_env (klayout_path_env);
if (! env.empty ()) {
split_path (env, klayout_path);
}
} else {
klayout_path.push_back (tl::get_inst_path ());
}