1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-14 22:34:09 +02:00

Made Replace in Files properly save files

This commit is contained in:
Brian Fiete 2020-02-08 10:42:14 -08:00
parent 6e485e5766
commit 89e6b0d577
2 changed files with 63 additions and 37 deletions

View file

@ -1387,6 +1387,55 @@ namespace IDE
return true;
}
public bool SaveFile(FileEditData editData, String forcePath = null)
{
var lineEndingKind = LineEndingKind.Default;
if (editData != null)
{
for (var user in editData.mEditWidget.mEditWidgetContent.mData.mUsers)
{
user.MarkDirty();
}
lineEndingKind = editData.mLineEndingKind;
}
// Lock file watcher to synchronize the 'file changed' notification so we don't
// think a file was externally saved
using (mFileWatcher.mMonitor.Enter())
{
String path = forcePath ?? editData.mFilePath;
String text = scope String();
editData.mEditWidget.GetText(text);
if (!SafeWriteTextFile(path, text, true, lineEndingKind, scope (outStr) =>
{
editData.BuildHash(outStr);
}))
{
return false;
}
editData.mLastFileTextVersion = editData.mEditWidget.Content.mData.mCurTextVersionId;
mFileWatcher.OmitFileChange(path, text);
if (forcePath == null)
{
for (var user in editData.mEditWidget.mEditWidgetContent.mData.mUsers)
{
if (var sourceEditWidgetContent = user as SourceEditWidgetContent)
{
var sourceViewPanel = sourceEditWidgetContent.mSourceViewPanel;
sourceViewPanel?.FileSaved();
}
}
}
#if IDE_C_SUPPORT
mDepClang.FileSaved(path);
#endif
}
return true;
}
public bool SaveFile(SourceViewPanel sourceViewPanel, String forcePath = null)
{
if ((sourceViewPanel.HasUnsavedChanges()) || (forcePath != null))
@ -1396,48 +1445,18 @@ namespace IDE
return SaveFileAs(sourceViewPanel);
}
var lineEndingKind = LineEndingKind.Default;
if (sourceViewPanel.mEditData != null)
{
for (var user in sourceViewPanel.mEditData.mEditWidget.mEditWidgetContent.mData.mUsers)
{
user.MarkDirty();
}
lineEndingKind = sourceViewPanel.mEditData.mLineEndingKind;
}
// Lock file watcher to synchronize the 'file changed' notification so we don't
// think a file was externally saved
using (mFileWatcher.mMonitor.Enter())
{
String path = forcePath ?? sourceViewPanel.mFilePath;
String text = scope String();
sourceViewPanel.mEditWidget.GetText(text);
if (!SafeWriteTextFile(path, text, true, lineEndingKind, scope (outStr) =>
{
sourceViewPanel.mEditData.BuildHash(outStr);
}))
{
if (!SaveFile(sourceViewPanel.mEditData, forcePath))
return false;
}
mFileWatcher.OmitFileChange(path, text);
if (forcePath == null)
sourceViewPanel.FileSaved();
#if IDE_C_SUPPORT
mDepClang.FileSaved(path);
#endif
if (sourceViewPanel.mProjectSource != null)
{
if (mWakaTime != null)
{
String path = forcePath ?? sourceViewPanel.mFilePath;
mWakaTime.QueueFile(path, sourceViewPanel.mProjectSource.mProject.mProjectName, true);
}
}
}
}
return true;
}

View file

@ -623,8 +623,10 @@ namespace IDE.ui
int replaceInFileCount = 0;
var editData = gApp.GetEditData(filePath);
bool hasUnsavedChanges = editData.HasTextChanged();
globalUndoData.mFileEditDatas.Add(editData);
var sourceEditBatchHelper = scope:: SourceEditBatchHelper(editData.mEditWidget, "#renameSymbol", new GlobalUndoAction(editData, globalUndoData));
var sourceEditBatchHelper = scope:: SourceEditBatchHelper(editData.mEditWidget, "#renameInFiles", new GlobalUndoAction(editData, globalUndoData));
bool matchCase = mSearchOptions.mMatchCase;
@ -698,6 +700,11 @@ namespace IDE.ui
sourceEditBatchHelper.Finish();
if (!hasUnsavedChanges)
{
gApp.SaveFile(editData);
}
if ((IDEApp.IsBeefFile(filePath)) && (gApp.mBfResolveCompiler != null))
{
for (var projectSource in editData.mProjectSources)