diff --git a/IDE/src/IDEApp.bf b/IDE/src/IDEApp.bf index ff84264f..96839ac6 100644 --- a/IDE/src/IDEApp.bf +++ b/IDE/src/IDEApp.bf @@ -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,45 +1445,15 @@ 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; - } + if (!SaveFile(sourceViewPanel.mEditData, forcePath)) + return false; - // Lock file watcher to synchronize the 'file changed' notification so we don't - // think a file was externally saved - using (mFileWatcher.mMonitor.Enter()) + if (sourceViewPanel.mProjectSource != null) { - 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); - })) - { - 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) { - if (mWakaTime != null) - { - mWakaTime.QueueFile(path, sourceViewPanel.mProjectSource.mProject.mProjectName, true); - } + String path = forcePath ?? sourceViewPanel.mFilePath; + mWakaTime.QueueFile(path, sourceViewPanel.mProjectSource.mProject.mProjectName, true); } } } diff --git a/IDE/src/ui/FindResultsPanel.bf b/IDE/src/ui/FindResultsPanel.bf index 3ea9415e..ca4bcd70 100644 --- a/IDE/src/ui/FindResultsPanel.bf +++ b/IDE/src/ui/FindResultsPanel.bf @@ -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)