Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

ui: handle case when selected project location can not be written #906

Merged
merged 1 commit into from Feb 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/lib/settings/Settings.cpp
Expand Up @@ -50,28 +50,32 @@ bool Settings::loadFromString(const std::string& text, bool readOnly)
return true;
}

void Settings::save()
bool Settings::save()
{
if (m_readOnly)
{
return;
return false;
}

bool success = false;
if (m_config.get() && !m_filePath.empty())
{
m_config->save(m_filePath.str());
success = m_config->save(m_filePath.str());
}
else

if (!success)
{
LOG_WARNING(L"Settings were not saved: " + m_filePath.wstr());
}

return success;
}

void Settings::save(const FilePath& filePath)
bool Settings::save(const FilePath& filePath)
{
setFilePath(filePath);

save();
return save();
}

void Settings::clear()
Expand Down
4 changes: 2 additions & 2 deletions src/lib/settings/Settings.h
Expand Up @@ -19,8 +19,8 @@ class Settings

bool load(const FilePath& filePath, bool readOnly = false);
bool loadFromString(const std::string& text, bool readOnly = false);
void save();
void save(const FilePath& filePath);
bool save();
bool save(const FilePath& filePath);

void clear();

Expand Down
4 changes: 2 additions & 2 deletions src/lib/utility/ConfigManager.cpp
Expand Up @@ -375,10 +375,10 @@ bool ConfigManager::load(const std::shared_ptr<TextAccess> textAccess)
return true;
}

void ConfigManager::save(const std::string filepath)
bool ConfigManager::save(const std::string filepath)
{
std::string output("");
createXmlDocument(true, filepath, output);
return createXmlDocument(true, filepath, output);
}

void ConfigManager::setWarnOnEmptyKey(bool warnOnEmptyKey) const
Expand Down
2 changes: 1 addition & 1 deletion src/lib/utility/ConfigManager.h
Expand Up @@ -59,7 +59,7 @@ class ConfigManager
std::vector<std::string> getSublevelKeys(const std::string& key) const;

bool load(const std::shared_ptr<TextAccess> textAccess);
void save(const std::string filepath);
bool save(const std::string filepath);
std::string toString();

void setWarnOnEmptyKey(bool warnOnEmptyKey) const;
Expand Down
18 changes: 16 additions & 2 deletions src/lib_gui/qt/project_wizard/QtProjectWizard.cpp
Expand Up @@ -1022,7 +1022,8 @@ void QtProjectWizard::removeSelectedSourceGroup()

QMessageBox msgBox;
msgBox.setText(QStringLiteral("Remove Source Group"));
msgBox.setInformativeText(QStringLiteral("Do you really want to remove this source group from the project?"));
msgBox.setInformativeText(
QStringLiteral("Do you really want to remove this source group from the project?"));
msgBox.addButton(QStringLiteral("Yes"), QMessageBox::ButtonRole::YesRole);
msgBox.addButton(QStringLiteral("No"), QMessageBox::ButtonRole::NoRole);
msgBox.setIcon(QMessageBox::Icon::Question);
Expand Down Expand Up @@ -1277,7 +1278,20 @@ void QtProjectWizard::createProject()

m_projectSettings->setVersion(ProjectSettings::VERSION);
m_projectSettings->setAllSourceGroupSettings(m_allSourceGroupSettings);
m_projectSettings->save(path);
if (!m_projectSettings->save(path))
{
MessageStatus(L"Unable to save project to location: " + path.wstr()).dispatch();

QMessageBox msgBox;
msgBox.setText("Could not create Project");
msgBox.setInformativeText(QString::fromStdWString(
L"<p>Sourcetrail was unable to save the project to the specified path. Please pick a "
L"different project location.</p>"));
msgBox.addButton("Ok", QMessageBox::ButtonRole::AcceptRole);
msgBox.exec();

return;
}

bool settingsChanged = false;
if (m_editing)
Expand Down