Refactor code to be more readable.
This commit is contained in:
parent
960d1fef1f
commit
81b6dd8be4
@ -288,6 +288,12 @@ void ProfilePanel::save_clicked (GdkEventButton* event)
|
|||||||
toSave = entry ? ProfileStore::getInstance()->getProfile(entry) : nullptr;
|
toSave = entry ? ProfileStore::getInstance()->getProfile(entry) : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If no entry has been selected or anything unpredictable happened, toSave
|
||||||
|
// can be nullptr.
|
||||||
|
if (toSave == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// If it's a partial profile, it's more intuitive to first allow the user
|
// If it's a partial profile, it's more intuitive to first allow the user
|
||||||
// to choose which parameters to save before showing the Save As dialog
|
// to choose which parameters to save before showing the Save As dialog
|
||||||
// #5491
|
// #5491
|
||||||
@ -336,52 +342,70 @@ void ProfilePanel::save_clicked (GdkEventButton* event)
|
|||||||
filter_any->add_pattern("*");
|
filter_any->add_pattern("*");
|
||||||
dialog.add_filter(filter_any);
|
dialog.add_filter(filter_any);
|
||||||
|
|
||||||
bool done = true;
|
while (true) {
|
||||||
|
|
||||||
do {
|
// Run the saving dialog and let the user select a path and filename.
|
||||||
done = true;
|
const auto response = dialog.run();
|
||||||
|
|
||||||
if (dialog.run() == Gtk::RESPONSE_OK) {
|
if (response != Gtk::RESPONSE_OK) {
|
||||||
|
// Just exit the loop, cause the user cancels the dialog.
|
||||||
|
|
||||||
std::string fname = dialog.get_filename();
|
break;
|
||||||
|
} else {
|
||||||
|
// Go on with saving the the profile.
|
||||||
|
|
||||||
|
auto fname = dialog.get_filename();
|
||||||
|
|
||||||
if (("." + getExtension(fname)) != paramFileExtension) {
|
if (("." + getExtension(fname)) != paramFileExtension) {
|
||||||
fname += paramFileExtension;
|
fname += paramFileExtension;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!confirmOverwrite(dialog, fname)) {
|
if (!confirmOverwrite(dialog, fname)) {
|
||||||
|
|
||||||
|
// The user doesn't want to override the existing file. So, just restart the loop,
|
||||||
|
// so the user can select a different path or file name.
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
lastFilename = Glib::path_get_basename(fname);
|
lastFilename = Glib::path_get_basename(fname);
|
||||||
|
|
||||||
if (toSave) {
|
auto retCode = -1;
|
||||||
int retCode;
|
|
||||||
|
|
||||||
if (isPartial) {
|
if (isPartial) {
|
||||||
// Build partial profile
|
// Build partial profile
|
||||||
PartialProfile ppTemp(true);
|
PartialProfile ppTemp(true);
|
||||||
partialProfileDlg->applyPaste(ppTemp.pparams, ppTemp.pedited, toSave->pparams, nullptr);
|
partialProfileDlg->applyPaste(ppTemp.pparams, ppTemp.pedited, toSave->pparams, nullptr);
|
||||||
// Save partial profile
|
|
||||||
retCode = ppTemp.pparams->save(fname, "", true, ppTemp.pedited);
|
|
||||||
// Cleanup
|
|
||||||
ppTemp.deleteInstance();
|
|
||||||
} else {
|
|
||||||
// Save full profile
|
|
||||||
retCode = toSave->pparams->save(fname);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!retCode) {
|
// Save partial profile
|
||||||
const auto ccPrevState = changeconn.block(true);
|
retCode = ppTemp.pparams->save(fname, "", true, ppTemp.pedited);
|
||||||
ProfileStore::getInstance()->parseProfiles();
|
|
||||||
changeconn.block(ccPrevState);
|
// Cleanup
|
||||||
} else {
|
ppTemp.deleteInstance();
|
||||||
done = false;
|
} else {
|
||||||
writeFailed(dialog, fname);
|
// Save full profile
|
||||||
}
|
retCode = toSave->pparams->save(fname);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (retCode == 0) {
|
||||||
|
// Saving the profile was successfull.
|
||||||
|
|
||||||
|
const auto ccPrevState = changeconn.block(true);
|
||||||
|
ProfileStore::getInstance()->parseProfiles();
|
||||||
|
changeconn.block(ccPrevState);
|
||||||
|
|
||||||
|
// Because saving has been successfull, just leave the loop;
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
// Saving the profile was not successfull.
|
||||||
|
|
||||||
|
writeFailed(dialog, fname);
|
||||||
|
|
||||||
|
// In case the saving process was not successfull (missing permissions, ...)
|
||||||
|
// reopen the dialog and try again.
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (!done);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user