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:
parent
6e485e5766
commit
89e6b0d577
2 changed files with 63 additions and 37 deletions
|
@ -1387,6 +1387,55 @@ namespace IDE
|
||||||
return true;
|
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)
|
public bool SaveFile(SourceViewPanel sourceViewPanel, String forcePath = null)
|
||||||
{
|
{
|
||||||
if ((sourceViewPanel.HasUnsavedChanges()) || (forcePath != null))
|
if ((sourceViewPanel.HasUnsavedChanges()) || (forcePath != null))
|
||||||
|
@ -1396,45 +1445,15 @@ namespace IDE
|
||||||
return SaveFileAs(sourceViewPanel);
|
return SaveFileAs(sourceViewPanel);
|
||||||
}
|
}
|
||||||
|
|
||||||
var lineEndingKind = LineEndingKind.Default;
|
if (!SaveFile(sourceViewPanel.mEditData, forcePath))
|
||||||
if (sourceViewPanel.mEditData != null)
|
return false;
|
||||||
{
|
|
||||||
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
|
if (sourceViewPanel.mProjectSource != null)
|
||||||
// think a file was externally saved
|
|
||||||
using (mFileWatcher.mMonitor.Enter())
|
|
||||||
{
|
{
|
||||||
String path = forcePath ?? sourceViewPanel.mFilePath;
|
if (mWakaTime != null)
|
||||||
String text = scope String();
|
|
||||||
sourceViewPanel.mEditWidget.GetText(text);
|
|
||||||
|
|
||||||
if (!SafeWriteTextFile(path, text, true, lineEndingKind, scope (outStr) =>
|
|
||||||
{
|
|
||||||
sourceViewPanel.mEditData.BuildHash(outStr);
|
|
||||||
}))
|
|
||||||
{
|
|
||||||
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);
|
||||||
mWakaTime.QueueFile(path, sourceViewPanel.mProjectSource.mProject.mProjectName, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -623,8 +623,10 @@ namespace IDE.ui
|
||||||
int replaceInFileCount = 0;
|
int replaceInFileCount = 0;
|
||||||
var editData = gApp.GetEditData(filePath);
|
var editData = gApp.GetEditData(filePath);
|
||||||
|
|
||||||
|
bool hasUnsavedChanges = editData.HasTextChanged();
|
||||||
|
|
||||||
globalUndoData.mFileEditDatas.Add(editData);
|
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;
|
bool matchCase = mSearchOptions.mMatchCase;
|
||||||
|
|
||||||
|
@ -698,6 +700,11 @@ namespace IDE.ui
|
||||||
|
|
||||||
sourceEditBatchHelper.Finish();
|
sourceEditBatchHelper.Finish();
|
||||||
|
|
||||||
|
if (!hasUnsavedChanges)
|
||||||
|
{
|
||||||
|
gApp.SaveFile(editData);
|
||||||
|
}
|
||||||
|
|
||||||
if ((IDEApp.IsBeefFile(filePath)) && (gApp.mBfResolveCompiler != null))
|
if ((IDEApp.IsBeefFile(filePath)) && (gApp.mBfResolveCompiler != null))
|
||||||
{
|
{
|
||||||
for (var projectSource in editData.mProjectSources)
|
for (var projectSource in editData.mProjectSources)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue