forked from organicmaps/organicmaps
Editor returns error code when saving changes.
This commit is contained in:
parent
c89818f243
commit
c72ff3cb24
4 changed files with 30 additions and 18 deletions
|
@ -387,7 +387,7 @@ void Editor::LoadMapEdits()
|
|||
LOG(LINFO, ("Loaded", modified, "modified,", created, "created and", deleted, "deleted features."));
|
||||
}
|
||||
|
||||
void Editor::Save(string const & fullFilePath) const
|
||||
bool Editor::Save(string const & fullFilePath) const
|
||||
{
|
||||
// TODO(AlexZ): Improve synchronization in Editor code.
|
||||
static mutex saveMutex;
|
||||
|
@ -396,7 +396,7 @@ void Editor::Save(string const & fullFilePath) const
|
|||
if (m_features.empty())
|
||||
{
|
||||
my::DeleteFileX(GetEditorFilePath());
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
xml_document doc;
|
||||
|
@ -438,14 +438,18 @@ void Editor::Save(string const & fullFilePath) const
|
|||
}
|
||||
}
|
||||
|
||||
if (doc)
|
||||
string const tmpFileName = fullFilePath + ".tmp";
|
||||
if (!doc.save_file(tmpFileName.data(), " "))
|
||||
{
|
||||
string const tmpFileName = fullFilePath + ".tmp";
|
||||
if (!doc.save_file(tmpFileName.data(), " "))
|
||||
LOG(LERROR, ("Can't save map edits into", tmpFileName));
|
||||
else if (!my::RenameFileX(tmpFileName, fullFilePath))
|
||||
LOG(LERROR, ("Can't rename file", tmpFileName, "to", fullFilePath));
|
||||
LOG(LERROR, ("Can't save map edits into", tmpFileName));
|
||||
return false;
|
||||
}
|
||||
else if (!my::RenameFileX(tmpFileName, fullFilePath))
|
||||
{
|
||||
LOG(LERROR, ("Can't rename file", tmpFileName, "to", fullFilePath));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void Editor::ClearAllLocalEdits()
|
||||
|
@ -497,7 +501,8 @@ void Editor::DeleteFeature(FeatureType const & feature)
|
|||
//}
|
||||
//} // namespace
|
||||
|
||||
void Editor::EditFeature(FeatureType & editedFeature, string const & editedStreet, string const & editedHouseNumber)
|
||||
Editor::SaveResult Editor::SaveEditedFeature(FeatureType & editedFeature, string const & editedStreet,
|
||||
string const & editedHouseNumber)
|
||||
{
|
||||
// Check house number for validity.
|
||||
if (editedHouseNumber.empty() || feature::IsHouseNumber(editedHouseNumber))
|
||||
|
@ -512,7 +517,7 @@ void Editor::EditFeature(FeatureType & editedFeature, string const & editedStree
|
|||
// TODO(AlexZ): Synchronize Save call/make it on a separate thread.
|
||||
Save(GetEditorFilePath());
|
||||
Invalidate();
|
||||
return;
|
||||
return NothingWasChanged;
|
||||
}
|
||||
|
||||
FeatureTypeInfo fti;
|
||||
|
@ -524,8 +529,9 @@ void Editor::EditFeature(FeatureType & editedFeature, string const & editedStree
|
|||
m_features[fid.m_mwmId][fid.m_index] = move(fti);
|
||||
|
||||
// TODO(AlexZ): Synchronize Save call/make it on a separate thread.
|
||||
Save(GetEditorFilePath());
|
||||
bool const savedSuccessfully = Save(GetEditorFilePath());
|
||||
Invalidate();
|
||||
return savedSuccessfully ? SavedSuccessfully : NoFreeSpaceError;
|
||||
}
|
||||
|
||||
void Editor::ForEachFeatureInMwmRectAndScale(MwmSet::MwmId const & id,
|
||||
|
|
|
@ -90,11 +90,16 @@ public:
|
|||
/// @returns sorted features indices with specified status.
|
||||
vector<uint32_t> GetFeaturesByStatus(MwmSet::MwmId const & mwmId, FeatureStatus status) const;
|
||||
|
||||
enum SaveResult
|
||||
{
|
||||
NothingWasChanged,
|
||||
SavedSuccessfully,
|
||||
NoFreeSpaceError
|
||||
};
|
||||
/// Editor checks internally if any feature params were actually edited.
|
||||
/// House number is correctly updated for editedFeature (if it's valid).
|
||||
void EditFeature(FeatureType & editedFeature,
|
||||
string const & editedStreet = "",
|
||||
string const & editedHouseNumber = "");
|
||||
SaveResult SaveEditedFeature(FeatureType & editedFeature, string const & editedStreet = "",
|
||||
string const & editedHouseNumber = "");
|
||||
|
||||
EditableProperties GetEditableProperties(FeatureType const & feature) const;
|
||||
|
||||
|
@ -119,7 +124,8 @@ public:
|
|||
|
||||
private:
|
||||
// TODO(AlexZ): Synchronize Save call/make it on a separate thread.
|
||||
void Save(string const & fullFilePath) const;
|
||||
/// @returns false if fails.
|
||||
bool Save(string const & fullFilePath) const;
|
||||
void RemoveFeatureFromStorageIfExists(MwmSet::MwmId const & mwmId, uint32_t index);
|
||||
/// Notify framework that something has changed and should be redisplayed.
|
||||
void Invalidate();
|
||||
|
|
|
@ -2317,13 +2317,13 @@ bool Framework::GetEditableMapObject(FeatureID const & fid, osm::EditableMapObje
|
|||
return true;
|
||||
}
|
||||
|
||||
void Framework::SaveEditedMapObject(osm::EditableMapObject const & emo) const
|
||||
osm::Editor::SaveResult Framework::SaveEditedMapObject(osm::EditableMapObject const & emo) const
|
||||
{
|
||||
// TODO(AlexZ): Move this code to the Editor.
|
||||
auto feature = GetFeatureByID(emo.GetID());
|
||||
FeatureType & ft = *feature;
|
||||
ft.ApplyPatch(emo);
|
||||
osm::Editor::Instance().SaveEditedFeature(ft, emo.GetStreet(), emo.GetHouseNumber());
|
||||
return osm::Editor::Instance().SaveEditedFeature(ft, emo.GetStreet(), emo.GetHouseNumber());
|
||||
}
|
||||
|
||||
void Framework::DeleteFeature(FeatureID const & fid) const
|
||||
|
|
|
@ -614,7 +614,7 @@ public:
|
|||
//@{
|
||||
/// @returns false if feature is invalid or can't be edited.
|
||||
bool GetEditableMapObject(FeatureID const & fid, osm:: EditableMapObject & emo) const;
|
||||
void SaveEditedMapObject(osm:: EditableMapObject const & emo) const;
|
||||
osm::Editor::SaveResult SaveEditedMapObject(osm:: EditableMapObject const & emo) const;
|
||||
void DeleteFeature(FeatureID const & fid) const;
|
||||
osm::NewFeatureCategories GetEditorCategories() const;
|
||||
//@}
|
||||
|
|
Loading…
Add table
Reference in a new issue